inputselector: Protect against pad-parent disappearing

This commit is contained in:
Havard Graff 2011-04-01 08:46:14 +02:00 committed by Sebastian Dröge
parent c19f44e1d2
commit 297407438a

View file

@ -122,8 +122,8 @@ static inline gboolean gst_input_selector_is_active_sinkpad (GstInputSelector *
sel, GstPad * pad); sel, GstPad * pad);
static GstPad *gst_input_selector_activate_sinkpad (GstInputSelector * sel, static GstPad *gst_input_selector_activate_sinkpad (GstInputSelector * sel,
GstPad * pad); GstPad * pad);
static GstPad *gst_input_selector_get_linked_pad (GstPad * pad, static GstPad *gst_input_selector_get_linked_pad (GstInputSelector * sel,
gboolean strict); GstPad * pad, gboolean strict);
#define GST_TYPE_SELECTOR_PAD \ #define GST_TYPE_SELECTOR_PAD \
(gst_selector_pad_get_type()) (gst_selector_pad_get_type())
@ -356,11 +356,15 @@ gst_selector_pad_reset (GstSelectorPad * pad)
static GstIterator * static GstIterator *
gst_selector_pad_iterate_linked_pads (GstPad * pad) gst_selector_pad_iterate_linked_pads (GstPad * pad)
{ {
GstInputSelector *sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad)); GstInputSelector *sel;
GstPad *otherpad; GstPad *otherpad;
GstIterator *it; GstIterator *it;
otherpad = gst_input_selector_get_linked_pad (pad, TRUE); sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
if (G_UNLIKELY (sel == NULL))
return NULL;
otherpad = gst_input_selector_get_linked_pad (sel, pad, TRUE);
it = gst_iterator_new_single (GST_TYPE_PAD, otherpad, it = gst_iterator_new_single (GST_TYPE_PAD, otherpad,
(GstCopyFunction) gst_object_ref, (GFreeFunc) gst_object_unref); (GstCopyFunction) gst_object_ref, (GFreeFunc) gst_object_unref);
@ -1145,13 +1149,11 @@ gst_input_selector_get_property (GObject * object, guint prop_id,
} }
static GstPad * static GstPad *
gst_input_selector_get_linked_pad (GstPad * pad, gboolean strict) gst_input_selector_get_linked_pad (GstInputSelector * sel, GstPad * pad,
gboolean strict)
{ {
GstInputSelector *sel;
GstPad *otherpad = NULL; GstPad *otherpad = NULL;
sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
GST_INPUT_SELECTOR_LOCK (sel); GST_INPUT_SELECTOR_LOCK (sel);
if (pad == sel->srcpad) if (pad == sel->srcpad)
otherpad = sel->active_sinkpad; otherpad = sel->active_sinkpad;
@ -1161,25 +1163,29 @@ gst_input_selector_get_linked_pad (GstPad * pad, gboolean strict)
gst_object_ref (otherpad); gst_object_ref (otherpad);
GST_INPUT_SELECTOR_UNLOCK (sel); GST_INPUT_SELECTOR_UNLOCK (sel);
gst_object_unref (sel);
return otherpad; return otherpad;
} }
static gboolean static gboolean
gst_input_selector_event (GstPad * pad, GstEvent * event) gst_input_selector_event (GstPad * pad, GstEvent * event)
{ {
GstInputSelector *sel;
gboolean res = FALSE; gboolean res = FALSE;
GstPad *otherpad; GstPad *otherpad;
otherpad = gst_input_selector_get_linked_pad (pad, TRUE); sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
if (G_UNLIKELY (sel == NULL))
return FALSE;
otherpad = gst_input_selector_get_linked_pad (sel, pad, TRUE);
if (otherpad) { if (otherpad) {
res = gst_pad_push_event (otherpad, event); res = gst_pad_push_event (otherpad, event);
gst_object_unref (otherpad); gst_object_unref (otherpad);
} else } else
gst_event_unref (event); gst_event_unref (event);
gst_object_unref (sel);
return res; return res;
} }
@ -1193,8 +1199,10 @@ gst_input_selector_query (GstPad * pad, GstQuery * query)
GstPad *otherpad; GstPad *otherpad;
sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad)); sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
if (G_UNLIKELY (sel == NULL))
return FALSE;
otherpad = gst_input_selector_get_linked_pad (pad, TRUE); otherpad = gst_input_selector_get_linked_pad (sel, pad, TRUE);
switch (GST_QUERY_TYPE (query)) { switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_LATENCY: case GST_QUERY_LATENCY:
@ -1270,12 +1278,14 @@ static GstCaps *
gst_input_selector_getcaps (GstPad * pad) gst_input_selector_getcaps (GstPad * pad)
{ {
GstPad *otherpad; GstPad *otherpad;
GstObject *parent; GstInputSelector *sel;
GstCaps *caps; GstCaps *caps;
parent = gst_object_get_parent (GST_OBJECT (pad)); sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
if (G_UNLIKELY (sel == NULL))
return FALSE;
otherpad = gst_input_selector_get_linked_pad (pad, FALSE); otherpad = gst_input_selector_get_linked_pad (sel, pad, FALSE);
if (!otherpad) { if (!otherpad) {
GST_DEBUG_OBJECT (pad, "Pad not linked, returning ANY"); GST_DEBUG_OBJECT (pad, "Pad not linked, returning ANY");
@ -1290,7 +1300,7 @@ gst_input_selector_getcaps (GstPad * pad)
gst_object_unref (otherpad); gst_object_unref (otherpad);
} }
gst_object_unref (parent); gst_object_unref (sel);
return caps; return caps;
} }