FFmpeg 源代码:avcodec_find_decoder()和avcodec_find_decoder_by_name()

网友投稿 1001 2022-11-21

FFmpeg 源代码:avcodec_find_decoder()和avcodec_find_decoder_by_name()

FFmpeg 源代码:avcodec_find_decoder()和avcodec_find_decoder_by_name()

avcodec_find_decoder()用于通过codec id 查找FFmpeg的解码器avcodec_find_decoder_by_name()用于通过codec name 查找FFmpeg的解码器

/** * Find a registered decoder with a matching codec ID. * * @param id AVCodecID of the requested decoder * @return A decoder if one was found, NULL otherwise. */const AVCodec *avcodec_find_decoder(enum AVCodecID id);/** * Find a registered decoder with the specified name. * * @param name name of the requested decoder * @return A decoder if one was found, NULL otherwise. */const AVCodec *avcodec_find_decoder_by_name(const char *name);

avcodec_find_decoder()函数的参数是一个解码器的ID,返回查找到的解码器(没有找到就返回NULL)avcodec_find_decoder_by_name()函数的参数是一个解码器的名称,返回查找到的解码器(没有找到就返回NULL)

avcodec_find_decoder()函数的定义位于libavcodec\allcodecs.c, 如下:

const AVCodec *avcodec_find_decoder(enum AVCodecID id){ return find_codec(id, av_codec_is_decoder);}

av_codec_is_decoder()是一个判断AVCodec是否为解码器的函数。如果是解码器,返回非0值,否则返回0

/** * @return a non-zero number if codec is a decoder, zero otherwise */int av_codec_is_decoder(const AVCodec *codec);

find_codec()函数的实现位于 libavcodec\allcodecs.c, 如下:

static const AVCodec *find_codec(enum AVCodecID id, int (*x)(const AVCodec *)){ const AVCodec *p, *experimental = NULL; void *i = 0; id = remap_deprecated_codec_id(id); while ((p = av_codec_iterate(&i))) { if (!x(p)) continue; if (p->id == id) { if (p->capabilities & AV_CODEC_CAP_EXPERIMENTAL && !experimental) { experimental = p; } else return p; } } return experimental;}

remap_deprecated_codec_id()用于将一些过时的编码器ID映射到新的编码器ID ,但是目前没有做任何映射,默认返回传入的codec id, 该接口主要是为了兼容性和可扩展性

find_codec() 函数主要是调用了av_codec_iterate() , av_codec_iterate() 是存储AVCodec链表的一个迭代器

总体实现是,find_codec()循环遍历存储AVCodec结构的链表,逐一比较输入的ID和每一个编码器的ID,直到找到ID取值相等的编码器。

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Mybatis执行插入语句后并返回主键ID
下一篇:基于spring data jpa @query返回map的踩坑记录
相关文章

 发表评论

暂时没有评论,来抢沙发吧~