audioconvert: add a function for getting channel's index in layout
authorAnton Khirnov <anton@khirnov.net>
Mon, 28 May 2012 06:16:40 +0000 (08:16 +0200)
committerAnton Khirnov <anton@khirnov.net>
Sun, 10 Jun 2012 06:02:18 +0000 (08:02 +0200)
libavutil/audioconvert.c
libavutil/audioconvert.h

index 1a8e5ee..9e2f812 100644 (file)
@@ -192,3 +192,13 @@ uint64_t av_get_default_channel_layout(int nb_channels)
     default: return 0;
     }
 }
+
+int av_get_channel_layout_channel_index(uint64_t channel_layout,
+                                        uint64_t channel)
+{
+    if (!(channel_layout & channel) ||
+        av_get_channel_layout_nb_channels(channel) != 1)
+        return AVERROR(EINVAL);
+    channel_layout &= channel - 1;
+    return av_get_channel_layout_nb_channels(channel_layout);
+}
index 35a1a08..6f6b444 100644 (file)
@@ -144,6 +144,18 @@ int av_get_channel_layout_nb_channels(uint64_t channel_layout);
 uint64_t av_get_default_channel_layout(int nb_channels);
 
 /**
+ * Get the index of a channel in channel_layout.
+ *
+ * @param channel a channel layout describing exactly one channel which must be
+ *                present in channel_layout.
+ *
+ * @return index of channel in channel_layout on success, a negative AVERROR
+ *         on error.
+ */
+int av_get_channel_layout_channel_index(uint64_t channel_layout,
+                                        uint64_t channel);
+
+/**
  * @}
  */