]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/af_pan.c
avfilter/af_dynaudnorm: fix hang with too short input
[ffmpeg] / libavfilter / af_pan.c
index 1eb102c10a4897e13fa9d1fefee98e35d9a6e8e3..94f15876f5f16068c1058783d31d93cd4fdf9607 100644 (file)
@@ -102,14 +102,14 @@ static av_cold int init(AVFilterContext *ctx)
 {
     PanContext *const pan = ctx->priv;
     char *arg, *arg0, *tokenizer, *args = av_strdup(pan->args);
-    int out_ch_id, in_ch_id, len, named, ret;
+    int out_ch_id, in_ch_id, len, named, ret, sign = 1;
     int nb_in_channels[2] = { 0, 0 }; // number of unnamed and named input channels
     double gain;
 
     if (!pan->args) {
         av_log(ctx, AV_LOG_ERROR,
                "pan filter needs a channel layout and a set "
-               "of channels definitions as parameter\n");
+               "of channel definitions as parameter\n");
         return AVERROR(EINVAL);
     }
     if (!args)
@@ -178,14 +178,18 @@ static av_cold int init(AVFilterContext *ctx)
                 ret = AVERROR(EINVAL);
                 goto fail;
             }
-            pan->gain[out_ch_id][in_ch_id] = gain;
+            pan->gain[out_ch_id][in_ch_id] = sign * gain;
             skip_spaces(&arg);
             if (!*arg)
                 break;
-            if (*arg != '+') {
+            if (*arg == '-') {
+                sign = -1;
+            } else if (*arg != '+') {
                 av_log(ctx, AV_LOG_ERROR, "Syntax error near \"%.8s\"\n", arg);
                 ret = AVERROR(EINVAL);
                 goto fail;
+            } else {
+                sign = 1;
             }
             arg++;
         }
@@ -276,7 +280,7 @@ static int config_props(AVFilterLink *link)
     if (link->channels > MAX_CHANNELS ||
         pan->nb_output_channels > MAX_CHANNELS) {
         av_log(ctx, AV_LOG_ERROR,
-               "af_pan support a maximum of %d channels. "
+               "af_pan supports a maximum of %d channels. "
                "Feel free to ask for a higher limit.\n", MAX_CHANNELS);
         return AVERROR_PATCHWELCOME;
     }
@@ -322,7 +326,7 @@ static int config_props(AVFilterLink *link)
                 continue;
             t = 0;
             for (j = 0; j < link->channels; j++)
-                t += pan->gain[i][j];
+                t += fabs(pan->gain[i][j]);
             if (t > -1E-5 && t < 1E-5) {
                 // t is almost 0 but not exactly, this is probably a mistake
                 if (t)