[{"id":3977,"web_url":"https://patchwork.libcamera.org/comment/3977/","msgid":"<20200306211354.GZ4878@pendragon.ideasonboard.com>","date":"2020-03-06T21:13:54","subject":"Re: [libcamera-devel] [PATCH v3 26/27] gst: libcamerasrc: Prevent\n\tsrc task deadlock on exhausted buffer pool","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Nicolas and Jakub,\n\nThank you for the patch.\n\nOn Fri, Mar 06, 2020 at 03:26:36PM -0500, Nicolas Dufresne wrote:\n> From: Jakub Adam <jakub.adam@collabora.com>\n> \n> Allow GstLibcameraPool to notify the source when a new buffer has become\n> available in a previously exhausted buffer pool. This can be used to\n> resume a src task that got paused because it couldn't acquire a buffer.\n> \n> Without this change the src task will never resume from pause once the\n> pool gets exhausted.\n> \n> To trigger the deadlock (it doesn't happen every time), run:\n> \n>   gst-launch-1.0 libcamerasrc ! queue ! glimagesink\n> \n> Signed-off-by: Jakub Adam <jakub.adam@collabora.com>\n\nI like the signal !\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  src/gstreamer/gstlibcamerapool.cpp | 17 +++++++++++++++++\n>  src/gstreamer/gstlibcamerasrc.cpp  |  5 ++++-\n>  2 files changed, 21 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/gstreamer/gstlibcamerapool.cpp b/src/gstreamer/gstlibcamerapool.cpp\n> index 3868905..8f53616 100644\n> --- a/src/gstreamer/gstlibcamerapool.cpp\n> +++ b/src/gstreamer/gstlibcamerapool.cpp\n> @@ -14,6 +14,13 @@\n>  \n>  using namespace libcamera;\n>  \n> +enum {\n> +\tSIGNAL_BUFFER_NOTIFY,\n> +\tN_SIGNALS\n> +};\n> +\n> +static guint signals[N_SIGNALS];\n> +\n>  struct _GstLibcameraPool {\n>  \tGstBufferPool parent;\n>  \n> @@ -55,7 +62,12 @@ static void\n>  gst_libcamera_pool_release_buffer(GstBufferPool *pool, GstBuffer *buffer)\n>  {\n>  \tGstLibcameraPool *self = GST_LIBCAMERA_POOL(pool);\n> +\tbool do_notify = gst_atomic_queue_length(self->queue) == 0;\n> +\n>  \tgst_atomic_queue_push(self->queue, buffer);\n> +\n> +\tif (do_notify)\n> +\t\tg_signal_emit(self, signals[SIGNAL_BUFFER_NOTIFY], 0);\n>  }\n>  \n>  static void\n> @@ -90,6 +102,11 @@ gst_libcamera_pool_class_init(GstLibcameraPoolClass *klass)\n>  \tpool_class->acquire_buffer = gst_libcamera_pool_acquire_buffer;\n>  \tpool_class->reset_buffer = gst_libcamera_pool_reset_buffer;\n>  \tpool_class->release_buffer = gst_libcamera_pool_release_buffer;\n> +\n> +\tsignals[SIGNAL_BUFFER_NOTIFY] = g_signal_new(\"buffer-notify\",\n> +\t\t\t\t\t\t     G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_LAST,\n> +\t\t\t\t\t\t     0, nullptr, nullptr, nullptr,\n> +\t\t\t\t\t\t     G_TYPE_NONE, 0);\n>  }\n>  \n>  GstLibcameraPool *\n> diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\n> index 22d9175..9755922 100644\n> --- a/src/gstreamer/gstlibcamerasrc.cpp\n> +++ b/src/gstreamer/gstlibcamerasrc.cpp\n> @@ -439,6 +439,9 @@ gst_libcamera_src_task_enter(GstTask *task, GThread *thread, gpointer user_data)\n>  \t\tconst StreamConfiguration &stream_cfg = state->config_->at(i);\n>  \t\tGstLibcameraPool *pool = gst_libcamera_pool_new(self->allocator,\n>  \t\t\t\t\t\t\t\tstream_cfg.stream());\n> +\t\tg_signal_connect_swapped(pool, \"buffer-notify\",\n> +\t\t\t\t\t G_CALLBACK(gst_libcamera_resume_task), task);\n> +\n>  \t\tgst_libcamera_pad_set_pool(srcpad, pool);\n>  \t\tgst_flow_combiner_add_pad(self->flow_combiner, srcpad);\n>  \t}\n> @@ -474,7 +477,7 @@ gst_libcamera_src_task_leave(GstTask *task, GThread *thread, gpointer user_data)\n>  \tstate->cam_->stop();\n>  \n>  \tfor (GstPad *srcpad : state->srcpads_)\n> -\t\tgst_libcamera_pad_set_pool(srcpad, NULL);\n> +\t\tgst_libcamera_pad_set_pool(srcpad, nullptr);\n>  \n>  \tg_clear_object(&self->allocator);\n>  \tg_clear_pointer(&self->flow_combiner,","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8A6FB60424\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Mar 2020 22:13:57 +0100 (CET)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 06F1724B;\n\tFri,  6 Mar 2020 22:13:56 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1583529237;\n\tbh=xV/o16cBw1fEmdJXfrY6tp4XYlhfLtJ2oJx9MCO1BwA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=uBaLiOTZ5KIDLpGAXztrAEAsDHt053QnVsbbVouA+infdHBNag206Nq1k+lwZ0Yu0\n\tnrCY9JIW2EfnVqvN6SOHlGpSzfHK1cOLLac9iBcOL8xPtUOga4pGKYYaEHlaXr2oHj\n\tsBgSBkSReGFJX0970ywaUJNUsxNzfgUq2kqDPt0I=","Date":"Fri, 6 Mar 2020 23:13:54 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Nicolas Dufresne <nicolas@ndufresne.ca>","Cc":"libcamera-devel@lists.libcamera.org,\n\tJakub Adam <jakub.adam@collabora.com>","Message-ID":"<20200306211354.GZ4878@pendragon.ideasonboard.com>","References":"<20200306202637.525587-1-nicolas@ndufresne.ca>\n\t<20200306202637.525587-27-nicolas@ndufresne.ca>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200306202637.525587-27-nicolas@ndufresne.ca>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v3 26/27] gst: libcamerasrc: Prevent\n\tsrc task deadlock on exhausted buffer pool","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Fri, 06 Mar 2020 21:13:57 -0000"}}]