+static gboolean
+gst_pipeline_do_latency (GstBin * bin)
+{
+ GstPipeline *pipeline = GST_PIPELINE (bin);
+ GstQuery *query;
+ GstClockTime latency;
+ GstClockTime min_latency, max_latency;
+ gboolean res;
+
+ GST_OBJECT_LOCK (pipeline);
+ latency = pipeline->priv->latency;
+ GST_OBJECT_UNLOCK (pipeline);
+
+ if (latency == GST_CLOCK_TIME_NONE)
+ return GST_BIN_CLASS (parent_class)->do_latency (bin);
+
+ GST_DEBUG_OBJECT (pipeline, "querying latency");
+
+ query = gst_query_new_latency ();
+ if ((res = gst_element_query (GST_ELEMENT_CAST (pipeline), query))) {
+ gboolean live;
+
+ gst_query_parse_latency (query, &live, &min_latency, &max_latency);
+
+ GST_DEBUG_OBJECT (pipeline,
+ "got min latency %" GST_TIME_FORMAT ", max latency %"
+ GST_TIME_FORMAT ", live %d", GST_TIME_ARGS (min_latency),
+ GST_TIME_ARGS (max_latency), live);
+
+ if (max_latency < min_latency) {
+ /* this is an impossible situation, some parts of the pipeline might not
+ * work correctly. We post a warning for now. */
+ GST_ELEMENT_WARNING (pipeline, CORE, CLOCK, (NULL),
+ ("Impossible to configure latency: max %" GST_TIME_FORMAT " < min %"
+ GST_TIME_FORMAT ". Add queues or other buffering elements.",
+ GST_TIME_ARGS (max_latency), GST_TIME_ARGS (min_latency)));
+ }
+
+ if (latency < min_latency) {
+ /* This is a problematic situation as we will most likely drop lots of
+ * data if we configure a too low latency */
+ GST_ELEMENT_WARNING (pipeline, CORE, CLOCK, (NULL),
+ ("Configured latency is lower than detected minimum latency: configured %"
+ GST_TIME_FORMAT " < min %" GST_TIME_FORMAT,
+ GST_TIME_ARGS (latency), GST_TIME_ARGS (min_latency)));
+ }
+ } else {
+ /* this is not a real problem, we just don't configure any latency. */
+ GST_WARNING_OBJECT (pipeline, "failed to query latency");
+ }
+ gst_query_unref (query);
+
+
+ /* configure latency on elements */
+ res =
+ gst_element_send_event (GST_ELEMENT_CAST (pipeline),
+ gst_event_new_latency (latency));
+ if (res) {
+ GST_INFO_OBJECT (pipeline, "configured latency of %" GST_TIME_FORMAT,
+ GST_TIME_ARGS (latency));
+ } else {
+ GST_WARNING_OBJECT (pipeline,
+ "did not really configure latency of %" GST_TIME_FORMAT,
+ GST_TIME_ARGS (latency));
+ }
+
+ return res;
+}
+