From 0517c9d6c4da58d5e8b76cef7fada58141859443 Mon Sep 17 00:00:00 2001 From: Francois Gouget Date: Fri, 23 Dec 2016 16:07:49 +0100 Subject: streaming: Fix a race condition in the GStreamer frame display queue When a frame is late we schedule its display right away with g_timeout_add(0, ...). This scheduling is done in one of the GStreamer thread, and the display_frame() callback will be called from the main thread. This can result in display_frame() being called before g_timeout_add() returns. This would cause the timer_id being reset before schedule_frame() had set it so that it would then never be reset. So from that point schedule_frame() would always think a frame was being displayed and thus would not schedule any more frames resulting in a video freeze. display_frame() now takes the queues mutex before resetting timer_id eliminating the race. Signed-off-by: Francois Gouget Acked-by: Christophe Fergeau --- src/channel-display-gst.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/channel-display-gst.c b/src/channel-display-gst.c index 9786342..5f4d321 100644 --- a/src/channel-display-gst.c +++ b/src/channel-display-gst.c @@ -127,9 +127,8 @@ static gboolean display_frame(gpointer video_decoder) GstBuffer *buffer; GstMapInfo mapinfo; - decoder->timer_id = 0; - g_mutex_lock(&decoder->queues_mutex); + decoder->timer_id = 0; frame = g_queue_pop_head(decoder->display_queue); g_mutex_unlock(&decoder->queues_mutex); /* If the queue is empty we don't even need to reschedule */ -- cgit v1.2.3