/*URLProtocol 是类似COM 接口的数据结构,表示广义的输入文件,着重于功能函数*/ typedef struct URLProtocol { const char *name; int (*url_open)(URLContext *h, const char *filename, int flags); 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 URLProtocol *next; int (*url_read_pause)(URLContext *h, int pause); int64_t (*url_read_seek)(URLContext *h, int stream_index, int64_t timestamp, int flags); } URLProtocol; //用file 协议相应函数初始化URLProtocol 结构。 URLProtocol file_protocol = { "file", file_open, file_read, file_write, file_seek, file_close, }; //注册协议 int av_register_protocol(URLProtocol *protocol) { URLProtocol **p; p = &first_protocol; while (*p != NULL) p = &(*p)->next; *p = protocol; protocol->next = NULL; return 0; } #define REGISTER_PROTOCOL(X,x) { \ extern URLProtocol x##_protocol; \ if(CONFIG_##X##_PROTOCOL) av_register_protocol(&x##_protocol); } //url_open中识别并打开协议 up = first_protocol; while (up != NULL) { if (!strcmp(proto_str, up->name)) return url_open_protocol (puc, up, filename, flags); up = up->next; } /*URLContext 结构表示程序运行的当前广义输入文件使用的上下文,着重于所有广义输入文件共有的属性(并 且是在程序运行时才能确定其值)和关联其他结构的字段。prot 字段关联相应的广义输入文件;priv_data 字段关 联各个具体广义输入文件的句柄。*/ struct URLContext { struct URLProtocol *prot; int flags; int is_streamed; /**< true if streamed (no seek possible), default = false */ int max_packet_size; /**< if non zero, the stream is packetized with this max packet size */ void *priv_data; char *filename; /**< specified filename */ };