videodecoder: Only post latency message if it changed

Posting latency messages causes a full and potentially expensive latency
recalculation of the pipeline. While subclasses should check whether the latency
really changed or not before calling this function, we ensure that we do not
post such messages if it didn't change.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3282>
This commit is contained in:
Edward Hervey 2022-10-27 07:21:19 +02:00 committed by GStreamer Marge Bot
parent 5c2eba666b
commit 8f286fc388

View file

@ -446,6 +446,9 @@ struct _GstVideoDecoderPrivate
gint64 min_latency;
gint64 max_latency;
/* Tracks whether the latency message was posted at least once */
gboolean posted_latency_msg;
/* upstream stream tags (global tags are passed through as-is) */
GstTagList *upstream_tags;
@ -2372,6 +2375,8 @@ gst_video_decoder_reset (GstVideoDecoder * decoder, gboolean full,
priv->dropped = 0;
priv->processed = 0;
priv->posted_latency_msg = FALSE;
priv->decode_frame_number = 0;
priv->base_picture_number = 0;
@ -5061,24 +5066,41 @@ gst_video_decoder_get_estimate_rate (GstVideoDecoder * dec)
* @min_latency: minimum latency
* @max_latency: maximum latency
*
* Lets #GstVideoDecoder sub-classes tell the baseclass what the decoder
* latency is. Will also post a LATENCY message on the bus so the pipeline
* can reconfigure its global latency.
* Lets #GstVideoDecoder sub-classes tell the baseclass what the decoder latency
* is. If the provided values changed from previously provided ones, this will
* also post a LATENCY message on the bus so the pipeline can reconfigure its
* global latency.
*/
void
gst_video_decoder_set_latency (GstVideoDecoder * decoder,
GstClockTime min_latency, GstClockTime max_latency)
{
gboolean post_message = FALSE;
g_return_if_fail (GST_CLOCK_TIME_IS_VALID (min_latency));
g_return_if_fail (max_latency >= min_latency);
GST_DEBUG_OBJECT (decoder,
"min_latency:%" GST_TIME_FORMAT " max_latency:%" GST_TIME_FORMAT,
GST_TIME_ARGS (min_latency), GST_TIME_ARGS (max_latency));
GST_OBJECT_LOCK (decoder);
decoder->priv->min_latency = min_latency;
decoder->priv->max_latency = max_latency;
if (decoder->priv->min_latency != min_latency) {
decoder->priv->min_latency = min_latency;
post_message = TRUE;
}
if (decoder->priv->max_latency != max_latency) {
decoder->priv->max_latency = max_latency;
post_message = TRUE;
}
if (!decoder->priv->posted_latency_msg) {
decoder->priv->posted_latency_msg = TRUE;
post_message = TRUE;
}
GST_OBJECT_UNLOCK (decoder);
gst_element_post_message (GST_ELEMENT_CAST (decoder),
gst_message_new_latency (GST_OBJECT_CAST (decoder)));
if (post_message)
gst_element_post_message (GST_ELEMENT_CAST (decoder),
gst_message_new_latency (GST_OBJECT_CAST (decoder)));
}
/**