[{"id":36433,"web_url":"https://patchwork.libcamera.org/comment/36433/","msgid":"<4nkpxpq2j62fax5i6wjfrclzq3lxqzejpofibyr4wa6xed3vsd@js6q4qlvd6g7>","date":"2025-10-24T11:53:29","subject":"Re: [PATCH v13 3/8] libcamera: simple: Handle processed and raw\n\tformats separately","submitter":{"id":232,"url":"https://patchwork.libcamera.org/api/people/232/","name":"Umang Jain","email":"uajain@igalia.com"},"content":"On Tue, Oct 21, 2025 at 08:27:10PM +0200, Milan Zamazal wrote:\n> Let's handle both processed and/or raw output configurations.  In\n> addition to the already handled processed formats and sizes, this patch\n> adds handling of raw formats and sizes, which correspond to the capture\n> formats and sizes.\n> \n> When creating stream configurations, raw or processed formats are\n> selected according to the requested stream roles.\n> \n> This is another preparatory patch without making raw outputs working.\n> \n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> ---\n>  src/libcamera/pipeline/simple/simple.cpp | 79 +++++++++++++++++-------\n>  1 file changed, 56 insertions(+), 23 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\n> index 1f67094db..d7675538f 100644\n> --- a/src/libcamera/pipeline/simple/simple.cpp\n> +++ b/src/libcamera/pipeline/simple/simple.cpp\n> @@ -1343,42 +1343,75 @@ SimplePipelineHandler::generateConfiguration(Camera *camera, Span<const StreamRo\n>  \tif (roles.empty())\n>  \t\treturn config;\n>  \n> -\t/* Create the formats map. */\n> -\tstd::map<PixelFormat, std::vector<SizeRange>> formats;\n> +\tbool processedRequested = false;\n> +\tbool rawRequested = false;\n> +\tfor (const auto &role : roles)\n> +\t\tif (role == StreamRole::Raw) {\n> +\t\t\tif (rawRequested) {\n> +\t\t\t\tLOG(SimplePipeline, Error)\n> +\t\t\t\t\t<< \"Can't capture multiple raw streams\";\n> +\t\t\t\treturn nullptr;\n> +\t\t\t}\n> +\t\t\trawRequested = true;\n> +\t\t} else {\n> +\t\t\tprocessedRequested = true;\n\nFor me, I find processed stream request is implicit to libcamera but if\nyou find you need to track these separately, I can live with that.\n\n> +\t\t}\n> +\n> +\t/* Create the formats maps. */\n> +\tstd::map<PixelFormat, std::vector<SizeRange>> processedFormats;\n> +\tstd::map<PixelFormat, std::vector<SizeRange>> rawFormats;\n>  \n>  \tfor (const SimpleCameraData::Configuration &cfg : data->configs_) {\n> +\t\trawFormats[cfg.captureFormat].push_back(cfg.captureSize);\n>  \t\tfor (PixelFormat format : cfg.outputFormats)\n> -\t\t\tformats[format].push_back(cfg.outputSizes);\n> +\t\t\tprocessedFormats[format].push_back(cfg.outputSizes);\n>  \t}\n>  \n> -\t/* Sort the sizes and merge any consecutive overlapping ranges. */\n> -\tfor (auto &[format, sizes] : formats) {\n> -\t\tstd::sort(sizes.begin(), sizes.end(),\n> -\t\t\t  [](SizeRange &a, SizeRange &b) {\n> -\t\t\t\t  return a.min < b.min;\n> -\t\t\t  });\n> -\n> -\t\tauto cur = sizes.begin();\n> -\t\tauto next = cur;\n> -\n> -\t\twhile (++next != sizes.end()) {\n> -\t\t\tif (cur->max.width >= next->min.width &&\n> -\t\t\t    cur->max.height >= next->min.height)\n> -\t\t\t\tcur->max = next->max;\n> -\t\t\telse if (++cur != next)\n> -\t\t\t\t*cur = *next;\n> -\t\t}\n> -\n> -\t\tsizes.erase(++cur, sizes.end());\n> +\tif (processedRequested && processedFormats.empty()) {\n> +\t\tLOG(SimplePipeline, Error)\n> +\t\t\t<< \"Processed stream requsted but no corresponding output configuration found\";\n\ns/requsted/requested\n\n> +\t\treturn nullptr;\n> +\t}\n> +\tif (rawRequested && rawFormats.empty()) {\n> +\t\tLOG(SimplePipeline, Error)\n> +\t\t\t<< \"Raw stream requsted but no corresponding output configuration found\";\n\nDitto.\n\nReviewed-by: Umang Jain <uajain@igalia.com>\n\n> +\t\treturn nullptr;\n>  \t}\n>  \n> +\tauto setUpFormatSizes = [](std::map<PixelFormat, std::vector<SizeRange>> &formats) {\n> +\t\t/* Sort the sizes and merge any consecutive overlapping ranges. */\n> +\n> +\t\tfor (auto &[format, sizes] : formats) {\n> +\t\t\tstd::sort(sizes.begin(), sizes.end(),\n> +\t\t\t\t  [](SizeRange &a, SizeRange &b) {\n> +\t\t\t\t\t  return a.min < b.min;\n> +\t\t\t\t  });\n> +\n> +\t\t\tauto cur = sizes.begin();\n> +\t\t\tauto next = cur;\n> +\n> +\t\t\twhile (++next != sizes.end()) {\n> +\t\t\t\tif (cur->max.width >= next->min.width &&\n> +\t\t\t\t    cur->max.height >= next->min.height)\n> +\t\t\t\t\tcur->max = next->max;\n> +\t\t\t\telse if (++cur != next)\n> +\t\t\t\t\t*cur = *next;\n> +\t\t\t}\n> +\n> +\t\t\tsizes.erase(++cur, sizes.end());\n> +\t\t}\n> +\t};\n> +\tsetUpFormatSizes(processedFormats);\n> +\tsetUpFormatSizes(rawFormats);\n> +\n>  \t/*\n>  \t * Create the stream configurations. Take the first entry in the formats\n>  \t * map as the default, for lack of a better option.\n>  \t *\n>  \t * \\todo Implement a better way to pick the default format\n>  \t */\n> -\tfor ([[maybe_unused]] StreamRole role : roles) {\n> +\tfor (StreamRole role : roles) {\n> +\t\tconst auto &formats = (role == StreamRole::Raw ? rawFormats : processedFormats);\n>  \t\tStreamConfiguration cfg{ StreamFormats{ formats } };\n>  \t\tcfg.pixelFormat = formats.begin()->first;\n>  \t\tcfg.size = formats.begin()->second[0].max;\n> -- \n> 2.51.0\n>","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 08A2ABE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 24 Oct 2025 11:53:03 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 23A3560934;\n\tFri, 24 Oct 2025 13:53:02 +0200 (CEST)","from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9C0AF608BD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Oct 2025 13:53:00 +0200 (CEST)","from 62-244-186-53.cust.exponential-e.net ([62.244.186.53]\n\thelo=uajain) by fanzine2.igalia.com with esmtpsa \n\t(Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256)\n\t(Exim) id 1vCGLr-00EkAP-UA; Fri, 24 Oct 2025 13:53:00 +0200"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=igalia.com header.i=@igalia.com\n\theader.b=\"h0KxMHk2\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com;\n\ts=20170329;\n\th=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:\n\tSubject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID:\n\tContent-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc\n\t:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe:\n\tList-Post:List-Owner:List-Archive;\n\tbh=AgQbpSgJUGwm91D0veihZ86V1XEbhiOyt6MMvUrOmaE=;\n\tb=h0KxMHk2lL9p29sQDYjfllATSu\n\tMf31WH5//7oQRRbMH2WGtWOZa0LOsMjlVCTk7/sfSN+qQ3nQE0fZJY3napiHJXKoCs0rN6uXcf1b4\n\tglR62dlKqB4n966LDCLGhA/oCaIL8juO+1ePlYn8l/HpbUG2NDPT98gWDGSrsW46bymLgQ+aeVK40\n\tcgn5xYb12OhDG8WecD3S+r+WzGaVBF4n6/db+wdr5Y/zjQj6s/9GX+TwAHpeAgcF+HGdifa4OtigT\n\tM87gP16kL5/r4JWkDRSfY+gVcJ8JRi5CBIKUEjFNrewrbxefm5052poyT0in7L62kB8Dca4oXp2qT\n\tAUMvrJuQ==;","Date":"Fri, 24 Oct 2025 12:53:29 +0100","From":"Umang Jain <uajain@igalia.com>","To":"Milan Zamazal <mzamazal@redhat.com>","Cc":"libcamera-devel@lists.libcamera.org, Laurent Pinchart\n\t<laurent.pinchart@ideasonboard.com>, Kieran Bingham\n\t<kieran.bingham@ideasonboard.com>, =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?=\n\t<barnabas.pocze@ideasonboard.com>, Paul Elder\n\t<paul.elder@ideasonboard.com>","Subject":"Re: [PATCH v13 3/8] libcamera: simple: Handle processed and raw\n\tformats separately","Message-ID":"<4nkpxpq2j62fax5i6wjfrclzq3lxqzejpofibyr4wa6xed3vsd@js6q4qlvd6g7>","References":"<20251021182716.29274-1-mzamazal@redhat.com>\n\t<20251021182716.29274-4-mzamazal@redhat.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20251021182716.29274-4-mzamazal@redhat.com>","User-Agent":"NeoMutt/20250905-dirty","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>"}}]