audio: Add function to reorder channel positions from any order to the GStreamer...
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Sat, 31 Dec 2011 12:33:01 +0000 (13:33 +0100)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Thu, 5 Jan 2012 09:34:24 +0000 (10:34 +0100)
gst-libs/gst/audio/audio.c
gst-libs/gst/audio/audio.h

index 8e0de022aa2354ef6779c8cb5bb3bab9093691a3..e8c62bab74a49f99b5c5edf15bf12b755df0ab97 100644 (file)
@@ -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;
+}
index c8068184d8dec4158bdfc09458f4187254f6c346..f2e45224f54297eae873c83e6a30f12cc8f6c2bc 100644 (file)
@@ -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);