From 9840f7144cd0ebe28196b2d987037ecd88114b8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 4 Jul 2016 10:55:07 +0200 Subject: videodecoder: Use the object lock to protect bytes/time tracking And especially don't use the stream lock for that, as otherwise non-serialized queries (CONVERT) will cause the stream lock to be taken and easily causes the application to deadlock. https://bugzilla.gnome.org/show_bug.cgi?id=768361 --- gst-libs/gst/video/gstvideodecoder.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/gst-libs/gst/video/gstvideodecoder.c b/gst-libs/gst/video/gstvideodecoder.c index 6013e94a9..90d999a70 100644 --- a/gst-libs/gst/video/gstvideodecoder.c +++ b/gst-libs/gst/video/gstvideodecoder.c @@ -1385,8 +1385,14 @@ gst_video_decoder_sink_event (GstPad * pad, GstObject * parent, static inline gboolean gst_video_decoder_do_byte (GstVideoDecoder * dec) { - return dec->priv->do_estimate_rate && (dec->priv->bytes_out > 0) + gboolean ret; + + GST_OBJECT_LOCK (dec); + ret = dec->priv->do_estimate_rate && (dec->priv->bytes_out > 0) && (dec->priv->time > GST_SECOND); + GST_OBJECT_UNLOCK (dec); + + return ret; } static gboolean @@ -1766,11 +1772,11 @@ gst_video_decoder_sink_query_default (GstVideoDecoder * decoder, gint64 src_val, dest_val; gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val); - GST_VIDEO_DECODER_STREAM_LOCK (decoder); + GST_OBJECT_LOCK (decoder); res = __gst_video_encoded_video_convert (priv->bytes_out, priv->time, src_fmt, src_val, &dest_fmt, &dest_val); - GST_VIDEO_DECODER_STREAM_UNLOCK (decoder); + GST_OBJECT_UNLOCK (decoder); if (!res) goto error; gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val); @@ -2049,8 +2055,10 @@ gst_video_decoder_reset (GstVideoDecoder * decoder, gboolean full, g_list_free_full (priv->timestamps, (GDestroyNotify) timestamp_free); priv->timestamps = NULL; + GST_OBJECT_LOCK (decoder); priv->bytes_out = 0; priv->time = 0; + GST_OBJECT_UNLOCK (decoder); GST_VIDEO_DECODER_STREAM_UNLOCK (decoder); } @@ -3079,6 +3087,7 @@ gst_video_decoder_clip_and_push_buf (GstVideoDecoder * decoder, GstBuffer * buf) } /* update rate estimate */ + GST_OBJECT_LOCK (decoder); priv->bytes_out += gst_buffer_get_size (buf); if (GST_CLOCK_TIME_IS_VALID (duration)) { priv->time += duration; @@ -3089,6 +3098,7 @@ gst_video_decoder_clip_and_push_buf (GstVideoDecoder * decoder, GstBuffer * buf) /* better none than nothing valid */ priv->time = GST_CLOCK_TIME_NONE; } + GST_OBJECT_UNLOCK (decoder); GST_DEBUG_OBJECT (decoder, "pushing buffer %p of size %" G_GSIZE_FORMAT ", " "PTS %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT, buf, -- cgit v1.2.1