[0.11] gst-plugins-bad: adpcmenc: port to 0.11

Mark Nauwelaerts mnauw at kemper.freedesktop.org
Thu Jan 26 15:32:48 PST 2012


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

Author: Mark Nauwelaerts <mark.nauwelaerts at collabora.co.uk>
Date:   Thu Jan 26 23:28:20 2012 +0100

adpcmenc: port to 0.11

---

 configure.ac            |    2 +-
 gst/adpcmdec/adpcmdec.c |   44 ++++++++++++++++-----------------------
 gst/adpcmenc/adpcmenc.c |   52 ++++++++++++++++++++++++----------------------
 3 files changed, 46 insertions(+), 52 deletions(-)

diff --git a/configure.ac b/configure.ac
index cb38343..d5db052 100644
--- a/configure.ac
+++ b/configure.ac
@@ -313,7 +313,7 @@ AG_GST_DEFAULT_ELEMENTS
 dnl *** plug-ins to include ***
 dnl Non ported plugins (non-dependant, then dependant)
 dnl Make sure you have a space before and after all plugins
-GST_PLUGINS_NONPORTED=" adpcmdec adpcmenc aiff asfmux \
+GST_PLUGINS_NONPORTED=" adpcmdec aiff asfmux \
  camerabin cdxaparse coloreffects \
  dccp debugutils faceoverlay festival \
  fieldanalysis freeverb freeze frei0r gaudieffects geometrictransform h264parse \
diff --git a/gst/adpcmdec/adpcmdec.c b/gst/adpcmdec/adpcmdec.c
index c6eb749..3e22b51 100644
--- a/gst/adpcmdec/adpcmdec.c
+++ b/gst/adpcmdec/adpcmdec.c
@@ -53,12 +53,10 @@ static GstStaticPadTemplate adpcmdec_src_template =
 GST_STATIC_PAD_TEMPLATE ("src",
     GST_PAD_SRC,
     GST_PAD_ALWAYS,
-    GST_STATIC_CAPS ("audio/x-raw-int, "
-        "depth = (int)16, "
-        "width = (int)16, "
-        "endianness = (int)" G_STRINGIFY (G_BYTE_ORDER) ", "
-        "signed = (boolean)TRUE, "
-        "channels = (int) [1,2], " "rate = (int)[1, MAX]")
+    GST_STATIC_CAPS ("audio/x-raw, "
+        "format = (string) " GST_AUDIO_NE (S16) ", "
+        "layout = (string) interleaved, "
+        "rate = (int) [1, MAX], channels = (int) [1,2]")
     );
 
 enum adpcm_layout
@@ -83,7 +81,7 @@ typedef struct _ADPCMDec
 } ADPCMDec;
 
 GType adpcmdec_get_type (void);
-GST_BOILERPLATE (ADPCMDec, adpcmdec, GstAudioDecoder, GST_TYPE_AUDIO_DECODER);
+G_DEFINE_TYPE (ADPCMDec, adpcmdec, GST_TYPE_AUDIO_DECODER);
 
 static gboolean
 adpcmdec_set_format (GstAudioDecoder * bdec, GstCaps * in_caps)
@@ -112,15 +110,13 @@ adpcmdec_set_format (GstAudioDecoder * bdec, GstCaps * in_caps)
   if (!gst_structure_get_int (structure, "channels", &dec->channels))
     return FALSE;
 
-  caps = gst_caps_new_simple ("audio/x-raw-int",
+  caps = gst_caps_new_simple ("audio/x-raw",
+      "format", G_TYPE_STRING, GST_AUDIO_NE (S16),
+      "layout", G_TYPE_STRING, "interleaved",
       "rate", G_TYPE_INT, dec->rate,
-      "channels", G_TYPE_INT, dec->channels,
-      "width", G_TYPE_INT, 16,
-      "depth", G_TYPE_INT, 16,
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "signed", G_TYPE_BOOLEAN, TRUE, NULL);
+      "channels", G_TYPE_INT, dec->channels, NULL);
 
-  gst_pad_set_caps (GST_AUDIO_DECODER_SRC_PAD (bdec), caps);
+  gst_audio_decoder_set_outcaps (bdec, caps);
   gst_caps_unref (caps);
 
   return TRUE;
@@ -457,26 +453,16 @@ adpcmdec_stop (GstAudioDecoder * dec)
 }
 
 static void
-adpcmdec_init (ADPCMDec * dec, ADPCMDecClass * klass)
+adpcmdec_init (ADPCMDec * dec)
 {
 }
 
 static void
 adpcmdec_class_init (ADPCMDecClass * klass)
 {
+  GstElementClass *element_class = (GstElementClass *) klass;
   GstAudioDecoderClass *base_class = (GstAudioDecoderClass *) klass;
 
-  base_class->start = GST_DEBUG_FUNCPTR (adpcmdec_start);
-  base_class->stop = GST_DEBUG_FUNCPTR (adpcmdec_stop);
-  base_class->set_format = GST_DEBUG_FUNCPTR (adpcmdec_set_format);
-  base_class->parse = GST_DEBUG_FUNCPTR (adpcmdec_parse);
-  base_class->handle_frame = GST_DEBUG_FUNCPTR (adpcmdec_handle_frame);
-}
-
-static void
-adpcmdec_base_init (gpointer klass)
-{
-  GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
   gst_element_class_add_pad_template (element_class,
       gst_static_pad_template_get (&adpcmdec_sink_template));
   gst_element_class_add_pad_template (element_class,
@@ -485,6 +471,12 @@ adpcmdec_base_init (gpointer klass)
       "Codec/Decoder/Audio",
       "Decode MS and IMA ADPCM audio",
       "Pioneers of the Inevitable <songbird at songbirdnest.com>");
+
+  base_class->start = GST_DEBUG_FUNCPTR (adpcmdec_start);
+  base_class->stop = GST_DEBUG_FUNCPTR (adpcmdec_stop);
+  base_class->set_format = GST_DEBUG_FUNCPTR (adpcmdec_set_format);
+  base_class->parse = GST_DEBUG_FUNCPTR (adpcmdec_parse);
+  base_class->handle_frame = GST_DEBUG_FUNCPTR (adpcmdec_handle_frame);
 }
 
 static gboolean
diff --git a/gst/adpcmenc/adpcmenc.c b/gst/adpcmenc/adpcmenc.c
index 0761c5c..e920da3 100644
--- a/gst/adpcmenc/adpcmenc.c
+++ b/gst/adpcmenc/adpcmenc.c
@@ -46,9 +46,10 @@ static GstStaticPadTemplate adpcmenc_sink_template =
 GST_STATIC_PAD_TEMPLATE ("sink",
     GST_PAD_SINK,
     GST_PAD_ALWAYS,
-    GST_STATIC_CAPS ("audio/x-raw-int, "
-        "depth = (int)16, "
-        "width = (int)16, " "channels = (int) [1,2], " "rate = (int)[1, MAX]")
+    GST_STATIC_CAPS ("audio/x-raw, "
+        "format = (string) " GST_AUDIO_NE (S16) ", "
+        "layout = (string) interleaved, "
+        "rate = (int) [1, MAX], channels = (int) [1,2]")
     );
 
 static GstStaticPadTemplate adpcmenc_src_template =
@@ -131,7 +132,7 @@ typedef struct _ADPCMEnc
 } ADPCMEnc;
 
 GType adpcmenc_get_type (void);
-GST_BOILERPLATE (ADPCMEnc, adpcmenc, GstAudioEncoder, GST_TYPE_AUDIO_ENCODER);
+G_DEFINE_TYPE (ADPCMEnc, adpcmenc, GST_TYPE_AUDIO_ENCODER);
 
 static gboolean
 adpcmenc_setup (ADPCMEnc * enc)
@@ -338,10 +339,13 @@ adpcmenc_encode_block (ADPCMEnc * enc, const gint16 * samples, int blocksize)
 {
   gboolean res = FALSE;
   GstBuffer *outbuf = NULL;
+  GstMapInfo omap;
 
   if (enc->layout == LAYOUT_ADPCM_DVI) {
     outbuf = gst_buffer_new_and_alloc (enc->blocksize);
-    res = adpcmenc_encode_ima_block (enc, samples, GST_BUFFER_DATA (outbuf));
+    gst_buffer_map (outbuf, &omap, GST_MAP_WRITE);
+    res = adpcmenc_encode_ima_block (enc, samples, omap.data);
+    gst_buffer_unmap (outbuf, &omap);
   } else {
     /* should not happen afaics */
     g_assert_not_reached ();
@@ -368,6 +372,7 @@ adpcmenc_handle_frame (GstAudioEncoder * benc, GstBuffer * buffer)
   GstBuffer *outbuf;
   int input_bytes_per_block;
   const int BYTES_PER_SAMPLE = 2;
+  GstMapInfo map;
 
   /* we don't deal with squeezing remnants, so simply discard those */
   if (G_UNLIKELY (buffer == NULL)) {
@@ -378,15 +383,17 @@ adpcmenc_handle_frame (GstAudioEncoder * benc, GstBuffer * buffer)
   input_bytes_per_block =
       enc->samples_per_block * BYTES_PER_SAMPLE * enc->channels;
 
-  if (G_UNLIKELY (GST_BUFFER_SIZE (buffer) < input_bytes_per_block)) {
-    GST_DEBUG_OBJECT (enc, "discarding trailing data %d",
-        GST_BUFFER_SIZE (buffer));
+  gst_buffer_map (buffer, &map, GST_MAP_READ);
+  if (G_UNLIKELY (map.size < input_bytes_per_block)) {
+    GST_DEBUG_OBJECT (enc, "discarding trailing data %d", (gint) map.size);
+    gst_buffer_unmap (buffer, &map);
     ret = gst_audio_encoder_finish_frame (benc, NULL, -1);
     goto done;
   }
 
-  samples = (gint16 *) GST_BUFFER_DATA (buffer);
+  samples = (gint16 *) map.data;
   outbuf = adpcmenc_encode_block (enc, samples, enc->blocksize);
+  gst_buffer_unmap (buffer, &map);
 
   ret = gst_audio_encoder_finish_frame (benc, outbuf, enc->samples_per_block);
 
@@ -411,7 +418,7 @@ adpcmenc_stop (GstAudioEncoder * enc)
 }
 
 static void
-adpcmenc_init (ADPCMEnc * enc, ADPCMEncClass * klass)
+adpcmenc_init (ADPCMEnc * enc)
 {
   /* Set defaults. */
   enc->blocksize = DEFAULT_ADPCM_BLOCK_SIZE;
@@ -422,11 +429,21 @@ static void
 adpcmenc_class_init (ADPCMEncClass * klass)
 {
   GObjectClass *gobjectclass = (GObjectClass *) klass;
+  GstElementClass *element_class = (GstElementClass *) klass;
   GstAudioEncoderClass *base_class = (GstAudioEncoderClass *) klass;
 
   gobjectclass->set_property = adpcmenc_set_property;
   gobjectclass->get_property = adpcmenc_get_property;
 
+  gst_element_class_add_pad_template (element_class,
+      gst_static_pad_template_get (&adpcmenc_sink_template));
+  gst_element_class_add_pad_template (element_class,
+      gst_static_pad_template_get (&adpcmenc_src_template));
+  gst_element_class_set_details_simple (element_class, "ADPCM encoder",
+      "Codec/Encoder/Audio",
+      "Encode ADPCM audio",
+      "Pioneers of the Inevitable <songbird at songbirdnest.com>");
+
   base_class->start = GST_DEBUG_FUNCPTR (adpcmenc_start);
   base_class->stop = GST_DEBUG_FUNCPTR (adpcmenc_stop);
   base_class->set_format = GST_DEBUG_FUNCPTR (adpcmenc_set_format);
@@ -444,21 +461,6 @@ adpcmenc_class_init (ADPCMEncClass * klass)
           MIN_ADPCM_BLOCK_SIZE, MAX_ADPCM_BLOCK_SIZE,
           DEFAULT_ADPCM_BLOCK_SIZE,
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-
-}
-
-static void
-adpcmenc_base_init (gpointer klass)
-{
-  GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
-  gst_element_class_add_pad_template (element_class,
-      gst_static_pad_template_get (&adpcmenc_sink_template));
-  gst_element_class_add_pad_template (element_class,
-      gst_static_pad_template_get (&adpcmenc_src_template));
-  gst_element_class_set_details_simple (element_class, "ADPCM encoder",
-      "Codec/Encoder/Audio",
-      "Encode ADPCM audio",
-      "Pioneers of the Inevitable <songbird at songbirdnest.com>");
 }
 
 static gboolean



More information about the gstreamer-commits mailing list