History

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.

Anton Khirnov committed 2 years ago

Commit b38f4e71 parent d0f4c081 file · +24 −24Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/af_pan.c+24−24
@@ -91,6 +91,28 @@ static int parse_channel_name(char **arg, int *rchannel, int *rnamed) · 90 unmodified lines
9191 return AVERROR(EINVAL);
9292 }
9393
94+static int are_gains_pure(const PanContext *pan)
95+{
96+ int i, j;
97+
98+ for (i = 0; i < MAX_CHANNELS; i++) {
99+ int nb_gain = 0;
100+
101+ for (j = 0; j < MAX_CHANNELS; j++) {
102+ double gain = pan->gain[i][j];
103+
104+ /* channel mapping is effective only if 0% or 100% of a channel is
105+ * selected... */
106+ if (gain != 0. && gain != 1.)
107+ return 0;
108+ /* ...and if the output channel is only composed of one input */
109+ if (gain && nb_gain++)
110+ return 0;
111+ }
112+ }
113+ return 1;
114+}
115+
94116 static av_cold int init(AVFilterContext *ctx)
95117 {
96118 PanContext *const pan = ctx->priv;
@@ -213,6 +235,7 @@ static av_cold int init(AVFilterContext *ctx) · 116 unmodified lines
213235 }
214236 }
215237 pan->need_renumber = !!nb_in_channels[1];
238+ pan->pure_gains = are_gains_pure(pan);
216239
217240 ret = 0;
218241 fail:
@@ -220,37 +243,14 @@ fail: · 1 unmodified line
220243 return ret;
221244 }
222245
223−static int are_gains_pure(const PanContext *pan)
224−{
225− int i, j;
226−
227− for (i = 0; i < MAX_CHANNELS; i++) {
228− int nb_gain = 0;
229−
230− for (j = 0; j < MAX_CHANNELS; j++) {
231− double gain = pan->gain[i][j];
232−
233− /* channel mapping is effective only if 0% or 100% of a channel is
234− * selected... */
235− if (gain != 0. && gain != 1.)
236− return 0;
237− /* ...and if the output channel is only composed of one input */
238− if (gain && nb_gain++)
239− return 0;
240− }
241− }
242− return 1;
243−}
244−
245246 static int query_formats(AVFilterContext *ctx)
246247 {
247− PanContext *pan = ctx->priv;
248+ const PanContext *pan = ctx->priv;
248249 AVFilterLink *inlink = ctx->inputs[0];
249250 AVFilterLink *outlink = ctx->outputs[0];
250251 AVFilterChannelLayouts *layouts;
251252 int ret;
252253
253− pan->pure_gains = are_gains_pure(pan);
254254 /* libswr supports any sample and packing formats */
255255 if ((ret = ff_set_common_formats(ctx, ff_all_formats(AVMEDIA_TYPE_AUDIO))) < 0)
256256 return ret;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t