From patchwork Mon Oct 11 15:11:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 14090 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 EEA85C323E for ; Mon, 11 Oct 2021 15:11:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 82F9E68F52; Mon, 11 Oct 2021 17:11:19 +0200 (CEST) Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3945568F4B for ; Mon, 11 Oct 2021 17:11:16 +0200 (CEST) Received: (Authenticated sender: jacopo@jmondi.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 2A974E000F; Mon, 11 Oct 2021 15:11:14 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 11 Oct 2021 17:11:44 +0200 Message-Id: <20211011151154.72856-7-jacopo@jmondi.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211011151154.72856-1-jacopo@jmondi.org> References: <20211011151154.72856-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 06/16] android: capabilities: Collect per-stream frame durations 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" Collect the per-stream frame durations while building the list of supported stream formats and resolutions. In order to get an updated list of controls it is necessary to apply to the Camera the configuration we're testing, which was so far only validated. The per-configuration durations will be used to populate the Android ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS static metadata. Signed-off-by: Jacopo Mondi Reviewed-by: Paul Elder Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart --- src/android/camera_capabilities.cpp | 39 ++++++++++++++++++++++++++--- src/android/camera_capabilities.h | 2 ++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/android/camera_capabilities.cpp b/src/android/camera_capabilities.cpp index 87a6e1c6f264..cfe0a1ad93e6 100644 --- a/src/android/camera_capabilities.cpp +++ b/src/android/camera_capabilities.cpp @@ -608,7 +608,32 @@ int CameraCapabilities::initializeStreamConfigurations() } for (const Size &res : resolutions) { - streamConfigurations_.push_back({ res, androidFormat }); + /* + * Configure the Camera with the collected format and + * resolution to get an updated list of controls. + * + * \todo Avoid the need to configure the camera when + * redesigning the configuration API. + */ + cfg.size = res; + int ret = camera_->configure(cameraConfig.get()); + if (ret) + return ret; + + const ControlInfoMap &controls = camera_->controls(); + const auto frameDurations = controls.find( + &controls::FrameDurationLimits); + if (frameDurations == controls.end()) { + LOG(HAL, Error) + << "Camera does not report frame durations"; + return -EINVAL; + } + + int64_t minFrameDuration = frameDurations->second.min().get() * 1000; + int64_t maxFrameDuration = frameDurations->second.max().get() * 1000; + streamConfigurations_.push_back({ + res, androidFormat, minFrameDuration, maxFrameDuration, + }); /* * If the format is HAL_PIXEL_FORMAT_YCbCr_420_888 @@ -620,10 +645,18 @@ int CameraCapabilities::initializeStreamConfigurations() * * \todo Support JPEG streams produced by the camera * natively. + * + * \todo HAL_PIXEL_FORMAT_BLOB is a 'stalling' format, + * its duration should take into account the time + * required for the YUV to JPEG encoding. For now + * use the same frame durations as collected for + * the YUV/RGB streams. */ if (androidFormat == HAL_PIXEL_FORMAT_YCbCr_420_888) { - streamConfigurations_.push_back( - { res, HAL_PIXEL_FORMAT_BLOB }); + streamConfigurations_.push_back({ + res, HAL_PIXEL_FORMAT_BLOB, + minFrameDuration, maxFrameDuration, + }); maxJpegSize = std::max(maxJpegSize, res); } } diff --git a/src/android/camera_capabilities.h b/src/android/camera_capabilities.h index a12596993ee5..6e55ddab445e 100644 --- a/src/android/camera_capabilities.h +++ b/src/android/camera_capabilities.h @@ -43,6 +43,8 @@ private: struct Camera3StreamConfiguration { libcamera::Size resolution; int androidFormat; + int64_t minFrameDurationNsec; + int64_t maxFrameDurationNsec; }; bool validateManualSensorCapability();