[0.11] gst-plugins-base: audio: Add function to reorder channel positions from any order to the GStreamer order

Sebastian Dröge slomo at kemper.freedesktop.org
Thu Jan 5 01:36:01 PST 2012


Module: gst-plugins-base
Branch: 0.11
Commit: e2c6b8ec4d04520ae5329da2cf3a7b3bb9d7a40e
URL:    http://cgit.freedesktop.org/gstreamer/gst-plugins-base/commit/?id=e2c6b8ec4d04520ae5329da2cf3a7b3bb9d7a40e

Author: Sebastian Dröge <sebastian.droege at collabora.co.uk>
Date:   Sat Dec 31 13:33:01 2011 +0100

audio: Add function to reorder channel positions from any order to the GStreamer order

---

 gst-libs/gst/audio/audio.c |   45 ++++++++++++++++++++++++++++++++++++++++++++
 gst-libs/gst/audio/audio.h |    3 ++
 2 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/gst-libs/gst/audio/audio.c b/gst-libs/gst/audio/audio.c
index 8e0de02..e8c62ba 100644
--- a/gst-libs/gst/audio/audio.c
+++ b/gst-libs/gst/audio/audio.c
@@ -1103,3 +1103,48 @@ gst_audio_get_channel_reorder_map (gint channels,
 
   return TRUE;
 }
+
+/**
+ * gst_audio_channel_positions_to_valid_order:
+ * @position: The channel positions to reorder to.
+ * @channels: The number of channels.
+ *
+ * Reorders the channel positions in @position from any order to
+ * the GStreamer channel order.
+ *
+ * Returns: %TRUE if the channel positions are valid and reordering
+ * was successful.
+ */
+gboolean
+gst_audio_channel_positions_to_valid_order (GstAudioChannelPosition * position,
+    gint channels)
+{
+  GstAudioChannelPosition tmp[64];
+  guint64 channel_mask = 0;
+  gint i, j;
+
+  g_return_val_if_fail (channels > 0, FALSE);
+  g_return_val_if_fail (position != NULL, FALSE);
+  g_return_val_if_fail (check_valid_channel_positions (position, channels,
+          FALSE, NULL), FALSE);
+
+  if (channels == 1 && position[0] == GST_AUDIO_CHANNEL_POSITION_MONO)
+    return TRUE;
+  if (position[0] == GST_AUDIO_CHANNEL_POSITION_NONE)
+    return TRUE;
+
+  check_valid_channel_positions (position, channels, FALSE, &channel_mask);
+
+  memset (tmp, 0xff, sizeof (tmp));
+  j = 0;
+  for (i = 0; i < 64; i++) {
+    if ((channel_mask & (G_GUINT64_CONSTANT (1) << i))) {
+      tmp[j] = i;
+      j++;
+    }
+  }
+
+  memcpy (position, tmp, sizeof (tmp[0]) * channels);
+
+  return TRUE;
+}
diff --git a/gst-libs/gst/audio/audio.h b/gst-libs/gst/audio/audio.h
index c806818..f2e4522 100644
--- a/gst-libs/gst/audio/audio.h
+++ b/gst-libs/gst/audio/audio.h
@@ -532,6 +532,9 @@ gboolean       gst_audio_reorder_channels        (gpointer data, gsize size,
                                                   const GstAudioChannelPosition * from,
                                                   const GstAudioChannelPosition * to);
 
+gboolean       gst_audio_channel_positions_to_valid_order (GstAudioChannelPosition *position,
+                                                           gint channels);
+
 gboolean       gst_audio_check_valid_channel_positions (const GstAudioChannelPosition *position,
                                                         gint channels, gboolean force_order);
 



More information about the gstreamer-commits mailing list