Show a patch.

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

{
    "id": 11464,
    "url": "https://patchwork.libcamera.org/api/patches/11464/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/11464/",
    "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": "<20210302151111.212591-4-naush@raspberrypi.com>",
    "date": "2021-03-02T15:11:10",
    "name": "[libcamera-devel,v4,3/4] pipeline: raspberrypi: Only enable embedded stream when available",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "b6cf6885bb95b255773efb01e7ee71d1ab5a4b19",
    "submitter": {
        "id": 34,
        "url": "https://patchwork.libcamera.org/api/people/34/?format=api",
        "name": "Naushir Patuck",
        "email": "naush@raspberrypi.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/11464/mbox/",
    "series": [
        {
            "id": 1742,
            "url": "https://patchwork.libcamera.org/api/series/1742/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1742",
            "date": "2021-03-02T15:11:07",
            "name": "Raspberry Pi: Embedded data usage",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/1742/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/11464/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/11464/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 48498BD1F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  2 Mar 2021 15:11:28 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1491768A99;\n\tTue,  2 Mar 2021 16:11:28 +0100 (CET)",
            "from mail-wm1-x331.google.com (mail-wm1-x331.google.com\n\t[IPv6:2a00:1450:4864:20::331])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0842F68A7E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  2 Mar 2021 16:11:26 +0100 (CET)",
            "by mail-wm1-x331.google.com with SMTP id i9so2520080wml.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 02 Mar 2021 07:11:26 -0800 (PST)",
            "from naush-laptop.patuck.local ([88.97.76.4])\n\tby smtp.gmail.com with ESMTPSA id\n\tw6sm7561062wrl.49.2021.03.02.07.11.23\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 02 Mar 2021 07:11:24 -0800 (PST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"thIKZiJd\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=Us06vAcUvmULLy6W6CRlr9gSJQeT9lvyMp5Qa4ZH2eo=;\n\tb=thIKZiJdZ44smq6/fQocwOP2sgsKA8ma/xXn9D8CNonC6QZobVuZXxjmoObGNlMnoO\n\tTmGQ/EVfU9VUx0YiFgwC6PEKwnvmBy8RR/yZ3pxHTPrYmemSr+jAa24syu/0ZJJbkz7D\n\t5pegPPuQyGOYb0T6Y3+ZtYUmSX85EXoeQGzlY8auO8sTvXBUPFjYxJGpnIXAEbjwalmw\n\tgwOVyz5qGsdX412MDB09Y10WYpIZaoxeSlcJISMAMArnfzKMFXp+usoyzTOpN25qnHXj\n\tO+6gJKuYKn9IesM6cVKD2EkvwM56Uo7DyvjFlA5SpCBPzYjs7g8XY1TZTpVlCxiI8XB6\n\tGPxw==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=Us06vAcUvmULLy6W6CRlr9gSJQeT9lvyMp5Qa4ZH2eo=;\n\tb=osSK5eXkI1V/DooOMOYoOxsS1hoDAYpvWCUaf0V3/cS/X3+kvqka2SCY3rRfFzS1Tr\n\tscYeuMawvcjrQuC2d3FiWJ5OjazEZkfM47Eb+M1Oxle9YuRTfHOcuwjrISQ7F855Uhss\n\tftg7lm5ecB5KgJx6oU89NE8YzQ/B4V02jHIh3KxDHxs1NoklCGc2h3OsP0hmvjl1TctO\n\tZiFO6ONnntVzaY++afDOOAI3INiBxd0T7OO/d2XEGAmvg1aHbMQUnLwrzwbLFsnGvIzO\n\tdt8HuBhT5rl1lPxVnpgWFO0OeMln6Upr7E/lT0+7UVQOQHSpv04I1iEmxNJqjocls3D7\n\trpZw==",
        "X-Gm-Message-State": "AOAM533S1AxSgshpI43I6F3fgpb63/QrVycvsy5d3gd/4wL3RkVUwnHT\n\tdk2lfuIHl5LStiLKf3sDFlL8xvqLyN9ElvUi",
        "X-Google-Smtp-Source": "ABdhPJy43eNVmscQg1bBrvZ0zwCHo7KMtOU1TWhStusgp+IBpYgv5OgK5JoSa6TyZG17977g2rdCJQ==",
        "X-Received": "by 2002:a1c:4b15:: with SMTP id y21mr4622866wma.94.1614697885342;\n\tTue, 02 Mar 2021 07:11:25 -0800 (PST)",
        "From": "Naushir Patuck <naush@raspberrypi.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue,  2 Mar 2021 15:11:10 +0000",
        "Message-Id": "<20210302151111.212591-4-naush@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20210302151111.212591-1-naush@raspberrypi.com>",
        "References": "<20210302151111.212591-1-naush@raspberrypi.com>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v4 3/4] pipeline: raspberrypi: Only enable\n\tembedded stream when available",
        "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": "The pipeline handler would enable and use the Unicam embedded data stream\neven if the sensor did not support it. This was to allow a means to\npass exposure and gain values for the frame to the IPA in a synchronised\nway.\n\nThe recent changes to get the pipeline handler to pass a ControlList\nwith exposure and gain values means this is no longer required. Disable\nthe use of the embedded data stream when a sensor does not support it.\n\nThis change also removes the mappedEmbeddedBuffers_ map as it is no\nlonger used.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nTested-by: David Plowman <david.plowman@raspberrypi.com>\n---\n .../pipeline/raspberrypi/raspberrypi.cpp      | 114 +++++++++++-------\n 1 file changed, 72 insertions(+), 42 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex d057241b9c76..5ae2551957f8 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -177,12 +177,6 @@ public:\n \t/* Stores the ids of the buffers mapped in the IPA. */\n \tstd::unordered_set<unsigned int> ipaBuffers_;\n \n-\t/*\n-\t * Map of (internal) mmaped embedded data buffers, to avoid having to\n-\t * map/unmap on every frame.\n-\t */\n-\tstd::map<unsigned int, MappedFrameBuffer> mappedEmbeddedBuffers_;\n-\n \t/* DMAHEAP allocation helper. */\n \tRPi::DmaHeap dmaHeap_;\n \tFileDescriptor lsTable_;\n@@ -636,14 +630,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n \n \t\tif (isRaw(cfg.pixelFormat)) {\n \t\t\tcfg.setStream(&data->unicam_[Unicam::Image]);\n-\t\t\t/*\n-\t\t\t * We must set both Unicam streams as external, even\n-\t\t\t * though the application may only request RAW frames.\n-\t\t\t * This is because we match timestamps on both streams\n-\t\t\t * to synchronise buffers.\n-\t\t\t */\n \t\t\tdata->unicam_[Unicam::Image].setExternal(true);\n-\t\t\tdata->unicam_[Unicam::Embedded].setExternal(true);\n \t\t\tcontinue;\n \t\t}\n \n@@ -715,17 +702,6 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n \t\treturn ret;\n \t}\n \n-\t/* Unicam embedded data output format. */\n-\tformat = {};\n-\tformat.fourcc = V4L2PixelFormat(V4L2_META_FMT_SENSOR_DATA);\n-\tLOG(RPI, Debug) << \"Setting embedded data format.\";\n-\tret = data->unicam_[Unicam::Embedded].dev()->setFormat(&format);\n-\tif (ret) {\n-\t\tLOG(RPI, Error) << \"Failed to set format on Unicam embedded: \"\n-\t\t\t\t<< format.toString();\n-\t\treturn ret;\n-\t}\n-\n \t/* Figure out the smallest selection the ISP will allow. */\n \tRectangle testCrop(0, 0, 1, 1);\n \tdata->isp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &testCrop);\n@@ -742,6 +718,41 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n \tif (ret)\n \t\tLOG(RPI, Error) << \"Failed to configure the IPA: \" << ret;\n \n+\t/*\n+\t * The IPA will set data->sensorMetadata_ to true if embedded data is\n+\t * supported on this sensor. If so, open the Unicam embedded data\n+\t * node and configure the output format.\n+\t */\n+\tif (data->sensorMetadata_) {\n+\t\tformat = {};\n+\t\tformat.fourcc = V4L2PixelFormat(V4L2_META_FMT_SENSOR_DATA);\n+\t\tLOG(RPI, Debug) << \"Setting embedded data format.\";\n+\t\tdata->unicam_[Unicam::Embedded].dev()->open();\n+\t\tret = data->unicam_[Unicam::Embedded].dev()->setFormat(&format);\n+\t\tif (ret) {\n+\t\t\tLOG(RPI, Error) << \"Failed to set format on Unicam embedded: \"\n+\t\t\t\t\t<< format.toString();\n+\t\t\treturn ret;\n+\t\t}\n+\n+\t\t/*\n+\t\t * If a RAW/Bayer stream has been requested by the application,\n+\t\t * we must set both Unicam streams as external, even though the\n+\t\t * application may only request RAW frames. This is because we\n+\t\t * match timestamps on both streams to synchronise buffers.\n+\t\t */\n+\t\tif (rawStream)\n+\t\t\tdata->unicam_[Unicam::Embedded].setExternal(true);\n+\t} else {\n+\t\t/*\n+\t\t * No embedded data present, so we do not want to iterate over\n+\t\t * the embedded data stream when starting and stopping.\n+\t\t */\n+\t\tdata->streams_.erase(std::remove(data->streams_.begin(), data->streams_.end(),\n+\t\t\t\t\t\t &data->unicam_[Unicam::Embedded]),\n+\t\t\t\t     data->streams_.end());\n+\t}\n+\n \t/*\n \t * Update the ScalerCropMaximum to the correct value for this camera mode.\n \t * For us, it's the same as the \"analogue crop\".\n@@ -949,10 +960,16 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator)\n \tfor (auto &stream : data->isp_)\n \t\tdata->streams_.push_back(&stream);\n \n-\t/* Open all Unicam and ISP streams. */\n+\t/*\n+\t * Open all Unicam and ISP streams. The exception is the embedded data\n+\t * stream, which only gets opened if the IPA reports that the sensor\n+\t * supports embedded data. This happens in RPiCameraData::configureIPA().\n+\t */\n \tfor (auto const stream : data->streams_) {\n-\t\tif (stream->dev()->open())\n-\t\t\treturn false;\n+\t\tif (stream != &data->unicam_[Unicam::Embedded]) {\n+\t\t\tif (stream->dev()->open())\n+\t\t\t\treturn false;\n+\t\t}\n \t}\n \n \t/* Wire up all the buffer connections. */\n@@ -1109,19 +1126,14 @@ int PipelineHandlerRPi::prepareBuffers(Camera *camera)\n \t\t\treturn ret;\n \t}\n \n-\tif (!data->sensorMetadata_) {\n-\t\tfor (auto const &it : data->unicam_[Unicam::Embedded].getBuffers()) {\n-\t\t\tMappedFrameBuffer fb(it.second, PROT_READ | PROT_WRITE);\n-\t\t\tdata->mappedEmbeddedBuffers_.emplace(it.first, std::move(fb));\n-\t\t}\n-\t}\n-\n \t/*\n \t * Pass the stats and embedded data buffers to the IPA. No other\n \t * buffers need to be passed.\n \t */\n \tmapBuffers(camera, data->isp_[Isp::Stats].getBuffers(), ipa::RPi::MaskStats);\n-\tmapBuffers(camera, data->unicam_[Unicam::Embedded].getBuffers(), ipa::RPi::MaskEmbeddedData);\n+\tif (data->sensorMetadata_)\n+\t\tmapBuffers(camera, data->unicam_[Unicam::Embedded].getBuffers(),\n+\t\t\t   ipa::RPi::MaskEmbeddedData);\n \n \treturn 0;\n }\n@@ -1154,7 +1166,6 @@ void PipelineHandlerRPi::freeBuffers(Camera *camera)\n \tstd::vector<unsigned int> ipaBuffers(data->ipaBuffers_.begin(), data->ipaBuffers_.end());\n \tdata->ipa_->unmapBuffers(ipaBuffers);\n \tdata->ipaBuffers_.clear();\n-\tdata->mappedEmbeddedBuffers_.clear();\n \n \tfor (auto const stream : data->streams_)\n \t\tstream->releaseBuffers();\n@@ -1652,7 +1663,7 @@ void RPiCameraData::tryRunPipeline()\n \n \t/* If any of our request or buffer queues are empty, we cannot proceed. */\n \tif (state_ != State::Idle || requestQueue_.empty() ||\n-\t    bayerQueue_.empty() || embeddedQueue_.empty())\n+\t    bayerQueue_.empty() || (embeddedQueue_.empty() && sensorMetadata_))\n \t\treturn;\n \n \tif (!findMatchingBuffers(bayerFrame, embeddedBuffer))\n@@ -1675,17 +1686,24 @@ void RPiCameraData::tryRunPipeline()\n \tstate_ = State::Busy;\n \n \tunsigned int bayerId = unicam_[Unicam::Image].getBufferId(bayerFrame.buffer);\n-\tunsigned int embeddedId = unicam_[Unicam::Embedded].getBufferId(embeddedBuffer);\n \n \tLOG(RPI, Debug) << \"Signalling signalIspPrepare:\"\n-\t\t\t<< \" Bayer buffer id: \" << bayerId\n-\t\t\t<< \" Embedded buffer id: \" << embeddedId;\n+\t\t\t<< \" Bayer buffer id: \" << bayerId;\n \n \tipa::RPi::ISPConfig ispPrepare;\n-\tispPrepare.embeddedBufferId = ipa::RPi::MaskEmbeddedData | embeddedId;\n \tispPrepare.bayerBufferId = ipa::RPi::MaskBayerData | bayerId;\n-\tispPrepare.embeddedBufferPresent = sensorMetadata_;\n \tispPrepare.controls = std::move(bayerFrame.controls);\n+\n+\tif (embeddedBuffer) {\n+\t\tunsigned int embeddedId = unicam_[Unicam::Embedded].getBufferId(embeddedBuffer);\n+\n+\t\tispPrepare.embeddedBufferId = ipa::RPi::MaskEmbeddedData | embeddedId;\n+\t\tispPrepare.embeddedBufferPresent = true;\n+\n+\t\tLOG(RPI, Debug) << \"Signalling signalIspPrepare:\"\n+\t\t\t\t<< \" Bayer buffer id: \" << embeddedId;\n+\t}\n+\n \tipa_->signalIspPrepare(ispPrepare);\n }\n \n@@ -1727,6 +1745,18 @@ bool RPiCameraData::findMatchingBuffers(BayerFrame &bayerFrame, FrameBuffer *&em\n \n \t\t\tLOG(RPI, Debug) << \"Could not find matching embedded buffer\";\n \n+\t\t\tif (!sensorMetadata_) {\n+\t\t\t\t/*\n+\t\t\t\t * If there is no sensor metadata, simply return the\n+\t\t\t\t * first bayer frame in the queue.\n+\t\t\t\t */\n+\t\t\t\tLOG(RPI, Debug) << \"Returning bayer frame without a match\";\n+\t\t\t\tbayerFrame = std::move(bayerQueue_.front());\n+\t\t\t\tbayerQueue_.pop();\n+\t\t\t\tembeddedBuffer = nullptr;\n+\t\t\t\treturn true;\n+\t\t\t}\n+\n \t\t\tif (!embeddedQueue_.empty()) {\n \t\t\t\t/*\n \t\t\t\t * Not found a matching embedded buffer for the bayer buffer in\n",
    "prefixes": [
        "libcamera-devel",
        "v4",
        "3/4"
    ]
}