X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavfilter%2Fbuffersink.c;h=c4147bf732492fd96c3604275650b43fa4a94c1d;hb=a04ad248a05e7b613abe09b3bb067f555108d794;hp=f9b0b5e7d8685bfd7bcaedaaa4799ced3d62f9b9;hpb=e645d7a6d452df83cedcbb1d6708429ceea156da;p=ffmpeg diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c index f9b0b5e7d86..c4147bf7324 100644 --- a/libavfilter/buffersink.c +++ b/libavfilter/buffersink.c @@ -61,8 +61,29 @@ typedef struct BufferSinkContext { } BufferSinkContext; #define NB_ITEMS(list) (list ## _size / sizeof(*list)) -#define FIFO_INIT_SIZE 8 -#define FIFO_INIT_ELEMENT_SIZE sizeof(void *) + +static void cleanup_redundant_layouts(AVFilterContext *ctx) +{ + BufferSinkContext *buf = ctx->priv; + int nb_layouts = NB_ITEMS(buf->channel_layouts); + int nb_counts = NB_ITEMS(buf->channel_counts); + uint64_t counts = 0; + int i, lc, n; + + for (i = 0; i < nb_counts; i++) + if (buf->channel_counts[i] < 64) + counts |= (uint64_t)1 << buf->channel_counts[i]; + for (i = lc = 0; i < nb_layouts; i++) { + n = av_get_channel_layout_nb_channels(buf->channel_layouts[i]); + if (n < 64 && (counts & ((uint64_t)1 << n))) + av_log(ctx, AV_LOG_WARNING, + "Removing channel layout 0x%"PRIx64", redundant with %d channels\n", + buf->channel_layouts[i], n); + else + buf->channel_layouts[lc++] = buf->channel_layouts[i]; + } + buf->channel_layouts_size = lc * sizeof(*buf->channel_layouts); +} int attribute_align_arg av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame) { @@ -127,6 +148,7 @@ int attribute_align_arg av_buffersink_get_samples(AVFilterContext *ctx, return get_frame_internal(ctx, frame, 0, nb_samples); } +#if FF_API_BUFFERSINK_ALLOC AVBufferSinkParams *av_buffersink_params_alloc(void) { static const int pixel_fmts[] = { AV_PIX_FMT_NONE }; @@ -146,6 +168,7 @@ AVABufferSinkParams *av_abuffersink_params_alloc(void) return NULL; return params; } +#endif static av_cold int common_init(AVFilterContext *ctx) { @@ -201,20 +224,6 @@ MAKE_AVFILTERLINK_ACCESSOR(int , sample_rate ) MAKE_AVFILTERLINK_ACCESSOR(AVBufferRef * , hw_frames_ctx ) -static av_cold int vsink_init(AVFilterContext *ctx, void *opaque) -{ - BufferSinkContext *buf = ctx->priv; - AVBufferSinkParams *params = opaque; - int ret; - - if (params) { - if ((ret = av_opt_set_int_list(buf, "pix_fmts", params->pixel_fmts, AV_PIX_FMT_NONE, 0)) < 0) - return ret; - } - - return common_init(ctx); -} - #define CHECK_LIST_SIZE(field) \ if (buf->field ## _size % sizeof(*buf->field)) { \ av_log(ctx, AV_LOG_ERROR, "Invalid size for " #field ": %d, " \ @@ -244,23 +253,6 @@ static int vsink_query_formats(AVFilterContext *ctx) return 0; } -static av_cold int asink_init(AVFilterContext *ctx, void *opaque) -{ - BufferSinkContext *buf = ctx->priv; - AVABufferSinkParams *params = opaque; - int ret; - - if (params) { - if ((ret = av_opt_set_int_list(buf, "sample_fmts", params->sample_fmts, AV_SAMPLE_FMT_NONE, 0)) < 0 || - (ret = av_opt_set_int_list(buf, "sample_rates", params->sample_rates, -1, 0)) < 0 || - (ret = av_opt_set_int_list(buf, "channel_layouts", params->channel_layouts, -1, 0)) < 0 || - (ret = av_opt_set_int_list(buf, "channel_counts", params->channel_counts, -1, 0)) < 0 || - (ret = av_opt_set_int(buf, "all_channel_counts", params->all_channel_counts, 0)) < 0) - return ret; - } - return common_init(ctx); -} - static int asink_query_formats(AVFilterContext *ctx) { BufferSinkContext *buf = ctx->priv; @@ -284,6 +276,7 @@ static int asink_query_formats(AVFilterContext *ctx) if (buf->channel_layouts_size || buf->channel_counts_size || buf->all_channel_counts) { + cleanup_redundant_layouts(ctx); for (i = 0; i < NB_ITEMS(buf->channel_layouts); i++) if ((ret = ff_add_channel_layout(&layouts, buf->channel_layouts[i])) < 0) return ret; @@ -336,42 +329,40 @@ AVFILTER_DEFINE_CLASS(abuffersink); static const AVFilterPad avfilter_vsink_buffer_inputs[] = { { - .name = "default", - .type = AVMEDIA_TYPE_VIDEO, + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, { NULL } }; -AVFilter ff_vsink_buffer = { - .name = "buffersink", - .description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."), - .priv_size = sizeof(BufferSinkContext), - .priv_class = &buffersink_class, - .init_opaque = vsink_init, - +const AVFilter ff_vsink_buffer = { + .name = "buffersink", + .description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."), + .priv_size = sizeof(BufferSinkContext), + .priv_class = &buffersink_class, + .init = common_init, .query_formats = vsink_query_formats, - .activate = activate, - .inputs = avfilter_vsink_buffer_inputs, - .outputs = NULL, + .activate = activate, + .inputs = avfilter_vsink_buffer_inputs, + .outputs = NULL, }; static const AVFilterPad avfilter_asink_abuffer_inputs[] = { { - .name = "default", - .type = AVMEDIA_TYPE_AUDIO, + .name = "default", + .type = AVMEDIA_TYPE_AUDIO, }, { NULL } }; -AVFilter ff_asink_abuffer = { - .name = "abuffersink", - .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."), - .priv_class = &abuffersink_class, - .priv_size = sizeof(BufferSinkContext), - .init_opaque = asink_init, - +const AVFilter ff_asink_abuffer = { + .name = "abuffersink", + .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."), + .priv_class = &abuffersink_class, + .priv_size = sizeof(BufferSinkContext), + .init = common_init, .query_formats = asink_query_formats, - .activate = activate, - .inputs = avfilter_asink_abuffer_inputs, - .outputs = NULL, + .activate = activate, + .inputs = avfilter_asink_abuffer_inputs, + .outputs = NULL, };