diff options
Diffstat (limited to 'gst/law/mulaw-encode.c')
-rw-r--r-- | gst/law/mulaw-encode.c | 116 |
1 files changed, 60 insertions, 56 deletions
diff --git a/gst/law/mulaw-encode.c b/gst/law/mulaw-encode.c index 305165b8..4a2576ac 100644 --- a/gst/law/mulaw-encode.c +++ b/gst/law/mulaw-encode.c @@ -42,7 +42,7 @@ static void gst_mulawenc_class_init (GstMuLawEncClass * klass); static void gst_mulawenc_base_init (GstMuLawEncClass * klass); static void gst_mulawenc_init (GstMuLawEnc * mulawenc); -static void gst_mulawenc_chain (GstPad * pad, GstData * _data); +static GstFlowReturn gst_mulawenc_chain (GstPad * pad, GstBuffer * buffer); static GstElementClass *parent_class = NULL; @@ -51,77 +51,85 @@ static GstElementClass *parent_class = NULL; static GstCaps * mulawenc_getcaps (GstPad * pad) { - GstMuLawEnc *mulawenc = GST_MULAWENC (gst_pad_get_parent (pad)); + GstMuLawEnc *mulawenc; GstPad *otherpad; GstCaps *base_caps, *othercaps; - GstStructure *structure; - const GValue *rate, *chans; + + mulawenc = GST_MULAWENC (GST_PAD_PARENT (pad)); + + base_caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad)); if (pad == mulawenc->srcpad) { otherpad = mulawenc->sinkpad; - base_caps = gst_caps_new_simple ("audio/x-mulaw", NULL); } else { otherpad = mulawenc->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); } - 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 -mulawenc_link (GstPad * pad, const GstCaps * caps) +static gboolean +mulawenc_setcaps (GstPad * pad, GstCaps * caps) { - GstMuLawEnc *mulawenc = GST_MULAWENC (gst_pad_get_parent (pad)); + GstMuLawEnc *mulawenc; GstPad *otherpad; GstStructure *structure; const GValue *rate, *chans; GstCaps *base_caps; - GstPadLinkReturn link_return; + + mulawenc = GST_MULAWENC (gst_pad_get_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 == mulawenc->sinkpad) { otherpad = mulawenc->srcpad; - base_caps = gst_caps_new_simple ("audio/x-mulaw", NULL); } else { otherpad = mulawenc->sinkpad; - 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_pad_set_caps (otherpad, base_caps); + gst_caps_unref (base_caps); - gst_caps_free (base_caps); - - return link_return; + return TRUE; } GType @@ -176,41 +184,37 @@ gst_mulawenc_init (GstMuLawEnc * mulawenc) { mulawenc->sinkpad = gst_pad_new_from_template (mulawenc_sink_template, "sink"); - gst_pad_set_link_function (mulawenc->sinkpad, mulawenc_link); + gst_pad_set_setcaps_function (mulawenc->sinkpad, mulawenc_setcaps); gst_pad_set_getcaps_function (mulawenc->sinkpad, mulawenc_getcaps); gst_pad_set_chain_function (mulawenc->sinkpad, gst_mulawenc_chain); gst_element_add_pad (GST_ELEMENT (mulawenc), mulawenc->sinkpad); mulawenc->srcpad = gst_pad_new_from_template (mulawenc_src_template, "src"); - gst_pad_set_link_function (mulawenc->srcpad, mulawenc_link); + gst_pad_set_setcaps_function (mulawenc->srcpad, mulawenc_setcaps); gst_pad_set_getcaps_function (mulawenc->srcpad, mulawenc_getcaps); gst_element_add_pad (GST_ELEMENT (mulawenc), mulawenc->srcpad); } -static void -gst_mulawenc_chain (GstPad * pad, GstData * _data) +static GstFlowReturn +gst_mulawenc_chain (GstPad * pad, GstBuffer * buffer) { - GstBuffer *buf = GST_BUFFER (_data); GstMuLawEnc *mulawenc; 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); - mulawenc = GST_MULAWENC (GST_OBJECT_PARENT (pad)); - g_return_if_fail (mulawenc != NULL); - g_return_if_fail (GST_IS_MULAWENC (mulawenc)); - linear_data = (gint16 *) 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); + linear_data = (gint16 *) 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 (mulawenc->srcpad)); mulaw_data = (gint8 *) GST_BUFFER_DATA (outbuf); + mulaw_encode (linear_data, mulaw_data, GST_BUFFER_SIZE (outbuf)); - gst_buffer_unref (buf); - gst_pad_push (mulawenc->srcpad, GST_DATA (outbuf)); + gst_buffer_unref (buffer); + + return gst_pad_push (mulawenc->srcpad, outbuf); } |