Show a patch.

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

{
    "id": 13240,
    "url": "https://patchwork.libcamera.org/api/patches/13240/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/13240/",
    "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": "<20210805222436.6263-10-laurent.pinchart@ideasonboard.com>",
    "date": "2021-08-05T22:24:35",
    "name": "[libcamera-devel,09/10] libcamera: pipeline: simple: Move bufferReady handler to SimpleCameraData",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "0b76168faab6404b7179cd645a111b1390edb326",
    "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/13240/mbox/",
    "series": [
        {
            "id": 2314,
            "url": "https://patchwork.libcamera.org/api/series/2314/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2314",
            "date": "2021-08-05T22:24:26",
            "name": "Concurrent camera support in simple pipeline handler",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/2314/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/13240/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/13240/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 8AF6FC323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  5 Aug 2021 22:25:04 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6BBCC68823;\n\tFri,  6 Aug 2021 00:25:03 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AF6CA68864\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Aug 2021 00:24:58 +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 5891D4FB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Aug 2021 00:24:58 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"kz1g+d6s\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1628202298;\n\tbh=rk2i+0Hbv2WpzF5aFkIirl35cpNkySJgXP5j1JzuCCc=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=kz1g+d6sF7Y4fX5ajgjudC36ilxZQr77YphAXFBphYNDZ3UWE9M0bCCi3jXyTEkl2\n\tF46UiV6FibG1Kbvrd8f9mC+9h9HjHww8TJb5084fIQUiconmxtjI4MfS1V6pu3+8LN\n\to+EK95pvTrhy2oHgQKu17DxlWzvqE9jKmzHseZVE=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri,  6 Aug 2021 01:24:35 +0300",
        "Message-Id": "<20210805222436.6263-10-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.31.1",
        "In-Reply-To": "<20210805222436.6263-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20210805222436.6263-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 09/10] libcamera: pipeline: simple: Move\n\tbufferReady handler to SimpleCameraData",
        "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>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "To use multiple cameras at the same time, a per-camera buffer ready\nhandler is needed. Move the bufferReady() function connected to the\nV4L2VideoDevice bufferReady signal from the SimplePipelineHandler class\nto the SimpleCameraData class.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/pipeline/simple/simple.cpp | 186 +++++++++++------------\n 1 file changed, 90 insertions(+), 96 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\nindex 961262b7803d..aa4542ed26b1 100644\n--- a/src/libcamera/pipeline/simple/simple.cpp\n+++ b/src/libcamera/pipeline/simple/simple.cpp\n@@ -179,6 +179,7 @@ public:\n \tint setupLinks();\n \tint setupFormats(V4L2SubdeviceFormat *format,\n \t\t\t V4L2Subdevice::Whence whence);\n+\tvoid bufferReady(FrameBuffer *buffer);\n \n \tunsigned int streamIndex(const Stream *stream) const\n \t{\n@@ -307,8 +308,6 @@ private:\n \tconst MediaPad *acquirePipeline(SimpleCameraData *data);\n \tvoid releasePipeline(SimpleCameraData *data);\n \n-\tvoid bufferReady(FrameBuffer *buffer);\n-\n \tMediaDevice *media_;\n \tstd::map<const MediaEntity *, EntityData> entities_;\n \n@@ -621,6 +620,91 @@ int SimpleCameraData::setupFormats(V4L2SubdeviceFormat *format,\n \treturn 0;\n }\n \n+void SimpleCameraData::bufferReady(FrameBuffer *buffer)\n+{\n+\t/*\n+\t * If an error occurred during capture, or if the buffer was cancelled,\n+\t * complete the request, even if the converter is in use as there's no\n+\t * point converting an erroneous buffer.\n+\t */\n+\tif (buffer->metadata().status != FrameMetadata::FrameSuccess) {\n+\t\tif (!useConverter_) {\n+\t\t\t/* No conversion, just complete the request. */\n+\t\t\tRequest *request = buffer->request();\n+\t\t\tpipe_->completeBuffer(request, buffer);\n+\t\t\tpipe_->completeRequest(request);\n+\t\t\treturn;\n+\t\t}\n+\n+\t\t/*\n+\t\t * The converter is in use. Requeue the internal buffer for\n+\t\t * capture (unless the stream is being stopped), and complete\n+\t\t * the request with all the user-facing buffers.\n+\t\t */\n+\t\tif (buffer->metadata().status != FrameMetadata::FrameCancelled)\n+\t\t\tvideo_->queueBuffer(buffer);\n+\n+\t\tif (converterQueue_.empty())\n+\t\t\treturn;\n+\n+\t\tRequest *request = nullptr;\n+\t\tfor (auto &item : converterQueue_.front()) {\n+\t\t\tFrameBuffer *outputBuffer = item.second;\n+\t\t\trequest = outputBuffer->request();\n+\t\t\tpipe_->completeBuffer(request, outputBuffer);\n+\t\t}\n+\t\tconverterQueue_.pop();\n+\n+\t\tif (request)\n+\t\t\tpipe_->completeRequest(request);\n+\t\treturn;\n+\t}\n+\n+\t/*\n+\t * Record the sensor's timestamp in the request metadata. The request\n+\t * needs to be obtained from the user-facing buffer, as internal\n+\t * buffers are free-wheeling and have no request associated with them.\n+\t *\n+\t * \\todo The sensor timestamp should be better estimated by connecting\n+\t * to the V4L2Device::frameStart signal if the platform provides it.\n+\t */\n+\tRequest *request = buffer->request();\n+\n+\tif (useConverter_ && !converterQueue_.empty()) {\n+\t\tconst std::map<unsigned int, FrameBuffer *> &outputs =\n+\t\t\tconverterQueue_.front();\n+\t\tif (!outputs.empty()) {\n+\t\t\tFrameBuffer *outputBuffer = outputs.begin()->second;\n+\t\t\tif (outputBuffer)\n+\t\t\t\trequest = outputBuffer->request();\n+\t\t}\n+\t}\n+\n+\tif (request)\n+\t\trequest->metadata().set(controls::SensorTimestamp,\n+\t\t\t\t\tbuffer->metadata().timestamp);\n+\n+\t/*\n+\t * Queue the captured and the request buffer to the converter if format\n+\t * conversion is needed. If there's no queued request, just requeue the\n+\t * captured buffer for capture.\n+\t */\n+\tif (useConverter_) {\n+\t\tif (converterQueue_.empty()) {\n+\t\t\tvideo_->queueBuffer(buffer);\n+\t\t\treturn;\n+\t\t}\n+\n+\t\tconverter_->queueBuffers(buffer, converterQueue_.front());\n+\t\tconverterQueue_.pop();\n+\t\treturn;\n+\t}\n+\n+\t/* Otherwise simply complete the request. */\n+\tpipe_->completeBuffer(request, buffer);\n+\tpipe_->completeRequest(request);\n+}\n+\n void SimpleCameraData::converterInputDone(FrameBuffer *buffer)\n {\n \t/* Queue the input buffer back for capture. */\n@@ -921,6 +1005,8 @@ int SimplePipelineHandler::start(Camera *camera, [[maybe_unused]] const ControlL\n \t\treturn ret;\n \t}\n \n+\tvideo->bufferReady.connect(data, &SimpleCameraData::bufferReady);\n+\n \tret = video->streamOn();\n \tif (ret < 0) {\n \t\tstop(camera);\n@@ -955,6 +1041,8 @@ void SimplePipelineHandler::stop(Camera *camera)\n \tvideo->streamOff();\n \tvideo->releaseBuffers();\n \n+\tvideo->bufferReady.disconnect(data, &SimpleCameraData::bufferReady);\n+\n \tdata->converterBuffers_.clear();\n \tactiveCamera_ = nullptr;\n \n@@ -1135,8 +1223,6 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator)\n \t\t\t\t\t<< \": \" << strerror(-ret);\n \t\t\t\treturn false;\n \t\t\t}\n-\n-\t\t\tvideo->bufferReady.connect(this, &SimplePipelineHandler::bufferReady);\n \t\t\tbreak;\n \n \t\tcase MediaEntity::Type::V4L2Subdevice:\n@@ -1250,98 +1336,6 @@ void SimplePipelineHandler::releasePipeline(SimpleCameraData *data)\n \t}\n }\n \n-/* -----------------------------------------------------------------------------\n- * Buffer Handling\n- */\n-\n-void SimplePipelineHandler::bufferReady(FrameBuffer *buffer)\n-{\n-\tASSERT(activeCamera_);\n-\tSimpleCameraData *data = cameraData(activeCamera_);\n-\n-\t/*\n-\t * If an error occurred during capture, or if the buffer was cancelled,\n-\t * complete the request, even if the converter is in use as there's no\n-\t * point converting an erroneous buffer.\n-\t */\n-\tif (buffer->metadata().status != FrameMetadata::FrameSuccess) {\n-\t\tif (!data->useConverter_) {\n-\t\t\t/* No conversion, just complete the request. */\n-\t\t\tRequest *request = buffer->request();\n-\t\t\tcompleteBuffer(request, buffer);\n-\t\t\tcompleteRequest(request);\n-\t\t\treturn;\n-\t\t}\n-\n-\t\t/*\n-\t\t * The converter is in use. Requeue the internal buffer for\n-\t\t * capture (unless the stream is being stopped), and complete\n-\t\t * the request with all the user-facing buffers.\n-\t\t */\n-\t\tif (buffer->metadata().status != FrameMetadata::FrameCancelled)\n-\t\t\tdata->video_->queueBuffer(buffer);\n-\n-\t\tif (data->converterQueue_.empty())\n-\t\t\treturn;\n-\n-\t\tRequest *request = nullptr;\n-\t\tfor (auto &item : data->converterQueue_.front()) {\n-\t\t\tFrameBuffer *outputBuffer = item.second;\n-\t\t\trequest = outputBuffer->request();\n-\t\t\tcompleteBuffer(request, outputBuffer);\n-\t\t}\n-\t\tdata->converterQueue_.pop();\n-\n-\t\tif (request)\n-\t\t\tcompleteRequest(request);\n-\t\treturn;\n-\t}\n-\n-\t/*\n-\t * Record the sensor's timestamp in the request metadata. The request\n-\t * needs to be obtained from the user-facing buffer, as internal\n-\t * buffers are free-wheeling and have no request associated with them.\n-\t *\n-\t * \\todo The sensor timestamp should be better estimated by connecting\n-\t * to the V4L2Device::frameStart signal if the platform provides it.\n-\t */\n-\tRequest *request = buffer->request();\n-\n-\tif (data->useConverter_ && !data->converterQueue_.empty()) {\n-\t\tconst std::map<unsigned int, FrameBuffer *> &outputs =\n-\t\t\tdata->converterQueue_.front();\n-\t\tif (!outputs.empty()) {\n-\t\t\tFrameBuffer *outputBuffer = outputs.begin()->second;\n-\t\t\tif (outputBuffer)\n-\t\t\t\trequest = outputBuffer->request();\n-\t\t}\n-\t}\n-\n-\tif (request)\n-\t\trequest->metadata().set(controls::SensorTimestamp,\n-\t\t\t\t\tbuffer->metadata().timestamp);\n-\n-\t/*\n-\t * Queue the captured and the request buffer to the converter if format\n-\t * conversion is needed. If there's no queued request, just requeue the\n-\t * captured buffer for capture.\n-\t */\n-\tif (data->useConverter_) {\n-\t\tif (data->converterQueue_.empty()) {\n-\t\t\tdata->video_->queueBuffer(buffer);\n-\t\t\treturn;\n-\t\t}\n-\n-\t\tdata->converter_->queueBuffers(buffer, data->converterQueue_.front());\n-\t\tdata->converterQueue_.pop();\n-\t\treturn;\n-\t}\n-\n-\t/* Otherwise simply complete the request. */\n-\tcompleteBuffer(request, buffer);\n-\tcompleteRequest(request);\n-}\n-\n REGISTER_PIPELINE_HANDLER(SimplePipelineHandler)\n \n } /* namespace libcamera */\n",
    "prefixes": [
        "libcamera-devel",
        "09/10"
    ]
}