[FFmpeg-devel] [PATCH 7/7] avutil/channel_layout: add specific text versions for unknown and unused channels

Marton Balint cus at passwd.hu
Sat Mar 9 23:54:14 EET 2024


Signed-off-by: Marton Balint <cus at passwd.hu>
---
 libavutil/channel_layout.c       | 13 +++++++++++++
 libavutil/tests/channel_layout.c |  2 ++
 tests/ref/fate/channel_layout    |  4 +++-
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c
index 9e8a1c12e6..a83618bcc7 100644
--- a/libavutil/channel_layout.c
+++ b/libavutil/channel_layout.c
@@ -86,6 +86,10 @@ void av_channel_name_bprint(AVBPrint *bp, enum AVChannel channel_id)
         av_bprintf(bp, "%s", channel_names[channel_id].name);
     else if (channel_id == AV_CHAN_NONE)
         av_bprintf(bp, "NONE");
+    else if (channel_id == AV_CHAN_UNKNOWN)
+        av_bprintf(bp, "UNK");
+    else if (channel_id == AV_CHAN_UNUSED)
+        av_bprintf(bp, "UNSD");
     else
         av_bprintf(bp, "USR%d", channel_id);
 }
@@ -115,6 +119,10 @@ void av_channel_description_bprint(AVBPrint *bp, enum AVChannel channel_id)
         av_bprintf(bp, "%s", channel_names[channel_id].description);
     else if (channel_id == AV_CHAN_NONE)
         av_bprintf(bp, "none");
+    else if (channel_id == AV_CHAN_UNKNOWN)
+        av_bprintf(bp, "unknown");
+    else if (channel_id == AV_CHAN_UNUSED)
+        av_bprintf(bp, "unused");
     else
         av_bprintf(bp, "user %d", channel_id);
 }
@@ -151,6 +159,11 @@ enum AVChannel av_channel_from_string(const char *str)
         if (channel_names[i].name && !strcmp(str, channel_names[i].name))
             return i;
     }
+    if (!strcmp(str, "UNK"))
+        return AV_CHAN_UNKNOWN;
+    if (!strcmp(str, "UNSD"))
+        return AV_CHAN_UNUSED;
+
     if (!strncmp(str, "USR", 3)) {
         const char *p = str + 3;
         id = strtol(p, &endptr, 0);
diff --git a/libavutil/tests/channel_layout.c b/libavutil/tests/channel_layout.c
index 14d36c71b5..8132b83434 100644
--- a/libavutil/tests/channel_layout.c
+++ b/libavutil/tests/channel_layout.c
@@ -348,6 +348,8 @@ int main(void)
     CHANNEL_LAYOUT_FROM_STRING("Dummy at FL");
     CHANNEL_LAYOUT_FROM_STRING("FR+Dummy");
     CHANNEL_LAYOUT_FROM_STRING("FR+Dummy at FL");
+    CHANNEL_LAYOUT_FROM_STRING("UNK+UNSD");
+    CHANNEL_LAYOUT_FROM_STRING("NONE");
     CHANNEL_LAYOUT_FROM_STRING("FR+ at FL");
     CHANNEL_LAYOUT_FROM_STRING("FL+@");
     CHANNEL_LAYOUT_FROM_STRING("FR+FL at Foo+USR63@Foo");
diff --git a/tests/ref/fate/channel_layout b/tests/ref/fate/channel_layout
index 117a5fd84d..0bcfefce3b 100644
--- a/tests/ref/fate/channel_layout
+++ b/tests/ref/fate/channel_layout
@@ -148,6 +148,8 @@ With "Dummy":                                                        fail
 With "Dummy at FL":                                                     fail
 With "FR+Dummy":                                                     fail
 With "FR+Dummy at FL":                                                  fail
+With "UNK+UNSD":                                    2 channels (UNK+UNSD)
+With "NONE":                                                         fail
 With "FR+ at FL":                                                       fail
 With "FL+@":                                                         fail
 With "FR+FL at Foo+USR63@Foo":              3 channels (FR+FL at Foo+USR63@Foo)
@@ -236,5 +238,5 @@ With "ambisonic 2+stereo": AMBI   (ambisonic 2+stereo)
 With "2C": UNSPEC (2 channels)
   == UNSPEC (2 channels)
   != NATIVE
-  == CUSTOM (2 channels (USR768+USR768))
+  == CUSTOM (2 channels (UNK+UNK))
   != AMBI
-- 
2.35.3



More information about the ffmpeg-devel mailing list