[FFmpeg-devel] [PATCH] af_pan: Separate layout from the args list

Michael Niedermayer michaelni at gmx.at
Tue Apr 30 00:03:17 CEST 2013


Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libavfilter/af_pan.c   |   11 +++++++----
 libavfilter/avfilter.c |    3 ++-
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/libavfilter/af_pan.c b/libavfilter/af_pan.c
index 800c40a..90bedac 100644
--- a/libavfilter/af_pan.c
+++ b/libavfilter/af_pan.c
@@ -41,6 +41,7 @@
 
 typedef struct PanContext {
     const AVClass *class;
+    char *layout;
     char *args;
     int64_t out_channel_layout;
     double gain[MAX_CHANNELS][MAX_CHANNELS];
@@ -103,11 +104,12 @@ static av_cold int init(AVFilterContext *ctx)
 {
     PanContext *const pan = ctx->priv;
     char *arg, *arg0, *tokenizer, *args = av_strdup(pan->args);
+    char *tokarg = args;
     int out_ch_id, in_ch_id, len, named, ret;
     int nb_in_channels[2] = { 0, 0 }; // number of unnamed and named input channels
     double gain;
 
-    if (!pan->args) {
+    if (!pan->args || !pan->layout) {
         av_log(ctx, AV_LOG_ERROR,
                "pan filter needs a channel layout and a set "
                "of channels definitions as parameter\n");
@@ -115,14 +117,14 @@ static av_cold int init(AVFilterContext *ctx)
     }
     if (!args)
         return AVERROR(ENOMEM);
-    arg = av_strtok(args, "|", &tokenizer);
-    ret = ff_parse_channel_layout(&pan->out_channel_layout, arg, ctx);
+    ret = ff_parse_channel_layout(&pan->out_channel_layout, pan->layout, ctx);
     if (ret < 0)
         goto fail;
     pan->nb_output_channels = av_get_channel_layout_nb_channels(pan->out_channel_layout);
 
     /* parse channel specifications */
-    while ((arg = arg0 = av_strtok(NULL, "|", &tokenizer))) {
+    while ((arg = arg0 = av_strtok(tokarg, "|", &tokenizer))) {
+        tokarg = NULL;
         /* channel name */
         if (parse_channel_name(&arg, &out_ch_id, &named)) {
             av_log(ctx, AV_LOG_ERROR,
@@ -385,6 +387,7 @@ static av_cold void uninit(AVFilterContext *ctx)
 #define OFFSET(x) offsetof(PanContext, x)
 
 static const AVOption pan_options[] = {
+    { "layout", NULL, OFFSET(layout), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM },
     { "args", NULL, OFFSET(args), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM },
     { NULL }
 };
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 06d92b2..f8da140 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -820,7 +820,8 @@ int avfilter_init_str(AVFilterContext *filter, const char *args)
             }
 
             if (!strcmp(filter->filter->name, "frei0r") ||
-                !strcmp(filter->filter->name, "ocv"))
+                !strcmp(filter->filter->name, "ocv") ||
+                !strcmp(filter->filter->name, "pan"))
                 nb_leading = 1;
             else if (!strcmp(filter->filter->name, "frei0r_src"))
                 nb_leading = 3;
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list