Patch Detail
Show a patch.
GET /api/1.1/patches/18834/?format=api
{ "id": 18834, "url": "https://patchwork.libcamera.org/api/1.1/patches/18834/?format=api", "web_url": "https://patchwork.libcamera.org/patch/18834/", "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": "<20230714142634.13134-3-jacopo.mondi@ideasonboard.com>", "date": "2023-07-14T14:26:33", "name": "[libcamera-devel,v2,2/3] libcamera: rpi: pipeline_base: Move findBestFormat to CameraData", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "6132160dfa4ddc86b7404a9df60641b6ccd36150", "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/18834/mbox/", "series": [ { "id": 3972, "url": "https://patchwork.libcamera.org/api/1.1/series/3972/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3972", "date": "2023-07-14T14:26:31", "name": "Raspberry Pi: Configuration simplifications", "version": 2, "mbox": "https://patchwork.libcamera.org/series/3972/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/18834/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/18834/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 1532AC32AA\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 14 Jul 2023 14:26:59 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 89C16628CB;\n\tFri, 14 Jul 2023 16:26:58 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 80D4C60382\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 14 Jul 2023 16:26:55 +0200 (CEST)", "from uno.localdomain (mob-5-90-9-92.net.vodafone.it [5.90.9.92])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5B196D01;\n\tFri, 14 Jul 2023 16:26:04 +0200 (CEST)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1689344818;\n\tbh=SJPvSZ3bvmhraCsC8eN2BA+aYYspDXZ2Jec5wa5heGs=;\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=dW1Hbs5VJnBIo4qBy/IrAXAgW4Wi9UGA0DxAicpq1rAYPco7pyWe0Vg5ox2xIYVCl\n\tHd+2ebYQuWXW+Jdeg+Q+j2wxrGvicBcyvZ08om29QWXIBV5IrzIg4TjcTEcsehgTtv\n\tAXo7AubpsU3q9dOzc8p5FDwq8B/Etxvl/l5r0E52YTH4QtfkNEw6j7UMwDSMgURUia\n\tlXPHhfqjDdHGEZzS6a9XtSE5l+jz6kUUxhZwgIxXfuOdR5LV42VETYKzzVqyw/SkpA\n\tpqHh2xsN0NPbkbM+pw50Ji34ecmRGjtPNcjLdHTB8SWaQ8chJy3CuJz8twM9as+3Eb\n\tT3PsT5iOK/aSg==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1689344764;\n\tbh=SJPvSZ3bvmhraCsC8eN2BA+aYYspDXZ2Jec5wa5heGs=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=WorixpT4a/7o4ZuvHQ65hIqBVlb+jy+brk7W9aMQcWkvU/yRc0r+HFAC1jsJrfTj0\n\t0oi0Ye1CXYRD6JvI0P2/CZyebN4LLf9qlZzCVo3Wbij56PRw0t+jbMB+qfKu5n07uf\n\tFN78Op79cr896XH8VOD7yjmpHxMJOR+5QSMxhNEk=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"WorixpT4\"; dkim-atps=neutral", "To": "libcamera-devel@lists.libcamera.org", "Date": "Fri, 14 Jul 2023 16:26:33 +0200", "Message-Id": "<20230714142634.13134-3-jacopo.mondi@ideasonboard.com>", "X-Mailer": "git-send-email 2.40.1", "In-Reply-To": "<20230714142634.13134-1-jacopo.mondi@ideasonboard.com>", "References": "<20230714142634.13134-1-jacopo.mondi@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 2/3] libcamera: rpi: pipeline_base:\n\tMove findBestFormat to CameraData", "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": "The findBestFormat() helper operates on the list of sensor formats,\nwhich is owned by the CameraData class. Move the function to that class\nas well to:\n\n1) Avoid passing the list of formats to the function\n2) Remove a static helper in favour of a class function\n3) Allow subclasses with access to CameraData to call the function\n\nMove to the CameraData class the scoreFormat helper as well.\n\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n---\n .../pipeline/rpi/common/pipeline_base.cpp | 139 ++++++++++--------\n .../pipeline/rpi/common/pipeline_base.h | 3 +\n 2 files changed, 78 insertions(+), 64 deletions(-)", "diff": "diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\nindex fb3756a47590..a71715a6aff0 100644\n--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n@@ -74,63 +74,6 @@ bool isMonoSensor(std::unique_ptr<CameraSensor> &sensor)\n \treturn bayer.order == BayerFormat::Order::MONO;\n }\n \n-double scoreFormat(double desired, double actual)\n-{\n-\tdouble score = desired - actual;\n-\t/* Smaller desired dimensions are preferred. */\n-\tif (score < 0.0)\n-\t\tscore = (-score) / 8;\n-\t/* Penalise non-exact matches. */\n-\tif (actual != desired)\n-\t\tscore *= 2;\n-\n-\treturn score;\n-}\n-\n-V4L2SubdeviceFormat findBestFormat(const SensorFormats &formatsMap, const Size &req, unsigned int bitDepth)\n-{\n-\tdouble bestScore = std::numeric_limits<double>::max(), score;\n-\tV4L2SubdeviceFormat bestFormat;\n-\tbestFormat.colorSpace = ColorSpace::Raw;\n-\n-\tconstexpr float penaltyAr = 1500.0;\n-\tconstexpr float penaltyBitDepth = 500.0;\n-\n-\t/* Calculate the closest/best mode from the user requested size. */\n-\tfor (const auto &iter : formatsMap) {\n-\t\tconst unsigned int mbusCode = iter.first;\n-\t\tconst PixelFormat format = mbusCodeToPixelFormat(mbusCode,\n-\t\t\t\t\t\t\t\t BayerFormat::Packing::None);\n-\t\tconst PixelFormatInfo &info = PixelFormatInfo::info(format);\n-\n-\t\tfor (const Size &size : iter.second) {\n-\t\t\tdouble reqAr = static_cast<double>(req.width) / req.height;\n-\t\t\tdouble fmtAr = static_cast<double>(size.width) / size.height;\n-\n-\t\t\t/* Score the dimensions for closeness. */\n-\t\t\tscore = scoreFormat(req.width, size.width);\n-\t\t\tscore += scoreFormat(req.height, size.height);\n-\t\t\tscore += penaltyAr * scoreFormat(reqAr, fmtAr);\n-\n-\t\t\t/* Add any penalties... this is not an exact science! */\n-\t\t\tscore += utils::abs_diff(info.bitsPerPixel, bitDepth) * penaltyBitDepth;\n-\n-\t\t\tif (score <= bestScore) {\n-\t\t\t\tbestScore = score;\n-\t\t\t\tbestFormat.mbus_code = mbusCode;\n-\t\t\t\tbestFormat.size = size;\n-\t\t\t}\n-\n-\t\t\tLOG(RPI, Debug) << \"Format: \" << size\n-\t\t\t\t\t<< \" fmt \" << format\n-\t\t\t\t\t<< \" Score: \" << score\n-\t\t\t\t\t<< \" (best \" << bestScore << \")\";\n-\t\t}\n-\t}\n-\n-\treturn bestFormat;\n-}\n-\n const std::vector<ColorSpace> validColorSpaces = {\n \tColorSpace::Sycc,\n \tColorSpace::Smpte170m,\n@@ -265,6 +208,17 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \t\t [](auto &l, auto &r) { return l.cfg->size > r.cfg->size; });\n \n \t/* Do any platform specific fixups. */\n+\tunsigned int bitDepth = defaultRawBitDepth;\n+\tif (!rawStreams.empty()) {\n+\t\tBayerFormat bayerFormat = BayerFormat::fromPixelFormat(rawStreams[0].cfg->pixelFormat);\n+\t\tbitDepth = bayerFormat.bitDepth;\n+\t}\n+\n+\tV4L2SubdeviceFormat sensorFormat =\n+\t\tdata_->findBestFormat(rawStreams.empty() ? outStreams[0].cfg->size\n+\t\t\t\t\t\t\t : rawStreams[0].cfg->size,\n+\t\t\t\t bitDepth);\n+\n \tstatus = data_->platformValidate(rawStreams, outStreams);\n \tif (status == Invalid)\n \t\treturn Invalid;\n@@ -275,8 +229,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \t\tV4L2DeviceFormat rawFormat;\n \n \t\tconst PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat);\n-\t\tunsigned int bitDepth = info.isValid() ? info.bitsPerPixel : defaultRawBitDepth;\n-\t\tV4L2SubdeviceFormat sensorFormat = findBestFormat(data_->sensorFormats_, cfg.size, bitDepth);\n+\t\tbitDepth = info.isValid() ? info.bitsPerPixel : defaultRawBitDepth;\n \n \t\tBayerFormat::Packing packing = BayerFormat::fromPixelFormat(cfg.pixelFormat).packing;\n \t\trawFormat = PipelineHandlerBase::toV4L2DeviceFormat(raw.dev, sensorFormat, packing);\n@@ -391,7 +344,7 @@ PipelineHandlerBase::generateConfiguration(Camera *camera, Span<const StreamRole\n \t\tswitch (role) {\n \t\tcase StreamRole::Raw:\n \t\t\tsize = sensorSize;\n-\t\t\tsensorFormat = findBestFormat(data->sensorFormats_, size, defaultRawBitDepth);\n+\t\t\tsensorFormat = data->findBestFormat(size, defaultRawBitDepth);\n \t\t\tpixelFormat = mbusCodeToPixelFormat(sensorFormat.mbus_code,\n \t\t\t\t\t\t\t BayerFormat::Packing::CSI2);\n \t\t\tASSERT(pixelFormat.isValid());\n@@ -531,10 +484,11 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config)\n \t\tbitDepth = bayerFormat.bitDepth;\n \t}\n \n-\tV4L2SubdeviceFormat sensorFormat = findBestFormat(data->sensorFormats_,\n-\t\t\t\t\t\t\t rawStreams.empty() ? ispStreams[0].cfg->size\n-\t\t\t\t\t\t\t\t\t : rawStreams[0].cfg->size,\n-\t\t\t\t\t\t\t bitDepth);\n+\tV4L2SubdeviceFormat sensorFormat =\n+\t\tdata->findBestFormat(rawStreams.empty() ? ispStreams[0].cfg->size\n+\t\t\t\t\t\t\t: rawStreams[0].cfg->size,\n+\t\t\t\t bitDepth);\n+\n \t/* Apply any cached transform. */\n \tconst RPiCameraConfiguration *rpiConfig = static_cast<const RPiCameraConfiguration *>(config);\n \n@@ -954,6 +908,63 @@ int PipelineHandlerBase::queueAllBuffers(Camera *camera)\n \treturn 0;\n }\n \n+double CameraData::scoreFormat(double desired, double actual) const\n+{\n+\tdouble score = desired - actual;\n+\t/* Smaller desired dimensions are preferred. */\n+\tif (score < 0.0)\n+\t\tscore = (-score) / 8;\n+\t/* Penalise non-exact matches. */\n+\tif (actual != desired)\n+\t\tscore *= 2;\n+\n+\treturn score;\n+}\n+\n+V4L2SubdeviceFormat CameraData::findBestFormat(const Size &req, unsigned int bitDepth) const\n+{\n+\tdouble bestScore = std::numeric_limits<double>::max(), score;\n+\tV4L2SubdeviceFormat bestFormat;\n+\tbestFormat.colorSpace = ColorSpace::Raw;\n+\n+\tconstexpr float penaltyAr = 1500.0;\n+\tconstexpr float penaltyBitDepth = 500.0;\n+\n+\t/* Calculate the closest/best mode from the user requested size. */\n+\tfor (const auto &iter : sensorFormats_) {\n+\t\tconst unsigned int mbusCode = iter.first;\n+\t\tconst PixelFormat format = mbusCodeToPixelFormat(mbusCode,\n+\t\t\t\t\t\t\t\t BayerFormat::Packing::None);\n+\t\tconst PixelFormatInfo &info = PixelFormatInfo::info(format);\n+\n+\t\tfor (const Size &size : iter.second) {\n+\t\t\tdouble reqAr = static_cast<double>(req.width) / req.height;\n+\t\t\tdouble fmtAr = static_cast<double>(size.width) / size.height;\n+\n+\t\t\t/* Score the dimensions for closeness. */\n+\t\t\tscore = scoreFormat(req.width, size.width);\n+\t\t\tscore += scoreFormat(req.height, size.height);\n+\t\t\tscore += penaltyAr * scoreFormat(reqAr, fmtAr);\n+\n+\t\t\t/* Add any penalties... this is not an exact science! */\n+\t\t\tscore += utils::abs_diff(info.bitsPerPixel, bitDepth) * penaltyBitDepth;\n+\n+\t\t\tif (score <= bestScore) {\n+\t\t\t\tbestScore = score;\n+\t\t\t\tbestFormat.mbus_code = mbusCode;\n+\t\t\t\tbestFormat.size = size;\n+\t\t\t}\n+\n+\t\t\tLOG(RPI, Debug) << \"Format: \" << size\n+\t\t\t\t\t<< \" fmt \" << format\n+\t\t\t\t\t<< \" Score: \" << score\n+\t\t\t\t\t<< \" (best \" << bestScore << \")\";\n+\t\t}\n+\t}\n+\n+\treturn bestFormat;\n+}\n+\n void CameraData::freeBuffers()\n {\n \tif (ipa_) {\ndiff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h\nindex f648e81054bb..2eda3cd89812 100644\n--- a/src/libcamera/pipeline/rpi/common/pipeline_base.h\n+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h\n@@ -81,6 +81,9 @@ public:\n \tvirtual void platformStart() = 0;\n \tvirtual void platformStop() = 0;\n \n+\tdouble scoreFormat(double desired, double actual) const;\n+\tV4L2SubdeviceFormat findBestFormat(const Size &req, unsigned int bitDepth) const;\n+\n \tvoid freeBuffers();\n \tvirtual void platformFreeBuffers() = 0;\n \n", "prefixes": [ "libcamera-devel", "v2", "2/3" ] }