From 623669a02cd6cdc5598801bf31fd77199e61bae1 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Wed, 24 Sep 2025 15:14:29 +0200 Subject: [PATCH] avfilter/buffersrc: add av_buffersrc_get_status() There is currently no way for API users to know that a buffersrc is no longer accepting input, except by trying to feed it a frame and seeing what happens. Of course, this is not possible if the user does not *have* a frame to feed, but may still wish to know if the filter is still accepting input or not. Since passing `frame == NULL` to `av_buffersrc_add_frame()` is already treated as closing the input, we are left with no choice but to introduce a new function for this. We don't explicitly return the result of `ff_outlink_get_status()` to avoid leaking internal status codes, and instead translate them all to AVERROR(EOF). --- doc/APIchanges | 3 +++ libavfilter/buffersrc.c | 10 ++++++++++ libavfilter/buffersrc.h | 8 ++++++++ libavfilter/version.h | 2 +- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index 93c6f92704..239137f1f2 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2025-03-28 API changes, most recent first: +2025-09-xx - xxxxxxxxxx - lavfi 11.10.100 - buffersrc.h + Add av_buffersrc_get_status(). + 2025-11-18 - xxxxxxxxxx - lavu 60.19.100 - hwcontext_amf.h avutil/hwcontext_amf: add lock and unlock for AVAMFDeviceContext. diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c index 30f4df83a1..b18d3f24dd 100644 --- a/libavfilter/buffersrc.c +++ b/libavfilter/buffersrc.c @@ -286,6 +286,16 @@ int av_buffersrc_close(AVFilterContext *ctx, int64_t pts, unsigned flags) return (flags & AV_BUFFERSRC_FLAG_PUSH) ? push_frame(ctx->graph) : 0; } +int av_buffersrc_get_status(AVFilterContext *ctx) +{ + BufferSourceContext *s = ctx->priv; + + if (!s->eof && ff_outlink_get_status(ctx->outputs[0])) + s->eof = 1; + + return s->eof ? AVERROR(EOF) : 0; +} + static av_cold int init_video(AVFilterContext *ctx) { BufferSourceContext *c = ctx->priv; diff --git a/libavfilter/buffersrc.h b/libavfilter/buffersrc.h index 54de1fd1f2..c7225b6752 100644 --- a/libavfilter/buffersrc.h +++ b/libavfilter/buffersrc.h @@ -216,6 +216,14 @@ int av_buffersrc_add_frame_flags(AVFilterContext *buffer_src, */ int av_buffersrc_close(AVFilterContext *ctx, int64_t pts, unsigned flags); +/** + * Returns 0 or a negative AVERROR code. Currently, this will only ever + * return AVERROR(EOF), to indicate that the buffer source has been closed, + * either as a result of av_buffersrc_close(), or because the downstream + * filter is no longer accepting new data. + */ +int av_buffersrc_get_status(AVFilterContext *ctx); + /** * @} */ diff --git a/libavfilter/version.h b/libavfilter/version.h index 77f38cb9b4..4a69d6be98 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -31,7 +31,7 @@ #include "version_major.h" -#define LIBAVFILTER_VERSION_MINOR 9 +#define LIBAVFILTER_VERSION_MINOR 10 #define LIBAVFILTER_VERSION_MICRO 100