[0.11] gst-plugins-ugly: a52dec: Update for the new raw audio caps

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


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

Author: Sebastian Dröge <sebastian.droege at collabora.co.uk>
Date:   Wed Jan  4 16:05:59 2012 +0100

a52dec: Update for the new raw audio caps

---

 ext/a52dec/gsta52dec.c |   44 ++++++++++++++++++++++++--------------------
 ext/a52dec/gsta52dec.h |    3 +++
 2 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/ext/a52dec/gsta52dec.c b/ext/a52dec/gsta52dec.c
index 64ddb09..558eb9b 100644
--- a/ext/a52dec/gsta52dec.c
+++ b/ext/a52dec/gsta52dec.c
@@ -43,7 +43,6 @@
 #include "_stdint.h"
 
 #include <gst/gst.h>
-#include <gst/audio/multichannel.h>
 
 #include <a52dec/a52.h>
 #include <a52dec/mm_accel.h>
@@ -84,6 +83,7 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
     GST_PAD_ALWAYS,
     GST_STATIC_CAPS ("audio/x-raw, "
         "format = (string) " SAMPLE_FORMAT ", "
+        "layout = (string) interleaved, "
         "rate = (int) [ 4000, 96000 ], " "channels = (int) [ 1, 6 ]")
     );
 
@@ -231,21 +231,14 @@ gst_a52dec_init (GstA52Dec * a52dec)
 }
 
 static gint
-gst_a52dec_channels (int flags, GstAudioChannelPosition ** _pos)
+gst_a52dec_channels (int flags, GstAudioChannelPosition * pos)
 {
   gint chans = 0;
-  GstAudioChannelPosition *pos = NULL;
-
-  /* allocated just for safety. Number makes no sense */
-  if (_pos) {
-    pos = g_new (GstAudioChannelPosition, 6);
-    *_pos = pos;
-  }
 
   if (flags & A52_LFE) {
     chans += 1;
     if (pos) {
-      pos[0] = GST_AUDIO_CHANNEL_POSITION_LFE;
+      pos[0] = GST_AUDIO_CHANNEL_POSITION_LFE1;
     }
   }
   flags &= A52_CHANNEL_MASK;
@@ -305,13 +298,12 @@ gst_a52dec_channels (int flags, GstAudioChannelPosition ** _pos)
       break;
     case A52_MONO:
       if (pos) {
-        pos[0 + chans] = GST_AUDIO_CHANNEL_POSITION_FRONT_MONO;
+        pos[0 + chans] = GST_AUDIO_CHANNEL_POSITION_MONO;
       }
       chans += 1;
       break;
     default:
       /* error, caller should post error message */
-      g_free (pos);
       return 0;
   }
 
@@ -381,6 +373,9 @@ gst_a52dec_push (GstA52Dec * a52dec,
       data[n * chans + c] = samples[c * 256 + n];
     }
   }
+  gst_audio_reorder_channels (data, 256 * chans * (SAMPLE_WIDTH / 8),
+      (SAMPLE_WIDTH == 64) ? GST_AUDIO_FORMAT_F64 : GST_AUDIO_FORMAT_F32, chans,
+      a52dec->from, a52dec->to);
   gst_buffer_unmap (buf, data, -1);
 
   GST_BUFFER_TIMESTAMP (buf) = timestamp;
@@ -423,23 +418,36 @@ no_channels:
 static gboolean
 gst_a52dec_reneg (GstA52Dec * a52dec, GstPad * pad)
 {
-  GstAudioChannelPosition *pos;
-  gint channels = gst_a52dec_channels (a52dec->using_channels, &pos);
+  gint channels;
   GstCaps *caps = NULL;
   gboolean result = FALSE;
 
+  channels = gst_a52dec_channels (a52dec->using_channels, a52dec->from);
+
   if (!channels)
     goto done;
 
   GST_INFO_OBJECT (a52dec, "reneg channels:%d rate:%d",
       channels, a52dec->sample_rate);
 
+  memcpy (a52dec->to, a52dec->from, sizeof (a52dec->from));
+  gst_audio_channel_positions_to_valid_order (a52dec->to, channels);
+
   caps = gst_caps_new_simple ("audio/x-raw",
       "format", G_TYPE_STRING, SAMPLE_FORMAT,
+      "layout", G_TYPE_STRING, "interleaved",
       "channels", G_TYPE_INT, channels,
       "rate", G_TYPE_INT, a52dec->sample_rate, NULL);
-  gst_audio_set_channel_positions (gst_caps_get_structure (caps, 0), pos);
-  g_free (pos);
+
+  if (channels > 1) {
+    guint64 channel_mask = 0;
+    gint i;
+
+    for (i = 0; i < channels; i++)
+      channel_mask |= G_GUINT64_CONSTANT (1) << a52dec->to[i];
+    gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, channel_mask,
+        NULL);
+  }
 
   if (!gst_pad_set_caps (pad, caps))
     goto done;
@@ -977,10 +985,6 @@ plugin_init (GstPlugin * plugin)
   orc_init ();
 #endif
 
-  /* ensure GstAudioChannelPosition type is registered */
-  if (!gst_audio_channel_position_get_type ())
-    return FALSE;
-
   if (!gst_element_register (plugin, "a52dec", GST_RANK_SECONDARY,
           GST_TYPE_A52DEC))
     return FALSE;
diff --git a/ext/a52dec/gsta52dec.h b/ext/a52dec/gsta52dec.h
index e575b81..4508a82 100644
--- a/ext/a52dec/gsta52dec.h
+++ b/ext/a52dec/gsta52dec.h
@@ -22,6 +22,7 @@
 #define __GST_A52DEC_H__
 
 #include <gst/gst.h>
+#include <gst/audio/audio.h>
 
 G_BEGIN_DECLS
 
@@ -60,6 +61,8 @@ struct _GstA52Dec {
   int            request_channels;
   int            using_channels;
 
+  GstAudioChannelPosition from[6], to[6];
+
   sample_t       level;
   sample_t       bias;
   gboolean       dynamic_range_compression;



More information about the gstreamer-commits mailing list