您当前的位置: 首页 > 

顺其自然~

暂无认证

  • 2浏览

    0关注

    1317博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

av_find_input_format

顺其自然~ 发布时间:2022-03-25 10:50:54 ,浏览量:2

函数原型
/**
 * Find AVInputFormat based on the short name of the input format.
 * 根据输入格式的短名称查找AVInputFormat。
 */
ff_const59 AVInputFormat *av_find_input_format(const char *short_name)
函数定义
ff_const59 AVInputFormat *av_find_input_format(const char *short_name)
{
    const AVInputFormat *fmt = NULL;
    void *i = 0;
    while ((fmt = av_demuxer_iterate(&i)))
        if (av_match_name(short_name, fmt->name))
            return (AVInputFormat*)fmt;
    return NULL;
}
 
const AVInputFormat *av_demuxer_iterate(void **opaque)
{
    static const uintptr_t size = sizeof(demuxer_list)/sizeof(demuxer_list[0]) - 1;
    uintptr_t i = (uintptr_t)*opaque;
    const AVInputFormat *f = NULL;
 
    if (i < size) {
        f = demuxer_list[i];
    } else if (outdev_list) {
        f = indev_list[i - size];
    }
 
    if (f)
        *opaque = (void*)(i + 1);
    return f;
}
 
int av_match_name(const char *name, const char *names)
{
    const char *p;
    int len, namelen;
 
    if (!name || !names)
        return 0;
 
    namelen = strlen(name);
    while (*names) {
        int negate = '-' == *names;
        p = strchr(names, ',');
        if (!p)
            p = names + strlen(names);
        names += negate;
        len = FFMAX(p - names, namelen);
        if (!av_strncasecmp(name, names, len) || !strncmp("ALL", names, FFMAX(3, p - names)))
            return !negate;
        names = p + (*p == ',');
    }
    return 0;
}

从以上代码中可以看出,av_find_input_format函数是通过av_demuxer_iterate函数遍历所有解封装格式列表和音视频输入设备列表,然后通过av_match_name函数判断name是否等于short_name,来返回AVInputFormat结构的。

av_demuxer_iterate函数会先后返回全局变量demuxer_list和indev_list中的每个成员,indev_list变量内容是通过avdevice_register_all函数注册的。

以avfoundation为例,avfoundation是IOS平台下音视频采集的格式:​​​​​​​

avdevice_register_all();
AVInputFormat *iFormat = av_find_open_input("avfoundation");

上述函数返回的AVInputFormat为ff_avfoundation_demuxer,该变量定义于libavdevice/avfoundation.m文件中。

AVInputFormat ff_avfoundation_demuxer = {
    .name           = "avfoundation",
    .long_name      = NULL_IF_CONFIG_SMALL("AVFoundation input device"),
    .priv_data_size = sizeof(AVFContext),
    .read_header    = avf_read_header,
    .read_packet    = avf_read_packet,
    .read_close     = avf_close,
    .flags          = AVFMT_NOFILE,
    .priv_class     = &avf_class,
};

每个AVInputFormat结构的name字段都是以逗号分隔的名称,如果在name中找到short_name指定的字符串或者name中包含ALL,则返回器对应的AVInputFormat结构。

每个AVInputFormat结构都很重要,之后很多地方都会用到该结构中的成员变量。

关注
打赏
1662339380
查看更多评论
立即登录/注册

微信扫码登录

0.0827s