与其说是分析,不如说是学习,只是看在自己第一次写系列文章的份上,给足自己面子,取个有"深度"的题目!如有人被题目所蒙骗进来,还望见谅!
URLProtocol,URLContext和ByteIOContext是FFMpeg操作文件(即I/O,包括网络数据流)的结构,这几个结构现实的功能类似于C++的多态继承吧,C++的多态是通过子类继承实现,而FFMpeg的“多态”是通过静态对像现实。这部分的代码非常值得C程序借鉴,我是说,如果你要在C里实现类似C++多态性的功能;比如当你要区分你老婆和情人之间的不同功能时。
好了,先来看一下这三个struct的定义吧
typedef struct URLProtocol {
const char *name; //Rotocol名称
int (*url_open)(URLContext *h, const char *url, int flags); //open函数指针对象,以下类似
int (*url_read)(URLContext *h, unsigned char *buf, int size);
int (*url_write)(URLContext *h, unsigned char *buf, int size);
int64_t (*url_seek)(URLContext *h, int64_t pos, int whence);
int (*url_close)(URLContext *h);
struct URL