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

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
91 return AVERROR(EINVAL);91 return AVERROR(EINVAL);
92}92}
93 93
94static 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
94static av_cold int init(AVFilterContext *ctx)116static av_cold int init(AVFilterContext *ctx)
95{117{
96 PanContext *const pan = ctx->priv;118 PanContext *const pan = ctx->priv;
@@ -213,6 +235,7 @@ static av_cold int init(AVFilterContext *ctx) · 116 unmodified lines
213 }235 }
214 }236 }
215 pan->need_renumber = !!nb_in_channels[1];237 pan->need_renumber = !!nb_in_channels[1];
238 pan->pure_gains = are_gains_pure(pan);
216 239
217 ret = 0;240 ret = 0;
218fail:241fail:
@@ -220,37 +243,14 @@ fail: · 1 unmodified line
220 return ret;243 return ret;
221}244}
222 245
223static 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
245static int query_formats(AVFilterContext *ctx)246static int query_formats(AVFilterContext *ctx)
246{247{
247 PanContext *pan = ctx->priv;248 const PanContext *pan = ctx->priv;
248 AVFilterLink *inlink = ctx->inputs[0];249 AVFilterLink *inlink = ctx->inputs[0];
249 AVFilterLink *outlink = ctx->outputs[0];250 AVFilterLink *outlink = ctx->outputs[0];
250 AVFilterChannelLayouts *layouts;251 AVFilterChannelLayouts *layouts;
251 int ret;252 int ret;
252 253
253 pan->pure_gains = are_gains_pure(pan);
254 /* libswr supports any sample and packing formats */254 /* libswr supports any sample and packing formats */
255 if ((ret = ff_set_common_formats(ctx, ff_all_formats(AVMEDIA_TYPE_AUDIO))) < 0)255 if ((ret = ff_set_common_formats(ctx, ff_all_formats(AVMEDIA_TYPE_AUDIO))) < 0)
256 return ret;256 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