gst/adder/gstadder.c: Implement latency query.

Original commit message from CVS:
* gst/adder/gstadder.c: (gst_adder_query_duration),
(gst_adder_query_latency), (gst_adder_query):
Implement latency query.
This commit is contained in:
Sebastian Dröge 2008-05-28 08:14:47 +00:00
parent 4ccac97b40
commit 57c3aa9b66
2 changed files with 94 additions and 0 deletions

View file

@ -1,3 +1,9 @@
2008-05-28 Sebastian Dröge <slomo@circular-chaos.org>
* gst/adder/gstadder.c: (gst_adder_query_duration),
(gst_adder_query_latency), (gst_adder_query):
Implement latency query.
2008-05-27 Sebastian Dröge <slomo@circular-chaos.org> 2008-05-27 Sebastian Dröge <slomo@circular-chaos.org>
* gst/adder/gstadder.c: (gst_adder_query_duration): * gst/adder/gstadder.c: (gst_adder_query_duration):

View file

@ -390,12 +390,97 @@ gst_adder_query_duration (GstAdder * adder, GstQuery * query)
if (res) { if (res) {
/* and store the max */ /* and store the max */
GST_DEBUG_OBJECT (adder, "Total duration in format %s: %"
GST_TIME_FORMAT, gst_format_get_name (format), GST_TIME_ARGS (max));
gst_query_set_duration (query, format, max); gst_query_set_duration (query, format, max);
} }
return res; return res;
} }
static gboolean
gst_adder_query_latency (GstAdder * adder, GstQuery * query)
{
GstClockTime min, max;
gboolean live;
gboolean res;
GstIterator *it;
gboolean done;
res = TRUE;
done = FALSE;
live = FALSE;
min = 0;
max = GST_CLOCK_TIME_NONE;
/* Take maximum of all latency values */
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);
GstQuery *peerquery;
GstClockTime min_cur, max_cur;
gboolean live_cur;
peerquery = gst_query_new_latency ();
/* Ask peer for latency */
res &= gst_pad_peer_query (pad, peerquery);
/* take max from all valid return values */
if (res) {
gst_query_parse_latency (peerquery, &live_cur, &min_cur, &max_cur);
if (min_cur > min)
min = min_cur;
if (max_cur != GST_CLOCK_TIME_NONE &&
((max != GST_CLOCK_TIME_NONE && max_cur > max) ||
(max == GST_CLOCK_TIME_NONE)))
max = max_cur;
live = live || live_cur;
}
gst_query_unref (peerquery);
break;
}
case GST_ITERATOR_RESYNC:
live = FALSE;
min = 0;
max = GST_CLOCK_TIME_NONE;
res = TRUE;
gst_iterator_resync (it);
break;
default:
res = FALSE;
done = TRUE;
break;
}
}
gst_iterator_free (it);
if (res) {
/* store the results */
GST_DEBUG_OBJECT (adder, "Calculated total latency: live %s, min %"
GST_TIME_FORMAT ", max %" GST_TIME_FORMAT,
(live ? "yes" : "no"), GST_TIME_ARGS (min), GST_TIME_ARGS (max));
gst_query_set_latency (query, live, min, max);
}
return res;
}
static gboolean static gboolean
gst_adder_query (GstPad * pad, GstQuery * query) gst_adder_query (GstPad * pad, GstQuery * query)
{ {
@ -427,6 +512,9 @@ gst_adder_query (GstPad * pad, GstQuery * query)
case GST_QUERY_DURATION: case GST_QUERY_DURATION:
res = gst_adder_query_duration (adder, query); res = gst_adder_query_duration (adder, query);
break; break;
case GST_QUERY_LATENCY:
res = gst_adder_query_latency (adder, query);
break;
default: default:
/* FIXME, needs a custom query handler because we have multiple /* FIXME, needs a custom query handler because we have multiple
* sinkpads */ * sinkpads */