]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/formats.c
Merge commit '441e8ae5efd681055e5af6f4317fb60110de9dd0'
[ffmpeg] / libavfilter / formats.c
index 4f9773bd1515334ab672372b290d5bed8cae4422..8758b3d113138a311e78a3e0ab2e08bf210c82f8 100644 (file)
@@ -637,23 +637,20 @@ int ff_parse_channel_layout(int64_t *ret, int *nret, const char *arg,
                             void *log_ctx)
 {
     char *tail;
-    int64_t chlayout, count;
+    int64_t chlayout;
 
-    if (nret) {
-        count = strtol(arg, &tail, 10);
-        if (*tail == 'c' && !tail[1] && count > 0 && count < 63) {
-            *nret = count;
-            *ret = 0;
-            return 0;
-        }
-    }
     chlayout = av_get_channel_layout(arg);
     if (chlayout == 0) {
         chlayout = strtol(arg, &tail, 10);
-        if (*tail || chlayout == 0) {
+        if (!(*tail == '\0' || *tail == 'c' && *(tail + 1) == '\0') || chlayout <= 0 || chlayout > 63) {
             av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg);
             return AVERROR(EINVAL);
         }
+        if (nret) {
+            *nret = chlayout;
+            *ret = 0;
+            return 0;
+        }
     }
     *ret = chlayout;
     if (nret)
@@ -669,12 +666,41 @@ int main(void)
 {
     const int64_t *cl;
     char buf[512];
+    int i;
+    const char *teststrings[] ={
+        "blah",
+        "1",
+        "2",
+        "-1",
+        "60",
+        "65",
+        "1c",
+        "2c",
+        "-1c",
+        "60c",
+        "65c",
+        "5.1",
+        "stereo",
+        "1+1+1+1",
+        "1c+1c+1c+1c",
+        "2c+1c",
+        "0x3",
+    };
 
     for (cl = avfilter_all_channel_layouts; *cl != -1; cl++) {
         av_get_channel_layout_string(buf, sizeof(buf), -1, *cl);
         printf("%s\n", buf);
     }
 
+    for ( i = 0; i<FF_ARRAY_ELEMS(teststrings); i++) {
+        int64_t layout = -1;
+        int count = -1;
+        int ret;
+        ret = ff_parse_channel_layout(&layout, &count, teststrings[i], NULL);
+
+        printf ("%d = ff_parse_channel_layout(%016"PRIX64", %2d, %s);\n", ret ? -1 : 0, layout, count, teststrings[i]);
+    }
+
     return 0;
 }