Show a patch.

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

{
    "id": 11432,
    "url": "https://patchwork.libcamera.org/api/patches/11432/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/11432/",
    "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": "<20210302112437.20638-1-laurent.pinchart@ideasonboard.com>",
    "date": "2021-03-02T11:24:37",
    "name": "[libcamera-devel,v1.1,19/20] libcamera: pipeline: simple: Support usage of multiple streams",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "df0f2c8cfa12eca3c42455103ec218b17dc7d309",
    "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/11432/mbox/",
    "series": [
        {
            "id": 1737,
            "url": "https://patchwork.libcamera.org/api/series/1737/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1737",
            "date": "2021-03-02T11:24:37",
            "name": null,
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/1737/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/11432/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/11432/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 E128EBD1F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  2 Mar 2021 11:25:12 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6DC6068A95;\n\tTue,  2 Mar 2021 12:25:12 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4976A68A93\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  2 Mar 2021 12:25:11 +0100 (CET)",
            "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id BEB1545D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  2 Mar 2021 12:25:10 +0100 (CET)"
        ],
        "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=\"ev3//9Cx\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1614684310;\n\tbh=1Jr1HRqmNjKPbyDfK77OIXHUPjfWW7ot7vvigxgGhco=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=ev3//9Cx6z5b/CsGQJoJMq36t6LsbbDeGxppqysHhXCI5uVGeGkg+pVqnNvX6tU8N\n\tO7ppHFQPEay4dUanLK9Hw4gyt06bNF972t/y9Gx7wCkJ1AEdP8mFqyQ1AYxncFv8/S\n\t1doB5u9radE9qWPGNT+ogjVzHmzdnW1sUd8ujges=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue,  2 Mar 2021 13:24:37 +0200",
        "Message-Id": "<20210302112437.20638-1-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.28.0",
        "In-Reply-To": "<20210131224702.8838-20-laurent.pinchart@ideasonboard.com>",
        "References": "<20210131224702.8838-20-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v1.1 19/20] libcamera: pipeline: simple:\n\tSupport usage of multiple streams",
        "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>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "To extend the multi-stream support to runtime operation of the pipeline,\nexpand the converter queue to store multiple output buffers, and update\nthe request queuing and buffer completion handlers accordingly.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nTested-by: Phi-Bang Nguyen <pnguyen@baylibre.com>\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\nChanges since v1:\n\n- Add streamIndex() helper\n- Don't requeue buffer when stopping stream\n---\n src/libcamera/pipeline/simple/simple.cpp | 91 ++++++++++++++----------\n 1 file changed, 55 insertions(+), 36 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\nindex ce4e42c3547e..d3e7f7828e96 100644\n--- a/src/libcamera/pipeline/simple/simple.cpp\n+++ b/src/libcamera/pipeline/simple/simple.cpp\n@@ -150,6 +150,11 @@ public:\n \tint setupFormats(V4L2SubdeviceFormat *format,\n \t\t\t V4L2Subdevice::Whence whence);\n \n+\tunsigned int streamIndex(const Stream *stream) const\n+\t{\n+\t\treturn stream - &streams_.front();\n+\t}\n+\n \tstruct Entity {\n \t\tMediaEntity *entity;\n \t\tMediaLink *link;\n@@ -173,7 +178,7 @@ public:\n \n \tstd::vector<std::unique_ptr<FrameBuffer>> converterBuffers_;\n \tbool useConverter_;\n-\tstd::queue<FrameBuffer *> converterQueue_;\n+\tstd::queue<std::map<unsigned int, FrameBuffer *>> converterQueue_;\n };\n \n class SimpleCameraConfiguration : public CameraConfiguration\n@@ -764,7 +769,8 @@ int SimplePipelineHandler::exportFrameBuffers(Camera *camera, Stream *stream,\n \t * whether the converter is used or not.\n \t */\n \tif (data->useConverter_)\n-\t\treturn converter_->exportBuffers(0, count, buffers);\n+\t\treturn converter_->exportBuffers(data->streamIndex(stream),\n+\t\t\t\t\t\t count, buffers);\n \telse\n \t\treturn data->video_->exportBuffers(count, buffers);\n }\n@@ -831,25 +837,29 @@ void SimplePipelineHandler::stop(Camera *camera)\n int SimplePipelineHandler::queueRequestDevice(Camera *camera, Request *request)\n {\n \tSimpleCameraData *data = cameraData(camera);\n-\tStream *stream = &data->streams_[0];\n+\tint ret;\n \n-\tFrameBuffer *buffer = request->findBuffer(stream);\n-\tif (!buffer) {\n-\t\tLOG(SimplePipeline, Error)\n-\t\t\t<< \"Attempt to queue request with invalid stream\";\n-\t\treturn -ENOENT;\n-\t}\n+\tstd::map<unsigned int, FrameBuffer *> buffers;\n \n-\t/*\n-\t * If conversion is needed, push the buffer to the converter queue, it\n-\t * will be handed to the converter in the capture completion handler.\n-\t */\n-\tif (data->useConverter_) {\n-\t\tdata->converterQueue_.push(buffer);\n-\t\treturn 0;\n+\tfor (auto &[stream, buffer] : request->buffers()) {\n+\t\t/*\n+\t\t * If conversion is needed, push the buffer to the converter\n+\t\t * queue, it will be handed to the converter in the capture\n+\t\t * completion handler.\n+\t\t */\n+\t\tif (data->useConverter_) {\n+\t\t\tbuffers.emplace(data->streamIndex(stream), buffer);\n+\t\t} else {\n+\t\t\tret = data->video_->queueBuffer(buffer);\n+\t\t\tif (ret < 0)\n+\t\t\t\treturn ret;\n+\t\t}\n \t}\n \n-\treturn data->video_->queueBuffer(buffer);\n+\tif (data->useConverter_)\n+\t\tdata->converterQueue_.push(std::move(buffers));\n+\n+\treturn 0;\n }\n \n /* -----------------------------------------------------------------------------\n@@ -1021,24 +1031,35 @@ void SimplePipelineHandler::bufferReady(FrameBuffer *buffer)\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/* Requeue the buffer for capture. */\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\t\t/*\n-\t\t\t * Get the next user-facing buffer to complete the\n-\t\t\t * request.\n-\t\t\t */\n-\t\t\tif (data->converterQueue_.empty())\n-\t\t\t\treturn;\n+\t\tif (data->converterQueue_.empty())\n+\t\t\treturn;\n \n-\t\t\tbuffer = data->converterQueue_.front();\n-\t\t\tdata->converterQueue_.pop();\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\tRequest *request = buffer->request();\n-\t\tcompleteBuffer(request, buffer);\n-\t\tcompleteRequest(request);\n+\t\tif (request)\n+\t\t\tcompleteRequest(request);\n \t\treturn;\n \t}\n \n@@ -1053,10 +1074,8 @@ void SimplePipelineHandler::bufferReady(FrameBuffer *buffer)\n \t\t\treturn;\n \t\t}\n \n-\t\tFrameBuffer *output = data->converterQueue_.front();\n+\t\tconverter_->queueBuffers(buffer, data->converterQueue_.front());\n \t\tdata->converterQueue_.pop();\n-\n-\t\tconverter_->queueBuffers(buffer, { { 0, output } });\n \t\treturn;\n \t}\n \n@@ -1079,10 +1098,10 @@ void SimplePipelineHandler::converterOutputDone(FrameBuffer *buffer)\n {\n \tASSERT(activeCamera_);\n \n-\t/* Complete the request. */\n+\t/* Complete the buffer and the request. */\n \tRequest *request = buffer->request();\n-\tcompleteBuffer(request, buffer);\n-\tcompleteRequest(request);\n+\tif (completeBuffer(request, buffer))\n+\t\tcompleteRequest(request);\n }\n \n REGISTER_PIPELINE_HANDLER(SimplePipelineHandler)\n",
    "prefixes": [
        "libcamera-devel",
        "v1.1",
        "19/20"
    ]
}