diff options
Diffstat (limited to 'gst/law/mulaw-decode.c')
-rw-r--r-- | gst/law/mulaw-decode.c | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/gst/law/mulaw-decode.c b/gst/law/mulaw-decode.c index 35c365f1..23df98e3 100644 --- a/gst/law/mulaw-decode.c +++ b/gst/law/mulaw-decode.c @@ -42,7 +42,7 @@ static void gst_mulawdec_class_init (GstMuLawDecClass * klass); static void gst_mulawdec_base_init (GstMuLawDecClass * klass); static void gst_mulawdec_init (GstMuLawDec * mulawdec); -static void gst_mulawdec_chain (GstPad * pad, GstData * _data); +static GstFlowReturn gst_mulawdec_chain (GstPad * pad, GstBuffer * buffer); static GstElementClass *parent_class = NULL; @@ -51,80 +51,85 @@ static GstElementClass *parent_class = NULL; static GstCaps * mulawdec_getcaps (GstPad * pad) { - GstMuLawDec *mulawdec = GST_MULAWDEC (gst_pad_get_parent (pad)); + GstMuLawDec *mulawdec; GstPad *otherpad; GstCaps *base_caps, *othercaps; - GstStructure *structure; - const GValue *rate, *chans; + + mulawdec = GST_MULAWDEC (GST_PAD_PARENT (pad)); + + base_caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad)); if (pad == mulawdec->sinkpad) { otherpad = mulawdec->srcpad; - base_caps = gst_caps_new_simple ("audio/x-mulaw", NULL); } else { otherpad = mulawdec->sinkpad; - base_caps = gst_caps_new_simple ("audio/x-raw-int", - "width", G_TYPE_INT, 16, "depth", G_TYPE_INT, 16, - "signed", G_TYPE_BOOLEAN, TRUE, - "endianness", G_TYPE_INT, G_BYTE_ORDER, - "signed", G_TYPE_BOOLEAN, TRUE, NULL); } - othercaps = gst_pad_get_allowed_caps (otherpad); - - /* Not fully correct, but usually, all structures in a caps have - * the same samplerate and channels range. */ - structure = gst_caps_get_structure (othercaps, 0); - rate = gst_structure_get_value (structure, "rate"); - chans = gst_structure_get_value (structure, "channels"); - if (!rate || !chans) - return gst_caps_new_empty (); - - /* Set the samplerate/channels on the to-be-returned caps */ - structure = gst_caps_get_structure (base_caps, 0); - gst_structure_set_value (structure, "rate", rate); - gst_structure_set_value (structure, "channels", chans); - gst_caps_free (othercaps); - + othercaps = gst_pad_peer_get_caps (otherpad); + if (othercaps) { + GstStructure *structure; + const GValue *orate, *ochans; + const GValue *rate, *chans; + GValue irate = { 0 }, ichans = { + 0}; + + structure = gst_caps_get_structure (othercaps, 0); + orate = gst_structure_get_value (structure, "rate"); + ochans = gst_structure_get_value (structure, "channels"); + if (!rate || !chans) + goto done; + + structure = gst_caps_get_structure (base_caps, 0); + rate = gst_structure_get_value (structure, "rate"); + chans = gst_structure_get_value (structure, "channels"); + if (!rate || !chans) + goto done; + + gst_value_intersect (&irate, orate, rate); + gst_value_intersect (&ichans, ochans, chans); + + /* Set the samplerate/channels on the to-be-returned caps */ + structure = gst_caps_get_structure (base_caps, 0); + gst_structure_set_value (structure, "rate", &irate); + gst_structure_set_value (structure, "channels", &ichans); + + gst_caps_unref (othercaps); + } +done: return base_caps; } -static GstPadLinkReturn -mulawdec_link (GstPad * pad, const GstCaps * caps) +static gboolean +mulawdec_setcaps (GstPad * pad, GstCaps * caps) { - GstMuLawDec *mulawdec = GST_MULAWDEC (gst_pad_get_parent (pad)); + GstMuLawDec *mulawdec; GstPad *otherpad; GstStructure *structure; const GValue *rate, *chans; GstCaps *base_caps; - GstPadLinkReturn link_return; + mulawdec = GST_MULAWDEC (GST_PAD_PARENT (pad)); structure = gst_caps_get_structure (caps, 0); rate = gst_structure_get_value (structure, "rate"); chans = gst_structure_get_value (structure, "channels"); if (!rate || !chans) - return GST_PAD_LINK_REFUSED; + return FALSE; if (pad == mulawdec->srcpad) { otherpad = mulawdec->sinkpad; - base_caps = gst_caps_new_simple ("audio/x-mulaw", NULL); } else { otherpad = mulawdec->srcpad; - base_caps = gst_caps_new_simple ("audio/x-raw-int", - "width", G_TYPE_INT, 16, "depth", G_TYPE_INT, 16, - "endianness", G_TYPE_INT, G_BYTE_ORDER, - "signed", G_TYPE_BOOLEAN, TRUE, NULL); } + base_caps = gst_caps_copy (gst_pad_get_pad_template_caps (otherpad)); structure = gst_caps_get_structure (base_caps, 0); gst_structure_set_value (structure, "rate", rate); gst_structure_set_value (structure, "channels", chans); - link_return = gst_pad_try_set_caps (otherpad, base_caps); - - gst_caps_free (base_caps); - - return link_return; + gst_pad_set_caps (otherpad, base_caps); + gst_caps_unref (base_caps); + return TRUE; } GType @@ -179,42 +184,37 @@ gst_mulawdec_init (GstMuLawDec * mulawdec) { mulawdec->sinkpad = gst_pad_new_from_template (mulawdec_sink_template, "sink"); - gst_pad_set_link_function (mulawdec->sinkpad, mulawdec_link); + gst_pad_set_setcaps_function (mulawdec->sinkpad, mulawdec_setcaps); gst_pad_set_getcaps_function (mulawdec->sinkpad, mulawdec_getcaps); gst_pad_set_chain_function (mulawdec->sinkpad, gst_mulawdec_chain); gst_element_add_pad (GST_ELEMENT (mulawdec), mulawdec->sinkpad); mulawdec->srcpad = gst_pad_new_from_template (mulawdec_src_template, "src"); - gst_pad_set_link_function (mulawdec->srcpad, mulawdec_link); + gst_pad_set_setcaps_function (mulawdec->srcpad, mulawdec_setcaps); gst_pad_set_getcaps_function (mulawdec->srcpad, mulawdec_getcaps); gst_element_add_pad (GST_ELEMENT (mulawdec), mulawdec->srcpad); } -static void -gst_mulawdec_chain (GstPad * pad, GstData * _data) +static GstFlowReturn +gst_mulawdec_chain (GstPad * pad, GstBuffer * buffer) { - GstBuffer *buf = GST_BUFFER (_data); GstMuLawDec *mulawdec; gint16 *linear_data; guint8 *mulaw_data; GstBuffer *outbuf; - g_return_if_fail (pad != NULL); - g_return_if_fail (GST_IS_PAD (pad)); - g_return_if_fail (buf != NULL); - mulawdec = GST_MULAWDEC (GST_OBJECT_PARENT (pad)); - g_return_if_fail (mulawdec != NULL); - g_return_if_fail (GST_IS_MULAWDEC (mulawdec)); - mulaw_data = (guint8 *) GST_BUFFER_DATA (buf); - outbuf = gst_buffer_new_and_alloc (GST_BUFFER_SIZE (buf) * 2); - GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf); - GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buf); + mulaw_data = (guint8 *) GST_BUFFER_DATA (buffer); + outbuf = gst_buffer_new_and_alloc (GST_BUFFER_SIZE (buffer) * 2); + GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buffer); + GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buffer); + gst_buffer_set_caps (outbuf, GST_PAD_CAPS (mulawdec->srcpad)); linear_data = (gint16 *) GST_BUFFER_DATA (outbuf); - mulaw_decode (mulaw_data, linear_data, GST_BUFFER_SIZE (buf)); + mulaw_decode (mulaw_data, linear_data, GST_BUFFER_SIZE (buffer)); + + gst_buffer_unref (buffer); - gst_buffer_unref (buf); - gst_pad_push (mulawdec->srcpad, GST_DATA (outbuf)); + return gst_pad_push (mulawdec->srcpad, outbuf); } |