From 5e8bd1219f3f825d67e6accbfb23e7ffbdd71f9e Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 5 Aug 2024 11:41:53 +0200 Subject: [PATCH] lavfi: move AVFilterLink.m{ax,in}_samples to FilterLink Also, document who sets these fields and when. Signed-off-by: Paul B Mahol --- libavfilter/af_firequalizer.c | 4 +++- libavfilter/af_lv2.c | 3 ++- libavfilter/af_replaygain.c | 6 ++++-- libavfilter/avfilter.c | 13 +++++++------ libavfilter/avfilter.h | 15 --------------- libavfilter/buffersink.c | 5 +++-- libavfilter/filters.h | 21 +++++++++++++++++++++ 7 files changed, 40 insertions(+), 27 deletions(-) diff --git a/libavfilter/af_firequalizer.c b/libavfilter/af_firequalizer.c index 5108edca48..b889872775 100644 --- a/libavfilter/af_firequalizer.c +++ b/libavfilter/af_firequalizer.c @@ -26,6 +26,7 @@ #include "libavutil/avassert.h" #include "libavutil/tx.h" #include "avfilter.h" +#include "filters.h" #include "internal.h" #include "audio.h" @@ -725,6 +726,7 @@ static int generate_kernel(AVFilterContext *ctx, const char *gain, const char *g static int config_input(AVFilterLink *inlink) { + FilterLink *l = ff_filter_link(inlink); AVFilterContext *ctx = inlink->dst; FIREqualizerContext *s = ctx->priv; float iscale, scale = 1.f; @@ -824,7 +826,7 @@ static int config_input(AVFilterLink *inlink) inlink->sample_rate, inlink->ch_layout.nb_channels, s->analysis_rdft_len, s->rdft_len, s->fir_len, s->nsamples_max); if (s->fixed) - inlink->min_samples = inlink->max_samples = s->nsamples_max; + l->min_samples = l->max_samples = s->nsamples_max; return generate_kernel(ctx, SELECT_GAIN(s), SELECT_GAIN_ENTRY(s)); } diff --git a/libavfilter/af_lv2.c b/libavfilter/af_lv2.c index 887f490d4a..9a6dcccd5d 100644 --- a/libavfilter/af_lv2.c +++ b/libavfilter/af_lv2.c @@ -37,6 +37,7 @@ #include "libavutil/opt.h" #include "audio.h" #include "avfilter.h" +#include "filters.h" #include "formats.h" #include "internal.h" @@ -354,7 +355,7 @@ static int config_output(AVFilterLink *outlink) s->inplace_broken = lilv_plugin_has_feature(s->plugin, s->lv2_inPlaceBroken); if (s->nb_inputs) { - AVFilterLink *inlink = ctx->inputs[0]; + FilterLink *inlink = ff_filter_link(ctx->inputs[0]); if (lilv_plugin_has_feature(s->plugin, s->powerOf2BlockLength)) { s->min_samples = 1 << av_ceil_log2(s->min_samples); diff --git a/libavfilter/af_replaygain.c b/libavfilter/af_replaygain.c index 266121e2c0..e7b0330e6c 100644 --- a/libavfilter/af_replaygain.c +++ b/libavfilter/af_replaygain.c @@ -30,6 +30,7 @@ #include "libavutil/opt.h" #include "audio.h" #include "avfilter.h" +#include "filters.h" #include "formats.h" #include "internal.h" @@ -349,6 +350,7 @@ static int query_formats(AVFilterContext *ctx) static int config_input(AVFilterLink *inlink) { + FilterLink *l = ff_filter_link(inlink); AVFilterContext *ctx = inlink->dst; ReplayGainContext *s = ctx->priv; int i; @@ -366,8 +368,8 @@ static int config_input(AVFilterLink *inlink) s->yule_hist_i = 20; s->butter_hist_i = 4; - inlink->min_samples = - inlink->max_samples = inlink->sample_rate / 20; + l->min_samples = + l->max_samples = inlink->sample_rate / 20; return 0; } diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 80c9cf7b51..75e9bf6724 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -1077,14 +1077,15 @@ static int samples_ready(FilterLinkInternal *link, unsigned min) static int take_samples(FilterLinkInternal *li, unsigned min, unsigned max, AVFrame **rframe) { - AVFilterLink *link = &li->l.pub; + FilterLink *l = &li->l; + AVFilterLink *link = &l->pub; AVFrame *frame0, *frame, *buf; unsigned nb_samples, nb_frames, i, p; int ret; /* Note: this function relies on no format changes and must only be called with enough samples. */ - av_assert1(samples_ready(li, link->min_samples)); + av_assert1(samples_ready(li, l->min_samples)); frame0 = frame = ff_framequeue_peek(&li->fifo, 0); if (!li->fifo.samples_skipped && frame->nb_samples >= min && frame->nb_samples <= max) { *rframe = ff_framequeue_take(&li->fifo); @@ -1142,8 +1143,8 @@ static int ff_filter_frame_to_filter(AVFilterLink *link) int ret; av_assert1(ff_framequeue_queued_frames(&li->fifo)); - ret = link->min_samples ? - ff_inlink_consume_samples(link, link->min_samples, link->max_samples, &frame) : + ret = li->l.min_samples ? + ff_inlink_consume_samples(link, li->l.min_samples, li->l.max_samples, &frame) : ff_inlink_consume_frame(link, &frame); av_assert1(ret); if (ret < 0) { @@ -1218,8 +1219,8 @@ static int ff_filter_activate_default(AVFilterContext *filter) } for (i = 0; i < filter->nb_inputs; i++) { - if (samples_ready(ff_link_internal(filter->inputs[i]), - filter->inputs[i]->min_samples)) { + FilterLinkInternal *li = ff_link_internal(filter->inputs[i]); + if (samples_ready(li, li->l.min_samples)) { return ff_filter_frame_to_filter(filter->inputs[i]); } } diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 7e51a07468..92e7d5fb25 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -626,21 +626,6 @@ struct AVFilterLink { */ AVRational frame_rate; - /** - * Minimum number of samples to filter at once. If filter_frame() is - * called with fewer samples, it will accumulate them in fifo. - * This field and the related ones must not be changed after filtering - * has started. - * If 0, all related fields are ignored. - */ - int min_samples; - - /** - * Maximum number of samples to filter at once. If filter_frame() is - * called with more samples, it will split them. - */ - int max_samples; - /** * Number of past frames sent through the link. */ diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c index 5da6c9b204..ef0bc2c73f 100644 --- a/libavfilter/buffersink.c +++ b/libavfilter/buffersink.c @@ -119,7 +119,8 @@ static int get_frame_internal(AVFilterContext *ctx, AVFrame *frame, int flags, i int attribute_align_arg av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags) { - return get_frame_internal(ctx, frame, flags, ctx->inputs[0]->min_samples); + return get_frame_internal(ctx, frame, flags, + ff_filter_link(ctx->inputs[0])->min_samples); } int attribute_align_arg av_buffersink_get_samples(AVFilterContext *ctx, @@ -163,7 +164,7 @@ static int activate(AVFilterContext *ctx) void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size) { - AVFilterLink *inlink = ctx->inputs[0]; + FilterLink *inlink = ff_filter_link(ctx->inputs[0]); inlink->min_samples = inlink->max_samples = frame_size; } diff --git a/libavfilter/filters.h b/libavfilter/filters.h index 2c856fead7..11064aee13 100644 --- a/libavfilter/filters.h +++ b/libavfilter/filters.h @@ -41,8 +41,29 @@ */ typedef struct FilterLink { AVFilterLink pub; + + /** + * Minimum number of samples to filter at once. + * + * May be set by the link destination filter in its config_props(). + * If 0, all related fields are ignored. + */ + int min_samples; + + /** + * Maximum number of samples to filter at once. If filter_frame() is + * called with more samples, it will split them. + * + * May be set by the link destination filter in its config_props(). + */ + int max_samples; } FilterLink; +static inline FilterLink* ff_filter_link(AVFilterLink *link) +{ + return (FilterLink*)link; +} + /** * Mark a filter ready and schedule it for activation. *