summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Khirnov <[email protected]>2024-09-25 14:38:49 +0200
committerAnton Khirnov <[email protected]>2024-09-28 17:04:33 +0200
commit6b402cdbf46e4398b3285277f3ff7c3654d57ce6 (patch)
tree45e87eb3c26774b332ff6c31833cae5ec7004a2a
parentcde307c78301724b8c917df6e535651682cf2f04 (diff)
lavfi/buffersink: allow av_buffersink_set_frame_size() to be called earlier
The function currently writes directly into the input link, which requires it to be called after the filter has been linked. However, the documentation does not mention this restriction and the natural place to call av_buffersink_set_frame_size() during the options-setting stage, that is before filter init (and so before the input link exists).
-rw-r--r--libavfilter/buffersink.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
index 5811720c61..af4dc38792 100644
--- a/libavfilter/buffersink.c
+++ b/libavfilter/buffersink.c
@@ -42,6 +42,7 @@
typedef struct BufferSinkContext {
const AVClass *class;
unsigned warning_limit;
+ unsigned frame_size;
/* only used for video */
enum AVPixelFormat *pixel_fmts; ///< list of accepted pixel formats
@@ -162,11 +163,25 @@ static int activate(AVFilterContext *ctx)
return 0;
}
+static int config_input_audio(AVFilterLink *inlink)
+{
+ BufferSinkContext *buf = inlink->dst->priv;
+ FilterLink *l = ff_filter_link(inlink);
+
+ l->min_samples = l->max_samples = buf->frame_size;
+
+ return 0;
+}
+
void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size)
{
- FilterLink *inlink = ff_filter_link(ctx->inputs[0]);
+ BufferSinkContext *buf = ctx->priv;
+ buf->frame_size = frame_size;
- inlink->min_samples = inlink->max_samples = frame_size;
+ if (ctx->inputs && ctx->inputs[0]) {
+ FilterLink *l = ff_filter_link(ctx->inputs[0]);
+ l->min_samples = l->max_samples = buf->frame_size;
+ }
}
#define MAKE_AVFILTERLINK_ACCESSOR(type, field) \
@@ -368,6 +383,14 @@ const AVFilter ff_vsink_buffer = {
FILTER_QUERY_FUNC(vsink_query_formats),
};
+static const AVFilterPad inputs_audio[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .config_props = config_input_audio,
+ },
+};
+
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."),
@@ -376,7 +399,7 @@ const AVFilter ff_asink_abuffer = {
.init = common_init,
.uninit = uninit,
.activate = activate,
- FILTER_INPUTS(ff_audio_default_filterpad),
+ FILTER_INPUTS(inputs_audio),
.outputs = NULL,
FILTER_QUERY_FUNC(asink_query_formats),
};