diff options
author | Ronald S. Bultje <rbultje@ronald.bitfreak.net> | 2004-03-26 01:56:11 +0000 |
---|---|---|
committer | Ronald S. Bultje <rbultje@ronald.bitfreak.net> | 2004-03-26 01:56:11 +0000 |
commit | 920ad8773bb23016eb882b1a23c665032a82b243 (patch) | |
tree | 4ccb58d00b979086cbf5751b8faa3258d7cadef2 /gst/law/mulaw-decode.c | |
parent | d21f04ca6fb0e4d3f912834542aa13d0d79fdf94 (diff) |
gst/law/: Fix capsnego in all four, remove the unused property functions and simplify the chain functions slightly. I...
Original commit message from CVS:
* gst/law/alaw-decode.c: (alawdec_getcaps), (alawdec_link),
(gst_alawdec_base_init), (gst_alawdec_class_init),
(gst_alawdec_init), (gst_alawdec_chain):
* gst/law/alaw-encode.c: (alawenc_getcaps), (alawenc_link),
(gst_alawenc_base_init), (gst_alawenc_class_init),
(gst_alawenc_init), (gst_alawenc_chain):
* gst/law/mulaw-decode.c: (mulawdec_getcaps), (mulawdec_link),
(gst_mulawdec_base_init), (gst_mulawdec_class_init),
(gst_mulawdec_init), (gst_mulawdec_chain):
* gst/law/mulaw-encode.c: (mulawenc_getcaps), (mulawenc_link),
(gst_mulawenc_base_init), (gst_mulawenc_class_init),
(gst_mulawenc_init), (gst_mulawenc_chain):
Fix capsnego in all four, remove the unused property functions and
simplify the chain functions slightly. I guess we could use macros
or something similar for those, since the code is so similar, but
I'm currently too lazy...
Diffstat (limited to 'gst/law/mulaw-decode.c')
-rw-r--r-- | gst/law/mulaw-decode.c | 151 |
1 files changed, 73 insertions, 78 deletions
diff --git a/gst/law/mulaw-decode.c b/gst/law/mulaw-decode.c index 807dd280..46d02730 100644 --- a/gst/law/mulaw-decode.c +++ b/gst/law/mulaw-decode.c @@ -26,14 +26,6 @@ extern GstPadTemplate *mulawdec_src_template, *mulawdec_sink_template; -/* elementfactory information */ -static GstElementDetails mulawdec_details = { - "Mu Law to PCM conversion", - "Codec/Decoder/Audio", - "Convert 8bit mu law to 16bit PCM", - "Zaheer Merali <zaheer@bellworldwide.net>" -}; - /* Stereo signals and args */ enum { @@ -50,43 +42,79 @@ 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_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec); -static void gst_mulawdec_get_property (GObject * object, guint prop_id, - GValue * value, GParamSpec * pspec); - static void gst_mulawdec_chain (GstPad * pad, GstData * _data); - static GstElementClass *parent_class = NULL; /*static guint gst_stereo_signals[LAST_SIGNAL] = { 0 };*/ +static GstCaps * +mulawdec_getcaps (GstPad * pad) +{ + GstMuLawDec *mulawdec = GST_MULAWDEC (gst_pad_get_parent (pad)); + GstPad *otherpad; + GstCaps *base_caps, *othercaps; + GstStructure *structure; + const GValue *rate, *chans; + + 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, + "endianness", G_TYPE_INT, G_BYTE_ORDER, 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); + + return base_caps; +} static GstPadLinkReturn mulawdec_link (GstPad * pad, const GstCaps * caps) { - GstCaps *tempcaps; - gint rate, channels; + GstMuLawDec *mulawdec = GST_MULAWDEC (gst_pad_get_parent (pad)); + GstPad *otherpad; GstStructure *structure; - gboolean ret; - - GstMuLawDec *mulawdec = GST_MULAWDEC (GST_OBJECT_PARENT (pad)); + const GValue *rate, *chans; + GstCaps *base_caps; structure = gst_caps_get_structure (caps, 0); - ret = gst_structure_get_int (structure, "rate", &rate); - ret = gst_structure_get_int (structure, "channels", &channels); - if (!ret) + rate = gst_structure_get_value (structure, "rate"); + chans = gst_structure_get_value (structure, "channels"); + if (!rate || !chans) return GST_PAD_LINK_REFUSED; - tempcaps = gst_caps_new_simple ("audio/x-raw-int", - "depth", G_TYPE_INT, 16, - "width", G_TYPE_INT, 16, - "signed", G_TYPE_BOOLEAN, TRUE, - "endianness", G_TYPE_INT, G_BYTE_ORDER, - "rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, channels, NULL); + 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, NULL); + } - return gst_pad_try_set_caps (mulawdec->srcpad, tempcaps); + structure = gst_caps_get_structure (base_caps, 0); + gst_structure_set_value (structure, "rate", rate); + gst_structure_set_value (structure, "channels", chans); + + return gst_pad_try_set_caps (otherpad, base_caps); } GType @@ -118,6 +146,12 @@ static void gst_mulawdec_base_init (GstMuLawDecClass * klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); + GstElementDetails mulawdec_details = { + "Mu Law to PCM conversion", + "Codec/Decoder/Audio", + "Convert 8bit mu law to 16bit PCM", + "Zaheer Merali <zaheer@bellworldwide.net>" + }; gst_element_class_add_pad_template (element_class, mulawdec_src_template); gst_element_class_add_pad_template (element_class, mulawdec_sink_template); @@ -127,16 +161,7 @@ gst_mulawdec_base_init (GstMuLawDecClass * klass) static void gst_mulawdec_class_init (GstMuLawDecClass * klass) { - GObjectClass *gobject_class; - GstElementClass *gstelement_class; - - gobject_class = (GObjectClass *) klass; - gstelement_class = (GstElementClass *) klass; - parent_class = g_type_class_ref (GST_TYPE_ELEMENT); - - gobject_class->set_property = gst_mulawdec_set_property; - gobject_class->get_property = gst_mulawdec_get_property; } static void @@ -144,11 +169,14 @@ gst_mulawdec_init (GstMuLawDec * mulawdec) { mulawdec->sinkpad = gst_pad_new_from_template (mulawdec_sink_template, "sink"); - mulawdec->srcpad = gst_pad_new_from_template (mulawdec_src_template, "src"); gst_pad_set_link_function (mulawdec->sinkpad, mulawdec_link); - - gst_element_add_pad (GST_ELEMENT (mulawdec), mulawdec->sinkpad); + 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_getcaps_function (mulawdec->srcpad, mulawdec_getcaps); gst_element_add_pad (GST_ELEMENT (mulawdec), mulawdec->srcpad); } @@ -170,46 +198,13 @@ gst_mulawdec_chain (GstPad * pad, GstData * _data) g_return_if_fail (GST_IS_MULAWDEC (mulawdec)); mulaw_data = (guint8 *) GST_BUFFER_DATA (buf); - outbuf = gst_buffer_new (); - GST_BUFFER_DATA (outbuf) = (gchar *) g_new (gint16, GST_BUFFER_SIZE (buf)); - GST_BUFFER_SIZE (outbuf) = GST_BUFFER_SIZE (buf) * 2; - + 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 (outbuf); + mulaw_decode (mulaw_data, linear_data, GST_BUFFER_SIZE (buf)); gst_buffer_unref (buf); gst_pad_push (mulawdec->srcpad, GST_DATA (outbuf)); } - -static void -gst_mulawdec_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec) -{ - GstMuLawDec *mulawdec; - - /* it's not null if we got it, but it might not be ours */ - g_return_if_fail (GST_IS_MULAWDEC (object)); - mulawdec = GST_MULAWDEC (object); - - switch (prop_id) { - default: - break; - } -} - -static void -gst_mulawdec_get_property (GObject * object, guint prop_id, GValue * value, - GParamSpec * pspec) -{ - GstMuLawDec *mulawdec; - - /* it's not null if we got it, but it might not be ours */ - g_return_if_fail (GST_IS_MULAWDEC (object)); - mulawdec = GST_MULAWDEC (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} |