Show a patch.

GET /api/1.1/patches/2908/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2908,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/2908/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/2908/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20200227200407.490616-27-nicolas.dufresne@collabora.com>",
    "date": "2020-02-27T20:04:06",
    "name": "[libcamera-devel,v2,26/27] gst: libcamerasrc: Prevent src task deadlock on exhausted buffer pool",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "196f89753f9f2ea18f93b86c09e274ed0a730451",
    "submitter": {
        "id": 31,
        "url": "https://patchwork.libcamera.org/api/1.1/people/31/?format=api",
        "name": "Nicolas Dufresne",
        "email": "nicolas.dufresne@collabora.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/2908/mbox/",
    "series": [
        {
            "id": 693,
            "url": "https://patchwork.libcamera.org/api/1.1/series/693/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=693",
            "date": "2020-02-27T20:03:40",
            "name": "GStreamer Element for libcamera",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/693/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/2908/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/2908/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<nicolas.dufresne@collabora.com>",
        "Received": [
            "from bhuna.collabora.co.uk (bhuna.collabora.co.uk\n\t[IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6F4EE62755\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 27 Feb 2020 21:04:30 +0100 (CET)",
            "from [127.0.0.1] (localhost [127.0.0.1])\n\t(Authenticated sender: nicolas) with ESMTPSA id D9C662949DF"
        ],
        "From": "Nicolas Dufresne <nicolas.dufresne@collabora.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Jakub Adam <jakub.adam@collabora.com>",
        "Date": "Thu, 27 Feb 2020 15:04:06 -0500",
        "Message-Id": "<20200227200407.490616-27-nicolas.dufresne@collabora.com>",
        "X-Mailer": "git-send-email 2.24.1",
        "In-Reply-To": "<20200227200407.490616-1-nicolas.dufresne@collabora.com>",
        "References": "<20200227200407.490616-1-nicolas.dufresne@collabora.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 26/27] gst: libcamerasrc: Prevent src\n\ttask 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": "Thu, 27 Feb 2020 20:04:31 -0000"
    },
    "content": "From: Jakub Adam <jakub.adam@collabora.com>\n\nAllow GstLibcameraPool to notify the source when a new buffer has become\navailable in a previously exhausted buffer pool. This can be used to\nresume a src task that got paused because it couldn't acquire a buffer.\n\nWithout this change the src task will never resume from pause once the\npool gets exhausted.\n\nTo trigger the deadlock (it doesn't happen every time), run:\n\n  gst-launch-1.0 libcamerasrc ! queue ! glimagesink\n\nSigned-off-by: Jakub Adam <jakub.adam@collabora.com>\n---\n src/gstreamer/gstlibcamerapool.cpp | 16 ++++++++++++++++\n src/gstreamer/gstlibcamerapool.h   |  6 ++++++\n src/gstreamer/gstlibcamerasrc.cpp  | 14 ++++++++++++--\n 3 files changed, 34 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/src/gstreamer/gstlibcamerapool.cpp b/src/gstreamer/gstlibcamerapool.cpp\nindex f85c3aa..5aa0eeb 100644\n--- a/src/gstreamer/gstlibcamerapool.cpp\n+++ b/src/gstreamer/gstlibcamerapool.cpp\n@@ -18,6 +18,8 @@ struct _GstLibcameraPool {\n \n \tGstAtomicQueue *queue;\n \tGstLibcameraAllocator *allocator;\n+\tGstLibcameraBufferNotify buffer_notify;\n+\tgpointer buffer_notify_data;\n \tStream *stream;\n };\n \n@@ -54,7 +56,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 && self->buffer_notify)\n+\t\tself->buffer_notify(self->buffer_notify_data);\n }\n \n static void\n@@ -108,6 +115,15 @@ gst_libcamera_pool_new(GstLibcameraAllocator *allocator, Stream *stream)\n \treturn pool;\n }\n \n+void\n+gst_libcamera_pool_set_buffer_notify(GstLibcameraPool *self,\n+\t\t\t\t     GstLibcameraBufferNotify notify,\n+\t\t\t\t     gpointer data)\n+{\n+\tself->buffer_notify = notify;\n+\tself->buffer_notify_data = data;\n+}\n+\n Stream *\n gst_libcamera_pool_get_stream(GstLibcameraPool *self)\n {\ndiff --git a/src/gstreamer/gstlibcamerapool.h b/src/gstreamer/gstlibcamerapool.h\nindex 6fd2913..545be01 100644\n--- a/src/gstreamer/gstlibcamerapool.h\n+++ b/src/gstreamer/gstlibcamerapool.h\n@@ -20,9 +20,15 @@\n #define GST_TYPE_LIBCAMERA_POOL gst_libcamera_pool_get_type()\n G_DECLARE_FINAL_TYPE(GstLibcameraPool, gst_libcamera_pool, GST_LIBCAMERA, POOL, GstBufferPool)\n \n+typedef void (*GstLibcameraBufferNotify)(gpointer data);\n+\n GstLibcameraPool *gst_libcamera_pool_new(GstLibcameraAllocator *allocator,\n \t\t\t\t\t libcamera::Stream *stream);\n \n+void gst_libcamera_pool_set_buffer_notify(GstLibcameraPool *self,\n+\t\t\t\t\t  GstLibcameraBufferNotify notify,\n+\t\t\t\t\t  gpointer data);\n+\n libcamera::Stream *gst_libcamera_pool_get_stream(GstLibcameraPool *self);\n \n libcamera::Stream *gst_libcamera_buffer_get_stream(GstBuffer *buffer);\ndiff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\nindex fe60584..ecbfe37 100644\n--- a/src/gstreamer/gstlibcamerasrc.cpp\n+++ b/src/gstreamer/gstlibcamerasrc.cpp\n@@ -434,6 +434,10 @@ 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\tgst_libcamera_pool_set_buffer_notify(pool,\n+\t\t\t\t\t\t     (GstLibcameraBufferNotify)gst_libcamera_resume_task,\n+\t\t\t\t\t\t     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@@ -468,8 +472,14 @@ gst_libcamera_src_task_leave(GstTask *task, GThread *thread, gpointer user_data)\n \n \tstate->cam->stop();\n \n-\tfor (GstPad *srcpad : state->srcpads)\n-\t\tgst_libcamera_pad_set_pool(srcpad, NULL);\n+\tfor (GstPad *srcpad : state->srcpads) {\n+\t\tauto *pool = gst_libcamera_pad_get_pool(srcpad);\n+\n+\t\tif (pool) {\n+\t\t\tgst_libcamera_pool_set_buffer_notify(pool, NULL, NULL);\n+\t\t\tgst_libcamera_pad_set_pool(srcpad, NULL);\n+\t\t}\n+\t}\n \n \tg_clear_object(&self->allocator);\n \tg_clear_pointer(&self->flow_combiner,\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "26/27"
    ]
}