From 72ca8467eb7a8c52c964039bc13b857c0d4b96c7 Mon Sep 17 00:00:00 2001 From: Olivier Crete Date: Thu, 15 May 2008 01:21:42 +0000 Subject: [MOVED FROM GST-P-FARSIGHT] Add duration query from adder 20080515012142-3e2dc-2768199183bfb9d569be1389e382bedc02e3e95e.gz --- gst/liveadder/liveadder.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/gst/liveadder/liveadder.c b/gst/liveadder/liveadder.c index ac039744..c20400bb 100644 --- a/gst/liveadder/liveadder.c +++ b/gst/liveadder/liveadder.c @@ -583,6 +583,81 @@ newseg_wrong_format: } } +/* FIXME: + * + * When we add a new stream (or remove a stream) the duration might + * also become invalid again and we need to post a new DURATION + * message to notify this fact to the parent. + * For now we take the max of all the upstream elements so the simple + * cases work at least somewhat. + */ +static gboolean +gst_live_adder_query_duration (GstLiveAdder * adder, GstQuery * query) +{ + gint64 max; + gboolean res; + GstFormat format; + GstIterator *it; + gboolean done; + + /* parse format */ + gst_query_parse_duration (query, &format, NULL); + + max = -1; + res = TRUE; + done = FALSE; + + it = gst_element_iterate_sink_pads (GST_ELEMENT_CAST (adder)); + while (!done) { + GstIteratorResult ires; + gpointer item; + + ires = gst_iterator_next (it, &item); + switch (ires) { + case GST_ITERATOR_DONE: + done = TRUE; + break; + case GST_ITERATOR_OK: + { + GstPad *pad = GST_PAD_CAST (item); + gint64 duration; + + /* ask sink peer for duration */ + res &= gst_pad_query_peer_duration (pad, &format, &duration); + /* take max from all valid return values */ + if (res) { + /* valid unknown length, stop searching */ + if (duration == -1) { + max = duration; + done = TRUE; + } + /* else see if bigger than current max */ + else if (duration > max) + max = duration; + } + break; + } + case GST_ITERATOR_RESYNC: + max = -1; + res = TRUE; + break; + default: + res = FALSE; + done = TRUE; + break; + } + } + gst_iterator_free (it); + + if (res) { + /* and store the max */ + gst_query_set_duration (query, format, max); + } + + return res; +} + + static gboolean gst_live_adder_query (GstPad * pad, GstQuery * query) { @@ -664,6 +739,9 @@ gst_live_adder_query (GstPad * pad, GstQuery * query) } break; } + case GST_QUERY_DURATION: + res = gst_live_adder_query_duration (adder, query); + break; default: res = gst_pad_query_default (pad, query); break; -- cgit v1.2.1