From 225d6b7e114b40066db3a3b0309b676b65f57526 Mon Sep 17 00:00:00 2001 From: Jonas Rebmann Date: Wed, 27 Nov 2024 12:16:37 +0100 Subject: [PATCH] v4l2videodec: fix freeze race condition This fixes a possible deadlock between gst_v4l2_video_dec_change_state and gst_v4l2_video_dec_loop on the buffer pool. When stopping capture, the flushing state of the v4l2 capture buffer pool gets reverted in the processing loop after it was set via gst_v4l2_object_unlock (self->v4l2capture) (in gst_v4l2_video_dec_change_state). As a result, gst_v4l2_video_dec_loop does not return and consequently, gst_pad_stop_task gets stuck waiting for the GST_PAD_STREAM_LOCK. To circumvent this, skip acquiring the buffer pool if stopping capture. Suggested-by: Nicolas Dufresne Part-of: --- subprojects/gst-plugins-good/sys/v4l2/gstv4l2videodec.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2videodec.c b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2videodec.c index 70edd06077..5c137cf7da 100644 --- a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2videodec.c +++ b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2videodec.c @@ -745,6 +745,13 @@ gst_v4l2_video_dec_loop (GstVideoDecoder * decoder) GST_VIDEO_DECODER_STREAM_UNLOCK (decoder); goto beach; } + + /* + * In case we are flushing or stopping the element, ensure the active + * state is reflected onto the newly create pool. + */ + if (!g_atomic_int_get (&self->active)) + gst_v4l2_object_unlock (self->v4l2capture); } /* just a safety, as introducing mistakes in negotiation seems rather