From: Anton Khirnov <anton@khirnov.net> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 03/10] lavfi: move AVFilterLink.m{ax, in}_samples to FilterLink Date: Sun, 11 Aug 2024 16:42:04 +0200 Message-ID: <20240811144211.5712-3-anton@khirnov.net> (raw) In-Reply-To: <20240811144211.5712-1-anton@khirnov.net> Also, document who sets these fields and when. --- 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 a5980d5e9c..f9425a5828 100644 --- a/libavfilter/af_lv2.c +++ b/libavfilter/af_lv2.c @@ -34,6 +34,7 @@ #include "libavutil/opt.h" #include "audio.h" #include "avfilter.h" +#include "filters.h" #include "formats.h" #include "internal.h" @@ -381,7 +382,7 @@ static int config_output(AVFilterLink *outlink) (lilv_plugin_has_feature(s->plugin, s->powerOf2BlockLength) || lilv_plugin_has_feature(s->plugin, s->fixedBlockLength) || lilv_plugin_has_feature(s->plugin, s->boundedBlockLength))) { - AVFilterLink *inlink = ctx->inputs[0]; + FilterLink *inlink = ff_filter_link(ctx->inputs[0]); inlink->min_samples = inlink->max_samples = 4096; } 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 a34e61f23c..2624b0cfca 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -625,21 +625,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 e05bd0a573..2c1fa4c293 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. * -- 2.43.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-08-11 14:43 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-08-11 14:42 [FFmpeg-devel] [PATCH 01/10] lavfi: set AVFilterLink.graph on link creation Anton Khirnov 2024-08-11 14:42 ` [FFmpeg-devel] [PATCH 02/10] lavfi: add a new struct for private link properties Anton Khirnov 2024-08-11 14:42 ` Anton Khirnov [this message] 2024-08-11 14:42 ` [FFmpeg-devel] [PATCH 04/10] lavfi/vf_*_cuda: do not access hw contexts before checking they exist Anton Khirnov 2024-08-11 14:42 ` [FFmpeg-devel] [PATCH 05/10] lavfi: move AVFilterLink.hw_frames_ctx to FilterLink Anton Khirnov 2024-08-11 14:42 ` [FFmpeg-devel] [PATCH 06/10] lavfi: move AVFilterLink.current_pts(_us) " Anton Khirnov 2024-08-11 14:42 ` [FFmpeg-devel] [PATCH 07/10] lavfi: move AVFilterLink.frame_rate " Anton Khirnov 2024-08-11 14:42 ` [FFmpeg-devel] [PATCH 08/10] lavfi: move AVFilterLink.{frame, sample}_count_{in, out} " Anton Khirnov 2024-08-12 20:19 ` Michael Niedermayer 2024-08-13 8:28 ` Anton Khirnov 2024-08-11 14:42 ` [FFmpeg-devel] [PATCH 09/10] lavfi: move AVFilterLink.frame_wanted_out to FilterLinkInternal Anton Khirnov 2024-08-11 14:42 ` [FFmpeg-devel] [PATCH 10/10] lavfi: move AVFilterLink.graph to FilterLink Anton Khirnov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240811144211.5712-3-anton@khirnov.net \ --to=anton@khirnov.net \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git