Commit bfcf84a3 authored by Olivier Crete's avatar Olivier Crete Committed by Sebastian Dröge

alaw/mulaw: Implement _getcaps function for alaw/mulaw decoders

Fixes bug #572358.
parent b3a90202
......@@ -145,6 +145,57 @@ gst_alaw_dec_sink_setcaps (GstPad * pad, GstCaps * caps)
return ret;
}
static GstCaps *
gst_alaw_dec_getcaps (GstPad * pad)
{
GstALawDec *alawdec;
GstPad *otherpad;
GstCaps *base_caps, *othercaps;
alawdec = GST_ALAW_DEC (GST_PAD_PARENT (pad));
base_caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
if (pad == alawdec->srcpad) {
otherpad = alawdec->sinkpad;
} else {
otherpad = alawdec->srcpad;
}
othercaps = gst_pad_peer_get_caps (otherpad);
if (othercaps) {
GstStructure *structure;
const GValue *orate, *ochans;
const GValue *rate, *chans;
GValue irate = { 0 };
GValue ichans = { 0 };
if (gst_caps_is_empty (othercaps) || gst_caps_is_any (othercaps))
goto done;
structure = gst_caps_get_structure (othercaps, 0);
orate = gst_structure_get_value (structure, "rate");
ochans = gst_structure_get_value (structure, "channels");
structure = gst_caps_get_structure (base_caps, 0);
rate = gst_structure_get_value (structure, "rate");
chans = gst_structure_get_value (structure, "channels");
if (orate) {
gst_value_intersect (&irate, orate, rate);
gst_structure_set_value (structure, "rate", &irate);
}
if (ochans) {
gst_value_intersect (&ichans, ochans, chans);
gst_structure_set_value (structure, "channels", &ichans);
}
done:
gst_caps_unref (othercaps);
}
return base_caps;
}
static void
gst_alaw_dec_base_init (gpointer klass)
{
......@@ -177,6 +228,8 @@ gst_alaw_dec_init (GstALawDec * alawdec, GstALawDecClass * klass)
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_chain_function (alawdec->sinkpad,
GST_DEBUG_FUNCPTR (gst_alaw_dec_chain));
gst_element_add_pad (GST_ELEMENT (alawdec), alawdec->sinkpad);
......@@ -184,6 +237,8 @@ gst_alaw_dec_init (GstALawDec * alawdec, GstALawDecClass * klass)
alawdec->srcpad =
gst_pad_new_from_static_template (&alaw_dec_src_factory, "src");
gst_pad_use_fixed_caps (alawdec->srcpad);
gst_pad_set_getcaps_function (alawdec->srcpad,
GST_DEBUG_FUNCPTR (gst_alaw_dec_getcaps));
gst_element_add_pad (GST_ELEMENT (alawdec), alawdec->srcpad);
}
......
......@@ -88,6 +88,57 @@ mulawdec_sink_setcaps (GstPad * pad, GstCaps * caps)
return ret;
}
static GstCaps *
mulawdec_getcaps (GstPad * pad)
{
GstMuLawDec *mulawdec;
GstPad *otherpad;
GstCaps *base_caps, *othercaps;
mulawdec = GST_MULAWDEC (GST_PAD_PARENT (pad));
base_caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
if (pad == mulawdec->srcpad) {
otherpad = mulawdec->sinkpad;
} else {
otherpad = mulawdec->srcpad;
}
othercaps = gst_pad_peer_get_caps (otherpad);
if (othercaps) {
GstStructure *structure;
const GValue *orate, *ochans;
const GValue *rate, *chans;
GValue irate = { 0 };
GValue ichans = { 0 };
if (gst_caps_is_empty (othercaps) || gst_caps_is_any (othercaps))
goto done;
structure = gst_caps_get_structure (othercaps, 0);
orate = gst_structure_get_value (structure, "rate");
ochans = gst_structure_get_value (structure, "channels");
structure = gst_caps_get_structure (base_caps, 0);
rate = gst_structure_get_value (structure, "rate");
chans = gst_structure_get_value (structure, "channels");
if (orate) {
gst_value_intersect (&irate, orate, rate);
gst_structure_set_value (structure, "rate", &irate);
}
if (ochans) {
gst_value_intersect (&ichans, ochans, chans);
gst_structure_set_value (structure, "channels", &ichans);
}
done:
gst_caps_unref (othercaps);
}
return base_caps;
}
GType
gst_mulawdec_get_type (void)
{
......@@ -146,12 +197,14 @@ gst_mulawdec_init (GstMuLawDec * mulawdec)
mulawdec->sinkpad =
gst_pad_new_from_static_template (&mulaw_dec_sink_factory, "sink");
gst_pad_set_setcaps_function (mulawdec->sinkpad, mulawdec_sink_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_static_template (&mulaw_dec_src_factory, "src");
gst_pad_use_fixed_caps (mulawdec->srcpad);
gst_pad_set_getcaps_function (mulawdec->srcpad, mulawdec_getcaps);
gst_element_add_pad (GST_ELEMENT (mulawdec), mulawdec->srcpad);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment