diff options
author | Wim Taymans <wim.taymans@collabora.co.uk> | 2011-08-29 19:11:25 +0200 |
---|---|---|
committer | Wim Taymans <wim.taymans@collabora.co.uk> | 2011-08-29 19:11:25 +0200 |
commit | 5ad41c7292ae168a6e534bf32cb7ad09c8de8c91 (patch) | |
tree | fc845364efe7237aeef2d250eaba35ac4fc1470e /gst/law | |
parent | e62d326dc2608615d3fef18e0bcdccad495fc5a1 (diff) | |
download | gstreamer-plugins-good-5ad41c7292ae168a6e534bf32cb7ad09c8de8c91.tar.gz |
alaw: port to 0.11
Diffstat (limited to 'gst/law')
-rw-r--r-- | gst/law/alaw-decode.c | 84 | ||||
-rw-r--r-- | gst/law/alaw-encode.c | 100 |
2 files changed, 95 insertions, 89 deletions
diff --git a/gst/law/alaw-decode.c b/gst/law/alaw-decode.c index ee5367a56..ed42b3d0e 100644 --- a/gst/law/alaw-decode.c +++ b/gst/law/alaw-decode.c @@ -36,9 +36,12 @@ GST_DEBUG_CATEGORY_STATIC (alaw_dec_debug); static GstStateChangeReturn gst_alaw_dec_change_state (GstElement * element, GstStateChange transition); + +static gboolean gst_alaw_dec_event (GstPad * pad, GstEvent * event); static GstFlowReturn gst_alaw_dec_chain (GstPad * pad, GstBuffer * buffer); -GST_BOILERPLATE (GstALawDec, gst_alaw_dec, GstElement, GST_TYPE_ELEMENT); +#define gst_alaw_dec_parent_class parent_class +G_DEFINE_TYPE (GstALawDec, gst_alaw_dec, GST_TYPE_ELEMENT); /* some day we might have defines in gstconfig.h that tell us about the * desired cpu/memory/binary size trade-offs */ @@ -110,16 +113,13 @@ alaw_to_s16 (guint8 a_val) #endif /* GST_ALAW_DEC_USE_TABLE */ static gboolean -gst_alaw_dec_sink_setcaps (GstPad * pad, GstCaps * caps) +gst_alaw_dec_setcaps (GstALawDec * alawdec, GstCaps * caps) { - GstALawDec *alawdec; GstStructure *structure; int rate, channels; gboolean ret; GstCaps *outcaps; - alawdec = GST_ALAW_DEC (GST_PAD_PARENT (pad)); - structure = gst_caps_get_structure (caps, 0); ret = gst_structure_get_int (structure, "rate", &rate); @@ -146,7 +146,7 @@ gst_alaw_dec_sink_setcaps (GstPad * pad, GstCaps * caps) } static GstCaps * -gst_alaw_dec_getcaps (GstPad * pad) +gst_alaw_dec_getcaps (GstPad * pad, GstCaps * filter) { GstALawDec *alawdec; GstPad *otherpad; @@ -166,7 +166,7 @@ gst_alaw_dec_getcaps (GstPad * pad) otherpad = alawdec->srcpad; } /* get caps from the peer, this can return NULL when there is no peer */ - othercaps = gst_pad_peer_get_caps (otherpad); + othercaps = gst_pad_peer_get_caps (otherpad, filter); /* get the template caps to make sure we return something acceptable */ templ = gst_pad_get_pad_template_caps (pad); @@ -208,7 +208,7 @@ gst_alaw_dec_getcaps (GstPad * pad) } static void -gst_alaw_dec_base_init (gpointer klass) +gst_alaw_dec_class_init (GstALawDecClass * klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); @@ -221,26 +221,20 @@ gst_alaw_dec_base_init (gpointer klass) "Codec/Decoder/Audio", "Convert 8bit A law to 16bit PCM", "Zaheer Abbas Merali <zaheerabbas at merali dot org>"); - GST_DEBUG_CATEGORY_INIT (alaw_dec_debug, "alawdec", 0, "A Law audio decoder"); -} - -static void -gst_alaw_dec_class_init (GstALawDecClass * klass) -{ - GstElementClass *element_class = (GstElementClass *) klass; - element_class->change_state = GST_DEBUG_FUNCPTR (gst_alaw_dec_change_state); + + GST_DEBUG_CATEGORY_INIT (alaw_dec_debug, "alawdec", 0, "A Law audio decoder"); } static void -gst_alaw_dec_init (GstALawDec * alawdec, GstALawDecClass * klass) +gst_alaw_dec_init (GstALawDec * alawdec) { alawdec->sinkpad = gst_pad_new_from_static_template (&alaw_dec_sink_factory, "sink"); - gst_pad_set_setcaps_function (alawdec->sinkpad, - GST_DEBUG_FUNCPTR (gst_alaw_dec_sink_setcaps)); gst_pad_set_getcaps_function (alawdec->sinkpad, GST_DEBUG_FUNCPTR (gst_alaw_dec_getcaps)); + gst_pad_set_event_function (alawdec->sinkpad, + GST_DEBUG_FUNCPTR (gst_alaw_dec_event)); gst_pad_set_chain_function (alawdec->sinkpad, GST_DEBUG_FUNCPTR (gst_alaw_dec_chain)); gst_element_add_pad (GST_ELEMENT (alawdec), alawdec->sinkpad); @@ -253,13 +247,40 @@ gst_alaw_dec_init (GstALawDec * alawdec, GstALawDecClass * klass) gst_element_add_pad (GST_ELEMENT (alawdec), alawdec->srcpad); } +static gboolean +gst_alaw_dec_event (GstPad * pad, GstEvent * event) +{ + GstALawDec *alawdec; + gboolean res; + + alawdec = GST_ALAW_DEC (GST_PAD_PARENT (pad)); + + switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_CAPS: + { + GstCaps *caps; + + gst_event_parse_caps (event, &caps); + gst_alaw_dec_setcaps (alawdec, caps); + gst_event_unref (event); + + res = TRUE; + break; + } + default: + res = gst_pad_event_default (pad, event); + break; + } + return res; +} + static GstFlowReturn gst_alaw_dec_chain (GstPad * pad, GstBuffer * buffer) { GstALawDec *alawdec; gint16 *linear_data; guint8 *alaw_data; - guint alaw_size; + gsize alaw_size; GstBuffer *outbuf; gint i; GstFlowReturn ret; @@ -272,17 +293,11 @@ gst_alaw_dec_chain (GstPad * pad, GstBuffer * buffer) GST_LOG_OBJECT (alawdec, "buffer with ts=%" GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer))); - alaw_data = GST_BUFFER_DATA (buffer); - alaw_size = GST_BUFFER_SIZE (buffer); + alaw_data = gst_buffer_map (buffer, &alaw_size, NULL, GST_MAP_READ); - ret = - gst_pad_alloc_buffer_and_set_caps (alawdec->srcpad, - GST_BUFFER_OFFSET_NONE, alaw_size * 2, GST_PAD_CAPS (alawdec->srcpad), - &outbuf); - if (ret != GST_FLOW_OK) - goto alloc_failed; + outbuf = gst_buffer_new_allocate (NULL, alaw_size, 0); - linear_data = (gint16 *) GST_BUFFER_DATA (outbuf); + linear_data = gst_buffer_map (outbuf, NULL, NULL, GST_MAP_WRITE); /* copy discont flag */ if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT)) @@ -290,11 +305,13 @@ gst_alaw_dec_chain (GstPad * pad, GstBuffer * buffer) GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buffer); GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buffer); - gst_buffer_set_caps (outbuf, GST_PAD_CAPS (alawdec->srcpad)); for (i = 0; i < alaw_size; i++) { linear_data[i] = alaw_to_s16 (alaw_data[i]); } + + gst_buffer_unmap (outbuf, linear_data, -1); + gst_buffer_unmap (buffer, alaw_data, -1); gst_buffer_unref (buffer); ret = gst_pad_push (alawdec->srcpad, outbuf); @@ -307,13 +324,6 @@ not_negotiated: GST_WARNING_OBJECT (alawdec, "no input format set: not-negotiated"); return GST_FLOW_NOT_NEGOTIATED; } -alloc_failed: - { - gst_buffer_unref (buffer); - GST_DEBUG_OBJECT (alawdec, "pad alloc failed, flow: %s", - gst_flow_get_name (ret)); - return ret; - } } static GstStateChangeReturn diff --git a/gst/law/alaw-encode.c b/gst/law/alaw-encode.c index f5514cef7..983a45700 100644 --- a/gst/law/alaw-encode.c +++ b/gst/law/alaw-encode.c @@ -34,9 +34,10 @@ GST_DEBUG_CATEGORY_STATIC (alaw_enc_debug); extern GstStaticPadTemplate alaw_enc_src_factory; extern GstStaticPadTemplate alaw_enc_sink_factory; +static gboolean gst_alaw_enc_event (GstPad * pad, GstEvent * event); static GstFlowReturn gst_alaw_enc_chain (GstPad * pad, GstBuffer * buffer); -GST_BOILERPLATE (GstALawEnc, gst_alaw_enc, GstElement, GST_TYPE_ELEMENT); +G_DEFINE_TYPE (GstALawEnc, gst_alaw_enc, GST_TYPE_ELEMENT); /* some day we might have defines in gstconfig.h that tell us about the * desired cpu/memory/binary size trade-offs */ @@ -297,7 +298,7 @@ s16_to_alaw (gint pcm_val) #endif /* GST_ALAW_ENC_USE_TABLE */ static GstCaps * -gst_alaw_enc_getcaps (GstPad * pad) +gst_alaw_enc_getcaps (GstPad * pad, GstCaps * filter) { GstALawEnc *alawenc; GstPad *otherpad; @@ -317,7 +318,7 @@ gst_alaw_enc_getcaps (GstPad * pad) otherpad = alawenc->srcpad; } /* get caps from the peer, this can return NULL when there is no peer */ - othercaps = gst_pad_peer_get_caps (otherpad); + othercaps = gst_pad_peer_get_caps (otherpad, filter); /* get the template caps to make sure we return something acceptable */ templ = gst_pad_get_pad_template_caps (pad); @@ -359,27 +360,17 @@ gst_alaw_enc_getcaps (GstPad * pad) } static gboolean -gst_alaw_enc_setcaps (GstPad * pad, GstCaps * caps) +gst_alaw_enc_setcaps (GstALawEnc * alawenc, GstCaps * caps) { - GstALawEnc *alawenc; - GstPad *otherpad; GstStructure *structure; gboolean ret; GstCaps *base_caps; - alawenc = GST_ALAW_ENC (GST_PAD_PARENT (pad)); - structure = gst_caps_get_structure (caps, 0); gst_structure_get_int (structure, "channels", &alawenc->channels); gst_structure_get_int (structure, "rate", &alawenc->rate); - if (pad == alawenc->sinkpad) { - otherpad = alawenc->srcpad; - } else { - otherpad = alawenc->sinkpad; - } - - base_caps = gst_caps_copy (gst_pad_get_pad_template_caps (otherpad)); + base_caps = gst_caps_copy (gst_pad_get_pad_template_caps (alawenc->srcpad)); structure = gst_caps_get_structure (base_caps, 0); gst_structure_set (structure, "rate", G_TYPE_INT, alawenc->rate, NULL); gst_structure_set (structure, "channels", G_TYPE_INT, alawenc->channels, @@ -388,7 +379,7 @@ gst_alaw_enc_setcaps (GstPad * pad, GstCaps * caps) GST_DEBUG_OBJECT (alawenc, "rate=%d, channels=%d", alawenc->rate, alawenc->channels); - ret = gst_pad_set_caps (otherpad, base_caps); + ret = gst_pad_set_caps (alawenc->srcpad, base_caps); gst_caps_unref (base_caps); @@ -396,7 +387,7 @@ gst_alaw_enc_setcaps (GstPad * pad, GstCaps * caps) } static void -gst_alaw_enc_base_init (gpointer klass) +gst_alaw_enc_class_init (GstALawEncClass * klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); @@ -414,28 +405,20 @@ gst_alaw_enc_base_init (gpointer klass) } static void -gst_alaw_enc_class_init (GstALawEncClass * klass) -{ - /* nothing to do here for now */ -} - -static void -gst_alaw_enc_init (GstALawEnc * alawenc, GstALawEncClass * klass) +gst_alaw_enc_init (GstALawEnc * alawenc) { alawenc->sinkpad = gst_pad_new_from_static_template (&alaw_enc_sink_factory, "sink"); - gst_pad_set_setcaps_function (alawenc->sinkpad, - GST_DEBUG_FUNCPTR (gst_alaw_enc_setcaps)); gst_pad_set_getcaps_function (alawenc->sinkpad, GST_DEBUG_FUNCPTR (gst_alaw_enc_getcaps)); + gst_pad_set_event_function (alawenc->sinkpad, + GST_DEBUG_FUNCPTR (gst_alaw_enc_event)); gst_pad_set_chain_function (alawenc->sinkpad, GST_DEBUG_FUNCPTR (gst_alaw_enc_chain)); gst_element_add_pad (GST_ELEMENT (alawenc), alawenc->sinkpad); alawenc->srcpad = gst_pad_new_from_static_template (&alaw_enc_src_factory, "src"); - gst_pad_set_setcaps_function (alawenc->srcpad, - GST_DEBUG_FUNCPTR (gst_alaw_enc_setcaps)); gst_pad_set_getcaps_function (alawenc->srcpad, GST_DEBUG_FUNCPTR (gst_alaw_enc_getcaps)); gst_pad_use_fixed_caps (alawenc->srcpad); @@ -446,12 +429,39 @@ gst_alaw_enc_init (GstALawEnc * alawenc, GstALawEncClass * klass) alawenc->rate = 0; } +static gboolean +gst_alaw_enc_event (GstPad * pad, GstEvent * event) +{ + GstALawEnc *alawenc; + gboolean res; + + alawenc = GST_ALAW_ENC (GST_PAD_PARENT (pad)); + + switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_CAPS: + { + GstCaps *caps; + + gst_event_parse_caps (event, &caps); + gst_alaw_enc_setcaps (alawenc, caps); + gst_event_unref (event); + + res = TRUE; + break; + } + default: + res = gst_pad_event_default (pad, event); + break; + } + return res; +} + static GstFlowReturn gst_alaw_enc_chain (GstPad * pad, GstBuffer * buffer) { GstALawEnc *alawenc; gint16 *linear_data; - guint linear_size; + gsize linear_size; guint8 *alaw_data; guint alaw_size; GstBuffer *outbuf; @@ -464,8 +474,7 @@ gst_alaw_enc_chain (GstPad * pad, GstBuffer * buffer) if (G_UNLIKELY (alawenc->rate == 0 || alawenc->channels == 0)) goto not_negotiated; - linear_data = (gint16 *) GST_BUFFER_DATA (buffer); - linear_size = GST_BUFFER_SIZE (buffer); + linear_data = gst_buffer_map (buffer, &linear_size, NULL, GST_MAP_READ); alaw_size = linear_size / 2; @@ -475,25 +484,14 @@ gst_alaw_enc_chain (GstPad * pad, GstBuffer * buffer) GST_LOG_OBJECT (alawenc, "buffer with ts=%" GST_TIME_FORMAT, GST_TIME_ARGS (timestamp)); - ret = - gst_pad_alloc_buffer_and_set_caps (alawenc->srcpad, - GST_BUFFER_OFFSET_NONE, alaw_size, GST_PAD_CAPS (alawenc->srcpad), - &outbuf); - if (ret != GST_FLOW_OK) - goto done; + outbuf = gst_buffer_new_allocate (NULL, alaw_size, 0); if (duration == GST_CLOCK_TIME_NONE) { duration = gst_util_uint64_scale_int (alaw_size, GST_SECOND, alawenc->rate * alawenc->channels); } - if (GST_BUFFER_SIZE (outbuf) < alaw_size) { - /* pad-alloc can return a smaller buffer */ - gst_buffer_unref (outbuf); - outbuf = gst_buffer_new_and_alloc (alaw_size); - } - - alaw_data = (guint8 *) GST_BUFFER_DATA (outbuf); + alaw_data = gst_buffer_map (outbuf, NULL, NULL, GST_MAP_WRITE); /* copy discont flag */ if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT)) @@ -502,23 +500,21 @@ gst_alaw_enc_chain (GstPad * pad, GstBuffer * buffer) GST_BUFFER_TIMESTAMP (outbuf) = timestamp; GST_BUFFER_DURATION (outbuf) = duration; - gst_buffer_set_caps (outbuf, GST_PAD_CAPS (alawenc->srcpad)); - for (i = 0; i < alaw_size; i++) { alaw_data[i] = s16_to_alaw (linear_data[i]); } - ret = gst_pad_push (alawenc->srcpad, outbuf); - -done: - + gst_buffer_unmap (outbuf, alaw_data, -1); + gst_buffer_unmap (buffer, linear_data, -1); gst_buffer_unref (buffer); + ret = gst_pad_push (alawenc->srcpad, outbuf); + return ret; not_negotiated: { - ret = GST_FLOW_NOT_NEGOTIATED; - goto done; + gst_buffer_unref (buffer); + return GST_FLOW_NOT_NEGOTIATED; } } |