{"id":19050,"url":"https://patchwork.libcamera.org/api/1.1/patches/19050/?format=json","web_url":"https://patchwork.libcamera.org/patch/19050/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20230916121930.29490-13-jacopo.mondi@ideasonboard.com>","date":"2023-09-16T12:19:30","name":"[libcamera-devel,v4,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/1.1/people/143/?format=json","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/19050/mbox/","series":[{"id":4027,"url":"https://patchwork.libcamera.org/api/1.1/series/4027/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4027","date":"2023-09-16T12:19:18","name":"libcamera: Introduce SensorConfiguration","version":4,"mbox":"https://patchwork.libcamera.org/series/4027/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19050/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19050/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 D610FBD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 16 Sep 2023 12:19:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7BB2F6292B;\n\tSat, 16 Sep 2023 14:19:51 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 73DBF6292C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 16 Sep 2023 14:19:42 +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 5E5181536;\n\tSat, 16 Sep 2023 14:18:08 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1694866791;\n\tbh=c2GvTrMZTJMcatCGIVz4vOVZW5KTZwYWXeD5Zy0NktE=;\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=Ut/RqphhMnBwM8uj3SCSHy4YbqZPExcQuGrUsdojRr2OfF55Pi1U1Vws2Xxfufl6R\n\tGYIorF59rGe/WpRIgIl6B5n9P2fCkuPWtO8ZiTWYFINYDjW7tRXDVPIts6dnQzdFVq\n\tq3Ru2HDNjXwwnmX6DLZxwa/V9qn1bFPxiyIvlDUadOkVBW0+RvpWnLc3o7ftyI/4Hj\n\tBS01wsy52y8WvQz6WWj4FCUPeRzmjPkMd6yE5w+GfZE9KJK4d7Foj3ajW6M2jYm/IU\n\t7GU1tCfmb6GZXKIzvX9pVDN0iGDAjFzGw1NhYRZwDqQZmJx8Y5gACJ+/QIxSPxd50m\n\tWAxw/E7UvBkbw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1694866688;\n\tbh=c2GvTrMZTJMcatCGIVz4vOVZW5KTZwYWXeD5Zy0NktE=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=R36eqtMi4VHmG4vRfdvSLey2yTwIizrrJ6EIiPE1PPO9kWVSuTt1LtonbwBQj5kQI\n\tn6Yg1H8MxxtVUe+xWCmiuYKXBjsMnx93VN3Kz8FdnUR422O1N7b9qQO92iMJ3xM8QU\n\tCUI/ubpxSuaA610om+ZTnhQtn0fptz37KIrlZgcs="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"R36eqtMi\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Sat, 16 Sep 2023 14:19:30 +0200","Message-ID":"<20230916121930.29490-13-jacopo.mondi@ideasonboard.com>","X-Mailer":"git-send-email 2.42.0","In-Reply-To":"<20230916121930.29490-1-jacopo.mondi@ideasonboard.com>","References":"<20230916121930.29490-1-jacopo.mondi@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 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 c69e076aac71..653faff12353 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","v4","12/12"]}