Patch Detail
Show a patch.
GET /api/patches/3969/?format=api
{ "id": 3969, "url": "https://patchwork.libcamera.org/api/patches/3969/?format=api", "web_url": "https://patchwork.libcamera.org/patch/3969/", "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": "<20200606150436.1851700-8-niklas.soderlund@ragnatech.se>", "date": "2020-06-06T15:04:33", "name": "[libcamera-devel,v2,07/10] libcamera: ipu3: cio2: Add function to generate configuration", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "5d3537f1bee94ead4096f2b305575355bdae8494", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/3969/mbox/", "series": [ { "id": 964, "url": "https://patchwork.libcamera.org/api/series/964/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=964", "date": "2020-06-06T15:04:26", "name": "libcamera: ipu3: Allow zero-copy RAW stream", "version": 2, "mbox": "https://patchwork.libcamera.org/series/964/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/3969/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/3969/checks/", "tags": {}, "headers": { "Return-Path": "<niklas.soderlund@ragnatech.se>", "Received": [ "from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net\n\t[195.74.38.228])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1F7F463C29\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 6 Jun 2020 17:04:58 +0200 (CEST)", "from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de\n\t[79.202.46.202]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid 1448c3c8-a807-11ea-933e-005056917a89;\n\tSat, 06 Jun 2020 17:04:54 +0200 (CEST)" ], "X-Halon-ID": "1448c3c8-a807-11ea-933e-005056917a89", "Authorized-sender": "niklas@soderlund.pp.se", "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sat, 6 Jun 2020 17:04:33 +0200", "Message-Id": "<20200606150436.1851700-8-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.26.2", "In-Reply-To": "<20200606150436.1851700-1-niklas.soderlund@ragnatech.se>", "References": "<20200606150436.1851700-1-niklas.soderlund@ragnatech.se>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 07/10] libcamera: ipu3: cio2: Add\n\tfunction to generate configuration", "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>", "X-List-Received-Date": "Sat, 06 Jun 2020 15:04:58 -0000" }, "content": "Collect the code used to generate configurations for the CIO2 block in\nthe CIO2Device class. This allows for both simplifying the code while\nextending its functionality. With this change applications can now\nfunction with pixelformats other then SBGGR10 which previously was hard\ncoded.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n* Changes since v1\n- Use anonymous namespace instead of static for sensorMbusToPixel map.\n- Handle case where the requested mbus code is not supported by the sensor.\n- Update commit message.\n---\n src/libcamera/pipeline/ipu3/cio2.cpp | 55 ++++++++++++++++++++++++++\n src/libcamera/pipeline/ipu3/cio2.h | 8 +++-\n src/libcamera/pipeline/ipu3/ipu3.cpp | 58 +++++++---------------------\n 3 files changed, 75 insertions(+), 46 deletions(-)", "diff": "diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp\nindex 1a9f185bc4e161c5..0d961ae8f5a0682b 100644\n--- a/src/libcamera/pipeline/ipu3/cio2.cpp\n+++ b/src/libcamera/pipeline/ipu3/cio2.cpp\n@@ -9,6 +9,8 @@\n \n #include <linux/media-bus-format.h>\n \n+#include <libcamera/stream.h>\n+\n #include \"libcamera/internal/camera_sensor.h\"\n #include \"libcamera/internal/media_device.h\"\n #include \"libcamera/internal/v4l2_subdevice.h\"\n@@ -18,6 +20,17 @@ namespace libcamera {\n \n LOG_DECLARE_CATEGORY(IPU3)\n \n+namespace {\n+\n+const std::map<uint32_t, PixelFormat> sensorMbusToPixel = {\n+\t{ MEDIA_BUS_FMT_SBGGR10_1X10, PixelFormat(DRM_FORMAT_SBGGR10, IPU3_FORMAT_MOD_PACKED) },\n+\t{ MEDIA_BUS_FMT_SGBRG10_1X10, PixelFormat(DRM_FORMAT_SGBRG10, IPU3_FORMAT_MOD_PACKED) },\n+\t{ MEDIA_BUS_FMT_SGRBG10_1X10, PixelFormat(DRM_FORMAT_SGRBG10, IPU3_FORMAT_MOD_PACKED) },\n+\t{ MEDIA_BUS_FMT_SRGGB10_1X10, PixelFormat(DRM_FORMAT_SRGGB10, IPU3_FORMAT_MOD_PACKED) },\n+};\n+\n+} /* namespace */\n+\n CIO2Device::CIO2Device()\n \t: output_(nullptr), csi2_(nullptr), sensor_(nullptr)\n {\n@@ -172,6 +185,48 @@ int CIO2Device::configure(const Size &size, V4L2DeviceFormat *outputFormat)\n \treturn 0;\n }\n \n+StreamConfiguration\n+CIO2Device::generateConfiguration(const PixelFormat desiredPixelFormat,\n+\t\t\t\t const Size desiredSize) const\n+{\n+\tStreamConfiguration cfg;\n+\n+\t/* If no desired pixelformat allow all the supported ones. */\n+\tstd::vector<unsigned int> mbusCodes = {\n+\t\tMEDIA_BUS_FMT_SBGGR10_1X10,\n+\t\tMEDIA_BUS_FMT_SGBRG10_1X10,\n+\t\tMEDIA_BUS_FMT_SGRBG10_1X10,\n+\t\tMEDIA_BUS_FMT_SRGGB10_1X10\n+\t};\n+\tif (desiredPixelFormat.isValid()) {\n+\t\tfor (const auto &iter : sensorMbusToPixel) {\n+\t\t\tif (iter.second == desiredPixelFormat) {\n+\t\t\t\tmbusCodes = { iter.first };\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\t/* If no desired size use the sensor resolution. */\n+\tSize size = sensor_->resolution();\n+\tif (desiredSize.width && desiredSize.height)\n+\t\tsize = desiredSize;\n+\n+\t/* Query the sensor static information for closest match. */\n+\tV4L2SubdeviceFormat sensorFormat = sensor_->getFormat(mbusCodes, size);\n+\n+\tif (!sensorFormat.mbus_code) {\n+\t\tLOG(IPU3, Error) << \"Sensor does not support mbus code\";\n+\t\treturn {};\n+\t}\n+\n+\tcfg.size = sensorFormat.size;\n+\tcfg.pixelFormat = sensorMbusToPixel.at(sensorFormat.mbus_code);\n+\tcfg.bufferCount = CIO2_BUFFER_COUNT;\n+\n+\treturn cfg;\n+}\n+\n /**\n * \\brief Allocate frame buffers for the CIO2 output\n *\ndiff --git a/src/libcamera/pipeline/ipu3/cio2.h b/src/libcamera/pipeline/ipu3/cio2.h\nindex b2c4f89d682d6cfb..b7eb69a4e104f400 100644\n--- a/src/libcamera/pipeline/ipu3/cio2.h\n+++ b/src/libcamera/pipeline/ipu3/cio2.h\n@@ -11,6 +11,9 @@\n #include <queue>\n #include <vector>\n \n+#include <libcamera/geometry.h>\n+#include <libcamera/pixel_format.h>\n+\n namespace libcamera {\n \n class CameraSensor;\n@@ -19,7 +22,7 @@ class MediaDevice;\n class V4L2DeviceFormat;\n class V4L2Subdevice;\n class V4L2VideoDevice;\n-struct Size;\n+struct StreamConfiguration;\n \n class CIO2Device\n {\n@@ -32,6 +35,9 @@ public:\n \tint init(const MediaDevice *media, unsigned int index);\n \tint configure(const Size &size, V4L2DeviceFormat *outputFormat);\n \n+\tStreamConfiguration generateConfiguration(const PixelFormat desiredPixelFormat = {},\n+\t\t\t\t\t\t const Size desiredSize = {}) const;\n+\n \tint allocateBuffers();\n \tvoid freeBuffers();\n \ndiff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex 257f5441c9ad7f5d..85d4e64396e77222 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -35,13 +35,6 @@ LOG_DEFINE_CATEGORY(IPU3)\n \n class IPU3CameraData;\n \n-static const std::map<uint32_t, PixelFormat> sensorMbusToPixel = {\n-\t{ MEDIA_BUS_FMT_SBGGR10_1X10, PixelFormat(DRM_FORMAT_SBGGR10, IPU3_FORMAT_MOD_PACKED) },\n-\t{ MEDIA_BUS_FMT_SGBRG10_1X10, PixelFormat(DRM_FORMAT_SGBRG10, IPU3_FORMAT_MOD_PACKED) },\n-\t{ MEDIA_BUS_FMT_SGRBG10_1X10, PixelFormat(DRM_FORMAT_SGRBG10, IPU3_FORMAT_MOD_PACKED) },\n-\t{ MEDIA_BUS_FMT_SRGGB10_1X10, PixelFormat(DRM_FORMAT_SRGGB10, IPU3_FORMAT_MOD_PACKED) },\n-};\n-\n class ImgUDevice\n {\n public:\n@@ -146,7 +139,7 @@ public:\n \n \tStatus validate() override;\n \n-\tconst V4L2SubdeviceFormat &sensorFormat() { return sensorFormat_; }\n+\tconst StreamConfiguration &sensorFormat() const { return sensorFormat_; };\n \tconst std::vector<const IPU3Stream *> &streams() { return streams_; }\n \n private:\n@@ -164,7 +157,7 @@ private:\n \tstd::shared_ptr<Camera> camera_;\n \tconst IPU3CameraData *data_;\n \n-\tV4L2SubdeviceFormat sensorFormat_;\n+\tStreamConfiguration sensorFormat_;\n \tstd::vector<const IPU3Stream *> streams_;\n };\n \n@@ -304,7 +297,6 @@ void IPU3CameraConfiguration::adjustStream(StreamConfiguration &cfg, bool scale)\n \n CameraConfiguration::Status IPU3CameraConfiguration::validate()\n {\n-\tconst CameraSensor *sensor = data_->cio2_.sensor_;\n \tStatus status = Valid;\n \n \tif (config_.empty())\n@@ -316,31 +308,23 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate()\n \t\tstatus = Adjusted;\n \t}\n \n-\t/*\n-\t * Select the sensor format by collecting the maximum width and height\n-\t * and picking the closest larger match, as the IPU3 can downscale\n-\t * only. If no resolution is requested for any stream, or if no sensor\n-\t * resolution is large enough, pick the largest one.\n-\t */\n+\t/* Find largets size and raw format (if any) in the configuration. */\n \tSize size = {};\n-\n+\tPixelFormat pixelFormat = {};\n \tfor (const StreamConfiguration &cfg : config_) {\n \t\tif (cfg.size.width > size.width)\n \t\t\tsize.width = cfg.size.width;\n \t\tif (cfg.size.height > size.height)\n \t\t\tsize.height = cfg.size.height;\n+\n+\t\tif (cfg.pixelFormat.modifier() == IPU3_FORMAT_MOD_PACKED)\n+\t\t\tpixelFormat = cfg.pixelFormat;\n \t}\n \n-\tif (!size.width || !size.height)\n-\t\tsize = sensor->resolution();\n-\n-\tsensorFormat_ = sensor->getFormat({ MEDIA_BUS_FMT_SBGGR10_1X10,\n-\t\t\t\t\t MEDIA_BUS_FMT_SGBRG10_1X10,\n-\t\t\t\t\t MEDIA_BUS_FMT_SGRBG10_1X10,\n-\t\t\t\t\t MEDIA_BUS_FMT_SRGGB10_1X10 },\n-\t\t\t\t\t size);\n-\tif (!sensorFormat_.size.width || !sensorFormat_.size.height)\n-\t\tsensorFormat_.size = sensor->resolution();\n+\t/* Generate raw configuration from CIO2. */\n+\tsensorFormat_ = data_->cio2_.generateConfiguration(pixelFormat, size);\n+\tif (!sensorFormat_.pixelFormat.isValid())\n+\t\treturn Invalid;\n \n \t/* Assign streams to each configuration entry. */\n \tassignStreams();\n@@ -352,13 +336,7 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate()\n \t\tconst IPU3Stream *stream = streams_[i];\n \n \t\tif (stream->raw_) {\n-\t\t\tconst auto &itFormat =\n-\t\t\t\tsensorMbusToPixel.find(sensorFormat_.mbus_code);\n-\t\t\tif (itFormat == sensorMbusToPixel.end())\n-\t\t\t\treturn Invalid;\n-\n-\t\t\tcfg.pixelFormat = itFormat->second;\n-\t\t\tcfg.size = sensorFormat_.size;\n+\t\t\tcfg = sensorFormat_;\n \t\t} else {\n \t\t\tbool scale = stream == &data_->vfStream_;\n \t\t\tadjustStream(config_[i], scale);\n@@ -442,17 +420,7 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera,\n \t\t\t}\n \n \t\t\tstream = &data->rawStream_;\n-\n-\t\t\tcfg.size = data->cio2_.sensor_->resolution();\n-\n-\t\t\tV4L2SubdeviceFormat sensorFormat =\n-\t\t\t\tdata->cio2_.sensor_->getFormat({ MEDIA_BUS_FMT_SBGGR10_1X10,\n-\t\t\t\t\t\t\t\t MEDIA_BUS_FMT_SGBRG10_1X10,\n-\t\t\t\t\t\t\t\t MEDIA_BUS_FMT_SGRBG10_1X10,\n-\t\t\t\t\t\t\t\t MEDIA_BUS_FMT_SRGGB10_1X10 },\n-\t\t\t\t\t\t\t cfg.size);\n-\t\t\tcfg.pixelFormat =\n-\t\t\t\tsensorMbusToPixel.at(sensorFormat.mbus_code);\n+\t\t\tcfg = data->cio2_.generateConfiguration();\n \t\t\tbreak;\n \t\t}\n \n", "prefixes": [ "libcamera-devel", "v2", "07/10" ] }