audioconvert: add a function for extracting the channel with the given index
authorAnton Khirnov <anton@khirnov.net>
Mon, 28 May 2012 10:20:57 +0000 (12:20 +0200)
committerAnton Khirnov <anton@khirnov.net>
Sun, 10 Jun 2012 06:03:45 +0000 (08:03 +0200)
libavutil/audioconvert.c
libavutil/audioconvert.h

index 36d07ee..1ac63a3 100644 (file)
@@ -213,3 +213,17 @@ const char *av_get_channel_name(uint64_t channel)
             return get_channel_name(i);
     return NULL;
 }
+
+uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index)
+{
+    int i;
+
+    if (av_get_channel_layout_nb_channels(channel_layout) <= index)
+        return 0;
+
+    for (i = 0; i < 64; i++) {
+        if ((1ULL << i) & channel_layout && !index--)
+            return 1ULL << i;
+    }
+    return 0;
+}
index e516ae8..691c64a 100644 (file)
@@ -155,6 +155,11 @@ uint64_t av_get_default_channel_layout(int nb_channels);
 int av_get_channel_layout_channel_index(uint64_t channel_layout,
                                         uint64_t channel);
 
+/**
+ * Get the channel with the given index in channel_layout.
+ */
+uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index);
+
 /**
  * Get the name of a given channel.
  *