diff options
author | Olivier Crete <olivier.crete@collabora.co.uk> | 2008-05-15 01:21:42 +0000 |
---|---|---|
committer | Edward Hervey <bilboed@bilboed.com> | 2009-02-17 19:29:06 +0100 |
commit | 72ca8467eb7a8c52c964039bc13b857c0d4b96c7 (patch) | |
tree | 4930b0352b8d99b273ddb17ca01f0a1204df91d1 /gst | |
parent | 3c835d5536e6a93583f3710e146988e54dcb521d (diff) | |
download | gst-plugins-bad-72ca8467eb7a8c52c964039bc13b857c0d4b96c7.tar.gz gst-plugins-bad-72ca8467eb7a8c52c964039bc13b857c0d4b96c7.tar.bz2 gst-plugins-bad-72ca8467eb7a8c52c964039bc13b857c0d4b96c7.zip |
[MOVED FROM GST-P-FARSIGHT] Add duration query from adder
20080515012142-3e2dc-2768199183bfb9d569be1389e382bedc02e3e95e.gz
Diffstat (limited to 'gst')
-rw-r--r-- | gst/liveadder/liveadder.c | 78 |
1 files changed, 78 insertions, 0 deletions
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; |