一个真正快乐的人,是能够享受他的创造的人。那些像海绵一样,只取不予的人,只会失去快乐。
avio_open2函数是用来打开输入输出文件,包括普通的文件、rtmp、udp、https等。
ffmpeg用来管理输入输出文件数据结构是AVIOContext。
一、函数参数解析
复制代码1
2int avio_open2(AVIOContext **s, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options);
1.s
带外参数,该函数主要用来分配和初始化该变量。
2.url
资源的访问地址,不限于本地文件。
3.flags
用于指示url参数指定的资源的打开方式。
4.int_cb
协议级的中断回调。
5.options
协议的私有选项
二、核心逻辑解析
复制代码
1
2
3
4
5int avio_open2(AVIOContext **s, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options) { return ffio_open_whitelist(s, filename, flags, int_cb, options, NULL, NULL); }
1.ffio_open_whitelist函数
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20int ffio_open_whitelist(AVIOContext **s, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist ) { URLContext *h; int err; *s = NULL; err = ffurl_open_whitelist(&h, filename, flags, int_cb, options, whitelist, blacklist, NULL); if (err < 0) return err; err = ffio_fdopen(s, h); if (err < 0) { ffurl_close(h); return err; } return 0;
AVIOContext结构体最重要的结构是URLContext,该结构用来保存url参数指定的资源的相关操作,包括打开、读取、关闭等。
2.ffurl_open_whitelist函数
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char* blacklist, URLContext *parent) { AVDictionary *tmp_opts = NULL; AVDictionaryEntry *e; int ret = ffurl_alloc(puc, filename, flags, int_cb); if (ret < 0) return ret; if (parent) av_opt_copy(*puc, parent); if (options && (ret = av_opt_set_dict(*puc, options)) < 0) goto fail; if (options && (*puc)->prot->priv_data_class && (ret = av_opt_set_dict((*puc)->priv_data, options)) < 0) goto fail; if (!options) options = &tmp_opts; av_assert0(!whitelist || !(e=av_dict_get(*options, "protocol_whitelist", NULL, 0)) || !strcmp(whitelist, e->value)); av_assert0(!blacklist || !(e=av_dict_get(*options, "protocol_blacklist", NULL, 0)) || !strcmp(blacklist, e->value)); if ((ret = av_dict_set(options, "protocol_whitelist", whitelist, 0)) < 0) goto fail; if ((ret = av_dict_set(options, "protocol_blacklist", blacklist, 0)) < 0) goto fail; if ((ret = av_opt_set_dict(*puc, options)) < 0) goto fail; ret = ffurl_connect(*puc, options); if (!ret) return 0; fail: ffurl_closep(puc); return ret; }
最后
以上就是爱听歌夕阳最近收集整理的关于FFmpeg源码分析:avio_open2的全部内容,更多相关FFmpeg源码分析内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复