{"id":19030,"url":"https://patchwork.libcamera.org/api/patches/19030/?format=json","web_url":"https://patchwork.libcamera.org/patch/19030/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20230915130650.35691-13-jacopo.mondi@ideasonboard.com>","date":"2023-09-15T13:06:50","name":"[libcamera-devel,v3,12/12] libcamera: rpi: Simplify validate() and configure() for YUV/RGB streams","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"40492a9573ae5da11fe3bb4c8abdcc40ad2cb2d7","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/?format=json","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/19030/mbox/","series":[{"id":4025,"url":"https://patchwork.libcamera.org/api/series/4025/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4025","date":"2023-09-15T13:06:38","name":"libcamera: Introduce SensorConfiguration","version":3,"mbox":"https://patchwork.libcamera.org/series/4025/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19030/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19030/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 A3A13C32B0\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 15 Sep 2023 13:07:21 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 65AF46292F;\n\tFri, 15 Sep 2023 15:07:21 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EE3F362928\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Sep 2023 15:07:12 +0200 (CEST)","from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 896A62F6C;\n\tFri, 15 Sep 2023 15:05:39 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1694783241;\n\tbh=t05fFLPiScMNjDYmygJ5MwL6tWEYKYUaHsg2TlIfDeY=;\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=N/r4kDjYC9qBrWtkk/93oMI2VGFCp4L3/ZjNcta4SvE9xTWBqFQ0oqqbRhebQiENT\n\tnaB5vPo9owUR8JktJ0aZjTs/eyb6OfwLRTYgdV7Xiijxi7uk3iCfzKA8+E1SXs3BjY\n\t3jDTcXla2Hqtov+6vTC0d0y0kLShi87hZtyAlId2rH1x1opYANWj08xzXAduKFMnav\n\taJCNsGOTpA8k9N7xizvZ6Vq+188DNTWaXDBYyY8Hp+LfiaBTiCZrwCNhCpHpU7N8B5\n\tGHBFXwKJsoZSAFQK6XD3rbbqWEFzV8euROTj9QBfWbkjwHshrGVqEukpbAbEGucAxq\n\tqK05khYxi68SA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1694783139;\n\tbh=t05fFLPiScMNjDYmygJ5MwL6tWEYKYUaHsg2TlIfDeY=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=MDXXHnROG/E5ttB4RGuQvj1SRoIogwuia5tevmA91cQfCKgkMANTPXDHZeLhlijtc\n\tZV2PU+5MosT+HCGlmeIzAj/wn1sDSG1KTizVMLrPW7spymZ1h0w4dQRGpoTWh+mvjC\n\tUrA0g/aYlPuxh9buEqCVOGNl2gB67efkRsZNUijA="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"MDXXHnRO\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 15 Sep 2023 15:06:50 +0200","Message-ID":"<20230915130650.35691-13-jacopo.mondi@ideasonboard.com>","X-Mailer":"git-send-email 2.42.0","In-Reply-To":"<20230915130650.35691-1-jacopo.mondi@ideasonboard.com>","References":"<20230915130650.35691-1-jacopo.mondi@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 12/12] libcamera: rpi: Simplify\n\tvalidate() and configure() for YUV/RGB 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- Determine the V4L2DeviceFormat structure fields for all streams\n  in validate(), cache them and reuse in configure() instead of\n  re-generating this structure multiple times.\n\n- Remove setting a default pixel format in validate(), this code patch\n  will not be used.\n\n- Use the recently added updateStreamConfig() and toV4L2DeviceFormat()\n  helpers to populate fields in the V4L2DeviceFormat and StreamConfiguration\n  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     | 49 ++++---------------\n src/libcamera/pipeline/rpi/vc4/vc4.cpp        | 15 ++----\n 2 files changed, 12 insertions(+), 52 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\nindex 0de91123ee50..51d54e57ceaf 100644\n--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n@@ -258,56 +258,25 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \n \t/* Further fixups on the ISP output streams. */\n \tfor (auto &out : outStreams_) {\n-\t\tStreamConfiguration &cfg = config_.at(out.index);\n-\t\tPixelFormat &cfgPixFmt = cfg.pixelFormat;\n-\t\tV4L2VideoDevice::Formats fmts = out.dev->formats();\n-\n-\t\tif (fmts.find(out.dev->toV4L2PixelFormat(cfgPixFmt)) == fmts.end()) {\n-\t\t\t/* If we cannot find a native format, use a default one. */\n-\t\t\tcfgPixFmt = formats::YUV420;\n-\t\t\tstatus = Adjusted;\n-\t\t}\n-\n-\t\tV4L2DeviceFormat format;\n-\t\tformat.fourcc = out.dev->toV4L2PixelFormat(cfg.pixelFormat);\n-\t\tformat.size = cfg.size;\n \n \t\t/*\n-\t\t * platformValidate may have worked out the correct stride so we\n-\t\t * must pass it in. This also needs the planesCount to be set\n-\t\t * correctly or the stride will be ignored.\n+\t\t * We want to send the associated YCbCr info through to the driver.\n+\t\t *\n+\t\t * But for RGB streams, the YCbCr info gets overwritten on the way back\n+\t\t * so we must check against what the stream cfg says, not what we actually\n+\t\t * requested (which carefully included the YCbCr info)!\n \t\t */\n-\t\tconst PixelFormat &pixFormat = format.fourcc.toPixelFormat();\n-\t\tconst PixelFormatInfo &info = PixelFormatInfo::info(pixFormat);\n-\t\tformat.planesCount = info.numPlanes();\n-\t\tformat.planes[0].bpl = cfg.stride;\n-\n-\t\t/* We want to send the associated YCbCr info through to the driver. */\n-\t\tformat.colorSpace = yuvColorSpace_;\n+\t\tout.format.colorSpace = yuvColorSpace_;\n \n \t\tLOG(RPI, Debug)\n-\t\t\t<< \"Try color space \" << ColorSpace::toString(cfg.colorSpace);\n+\t\t\t<< \"Try color space \" << ColorSpace::toString(out.cfg->colorSpace);\n \n-\t\tint ret = out.dev->tryFormat(&format);\n+\t\tint ret = out.dev->tryFormat(&out.format);\n \t\tif (ret)\n \t\t\treturn Invalid;\n \n-\t\t/*\n-\t\t * But for RGB streams, the YCbCr info gets overwritten on the way back\n-\t\t * so we must check against what the stream cfg says, not what we actually\n-\t\t * requested (which carefully included the YCbCr info)!\n-\t\t */\n-\t\tif (cfg.colorSpace != format.colorSpace) {\n+\t\tif (RPi::PipelineHandlerBase::updateStreamConfig(out.cfg, out.format))\n \t\t\tstatus = Adjusted;\n-\t\t\tLOG(RPI, Debug)\n-\t\t\t\t<< \"Color space changed from \"\n-\t\t\t\t<< ColorSpace::toString(cfg.colorSpace) << \" to \"\n-\t\t\t\t<< ColorSpace::toString(format.colorSpace);\n-\t\t}\n-\n-\t\tcfg.colorSpace = format.colorSpace;\n-\t\tcfg.stride = format.planes[0].bpl;\n-\t\tcfg.frameSize = format.planes[0].size;\n \t}\n \n \treturn status;\ndiff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\nindex 1a03c88d7ee3..a1813ba65725 100644\n--- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n+++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n@@ -457,6 +457,8 @@ CameraConfiguration::Status Vc4CameraData::platformValidate(RPi::RPiCameraConfig\n \t\t * have that fixed up in the code above.\n \t\t */\n \t\toutStreams[i].dev = isp_[i == 0 ? Isp::Output0 : Isp::Output1].dev();\n+\n+\t\toutStreams[i].format = RPi::PipelineHandlerBase::toV4L2DeviceFormat(outStreams[i].dev, outStreams[i].cfg);\n \t}\n \n \treturn status;\n@@ -549,11 +551,7 @@ int Vc4CameraData::platformConfigure(const RPi::RPiCameraConfiguration *rpiConfi\n \n \t\t/* The largest resolution gets routed to the ISP Output 0 node. */\n \t\tRPi::Stream *stream = i == 0 ? &isp_[Isp::Output0] : &isp_[Isp::Output1];\n-\n-\t\tV4L2PixelFormat fourcc = stream->dev()->toV4L2PixelFormat(cfg->pixelFormat);\n-\t\tformat.size = cfg->size;\n-\t\tformat.fourcc = fourcc;\n-\t\tformat.colorSpace = cfg->colorSpace;\n+\t\tformat = outStreams[i].format;\n \n \t\tLOG(RPI, Debug) << \"Setting \" << stream->name() << \" to \"\n \t\t\t\t<< format;\n@@ -562,13 +560,6 @@ int Vc4CameraData::platformConfigure(const RPi::RPiCameraConfiguration *rpiConfi\n \t\tif (ret)\n \t\t\treturn -EINVAL;\n \n-\t\tif (format.size != cfg->size || format.fourcc != fourcc) {\n-\t\t\tLOG(RPI, Error)\n-\t\t\t\t<< \"Failed to set requested format on \" << stream->name()\n-\t\t\t\t<< \", returned \" << format;\n-\t\t\treturn -EINVAL;\n-\t\t}\n-\n \t\tLOG(RPI, Debug)\n \t\t\t<< \"Stream \" << stream->name() << \" has color space \"\n \t\t\t<< ColorSpace::toString(cfg->colorSpace);\n","prefixes":["libcamera-devel","v3","12/12"]}