Patch Detail
Show a patch.
GET /api/1.1/patches/14255/?format=api
{ "id": 14255, "url": "https://patchwork.libcamera.org/api/1.1/patches/14255/?format=api", "web_url": "https://patchwork.libcamera.org/patch/14255/", "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": "<20211022115537.2964533-4-naush@raspberrypi.com>", "date": "2021-10-22T11:55:34", "name": "[libcamera-devel,3/6] pipeline: raspberrypi: Return a PixelFormat from findBestMode()", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "74c00e31fc0dcd45e0173d0101f81178897da09f", "submitter": { "id": 34, "url": "https://patchwork.libcamera.org/api/1.1/people/34/?format=api", "name": "Naushir Patuck", "email": "naush@raspberrypi.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/14255/mbox/", "series": [ { "id": 2649, "url": "https://patchwork.libcamera.org/api/1.1/series/2649/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2649", "date": "2021-10-22T11:55:31", "name": "Raspberry Pi: Conversion to media controller", "version": 1, "mbox": "https://patchwork.libcamera.org/series/2649/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/14255/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/14255/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 EF323BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 22 Oct 2021 11:55:48 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AE88068F68;\n\tFri, 22 Oct 2021 13:55:48 +0200 (CEST)", "from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com\n\t[IPv6:2a00:1450:4864:20::42e])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id ACFBE68F5E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 22 Oct 2021 13:55:44 +0200 (CEST)", "by mail-wr1-x42e.google.com with SMTP id e12so3577351wra.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 22 Oct 2021 04:55:44 -0700 (PDT)", "from naush-laptop.pitowers.org\n\t([2a00:1098:3142:14:f00d:ddf0:61b0:a4cd])\n\tby smtp.gmail.com with ESMTPSA id\n\tl5sm7853364wru.24.2021.10.22.04.55.42\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 22 Oct 2021 04:55:43 -0700 (PDT)" ], "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=\"sK2flQGo\"; 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=ZtQR4caqAxW5pY0otRC3Bfy56XbPIGt7rkbYnd54QuY=;\n\tb=sK2flQGokXoH/h69QXg7khQWxelLq+evFy/zNGXLDZk0jXtxanq630O9d/S3Dp3gNx\n\tJOg6AaWBNmtGP/DFroWsokL5lTyRUsgz5UGeM/Wtn5gNtV/Iu/t2w3OCn2Tsp6t4U6Ei\n\tuV0+CVSEROl6lyhzJRDYji8ZUsYNwhR5kif1E6iHn/kACcLqMu3JhTOOd4GwVz1BXUpq\n\tIyp9Cwobkr6AIbi2CZIds1UKNPT2x+/eOLbs4j7/EUF6KbfAAEXMx/bZTsqWyHlqNIqu\n\taASPgnRKRIW4Z+HFI5scmg7o6sdj/+jM/AkT891++5oxp4/wgTZ7Q8i8OlopoxPNCptD\n\tOIWw==", "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=ZtQR4caqAxW5pY0otRC3Bfy56XbPIGt7rkbYnd54QuY=;\n\tb=aaS9Vrd3oLkCOIADFy0XtcVIiWnIuQmPvWx/YBCQpHo4VXDryFNfCUARCBhMVRvIW/\n\txl2M8Nda9YT/P1Un5g3j2T3FstQr2IAb3irXObF3h30X4g+Dk39IZwg78VDIxItXvG1b\n\t5urY4GFqnIwV0Y5DgB8H95vt4/AgArsBCXwBQCl19u6SZZwq77x1kV4UIDhPg8praBNh\n\tl8lYZf4iAok584xxi832CNTr0e6covaECeoi8miCuU3KQ9l1Ycz8ewPXDN9Yq10TUcXP\n\tLRy4gWt0iVyF10PgP5zfFOD6gslrcFoG66XwQ8CQGkktVwc6OpBMymGI0VTr5Hl7u9bZ\n\tqPaQ==", "X-Gm-Message-State": "AOAM5322WJcGl1IpmXKer5LicIgJNTYNj3jayB/+0HWl6LTaBQvXiGCD\n\tegMJRmdpr5rLpFJueWqdqvQbwTO/lm0DFSeC", "X-Google-Smtp-Source": "ABdhPJxcPJ2GK5LGE3g41fdjDWz3gZ7ecMnIRUqqh2rmsGTvy35gUTQUVMZSkp5MQ4vp12b9uD9kvw==", "X-Received": "by 2002:adf:d1eb:: with SMTP id\n\tg11mr14926382wrd.16.1634903744017; \n\tFri, 22 Oct 2021 04:55:44 -0700 (PDT)", "From": "Naushir Patuck <naush@raspberrypi.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Fri, 22 Oct 2021 12:55:34 +0100", "Message-Id": "<20211022115537.2964533-4-naush@raspberrypi.com>", "X-Mailer": "git-send-email 2.25.1", "In-Reply-To": "<20211022115537.2964533-1-naush@raspberrypi.com>", "References": "<20211022115537.2964533-1-naush@raspberrypi.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 3/6] pipeline: raspberrypi: Return a\n\tPixelFormat from findBestMode()", "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": "It is more convenient to return a PixelFormat from findBestMode(), as the\nconversions from PixelFormat to V4L2SubdeviceFormat and V4L2DeviceFormat are\nsimpler.\n\nAdd some internal helpers to perform these conversions.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\n---\n .../pipeline/raspberrypi/raspberrypi.cpp | 73 +++++++++++++------\n 1 file changed, 52 insertions(+), 21 deletions(-)", "diff": "diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 730f1575095c..0f13127a7748 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -50,6 +50,7 @@ namespace {\n \n /* Map of mbus codes to supported sizes reported by the sensor. */\n using SensorFormats = std::map<unsigned int, std::vector<Size>>;\n+using SensorMode = std::pair<PixelFormat, Size>;\n \n SensorFormats populateSensorFormats(std::unique_ptr<CameraSensor> &sensor)\n {\n@@ -61,6 +62,34 @@ SensorFormats populateSensorFormats(std::unique_ptr<CameraSensor> &sensor)\n \treturn formats;\n }\n \n+inline V4L2DeviceFormat toV4L2DeviceFormat(SensorMode &mode)\n+{\n+\tV4L2DeviceFormat deviceFormat;\n+\n+\tdeviceFormat.fourcc = V4L2PixelFormat::fromPixelFormat(mode.first);\n+\tdeviceFormat.size = mode.second;\n+\treturn deviceFormat;\n+}\n+\n+inline V4L2DeviceFormat toV4L2DeviceFormat(V4L2SubdeviceFormat &format)\n+{\n+\tV4L2DeviceFormat deviceFormat;\n+\n+\tdeviceFormat.fourcc = BayerFormat::fromMbusCode(format.mbus_code).toV4L2PixelFormat();\n+\tdeviceFormat.size = format.size;\n+\treturn deviceFormat;\n+}\n+\n+inline V4L2SubdeviceFormat toV4L2SubdeviceFormat(SensorMode &mode)\n+{\n+\tV4L2SubdeviceFormat subdeviceFormat;\n+\tV4L2PixelFormat fourcc = V4L2PixelFormat::fromPixelFormat(mode.first);\n+\n+\tsubdeviceFormat.mbus_code = BayerFormat::fromV4L2PixelFormat(fourcc).toMbusCode();\n+\tsubdeviceFormat.size = mode.second;\n+\treturn subdeviceFormat;\n+}\n+\n bool isRaw(PixelFormat &pixFmt)\n {\n \t/*\n@@ -87,10 +116,10 @@ double scoreFormat(double desired, double actual)\n \treturn score;\n }\n \n-V4L2DeviceFormat findBestMode(const SensorFormats &formatsMap, const Size &req)\n+SensorMode findBestMode(const SensorFormats &formatsMap, const Size &req)\n {\n \tdouble bestScore = std::numeric_limits<double>::max(), score;\n-\tV4L2DeviceFormat bestMode;\n+\tSensorMode bestMode;\n \n #define PENALTY_AR\t\t1500.0\n #define PENALTY_8BIT\t\t2000.0\n@@ -101,8 +130,8 @@ V4L2DeviceFormat findBestMode(const SensorFormats &formatsMap, const Size &req)\n \t/* Calculate the closest/best mode from the user requested size. */\n \tfor (const auto &iter : formatsMap) {\n \t\tconst unsigned int mbus_code = iter.first;\n-\t\tconst V4L2PixelFormat v4l2Format = BayerFormat::fromMbusCode(mbus_code).toV4L2PixelFormat();\n-\t\tconst PixelFormatInfo &info = PixelFormatInfo::info(v4l2Format);\n+\t\tconst PixelFormat format = BayerFormat::fromMbusCode(mbus_code).toPixelFormat();\n+\t\tconst PixelFormatInfo &info = PixelFormatInfo::info(format);\n \n \t\tfor (const Size &sz : iter.second) {\n \t\t\tdouble reqAr = static_cast<double>(req.width) / req.height;\n@@ -126,12 +155,12 @@ V4L2DeviceFormat findBestMode(const SensorFormats &formatsMap, const Size &req)\n \n \t\t\tif (score <= bestScore) {\n \t\t\t\tbestScore = score;\n-\t\t\t\tbestMode.fourcc = v4l2Format;\n-\t\t\t\tbestMode.size = sz;\n+\t\t\t\tbestMode.first = format;\n+\t\t\t\tbestMode.second = sz;\n \t\t\t}\n \n \t\t\tLOG(RPI, Info) << \"Mode: \" << sz.width << \"x\" << sz.height\n-\t\t\t\t << \" fmt \" << v4l2Format.toString()\n+\t\t\t\t << \" fmt \" << format.toString()\n \t\t\t\t << \" Score: \" << score\n \t\t\t\t << \" (best \" << bestScore << \")\";\n \t\t}\n@@ -364,8 +393,9 @@ 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\tV4L2DeviceFormat sensorFormat = findBestMode(data_->sensorFormats_, cfg.size);\n-\t\t\tint ret = data_->unicam_[Unicam::Image].dev()->tryFormat(&sensorFormat);\n+\t\t\tSensorMode sensorMode = findBestMode(data_->sensorFormats_, cfg.size);\n+\t\t\tV4L2DeviceFormat unicamFormat = toV4L2DeviceFormat(sensorMode);\n+\t\t\tint ret = data_->unicam_[Unicam::Image].dev()->tryFormat(&unicamFormat);\n \t\t\tif (ret)\n \t\t\t\treturn Invalid;\n \n@@ -377,7 +407,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \t\t\t * fetch the \"native\" (i.e. untransformed) Bayer order,\n \t\t\t * because the sensor may currently be flipped!\n \t\t\t */\n-\t\t\tV4L2PixelFormat fourcc = sensorFormat.fourcc;\n+\t\t\tV4L2PixelFormat fourcc = unicamFormat.fourcc;\n \t\t\tif (data_->flipsAlterBayerOrder_) {\n \t\t\t\tBayerFormat bayer = BayerFormat::fromV4L2PixelFormat(fourcc);\n \t\t\t\tbayer.order = data_->nativeBayerOrder_;\n@@ -386,15 +416,15 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \t\t\t}\n \n \t\t\tPixelFormat sensorPixFormat = fourcc.toPixelFormat();\n-\t\t\tif (cfg.size != sensorFormat.size ||\n+\t\t\tif (cfg.size != unicamFormat.size ||\n \t\t\t cfg.pixelFormat != sensorPixFormat) {\n-\t\t\t\tcfg.size = sensorFormat.size;\n+\t\t\t\tcfg.size = unicamFormat.size;\n \t\t\t\tcfg.pixelFormat = sensorPixFormat;\n \t\t\t\tstatus = Adjusted;\n \t\t\t}\n \n-\t\t\tcfg.stride = sensorFormat.planes[0].bpl;\n-\t\t\tcfg.frameSize = sensorFormat.planes[0].size;\n+\t\t\tcfg.stride = unicamFormat.planes[0].bpl;\n+\t\t\tcfg.frameSize = unicamFormat.planes[0].size;\n \n \t\t\trawCount++;\n \t\t} else {\n@@ -483,7 +513,8 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n {\n \tRPiCameraData *data = cameraData(camera);\n \tCameraConfiguration *config = new RPiCameraConfiguration(data);\n-\tV4L2DeviceFormat sensorFormat;\n+\tV4L2DeviceFormat unicamFormat;\n+\tSensorMode sensorMode;\n \tunsigned int bufferCount;\n \tPixelFormat pixelFormat;\n \tV4L2VideoDevice::Formats fmts;\n@@ -498,8 +529,9 @@ 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 = findBestMode(data->sensorFormats_, size);\n-\t\t\tpixelFormat = sensorFormat.fourcc.toPixelFormat();\n+\t\t\tsensorMode = findBestMode(data->sensorFormats_, size);\n+\t\t\tunicamFormat = toV4L2DeviceFormat(sensorMode);\n+\t\t\tpixelFormat = sensorMode.first;\n \t\t\tASSERT(pixelFormat.isValid());\n \t\t\tbufferCount = 2;\n \t\t\trawCount++;\n@@ -609,10 +641,9 @@ 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-\tV4L2DeviceFormat unicamFormat = findBestMode(data->sensorFormats_, rawStream ? sensorSize : maxSize);\n-\n-\tunsigned int mbus_code = BayerFormat::fromV4L2PixelFormat(unicamFormat.fourcc).toMbusCode();\n-\tV4L2SubdeviceFormat sensorFormat { .mbus_code = mbus_code, .size = unicamFormat.size };\n+\tSensorMode sensorMode = findBestMode(data->sensorFormats_, rawStream ? sensorSize : maxSize);\n+\tV4L2SubdeviceFormat sensorFormat = toV4L2SubdeviceFormat(sensorMode);\n+\tV4L2DeviceFormat unicamFormat = toV4L2DeviceFormat(sensorMode);\n \n \tret = data->sensor_->setFormat(&sensorFormat);\n \tif (ret)\n", "prefixes": [ "libcamera-devel", "3/6" ] }