From patchwork Wed Jul 12 10:55:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18812 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 9B05CBEFBE for ; Wed, 12 Jul 2023 10:55:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 611D9628C5; Wed, 12 Jul 2023 12:55:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1689159319; bh=GbCNopN9pW8LtUqh1yGFB6TheYb7T5Tuyy3vafgL4PE=; 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=OMsNXyzwZBP4h71izVpUQmE5u3V9O8dzPkYAP0N/7yZ+QQwCrk+PksScP1UvEBgR1 UXp4sYMCfRDP68oWpzzC/ysLSximpq9MwcSOgshOHyXCTl5WjK4MqRY0Ub6Mljiluo 14FFLAnU4FqV01Y8Xsp0ex2KlmLTJTrDHIW8bey4sZmf2CFoYDbCkqLcCVK9070mzQ dw42SnmA7kU7A5XOLaqJ01sW8O7K85mf5rXf+Pibf3nLQ5+P0JLU5xGd5RhmAPfk1j jVZZUOQvG+Lzu8AQN0inl77LyyS5u+Mt9v111zP5o1CJ+IC3K9NSiwg81hNft9t8Gu 0NkvXQNg7g8bA== Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 120C8628BC for ; Wed, 12 Jul 2023 12:55:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="ALfh0iSZ"; dkim-atps=neutral Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3fbf1b82dc7so69572365e9.2 for ; Wed, 12 Jul 2023 03:55:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1689159316; x=1691751316; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3I3mQQ7p5w35xVgOx/HdcUcYkY49S25NpmzKkcobU9k=; b=ALfh0iSZU/WGHF7gvWJXhIsMGlKaFH8rXKZowmMPLWEk+G2Vef+Pjr2cmCr+0vQf8d so64oRQOoi2Q5LNt/jxLUaoW3zBsXRqyeGD2sw/3a67D4m04y/qsaBb54+W5vf6BiWSR fh0MSqTnAxvFFupQzE9eZdTbkV7TdMMqNSjpeSsLI0IXU/PP2ViS1CB1elvoPwR5/azn 5iq9yKY/FXw/PP5csH3BWqDaOugHM7/pN+QCBgUIXotZQvLdTE4IL5InWP52BQHigbaY YwmhJH8yTkXLx1UpejTbU0pax2yovhF0XZVenVaIfVx5sY5btSb7+Sy1+sa32XcVuBBA 0zEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689159316; x=1691751316; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3I3mQQ7p5w35xVgOx/HdcUcYkY49S25NpmzKkcobU9k=; b=Ms7psF1D5RIciopSJcAXUVwdWUZael6aKiecb+qtMy9BzfhJNPBGW4PkAE1Wk0yDKS ezPR8wg7V51tIumSW+Xo3eFvIFdiBC4CgKUcxyCqO4UQCvQG6dpPLk/g7Un7TZSNkXNv M4zOZUvyjnC5w6BWWruY+k0tPLuRU0N9dN+khZ4eBBa8FIpzl0edFYb2LmDGYeWr25Y9 iJgOn4410QVtlUYr4STxS9nKBm5Irne/0cu21+uxbzebEO1fLoikZxMecYkgWV+1Brp7 vtYd0mC1olIsbSaz/ewLGLnoFV2KyxMbfmv9Io6GJRri2ChFJ+Q8Jjeow3aTcFDIP+qN FbIg== X-Gm-Message-State: ABy/qLYjZGKd4FcKJ/1P5gSGkrqyf1J0DolHyAuG/Vl4KXm10UdSiGaH g1facTCQAMjtLJo27TqNT/xV3qeCu6qQPU+UHWIaYw== X-Google-Smtp-Source: APBJJlFj5u21CRGoEiRJUGOAlkVefo2HF4ugzBK/yK/7ph6wQ5QShI9zDKaZ3Xx5o6urPwRTVivGHQ== X-Received: by 2002:a1c:750a:0:b0:3fb:c462:1833 with SMTP id o10-20020a1c750a000000b003fbc4621833mr17406998wmc.30.1689159316355; Wed, 12 Jul 2023 03:55:16 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id h14-20020a05600c260e00b003fc05b89e5bsm4729236wma.34.2023.07.12.03.55.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 03:55:16 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 12 Jul 2023 11:55:08 +0100 Message-Id: <20230712105510.14658-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230712105510.14658-1-naush@raspberrypi.com> References: <20230712105510.14658-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 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: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Jacopo Mondi 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 Wed Jul 12 10:55:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18813 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 E21AEC3243 for ; Wed, 12 Jul 2023 10:55:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EFC9C628C0; Wed, 12 Jul 2023 12:55:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1689159320; bh=1sWGanjV4RzWljAseBrrIQv/Co7vS/CBO3bYxB5L+B0=; 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=GPdIVcZFtCh2AH7zNn+fZAGx3hCDYmcrPqYgwd3eJPU3N4kzSrtvDJj66wN/1JXZ4 0zvi1Z3CQ27IZEiQl8LYpkH5wwrdNIwi5geSqV9eec0bfhzZsuM5m2PyZnd6Og0ygd y3XNtzhWCE7oP85rlteXS3dlFdOOrMv166LxX/nfTnFAqrcWzfgzzj+04O/uIV/LNR S46//1/W/YOG9jpZW0YNJSX706KXiG7ucwO9aw7TMw/sNSck22cHTCNI4hWyWkNCJd YzxrU3Fn+UHcvWiUWTh3GeE6i+YzFBvu50lt2ILDaEe+mPXOmSRTY0W89O4eiHXQwM sRM3GT4GLDHqw== Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A4FBC628BF for ; Wed, 12 Jul 2023 12:55:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="DfFHV2DB"; dkim-atps=neutral Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-3fbf1b82dc7so69572455e9.2 for ; Wed, 12 Jul 2023 03:55:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1689159317; x=1691751317; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2uSSj325O/nrrSzfl57V3hKln92+IihZFGi4yGkEac8=; b=DfFHV2DBnJ8tI1kWaocJuS+FFKm31Q4tSpKVI6f66P8qzCNa6rmVlD0ZVnSumTOWMR DV0chxKq15ZPX5xJZ74hQsznFRJNaap4J95trotJjjNWhuRD+jGxdrTcbDzull7n2HF4 LCgRpHnvT/kA/6/khTAJ5fRrMDZ2vW9EOSefU55QXNcVJ7gtsJRp7HlEURPNdEPZkEYm tdfgbGFmy/9F74Tgsok44zvFYH25UuQdAdOiqbT8s9MjIQp/PcqEG2ZvH3sWWzW7Dk2A 2ZaOdOPDIND80Wua9nBCk4YN6uvGvETGFhVIhXYPLDw1e8/K8I7eRTtY3nqwA5P8lkFB lSjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689159317; x=1691751317; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2uSSj325O/nrrSzfl57V3hKln92+IihZFGi4yGkEac8=; b=BYkdSfElbXUmAYq4EwDkLfE94YAjRyjzRVuNcskWD3aq5d1QbEmNngRyVTTDyrfQhT 2JKdy7bu/TjC5h901GByOpybLTNqpfkoDsbSApP2YaK3ATkpnsEq4nvbXKFitKd1LnuQ rFRViJWZkTig5KlUUFnxmHpoAeVOM6g/Kn+L4JMB+fbUmVCt5nnKLs+0zqrkxBN3VxNM Sy4Z2kkgTbdYTvLW82Oq/YZ/xTxFz1JNub+fMq/6he0ITpG3oWcVBxjrsxeHBuIGfF2n ueaDdVrXLEiFNFh4Vxhp6h7ye+kHjVll7iALL0pxvprDWHToQczJFhxhI0iD6LyuTNXt HdCQ== X-Gm-Message-State: ABy/qLby0XOdUrGuegbLR5onrQ90woqEIZDGBhLCiQ68+Je0c2iNGWa9 dcQ+mSJkahrtZM012nzq7BbXd6edEtllv79QMzB1eA== X-Google-Smtp-Source: APBJJlFIbWrnD+bB3UJ0/mMof1q/0bwTldQ3z9WVNuLOf4HecftypdONOEjpamFjiLuXY2A46Q3KrQ== X-Received: by 2002:a05:600c:2902:b0:3f9:b430:199b with SMTP id i2-20020a05600c290200b003f9b430199bmr17202733wmd.15.1689159316999; Wed, 12 Jul 2023 03:55:16 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id h14-20020a05600c260e00b003fc05b89e5bsm4729236wma.34.2023.07.12.03.55.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 03:55:16 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 12 Jul 2023 11:55:09 +0100 Message-Id: <20230712105510.14658-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230712105510.14658-1-naush@raspberrypi.com> References: <20230712105510.14658-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 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: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Jacopo Mondi 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 | 140 ++++++++++-------- .../pipeline/rpi/common/pipeline_base.h | 3 + 2 files changed, 79 insertions(+), 64 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index fb3756a47590..725c1db0d527 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, @@ -265,6 +208,17 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() [](auto &l, auto &r) { return l.cfg->size > r.cfg->size; }); /* Do any platform specific fixups. */ + unsigned int bitDepth = defaultRawBitDepth; + if (!rawStreams.empty()) { + BayerFormat bayerFormat = BayerFormat::fromPixelFormat(rawStreams[0].cfg->pixelFormat); + bitDepth = bayerFormat.bitDepth; + } + + V4L2SubdeviceFormat sensorFormat = + data_->findBestFormat(rawStreams.empty() ? outStreams[0].cfg->size + : rawStreams[0].cfg->size, + bitDepth); + status = data_->platformValidate(rawStreams, outStreams); if (status == Invalid) return Invalid; @@ -275,8 +229,8 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() V4L2DeviceFormat rawFormat; const PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat); - unsigned int bitDepth = info.isValid() ? info.bitsPerPixel : defaultRawBitDepth; - V4L2SubdeviceFormat sensorFormat = findBestFormat(data_->sensorFormats_, cfg.size, bitDepth); + bitDepth = info.isValid() ? info.bitsPerPixel : defaultRawBitDepth; + sensorFormat = data_->findBestFormat(cfg.size, bitDepth); BayerFormat::Packing packing = BayerFormat::fromPixelFormat(cfg.pixelFormat).packing; rawFormat = PipelineHandlerBase::toV4L2DeviceFormat(raw.dev, sensorFormat, packing); @@ -391,7 +345,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 +485,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 +909,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 Wed Jul 12 10:55:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18814 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 9496EC32AA for ; Wed, 12 Jul 2023 10:55:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2AFC9628C7; Wed, 12 Jul 2023 12:55:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1689159321; bh=aHk2zTyENpUWBARItTcIPD+G7T6aEl7gR3EykRwUqm4=; 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=txWKwztZthk50DNfSWa6oOVvbSSiIjrDhNi/w75Z3QQDKlMjNeYIYL7vlFS4fu1MQ vYiI3XBW+8lZ2lCo7rq+nKOMuLpLUsuzL/EzpaS//V//WoqDA/nMHAbP9cFzqH3c9e b5sw0VX9mzAMx4EWsOAlnWuNLmGIHOo9FMqx0B6F11CUmj95qUZhfW7Z6IFqr6f/NI nXTLV/B2//t0C8Nnetzw3sf0p/lMEuQMhRe0RWMLLbNfQEKX0kCb9sM6kJtrjQOv+W ce1WCNTuC6gDQgtfjgnWM8ACJ7XK6CzrA+5DR6KCQSuzm1Yas7NCaf0Q8h5+kxNt99 pGMk5iXeNcGkQ== Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 091EE628BF for ; Wed, 12 Jul 2023 12:55:18 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="gqDv8b4u"; dkim-atps=neutral Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3fbef8ad9bbso73637715e9.0 for ; Wed, 12 Jul 2023 03:55:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1689159317; x=1691751317; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LuE01IzKS/jg841yuDMjBnJW/WQ5GKocPMPeElWrjP4=; b=gqDv8b4uLltOJhc1mHF1Qbgi0Bu86j8+WWvWVSA0swbLVY3LQlIsIYlsbdBKtRdcTN Q09d+3oKnVJLDzUCb2h9NHphmcuPak4drABB2LJZ93YJtzQVSn7z8XoCDlFQVcDKTk0l ufoLF9xHwL78yLeTfxa76pJ7kIc2GlYC4gGSlOpYOLTaGlRj/XD2QcHKatMuW5UpL7tV T6LhZ7rEaCO9dMoFlqbJMI2XXTGayhXV/ofkDnWU5dEg+ibYiPEZ7sgnSZKo7cWCffn4 a68x0CiqPBxkIcXcl8KaXliNu4lqK0WgotzQg6uxLNvBnjKgWNpTTCW7gDCS/ITVHIPO nzcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689159317; x=1691751317; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LuE01IzKS/jg841yuDMjBnJW/WQ5GKocPMPeElWrjP4=; b=Gxchc5FIPC5+tgJw5cdDuOvxqrqW24K6Y5CH0UEifGhjjxx4TmfqS9U75JhWi4gLqV zwcc+DFHcgdabk/9wY2kbQPSCatGmAxyJn7+vQ8mC7NqAzLu3t5hL4wCqnrkGzyjRHQ3 EekjTQNhYRRNkRpklDjNEISnWPvg11xgvhH5Fb2Fg3Es90Yki8K4SqlBhhuGTwn0SYq7 DdY2BI7BYGsG712PwJLgGdT7BbAMVzIJlh+Zpt7w2shhDOSBBprCIDDkzdnaE+fczccz Rh4abKL8392izmDpX/rR9fgeLuzul/YJwob+06SMsgK0XBAm1QN8UFAtk8S3c8BAFGGm jH4Q== X-Gm-Message-State: ABy/qLZWNhE3HFOuD73oFThe6KC/1FzcAb5yKlUm+jUDpRMhLsMMlYmI +jM34qJyH8rZ0LCoAW3tEJ2efsEn1oqCHqKptg3VjQ== X-Google-Smtp-Source: APBJJlHVmNUlVfq66m5bHfOYA/GcJDdgSCf6QLgThXcxonn9YCvOF3dq+bdojgQzDSqlQvf+7jPCXg== X-Received: by 2002:a5d:4c92:0:b0:314:1494:ea01 with SMTP id z18-20020a5d4c92000000b003141494ea01mr18207220wrs.5.1689159317478; Wed, 12 Jul 2023 03:55:17 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id h14-20020a05600c260e00b003fc05b89e5bsm4729236wma.34.2023.07.12.03.55.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 03:55:17 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 12 Jul 2023 11:55:10 +0100 Message-Id: <20230712105510.14658-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230712105510.14658-1-naush@raspberrypi.com> References: <20230712105510.14658-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 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: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Jacopo Mondi 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 | 46 +++++++------------ .../pipeline/rpi/common/pipeline_base.h | 2 + 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 725c1db0d527..d96277a2794e 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -214,10 +214,9 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() bitDepth = bayerFormat.bitDepth; } - V4L2SubdeviceFormat sensorFormat = - data_->findBestFormat(rawStreams.empty() ? outStreams[0].cfg->size - : rawStreams[0].cfg->size, - bitDepth); + sensorFormat_ = data_->findBestFormat(rawStreams.empty() ? outStreams[0].cfg->size + : rawStreams[0].cfg->size, + bitDepth); status = data_->platformValidate(rawStreams, outStreams); if (status == Invalid) @@ -230,10 +229,10 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() const PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat); bitDepth = info.isValid() ? info.bitsPerPixel : defaultRawBitDepth; - sensorFormat = data_->findBestFormat(cfg.size, bitDepth); + V4L2SubdeviceFormat subdevFormat = 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, subdevFormat, packing); int ret = raw.dev->tryFormat(&rawFormat); if (ret) @@ -453,8 +452,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); @@ -472,32 +469,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_;