queue[2]: Make src query MT-safe

It is possible that the element might be going down while the event arrives
This commit is contained in:
Havard Graff 2011-03-20 00:56:08 +01:00 committed by Sebastian Dröge
parent 3d833e42b6
commit d092e3b9ff
2 changed files with 16 additions and 4 deletions

View file

@ -1304,17 +1304,24 @@ gst_queue_handle_src_event (GstPad * pad, GstEvent * event)
static gboolean static gboolean
gst_queue_handle_src_query (GstPad * pad, GstQuery * query) gst_queue_handle_src_query (GstPad * pad, GstQuery * query)
{ {
GstQueue *queue = GST_QUEUE (GST_PAD_PARENT (pad)); GstQueue *queue = GST_QUEUE (gst_pad_get_parent (pad));
GstPad *peer; GstPad *peer;
gboolean res; gboolean res;
if (!(peer = gst_pad_get_peer (queue->sinkpad))) if (G_UNLIKELY (queue == NULL))
return FALSE; return FALSE;
if (!(peer = gst_pad_get_peer (queue->sinkpad))) {
gst_object_unref (queue);
return FALSE;
}
res = gst_pad_query (peer, query); res = gst_pad_query (peer, query);
gst_object_unref (peer); gst_object_unref (peer);
if (!res) if (!res) {
gst_object_unref (queue);
return FALSE; return FALSE;
}
switch (GST_QUERY_TYPE (query)) { switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_POSITION: case GST_QUERY_POSITION:
@ -1370,6 +1377,7 @@ gst_queue_handle_src_query (GstPad * pad, GstQuery * query)
break; break;
} }
gst_object_unref (queue);
return TRUE; return TRUE;
} }

View file

@ -2441,7 +2441,9 @@ gst_queue2_handle_src_query (GstPad * pad, GstQuery * query)
{ {
GstQueue2 *queue; GstQueue2 *queue;
queue = GST_QUEUE2 (GST_PAD_PARENT (pad)); queue = GST_QUEUE2 (gst_pad_get_parent (pad));
if (G_UNLIKELY (queue == NULL))
return FALSE;
switch (GST_QUERY_TYPE (query)) { switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_POSITION: case GST_QUERY_POSITION:
@ -2612,12 +2614,14 @@ gst_queue2_handle_src_query (GstPad * pad, GstQuery * query)
break; break;
} }
gst_object_unref (queue);
return TRUE; return TRUE;
/* ERRORS */ /* ERRORS */
peer_failed: peer_failed:
{ {
GST_DEBUG_OBJECT (queue, "failed peer query"); GST_DEBUG_OBJECT (queue, "failed peer query");
gst_object_unref (queue);
return FALSE; return FALSE;
} }
} }