Show a patch.

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

{
    "id": 16448,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/16448/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/16448/",
    "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": "<20220630000251.31295-12-laurent.pinchart@ideasonboard.com>",
    "date": "2022-06-30T00:02:50",
    "name": "[libcamera-devel,v2,11/12] gstreamer: Split completed request processing to a separate function",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "b125d60dd0d34e474ac69818a1f39da5742f1271",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/16448/mbox/",
    "series": [
        {
            "id": 3234,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3234/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3234",
            "date": "2022-06-30T00:02:39",
            "name": "gstreamer: Queue multiple requests",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/3234/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/16448/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/16448/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 30EE0BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 30 Jun 2022 00:03:36 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BDD4F65652;\n\tThu, 30 Jun 2022 02:03:35 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 27E5A65638\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Jun 2022 02:03:20 +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 AD87D6D1;\n\tThu, 30 Jun 2022 02:03:19 +0200 (CEST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1656547415;\n\tbh=/Y6Gh5gSlLJaNtCb6JdJ/0zj1CcdRKeiIr10vTYnpTs=;\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=AjvAMr4dEA45/kytqWew8qLJ6pZ5zDWwe2Zx2w6zOve/nmXgKCs/nx6KueWotjmX+\n\tlNbWNB1zuPLq6aq51SL3UOVfQvtuKu1ukZLOpwzQWT8/yZKiuLpeV833KBGW+jTuh3\n\tEl4abZxse7vf6U86WSzsJ1fE0ytqZ9wXcewfrpaSjMTfvUrIMUEDqCw5C4suC5c7oB\n\t7Quf99/VYMj22LQPf4mfnTTReP3H9WGzfV8IXQH9zh4jsy1I/IZSWb79SzvG0imaCl\n\t14ccQsXNdczYUis7OY1WMK4/p9eThJjHQAbH8KUn0XacXBVVMhwtdHqUDzrHen1osY\n\tclNQPIUltAkOg==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1656547399;\n\tbh=/Y6Gh5gSlLJaNtCb6JdJ/0zj1CcdRKeiIr10vTYnpTs=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=gIZ+cejFd4P1oy96FWt/n07RZOvCAfXvHFmFFTUj12f45z1InL+D4eRimqY6Xc0n2\n\tSwwvmJnWMbOrDvH8c1VleOJzpLho+wxbDSIl2k5VdQggRKXYBDE42zql9KyP/1nTIw\n\tzeZ6KJcVREUshNiGvKAyPlWl2j61TesJ9AdGLexM="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"gIZ+cejF\"; dkim-atps=neutral",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu, 30 Jun 2022 03:02:50 +0300",
        "Message-Id": "<20220630000251.31295-12-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.35.1",
        "In-Reply-To": "<20220630000251.31295-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20220630000251.31295-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 11/12] gstreamer: Split completed\n\trequest processing to a separate function",
        "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>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Simplify the task run function futher by moving the processing of\ncompleted requests to a separate function. No functional change\nintended, only increased readability.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n---\nChanges since v1:\n\n- Add comment about locking requirement\n---\n src/gstreamer/gstlibcamerasrc.cpp | 126 ++++++++++++++++++------------\n 1 file changed, 74 insertions(+), 52 deletions(-)",
    "diff": "diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\nindex d63083d0cd8f..9ea59631a9f2 100644\n--- a/src/gstreamer/gstlibcamerasrc.cpp\n+++ b/src/gstreamer/gstlibcamerasrc.cpp\n@@ -135,6 +135,7 @@ struct GstLibcameraSrcState {\n \n \tint queueRequest();\n \tvoid requestCompleted(Request *request);\n+\tint processRequest();\n };\n \n struct _GstLibcameraSrc {\n@@ -254,6 +255,64 @@ GstLibcameraSrcState::requestCompleted(Request *request)\n \tgst_task_resume(src_->task);\n }\n \n+/* Must be called with stream_lock held. */\n+int GstLibcameraSrcState::processRequest()\n+{\n+\tstd::unique_ptr<RequestWrap> wrap;\n+\n+\t{\n+\t\tMutexLocker locker(lock_);\n+\n+\t\tif (!completedRequests_.empty()) {\n+\t\t\twrap = std::move(completedRequests_.front());\n+\t\t\tcompletedRequests_.pop();\n+\t\t}\n+\t}\n+\n+\tif (!wrap)\n+\t\treturn -ENODATA;\n+\n+\tGstFlowReturn ret = GST_FLOW_OK;\n+\tgst_flow_combiner_reset(src_->flow_combiner);\n+\n+\tfor (GstPad *srcpad : srcpads_) {\n+\t\tStream *stream = gst_libcamera_pad_get_stream(srcpad);\n+\t\tGstBuffer *buffer = wrap->detachBuffer(stream);\n+\n+\t\tFrameBuffer *fb = gst_libcamera_buffer_get_frame_buffer(buffer);\n+\n+\t\tif (GST_CLOCK_TIME_IS_VALID(wrap->pts_)) {\n+\t\t\tGST_BUFFER_PTS(buffer) = wrap->pts_;\n+\t\t\tgst_libcamera_pad_set_latency(srcpad, wrap->latency_);\n+\t\t} else {\n+\t\t\tGST_BUFFER_PTS(buffer) = 0;\n+\t\t}\n+\n+\t\tGST_BUFFER_OFFSET(buffer) = fb->metadata().sequence;\n+\t\tGST_BUFFER_OFFSET_END(buffer) = fb->metadata().sequence;\n+\n+\t\tret = gst_pad_push(srcpad, buffer);\n+\t\tret = gst_flow_combiner_update_pad_flow(src_->flow_combiner,\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 : 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(src_, ret);\n+\t\t}\n+\n+\t\treturn -EPIPE;\n+\t}\n+\n+\treturn 0;\n+}\n+\n static bool\n gst_libcamera_src_open(GstLibcameraSrc *self)\n {\n@@ -321,8 +380,13 @@ gst_libcamera_src_task_run(gpointer user_data)\n \tGstLibcameraSrc *self = GST_LIBCAMERA_SRC(user_data);\n \tGstLibcameraSrcState *state = self->state;\n \n-\tint err = state->queueRequest();\n-\tif (err == -ENOMEM) {\n+\t/*\n+\t * Create and queue one request. If no buffers are available the\n+\t * function returns -ENOBUFS, which we ignore here as that's not a\n+\t * fatal error.\n+\t */\n+\tint ret = state->queueRequest();\n+\tif (ret == -ENOMEM) {\n \t\tGST_ELEMENT_ERROR(self, RESOURCE, NO_SPACE_LEFT,\n \t\t\t\t  (\"Failed to allocate request for camera '%s'.\",\n \t\t\t\t   state->cam_->id().c_str()),\n@@ -331,58 +395,16 @@ gst_libcamera_src_task_run(gpointer user_data)\n \t\treturn;\n \t}\n \n-\tstd::unique_ptr<RequestWrap> wrap;\n-\n-\t{\n-\t\tMutexLocker locker(state->lock_);\n-\n-\t\tif (!state->completedRequests_.empty()) {\n-\t\t\twrap = std::move(state->completedRequests_.front());\n-\t\t\tstate->completedRequests_.pop();\n-\t\t}\n-\t}\n-\n-\tif (!wrap) {\n-\t\tgst_task_pause(self->task);\n-\t\treturn;\n-\t}\n-\n-\tGstFlowReturn ret = GST_FLOW_OK;\n-\tgst_flow_combiner_reset(self->flow_combiner);\n-\n-\tfor (GstPad *srcpad : state->srcpads_) {\n-\t\tStream *stream = gst_libcamera_pad_get_stream(srcpad);\n-\t\tGstBuffer *buffer = wrap->detachBuffer(stream);\n-\n-\t\tFrameBuffer *fb = gst_libcamera_buffer_get_frame_buffer(buffer);\n-\n-\t\tif (GST_CLOCK_TIME_IS_VALID(wrap->pts_)) {\n-\t\t\tGST_BUFFER_PTS(buffer) = wrap->pts_;\n-\t\t\tgst_libcamera_pad_set_latency(srcpad, wrap->latency_);\n-\t\t} else {\n-\t\t\tGST_BUFFER_PTS(buffer) = 0;\n-\t\t}\n-\n-\t\tGST_BUFFER_OFFSET(buffer) = fb->metadata().sequence;\n-\t\tGST_BUFFER_OFFSET_END(buffer) = fb->metadata().sequence;\n-\n-\t\tret = gst_pad_push(srcpad, buffer);\n-\t\tret = gst_flow_combiner_update_pad_flow(self->flow_combiner,\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/* Process one completed request, if available. */\n+\tret = state->processRequest();\n+\tswitch (ret) {\n+\tcase -EPIPE:\n \t\tgst_task_stop(self->task);\n \t\treturn;\n+\n+\tcase -ENODATA:\n+\t\tgst_task_pause(self->task);\n+\t\treturn;\n \t}\n \n \t/*\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "11/12"
    ]
}