audio: Add public functions to check channel positions validity and to get a reorder map
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Sat, 24 Dec 2011 09:37:28 +0000 (10:37 +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 90b1967..ac7c793 100644 (file)
@@ -943,42 +943,28 @@ gst_audio_buffer_reorder_channels (GstBuffer * buffer,
 }
 
 gboolean
-gst_audio_reorder_channels (gpointer data, gsize size, GstAudioFormat format,
-    gint channels, const GstAudioChannelPosition * from,
-    const GstAudioChannelPosition * to)
+gst_audio_check_valid_channel_positions (const GstAudioChannelPosition *
+    position, gint channels, gboolean force_order)
 {
-  const GstAudioFormatInfo *info;
-  gint i, j, n;
-  gint reorder_map[64] = { 0, };
-  guint8 *ptr;
-  gint bpf, bps;
-  guint8 tmp[64 * 8];
+  return check_valid_channel_positions (position, channels, force_order, NULL);
+}
 
-  info = gst_audio_format_get_info (format);
+gboolean
+gst_audio_get_channel_reorder_map (gint channels,
+    const GstAudioChannelPosition * from, const GstAudioChannelPosition * to,
+    gint * reorder_map)
+{
+  gint i, j;
 
-  g_return_val_if_fail (data != NULL, FALSE);
-  g_return_val_if_fail (from != NULL, FALSE);
-  g_return_val_if_fail (info != NULL && info->width > 0, FALSE);
-  g_return_val_if_fail (info->width > 0, FALSE);
-  g_return_val_if_fail (info->width <= 8 * 64, FALSE);
-  g_return_val_if_fail (size % ((info->width * channels) / 8) != 0, FALSE);
+  g_return_val_if_fail (reorder_map != NULL, FALSE);
   g_return_val_if_fail (channels > 0, FALSE);
-  g_return_val_if_fail (channels <= 64, FALSE);
+  g_return_val_if_fail (from != NULL, FALSE);
   g_return_val_if_fail (to != NULL, FALSE);
   g_return_val_if_fail (check_valid_channel_positions (from, channels, FALSE,
           NULL), FALSE);
   g_return_val_if_fail (check_valid_channel_positions (to, channels, FALSE,
           NULL), FALSE);
 
-  if (size == 0)
-    return TRUE;
-
-  if (memcmp (from, to, channels * sizeof (from[0])) == 0)
-    return TRUE;
-
-  bps = info->width / 8;
-  bpf = bps * channels;
-
   /* Build reorder map and check compatibility */
   for (i = 0; i < channels; i++) {
     if (from[i] == GST_AUDIO_CHANNEL_POSITION_NONE
@@ -1003,6 +989,44 @@ gst_audio_reorder_channels (gpointer data, gsize size, GstAudioFormat format,
       return FALSE;
   }
 
+  return TRUE;
+}
+
+gboolean
+gst_audio_reorder_channels (gpointer data, gsize size, GstAudioFormat format,
+    gint channels, const GstAudioChannelPosition * from,
+    const GstAudioChannelPosition * to)
+{
+  const GstAudioFormatInfo *info;
+  gint i, j, n;
+  gint reorder_map[64] = { 0, };
+  guint8 *ptr;
+  gint bpf, bps;
+  guint8 tmp[64 * 8];
+
+  info = gst_audio_format_get_info (format);
+
+  g_return_val_if_fail (data != NULL, FALSE);
+  g_return_val_if_fail (from != NULL, FALSE);
+  g_return_val_if_fail (to != NULL, FALSE);
+  g_return_val_if_fail (info != NULL && info->width > 0, FALSE);
+  g_return_val_if_fail (info->width > 0, FALSE);
+  g_return_val_if_fail (info->width <= 8 * 64, FALSE);
+  g_return_val_if_fail (size % ((info->width * channels) / 8) != 0, FALSE);
+  g_return_val_if_fail (channels > 0, FALSE);
+  g_return_val_if_fail (channels <= 64, FALSE);
+
+  if (size == 0)
+    return TRUE;
+
+  if (memcmp (from, to, channels * sizeof (from[0])) == 0)
+    return TRUE;
+
+  if (!gst_audio_get_channel_reorder_map (channels, from, to, reorder_map))
+    return FALSE;
+
+  bps = info->width / 8;
+  bpf = bps * channels;
   ptr = data;
 
   n = size / bpf;
index 721e09a..c806818 100644 (file)
@@ -532,6 +532,14 @@ gboolean       gst_audio_reorder_channels        (gpointer data, gsize size,
                                                   const GstAudioChannelPosition * from,
                                                   const GstAudioChannelPosition * to);
 
+gboolean       gst_audio_check_valid_channel_positions (const GstAudioChannelPosition *position,
+                                                        gint channels, gboolean force_order);
+
+gboolean       gst_audio_get_channel_reorder_map (gint channels,
+                                                  const GstAudioChannelPosition * from,
+                                                  const GstAudioChannelPosition * to,
+                                                  gint *reorder_map);
+
 G_END_DECLS
 
 #endif /* __GST_AUDIO_AUDIO_H__ */