It is not supposed to have any side effects, and the modification in question can just as well be done in filter init.
Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -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 | ||
| 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 | |||
| 94 | static av_cold int init(AVFilterContext *ctx) | 116 | static 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; |
| 218 | fail: | 241 | fail: |
| @@ -220,37 +243,14 @@ fail: · 1 unmodified line | |||
| 220 | return ret; | 243 | return ret; |
| 221 | } | 244 | } |
| 222 | 245 | ||
| 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 | |||
| 245 | static int query_formats(AVFilterContext *ctx) | 246 | static 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; |