From e33286298591eb805a59a398667d247180c6395d Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 14 Mar 2012 16:27:31 +0100 Subject: [PATCH] pad: implement DRAIN handling When we forward the DRAIN query and there is nothing to forward it to, assume we are drained. When a basesink receives a drain query, reply with TRUE. --- gst/gstpad.c | 42 ++++++++++++++++++++++++++++++++++++++++-- libs/gst/base/gstbasesink.c | 3 +++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/gst/gstpad.c b/gst/gstpad.c index 9cafd95..ea4796a 100644 --- a/gst/gstpad.c +++ b/gst/gstpad.c @@ -2757,6 +2757,29 @@ filter_done: return TRUE; } +typedef struct +{ + GstQuery *query; + gboolean result; + gboolean dispatched; +} QueryData; + +static gboolean +query_forward_func (GstPad * pad, QueryData * data) +{ + /* for each pad we send to, we should ref the query; it's up + * to downstream to unref again when handled. */ + GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s", + data->query, GST_EVENT_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad)); + + data->result |= gst_pad_peer_query (pad, data->query); + + data->dispatched = TRUE; + + /* stop on first successful reply */ + return data->result; +} + /** * gst_pad_query_default: * @pad: a #GstPad to call the default query handler on. @@ -2804,8 +2827,23 @@ gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query) } if (forward) { - ret = gst_pad_forward - (pad, (GstPadForwardFunction) gst_pad_peer_query, query); + QueryData data; + + data.query = query; + data.dispatched = FALSE; + data.result = FALSE; + + gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data); + + if (data.dispatched) { + ret = data.result; + } else { + /* nothing dispatched, could be drained */ + if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN) + ret = TRUE; + else + ret = FALSE; + } } return ret; } diff --git a/libs/gst/base/gstbasesink.c b/libs/gst/base/gstbasesink.c index 6dcdb91..151015d 100644 --- a/libs/gst/base/gstbasesink.c +++ b/libs/gst/base/gstbasesink.c @@ -4550,6 +4550,9 @@ gst_base_sink_default_query (GstBaseSink * basesink, GstQuery * query) res = TRUE; break; } + case GST_QUERY_DRAIN: + res = TRUE; + break; default: res = gst_pad_query_default (basesink->sinkpad, GST_OBJECT_CAST (basesink), -- 2.7.4