From: Zongyi Zhou <zho...@os.pku.edu.cn> Original patch was adding an arg field in the context structure. As it is most often only useful once, allow passing the arguments on init.
The proper solution would be using AVOption, but this is overkill for now. Signed-off-by: Christophe Gisquet <christophe.gisq...@gmail.com> --- ffmpeg_opt.c | 5 ++++- libavcodec/avcodec.h | 5 ++++- libavcodec/bitstream_filter.c | 8 +++++++- libavformat/concatdec.c | 2 +- libavformat/tee.c | 7 ++++++- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c index 03e049b..b8cd35d 100644 --- a/ffmpeg_opt.c +++ b/ffmpeg_opt.c @@ -1138,9 +1138,12 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e MATCH_PER_STREAM_OPT(bitstream_filters, str, bsf, oc, st); while (bsf) { + char *arg = NULL; if (next = strchr(bsf, ',')) *next++ = 0; - if (!(bsfc = av_bitstream_filter_init(bsf))) { + if (arg = strchr(bsf, '=')) + *arg++ = 0; + if (!(bsfc = av_bitstream_filter_init(bsf, arg))) { av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf); exit_program(1); } diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 3323284..03ce21f 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -5013,6 +5013,7 @@ typedef struct AVBitStreamFilter { const uint8_t *buf, int buf_size, int keyframe); void (*close)(AVBitStreamFilterContext *bsfc); struct AVBitStreamFilter *next; + int (*init)(AVBitStreamFilterContext *bsfc, const char *args); } AVBitStreamFilter; /** @@ -5033,10 +5034,12 @@ void av_register_bitstream_filter(AVBitStreamFilter *bsf); * The returned context must be freed with av_bitstream_filter_close(). * * @param name the name of the bitstream filter + * @param args initialization arguments for the bitstream filter * @return a bitstream filter context if a matching filter was found * and successfully initialized, NULL otherwise */ -AVBitStreamFilterContext *av_bitstream_filter_init(const char *name); +AVBitStreamFilterContext *av_bitstream_filter_init(const char *name, + const char *args); /** * Filter bitstream. diff --git a/libavcodec/bitstream_filter.c b/libavcodec/bitstream_filter.c index 3275326..53ec379 100644 --- a/libavcodec/bitstream_filter.c +++ b/libavcodec/bitstream_filter.c @@ -41,7 +41,8 @@ void av_register_bitstream_filter(AVBitStreamFilter *bsf) } while(bsf->next != avpriv_atomic_ptr_cas((void * volatile *)&first_bitstream_filter, bsf->next, bsf)); } -AVBitStreamFilterContext *av_bitstream_filter_init(const char *name) +AVBitStreamFilterContext *av_bitstream_filter_init(const char *name, + const char *args) { AVBitStreamFilter *bsf = NULL; @@ -52,6 +53,11 @@ AVBitStreamFilterContext *av_bitstream_filter_init(const char *name) bsfc->filter = bsf; bsfc->priv_data = bsf->priv_data_size ? av_mallocz(bsf->priv_data_size) : NULL; + if (bsfc->filter->init && + !bsfc->filter->init(bsfc, args)) { + av_bitstream_filter_close(bsfc); + return NULL; + } return bsfc; } } diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c index a2584d7..9d46ffe 100644 --- a/libavformat/concatdec.c +++ b/libavformat/concatdec.c @@ -186,7 +186,7 @@ static int detect_stream_specific(AVFormatContext *avf, int idx) (st->codec->extradata_size < 4 || AV_RB32(st->codec->extradata) != 1)) { av_log(cat->avf, AV_LOG_INFO, "Auto-inserting h264_mp4toannexb bitstream filter\n"); - if (!(bsf = av_bitstream_filter_init("h264_mp4toannexb"))) { + if (!(bsf = av_bitstream_filter_init("h264_mp4toannexb", NULL))) { av_log(avf, AV_LOG_ERROR, "h264_mp4toannexb bitstream filter " "required for H.264 streams\n"); return AVERROR_BSF_NOT_FOUND; diff --git a/libavformat/tee.c b/libavformat/tee.c index 681f943..88615ed 100644 --- a/libavformat/tee.c +++ b/libavformat/tee.c @@ -109,7 +109,12 @@ static int parse_bsfs(void *log_ctx, const char *bsfs_spec, return AVERROR(ENOMEM); while (bsf_name = av_strtok(buf, ",", &saveptr)) { - AVBitStreamFilterContext *bsf = av_bitstream_filter_init(bsf_name); + char *arg = strchr(buf, '='); + AVBitStreamFilterContext *bsf; + + if (arg) + *arg++ = 0; + bsf = av_bitstream_filter_init(bsf_name, arg); if (!bsf) { av_log(log_ctx, AV_LOG_ERROR, -- 1.9.2.msysgit.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel