Browse code

lavfi: parsing helper for unknown channel layouts.

Make ff_parse_channel_layout() accept unknown layouts too.

Nicolas George authored on 2013/10/25 22:07:40
Showing 6 changed files
... ...
@@ -66,7 +66,7 @@ static av_cold int init(AVFilterContext *ctx)
66 66
         (ret = ff_parse_sample_format(&aconvert->out_sample_fmt, aconvert->format_str, ctx)) < 0)
67 67
         return ret;
68 68
     if (aconvert->channel_layout_str && strcmp(aconvert->channel_layout_str, "auto"))
69
-        return ff_parse_channel_layout(&aconvert->out_chlayout, aconvert->channel_layout_str, ctx);
69
+        return ff_parse_channel_layout(&aconvert->out_chlayout, NULL, aconvert->channel_layout_str, ctx);
70 70
     return ret;
71 71
 }
72 72
 
... ...
@@ -116,7 +116,7 @@ static av_cold int init(AVFilterContext *ctx)
116 116
     if (!args)
117 117
         return AVERROR(ENOMEM);
118 118
     arg = av_strtok(args, "|", &tokenizer);
119
-    ret = ff_parse_channel_layout(&pan->out_channel_layout, arg, ctx);
119
+    ret = ff_parse_channel_layout(&pan->out_channel_layout, NULL, arg, ctx);
120 120
     if (ret < 0)
121 121
         goto fail;
122 122
     pan->nb_output_channels = av_get_channel_layout_nb_channels(pan->out_channel_layout);
... ...
@@ -109,7 +109,7 @@ static av_cold int init(AVFilterContext *ctx)
109 109
 
110 110
     if (eval->chlayout_str) {
111 111
         int n;
112
-        ret = ff_parse_channel_layout(&eval->chlayout, eval->chlayout_str, ctx);
112
+        ret = ff_parse_channel_layout(&eval->chlayout, NULL, eval->chlayout_str, ctx);
113 113
         if (ret < 0)
114 114
             goto end;
115 115
 
... ...
@@ -68,7 +68,7 @@ static av_cold int init(AVFilterContext *ctx)
68 68
                                      null->sample_rate_str, ctx)) < 0)
69 69
         return ret;
70 70
 
71
-    if ((ret = ff_parse_channel_layout(&null->channel_layout,
71
+    if ((ret = ff_parse_channel_layout(&null->channel_layout, NULL,
72 72
                                         null->channel_layout_str, ctx)) < 0)
73 73
         return ret;
74 74
 
... ...
@@ -615,10 +615,21 @@ int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx)
615 615
     return 0;
616 616
 }
617 617
 
618
-int ff_parse_channel_layout(int64_t *ret, const char *arg, void *log_ctx)
618
+int ff_parse_channel_layout(int64_t *ret, int *nret, const char *arg,
619
+                            void *log_ctx)
619 620
 {
620 621
     char *tail;
621
-    int64_t chlayout = av_get_channel_layout(arg);
622
+    int64_t chlayout, count;
623
+
624
+    if (nret) {
625
+        count = strtol(arg, &tail, 10);
626
+        if (*tail == 'c' && !tail[1] && count > 0 && count < 63) {
627
+            *nret = count;
628
+            *ret = 0;
629
+            return 0;
630
+        }
631
+    }
632
+    chlayout = av_get_channel_layout(arg);
622 633
     if (chlayout == 0) {
623 634
         chlayout = strtol(arg, &tail, 10);
624 635
         if (*tail || chlayout == 0) {
... ...
@@ -627,6 +638,8 @@ int ff_parse_channel_layout(int64_t *ret, const char *arg, void *log_ctx)
627 627
         }
628 628
     }
629 629
     *ret = chlayout;
630
+    if (nret)
631
+        *nret = av_get_channel_layout_nb_channels(chlayout);
630 632
     return 0;
631 633
 }
632 634
 
... ...
@@ -207,11 +207,14 @@ int ff_parse_sample_format(int *ret, const char *arg, void *log_ctx);
207 207
  * Parse a channel layout or a corresponding integer representation.
208 208
  *
209 209
  * @param ret 64bit integer pointer to where the value should be written.
210
+ * @param nret integer pointer to the number of channels;
211
+ *             if not NULL, then unknown channel layouts are accepted
210 212
  * @param arg string to parse
211 213
  * @param log_ctx log context
212 214
  * @return >= 0 in case of success, a negative AVERROR code on error
213 215
  */
214
-int ff_parse_channel_layout(int64_t *ret, const char *arg, void *log_ctx);
216
+int ff_parse_channel_layout(int64_t *ret, int *nret, const char *arg,
217
+                            void *log_ctx);
215 218
 
216 219
 void ff_update_link_current_pts(AVFilterLink *link, int64_t pts);
217 220