Show a patch.

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

{
    "id": 16356,
    "url": "https://patchwork.libcamera.org/api/patches/16356/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/16356/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20220623232210.18742-11-laurent.pinchart@ideasonboard.com>",
    "date": "2022-06-23T23:22:07",
    "name": "[libcamera-devel,10/13] gstreamer: Fix pads locking",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "1444328d2b7556ccd31f1f6c0ac4b1e09ceb0018",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/16356/mbox/",
    "series": [
        {
            "id": 3214,
            "url": "https://patchwork.libcamera.org/api/series/3214/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3214",
            "date": "2022-06-23T23:21:57",
            "name": "gstreamer: Queue multiple requests",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/3214/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/16356/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/16356/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": "parsemail@patchwork.libcamera.org",
        "Received": [
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 0A14BBD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 23 Jun 2022 23:22:48 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A489665659;\n\tFri, 24 Jun 2022 01:22:47 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8638F65645\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Jun 2022 01:22:33 +0200 (CEST)",
            "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0E18E80A;\n\tFri, 24 Jun 2022 01:22:32 +0200 (CEST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1656026567;\n\tbh=/q7FTUIgh7FCA3PW9417UeXt7frh0GiAoe4hGHSb3EE=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=BOi/HOUQ2o/8p4wROtzau5RxMq31oqfDHMISmmNW5A7EEUfQW16f+WFD7DsKsZ8dH\n\tovTtLIG+8gMm3VB2L5L/Ym7EZNp3TXPn3NM+0Q/7nv7N3KqR0ydbJGuPJ5x6m04Lsi\n\tjkxrGcBnqTqeVyYlhx7xQ3rQsAyeyg6IsFTypMGhBvR40yXGP0O0gaP1jsJs591/5F\n\t8oc2EhWwNvn+OTKI5iPTNThioG6JxBURCz+jQiEdpAAL4Vl6gUDNhye4DzOo74cRNg\n\twBh506H/1sq1ZzGePKod5mkirArrRWCQ5/usY4xiSMoAUPf4XalKC9uavdRqzeWUsc\n\t6nq6hIwOVTVFA==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1656026553;\n\tbh=/q7FTUIgh7FCA3PW9417UeXt7frh0GiAoe4hGHSb3EE=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=mETVWfuw/DXpx6FqBuwo3tCuXNVVY58LMgbiUE+dmWhzvYV9iBbrCqQqEzXkNsfYM\n\tnmSnRAlVLsC/Y26C83lEUvjGk63uUDhJ+xEEyqYhL9THxRgaihuRPYs0sox+OK35oS\n\twlHsj3Z/Yon7gxF7vN7DJQxiY6D3aFG2jvBnmVDY="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"mETVWfuw\"; dkim-atps=neutral",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri, 24 Jun 2022 02:22:07 +0300",
        "Message-Id": "<20220623232210.18742-11-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.35.1",
        "In-Reply-To": "<20220623232210.18742-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20220623232210.18742-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 10/13] gstreamer: Fix pads locking",
        "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>",
        "From": "Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "Cc": "Nicolas Dufresne <nicolas.dufresne@collabora.com>,\n\tVedant Paranjape <vedantparanjape160201@gmail.com>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "The srcpads_ vector is protected by two different locks, the GstObject\nlock of the libcamerasrc element, and the stream_lock that covers the\nrun function of the thread. This isn't correct. Use the stream_lock\nconsistently to protect the pads.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/gstreamer/gstlibcamerasrc.cpp | 68 ++++++++++++++++---------------\n 1 file changed, 35 insertions(+), 33 deletions(-)",
    "diff": "diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\nindex b85ba39fb808..58a322b251c7 100644\n--- a/src/gstreamer/gstlibcamerasrc.cpp\n+++ b/src/gstreamer/gstlibcamerasrc.cpp\n@@ -112,7 +112,8 @@ struct GstLibcameraSrcState {\n \tstd::shared_ptr<CameraManager> cm_;\n \tstd::shared_ptr<Camera> cam_;\n \tstd::unique_ptr<CameraConfiguration> config_;\n-\tstd::vector<GstPad *> srcpads_;\n+\n+\tstd::vector<GstPad *> srcpads_; /* Protected by stream_lock */\n \n \tMutex lock_;\n \tstd::queue<std::unique_ptr<RequestWrap>> queuedRequests_\n@@ -349,36 +350,34 @@ gst_libcamera_src_task_run(gpointer user_data)\n \t\t\t\t\t\t\tsrcpad, ret);\n \t}\n \n+\tif (ret != GST_FLOW_OK) {\n+\t\tif (ret == GST_FLOW_EOS) {\n+\t\t\tg_autoptr(GstEvent) eos = gst_event_new_eos();\n+\t\t\tguint32 seqnum = gst_util_seqnum_next();\n+\t\t\tgst_event_set_seqnum(eos, seqnum);\n+\t\t\tfor (GstPad *srcpad : state->srcpads_)\n+\t\t\t\tgst_pad_push_event(srcpad, gst_event_ref(eos));\n+\t\t} else if (ret != GST_FLOW_FLUSHING) {\n+\t\t\tGST_ELEMENT_FLOW_ERROR(self, ret);\n+\t\t}\n+\t\tgst_task_stop(self->task);\n+\t\treturn;\n+\t}\n+\n+\t/*\n+\t * Here we need to decide if we want to pause. This needs to\n+\t * happen in lock step with the callback thread which may want\n+\t * to resume the task and might push pending buffers.\n+\t */\n+\tbool do_pause;\n+\n \t{\n-\t\tif (ret != GST_FLOW_OK) {\n-\t\t\tif (ret == GST_FLOW_EOS) {\n-\t\t\t\tg_autoptr(GstEvent) eos = gst_event_new_eos();\n-\t\t\t\tguint32 seqnum = gst_util_seqnum_next();\n-\t\t\t\tgst_event_set_seqnum(eos, seqnum);\n-\t\t\t\tfor (GstPad *srcpad : state->srcpads_)\n-\t\t\t\t\tgst_pad_push_event(srcpad, gst_event_ref(eos));\n-\t\t\t} else if (ret != GST_FLOW_FLUSHING) {\n-\t\t\t\tGST_ELEMENT_FLOW_ERROR(self, ret);\n-\t\t\t}\n-\t\t\tgst_task_stop(self->task);\n-\t\t\treturn;\n-\t\t}\n-\n-\t\t/*\n-\t\t * Here we need to decide if we want to pause. This needs to\n-\t\t * happen in lock step with the callback thread which may want\n-\t\t * to resume the task and might push pending buffers.\n-\t\t */\n-\t\tbool do_pause;\n-\n-\t\t{\n-\t\t\tMutexLocker locker(state->lock_);\n-\t\t\tdo_pause = state->completedRequests_.empty();\n-\t\t}\n-\n-\t\tif (do_pause)\n-\t\t\tgst_task_pause(self->task);\n+\t\tMutexLocker locker(state->lock_);\n+\t\tdo_pause = state->completedRequests_.empty();\n \t}\n+\n+\tif (do_pause)\n+\t\tgst_task_pause(self->task);\n }\n \n static void\n@@ -532,8 +531,11 @@ gst_libcamera_src_task_leave([[maybe_unused]] GstTask *task,\n \t\tstate->completedRequests_ = {};\n \t}\n \n-\tfor (GstPad *srcpad : state->srcpads_)\n-\t\tgst_libcamera_pad_set_pool(srcpad, nullptr);\n+\t{\n+\t\tGLibRecLocker locker(&self->stream_lock);\n+\t\tfor (GstPad *srcpad : state->srcpads_)\n+\t\t\tgst_libcamera_pad_set_pool(srcpad, nullptr);\n+\t}\n \n \tg_clear_object(&self->allocator);\n \tg_clear_pointer(&self->flow_combiner,\n@@ -692,7 +694,7 @@ gst_libcamera_src_request_new_pad(GstElement *element, GstPadTemplate *templ,\n \tg_object_ref_sink(pad);\n \n \tif (gst_element_add_pad(element, pad)) {\n-\t\tGLibLocker lock(GST_OBJECT(self));\n+\t\tGLibRecLocker lock(&self->stream_lock);\n \t\tself->state->srcpads_.push_back(reinterpret_cast<GstPad *>(g_object_ref(pad)));\n \t} else {\n \t\tGST_ELEMENT_ERROR(element, STREAM, FAILED,\n@@ -712,7 +714,7 @@ gst_libcamera_src_release_pad(GstElement *element, GstPad *pad)\n \tGST_DEBUG_OBJECT(self, \"Pad %\" GST_PTR_FORMAT \" being released\", pad);\n \n \t{\n-\t\tGLibLocker lock(GST_OBJECT(self));\n+\t\tGLibRecLocker lock(&self->stream_lock);\n \t\tstd::vector<GstPad *> &pads = self->state->srcpads_;\n \t\tauto begin_iterator = pads.begin();\n \t\tauto end_iterator = pads.end();\n",
    "prefixes": [
        "libcamera-devel",
        "10/13"
    ]
}