From patchwork Fri Mar 6 20:26:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Dufresne X-Patchwork-Id: 3032 Return-Path: Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7F7E0628B3 for ; Fri, 6 Mar 2020 21:27:13 +0100 (CET) Received: from nicolas-tpx395.localdomain (unknown [IPv6:2610:98:8005::527]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: nicolas) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 008E52970E7; Fri, 6 Mar 2020 20:27:12 +0000 (GMT) From: Nicolas Dufresne To: libcamera-devel@lists.libcamera.org Cc: Jakub Adam Date: Fri, 6 Mar 2020 15:26:36 -0500 Message-Id: <20200306202637.525587-27-nicolas@ndufresne.ca> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200306202637.525587-1-nicolas@ndufresne.ca> References: <20200306202637.525587-1-nicolas@ndufresne.ca> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 26/27] gst: libcamerasrc: Prevent src task deadlock on exhausted buffer pool X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Mar 2020 20:27:13 -0000 From: Jakub Adam Allow GstLibcameraPool to notify the source when a new buffer has become available in a previously exhausted buffer pool. This can be used to resume a src task that got paused because it couldn't acquire a buffer. Without this change the src task will never resume from pause once the pool gets exhausted. To trigger the deadlock (it doesn't happen every time), run: gst-launch-1.0 libcamerasrc ! queue ! glimagesink Signed-off-by: Jakub Adam Reviewed-by: Laurent Pinchart --- src/gstreamer/gstlibcamerapool.cpp | 17 +++++++++++++++++ src/gstreamer/gstlibcamerasrc.cpp | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/gstreamer/gstlibcamerapool.cpp b/src/gstreamer/gstlibcamerapool.cpp index 3868905..8f53616 100644 --- a/src/gstreamer/gstlibcamerapool.cpp +++ b/src/gstreamer/gstlibcamerapool.cpp @@ -14,6 +14,13 @@ using namespace libcamera; +enum { + SIGNAL_BUFFER_NOTIFY, + N_SIGNALS +}; + +static guint signals[N_SIGNALS]; + struct _GstLibcameraPool { GstBufferPool parent; @@ -55,7 +62,12 @@ static void gst_libcamera_pool_release_buffer(GstBufferPool *pool, GstBuffer *buffer) { GstLibcameraPool *self = GST_LIBCAMERA_POOL(pool); + bool do_notify = gst_atomic_queue_length(self->queue) == 0; + gst_atomic_queue_push(self->queue, buffer); + + if (do_notify) + g_signal_emit(self, signals[SIGNAL_BUFFER_NOTIFY], 0); } static void @@ -90,6 +102,11 @@ gst_libcamera_pool_class_init(GstLibcameraPoolClass *klass) pool_class->acquire_buffer = gst_libcamera_pool_acquire_buffer; pool_class->reset_buffer = gst_libcamera_pool_reset_buffer; pool_class->release_buffer = gst_libcamera_pool_release_buffer; + + signals[SIGNAL_BUFFER_NOTIFY] = g_signal_new("buffer-notify", + G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_LAST, + 0, nullptr, nullptr, nullptr, + G_TYPE_NONE, 0); } GstLibcameraPool * diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index 22d9175..9755922 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -439,6 +439,9 @@ gst_libcamera_src_task_enter(GstTask *task, GThread *thread, gpointer user_data) const StreamConfiguration &stream_cfg = state->config_->at(i); GstLibcameraPool *pool = gst_libcamera_pool_new(self->allocator, stream_cfg.stream()); + g_signal_connect_swapped(pool, "buffer-notify", + G_CALLBACK(gst_libcamera_resume_task), task); + gst_libcamera_pad_set_pool(srcpad, pool); gst_flow_combiner_add_pad(self->flow_combiner, srcpad); } @@ -474,7 +477,7 @@ gst_libcamera_src_task_leave(GstTask *task, GThread *thread, gpointer user_data) state->cam_->stop(); for (GstPad *srcpad : state->srcpads_) - gst_libcamera_pad_set_pool(srcpad, NULL); + gst_libcamera_pad_set_pool(srcpad, nullptr); g_clear_object(&self->allocator); g_clear_pointer(&self->flow_combiner,