[FFmpeg-cvslog] lavfi/af_pan: stop modifying private data in query_formats()
Anton Khirnov
git at videolan.org
Mon Sep 9 18:27:33 EEST 2024
ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Thu Sep 5 11:03:24 2024 +0200| [b38f4e7f865df63610987e5dd78ccbda9a5dc01a] | committer: Anton Khirnov
lavfi/af_pan: stop modifying private data in query_formats()
It is not supposed to have any side effects, and the modification in
question can just as well be done in filter init.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b38f4e7f865df63610987e5dd78ccbda9a5dc01a
---
libavfilter/af_pan.c | 48 ++++++++++++++++++++++++------------------------
1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/libavfilter/af_pan.c b/libavfilter/af_pan.c
index 02a899b88e..f2f6daa658 100644
--- a/libavfilter/af_pan.c
+++ b/libavfilter/af_pan.c
@@ -91,6 +91,28 @@ static int parse_channel_name(char **arg, int *rchannel, int *rnamed)
return AVERROR(EINVAL);
}
+static int are_gains_pure(const PanContext *pan)
+{
+ int i, j;
+
+ for (i = 0; i < MAX_CHANNELS; i++) {
+ int nb_gain = 0;
+
+ for (j = 0; j < MAX_CHANNELS; j++) {
+ double gain = pan->gain[i][j];
+
+ /* channel mapping is effective only if 0% or 100% of a channel is
+ * selected... */
+ if (gain != 0. && gain != 1.)
+ return 0;
+ /* ...and if the output channel is only composed of one input */
+ if (gain && nb_gain++)
+ return 0;
+ }
+ }
+ return 1;
+}
+
static av_cold int init(AVFilterContext *ctx)
{
PanContext *const pan = ctx->priv;
@@ -213,6 +235,7 @@ static av_cold int init(AVFilterContext *ctx)
}
}
pan->need_renumber = !!nb_in_channels[1];
+ pan->pure_gains = are_gains_pure(pan);
ret = 0;
fail:
@@ -220,37 +243,14 @@ fail:
return ret;
}
-static int are_gains_pure(const PanContext *pan)
-{
- int i, j;
-
- for (i = 0; i < MAX_CHANNELS; i++) {
- int nb_gain = 0;
-
- for (j = 0; j < MAX_CHANNELS; j++) {
- double gain = pan->gain[i][j];
-
- /* channel mapping is effective only if 0% or 100% of a channel is
- * selected... */
- if (gain != 0. && gain != 1.)
- return 0;
- /* ...and if the output channel is only composed of one input */
- if (gain && nb_gain++)
- return 0;
- }
- }
- return 1;
-}
-
static int query_formats(AVFilterContext *ctx)
{
- PanContext *pan = ctx->priv;
+ const PanContext *pan = ctx->priv;
AVFilterLink *inlink = ctx->inputs[0];
AVFilterLink *outlink = ctx->outputs[0];
AVFilterChannelLayouts *layouts;
int ret;
- pan->pure_gains = are_gains_pure(pan);
/* libswr supports any sample and packing formats */
if ((ret = ff_set_common_formats(ctx, ff_all_formats(AVMEDIA_TYPE_AUDIO))) < 0)
return ret;
More information about the ffmpeg-cvslog
mailing list