plugins/elements/gstinputselector.c: Reuse the get_linked_pads for both source and sinkpads because they are the same.

Original commit message from CVS:
* plugins/elements/gstinputselector.c: (gst_input_selector_init),
(gst_input_selector_event), (gst_input_selector_query):
Reuse the get_linked_pads for both source and sinkpads because they are
the same.
Implement a custum event handler and get the internally linked pad
directly instead of relying on the default (slower) implementation.
This commit is contained in:
Wim Taymans 2008-09-01 13:23:03 +00:00 committed by Tim-Philipp Müller
parent a7cd6eeb61
commit f7dad96f47

View file

@ -656,8 +656,8 @@ static void gst_input_selector_release_pad (GstElement * element, GstPad * pad);
static GstStateChangeReturn gst_input_selector_change_state (GstElement * static GstStateChangeReturn gst_input_selector_change_state (GstElement *
element, GstStateChange transition); element, GstStateChange transition);
static GList *gst_input_selector_get_linked_pads (GstPad * pad);
static GstCaps *gst_input_selector_getcaps (GstPad * pad); static GstCaps *gst_input_selector_getcaps (GstPad * pad);
static gboolean gst_input_selector_event (GstPad * pad, GstEvent * event);
static gboolean gst_input_selector_query (GstPad * pad, GstQuery * query); static gboolean gst_input_selector_query (GstPad * pad, GstQuery * query);
static gint64 gst_input_selector_block (GstInputSelector * self); static gint64 gst_input_selector_block (GstInputSelector * self);
static void gst_input_selector_switch (GstInputSelector * self, static void gst_input_selector_switch (GstInputSelector * self,
@ -807,11 +807,13 @@ gst_input_selector_init (GstInputSelector * sel)
{ {
sel->srcpad = gst_pad_new ("src", GST_PAD_SRC); sel->srcpad = gst_pad_new ("src", GST_PAD_SRC);
gst_pad_set_internal_link_function (sel->srcpad, gst_pad_set_internal_link_function (sel->srcpad,
GST_DEBUG_FUNCPTR (gst_input_selector_get_linked_pads)); GST_DEBUG_FUNCPTR (gst_selector_pad_get_linked_pads));
gst_pad_set_getcaps_function (sel->srcpad, gst_pad_set_getcaps_function (sel->srcpad,
GST_DEBUG_FUNCPTR (gst_input_selector_getcaps)); GST_DEBUG_FUNCPTR (gst_input_selector_getcaps));
gst_pad_set_query_function (sel->srcpad, gst_pad_set_query_function (sel->srcpad,
GST_DEBUG_FUNCPTR (gst_input_selector_query)); GST_DEBUG_FUNCPTR (gst_input_selector_query));
gst_pad_set_event_function (sel->srcpad,
GST_DEBUG_FUNCPTR (gst_input_selector_event));
gst_element_add_pad (GST_ELEMENT (sel), sel->srcpad); gst_element_add_pad (GST_ELEMENT (sel), sel->srcpad);
/* sinkpad management */ /* sinkpad management */
sel->active_sinkpad = NULL; sel->active_sinkpad = NULL;
@ -1011,6 +1013,21 @@ gst_input_selector_get_linked_pad (GstPad * pad, gboolean strict)
return otherpad; return otherpad;
} }
static gboolean
gst_input_selector_event (GstPad * pad, GstEvent * event)
{
gboolean res;
GstPad *otherpad;
otherpad = gst_input_selector_get_linked_pad (pad, TRUE);
res = gst_pad_push_event (otherpad, event);
gst_object_unref (otherpad);
return res;
}
/* query on the srcpad. We override this function because by default it will /* query on the srcpad. We override this function because by default it will
* only forward the query to one random sinkpad */ * only forward the query to one random sinkpad */
static gboolean static gboolean
@ -1018,9 +1035,12 @@ gst_input_selector_query (GstPad * pad, GstQuery * query)
{ {
gboolean res; gboolean res;
GstInputSelector *sel; GstInputSelector *sel;
GstPad *otherpad;
sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad)); sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
otherpad = gst_input_selector_get_linked_pad (pad, TRUE);
switch (GST_QUERY_TYPE (query)) { switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_LATENCY: case GST_QUERY_LATENCY:
{ {
@ -1080,9 +1100,10 @@ gst_input_selector_query (GstPad * pad, GstQuery * query)
break; break;
} }
default: default:
res = gst_pad_query_default (pad, query); res = gst_pad_peer_query (otherpad, query);
break; break;
} }
gst_object_unref (otherpad);
gst_object_unref (sel); gst_object_unref (sel);
return res; return res;
@ -1162,19 +1183,6 @@ gst_input_selector_activate_sinkpad (GstInputSelector * sel, GstPad * pad)
return active_sinkpad; return active_sinkpad;
} }
static GList *
gst_input_selector_get_linked_pads (GstPad * pad)
{
GstPad *otherpad;
otherpad = gst_input_selector_get_linked_pad (pad, TRUE);
if (!otherpad)
return NULL;
/* need to drop the ref, internal linked pads is not MT safe */
gst_object_unref (otherpad);
return g_list_append (NULL, otherpad);
}
static GstPad * static GstPad *
gst_input_selector_request_new_pad (GstElement * element, gst_input_selector_request_new_pad (GstElement * element,
GstPadTemplate * templ, const gchar * unused) GstPadTemplate * templ, const gchar * unused)