From af6e6cf1cc2d566dd98ca3f26587ed29ffe2b8d9 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 24 Sep 2007 12:29:23 +0000 Subject: [PATCH] libs/gst/base/gstbasesink.c: Simplify latency query. Original commit message from CVS: * libs/gst/base/gstbasesink.c: (gst_base_sink_query_latency), (gst_base_sink_event), (gst_base_sink_query), (gst_base_sink_change_state): Simplify latency query. When not synchronizing, we can report latency without querying the peer element. --- ChangeLog | 9 +++++ libs/gst/base/gstbasesink.c | 74 ++++++++++++++++--------------------- 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0449b1b51b..c79f05c297 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-09-24 Wim Taymans + + * libs/gst/base/gstbasesink.c: (gst_base_sink_query_latency), + (gst_base_sink_event), (gst_base_sink_query), + (gst_base_sink_change_state): + Simplify latency query. + When not synchronizing, we can report latency without querying the peer + element. + 2007-09-24 Wim Taymans * gst/gstobject.h: diff --git a/libs/gst/base/gstbasesink.c b/libs/gst/base/gstbasesink.c index d466128c49..687d8e34f9 100644 --- a/libs/gst/base/gstbasesink.c +++ b/libs/gst/base/gstbasesink.c @@ -833,37 +833,47 @@ gst_base_sink_query_latency (GstBaseSink * sink, gboolean * live, gboolean * upstream_live, GstClockTime * min_latency, GstClockTime * max_latency) { - gboolean l, us_live, res; + gboolean l, us_live, res, have_latency; GstClockTime min, max; GstQuery *query; GstClockTime us_min, us_max; /* we are live when we sync to the clock */ - l = gst_base_sink_get_sync (sink); + GST_OBJECT_LOCK (sink); + l = sink->sync; + have_latency = sink->priv->have_latency; + GST_OBJECT_UNLOCK (sink); /* assume no latency */ min = 0; max = -1; us_live = FALSE; + res = TRUE; - query = gst_query_new_latency (); + /* we are live and we are prerolled, do upstream query to get the total + * picture */ + if (l && have_latency) { + query = gst_query_new_latency (); - /* ask the peer for the latency */ - if (!(res = gst_base_sink_peer_query (sink, query))) - goto query_failed; + /* ask the peer for the latency */ + if (!(res = gst_base_sink_peer_query (sink, query))) + goto query_failed; - /* get upstream min and max latency */ - gst_query_parse_latency (query, &us_live, &us_min, &us_max); - if (us_live) { - /* upstream live, use its latency, subclasses should use these - * values to create the complete latency. */ - min = us_min; - max = us_max; + /* get upstream min and max latency */ + gst_query_parse_latency (query, &us_live, &us_min, &us_max); + gst_query_unref (query); + + if (us_live) { + /* upstream live, use its latency, subclasses should use these + * values to create the complete latency. */ + min = us_min; + max = us_max; + } } - GST_DEBUG_OBJECT (sink, "latency query: live: %d, upstream: %d, min %" - GST_TIME_FORMAT ", max %" GST_TIME_FORMAT, l, us_live, - GST_TIME_ARGS (min), GST_TIME_ARGS (max)); + GST_DEBUG_OBJECT (sink, "latency query: live: %d, have_latency %d," + " upstream: %d, min %" GST_TIME_FORMAT ", max %" GST_TIME_FORMAT, l, + have_latency, us_live, GST_TIME_ARGS (min), GST_TIME_ARGS (max)); if (live) *live = l; @@ -874,16 +884,14 @@ gst_base_sink_query_latency (GstBaseSink * sink, gboolean * live, if (max_latency) *max_latency = max; -done: - gst_query_unref (query); - return res; /* ERRORS */ query_failed: { GST_DEBUG_OBJECT (sink, "latency query failed"); - goto done; + gst_query_unref (query); + return FALSE; } } @@ -2950,30 +2958,12 @@ gst_base_sink_query (GstElement * element, GstQuery * query) break; case GST_QUERY_LATENCY: { - gboolean live, us_live, have_latency; + gboolean live, us_live; GstClockTime min, max; - /* we need to be negotiated before we can report caps */ - GST_OBJECT_LOCK (basesink); - have_latency = basesink->priv->have_latency; - GST_OBJECT_UNLOCK (basesink); - - if (!have_latency) { - GST_DEBUG_OBJECT (basesink, "not prerolled yet, can't report latency"); - res = FALSE; - } else { - if ((res = gst_base_sink_query_latency (basesink, &live, &us_live, &min, - &max))) { - /* if we or the upstream elements are not live, we don't need latency - * compensation */ - if (!live || !us_live) { - GST_DEBUG_OBJECT (basesink, - "no latency compensation, we %d, upstream %d", live, us_live); - min = 0; - max = -1; - } - gst_query_set_latency (query, live, min, max); - } + if ((res = gst_base_sink_query_latency (basesink, &live, &us_live, &min, + &max))) { + gst_query_set_latency (query, live, min, max); } break; }