[0.11] gst-plugins-base: audio: Add public functions to check channel positions validity and to get a reorder map

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


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

Author: Sebastian Dröge <sebastian.droege at collabora.co.uk>
Date:   Sat Dec 24 10:37:28 2011 +0100

audio: Add public functions to check channel positions validity and to get a reorder map

---

 gst-libs/gst/audio/audio.c |   76 +++++++++++++++++++++++++++++---------------
 gst-libs/gst/audio/audio.h |    8 +++++
 2 files changed, 58 insertions(+), 26 deletions(-)

diff --git a/gst-libs/gst/audio/audio.c b/gst-libs/gst/audio/audio.c
index 90b1967..ac7c793 100644
--- a/gst-libs/gst/audio/audio.c
+++ b/gst-libs/gst/audio/audio.c
@@ -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;
diff --git a/gst-libs/gst/audio/audio.h b/gst-libs/gst/audio/audio.h
index 721e09a..c806818 100644
--- a/gst-libs/gst/audio/audio.h
+++ b/gst-libs/gst/audio/audio.h
@@ -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__ */



More information about the gstreamer-commits mailing list