From 74ec0d4b0ca5da9a9059d9a77a2e3288b16bffe1 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Thu, 27 Oct 2022 07:21:19 +0200 Subject: [PATCH] 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: --- .../gst-libs/gst/video/gstvideodecoder.c | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/subprojects/gst-plugins-base/gst-libs/gst/video/gstvideodecoder.c b/subprojects/gst-plugins-base/gst-libs/gst/video/gstvideodecoder.c index e55dec6df2..cc5181c869 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/video/gstvideodecoder.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/video/gstvideodecoder.c @@ -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; @@ -2384,6 +2387,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; @@ -5073,24 +5078,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))); } /**