avcodec_find_decoder作用
/**
* 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.
*/
AVCodec *avcodec_find_decoder(enum AVCodecID id);
就很简单,就是根据输入的AVCodecID类型,找到对应的解码器
avcodec_find_encoder作用
/**
* Find a registered encoder with a matching codec ID.
*
* @param id AVCodecID of the requested encoder
* @return An encoder if one was found, NULL otherwise.
*/
AVCodec *avcodec_find_encoder(enum AVCodecID id);
根据输入的AVCodecID类型,找到对应的编码器
avcodec_find_decoder | avcodec_find_encoder源码分析
AVCodec *avcodec_find_encoder(enum AVCodecID id)
{
return find_codec(id, av_codec_is_encoder);
}
AVCodec *avcodec_find_decoder(enum AVCodecID id)
{
return find_codec(id, av_codec_is_decoder);
}
实际调用的是find_codec函数,输入AVCodecID和一个判断函数,avcodec_find_encoder中输入函数指针作用是编解码器是否为编码器,avcodec_find_decoder中则是判断是否为解码器。
find_codec
static AVCodec *find_codec(enum AVCodecID id, int (*x)(const AVCodec *))
{
const AVCodec *p, *experimental = NULL;
void *i = 0;
// 4.4版本里面这个函数没有任何作用
id = remap_deprecated_codec_id(id);
// 遍历存储codec的数组,依次找到
while ((p = av_codec_iterate(&i))) {
// 找到的编解码器是否符合
if (!x(p))
continue;
// id相等
if (p->id == id) {
if (p->capabilities & AV_CODEC_CAP_EXPERIMENTAL && !experimental) {
experimental = p;
} else
return (AVCodec*)p;
}
}
return (AVCodec*)experimental;
}
av_codec_iterate
const AVCodec *av_codec_iterate(void **opaque)
{
uintptr_t i = (uintptr_t)*opaque;
//codec_list是存放所有codec的地址,包括编解码器
const AVCodec *c = codec_list[i];
// 不管多少线程调用,只执行一次,部分codec的初始化操作
ff_thread_once(&av_codec_static_init, av_codec_init_static);
//遍历
if (c)
*opaque = (void*)(i + 1);
return c;
}