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) |