From patchwork Thu Mar 14 15:51:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 736 Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B0A20600CB for ; Thu, 14 Mar 2019 16:50:37 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 48F3E100005; Thu, 14 Mar 2019 15:50:37 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Thu, 14 Mar 2019 16:51:03 +0100 Message-Id: <20190314155106.30106-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190314155106.30106-1-jacopo@jmondi.org> References: <20190314155106.30106-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/4] libcamera: formats: Add toString() methods X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Mar 2019 15:50:37 -0000 Add toString() helpers to pretty print out a V4L2Device or V4L2Subdevice format. Signed-off-by: Jacopo Mondi --- v2->v3: - remove planes and mbus code hex code length - TODO: clarify the format formatting --- src/libcamera/include/v4l2_device.h | 2 ++ src/libcamera/include/v4l2_subdevice.h | 2 ++ src/libcamera/v4l2_device.cpp | 18 ++++++++++++++++++ src/libcamera/v4l2_subdevice.cpp | 18 ++++++++++++++++++ 4 files changed, 40 insertions(+) -- 2.21.0 diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h index 5c379fac66dc..258deee8d461 100644 --- a/src/libcamera/include/v4l2_device.h +++ b/src/libcamera/include/v4l2_device.h @@ -100,6 +100,8 @@ public: uint32_t bpl; } planes[3]; unsigned int planesCount; + + const std::string toString() const; }; class V4L2Device : protected Loggable diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h index 1cc0fab73103..700e66bcddac 100644 --- a/src/libcamera/include/v4l2_subdevice.h +++ b/src/libcamera/include/v4l2_subdevice.h @@ -21,6 +21,8 @@ struct V4L2SubdeviceFormat { uint32_t mbus_code; uint32_t width; uint32_t height; + + const std::string toString() const; }; class V4L2Subdevice : protected Loggable diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index a88a5f5ff036..127140b24314 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -6,6 +6,8 @@ */ #include +#include +#include #include #include #include @@ -223,6 +225,22 @@ LOG_DEFINE_CATEGORY(V4L2) * \brief The number of valid data planes */ +/** + * \brief Assemble and return a string describing the format + * + * \return A string describing the V4L2DeviceFormat + */ +const std::string V4L2DeviceFormat::toString() const +{ + std::stringstream ss; + + ss.fill(0); + ss << width << "x" << height << "- 0x" << std::hex + << std::setw(8) << fourcc; + + return ss.str(); +} + /** * \class V4L2Device * \brief V4L2Device object and API diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 5f58904bf9e6..eb60fe42bb4e 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -6,6 +6,8 @@ */ #include +#include +#include #include #include #include @@ -69,6 +71,22 @@ LOG_DEFINE_CATEGORY(V4L2Subdev) * \brief The image height in pixels */ +/** + * \brief Assemble and return a string describing the format + * + * \return A string describing the V4L2SubdeviceFormat + */ +const std::string V4L2SubdeviceFormat::toString() const +{ + std::stringstream ss; + + ss.fill(0); + ss << width << "x" << height << " - 0x" << std::hex << std::setw(4) + << mbus_code; + + return ss.str(); +} + /** * \class V4L2Subdevice * \brief A V4L2 subdevice as exposed by the Linux kernel From patchwork Thu Mar 14 15:51:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 737 Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5669F6110A for ; Thu, 14 Mar 2019 16:50:38 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id DABDF100005; Thu, 14 Mar 2019 15:50:37 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Thu, 14 Mar 2019 16:51:04 +0100 Message-Id: <20190314155106.30106-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190314155106.30106-1-jacopo@jmondi.org> References: <20190314155106.30106-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/4] libcamera: formats: Define FormatEnum type X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Mar 2019 15:50:39 -0000 Add an internal format.h and format.cpp files to collect libcamera image format related types, helpers and structures. Define and document there the FormatEnum type, used to enumerate pixel image formats and associated image resolutions. Signed-off-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- src/libcamera/formats.cpp | 27 ++++++++++++++++++++++++++ src/libcamera/include/formats.h | 22 +++++++++++++++++++++ src/libcamera/include/v4l2_subdevice.h | 4 ++-- src/libcamera/meson.build | 1 + src/libcamera/v4l2_subdevice.cpp | 5 ++--- 5 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 src/libcamera/formats.cpp create mode 100644 src/libcamera/include/formats.h diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp new file mode 100644 index 000000000000..a6251fe91cec --- /dev/null +++ b/src/libcamera/formats.cpp @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * formats.cpp - Libcamera image formats + */ + +#include "formats.h" + +/** + * \file formats.h + * \brief Types and helper methods to handle libcamera image formats + */ + +namespace libcamera { + +/** + * \typedef FormatEnum + * \brief Type definition for the map of image formats and sizes + * + * Type definition used to enumerate the supported pixel formats and image frame + * sizes. The type associates in a map a pixel code, used to represent memory or + * wire image formats, to a vector of image resolutions represented by SizeRange + * items. + */ + +} /* namespace libcamera */ diff --git a/src/libcamera/include/formats.h b/src/libcamera/include/formats.h new file mode 100644 index 000000000000..5fcfb11318e7 --- /dev/null +++ b/src/libcamera/include/formats.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * formats.h - Libcamera image formats + */ + +#ifndef __LIBCAMERA_FORMATS_H__ +#define __LIBCAMERA_FORMATS_H__ + +#include +#include + +#include "geometry.h" + +namespace libcamera { + +typedef std::map> FormatEnum; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_FORMATS_H__ */ diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h index 700e66bcddac..3ecf08514898 100644 --- a/src/libcamera/include/v4l2_subdevice.h +++ b/src/libcamera/include/v4l2_subdevice.h @@ -11,6 +11,7 @@ #include #include +#include "formats.h" #include "geometry.h" #include "log.h" #include "media_object.h" @@ -42,8 +43,7 @@ public: int setCrop(unsigned int pad, Rectangle *rect); int setCompose(unsigned int pad, Rectangle *rect); - const std::map> - formats(unsigned int pad); + FormatEnum formats(unsigned int pad); int getFormat(unsigned int pad, V4L2SubdeviceFormat *format); int setFormat(unsigned int pad, V4L2SubdeviceFormat *format); diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 8384cd0af451..4433abfceca3 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -6,6 +6,7 @@ libcamera_sources = files([ 'event_dispatcher.cpp', 'event_dispatcher_poll.cpp', 'event_notifier.cpp', + 'formats.cpp', 'geometry.cpp', 'log.cpp', 'media_device.cpp', diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index eb60fe42bb4e..caaf25ce1b36 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -210,10 +210,9 @@ int V4L2Subdevice::setCompose(unsigned int pad, Rectangle *rect) * \return A map of image formats associated with a list of image sizes, or * an empty map on error or if the pad does not exist */ -const std::map> -V4L2Subdevice::formats(unsigned int pad) +FormatEnum V4L2Subdevice::formats(unsigned int pad) { - std::map> formatMap = {}; + FormatEnum formatMap = {}; struct v4l2_subdev_mbus_code_enum mbusEnum = {}; int ret; From patchwork Thu Mar 14 15:51:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 738 Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E70E9610C5 for ; Thu, 14 Mar 2019 16:50:38 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 7F7A5100002; Thu, 14 Mar 2019 15:50:38 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Thu, 14 Mar 2019 16:51:05 +0100 Message-Id: <20190314155106.30106-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190314155106.30106-1-jacopo@jmondi.org> References: <20190314155106.30106-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 3/4] libcamera: ipu3: Make sure sensor provides a compatible format X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Mar 2019 15:50:39 -0000 When creating a camera, make sure a the image sensor provides images in a format compatible with IPU3 CIO2 unit requirements. Signed-off-by: Jacopo Mondi --- src/libcamera/pipeline/ipu3/ipu3.cpp | 58 +++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 55489c31df2d..90faef1bdece 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -8,6 +8,8 @@ #include #include +#include + #include #include #include @@ -78,6 +80,8 @@ private: PipelineHandler::cameraData(camera)); } + int mediaBusToCIO2Format(unsigned int code); + void registerCameras(); std::shared_ptr cio2_; @@ -327,6 +331,38 @@ bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator) return true; } +int PipelineHandlerIPU3::mediaBusToCIO2Format(unsigned int code) +{ + switch(code) { + case MEDIA_BUS_FMT_SBGGR8_1X8: + case MEDIA_BUS_FMT_SBGGR10_1X10: + case MEDIA_BUS_FMT_SBGGR12_1X12: + case MEDIA_BUS_FMT_SBGGR14_1X14: + case MEDIA_BUS_FMT_SBGGR16_1X16: + return V4L2_PIX_FMT_IPU3_SBGGR10; + case MEDIA_BUS_FMT_SGBRG8_1X8: + case MEDIA_BUS_FMT_SGBRG10_1X10: + case MEDIA_BUS_FMT_SGBRG12_1X12: + case MEDIA_BUS_FMT_SGBRG14_1X14: + case MEDIA_BUS_FMT_SGBRG16_1X16: + return V4L2_PIX_FMT_IPU3_SGBRG10; + case MEDIA_BUS_FMT_SGRBG8_1X8: + case MEDIA_BUS_FMT_SGRBG10_1X10: + case MEDIA_BUS_FMT_SGRBG12_1X12: + case MEDIA_BUS_FMT_SGRBG14_1X14: + case MEDIA_BUS_FMT_SGRBG16_1X16: + return V4L2_PIX_FMT_IPU3_SGRBG10; + case MEDIA_BUS_FMT_SRGGB8_1X8: + case MEDIA_BUS_FMT_SRGGB10_1X10: + case MEDIA_BUS_FMT_SRGGB12_1X12: + case MEDIA_BUS_FMT_SRGGB14_1X14: + case MEDIA_BUS_FMT_SRGGB16_1X16: + return V4L2_PIX_FMT_IPU3_SRGGB10; + default: + return -EINVAL; + } +} + /* * Cameras are created associating an image sensor (represented by a * media entity with function MEDIA_ENT_F_CAM_SENSOR) to one of the four @@ -404,18 +440,36 @@ void PipelineHandlerIPU3::registerCameras() if (ret) continue; - data->cio2_->bufferReady.connect(data.get(), &IPU3CameraData::bufferReady); - + /* + * Make sure the sensor produces at least one image format + * compatible with IPU3 CIO2 requirements. + */ data->sensor_ = new V4L2Subdevice(sensor); ret = data->sensor_->open(); if (ret) continue; + const FormatEnum formats = data->sensor_->formats(0); + auto it = formats.begin(); + for (; it != formats.end(); ++it) { + if (mediaBusToCIO2Format(it->first) != -EINVAL) + break; + } + if (it == formats.end()) { + LOG(IPU3, Info) << "Sensor '" << data->sensor_->deviceName() + << "' detected, but no supported image format " + << " found: skip camera creation"; + continue; + } + data->csi2_ = new V4L2Subdevice(csi2); ret = data->csi2_->open(); if (ret) continue; + data->cio2_->bufferReady.connect(data.get(), + &IPU3CameraData::bufferReady); + registerCamera(std::move(camera), std::move(data)); LOG(IPU3, Info) From patchwork Thu Mar 14 15:51:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 739 Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 88B72610C5 for ; Thu, 14 Mar 2019 16:50:39 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 1C6D8100002; Thu, 14 Mar 2019 15:50:38 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Thu, 14 Mar 2019 16:51:06 +0100 Message-Id: <20190314155106.30106-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190314155106.30106-1-jacopo@jmondi.org> References: <20190314155106.30106-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 4/4] libcamera: ipu3: Set stream configuration from sensor X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Mar 2019 15:50:39 -0000 Inspect all image sizes provided by the sensor and select the biggest of them, associated with an image format code supported by the CIO2 unit. Signed-off-by: Jacopo Mondi --- src/libcamera/pipeline/ipu3/ipu3.cpp | 46 ++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 90faef1bdece..4c2c61c993cb 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -5,6 +5,7 @@ * ipu3.cpp - Pipeline handler for Intel IPU3 */ +#include #include #include @@ -74,6 +75,8 @@ private: Stream stream_; }; + static constexpr unsigned int IPU3_BUFFER_COUNT = 4; + IPU3CameraData *cameraData(const Camera *camera) { return static_cast( @@ -106,26 +109,43 @@ std::map PipelineHandlerIPU3::streamConfiguration(Camera *camera, std::set &streams) { - IPU3CameraData *data = cameraData(camera); std::map configs; - V4L2SubdeviceFormat format = {}; + IPU3CameraData *data = cameraData(camera); + V4L2Subdevice *sensor = data->sensor_; + StreamConfiguration *config = &configs[&data->stream_]; + unsigned int bestSize = 0; /* - * FIXME: As of now, return the image format reported by the sensor. - * In future good defaults should be provided for each stream. + * Make sure the sensor produces a raw format compatible with the + * CIO2 and use the largest image size the sensor provides. */ - if (data->sensor_->getFormat(0, &format)) { - LOG(IPU3, Error) << "Failed to create stream configurations"; - return configs; + const FormatEnum formats = sensor->formats(0); + for (auto it = formats.begin(); it != formats.end(); ++it) { + int cio2Code = mediaBusToCIO2Format(it->first); + if (cio2Code == -EINVAL) + continue; + + for (const SizeRange &range : it->second) { + unsigned int frameSize = range.maxWidth + * range.maxHeight; + + if (frameSize < bestSize) + continue; + + bestSize = frameSize; + + config->width = range.maxWidth; + config->height = range.maxHeight; + config->pixelFormat = cio2Code; + } } - StreamConfiguration config = {}; - config.width = format.width; - config.height = format.height; - config.pixelFormat = V4L2_PIX_FMT_IPU3_SGRBG10; - config.bufferCount = 4; + config->bufferCount = IPU3_BUFFER_COUNT; - configs[&data->stream_] = config; + LOG(IPU3, Debug) + << "Stream format set to " << config->width << "x" + << config->height << " - 0x" << std::hex << std::setfill('0') + << std::setw(4) << config->pixelFormat; return configs; }