diff options
author | Josh de Kock <josh@itanimul.li> | 2017-12-23 01:17:00 +0300 |
---|---|---|
committer | Josh de Kock <josh@itanimul.li> | 2018-02-06 21:50:27 +0300 |
commit | 7e8eba2d8755962d9dca5eade57bf8f591a73c0c (patch) | |
tree | b997d9b1f5efa61f828f21e130355e3f9d85d3b0 /libavcodec/parser.c | |
parent | caa4bd7a9fe9186a56fdcb8194263b066978cbbe (diff) |
lavc: add new API for iterating codecs and codec parsers
Based on an unfinished patch by atomnuker.
Diffstat (limited to 'libavcodec/parser.c')
-rw-r--r-- | libavcodec/parser.c | 84 |
1 files changed, 74 insertions, 10 deletions
diff --git a/libavcodec/parser.c b/libavcodec/parser.c index 747ea2ee8a..0c66e80b96 100644 --- a/libavcodec/parser.c +++ b/libavcodec/parser.c @@ -32,36 +32,100 @@ #include "internal.h" #include "parser.h" -static AVCodecParser *av_first_parser = NULL; +/* Parsers */ +extern AVCodecParser ff_aac_parser; +extern AVCodecParser ff_aac_latm_parser; +extern AVCodecParser ff_ac3_parser; +extern AVCodecParser ff_adx_parser; +extern AVCodecParser ff_bmp_parser; +extern AVCodecParser ff_cavsvideo_parser; +extern AVCodecParser ff_cook_parser; +extern AVCodecParser ff_dca_parser; +extern AVCodecParser ff_dirac_parser; +extern AVCodecParser ff_dnxhd_parser; +extern AVCodecParser ff_dpx_parser; +extern AVCodecParser ff_dvaudio_parser; +extern AVCodecParser ff_dvbsub_parser; +extern AVCodecParser ff_dvdsub_parser; +extern AVCodecParser ff_dvd_nav_parser; +extern AVCodecParser ff_flac_parser; +extern AVCodecParser ff_g729_parser; +extern AVCodecParser ff_gsm_parser; +extern AVCodecParser ff_h261_parser; +extern AVCodecParser ff_h263_parser; +extern AVCodecParser ff_h264_parser; +extern AVCodecParser ff_hevc_parser; +extern AVCodecParser ff_mjpeg_parser; +extern AVCodecParser ff_mlp_parser; +extern AVCodecParser ff_mpeg4video_parser; +extern AVCodecParser ff_mpegaudio_parser; +extern AVCodecParser ff_mpegvideo_parser; +extern AVCodecParser ff_opus_parser; +extern AVCodecParser ff_png_parser; +extern AVCodecParser ff_pnm_parser; +extern AVCodecParser ff_rv30_parser; +extern AVCodecParser ff_rv40_parser; +extern AVCodecParser ff_sipr_parser; +extern AVCodecParser ff_tak_parser; +extern AVCodecParser ff_vc1_parser; +extern AVCodecParser ff_vorbis_parser; +extern AVCodecParser ff_vp3_parser; +extern AVCodecParser ff_vp8_parser; +extern AVCodecParser ff_vp9_parser; +extern AVCodecParser ff_xma_parser; + +#include "libavcodec/parser_list.c" + +static AVOnce av_parser_next_init = AV_ONCE_INIT; + +static void av_parser_init_next(void) +{ + AVCodecParser *prev = NULL, *p; + int i = 0; + while ((p = (AVCodecParser*)parser_list[i++])) { + if (prev) + prev->next = p; + prev = p; + } +} AVCodecParser *av_parser_next(const AVCodecParser *p) { + ff_thread_once(&av_parser_next_init, av_parser_init_next); + if (p) return p->next; else - return av_first_parser; + return (AVCodecParser*)parser_list[0]; } -static AVMutex parser_register_mutex = AV_MUTEX_INITIALIZER; +const AVCodecParser *av_parser_iterate(void **opaque) +{ + uintptr_t i = (uintptr_t)*opaque; + const AVCodecParser *p = parser_list[i]; + + if (p) + *opaque = (void*)(i + 1); + + return p; +} void av_register_codec_parser(AVCodecParser *parser) { - ff_mutex_lock(&parser_register_mutex); - parser->next = av_first_parser; - av_first_parser = parser; - ff_mutex_unlock(&parser_register_mutex); + ff_thread_once(&av_parser_next_init, av_parser_init_next); } AVCodecParserContext *av_parser_init(int codec_id) { AVCodecParserContext *s = NULL; - AVCodecParser *parser; + const AVCodecParser *parser; + void *i = 0; int ret; if (codec_id == AV_CODEC_ID_NONE) return NULL; - for (parser = av_first_parser; parser; parser = parser->next) { + while ((parser = av_parser_iterate(&i))) { if (parser->codec_ids[0] == codec_id || parser->codec_ids[1] == codec_id || parser->codec_ids[2] == codec_id || @@ -75,7 +139,7 @@ found: s = av_mallocz(sizeof(AVCodecParserContext)); if (!s) goto err_out; - s->parser = parser; + s->parser = (AVCodecParser*)parser; s->priv_data = av_mallocz(parser->priv_data_size); if (!s->priv_data) goto err_out; |