From patchwork Mon Jul 24 09:59:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 18874 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 32440C324E for ; Mon, 24 Jul 2023 09:59:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7EBC5628C5; Mon, 24 Jul 2023 11:59:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1690192781; bh=9Kta1lfznw4qKHx0EmPOtWEqvppqoOB+TGqdiXb7qpA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=E+nh7xIP6qy0H25TTvzyFl7DFzF6DYNlzhKYvLFIusEpSvUjEQ+fhOE63ukg8xu/S +LSfL3NfWw6zzTUtLljfSixf7FP51S3jbpG/I+X4mZKIyjYsDP+2RW1L7HDO1MX1LU s5LA5RscoD3l7jt5VgVevX1DUBZI0apzDJh9Esbbtl8U3DvmyqidempVeQapfhLWgJ 4I1lQFpL+eVViw0weVEEyNUFb0sHszbjRrheUnifV/cN/MJkxeObMPa4wFf7RyikAV lxEwBOoNqfS9l8Seiz0IFy0xEr/g7urU6rGleJQ5CX2xMwahTU9ZmievdBsytCadEm BRLB/bhYz6ing== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 03BFF60387 for ; Mon, 24 Jul 2023 11:59:39 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BC84txmz"; dkim-atps=neutral Received: from uno.localdomain (mob-5-91-20-233.net.vodafone.it [5.91.20.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 14089127D; Mon, 24 Jul 2023 11:58:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1690192721; bh=9Kta1lfznw4qKHx0EmPOtWEqvppqoOB+TGqdiXb7qpA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BC84txmzKur1Yw8n3jHM/cApE1+wXMzcnRPphHpqRqKQLdzMqRobg79hjDoTjCVIp CCxXuyTM7+zjbwZvUxsyV59Bl7Wu9CaCbE2RgwmErahSaoE9Wy4ltG9ZDK3teotiVg nCFxcqeBRXxyykQyPEbFojy1Xjbv3NTweKQL4y+Q= To: libcamera-devel@lists.libcamera.org Date: Mon, 24 Jul 2023 11:59:23 +0200 Message-Id: <20230724095925.20877-2-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230724095925.20877-1-jacopo.mondi@ideasonboard.com> References: <20230724095925.20877-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/3] libcamera: rpi: pipeline_base: Remove populateSensorFormats() 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: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" populateSensorFormats() is a static helper that is called from a single place and performs a simple loop over the sensor camera formats. Remove it and in-line it in the caller to remove one static helper from the pipeline_base.cpp file. Signed-off-by: Jacopo Mondi Reviewed-by: Naushir Patuck Reviewed-by: Kieran Bingham --- .../pipeline/rpi/common/pipeline_base.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 179a5b81a516..fb3756a47590 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -66,16 +66,6 @@ PixelFormat mbusCodeToPixelFormat(unsigned int mbus_code, return pix; } -SensorFormats populateSensorFormats(std::unique_ptr &sensor) -{ - SensorFormats formats; - - for (auto const mbusCode : sensor->mbusCodes()) - formats.emplace(mbusCode, sensor->sizes(mbusCode)); - - return formats; -} - bool isMonoSensor(std::unique_ptr &sensor) { unsigned int mbusCode = sensor->mbusCodes()[0]; @@ -804,7 +794,10 @@ int PipelineHandlerBase::registerCamera(std::unique_ptr &camera if (data->sensor_->init()) return -EINVAL; - data->sensorFormats_ = populateSensorFormats(data->sensor_); + /* Populate the map of sensor supported formats and sizes. */ + for (auto const mbusCode : data->sensor_->mbusCodes()) + data->sensorFormats_.emplace(mbusCode, + data->sensor_->sizes(mbusCode)); /* * Enumerate all the Video Mux/Bridge devices across the sensor -> Fr From patchwork Mon Jul 24 09:59:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 18875 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 4C018BDC71 for ; Mon, 24 Jul 2023 09:59:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0BEC3628C1; Mon, 24 Jul 2023 11:59:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1690192783; bh=BJgz2A0FbhIgFokyI5u9AQHq3W92s4WU+W3DdmM1Dg0=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=dCu2YrrYiC6rRToA37q16wH3hxsm09allQYHz7jh89Nh6uVcy5C5iH/s01W//dMK+ gBo82BDuwkzRD9qzWcdYSwB9tZEbR2Rx8GdgyGYGeRx2mOcIJXqLipZdbaDwZ0wK1o S1Vc5b8pf/eIeAWpoNMszYCeZdALVzpIElb5xVBMJgBZgJxRuLrlLhOC3nz4bWPR9U YtOLDNqFaAfuSjy/+Bm/bRWUn9ALGC/W4RIRdT4kZk1iIWIip5MAHg5sX05ddp3q2Q 9+c/qLL5MtbmkyJp+UA0taKUnaZM4tJ1hNP/09t4rt58xw+61+yrK+jzI6mh4iiycI UtrqmyWSf1p/Q== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ADFED628C2 for ; Mon, 24 Jul 2023 11:59:39 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="hpWJninX"; dkim-atps=neutral Received: from uno.localdomain (mob-5-91-20-233.net.vodafone.it [5.91.20.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F23DF735; Mon, 24 Jul 2023 11:58:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1690192722; bh=BJgz2A0FbhIgFokyI5u9AQHq3W92s4WU+W3DdmM1Dg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hpWJninX2nbtxF1WzOv0Hc+mC/Rbr1pkdu18vyL8IdknulXz4p4tDDJLKexWeATHZ oYBKYZj0rMMlpR50aErv+BvWQi/WPehduAIZfZcyAd1Zf7J6a2tebpu86E07wz1ik7 jyLIIVQv9IJQtUWbBUldo/z5Fvjaaf7egMPerqVc= To: libcamera-devel@lists.libcamera.org Date: Mon, 24 Jul 2023 11:59:24 +0200 Message-Id: <20230724095925.20877-3-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230724095925.20877-1-jacopo.mondi@ideasonboard.com> References: <20230724095925.20877-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/3] libcamera: rpi: pipeline_base: Move findBestFormat to CameraData 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: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The findBestFormat() helper operates on the list of sensor formats, which is owned by the CameraData class. Move the function to that class as well to: 1) Avoid passing the list of formats to the function 2) Remove a static helper in favour of a class function 3) Allow subclasses with access to CameraData to call the function Move to the CameraData class the scoreFormat helper as well. Signed-off-by: Jacopo Mondi Reviewed-by: Naushir Patuck --- .../pipeline/rpi/common/pipeline_base.cpp | 127 +++++++++--------- .../pipeline/rpi/common/pipeline_base.h | 3 + 2 files changed, 67 insertions(+), 63 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index fb3756a47590..d794e9fc429f 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -74,63 +74,6 @@ bool isMonoSensor(std::unique_ptr &sensor) return bayer.order == BayerFormat::Order::MONO; } -double scoreFormat(double desired, double actual) -{ - double score = desired - actual; - /* Smaller desired dimensions are preferred. */ - if (score < 0.0) - score = (-score) / 8; - /* Penalise non-exact matches. */ - if (actual != desired) - score *= 2; - - return score; -} - -V4L2SubdeviceFormat findBestFormat(const SensorFormats &formatsMap, const Size &req, unsigned int bitDepth) -{ - double bestScore = std::numeric_limits::max(), score; - V4L2SubdeviceFormat bestFormat; - bestFormat.colorSpace = ColorSpace::Raw; - - constexpr float penaltyAr = 1500.0; - constexpr float penaltyBitDepth = 500.0; - - /* Calculate the closest/best mode from the user requested size. */ - for (const auto &iter : formatsMap) { - const unsigned int mbusCode = iter.first; - const PixelFormat format = mbusCodeToPixelFormat(mbusCode, - BayerFormat::Packing::None); - const PixelFormatInfo &info = PixelFormatInfo::info(format); - - for (const Size &size : iter.second) { - double reqAr = static_cast(req.width) / req.height; - double fmtAr = static_cast(size.width) / size.height; - - /* Score the dimensions for closeness. */ - score = scoreFormat(req.width, size.width); - score += scoreFormat(req.height, size.height); - score += penaltyAr * scoreFormat(reqAr, fmtAr); - - /* Add any penalties... this is not an exact science! */ - score += utils::abs_diff(info.bitsPerPixel, bitDepth) * penaltyBitDepth; - - if (score <= bestScore) { - bestScore = score; - bestFormat.mbus_code = mbusCode; - bestFormat.size = size; - } - - LOG(RPI, Debug) << "Format: " << size - << " fmt " << format - << " Score: " << score - << " (best " << bestScore << ")"; - } - } - - return bestFormat; -} - const std::vector validColorSpaces = { ColorSpace::Sycc, ColorSpace::Smpte170m, @@ -276,7 +219,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() const PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat); unsigned int bitDepth = info.isValid() ? info.bitsPerPixel : defaultRawBitDepth; - V4L2SubdeviceFormat sensorFormat = findBestFormat(data_->sensorFormats_, cfg.size, bitDepth); + V4L2SubdeviceFormat sensorFormat = data_->findBestFormat(cfg.size, bitDepth); BayerFormat::Packing packing = BayerFormat::fromPixelFormat(cfg.pixelFormat).packing; rawFormat = PipelineHandlerBase::toV4L2DeviceFormat(raw.dev, sensorFormat, packing); @@ -391,7 +334,7 @@ PipelineHandlerBase::generateConfiguration(Camera *camera, SpansensorFormats_, size, defaultRawBitDepth); + sensorFormat = data->findBestFormat(size, defaultRawBitDepth); pixelFormat = mbusCodeToPixelFormat(sensorFormat.mbus_code, BayerFormat::Packing::CSI2); ASSERT(pixelFormat.isValid()); @@ -531,10 +474,11 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) bitDepth = bayerFormat.bitDepth; } - V4L2SubdeviceFormat sensorFormat = findBestFormat(data->sensorFormats_, - rawStreams.empty() ? ispStreams[0].cfg->size - : rawStreams[0].cfg->size, - bitDepth); + V4L2SubdeviceFormat sensorFormat = + data->findBestFormat(rawStreams.empty() ? ispStreams[0].cfg->size + : rawStreams[0].cfg->size, + bitDepth); + /* Apply any cached transform. */ const RPiCameraConfiguration *rpiConfig = static_cast(config); @@ -954,6 +898,63 @@ int PipelineHandlerBase::queueAllBuffers(Camera *camera) return 0; } +double CameraData::scoreFormat(double desired, double actual) const +{ + double score = desired - actual; + /* Smaller desired dimensions are preferred. */ + if (score < 0.0) + score = (-score) / 8; + /* Penalise non-exact matches. */ + if (actual != desired) + score *= 2; + + return score; +} + +V4L2SubdeviceFormat CameraData::findBestFormat(const Size &req, unsigned int bitDepth) const +{ + double bestScore = std::numeric_limits::max(), score; + V4L2SubdeviceFormat bestFormat; + bestFormat.colorSpace = ColorSpace::Raw; + + constexpr float penaltyAr = 1500.0; + constexpr float penaltyBitDepth = 500.0; + + /* Calculate the closest/best mode from the user requested size. */ + for (const auto &iter : sensorFormats_) { + const unsigned int mbusCode = iter.first; + const PixelFormat format = mbusCodeToPixelFormat(mbusCode, + BayerFormat::Packing::None); + const PixelFormatInfo &info = PixelFormatInfo::info(format); + + for (const Size &size : iter.second) { + double reqAr = static_cast(req.width) / req.height; + double fmtAr = static_cast(size.width) / size.height; + + /* Score the dimensions for closeness. */ + score = scoreFormat(req.width, size.width); + score += scoreFormat(req.height, size.height); + score += penaltyAr * scoreFormat(reqAr, fmtAr); + + /* Add any penalties... this is not an exact science! */ + score += utils::abs_diff(info.bitsPerPixel, bitDepth) * penaltyBitDepth; + + if (score <= bestScore) { + bestScore = score; + bestFormat.mbus_code = mbusCode; + bestFormat.size = size; + } + + LOG(RPI, Debug) << "Format: " << size + << " fmt " << format + << " Score: " << score + << " (best " << bestScore << ")"; + } + } + + return bestFormat; +} + void CameraData::freeBuffers() { if (ipa_) { diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index f648e81054bb..2eda3cd89812 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -81,6 +81,9 @@ public: virtual void platformStart() = 0; virtual void platformStop() = 0; + double scoreFormat(double desired, double actual) const; + V4L2SubdeviceFormat findBestFormat(const Size &req, unsigned int bitDepth) const; + void freeBuffers(); virtual void platformFreeBuffers() = 0; From patchwork Mon Jul 24 09:59:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 18876 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 9E15FC32AA for ; Mon, 24 Jul 2023 09:59:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 936DA628CC; Mon, 24 Jul 2023 11:59:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1690192783; bh=29iHnH9c9w7smKo5V0ntKFuWaUJ8AL/0yKn0ydo8CNY=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=vEj3AFgJWlX+1pf6PfyUhkUVl4Y98F+k6k/HJ/lmFCUguVuDYZfkU7S9JcIe0xWXI /q+1+1Z/q8GqA1EVLOYjQjwbGNLGi/UhDJjUggZfW4xKlhkljVUBm0Mrn56UfImChL 7gB4RrexhEqLtEeQejpzj5yx30qdsfENe9zLrgOc5isciylPDLyvRAKddwkIiUiPET LPKlniKAKg+TJcfvvdlCc3Vuw1/j8J4JRQkH5Y/M0fXNc0oh8SsXwhKtsX8mGAxBzt QFZ00mrmYZdFT2Wgz6qFFdCcRrcprbK3UJWK8uwJHaVbGovxx7Xvi06gQrVaefT8VH sPRWH3V9tkndg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 45234628C2 for ; Mon, 24 Jul 2023 11:59:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="VSNhxVCK"; dkim-atps=neutral Received: from uno.localdomain (mob-5-91-20-233.net.vodafone.it [5.91.20.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8C2CE12B1; Mon, 24 Jul 2023 11:58:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1690192722; bh=29iHnH9c9w7smKo5V0ntKFuWaUJ8AL/0yKn0ydo8CNY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VSNhxVCKhN2sWnuHJqlgbAc2l1RwQWxEP98hlkRYaBk5QvbXye5R4g2bBPWC74YAa OE8SALLtfi6IN7nqURcwPtiGhxFgXeUi4m91EmA4NYlc3FTpj1BP1TskImEtT11oyv 3cOPKBfYhimaL4bFkUsOCR67M1+ucseK15QurY/w= To: libcamera-devel@lists.libcamera.org Date: Mon, 24 Jul 2023 11:59:25 +0200 Message-Id: <20230724095925.20877-4-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230724095925.20877-1-jacopo.mondi@ideasonboard.com> References: <20230724095925.20877-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 3/3] libcamera: rpi: pipeline_base: Cache sensor format 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: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The format to be applied on the sensor is selected by two criteria: the desired output size and the bit depth. As the selection depends on the presence of a RAW stream and the streams configuration is handled in validate() there is no need to re-compute the format in configure(). Centralize the computation of the sensor format in validate() and remove it from configure(). Signed-off-by: Jacopo Mondi Reviewed-by: Naushir Patuck --- .../pipeline/rpi/common/pipeline_base.cpp | 52 +++++++++---------- .../pipeline/rpi/common/pipeline_base.h | 2 + 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index d794e9fc429f..e0fbeec37fe9 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -207,6 +207,17 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() std::sort(outStreams.begin(), outStreams.end(), [](auto &l, auto &r) { return l.cfg->size > r.cfg->size; }); + /* Compute the sensor configuration. */ + unsigned int bitDepth = defaultRawBitDepth; + if (!rawStreams.empty()) { + BayerFormat bayerFormat = BayerFormat::fromPixelFormat(rawStreams[0].cfg->pixelFormat); + bitDepth = bayerFormat.bitDepth; + } + + sensorFormat_ = data_->findBestFormat(rawStreams.empty() ? outStreams[0].cfg->size + : rawStreams[0].cfg->size, + bitDepth); + /* Do any platform specific fixups. */ status = data_->platformValidate(rawStreams, outStreams); if (status == Invalid) @@ -217,12 +228,8 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() StreamConfiguration &cfg = config_.at(raw.index); V4L2DeviceFormat rawFormat; - const PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat); - unsigned int bitDepth = info.isValid() ? info.bitsPerPixel : defaultRawBitDepth; - V4L2SubdeviceFormat sensorFormat = data_->findBestFormat(cfg.size, bitDepth); - BayerFormat::Packing packing = BayerFormat::fromPixelFormat(cfg.pixelFormat).packing; - rawFormat = PipelineHandlerBase::toV4L2DeviceFormat(raw.dev, sensorFormat, packing); + rawFormat = PipelineHandlerBase::toV4L2DeviceFormat(raw.dev, sensorFormat_, packing); int ret = raw.dev->tryFormat(&rawFormat); if (ret) @@ -442,8 +449,6 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) stream->clearFlags(StreamFlag::External); std::vector rawStreams, ispStreams; - std::optional packing; - unsigned int bitDepth = defaultRawBitDepth; for (unsigned i = 0; i < config->size(); i++) { StreamConfiguration *cfg = &config->at(i); @@ -461,32 +466,23 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) std::sort(ispStreams.begin(), ispStreams.end(), [](auto &l, auto &r) { return l.cfg->size > r.cfg->size; }); - /* - * Calculate the best sensor mode we can use based on the user's request, - * and apply it to the sensor with the cached tranform, if any. - * - * If we have been given a RAW stream, use that size for setting up the sensor. - */ - if (!rawStreams.empty()) { - BayerFormat bayerFormat = BayerFormat::fromPixelFormat(rawStreams[0].cfg->pixelFormat); - /* Replace the user requested packing/bit-depth. */ - packing = bayerFormat.packing; - bitDepth = bayerFormat.bitDepth; - } - - V4L2SubdeviceFormat sensorFormat = - data->findBestFormat(rawStreams.empty() ? ispStreams[0].cfg->size - : rawStreams[0].cfg->size, - bitDepth); + /* Apply the format on the sensor with any cached transform. */ + const RPiCameraConfiguration *rpiConfig = + static_cast(config); + V4L2SubdeviceFormat sensorFormat = rpiConfig->sensorFormat_; - /* Apply any cached transform. */ - const RPiCameraConfiguration *rpiConfig = static_cast(config); - - /* Then apply the format on the sensor. */ ret = data->sensor_->setFormat(&sensorFormat, rpiConfig->combinedTransform_); if (ret) return ret; + /* Use the user requested packing/bit-depth. */ + std::optional packing; + if (!rawStreams.empty()) { + BayerFormat bayerFormat = + BayerFormat::fromPixelFormat(rawStreams[0].cfg->pixelFormat); + packing = bayerFormat.packing; + } + /* * Platform specific internal stream configuration. This also assigns * external streams which get configured below. diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index 2eda3cd89812..a139c98a5a2b 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -262,6 +262,8 @@ public: /* Cache the combinedTransform_ that will be applied to the sensor */ Transform combinedTransform_; + /* The sensor format computed in validate() */ + V4L2SubdeviceFormat sensorFormat_; private: const CameraData *data_;