Patch Detail
Show a patch.
GET /api/patches/14955/?format=api
{ "id": 14955, "url": "https://patchwork.libcamera.org/api/patches/14955/?format=api", "web_url": "https://patchwork.libcamera.org/patch/14955/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/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": "<20211201101508.10619-3-david.plowman@raspberrypi.com>", "date": "2021-12-01T10:15:08", "name": "[libcamera-devel,v2,2/2] pipeline: raspberrypi: Choose bit depth and packing according to raw stream", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "6a7744aca7c96f01b56efdcb34d9955e7db60e08", "submitter": { "id": 42, "url": "https://patchwork.libcamera.org/api/people/42/?format=api", "name": "David Plowman", "email": "david.plowman@raspberrypi.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/14955/mbox/", "series": [ { "id": 2792, "url": "https://patchwork.libcamera.org/api/series/2792/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2792", "date": "2021-12-01T10:15:06", "name": "Buffer format and allocation fixes", "version": 2, "mbox": "https://patchwork.libcamera.org/series/2792/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/14955/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/14955/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 9F2E5C3251\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 1 Dec 2021 10:15:23 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0B92D60729;\n\tWed, 1 Dec 2021 11:15:22 +0100 (CET)", "from mail-wr1-x435.google.com (mail-wr1-x435.google.com\n\t[IPv6:2a00:1450:4864:20::435])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2EE1B6011D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 1 Dec 2021 11:15:20 +0100 (CET)", "by mail-wr1-x435.google.com with SMTP id v11so51010251wrw.10\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 01 Dec 2021 02:15:20 -0800 (PST)", "from pi4-davidp.pitowers.org\n\t([2a00:1098:3142:14:e4a2:3070:eea4:e434])\n\tby smtp.gmail.com with ESMTPSA id\n\tz18sm18815535wrq.11.2021.12.01.02.15.19\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 01 Dec 2021 02:15:19 -0800 (PST)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"c0gIV4fM\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=5zCiFuQtuj7Sh6qS4ID/TIMwe//x9gGRyINlvmZvs2Y=;\n\tb=c0gIV4fMmU9wWytZDYUkkmm0w4pwOEYoqRJsys89wUE7Y2sub8jRCqu6Qjrt826FRD\n\tWaRTnqgrjHQqMaOmZav+xqa/CVL/JRliidig3LtwjGEQMvUAuW0X1/Ls7C0pn5CZlpOV\n\tSzyKwnaYWtRceTXIeGYX8hAoqQSnEdKItohO7lmJCB0u67waeSqdC+N9IvhWSPs/j7wp\n\tspt1CONNk6OkYW4BjVpkOTtHrDAqBFL95eZ7IdeldHtE3w6xFsbLy8lT2Mj8Xz7UzI4d\n\tBv489FrjkStbwAmktXdXDRr5mYqlBusgTXKq2/nrAkfUeMYA8nb0VEeXXSlmI0pakUe0\n\t0Myg==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=5zCiFuQtuj7Sh6qS4ID/TIMwe//x9gGRyINlvmZvs2Y=;\n\tb=pwB3rF3asshpYjxx9UTSspKNVcQ+53VqtUY6/cKO04MHfF9Di+9/U0TeJYE2iOkF1i\n\tr/HeQ6ASXgwKqmG0wPq9EUsrUwmOsuRUCJhkRKY+jf1GvVm1WlpcOKKZdcdgHzPp6cnS\n\tvJS9GknIeM01RJSUv6q/y+Gu2dt7+/l8dY6fJy0krMyZuMSz/yEIOlVxkl/NM6J9tX7J\n\td0ljZOaRcKtXVvuWs15nm0Eufgdl+gPlQTR+TMblRR0DatKFDrQRi73nSrp6/q0zr/C7\n\t29t19k+qna0mJD2WKi97q8/THBBAsViGk8PniIDT8+BzDdIhdh6GQN82nfcGaFLE/git\n\tJ89A==", "X-Gm-Message-State": "AOAM531TMj2HymlmZOEEt4D7U33Rm1lp/2NbceSUdPr2YSw1EzOmTeEC\n\tTycZ2KV1L99s/O8Ef+zo3I3o1viIhkVF5Q0I", "X-Google-Smtp-Source": "ABdhPJwB9Kqp9h8H2bMwtuSQM+3zVZm561EBtflJ0nOlxA9MbQXH+EiReH2gH8U7d3edGffHlPqz3g==", "X-Received": "by 2002:a5d:52c3:: with SMTP id r3mr5618937wrv.115.1638353719701;\n\tWed, 01 Dec 2021 02:15:19 -0800 (PST)", "From": "David Plowman <david.plowman@raspberrypi.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 1 Dec 2021 10:15:08 +0000", "Message-Id": "<20211201101508.10619-3-david.plowman@raspberrypi.com>", "X-Mailer": "git-send-email 2.30.2", "In-Reply-To": "<20211201101508.10619-1-david.plowman@raspberrypi.com>", "References": "<20211201101508.10619-1-david.plowman@raspberrypi.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 2/2] pipeline: raspberrypi: Choose bit\n\tdepth and packing according to raw stream", "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": "When a raw stream is specified, the bit depth and packing requested\nshould influence our choice of camera mode to match (if possible).\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n---\n .../pipeline/raspberrypi/raspberrypi.cpp | 37 ++++++++++---------\n 1 file changed, 20 insertions(+), 17 deletions(-)", "diff": "diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 045725dd..c01e0769 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -49,6 +49,8 @@ LOG_DEFINE_CATEGORY(RPI)\n \n namespace {\n \n+constexpr unsigned int defaultRawBitDepth = 12;\n+\n /* Map of mbus codes to supported sizes reported by the sensor. */\n using SensorFormats = std::map<unsigned int, std::vector<Size>>;\n \n@@ -125,15 +127,13 @@ double scoreFormat(double desired, double actual)\n \treturn score;\n }\n \n-V4L2SubdeviceFormat findBestFormat(const SensorFormats &formatsMap, const Size &req)\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 \n-#define PENALTY_AR\t\t1500.0\n-#define PENALTY_8BIT\t\t2000.0\n-#define PENALTY_10BIT\t\t1000.0\n-#define PENALTY_12BIT\t\t 0.0\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@@ -149,15 +149,10 @@ V4L2SubdeviceFormat findBestFormat(const SensorFormats &formatsMap, const Size &\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 += PENALTY_AR * scoreFormat(reqAr, fmtAr);\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\tif (info.bitsPerPixel == 12)\n-\t\t\t\tscore += PENALTY_12BIT;\n-\t\t\telse if (info.bitsPerPixel == 10)\n-\t\t\t\tscore += PENALTY_10BIT;\n-\t\t\telse if (info.bitsPerPixel == 8)\n-\t\t\t\tscore += PENALTY_8BIT;\n+\t\t\tscore += abs(info.bitsPerPixel - bitDepth) * penaltyBitDepth;\n \n \t\t\tif (score <= bestScore) {\n \t\t\t\tbestScore = score;\n@@ -397,9 +392,14 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \t\t\t * Calculate the best sensor mode we can use based on\n \t\t\t * the user request.\n \t\t\t */\n-\t\t\tV4L2SubdeviceFormat sensorFormat = findBestFormat(data_->sensorFormats_, cfg.size);\n+\t\t\tconst PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat);\n+\t\t\tunsigned int bitDepth = info.isValid() ? info.bitsPerPixel : defaultRawBitDepth;\n+\t\t\tV4L2SubdeviceFormat sensorFormat = findBestFormat(data_->sensorFormats_, cfg.size, bitDepth);\n+\t\t\tBayerFormat::Packing packing = BayerFormat::Packing::CSI2;\n+\t\t\tif (info.isValid() && !info.packed)\n+\t\t\t\tpacking = BayerFormat::Packing::None;\n \t\t\tV4L2DeviceFormat unicamFormat = toV4L2DeviceFormat(sensorFormat,\n-\t\t\t\t\t\t\t\t\t BayerFormat::Packing::CSI2);\n+\t\t\t\t\t\t\t\t\t packing);\n \t\t\tint ret = data_->unicam_[Unicam::Image].dev()->tryFormat(&unicamFormat);\n \t\t\tif (ret)\n \t\t\t\treturn Invalid;\n@@ -533,7 +533,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n \t\tswitch (role) {\n \t\tcase StreamRole::Raw:\n \t\t\tsize = data->sensor_->resolution();\n-\t\t\tsensorFormat = findBestFormat(data->sensorFormats_, size);\n+\t\t\tsensorFormat = findBestFormat(data->sensorFormats_, 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@@ -622,6 +622,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n \tSize maxSize, sensorSize;\n \tunsigned int maxIndex = 0;\n \tbool rawStream = false;\n+\tunsigned int bitDepth = defaultRawBitDepth;\n \n \t/*\n \t * Look for the RAW stream (if given) size as well as the largest\n@@ -638,7 +639,9 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n \t\t\tsensorSize = cfg.size;\n \t\t\trawStream = true;\n \t\t\t/* Check if the user has explicitly set an unpacked format. */\n-\t\t\tpacking = BayerFormat::fromPixelFormat(cfg.pixelFormat).packing;\n+\t\t\tBayerFormat bayerFormat = BayerFormat::fromPixelFormat(cfg.pixelFormat);\n+\t\t\tpacking = bayerFormat.packing;\n+\t\t\tbitDepth = bayerFormat.bitDepth;\n \t\t} else {\n \t\t\tif (cfg.size > maxSize) {\n \t\t\t\tmaxSize = config->at(i).size;\n@@ -664,7 +667,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n \t}\n \n \t/* First calculate the best sensor mode we can use based on the user request. */\n-\tV4L2SubdeviceFormat sensorFormat = findBestFormat(data->sensorFormats_, rawStream ? sensorSize : maxSize);\n+\tV4L2SubdeviceFormat sensorFormat = findBestFormat(data->sensorFormats_, rawStream ? sensorSize : maxSize, bitDepth);\n \tret = data->sensor_->setFormat(&sensorFormat);\n \tif (ret)\n \t\treturn ret;\n", "prefixes": [ "libcamera-devel", "v2", "2/2" ] }