mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 18:21:04 +00:00
Improve and fix LATENCY query handling
This now follows the design docs everywhere, especially the maximum latency handling. https://bugzilla.gnome.org/show_bug.cgi?id=744106
This commit is contained in:
parent
cdd86d025a
commit
8547594727
8 changed files with 43 additions and 40 deletions
|
@ -887,10 +887,10 @@ gst_app_src_query (GstBaseSrc * src, GstQuery * query)
|
|||
|
||||
/* overwrite with our values when we need to */
|
||||
g_mutex_lock (&priv->mutex);
|
||||
if (priv->min_latency != -1)
|
||||
if (priv->min_latency != -1) {
|
||||
min = priv->min_latency;
|
||||
if (priv->max_latency != -1)
|
||||
max = priv->max_latency;
|
||||
}
|
||||
g_mutex_unlock (&priv->mutex);
|
||||
|
||||
gst_query_set_latency (query, live, min, max);
|
||||
|
|
|
@ -464,7 +464,6 @@ gst_audio_base_sink_query (GstElement * element, GstQuery * query)
|
|||
* amount of time. */
|
||||
max_latency = (max_l == -1) ? -1 : (base_latency + max_l);
|
||||
|
||||
|
||||
GST_DEBUG_OBJECT (basesink,
|
||||
"peer min %" GST_TIME_FORMAT ", our min latency: %"
|
||||
GST_TIME_FORMAT, GST_TIME_ARGS (min_l),
|
||||
|
|
|
@ -521,7 +521,7 @@ gst_audio_decoder_init (GstAudioDecoder * dec, GstAudioDecoderClass * klass)
|
|||
|
||||
/* init state */
|
||||
dec->priv->ctx.min_latency = 0;
|
||||
dec->priv->ctx.max_latency = GST_CLOCK_TIME_NONE;
|
||||
dec->priv->ctx.max_latency = 0;
|
||||
gst_audio_decoder_reset (dec, TRUE);
|
||||
GST_DEBUG_OBJECT (dec, "init ok");
|
||||
}
|
||||
|
@ -2692,9 +2692,10 @@ gst_audio_decoder_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
|||
|
||||
GST_OBJECT_LOCK (dec);
|
||||
/* add our latency */
|
||||
if (min_latency != -1)
|
||||
min_latency += dec->priv->ctx.min_latency;
|
||||
if (max_latency != -1 && dec->priv->ctx.max_latency != -1)
|
||||
if (max_latency == -1 || dec->priv->ctx.max_latency == -1)
|
||||
max_latency = -1;
|
||||
else
|
||||
max_latency += dec->priv->ctx.max_latency;
|
||||
GST_OBJECT_UNLOCK (dec);
|
||||
|
||||
|
|
|
@ -447,7 +447,7 @@ gst_audio_encoder_init (GstAudioEncoder * enc, GstAudioEncoderClass * bclass)
|
|||
|
||||
/* init state */
|
||||
enc->priv->ctx.min_latency = 0;
|
||||
enc->priv->ctx.max_latency = GST_CLOCK_TIME_NONE;
|
||||
enc->priv->ctx.max_latency = 0;
|
||||
gst_audio_encoder_reset (enc, TRUE);
|
||||
GST_DEBUG_OBJECT (enc, "init ok");
|
||||
}
|
||||
|
@ -1837,9 +1837,10 @@ gst_audio_encoder_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
|||
|
||||
GST_OBJECT_LOCK (enc);
|
||||
/* add our latency */
|
||||
if (min_latency != -1)
|
||||
min_latency += enc->priv->ctx.min_latency;
|
||||
if (max_latency != -1 && enc->priv->ctx.max_latency != -1)
|
||||
if (max_latency == -1 || enc->priv->ctx.max_latency == -1)
|
||||
max_latency = -1;
|
||||
else
|
||||
max_latency += enc->priv->ctx.max_latency;
|
||||
GST_OBJECT_UNLOCK (enc);
|
||||
|
||||
|
|
|
@ -569,7 +569,7 @@ gst_video_decoder_init (GstVideoDecoder * decoder, GstVideoDecoderClass * klass)
|
|||
decoder->priv->needs_format = FALSE;
|
||||
|
||||
decoder->priv->min_latency = 0;
|
||||
decoder->priv->max_latency = GST_CLOCK_TIME_NONE;
|
||||
decoder->priv->max_latency = 0;
|
||||
|
||||
gst_video_decoder_reset (decoder, TRUE, TRUE);
|
||||
}
|
||||
|
@ -1541,12 +1541,11 @@ gst_video_decoder_src_query_default (GstVideoDecoder * dec, GstQuery * query)
|
|||
|
||||
GST_OBJECT_LOCK (dec);
|
||||
min_latency += dec->priv->min_latency;
|
||||
if (max_latency != GST_CLOCK_TIME_NONE
|
||||
&& dec->priv->max_latency != GST_CLOCK_TIME_NONE) {
|
||||
if (max_latency == GST_CLOCK_TIME_NONE
|
||||
|| dec->priv->max_latency == GST_CLOCK_TIME_NONE)
|
||||
max_latency = GST_CLOCK_TIME_NONE;
|
||||
else
|
||||
max_latency += dec->priv->max_latency;
|
||||
} else if (dec->priv->max_latency != GST_CLOCK_TIME_NONE) {
|
||||
max_latency = dec->priv->max_latency;
|
||||
}
|
||||
GST_OBJECT_UNLOCK (dec);
|
||||
|
||||
gst_query_set_latency (query, live, min_latency, max_latency);
|
||||
|
|
|
@ -454,7 +454,7 @@ gst_video_encoder_init (GstVideoEncoder * encoder, GstVideoEncoderClass * klass)
|
|||
priv->new_headers = FALSE;
|
||||
|
||||
priv->min_latency = 0;
|
||||
priv->max_latency = GST_CLOCK_TIME_NONE;
|
||||
priv->max_latency = 0;
|
||||
|
||||
gst_video_encoder_reset (encoder, TRUE);
|
||||
}
|
||||
|
@ -1199,12 +1199,11 @@ gst_video_encoder_src_query_default (GstVideoEncoder * enc, GstQuery * query)
|
|||
|
||||
GST_OBJECT_LOCK (enc);
|
||||
min_latency += priv->min_latency;
|
||||
if (max_latency != GST_CLOCK_TIME_NONE
|
||||
&& enc->priv->max_latency != GST_CLOCK_TIME_NONE) {
|
||||
if (max_latency == GST_CLOCK_TIME_NONE
|
||||
|| enc->priv->max_latency == GST_CLOCK_TIME_NONE)
|
||||
max_latency = GST_CLOCK_TIME_NONE;
|
||||
else
|
||||
max_latency += enc->priv->max_latency;
|
||||
} else if (enc->priv->max_latency != GST_CLOCK_TIME_NONE) {
|
||||
max_latency = enc->priv->max_latency;
|
||||
}
|
||||
GST_OBJECT_UNLOCK (enc);
|
||||
|
||||
gst_query_set_latency (query, live, min_latency, max_latency);
|
||||
|
|
|
@ -527,15 +527,17 @@ gst_adder_query_latency (GstAdder * adder, GstQuery * query)
|
|||
if (res) {
|
||||
gst_query_parse_latency (peerquery, &live_cur, &min_cur, &max_cur);
|
||||
|
||||
if (live_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)))
|
||||
if (max == GST_CLOCK_TIME_NONE)
|
||||
max = max_cur;
|
||||
else if (max_cur < max)
|
||||
max = max_cur;
|
||||
|
||||
live = live || live_cur;
|
||||
live = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
gst_query_unref (peerquery);
|
||||
|
|
|
@ -2564,6 +2564,7 @@ decoder_query_latency_fold (const GValue * item, GValue * ret, QueryFold * fold)
|
|||
"got latency min %" GST_TIME_FORMAT ", max %" GST_TIME_FORMAT
|
||||
", live %d", GST_TIME_ARGS (min), GST_TIME_ARGS (max), live);
|
||||
|
||||
if (live) {
|
||||
/* for the combined latency we collect the MAX of all min latencies and
|
||||
* the MIN of all max latencies */
|
||||
if (min > fold->min)
|
||||
|
@ -2572,8 +2573,9 @@ decoder_query_latency_fold (const GValue * item, GValue * ret, QueryFold * fold)
|
|||
fold->max = max;
|
||||
else if (max < fold->max)
|
||||
fold->max = max;
|
||||
if (!fold->live)
|
||||
fold->live = live;
|
||||
|
||||
fold->live = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
|
Loading…
Reference in a new issue