Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7894209
  • 博文数量: 701
  • 博客积分: 2150
  • 博客等级: 上尉
  • 技术积分: 13233
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-29 16:28
个人简介

天行健,君子以自强不息!

文章分类

全部博文(701)

文章存档

2019年(2)

2018年(12)

2017年(76)

2016年(120)

2015年(178)

2014年(129)

2013年(123)

2012年(61)

分类: 云计算

2017-09-12 12:13:17

av_register_all()函数的定义在 libavformat/allformats.c,
它的作用的注册ffmpeg的各种mux和demux。

1. 函数主体

void av_register_all(void)
{
    static int initialized;

    if (initialized)
        return;
    avcodec_register_all();

    /* (de)muxers */
    REGISTER_MUXER   (A64,              a64);
    REGISTER_DEMUXER (AA,               aa);
    ...

    /* image demuxers */
    REGISTER_DEMUXER (IMAGE_BMP_PIPE,        image_bmp_pipe);
    REGISTER_DEMUXER (IMAGE_DDS_PIPE,        image_dds_pipe);
    ...

    /* external libraries */
    REGISTER_MUXER   (CHROMAPRINT,      chromaprint);
    REGISTER_DEMUXER (LIBGME,           libgme);
    ...

    initialized = 1;
}

2. demux的注册

#define REGISTER_DEMUXER(X, x)                                          \
    {                                                                   \
        extern AVInputFormat ff_##x##_demuxer;                          \
        if (CONFIG_##X##_DEMUXER)                                       \
            av_register_input_format(&ff_##x##_demuxer);                \
    }

宏展开后:
{
  extern AVInputFormat ff_aa_muxer;
  if (CONFIG_A64_MUXER)
    av_register_input_format(&ff_aa_muxer);
}

libavformat/format.c

/** head of registered input format linked list */
static AVInputFormat *first_iformat = NULL;
/** head of registered output format linked list */
static AVOutputFormat *first_oformat = NULL;

static AVInputFormat **last_iformat = &first_iformat;
static AVOutputFormat **last_oformat = &first_oformat;

void av_register_input_format(AVInputFormat *format)
{
    AVInputFormat **p = last_iformat;

    // Note, format could be added after the first 2 checks but that implies that *p is no longer NULL
    while(p != &format->next && !format->next && avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
        p = &(*p)->next;

    if (!format->next)
        last_iformat = &format->next;
}
将新的用于处理输入format的demux添加到链表的尾部;

3. mux的注册

#define REGISTER_MUXER(X, x)                                            \
    {                                                                   \
        extern AVOutputFormat ff_##x##_muxer;                           \
        if (CONFIG_##X##_MUXER)                                         \
            av_register_output_format(&ff_##x##_muxer);                 \
    }

宏展开后:
{
  extern AVOutputFormat ff_a64_muxer;
  if (CONFIG_A64_MUXER)
    av_register_output_format(&ff_a64_muxer);
}

liavformat/format.c

/** head of registered input format linked list */
static AVInputFormat *first_iformat = NULL;
/** head of registered output format linked list */
static AVOutputFormat *first_oformat = NULL;

static AVInputFormat **last_iformat = &first_iformat;
static AVOutputFormat **last_oformat = &first_oformat;

void av_register_output_format(AVOutputFormat *format)
{
    AVOutputFormat **p = last_oformat;

    // Note, format could be added after the first 2 checks but that implies that *p is no longer NULL
    while(p != &format->next && !format->next && avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
        p = &(*p)->next;

    if (!format->next)
        last_oformat = &format->next;
}

将新的用于处理输入format的mux添加到链表的尾部;
阅读(1301) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~