{"id":19951,"url":"https://patchwork.libcamera.org/api/patches/19951/?format=json","web_url":"https://patchwork.libcamera.org/patch/19951/","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":"<20240424234224.9658-7-laurent.pinchart@ideasonboard.com>","date":"2024-04-24T23:42:24","name":"[v1,6/6] pipeline: vimc: Don't hardcode scaling factor with recent kernels","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"f02f477020bcf992423c14ba9a62bb9981e785d4","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/19951/mbox/","series":[{"id":4271,"url":"https://patchwork.libcamera.org/api/series/4271/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4271","date":"2024-04-24T23:42:18","name":"vimc scaling improvements","version":1,"mbox":"https://patchwork.libcamera.org/series/4271/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19951/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19951/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 99C9AC3200\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 24 Apr 2024 23:42:50 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 60C0D63413;\n\tThu, 25 Apr 2024 01:42:49 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4471F633F3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 25 Apr 2024 01:42:36 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(117.145-247-81.adsl-dyn.isp.belgacom.be [81.247.145.117])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F0080B1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 25 Apr 2024 01:41:43 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"WL28wOUH\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1714002104;\n\tbh=hIGqR6Kt4tDC1fVeCf/uWAtzTPzODPcv5qnjoaKSsoo=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=WL28wOUHhGjQvzTjE2FGsBKx+9a6Gxwi6l26tM2u2SgMxF8UWIy1KThksNLmeJPnC\n\t6Uf8KB30/+V1Sx229bQovB9GJEDMA78XArchlyLUDP+Hygr0DUcNmHoT8ej0H7qy/N\n\t88Zuxadw5JshTQpCMdZif1V6Qe1mg7POJML553R0=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"[PATCH v1 6/6] pipeline: vimc: Don't hardcode scaling factor with\n\trecent kernels","Date":"Thu, 25 Apr 2024 02:42:24 +0300","Message-ID":"<20240424234224.9658-7-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.43.2","In-Reply-To":"<20240424234224.9658-1-laurent.pinchart@ideasonboard.com>","References":"<20240424234224.9658-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Starting in kernel v5.16, the vimc driver stopped hardcoding the scaler\nfactor. Use this to lift constraints on the camera configuration, and in\nparticular on the exotic output size alignment to a multiple of 6. As a\nresult, vimc-based cameras can more easily match common display\nresolutions.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/pipeline/vimc/vimc.cpp | 47 +++++++++++++++++++---------\n 1 file changed, 33 insertions(+), 14 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp\nindex 5e66ee1d26c1..be7a6733472b 100644\n--- a/src/libcamera/pipeline/vimc/vimc.cpp\n+++ b/src/libcamera/pipeline/vimc/vimc.cpp\n@@ -114,6 +114,9 @@ static const std::map<PixelFormat, uint32_t> pixelformats{\n \t{ formats::BGR888, MEDIA_BUS_FMT_RGB888_1X24 },\n };\n \n+static constexpr Size kMinSize{ 16, 16 };\n+static constexpr Size kMaxSize{ 4096, 2160 };\n+\n } /* namespace */\n \n VimcCameraConfiguration::VimcCameraConfiguration(VimcCameraData *data)\n@@ -153,14 +156,20 @@ CameraConfiguration::Status VimcCameraConfiguration::validate()\n \tconst Size size = cfg.size;\n \n \t/*\n-\t * The scaler hardcodes a x3 scale-up ratio, and the sensor output size\n-\t * is aligned to two pixels in both directions. The output width and\n-\t * height thus have to be multiples of 6.\n+\t * The sensor output size is aligned to two pixels in both directions.\n+\t * Additionally, prior to v5.16, the scaler hardcodes a x3 scale-up\n+\t * ratio, requiring the output width and height to be multiples of 6.\n \t */\n-\tcfg.size.width = std::max(48U, std::min(4096U, cfg.size.width));\n-\tcfg.size.height = std::max(48U, std::min(2160U, cfg.size.height));\n-\tcfg.size.width -= cfg.size.width % 6;\n-\tcfg.size.height -= cfg.size.height % 6;\n+\tSize minSize{ kMinSize };\n+\tunsigned int alignment = 2;\n+\n+\tif (data_->media_->version() < KERNEL_VERSION(5, 16, 0)) {\n+\t\tminSize *= 3;\n+\t\talignment *= 3;\n+\t}\n+\n+\tcfg.size.expandTo(minSize).boundTo(kMaxSize)\n+\t\t.alignDownTo(alignment, alignment);\n \n \tif (cfg.size != size) {\n \t\tLOG(VIMC, Debug)\n@@ -216,10 +225,12 @@ PipelineHandlerVimc::generateConfiguration(Camera *camera,\n \t\t\t}\n \t\t}\n \n-\t\t/* The scaler hardcodes a x3 scale-up ratio. */\n-\t\tstd::vector<SizeRange> sizes{\n-\t\t\tSizeRange{ { 48, 48 }, { 4096, 2160 } }\n-\t\t};\n+\t\t/* Prior to v5.16, the scaler hardcodes a x3 scale-up ratio. */\n+\t\tSize minSize{ kMinSize };\n+\t\tif (data->media_->version() < KERNEL_VERSION(5, 16, 0))\n+\t\t\tminSize *= 3;\n+\n+\t\tstd::vector<SizeRange> sizes{ { minSize, kMaxSize } };\n \t\tformats[pixelformat.first] = sizes;\n \t}\n \n@@ -242,10 +253,18 @@ int PipelineHandlerVimc::configure(Camera *camera, CameraConfiguration *config)\n \tStreamConfiguration &cfg = config->at(0);\n \tint ret;\n \n-\t/* The scaler hardcodes a x3 scale-up ratio. */\n+\t/*\n+\t * Prior to v5.16, the scaler hardcodes a x3 scale-up ratio. For newer\n+\t * kernels, use a sensor resolution of 1920x1080 and let the scaler\n+\t * produce the requested stream size.\n+\t */\n+\tSize sensorSize{ 1920, 1080 };\n+\tif (data->media_->version() < KERNEL_VERSION(5, 16, 0))\n+\t\tsensorSize = { cfg.size.width / 3, cfg.size.height / 3 };\n+\n \tV4L2SubdeviceFormat subformat = {};\n \tsubformat.code = MEDIA_BUS_FMT_SGRBG8_1X8;\n-\tsubformat.size = { cfg.size.width / 3, cfg.size.height / 3 };\n+\tsubformat.size = sensorSize;\n \n \tret = data->sensor_->setFormat(&subformat);\n \tif (ret)\n@@ -293,7 +312,7 @@ int PipelineHandlerVimc::configure(Camera *camera, CameraConfiguration *config)\n \t * vimc driver will fail pipeline validation.\n \t */\n \tformat.fourcc = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8);\n-\tformat.size = { cfg.size.width / 3, cfg.size.height / 3 };\n+\tformat.size = sensorSize;\n \n \tret = data->raw_->setFormat(&format);\n \tif (ret)\n","prefixes":["v1","6/6"]}