From 1f00cce2f797ff3b0cb8105a91b7f9a87a855c6f Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Mon, 2 Aug 2004 09:16:14 +0000 Subject: [PATCH] add link function. fixes @148986 Original commit message from CVS: add link function. fixes @148986 --- ext/lame/gstlame.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/ext/lame/gstlame.c b/ext/lame/gstlame.c index 08346eb1b1..b3e63e3f09 100644 --- a/ext/lame/gstlame.c +++ b/ext/lame/gstlame.c @@ -346,6 +346,51 @@ gst_lame_class_init (GstLameClass * klass) gstelement_class->change_state = gst_lame_change_state; } +static GstPadLinkReturn +gst_lame_src_link (GstPad * pad, const GstCaps * caps) +{ + GstLame *lame; + gint out_samplerate; + GstStructure *structure; + GstCaps *othercaps, *channelcaps; + GstPadLinkReturn result; + + lame = GST_LAME (gst_pad_get_parent (pad)); + structure = gst_caps_get_structure (caps, 0); + + if (!gst_structure_get_int (structure, "rate", &out_samplerate) || + !gst_structure_get_int (structure, "channels", &lame->num_channels)) + g_return_val_if_reached (GST_PAD_LINK_REFUSED); + + if (lame_set_out_samplerate (lame->lgf, out_samplerate) != 0) + return GST_PAD_LINK_REFUSED; + + /* we don't do channel conversion */ + channelcaps = gst_caps_new_simple ("audio/x-raw-int", "chnnels", G_TYPE_INT, + lame->num_channels, NULL); + othercaps = gst_caps_intersect (gst_pad_get_pad_template_caps (lame->sinkpad), + channelcaps); + gst_caps_free (channelcaps); + + result = gst_pad_try_set_caps_nonfixed (lame->sinkpad, othercaps); + + if (GST_PAD_LINK_FAILED (result)) + return result; + + caps = gst_pad_get_negotiated_caps (lame->sinkpad); + structure = gst_caps_get_structure (caps, 0); + if (!gst_structure_get_int (structure, "rate", &lame->samplerate)) + g_return_val_if_reached (GST_PAD_LINK_REFUSED); + + if (!gst_lame_setup (lame)) { + GST_ELEMENT_ERROR (lame, CORE, NEGOTIATION, (NULL), + ("could not initialize encoder (wrong parameters?)")); + return GST_PAD_LINK_REFUSED; + } + + return result; +} + static GstPadLinkReturn gst_lame_sink_link (GstPad * pad, const GstCaps * caps) { @@ -394,6 +439,7 @@ gst_lame_init (GstLame * lame) gst_pad_new_from_template (gst_static_pad_template_get (&gst_lame_src_template), "src"); gst_element_add_pad (GST_ELEMENT (lame), lame->srcpad); + gst_pad_set_link_function (lame->srcpad, gst_lame_src_link); GST_FLAG_SET (lame, GST_ELEMENT_EVENT_AWARE);