From patchwork Wed Jul 1 12:30:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8528 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 855EEBF415 for ; Wed, 1 Jul 2020 12:27:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2E92660C5F; Wed, 1 Jul 2020 14:27:22 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 33E9B609A9 for ; Wed, 1 Jul 2020 14:27:20 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id CB4B71C0015; Wed, 1 Jul 2020 12:27:19 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Jul 2020 14:30:22 +0200 Message-Id: <20200701123036.51922-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701123036.51922-1-jacopo@jmondi.org> References: <20200701123036.51922-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 01/15] libcamera: ipu3: Rename mbusCodesToInfo X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The mbusCodesToInfo map actually maps media bus codes to PixelFormat instances. Rename the map according to its actual function. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund Reviewed-by: Kieran Bingham --- src/libcamera/pipeline/ipu3/cio2.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index aa1459fb3599..2ec8fcb42d92 100644 --- a/src/libcamera/pipeline/ipu3/cio2.cpp +++ b/src/libcamera/pipeline/ipu3/cio2.cpp @@ -23,7 +23,7 @@ LOG_DECLARE_CATEGORY(IPU3) namespace { -static const std::map mbusCodesToInfo = { +static const std::map mbusCodesToPixelFormat = { { MEDIA_BUS_FMT_SBGGR10_1X10, formats::SBGGR10_IPU3 }, { MEDIA_BUS_FMT_SGBRG10_1X10, formats::SGBRG10_IPU3 }, { MEDIA_BUS_FMT_SGRBG10_1X10, formats::SGRBG10_IPU3 }, @@ -96,8 +96,8 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index) * cio2Codes vector sorted in ascending order. */ std::vector cio2Codes; - cio2Codes.reserve(mbusCodesToInfo.size()); - std::transform(mbusCodesToInfo.begin(), mbusCodesToInfo.end(), + cio2Codes.reserve(mbusCodesToPixelFormat.size()); + std::transform(mbusCodesToPixelFormat.begin(), mbusCodesToPixelFormat.end(), std::back_inserter(cio2Codes), [](auto &pair) { return pair.first; }); const std::vector &sensorCodes = sensor_->mbusCodes(); @@ -146,8 +146,8 @@ int CIO2Device::configure(const Size &size, V4L2DeviceFormat *outputFormat) * the CIO2 output device. */ std::vector mbusCodes; - mbusCodes.reserve(mbusCodesToInfo.size()); - std::transform(mbusCodesToInfo.begin(), mbusCodesToInfo.end(), + mbusCodes.reserve(mbusCodesToPixelFormat.size()); + std::transform(mbusCodesToPixelFormat.begin(), mbusCodesToPixelFormat.end(), std::back_inserter(mbusCodes), [](auto &pair) { return pair.first; }); @@ -160,8 +160,8 @@ int CIO2Device::configure(const Size &size, V4L2DeviceFormat *outputFormat) if (ret) return ret; - const auto &itInfo = mbusCodesToInfo.find(sensorFormat.mbus_code); - if (itInfo == mbusCodesToInfo.end()) + const auto &itInfo = mbusCodesToPixelFormat.find(sensorFormat.mbus_code); + if (itInfo == mbusCodesToPixelFormat.end()) return -EINVAL; const PixelFormatInfo &info = PixelFormatInfo::info(itInfo->second); @@ -190,7 +190,7 @@ CIO2Device::generateConfiguration(Size size) const /* Query the sensor static information for closest match. */ std::vector mbusCodes; - std::transform(mbusCodesToInfo.begin(), mbusCodesToInfo.end(), + std::transform(mbusCodesToPixelFormat.begin(), mbusCodesToPixelFormat.end(), std::back_inserter(mbusCodes), [](auto &pair) { return pair.first; }); @@ -201,7 +201,7 @@ CIO2Device::generateConfiguration(Size size) const } cfg.size = sensorFormat.size; - cfg.pixelFormat = mbusCodesToInfo.at(sensorFormat.mbus_code); + cfg.pixelFormat = mbusCodesToPixelFormat.at(sensorFormat.mbus_code); cfg.bufferCount = CIO2_BUFFER_COUNT; return cfg; From patchwork Wed Jul 1 12:30:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8529 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 6B49CBF415 for ; Wed, 1 Jul 2020 12:27:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4E35F60C5D; Wed, 1 Jul 2020 14:27:22 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B8673603B4 for ; Wed, 1 Jul 2020 14:27:20 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 553A91C0018; Wed, 1 Jul 2020 12:27:20 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Jul 2020 14:30:23 +0200 Message-Id: <20200701123036.51922-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701123036.51922-1-jacopo@jmondi.org> References: <20200701123036.51922-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 02/15] libcamera: ipu3: Remove streams from generateConfiguration X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Remove stream assignement from the IPU3 pipeline handler generateConfiguration() implementation. The function aims to provide a suitable default for the requested use cases. Defer stream assignement to validation and only assign sizes and formats to stream configurations. Signed-off-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- src/libcamera/pipeline/ipu3/ipu3.cpp | 93 ++++++++-------------------- 1 file changed, 27 insertions(+), 66 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 1bdad209de6e..97fc8b60c3cb 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -31,6 +31,9 @@ namespace libcamera { LOG_DEFINE_CATEGORY(IPU3) +static constexpr unsigned int IPU3_BUFFER_COUNT = 4; +static constexpr unsigned int IPU3_MAX_STREAMS = 3; + class IPU3CameraData : public CameraData { public: @@ -61,9 +64,6 @@ public: const std::vector &streams() { return streams_; } private: - static constexpr unsigned int IPU3_BUFFER_COUNT = 4; - static constexpr unsigned int IPU3_MAX_STREAMS = 3; - void assignStreams(); void adjustStream(StreamConfiguration &cfg, bool scale); @@ -293,94 +293,55 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera, { IPU3CameraData *data = cameraData(camera); IPU3CameraConfiguration *config = new IPU3CameraConfiguration(camera, data); - std::set streams = { - &data->outStream_, - &data->vfStream_, - &data->rawStream_, - }; if (roles.empty()) return config; + Size sensorResolution = data->cio2_.sensor()->resolution(); + unsigned int rawCount = 0; + unsigned int outCount = 0; for (const StreamRole role : roles) { StreamConfiguration cfg = {}; - Stream *stream = nullptr; - - cfg.pixelFormat = formats::NV12; switch (role) { case StreamRole::StillCapture: /* - * Pick the output stream by default as the Viewfinder - * and VideoRecording roles are not allowed on - * the output stream. + * Use the sensor resolution adjusted to respect the + * ImgU output alignement contraints. */ - if (streams.find(&data->outStream_) != streams.end()) { - stream = &data->outStream_; - } else if (streams.find(&data->vfStream_) != streams.end()) { - stream = &data->vfStream_; - } else { - LOG(IPU3, Error) - << "No stream available for requested role " - << role; - break; - } + cfg.pixelFormat = formats::NV12; + cfg.size = sensorResolution; + cfg.size.width &= ~7; + cfg.size.height &= ~3; + cfg.bufferCount = IPU3_BUFFER_COUNT; - /* - * FIXME: Soraka: the maximum resolution reported by - * both sensors (2592x1944 for ov5670 and 4224x3136 for - * ov13858) are returned as default configurations but - * they're not correctly processed by the ImgU. - * Resolutions up tp 2560x1920 have been validated. - * - * \todo Clarify ImgU alignment requirements. - */ - cfg.size = { 2560, 1920 }; + outCount++; break; case StreamRole::StillCaptureRaw: { - if (streams.find(&data->rawStream_) == streams.end()) { - LOG(IPU3, Error) - << "Multiple raw streams are not supported"; - break; - } + cfg = data->cio2_.generateConfiguration(sensorResolution); + cfg.bufferCount = 1; - stream = &data->rawStream_; + rawCount++; - cfg.size = data->cio2_.sensor()->resolution(); - - cfg = data->cio2_.generateConfiguration(cfg.size); break; } case StreamRole::Viewfinder: case StreamRole::VideoRecording: { - /* - * We can't use the 'output' stream for viewfinder or - * video capture roles. - * - * \todo This is an artificial limitation until we - * figure out the exact capabilities of the hardware. - */ - if (streams.find(&data->vfStream_) == streams.end()) { - LOG(IPU3, Error) - << "No stream available for requested role " - << role; - break; - } - - stream = &data->vfStream_; - /* * Align the default viewfinder size to the maximum * available sensor resolution and to the IPU3 * alignment constraints. */ - const Size &res = data->cio2_.sensor()->resolution(); - unsigned int width = std::min(1280U, res.width); - unsigned int height = std::min(720U, res.height); + unsigned int width = std::min(1280U, sensorResolution.width); + unsigned int height = std::min(720U, sensorResolution.height); cfg.size = { width & ~7, height & ~3 }; + cfg.pixelFormat = formats::NV12; + cfg.bufferCount = IPU3_BUFFER_COUNT; + + outCount++; break; } @@ -388,16 +349,16 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera, default: LOG(IPU3, Error) << "Requested stream role not supported: " << role; - break; + delete config; + return nullptr; } - if (!stream) { + if (rawCount > 1 || outCount > 2) { + LOG(IPU3, Error) << "Invalid stream roles requested"; delete config; return nullptr; } - streams.erase(stream); - config->addConfiguration(cfg); } From patchwork Wed Jul 1 12:30:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8530 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id C4989C2E69 for ; Wed, 1 Jul 2020 12:27:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 68A5060CA5; Wed, 1 Jul 2020 14:27:22 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 48BFB609A9 for ; Wed, 1 Jul 2020 14:27:21 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id DAD641C0009; Wed, 1 Jul 2020 12:27:20 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Jul 2020 14:30:24 +0200 Message-Id: <20200701123036.51922-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701123036.51922-1-jacopo@jmondi.org> References: <20200701123036.51922-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 03/15] libcamera: ipu3: cio2: Report format and sizes X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add two methods to the CIO2Device class to retrieve all the supported PixelFormats and sizes. Signed-off-by: Jacopo Mondi --- src/libcamera/pipeline/ipu3/cio2.cpp | 43 +++++++++++++++++++++++++++- src/libcamera/pipeline/ipu3/cio2.h | 7 +++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index 2ec8fcb42d92..b34194c5097f 100644 --- a/src/libcamera/pipeline/ipu3/cio2.cpp +++ b/src/libcamera/pipeline/ipu3/cio2.cpp @@ -33,7 +33,7 @@ static const std::map mbusCodesToPixelFormat = { } /* namespace */ CIO2Device::CIO2Device() - : sensor_(nullptr), csi2_(nullptr), output_(nullptr) + : sensor_(nullptr), csi2_(nullptr), output_(nullptr), initialized_(false) { } @@ -44,6 +44,45 @@ CIO2Device::~CIO2Device() delete sensor_; } +/** + * \brief Retrieve the list of supported PixelFormats + * + * Retrieve the list of supported pixel formats by matching the sensor produced + * media bus codes with the formats supported by the CIO2 unit. + * + * \return The list of supported PixelFormat + */ +std::vector CIO2Device::formats() const +{ + if (!initialized_) + return {}; + + std::vector formats; + for (unsigned int code : sensor_->mbusCodes()) { + auto it = mbusCodesToPixelFormat.find(code); + if (it != mbusCodesToPixelFormat.end()) + formats.push_back(it->second); + } + + return formats; +} + +/** + * \brief Retrieve the list of supported size ranges + * \return The list of supported SizeRange + */ +std::vector CIO2Device::sizes() const +{ + if (!initialized_) + return {}; + + std::vector sizes; + for (const Size &size : sensor_->sizes()) + sizes.emplace_back(size, size); + + return sizes; +} + /** * \brief Initialize components of the CIO2 device with \a index * \param[in] media The CIO2 media device @@ -127,6 +166,8 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index) output_->bufferReady.connect(this, &CIO2Device::cio2BufferReady); + initialized_ = true; + return 0; } diff --git a/src/libcamera/pipeline/ipu3/cio2.h b/src/libcamera/pipeline/ipu3/cio2.h index dc764b101f11..7e793e8450f5 100644 --- a/src/libcamera/pipeline/ipu3/cio2.h +++ b/src/libcamera/pipeline/ipu3/cio2.h @@ -18,7 +18,9 @@ namespace libcamera { class CameraSensor; class FrameBuffer; class MediaDevice; +class PixelFormat; class Request; +class SizeRange; class V4L2DeviceFormat; class V4L2Subdevice; class V4L2VideoDevice; @@ -33,6 +35,9 @@ public: CIO2Device(); ~CIO2Device(); + std::vector formats() const; + std::vector sizes() const; + int init(const MediaDevice *media, unsigned int index); int configure(const Size &size, V4L2DeviceFormat *outputFormat); @@ -61,6 +66,8 @@ private: std::vector> buffers_; std::queue availableBuffers_; + + bool initialized_; }; } /* namespace libcamera */ From patchwork Wed Jul 1 12:30:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8531 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 0758CBF415 for ; Wed, 1 Jul 2020 12:27:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 85D2260CB2; Wed, 1 Jul 2020 14:27:22 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C1F5F60C53 for ; Wed, 1 Jul 2020 14:27:21 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 683E51C0019; Wed, 1 Jul 2020 12:27:21 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Jul 2020 14:30:25 +0200 Message-Id: <20200701123036.51922-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701123036.51922-1-jacopo@jmondi.org> References: <20200701123036.51922-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 04/15] libcamera: ipu3: Do not overwrite StreamConfiguration X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The validate function overwrites the generated StreamConfiguration with the one reported by the CIO2 unit when inspecting the RAW stream configuration. As we prepare to add StreamFormats to the IPU3 StreamConfiguration, assigning to the CIO2 generated configuration would delete the StreamFormats. Fix this by updating relevant fields only in order to keep the assigned StreamFormats. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/pipeline/ipu3/ipu3.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.27.0 diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 97fc8b60c3cb..cd18c6f31023 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -264,7 +264,9 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate() const Stream *stream = streams_[i]; if (stream == &data_->rawStream_) { - cfg = cio2Configuration_; + cfg.size = cio2Configuration_.size; + cfg.pixelFormat = cio2Configuration_.pixelFormat; + cfg.bufferCount = cio2Configuration_.bufferCount; } else { bool scale = stream == &data_->vfStream_; adjustStream(config_[i], scale); From patchwork Wed Jul 1 12:30:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8532 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id E9C3ABF415 for ; Wed, 1 Jul 2020 12:27:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C675F60C62; Wed, 1 Jul 2020 14:27:24 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6DEA860CAE for ; Wed, 1 Jul 2020 14:27:22 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id E6DB51C0003; Wed, 1 Jul 2020 12:27:21 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Jul 2020 14:30:26 +0200 Message-Id: <20200701123036.51922-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701123036.51922-1-jacopo@jmondi.org> References: <20200701123036.51922-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 05/15] libcamera: ipu3: Report StreamFormats X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Report StreamFormats associated to each StreamConfiguration generated by the IPU3 pipeline handler. The StreamFormats are generated differently for RAW and processed streams, with the former using the sensor enumerated resolutions and the latter using a continuous range of sizes constructed by matching the sensor capabilities with the platform constraints. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/pipeline/ipu3/ipu3.cpp | 47 +++++++++++++++++++++------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index cd18c6f31023..ed2360347fb4 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -33,6 +33,9 @@ LOG_DEFINE_CATEGORY(IPU3) static constexpr unsigned int IPU3_BUFFER_COUNT = 4; static constexpr unsigned int IPU3_MAX_STREAMS = 3; +static constexpr unsigned int IPU3_OUTPUT_MAX_WIDTH = 4480; +static constexpr unsigned int IPU3_OUTPUT_MAX_HEIGHT = 34004; +static const Size minIPU3OutputSize = { 2, 2 }; class IPU3CameraData : public CameraData { @@ -295,15 +298,19 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera, { IPU3CameraData *data = cameraData(camera); IPU3CameraConfiguration *config = new IPU3CameraConfiguration(camera, data); + CIO2Device *cio2 = &data->cio2_; if (roles.empty()) return config; - Size sensorResolution = data->cio2_.sensor()->resolution(); + Size sensorResolution = cio2->sensor()->resolution(); unsigned int rawCount = 0; unsigned int outCount = 0; for (const StreamRole role : roles) { - StreamConfiguration cfg = {}; + std::map> streamFormats; + unsigned int bufferCount; + PixelFormat pixelFormat; + Size size; switch (role) { case StreamRole::StillCapture: @@ -311,19 +318,29 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera, * Use the sensor resolution adjusted to respect the * ImgU output alignement contraints. */ - cfg.pixelFormat = formats::NV12; - cfg.size = sensorResolution; - cfg.size.width &= ~7; - cfg.size.height &= ~3; - cfg.bufferCount = IPU3_BUFFER_COUNT; + pixelFormat = formats::NV12; + size.width = std::min(sensorResolution.width, + IPU3_OUTPUT_MAX_WIDTH); + size.height = std::min(sensorResolution.height, + IPU3_OUTPUT_MAX_HEIGHT); + size.width &= ~7; + size.height &= ~3; + bufferCount = IPU3_BUFFER_COUNT; + streamFormats[pixelFormat] = { { minIPU3OutputSize, size } }; outCount++; break; case StreamRole::StillCaptureRaw: { - cfg = data->cio2_.generateConfiguration(sensorResolution); - cfg.bufferCount = 1; + StreamConfiguration cio2Config = + cio2->generateConfiguration(sensorResolution); + pixelFormat = cio2Config.pixelFormat; + size = cio2Config.size; + bufferCount = cio2Config.bufferCount; + + for (const PixelFormat &format : cio2->formats()) + streamFormats[format] = cio2->sizes(); rawCount++; @@ -339,9 +356,10 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera, */ unsigned int width = std::min(1280U, sensorResolution.width); unsigned int height = std::min(720U, sensorResolution.height); - cfg.size = { width & ~7, height & ~3 }; - cfg.pixelFormat = formats::NV12; - cfg.bufferCount = IPU3_BUFFER_COUNT; + size = { width & ~7, height & ~3 }; + pixelFormat = formats::NV12; + bufferCount = IPU3_BUFFER_COUNT; + streamFormats[pixelFormat] = { { minIPU3OutputSize, size } }; outCount++; @@ -361,6 +379,11 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera, return nullptr; } + StreamFormats formats(streamFormats); + StreamConfiguration cfg(formats); + cfg.size = size; + cfg.pixelFormat = pixelFormat; + cfg.bufferCount = bufferCount; config->addConfiguration(cfg); } From patchwork Wed Jul 1 12:30:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8533 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 2C8A2C2E69 for ; Wed, 1 Jul 2020 12:27:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EE39960CBC; Wed, 1 Jul 2020 14:27:24 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C976F60C5B for ; Wed, 1 Jul 2020 14:27:22 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 6A7A51C0007; Wed, 1 Jul 2020 12:27:22 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Jul 2020 14:30:27 +0200 Message-Id: <20200701123036.51922-7-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701123036.51922-1-jacopo@jmondi.org> References: <20200701123036.51922-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 06/15] libcamera: ipu3: Rework stream validation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" With the goal of moving stream assignement to configuration from validate() to configure(), rework the validate() function to not inspect the stream assigned to a configuration to identify it. Re-work the validation logic to follow this simpler flow: - if a stream is a raw stream use the sensor configuration - if a stream is a processed one, make sure it respects the ImgU output size and alignment constraints. Remove the 'adjustStream()' function as it depends on stream assignment and was built on the assumption the main output should always work at the maximum available resolution, and it addressed the case where no width or height where supplied for a viewfinder stream, which should only be validated against the ImgU output constraints, not defaulted to a sane value. Retain the call to assignStreams() in validate() for the moment in order not to break capture operations, but while at it clean up the code a bit by removing a rogue empty line and make a conditional check fit on a single line. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/pipeline/ipu3/ipu3.cpp | 85 ++++++++++------------------ 1 file changed, 31 insertions(+), 54 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index ed2360347fb4..daa6d71dae72 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -68,7 +68,6 @@ public: private: void assignStreams(); - void adjustStream(StreamConfiguration &cfg, bool scale); /* * The IPU3CameraData instance is guaranteed to be valid as long as the @@ -178,52 +177,6 @@ void IPU3CameraConfiguration::assignStreams() } } -void IPU3CameraConfiguration::adjustStream(StreamConfiguration &cfg, bool scale) -{ - /* The only pixel format the driver supports is NV12. */ - cfg.pixelFormat = formats::NV12; - - if (scale) { - /* - * Provide a suitable default that matches the sensor aspect - * ratio. - */ - if (!cfg.size.width || !cfg.size.height) { - cfg.size.width = 1280; - cfg.size.height = 1280 * cio2Configuration_.size.height - / cio2Configuration_.size.width; - } - - /* - * \todo: Clamp the size to the hardware bounds when we will - * figure them out. - * - * \todo: Handle the scaler (BDS) restrictions. The BDS can - * only scale with the same factor in both directions, and the - * scaling factor is limited to a multiple of 1/32. At the - * moment the ImgU driver hides these constraints by applying - * additional cropping, this should be fixed on the driver - * side, and cropping should be exposed to us. - */ - } else { - /* - * \todo: Properly support cropping when the ImgU driver - * interface will be cleaned up. - */ - cfg.size = cio2Configuration_.size; - } - - /* - * Clamp the size to match the ImgU alignment constraints. The width - * shall be a multiple of 8 pixels and the height a multiple of 4 - * pixels. - */ - if (cfg.size.width % 8 || cfg.size.height % 4) { - cfg.size.width &= ~7; - cfg.size.height &= ~3; - } -} - CameraConfiguration::Status IPU3CameraConfiguration::validate() { Status status = Valid; @@ -244,7 +197,6 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate() * resolution is large enough, pick the largest one. */ Size size = {}; - for (const StreamConfiguration &cfg : config_) { if (cfg.size.width > size.width) size.width = cfg.size.width; @@ -264,20 +216,45 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate() for (unsigned int i = 0; i < config_.size(); ++i) { StreamConfiguration &cfg = config_[i]; const StreamConfiguration oldCfg = cfg; - const Stream *stream = streams_[i]; + const PixelFormatInfo &info = + PixelFormatInfo::info(cfg.pixelFormat); - if (stream == &data_->rawStream_) { + if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) { cfg.size = cio2Configuration_.size; cfg.pixelFormat = cio2Configuration_.pixelFormat; cfg.bufferCount = cio2Configuration_.bufferCount; } else { - bool scale = stream == &data_->vfStream_; - adjustStream(config_[i], scale); + /* + * Clamp the size to match the ImgU alignment + * constraints. + */ + size.width = std::min(cfg.size.width, + IPU3_OUTPUT_MAX_WIDTH); + size.height = std::min(cfg.size.height, + IPU3_OUTPUT_MAX_HEIGHT); + size.width = std::max(cfg.size.width, + minIPU3OutputSize.width); + size.height = std::max(cfg.size.height, + minIPU3OutputSize.height); + if (cfg.size.width % 8 || cfg.size.height % 4) { + cfg.size.width &= ~7; + cfg.size.height &= ~3; + } + cfg.pixelFormat = formats::NV12; cfg.bufferCount = IPU3_BUFFER_COUNT; + + /* + * \todo: Handle the scaler (BDS) restrictions. The BDS + * can only scale with the same factor in both + * directions, and the scaling factor is limited to a + * multiple of 1/32. At the moment the ImgU driver hides + * these constraints by applying additional cropping, + * this should be fixed on the driver side, and cropping + * should be exposed to us. + */ } - if (cfg.pixelFormat != oldCfg.pixelFormat || - cfg.size != oldCfg.size) { + if (cfg.pixelFormat != oldCfg.pixelFormat || cfg.size != oldCfg.size) { LOG(IPU3, Debug) << "Stream " << i << " configuration adjusted to " << cfg.toString(); From patchwork Wed Jul 1 12:30:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8534 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 86A5EBF415 for ; Wed, 1 Jul 2020 12:27:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4986560C59; Wed, 1 Jul 2020 14:27:26 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5415460C53 for ; Wed, 1 Jul 2020 14:27:23 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id EBA581C0009; Wed, 1 Jul 2020 12:27:22 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Jul 2020 14:30:28 +0200 Message-Id: <20200701123036.51922-8-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701123036.51922-1-jacopo@jmondi.org> References: <20200701123036.51922-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 07/15] libcamera: ipu3: Refuse unsupported configuration X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Make sure in the validate() function that the number of raw and processed streams requested by applications is supported by the platform. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/pipeline/ipu3/ipu3.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index daa6d71dae72..651e0c93a7ab 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -213,6 +213,8 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate() assignStreams(); /* Verify and adjust configuration if needed. */ + unsigned int rawCount = 0; + unsigned int outCount = 0; for (unsigned int i = 0; i < config_.size(); ++i) { StreamConfiguration &cfg = config_[i]; const StreamConfiguration oldCfg = cfg; @@ -223,6 +225,7 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate() cfg.size = cio2Configuration_.size; cfg.pixelFormat = cio2Configuration_.pixelFormat; cfg.bufferCount = cio2Configuration_.bufferCount; + rawCount++; } else { /* * Clamp the size to match the ImgU alignment @@ -242,6 +245,7 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate() } cfg.pixelFormat = formats::NV12; cfg.bufferCount = IPU3_BUFFER_COUNT; + outCount++; /* * \todo: Handle the scaler (BDS) restrictions. The BDS @@ -254,6 +258,13 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate() */ } + if (rawCount > 1 || outCount > 2) { + LOG(IPU3, Error) + << "Camera configuration not supported: " + << "the platform supports up to one raw stream and two processed ones."; + return Invalid; + } + if (cfg.pixelFormat != oldCfg.pixelFormat || cfg.size != oldCfg.size) { LOG(IPU3, Debug) << "Stream " << i << " configuration adjusted to " From patchwork Wed Jul 1 12:30:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8535 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id BE446C2E69 for ; Wed, 1 Jul 2020 12:27:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9818860CDD; Wed, 1 Jul 2020 14:27:26 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DA8FF60C62 for ; Wed, 1 Jul 2020 14:27:23 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 77E851C0007; Wed, 1 Jul 2020 12:27:23 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Jul 2020 14:30:29 +0200 Message-Id: <20200701123036.51922-9-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701123036.51922-1-jacopo@jmondi.org> References: <20200701123036.51922-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 08/15] libcamera: ipu3: Assign streams at configure() time X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Assign streams to StreamConfiguration at configure() time, instead of doing so during validation. This allows easier computation of stream assignement and will allow removing the vector of stream instances from the IPU3CameraConfiguration. Signed-off-by: Jacopo Mondi --- src/libcamera/pipeline/ipu3/ipu3.cpp | 146 +++++++++++++-------------- 1 file changed, 69 insertions(+), 77 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 651e0c93a7ab..8f75c5186b13 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -67,8 +67,6 @@ public: const std::vector &streams() { return streams_; } private: - void assignStreams(); - /* * The IPU3CameraData instance is guaranteed to be valid as long as the * corresponding Camera instance is valid. In order to borrow a @@ -133,50 +131,6 @@ IPU3CameraConfiguration::IPU3CameraConfiguration(Camera *camera, data_ = data; } -void IPU3CameraConfiguration::assignStreams() -{ - /* - * Verify and update all configuration entries, and assign a stream to - * each of them. The viewfinder stream can scale, while the output - * stream can crop only, so select the output stream when the requested - * resolution is equal to the sensor resolution, and the viewfinder - * stream otherwise. - */ - std::set availableStreams = { - &data_->outStream_, - &data_->vfStream_, - &data_->rawStream_, - }; - - /* - * The caller is responsible to limit the number of requested streams - * to a number supported by the pipeline before calling this function. - */ - ASSERT(availableStreams.size() >= config_.size()); - - streams_.clear(); - streams_.reserve(config_.size()); - - for (const StreamConfiguration &cfg : config_) { - const PixelFormatInfo &info = - PixelFormatInfo::info(cfg.pixelFormat); - const Stream *stream; - - if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) - stream = &data_->rawStream_; - else if (cfg.size == cio2Configuration_.size) - stream = &data_->outStream_; - else - stream = &data_->vfStream_; - - if (availableStreams.find(stream) == availableStreams.end()) - stream = *availableStreams.begin(); - - streams_.push_back(stream); - availableStreams.erase(stream); - } -} - CameraConfiguration::Status IPU3CameraConfiguration::validate() { Status status = Valid; @@ -209,9 +163,6 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate() if (!cio2Configuration_.pixelFormat.isValid()) return Invalid; - /* Assign streams to each configuration entry. */ - assignStreams(); - /* Verify and adjust configuration if needed. */ unsigned int rawCount = 0; unsigned int outCount = 0; @@ -385,9 +336,6 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) IPU3CameraConfiguration *config = static_cast(c); IPU3CameraData *data = cameraData(camera); - Stream *outStream = &data->outStream_; - Stream *vfStream = &data->vfStream_; - CIO2Device *cio2 = &data->cio2_; ImgUDevice *imgu = data->imgu_; V4L2DeviceFormat outputFormat; int ret; @@ -435,12 +383,36 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) return ret; /* - * Pass the requested stream size to the CIO2 unit and get back the - * adjusted format to be propagated to the ImgU output devices. + * Identify the maximum sizes and the number of non-raw streams + * requested. + */ + unsigned int outCount = 0; + Size maxOut; + for (unsigned int i = 0; i < config->size(); ++i) { + const StreamConfiguration &cfg = (*config)[i]; + const PixelFormatInfo &info = + PixelFormatInfo::info(cfg.pixelFormat); + + /* + * We have validated that only one raw stream can be requested + * and the CIO2 configuration has been set during validation. + */ + if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) + continue; + + /* Get the largest size of the two available processed streams. */ + if (maxOut < cfg.size) + maxOut = cfg.size; + outCount++; + } + + /* + * Configure the CIO2 unit with the format computed during validation + * and apply the same format to the ImgU input. */ const Size &sensorSize = config->cio2Format().size; V4L2DeviceFormat cio2Format = {}; - ret = cio2->configure(sensorSize, &cio2Format); + ret = data->cio2_.configure(sensorSize, &cio2Format); if (ret) return ret; @@ -451,40 +423,60 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) /* Apply the format to the configured streams output devices. */ bool outActive = false; bool vfActive = false; - for (unsigned int i = 0; i < config->size(); ++i) { - /* - * Use a const_cast<> here instead of storing a mutable stream - * pointer in the configuration to let the compiler catch - * unwanted modifications of camera data in the configuration - * validate() implementation. - */ - Stream *stream = const_cast(config->streams()[i]); StreamConfiguration &cfg = (*config)[i]; + const PixelFormatInfo &info = + PixelFormatInfo::info(cfg.pixelFormat); + if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) { + /* + * The RAW stream is configured as part of the CIO2 and + * no configuration is needed for the ImgU. + */ + cfg.setStream(&data->rawStream_); + cfg.stride = cio2Format.planes[0].bpl; - cfg.setStream(stream); + LOG(IPU3, Debug) << "Assigned " << cfg.toString() + << " to the raw output"; + continue; + } - if (stream == outStream) { + /* + * The viewfinder stream can scale, while the main output stream + * can crop only. Select the main output for the largest + * non-raw stream only if another smaller one has been + * requested. + */ + if (cfg.size == maxOut && outCount > 1) { ret = imgu->configureOutput(cfg, &outputFormat); if (ret) return ret; cfg.stride = outputFormat.planes[0].bpl; + cfg.setStream(&data->outStream_); outActive = true; - } else if (stream == vfStream) { - ret = imgu->configureViewfinder(cfg, &outputFormat); - if (ret) - return ret; - cfg.stride = outputFormat.planes[0].bpl; - vfActive = true; - } else { - /* - * The RAW stream is configured as part of the CIO2 and - * no configuration is needed for the ImgU. - */ - cfg.stride = cio2Format.planes[0].bpl; + LOG(IPU3, Debug) << "Assigned " << cfg.toString() + << " to the main output"; + continue; } + + /* + * If a single non-raw stream has been requested, assign it to + * the viewfinder output regardless of its size. If more than + * one non-raw stream has been requested, assign to viewfinder + * the smaller one to reduce the cropping required (if any) on + * the main output. + */ + ret = imgu->configureViewfinder(cfg, &outputFormat); + if (ret) + return ret; + + cfg.stride = outputFormat.planes[0].bpl; + cfg.setStream(&data->vfStream_); + vfActive = true; + + LOG(IPU3, Debug) << "Assigned " << cfg.toString() + << " to the viewfinder output"; } /* From patchwork Wed Jul 1 12:30:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8536 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id E1E0BC2E6B for ; Wed, 1 Jul 2020 12:27:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BF34C60CE2; Wed, 1 Jul 2020 14:27:26 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 79C4260C53 for ; Wed, 1 Jul 2020 14:27:24 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 0869E1C0007; Wed, 1 Jul 2020 12:27:23 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Jul 2020 14:30:30 +0200 Message-Id: <20200701123036.51922-10-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701123036.51922-1-jacopo@jmondi.org> References: <20200701123036.51922-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 09/15] libcamera: ipu3: Remove streams from IPU3CameraConfiguration X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The IPU3CameraConfiguration::streams_ field was used to keep an association between the StreamConfiguration and the assigned streams before CameraConfiguration::setStream() was called at configure() time. The stream assignment was based on the order in which elements were inserted in the vector, implementing a fragile association between streams and their intended configurations. As stream assignment now happens at configure() time, there is no need to keep that association in place, and the streams_ vector is now unused. Remove it and the associated accessor method from the IPU3CameraConfiguration class. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/pipeline/ipu3/ipu3.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 8f75c5186b13..4d70f9e3a30c 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -64,7 +64,6 @@ public: Status validate() override; const StreamConfiguration &cio2Format() const { return cio2Configuration_; }; - const std::vector &streams() { return streams_; } private: /* @@ -76,7 +75,6 @@ private: const IPU3CameraData *data_; StreamConfiguration cio2Configuration_; - std::vector streams_; }; class PipelineHandlerIPU3 : public PipelineHandler From patchwork Wed Jul 1 12:30:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8537 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 175DFC2E6C for ; Wed, 1 Jul 2020 12:27:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E413E60CC2; Wed, 1 Jul 2020 14:27:26 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 00BC160CBE for ; Wed, 1 Jul 2020 14:27:25 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 9B0C81C0003; Wed, 1 Jul 2020 12:27:24 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Jul 2020 14:30:31 +0200 Message-Id: <20200701123036.51922-11-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701123036.51922-1-jacopo@jmondi.org> References: <20200701123036.51922-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 10/15] libcamera: ipu3: Remove camera_ from IPU3CameraConfiguration X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The IPU3CameraConfiguration::camera_ shared pointer is not used. Remove it. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/pipeline/ipu3/ipu3.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 4d70f9e3a30c..16bda97a3cc3 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -59,19 +59,13 @@ public: class IPU3CameraConfiguration : public CameraConfiguration { public: - IPU3CameraConfiguration(Camera *camera, IPU3CameraData *data); + IPU3CameraConfiguration(IPU3CameraData *data); Status validate() override; const StreamConfiguration &cio2Format() const { return cio2Configuration_; }; private: - /* - * The IPU3CameraData instance is guaranteed to be valid as long as the - * corresponding Camera instance is valid. In order to borrow a - * reference to the camera data, store a new reference to the camera. - */ - std::shared_ptr camera_; const IPU3CameraData *data_; StreamConfiguration cio2Configuration_; @@ -121,11 +115,9 @@ private: MediaDevice *imguMediaDev_; }; -IPU3CameraConfiguration::IPU3CameraConfiguration(Camera *camera, - IPU3CameraData *data) +IPU3CameraConfiguration::IPU3CameraConfiguration(IPU3CameraData *data) : CameraConfiguration() { - camera_ = camera->shared_from_this(); data_ = data; } @@ -234,7 +226,7 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera, const StreamRoles &roles) { IPU3CameraData *data = cameraData(camera); - IPU3CameraConfiguration *config = new IPU3CameraConfiguration(camera, data); + IPU3CameraConfiguration *config = new IPU3CameraConfiguration(data); CIO2Device *cio2 = &data->cio2_; if (roles.empty()) From patchwork Wed Jul 1 12:30:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8538 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 50C5BBF415 for ; Wed, 1 Jul 2020 12:27:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 223D560CBE; Wed, 1 Jul 2020 14:27:27 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8909960CC2 for ; Wed, 1 Jul 2020 14:27:25 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 2813C1C0003; Wed, 1 Jul 2020 12:27:24 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Jul 2020 14:30:32 +0200 Message-Id: <20200701123036.51922-12-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701123036.51922-1-jacopo@jmondi.org> References: <20200701123036.51922-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 11/15] libcamera: geometry: Add isNull() function to Rectangle class X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" It's common for code to check if a rectangle is null. Add a helper function to do so. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- include/libcamera/geometry.h | 1 + src/libcamera/geometry.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h index 7d4b8bcfe3d8..44561d9cc5a4 100644 --- a/include/libcamera/geometry.h +++ b/include/libcamera/geometry.h @@ -18,6 +18,7 @@ struct Rectangle { unsigned int width; unsigned int height; + bool isNull() const { return !width && !height; } const std::string toString() const; }; diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp index 24c44fb43acf..af29ed1119fe 100644 --- a/src/libcamera/geometry.cpp +++ b/src/libcamera/geometry.cpp @@ -49,6 +49,12 @@ namespace libcamera { * \brief The distance between the top and bottom sides */ +/** + * \fn bool Rectangle::isNull() const + * \brief Check if the rectangle is null + * \return True if both the width and height are 0, or false otherwise + */ + /** * \brief Assemble and return a string describing the rectangle * \return A string describing the Rectangle From patchwork Wed Jul 1 12:30:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8539 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 6EBA7BF415 for ; Wed, 1 Jul 2020 12:27:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4892C60C5C; Wed, 1 Jul 2020 14:27:29 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 109EB60CC2 for ; Wed, 1 Jul 2020 14:27:26 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id A5E741C0007; Wed, 1 Jul 2020 12:27:25 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Jul 2020 14:30:33 +0200 Message-Id: <20200701123036.51922-13-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701123036.51922-1-jacopo@jmondi.org> References: <20200701123036.51922-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 12/15] libcamera: ipu3: add ImgUDevice::Pipe X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a structure that describes the ImgU pipe configuration. The new structure reports the size of the ImgU input frame, the desired main output size and desired viewfinder size. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/pipeline/ipu3/imgu.cpp | 19 +++++++++++++++++++ src/libcamera/pipeline/ipu3/imgu.h | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp index d7f4173d3607..7e9047cc8dc1 100644 --- a/src/libcamera/pipeline/ipu3/imgu.cpp +++ b/src/libcamera/pipeline/ipu3/imgu.cpp @@ -19,6 +19,25 @@ namespace libcamera { LOG_DECLARE_CATEGORY(IPU3) +/** + * \struct Pipe + * \brief Describe the ImgU requested configuration + * + * The ImgU unit processes images through several components, which have + * to be properly configured inspecting the input image size and the desired + * output sizes. This structure collects the ImgU input configuration and the + * requested main output and viewfinder configurations. + * + * \var Pipe::input + * \brief The input image size + * + * \var Pipe::output + * \brief The requested main output size + * + * \var Pipe::viewfinder + * \brief The requested viewfinder size + */ + /** * \brief Initialize components of the ImgU instance * \param[in] mediaDevice The ImgU instance media device diff --git a/src/libcamera/pipeline/ipu3/imgu.h b/src/libcamera/pipeline/ipu3/imgu.h index 5c124af2e9fe..8fb271fb8350 100644 --- a/src/libcamera/pipeline/ipu3/imgu.h +++ b/src/libcamera/pipeline/ipu3/imgu.h @@ -23,6 +23,12 @@ struct StreamConfiguration; class ImgUDevice { public: + struct Pipe { + Size input; + Size output; + Size viewfinder; + }; + int init(MediaDevice *media, unsigned int index); int configureInput(const Size &size, V4L2DeviceFormat *inputFormat); From patchwork Wed Jul 1 12:30:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8540 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8F346C2E69 for ; Wed, 1 Jul 2020 12:27:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 65CA860CDB; Wed, 1 Jul 2020 14:27:29 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 96B2960CDB for ; Wed, 1 Jul 2020 14:27:26 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 31D361C000F; Wed, 1 Jul 2020 12:27:26 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Jul 2020 14:30:34 +0200 Message-Id: <20200701123036.51922-14-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701123036.51922-1-jacopo@jmondi.org> References: <20200701123036.51922-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 13/15] libcamera: ipu3: Collect ImgU pipe configuration X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Break the stream assignement and ImgU configuration performed at IPU3PipelineHandler::configure() time in two parts, to collect the ImgU pipe configuration. The first pass collects the desired ImgU pipe configuration and assigns streams to configurations. The second pass, which is performed after the ImgU pipe has been configured, programs the computed sizes to the ImgU output video devices. Use the collected pipe configuration in ImgUDevice::configureInput() as it will be used to compute the pipe configuration parameters. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/pipeline/ipu3/imgu.cpp | 11 ++-- src/libcamera/pipeline/ipu3/imgu.h | 2 +- src/libcamera/pipeline/ipu3/ipu3.cpp | 80 +++++++++++++++++++--------- 3 files changed, 60 insertions(+), 33 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp index 7e9047cc8dc1..49201157eb07 100644 --- a/src/libcamera/pipeline/ipu3/imgu.cpp +++ b/src/libcamera/pipeline/ipu3/imgu.cpp @@ -95,12 +95,11 @@ int ImgUDevice::init(MediaDevice *media, unsigned int index) /** * \brief Configure the ImgU unit input - * \param[in] size The ImgU input frame size + * \param[in] pipe The ImgU pipe configuration * \param[in] inputFormat The format to be applied to ImgU input * \return 0 on success or a negative error code otherwise */ -int ImgUDevice::configureInput(const Size &size, - V4L2DeviceFormat *inputFormat) +int ImgUDevice::configureInput(struct Pipe *pipe, V4L2DeviceFormat *inputFormat) { /* Configure the ImgU input video device with the requested sizes. */ int ret = input_->setFormat(inputFormat); @@ -122,8 +121,8 @@ int ImgUDevice::configureInput(const Size &size, Rectangle rect = { .x = 0, .y = 0, - .width = inputFormat->size.width, - .height = inputFormat->size.height, + .width = pipe->input.width, + .height = pipe->input.height, }; ret = imgu_->setSelection(PAD_INPUT, V4L2_SEL_TGT_CROP, &rect); if (ret) @@ -138,7 +137,7 @@ int ImgUDevice::configureInput(const Size &size, V4L2SubdeviceFormat imguFormat = {}; imguFormat.mbus_code = MEDIA_BUS_FMT_FIXED; - imguFormat.size = size; + imguFormat.size = pipe->input; ret = imgu_->setFormat(PAD_INPUT, &imguFormat); if (ret) diff --git a/src/libcamera/pipeline/ipu3/imgu.h b/src/libcamera/pipeline/ipu3/imgu.h index 8fb271fb8350..c0353955ea43 100644 --- a/src/libcamera/pipeline/ipu3/imgu.h +++ b/src/libcamera/pipeline/ipu3/imgu.h @@ -31,7 +31,7 @@ public: int init(MediaDevice *media, unsigned int index); - int configureInput(const Size &size, V4L2DeviceFormat *inputFormat); + int configureInput(struct Pipe *pipe, V4L2DeviceFormat *inputFormat); int configureOutput(const StreamConfiguration &cfg, V4L2DeviceFormat *outputFormat) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 16bda97a3cc3..9499c127ef79 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -396,32 +396,26 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) outCount++; } - /* - * Configure the CIO2 unit with the format computed during validation - * and apply the same format to the ImgU input. - */ + /* Configure the CIO2 unit with the format computed during validation. */ const Size &sensorSize = config->cio2Format().size; V4L2DeviceFormat cio2Format = {}; ret = data->cio2_.configure(sensorSize, &cio2Format); if (ret) return ret; - ret = imgu->configureInput(sensorSize, &cio2Format); - if (ret) - return ret; + /* + * Collect the input, output and viewfinder sizes to configure the + * ImgU pipe and assign streams to configurations while iterating them. + */ + ImgUDevice::Pipe imguPipe{}; + imguPipe.input.width = cio2Format.size.width; + imguPipe.input.height = cio2Format.size.height; - /* Apply the format to the configured streams output devices. */ - bool outActive = false; - bool vfActive = false; for (unsigned int i = 0; i < config->size(); ++i) { StreamConfiguration &cfg = (*config)[i]; const PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat); if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) { - /* - * The RAW stream is configured as part of the CIO2 and - * no configuration is needed for the ImgU. - */ cfg.setStream(&data->rawStream_); cfg.stride = cio2Format.planes[0].bpl; @@ -437,13 +431,9 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) * requested. */ if (cfg.size == maxOut && outCount > 1) { - ret = imgu->configureOutput(cfg, &outputFormat); - if (ret) - return ret; - - cfg.stride = outputFormat.planes[0].bpl; cfg.setStream(&data->outStream_); - outActive = true; + imguPipe.output.width = cfg.size.width; + imguPipe.output.height = cfg.size.height; LOG(IPU3, Debug) << "Assigned " << cfg.toString() << " to the main output"; @@ -457,18 +447,56 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) * the smaller one to reduce the cropping required (if any) on * the main output. */ - ret = imgu->configureViewfinder(cfg, &outputFormat); - if (ret) - return ret; - - cfg.stride = outputFormat.planes[0].bpl; cfg.setStream(&data->vfStream_); - vfActive = true; + imguPipe.viewfinder.width = cfg.size.width; + imguPipe.viewfinder.height = cfg.size.height; LOG(IPU3, Debug) << "Assigned " << cfg.toString() << " to the viewfinder output"; } + /* + * Configure the ImgU with the collected pipe configuration and the + * CIO2 unit format. + */ + ret = imgu->configureInput(&imguPipe, &cio2Format); + if (ret) + return ret; + + /* Apply the format to the ImgU output devices. */ + bool outActive = false; + bool vfActive = false; + for (unsigned int i = 0; i < config->size(); ++i) { + StreamConfiguration &cfg = (*config)[i]; + Stream *stream = cfg.stream(); + + if (stream == &data->rawStream_) { + /* + * The RAW stream is configured as part of the CIO2 and + * no configuration is needed for the ImgU. + */ + continue; + } + + if (stream == &data->outStream_) { + ret = imgu->configureOutput(cfg, &outputFormat); + if (ret) + return ret; + + outActive = true; + cfg.stride = outputFormat.planes[0].bpl; + } + + if (stream == &data->vfStream_) { + ret = imgu->configureViewfinder(cfg, &outputFormat); + if (ret) + return ret; + + vfActive = true; + cfg.stride = outputFormat.planes[0].bpl; + } + } + /* * As we need to set format also on the non-active streams, use * the configuration of the active one for that purpose (there should From patchwork Wed Jul 1 12:30:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8541 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id B3A0FC2E6B for ; Wed, 1 Jul 2020 12:27:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8B9A460D4C; Wed, 1 Jul 2020 14:27:29 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2295C60CE8 for ; Wed, 1 Jul 2020 14:27:27 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id B69881C000F; Wed, 1 Jul 2020 12:27:26 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Jul 2020 14:30:35 +0200 Message-Id: <20200701123036.51922-15-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701123036.51922-1-jacopo@jmondi.org> References: <20200701123036.51922-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 14/15] libcamera: ipu3: Rename ImgUDevice::configureInput() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Rename the ImgUDevice::configureInput() method to just configure() as it will be modified not only configure the ImgU unit input, but calculate the whole pipeline configuration parameters. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/pipeline/ipu3/imgu.cpp | 2 +- src/libcamera/pipeline/ipu3/imgu.h | 2 +- src/libcamera/pipeline/ipu3/ipu3.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp index 49201157eb07..f580c1d2ff6c 100644 --- a/src/libcamera/pipeline/ipu3/imgu.cpp +++ b/src/libcamera/pipeline/ipu3/imgu.cpp @@ -99,7 +99,7 @@ int ImgUDevice::init(MediaDevice *media, unsigned int index) * \param[in] inputFormat The format to be applied to ImgU input * \return 0 on success or a negative error code otherwise */ -int ImgUDevice::configureInput(struct Pipe *pipe, V4L2DeviceFormat *inputFormat) +int ImgUDevice::configure(struct Pipe *pipe, V4L2DeviceFormat *inputFormat) { /* Configure the ImgU input video device with the requested sizes. */ int ret = input_->setFormat(inputFormat); diff --git a/src/libcamera/pipeline/ipu3/imgu.h b/src/libcamera/pipeline/ipu3/imgu.h index c0353955ea43..45c5cc1ce8e6 100644 --- a/src/libcamera/pipeline/ipu3/imgu.h +++ b/src/libcamera/pipeline/ipu3/imgu.h @@ -31,7 +31,7 @@ public: int init(MediaDevice *media, unsigned int index); - int configureInput(struct Pipe *pipe, V4L2DeviceFormat *inputFormat); + int configure(struct Pipe *pipe, V4L2DeviceFormat *inputFormat); int configureOutput(const StreamConfiguration &cfg, V4L2DeviceFormat *outputFormat) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 9499c127ef79..317e78155ebb 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -459,7 +459,7 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) * Configure the ImgU with the collected pipe configuration and the * CIO2 unit format. */ - ret = imgu->configureInput(&imguPipe, &cio2Format); + ret = imgu->configure(&imguPipe, &cio2Format); if (ret) return ret; From patchwork Wed Jul 1 12:30:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8542 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id D864DC2E6C for ; Wed, 1 Jul 2020 12:27:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ABE4060D50; Wed, 1 Jul 2020 14:27:29 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AB5C160C5C for ; Wed, 1 Jul 2020 14:27:27 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 4BDDB1C0007; Wed, 1 Jul 2020 12:27:27 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Jul 2020 14:30:36 +0200 Message-Id: <20200701123036.51922-16-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701123036.51922-1-jacopo@jmondi.org> References: <20200701123036.51922-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 15/15] libcamera: ipu3: Pass cio2 fourcc to ImgUDevice::configure() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Only the CIO2 4cc code is required for ImgUDevice::configure(), as the input frame sizes are now reported through the ImgUDevice::Pipe structure. Add the CIO2 pixel format to ImguDevice::Pipe instead of passing the whole CIO2 V4L2DeviceFormat to ImgUDevice::configure(). Signed-off-by: Jacopo Mondi --- src/libcamera/pipeline/ipu3/imgu.cpp | 19 ++++++++++++++----- src/libcamera/pipeline/ipu3/imgu.h | 3 ++- src/libcamera/pipeline/ipu3/ipu3.cpp | 3 ++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp index f580c1d2ff6c..59e63644d22f 100644 --- a/src/libcamera/pipeline/ipu3/imgu.cpp +++ b/src/libcamera/pipeline/ipu3/imgu.cpp @@ -26,11 +26,16 @@ LOG_DECLARE_CATEGORY(IPU3) * The ImgU unit processes images through several components, which have * to be properly configured inspecting the input image size and the desired * output sizes. This structure collects the ImgU input configuration and the - * requested main output and viewfinder configurations. + * requested main output and viewfinder configurations, along with the + * pixel format to be applied to the ImgU input, which is the same as the + * one used by the CIO2 unit. * * \var Pipe::input * \brief The input image size * + * \var Pipe::cio2Fourcc + * \brief The CIO2 pixel format to be applied to ImgU input + * * \var Pipe::output * \brief The requested main output size * @@ -96,17 +101,21 @@ int ImgUDevice::init(MediaDevice *media, unsigned int index) /** * \brief Configure the ImgU unit input * \param[in] pipe The ImgU pipe configuration - * \param[in] inputFormat The format to be applied to ImgU input * \return 0 on success or a negative error code otherwise */ -int ImgUDevice::configure(struct Pipe *pipe, V4L2DeviceFormat *inputFormat) +int ImgUDevice::configure(struct Pipe *pipe) { /* Configure the ImgU input video device with the requested sizes. */ - int ret = input_->setFormat(inputFormat); + V4L2DeviceFormat inputFormat = { + .fourcc = pipe->cio2Fourcc, + .size = pipe->input, + .planesCount = 1, + }; + int ret = input_->setFormat(&inputFormat); if (ret) return ret; - LOG(IPU3, Debug) << "ImgU input format = " << inputFormat->toString(); + LOG(IPU3, Debug) << "ImgU input format = " << inputFormat.toString(); /* * \todo The IPU3 driver implementation shall be changed to use the diff --git a/src/libcamera/pipeline/ipu3/imgu.h b/src/libcamera/pipeline/ipu3/imgu.h index 45c5cc1ce8e6..b0ed228756c7 100644 --- a/src/libcamera/pipeline/ipu3/imgu.h +++ b/src/libcamera/pipeline/ipu3/imgu.h @@ -25,13 +25,14 @@ class ImgUDevice public: struct Pipe { Size input; + V4L2PixelFormat cio2Fourcc; Size output; Size viewfinder; }; int init(MediaDevice *media, unsigned int index); - int configure(struct Pipe *pipe, V4L2DeviceFormat *inputFormat); + int configure(struct Pipe *pipe); int configureOutput(const StreamConfiguration &cfg, V4L2DeviceFormat *outputFormat) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 317e78155ebb..79ec492341b2 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -410,6 +410,7 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) ImgUDevice::Pipe imguPipe{}; imguPipe.input.width = cio2Format.size.width; imguPipe.input.height = cio2Format.size.height; + imguPipe.cio2Fourcc = cio2Format.fourcc; for (unsigned int i = 0; i < config->size(); ++i) { StreamConfiguration &cfg = (*config)[i]; @@ -459,7 +460,7 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) * Configure the ImgU with the collected pipe configuration and the * CIO2 unit format. */ - ret = imgu->configure(&imguPipe, &cio2Format); + ret = imgu->configure(&imguPipe); if (ret) return ret;