From f9863d1274841ffa83f878c1cff7c0a25acebb78 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 4 Oct 2011 17:35:40 +0200 Subject: [PATCH] amrnb: port to 0.11 --- configure.ac | 3 +- ext/amrnb/amrnbdec.c | 87 +++++++++++++++++++++----------------------- ext/amrnb/amrnbenc.c | 58 ++++++++++++++--------------- 3 files changed, 70 insertions(+), 78 deletions(-) diff --git a/configure.ac b/configure.ac index f8390dcea0..10bc7a1cac 100644 --- a/configure.ac +++ b/configure.ac @@ -211,8 +211,7 @@ 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=" dvdsub iec958 synaesthesia xingmux \ - mpegstream realmedia \ - amrnb cdio dvdread twolame " + mpegstream realmedia cdio dvdread twolame " AC_SUBST(GST_PLUGINS_NONPORTED) dnl these are all the gst plug-ins, compilable without additional libs diff --git a/ext/amrnb/amrnbdec.c b/ext/amrnb/amrnbdec.c index b6b4169a1f..ea6df3ae96 100644 --- a/ext/amrnb/amrnbdec.c +++ b/ext/amrnb/amrnbdec.c @@ -104,27 +104,8 @@ static GstStateChangeReturn gst_amrnbdec_state_change (GstElement * element, static void gst_amrnbdec_finalize (GObject * object); -#define _do_init(bla) \ - GST_DEBUG_CATEGORY_INIT (gst_amrnbdec_debug, "amrnbdec", 0, "AMR-NB audio decoder"); - -GST_BOILERPLATE_FULL (GstAmrnbDec, gst_amrnbdec, GstElement, GST_TYPE_ELEMENT, - _do_init); - -static void -gst_amrnbdec_base_init (gpointer klass) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&sink_template)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&src_template)); - - gst_element_class_set_details_simple (element_class, "AMR-NB audio decoder", - "Codec/Decoder/Audio", - "Adaptive Multi-Rate Narrow-Band audio decoder", - "GStreamer maintainers "); -} +#define gst_amrnbdec_parent_class parent_class +G_DEFINE_TYPE (GstAmrnbDec, gst_amrnbdec, GST_TYPE_ELEMENT); static void gst_amrnbdec_class_init (GstAmrnbDecClass * klass) @@ -143,14 +124,26 @@ gst_amrnbdec_class_init (GstAmrnbDecClass * klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); element_class->change_state = GST_DEBUG_FUNCPTR (gst_amrnbdec_state_change); + + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_template)); + + gst_element_class_set_details_simple (element_class, "AMR-NB audio decoder", + "Codec/Decoder/Audio", + "Adaptive Multi-Rate Narrow-Band audio decoder", + "GStreamer maintainers "); + + GST_DEBUG_CATEGORY_INIT (gst_amrnbdec_debug, "amrnbdec", 0, + "AMR-NB audio decoder"); } static void -gst_amrnbdec_init (GstAmrnbDec * amrnbdec, GstAmrnbDecClass * klass) +gst_amrnbdec_init (GstAmrnbDec * amrnbdec) { /* create the sink pad */ amrnbdec->sinkpad = gst_pad_new_from_static_template (&sink_template, "sink"); - gst_pad_set_setcaps_function (amrnbdec->sinkpad, gst_amrnbdec_setcaps); gst_pad_set_event_function (amrnbdec->sinkpad, gst_amrnbdec_event); gst_pad_set_chain_function (amrnbdec->sinkpad, gst_amrnbdec_chain); gst_element_add_pad (GST_ELEMENT (amrnbdec), amrnbdec->sinkpad); @@ -256,6 +249,15 @@ gst_amrnbdec_event (GstPad * pad, GstEvent * event) amrnbdec = GST_AMRNBDEC (gst_pad_get_parent (pad)); switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_CAPS: + { + GstCaps *caps; + + gst_event_parse_caps (event, &caps); + ret = gst_amrnbdec_setcaps (pad, caps); + gst_event_unref (event); + break; + } case GST_EVENT_FLUSH_START: ret = gst_pad_push_event (amrnbdec->srcpad, event); break; @@ -268,32 +270,24 @@ gst_amrnbdec_event (GstPad * pad, GstEvent * event) gst_adapter_clear (amrnbdec->adapter); ret = gst_pad_push_event (amrnbdec->srcpad, event); break; - case GST_EVENT_NEWSEGMENT: + case GST_EVENT_SEGMENT: { - GstFormat format; - gdouble rate, arate; - gint64 start, stop, time; - gboolean update; + GstSegment seg; - gst_event_parse_new_segment_full (event, &update, &rate, &arate, &format, - &start, &stop, &time); + gst_event_copy_segment (event, &seg); /* we need time for now */ - if (format != GST_FORMAT_TIME) + if (seg.format != GST_FORMAT_TIME) goto newseg_wrong_format; - GST_DEBUG_OBJECT (amrnbdec, - "newsegment: update %d, rate %g, arate %g, start %" GST_TIME_FORMAT - ", stop %" GST_TIME_FORMAT ", time %" GST_TIME_FORMAT, - update, rate, arate, GST_TIME_ARGS (start), GST_TIME_ARGS (stop), - GST_TIME_ARGS (time)); + GST_DEBUG_OBJECT (amrnbdec, "segment: %" GST_SEGMENT_FORMAT, &seg); /* now configure the values */ - gst_segment_set_newsegment_full (&amrnbdec->segment, update, - rate, arate, format, start, stop, time); + amrnbdec->segment = seg; + ret = gst_pad_push_event (amrnbdec->srcpad, event); - } break; + } default: ret = gst_pad_push_event (amrnbdec->srcpad, event); break; @@ -341,22 +335,24 @@ gst_amrnbdec_chain (GstPad * pad, GstBuffer * buffer) while (TRUE) { GstBuffer *out; + guint8 head[1]; guint8 *data; + short *out_data; gint block, mode; /* need to peek data to get the size */ if (gst_adapter_available (amrnbdec->adapter) < 1) break; - data = (guint8 *) gst_adapter_peek (amrnbdec->adapter, 1); + gst_adapter_copy (amrnbdec->adapter, head, 0, 1); /* get size */ switch (amrnbdec->variant) { case GST_AMRNB_VARIANT_IF1: - mode = (data[0] >> 3) & 0x0F; + mode = (head[0] >> 3) & 0x0F; block = block_size_if1[mode] + 1; break; case GST_AMRNB_VARIANT_IF2: - mode = data[0] & 0x0F; + mode = head[0] & 0x0F; block = block_size_if2[mode] + 1; break; default: @@ -384,11 +380,10 @@ gst_amrnbdec_chain (GstPad * pad, GstBuffer * buffer) amrnbdec->discont = FALSE; } - gst_buffer_set_caps (out, GST_PAD_CAPS (amrnbdec->srcpad)); - /* decode */ - Decoder_Interface_Decode (amrnbdec->handle, data, - (short *) GST_BUFFER_DATA (out), 0); + out_data = gst_buffer_map (out, NULL, NULL, GST_MAP_WRITE); + Decoder_Interface_Decode (amrnbdec->handle, data, out_data, 0); + gst_buffer_unmap (out, out_data, -1); g_free (data); /* send out */ diff --git a/ext/amrnb/amrnbenc.c b/ext/amrnb/amrnbenc.c index 3bc90f9509..cb8f4c4330 100644 --- a/ext/amrnb/amrnbenc.c +++ b/ext/amrnb/amrnbenc.c @@ -99,8 +99,8 @@ static gboolean gst_amrnbenc_set_format (GstAudioEncoder * enc, static GstFlowReturn gst_amrnbenc_handle_frame (GstAudioEncoder * enc, GstBuffer * in_buf); -GST_BOILERPLATE (GstAmrnbEnc, gst_amrnbenc, GstAudioEncoder, - GST_TYPE_AUDIO_ENCODER); +#define gst_amrnbenc_parent_class parent_class +G_DEFINE_TYPE (GstAmrnbEnc, gst_amrnbenc, GST_TYPE_AUDIO_ENCODER); static void gst_amrnbenc_set_property (GObject * object, guint prop_id, @@ -136,26 +136,11 @@ gst_amrnbenc_get_property (GObject * object, guint prop_id, return; } -static void -gst_amrnbenc_base_init (gpointer klass) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&sink_template)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&src_template)); - - gst_element_class_set_details_simple (element_class, "AMR-NB audio encoder", - "Codec/Encoder/Audio", - "Adaptive Multi-Rate Narrow-Band audio encoder", - "Wim Taymans "); -} - static void gst_amrnbenc_class_init (GstAmrnbEncClass * klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + GstElementClass *element_class = GST_ELEMENT_CLASS (klass); GstAudioEncoderClass *base_class = GST_AUDIO_ENCODER_CLASS (klass); object_class->set_property = gst_amrnbenc_set_property; @@ -172,12 +157,22 @@ gst_amrnbenc_class_init (GstAmrnbEncClass * klass) BANDMODE_DEFAULT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_template)); + + gst_element_class_set_details_simple (element_class, "AMR-NB audio encoder", + "Codec/Encoder/Audio", + "Adaptive Multi-Rate Narrow-Band audio encoder", + "Wim Taymans "); + GST_DEBUG_CATEGORY_INIT (gst_amrnbenc_debug, "amrnbenc", 0, "AMR-NB audio encoder"); } static void -gst_amrnbenc_init (GstAmrnbEnc * amrnbenc, GstAmrnbEncClass * klass) +gst_amrnbenc_init (GstAmrnbEnc * amrnbenc) { } @@ -249,8 +244,9 @@ gst_amrnbenc_handle_frame (GstAudioEncoder * enc, GstBuffer * buffer) GstAmrnbEnc *amrnbenc; GstFlowReturn ret; GstBuffer *out; - guint8 *data; - gint outsize; + short *in_data; + guint8 *out_data; + gsize in_size, out_size; amrnbenc = GST_AMRNBENC (enc); @@ -262,9 +258,11 @@ gst_amrnbenc_handle_frame (GstAudioEncoder * enc, GstBuffer * buffer) return GST_FLOW_OK; } - if (G_UNLIKELY (GST_BUFFER_SIZE (buffer) < 320)) { - GST_DEBUG_OBJECT (amrnbenc, "discarding trailing data %d", - buffer ? GST_BUFFER_SIZE (buffer) : 0); + in_data = gst_buffer_map (buffer, &in_size, NULL, GST_MAP_READ); + + if (G_UNLIKELY (in_size < 320)) { + gst_buffer_unmap (buffer, in_data, in_size); + GST_DEBUG_OBJECT (amrnbenc, "discarding trailing data %d", in_size); return gst_audio_encoder_finish_frame (enc, NULL, -1); } @@ -272,17 +270,17 @@ gst_amrnbenc_handle_frame (GstAudioEncoder * enc, GstBuffer * buffer) out = gst_buffer_new_and_alloc (32); /* AMR encoder actually writes into the source data buffers it gets */ /* should be able to handle that with what we are given */ - data = GST_BUFFER_DATA (buffer); + out_data = gst_buffer_map (buffer, NULL, NULL, GST_MAP_WRITE); /* encode */ - outsize = + out_size = Encoder_Interface_Encode (amrnbenc->handle, amrnbenc->bandmode, - (short *) data, (guint8 *) GST_BUFFER_DATA (out), 0); + in_data, out_data, 0); + gst_buffer_unmap (out, out_data, out_size); - GST_LOG_OBJECT (amrnbenc, "output data size %d", outsize); + GST_LOG_OBJECT (amrnbenc, "output data size %d", out_size); - if (outsize) { - GST_BUFFER_SIZE (out) = outsize; + if (out_size) { ret = gst_audio_encoder_finish_frame (enc, out, 160); } else { /* should not happen (without dtx or so at least) */