Show a patch.

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

{
    "id": 19074,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/19074/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/19074/",
    "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": "<20230921165550.50956-11-jacopo.mondi@ideasonboard.com>",
    "date": "2023-09-21T16:55:47",
    "name": "[libcamera-devel,v5,10/13] libcamera: rpi: Simplify validate() and configure() for RAW streams",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "48905665ff773c01cf9bdf846ae4792b48aa0914",
    "submitter": {
        "id": 143,
        "url": "https://patchwork.libcamera.org/api/1.1/people/143/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo.mondi@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/19074/mbox/",
    "series": [
        {
            "id": 4034,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4034/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4034",
            "date": "2023-09-21T16:55:37",
            "name": "libcamera: Introduce SensorConfiguration",
            "version": 5,
            "mbox": "https://patchwork.libcamera.org/series/4034/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/19074/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/19074/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 C9825C32B2\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 21 Sep 2023 16:56:13 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 648546295E;\n\tThu, 21 Sep 2023 18:56:12 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8803962949\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 21 Sep 2023 18:56:05 +0200 (CEST)",
            "from uno.lan (93-46-82-201.ip106.fastwebnet.it [93.46.82.201])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F19478201;\n\tThu, 21 Sep 2023 18:54:27 +0200 (CEST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1695315372;\n\tbh=b7QR/oq6w7h5sgTDU/EyZf2vV029gv5VibFRR0wa3dI=;\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=slS2EDIw/+iRDvS8bVPpBpnvJ9vBYGyNPREk4YBszA/jCOJ/SbLwN77RMqDkmDP0l\n\tpPoY2zfoI8tzfc+HJALcP21LZmblskUp/SYTC54mZVhEs9WdYHDBnPiaVKowNKak/q\n\t2h/yqukZjtusa8+VRwgPEp1CC/NUihsyIHK+WtQx+jCH2ha2gNfVBpDBaB7pCqhkpU\n\tP4Tfq8lGKWXwb+69Zpw9fcf0g8cSjWpmcTV2ZhAkIJAHA9woPOKbnAvV54GMu7gdRV\n\tRW1tiwzOmE1AoIDawcjO8vONPZ7sQfDCu4kL0607lWO/zil11xj2kTCOAl7r/Dop/w\n\tM6Dk1NbDinUPg==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1695315268;\n\tbh=b7QR/oq6w7h5sgTDU/EyZf2vV029gv5VibFRR0wa3dI=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=GmIm67AGuozR57+dQFEmUY5VxZbYYC5ydI+lVo1JGC956Ma8bcijCUUrU3yGHo51y\n\tinAxsf3uzzDbpYlyKYZhNtjOo2pET6SRDBGZYFKyjZkSfLAo97N4BJEWanP5L0SBm0\n\tlBaxZ+BeLFHwxb/AryCvtqnW3QgSSeniRzaY4RMQ="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"GmIm67AG\"; dkim-atps=neutral",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu, 21 Sep 2023 18:55:47 +0200",
        "Message-ID": "<20230921165550.50956-11-jacopo.mondi@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.42.0",
        "In-Reply-To": "<20230921165550.50956-1-jacopo.mondi@ideasonboard.com>",
        "References": "<20230921165550.50956-1-jacopo.mondi@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v5 10/13] libcamera: rpi: Simplify\n\tvalidate() and configure() for RAW 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>",
        "From": "Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>",
        "Cc": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "From: Naushir Patuck <naush@raspberrypi.com>\n\nThis commit simplifies the validate() and configure() calls in the\npipeline handler in a number of ways:\n\n- Only pass the RPiCameraConfiguration structure into platformValidate()\n  and platformConfigure().\n\n- Determine the V4L2DeviceFormat structure fields for all streams in\n  validate(), cache them and reuse in configure() instead of\n  re-generating this structure multiple times.\n\n- Use the recently added updateStreamConfig() and toV4L2DeviceFormat()\n  helpers to populate fields in the V4L2DeviceFormat and\n  StreamConfiguration structures to reduce code duplication.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\n .../pipeline/rpi/common/pipeline_base.cpp     | 48 +++++--------------\n .../pipeline/rpi/common/pipeline_base.h       |  5 +-\n src/libcamera/pipeline/rpi/vc4/vc4.cpp        | 35 ++++++++------\n 3 files changed, 34 insertions(+), 54 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\nindex f9b67563af17..c560e48c12fb 100644\n--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n@@ -238,16 +238,10 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \n \t/* Further fixups on the RAW streams. */\n \tfor (auto &raw : rawStreams_) {\n-\t\tStreamConfiguration &cfg = config_.at(raw.index);\n-\n-\t\tV4L2DeviceFormat rawFormat;\n-\t\trawFormat.fourcc = raw.dev->toV4L2PixelFormat(cfg.pixelFormat);\n-\t\trawFormat.size = cfg.size;\n-\t\trawFormat.colorSpace = cfg.colorSpace;\n-\n-\t\tint ret = raw.dev->tryFormat(&rawFormat);\n+\t\tint ret = raw.dev->tryFormat(&raw.format);\n \t\tif (ret)\n \t\t\treturn Invalid;\n+\n \t\t/*\n \t\t * Some sensors change their Bayer order when they are h-flipped\n \t\t * or v-flipped, according to the transform. If this one does, we\n@@ -255,23 +249,15 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \t\t * Note how we must fetch the \"native\" (i.e. untransformed) Bayer\n \t\t * order, because the sensor may currently be flipped!\n \t\t */\n-\t\tV4L2PixelFormat fourcc = rawFormat.fourcc;\n+\t\tBayerFormat bayer = BayerFormat::fromPixelFormat(raw.cfg->pixelFormat);\n \t\tif (data_->flipsAlterBayerOrder_) {\n-\t\t\tBayerFormat bayer = BayerFormat::fromV4L2PixelFormat(fourcc);\n \t\t\tbayer.order = data_->nativeBayerOrder_;\n \t\t\tbayer = bayer.transform(combinedTransform_);\n-\t\t\tfourcc = bayer.toV4L2PixelFormat();\n \t\t}\n+\t\traw.cfg->pixelFormat = bayer.toPixelFormat();\n \n-\t\tPixelFormat inputPixFormat = fourcc.toPixelFormat();\n-\t\tif (raw.cfg->size != rawFormat.size || raw.cfg->pixelFormat != inputPixFormat) {\n-\t\t\traw.cfg->size = rawFormat.size;\n-\t\t\traw.cfg->pixelFormat = inputPixFormat;\n+\t\tif (RPi::PipelineHandlerBase::updateStreamConfig(raw.cfg, raw.format))\n \t\t\tstatus = Adjusted;\n-\t\t}\n-\n-\t\traw.cfg->stride = rawFormat.planes[0].bpl;\n-\t\traw.cfg->frameSize = rawFormat.planes[0].size;\n \t}\n \n \t/* Further fixups on the ISP output streams. */\n@@ -548,35 +534,25 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config)\n \t * If the application has provided a sensor configuration apply it\n \t * instead of just applying a format.\n \t */\n-\tconst RPiCameraConfiguration *rpiConfig =\n-\t\t\t\tstatic_cast<const RPiCameraConfiguration *>(config);\n-\tV4L2SubdeviceFormat sensorFormat;\n+\tRPiCameraConfiguration *rpiConfig = static_cast<RPiCameraConfiguration *>(config);\n+\tV4L2SubdeviceFormat *sensorFormat = &rpiConfig->sensorFormat_;\n \n \tif (rpiConfig->sensorConfig) {\n \t\tret = data->sensor_->applyConfiguration(*rpiConfig->sensorConfig,\n \t\t\t\t\t\t\trpiConfig->combinedTransform_,\n-\t\t\t\t\t\t\t&sensorFormat);\n+\t\t\t\t\t\t\tsensorFormat);\n \t} else {\n-\t\tsensorFormat = rpiConfig->sensorFormat_;\n-\t\tret = data->sensor_->setFormat(&sensorFormat,\n+\t\tret = data->sensor_->setFormat(sensorFormat,\n \t\t\t\t\t       rpiConfig->combinedTransform_);\n \t}\n \tif (ret)\n \t\treturn ret;\n \n-\t/* Use the user requested packing/bit-depth. */\n-\tstd::optional<BayerFormat::Packing> packing;\n-\tif (!rpiConfig->rawStreams_.empty()) {\n-\t\tBayerFormat bayerFormat =\n-\t\t\tBayerFormat::fromPixelFormat(rpiConfig->rawStreams_[0].cfg->pixelFormat);\n-\t\tpacking = bayerFormat.packing;\n-\t}\n-\n \t/*\n \t * Platform specific internal stream configuration. This also assigns\n \t * external streams which get configured below.\n \t */\n-\tret = data->platformConfigure(sensorFormat, packing, rpiConfig);\n+\tret = data->platformConfigure(rpiConfig);\n \tif (ret)\n \t\treturn ret;\n \n@@ -640,11 +616,11 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config)\n \t\t */\n \t\tlink->setEnabled(true);\n \t\tconst MediaPad *sinkPad = link->sink();\n-\t\tret = device->setFormat(sinkPad->index(), &sensorFormat);\n+\t\tret = device->setFormat(sinkPad->index(), sensorFormat);\n \t\tif (ret) {\n \t\t\tLOG(RPI, Error) << \"Failed to set format on \" << device->entity()->name()\n \t\t\t\t\t<< \" pad \" << sinkPad->index()\n-\t\t\t\t\t<< \" with format  \" << sensorFormat\n+\t\t\t\t\t<< \" with format  \" << *sensorFormat\n \t\t\t\t\t<< \": \" << ret;\n \t\t\treturn ret;\n \t\t}\ndiff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h\nindex 491c5e98c4a1..0c4a59b7f590 100644\n--- a/src/libcamera/pipeline/rpi/common/pipeline_base.h\n+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h\n@@ -58,9 +58,7 @@ public:\n \t}\n \n \tvirtual CameraConfiguration::Status platformValidate(RPiCameraConfiguration *rpiConfig) const = 0;\n-\tvirtual int platformConfigure(const V4L2SubdeviceFormat &sensorFormat,\n-\t\t\t\t      std::optional<BayerFormat::Packing> packing,\n-\t\t\t\t      const RPiCameraConfiguration *rpiConfig) = 0;\n+\tvirtual int platformConfigure(const RPiCameraConfiguration *rpiConfig) = 0;\n \tvirtual void platformStart() = 0;\n \tvirtual void platformStop() = 0;\n \n@@ -269,6 +267,7 @@ public:\n \t\tunsigned int index;\n \t\tStreamConfiguration *cfg;\n \t\tV4L2VideoDevice *dev;\n+\t\tV4L2DeviceFormat format;\n \t};\n \n \tstd::vector<StreamParams> rawStreams_;\ndiff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\nindex 2308577a613b..1a03c88d7ee3 100644\n--- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n+++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n@@ -115,9 +115,7 @@ private:\n \t\tisp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &ispCrop_);\n \t}\n \n-\tint platformConfigure(const V4L2SubdeviceFormat &sensorFormat,\n-\t\t\t      std::optional<BayerFormat::Packing> packing,\n-\t\t\t      const RPi::RPiCameraConfiguration *rpiConfig) override;\n+\tint platformConfigure(const RPi::RPiCameraConfiguration *rpiConfig) override;\n \tint platformConfigureIpa(ipa::RPi::ConfigParams &params) override;\n \n \tint platformInitIpa([[maybe_unused]] ipa::RPi::InitParams &params) override\n@@ -416,6 +414,9 @@ CameraConfiguration::Status Vc4CameraData::platformValidate(RPi::RPiCameraConfig\n \t\t/* Handle flips to make sure to match the RAW stream format. */\n \t\tif (flipsAlterBayerOrder_)\n \t\t\trawBayer = rawBayer.transform(rpiConfig->combinedTransform_);\n+\n+\t\t/* Apply the user requested packing. */\n+\t\trawBayer.packing = BayerFormat::fromPixelFormat(rawStream->pixelFormat).packing;\n \t\tPixelFormat rawFormat = rawBayer.toPixelFormat();\n \n \t\tif (rawStream->pixelFormat != rawFormat ||\n@@ -425,6 +426,9 @@ CameraConfiguration::Status Vc4CameraData::platformValidate(RPi::RPiCameraConfig\n \n \t\t\tstatus = CameraConfiguration::Adjusted;\n \t\t}\n+\n+\t\trawStreams[0].format =\n+\t\t\tRPi::PipelineHandlerBase::toV4L2DeviceFormat(unicam_[Unicam::Image].dev(), rawStream);\n \t}\n \n \t/*\n@@ -500,23 +504,14 @@ int Vc4CameraData::platformPipelineConfigure(const std::unique_ptr<YamlObject> &\n \treturn 0;\n }\n \n-int Vc4CameraData::platformConfigure(const V4L2SubdeviceFormat &sensorFormat,\n-\t\t\t\t     std::optional<BayerFormat::Packing> packing,\n-\t\t\t\t     const RPi::RPiCameraConfiguration *rpiConfig)\n+int Vc4CameraData::platformConfigure(const RPi::RPiCameraConfiguration *rpiConfig)\n {\n \tconst std::vector<StreamParams> &rawStreams = rpiConfig->rawStreams_;\n \tconst std::vector<StreamParams> &outStreams = rpiConfig->outStreams_;\n \tint ret;\n \n-\tif (!packing)\n-\t\tpacking = BayerFormat::Packing::CSI2;\n-\n \tV4L2VideoDevice *unicam = unicam_[Unicam::Image].dev();\n-\tV4L2DeviceFormat unicamFormat = RPi::PipelineHandlerBase::toV4L2DeviceFormat(unicam, sensorFormat, *packing);\n-\n-\tret = unicam->setFormat(&unicamFormat);\n-\tif (ret)\n-\t\treturn ret;\n+\tV4L2DeviceFormat unicamFormat;\n \n \t/*\n \t * See which streams are requested, and route the user\n@@ -525,14 +520,24 @@ int Vc4CameraData::platformConfigure(const V4L2SubdeviceFormat &sensorFormat,\n \tif (!rawStreams.empty()) {\n \t\trawStreams[0].cfg->setStream(&unicam_[Unicam::Image]);\n \t\tunicam_[Unicam::Image].setFlags(StreamFlag::External);\n+\t\tunicamFormat = rawStreams[0].format;\n+\t} else {\n+\t\tunicamFormat =\n+\t\t\tRPi::PipelineHandlerBase::toV4L2DeviceFormat(unicam,\n+\t\t\t\t\t\t\t\t     rpiConfig->sensorFormat_,\n+\t\t\t\t\t\t\t\t     BayerFormat::Packing::CSI2);\n \t}\n \n+\tret = unicam->setFormat(&unicamFormat);\n+\tif (ret)\n+\t\treturn ret;\n+\n \tret = isp_[Isp::Input].dev()->setFormat(&unicamFormat);\n \tif (ret)\n \t\treturn ret;\n \n \tLOG(RPI, Info) << \"Sensor: \" << sensor_->id()\n-\t\t       << \" - Selected sensor format: \" << sensorFormat\n+\t\t       << \" - Selected sensor format: \" << rpiConfig->sensorFormat_\n \t\t       << \" - Selected unicam format: \" << unicamFormat;\n \n \t/* Use a sensible small default size if no output streams are configured. */\n",
    "prefixes": [
        "libcamera-devel",
        "v5",
        "10/13"
    ]
}