From patchwork Wed Sep 2 15:22:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9462 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 F169FBE174 for ; Wed, 2 Sep 2020 15:19:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B69C562984; Wed, 2 Sep 2020 17:19:00 +0200 (CEST) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 82A51629A3 for ; Wed, 2 Sep 2020 17:18:58 +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 relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 42DF4240009; Wed, 2 Sep 2020 15:18:57 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Sep 2020 17:22:25 +0200 Message-Id: <20200902152236.69770-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200902152236.69770-1-jacopo@jmondi.org> References: <20200902152236.69770-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 01/12] android: camera_device: Refuse unsupported formats 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: , Cc: tfiga@google.com, hiroh@google.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The current implementation of CameraDevice::initializeStreamConfigurations() fails if an image format marked as mandatory is not supported by the libcamera::Camera device, but erroneously accepts non-mandatory non-supported formats in the list of accepted ones. Fix this by ignoring non supported image formats which are not marked as mandatory. Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Hirokazu Honda --- src/android/camera_device.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 9605b9e9069e..ad0d7fd15d90 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -392,10 +392,16 @@ int CameraDevice::initializeStreamConfigurations() break; } } - if (camera3Format.mandatory && !mappedFormat.isValid()) { - LOG(HAL, Error) << "Failed to map Android format " - << camera3Format.name << " (" - << utils::hex(androidFormat) << ")"; + + if (!mappedFormat.isValid()) { + /* If the format is not mandatory, skip it. */ + if (!camera3Format.mandatory) + continue; + + LOG(HAL, Error) + << "Failed to map mandatory Android format " + << camera3Format.name << " (" + << utils::hex(androidFormat) << "): aborting"; return -EINVAL; } From patchwork Wed Sep 2 15:22:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9463 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 7E27BBE174 for ; Wed, 2 Sep 2020 15:19:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DC8CD629CB; Wed, 2 Sep 2020 17:19:00 +0200 (CEST) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E437862931 for ; Wed, 2 Sep 2020 17:18:59 +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 relay1-d.mail.gandi.net (Postfix) with ESMTPSA id A20CE24000C; Wed, 2 Sep 2020 15:18:58 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Sep 2020 17:22:26 +0200 Message-Id: <20200902152236.69770-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200902152236.69770-1-jacopo@jmondi.org> References: <20200902152236.69770-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 02/12] android: camera_device: Generate JPEG 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: , Cc: tfiga@google.com, hiroh@google.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When producing the list of image resolution to claim as supported by the camera HAL, the JPEG stream was assumed to be 'always valid' as, at the time, there was no JPEG support in place at all. With the introduction of support for JPEG compression, reporting non-valid sizes as supported obviously causes troubles. In order to avoid reporting non-supported resolutions as supported, produce the list of available JPEG sizes by using the ones supported by the YCbCr_420_888 format, from which the JPEG stream is encoded. Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 43 +++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index ad0d7fd15d90..8a8072123961 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -363,17 +363,27 @@ int CameraDevice::initializeStreamConfigurations() const std::vector &libcameraFormats = camera3Format.libcameraFormats; + /* + * Fixed format mapping for JPEG. + * + * The list of supported JPEG resolutions is generated + * from the list of resolutions supported by + * HAL_PIXEL_FORMAT_YCbCr_420_888 from which JPEG is produced. + * + * \todo Wire the JPEG encoder interface to query the list + * of supported resolutions. + */ + if (androidFormat == HAL_PIXEL_FORMAT_BLOB) { + formatsMap_[androidFormat] = formats::MJPEG; + continue; + } + /* * Test the libcamera formats that can produce images * compatible with the format defined by Android. */ PixelFormat mappedFormat; for (const PixelFormat &pixelFormat : libcameraFormats) { - /* \todo Fixed mapping for JPEG. */ - if (androidFormat == HAL_PIXEL_FORMAT_BLOB) { - mappedFormat = formats::MJPEG; - break; - } /* * The stream configuration size can be adjusted, @@ -416,19 +426,22 @@ int CameraDevice::initializeStreamConfigurations() cfg.size = res; CameraConfiguration::Status status = cameraConfig->validate(); - /* - * Unconditionally report we can produce JPEG. - * - * \todo The JPEG stream will be implemented as an - * HAL-only stream, but some cameras can produce it - * directly. As of now, claim support for JPEG without - * inspecting where the JPEG stream is produced. - */ - if (androidFormat != HAL_PIXEL_FORMAT_BLOB && - status != CameraConfiguration::Valid) + if (status != CameraConfiguration::Valid) continue; streamConfigurations_.push_back({ res, androidFormat }); + + /* + * If the format is HAL_PIXEL_FORMAT_YCbCr_420_888 + * from which JPEG is produced, add an entry for + * the JPEG stream. + * + * \todo Wire the JPEG encoder to query the supported + * sizes provided a list of formats it can encode. + */ + if (androidFormat == HAL_PIXEL_FORMAT_YCbCr_420_888) + streamConfigurations_.push_back( + { res, HAL_PIXEL_FORMAT_BLOB }); } } From patchwork Wed Sep 2 15:22:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9464 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 273E0BE174 for ; Wed, 2 Sep 2020 15:19:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 00B44629C7; Wed, 2 Sep 2020 17:19:03 +0200 (CEST) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 759DD60374 for ; Wed, 2 Sep 2020 17:19:01 +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 relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 1ADF5240012; Wed, 2 Sep 2020 15:18:59 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Sep 2020 17:22:27 +0200 Message-Id: <20200902152236.69770-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200902152236.69770-1-jacopo@jmondi.org> References: <20200902152236.69770-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 03/12] android: camera_device: Add debug to stream initialization 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: , Cc: tfiga@google.com, hiroh@google.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add debug printouts to the CameraDevice::initializeStreamConfigurations() function that helps to follow the process of building the stream configurations map. Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Hirokazu Honda --- src/android/camera_device.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 8a8072123961..493d6cecde72 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -363,6 +363,9 @@ int CameraDevice::initializeStreamConfigurations() const std::vector &libcameraFormats = camera3Format.libcameraFormats; + LOG(HAL, Debug) << "Testing Android format: " + << camera3Format.name; + /* * Fixed format mapping for JPEG. * @@ -375,6 +378,10 @@ int CameraDevice::initializeStreamConfigurations() */ if (androidFormat == HAL_PIXEL_FORMAT_BLOB) { formatsMap_[androidFormat] = formats::MJPEG; + LOG(HAL, Debug) << "Mapped Android format: " + << camera3Format.name << " to: " + << formats::MJPEG.toString() + << " (fixed mapping)"; continue; } @@ -385,6 +392,10 @@ int CameraDevice::initializeStreamConfigurations() PixelFormat mappedFormat; for (const PixelFormat &pixelFormat : libcameraFormats) { + LOG(HAL, Debug) << "Testing Android format: " + << camera3Format.name << " with: " + << pixelFormat.toString(); + /* * The stream configuration size can be adjusted, * not the pixel format. @@ -420,14 +431,27 @@ int CameraDevice::initializeStreamConfigurations() * stream configurations map, by testing the image resolutions. */ formatsMap_[androidFormat] = mappedFormat; + LOG(HAL, Debug) << "Mapped Android format: " + << camera3Format.name << " to: " + << mappedFormat.toString(); for (const Size &res : cameraResolutions) { cfg.pixelFormat = mappedFormat; cfg.size = res; + std::stringstream ss; + ss << "Testing (" << res.toString() << ")[" + << mappedFormat.toString() << "]: "; + CameraConfiguration::Status status = cameraConfig->validate(); - if (status != CameraConfiguration::Valid) + if (status != CameraConfiguration::Valid) { + ss << " not supported"; + LOG(HAL, Debug) << ss.str(); continue; + } + + ss << " supported"; + LOG(HAL, Debug) << ss.str(); streamConfigurations_.push_back({ res, androidFormat }); From patchwork Wed Sep 2 15:22:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9465 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 448B4BE174 for ; Wed, 2 Sep 2020 15:19:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1F01262931; Wed, 2 Sep 2020 17:19:04 +0200 (CEST) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C6E4560374 for ; Wed, 2 Sep 2020 17:19:02 +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 relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 9A84A240018; Wed, 2 Sep 2020 15:19:01 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Sep 2020 17:22:28 +0200 Message-Id: <20200902152236.69770-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200902152236.69770-1-jacopo@jmondi.org> References: <20200902152236.69770-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 04/12] android: camera_device: Break out size calculation 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: , Cc: tfiga@google.com, hiroh@google.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" As the RAW stream sizes needs to be calculated differently from the processed one, break out break out the procedure to calculate the processed (RGB/YUV) resolutions from initializeStreamConfigurations() in order to prepare for RAW sizes calculation. Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Hirokazu Honda --- src/android/camera_device.cpp | 55 ++++++++++++++++++++++++----------- src/android/camera_device.h | 5 ++++ 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 493d6cecde72..58b2ad27c5e2 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -283,6 +283,37 @@ int CameraDevice::initialize() return ret; } +std::vector CameraDevice::filterYUVResolutions(CameraConfiguration *cameraConfig, + const PixelFormat &pixelFormat, + const std::vector &resolutions) +{ + std::vector supportedResolutions; + + StreamConfiguration &cfg = cameraConfig->at(0); + for (const Size &res : resolutions) { + cfg.pixelFormat = pixelFormat; + cfg.size = res; + + std::stringstream ss; + ss << "Tested (" << res.toString() << ")[" + << pixelFormat.toString() << "]: "; + + CameraConfiguration::Status status = cameraConfig->validate(); + if (status != CameraConfiguration::Valid) { + ss << " not supported"; + LOG(HAL, Debug) << ss.str(); + continue; + } + + ss << " supported"; + LOG(HAL, Debug) << ss.str(); + + supportedResolutions.push_back(res); + } + + return supportedResolutions; +} + /* * Initialize the format conversion map to translate from Android format * identifier to libcamera pixel formats and fill in the list of supported @@ -435,24 +466,14 @@ int CameraDevice::initializeStreamConfigurations() << camera3Format.name << " to: " << mappedFormat.toString(); - for (const Size &res : cameraResolutions) { - cfg.pixelFormat = mappedFormat; - cfg.size = res; - - std::stringstream ss; - ss << "Testing (" << res.toString() << ")[" - << mappedFormat.toString() << "]: "; - - CameraConfiguration::Status status = cameraConfig->validate(); - if (status != CameraConfiguration::Valid) { - ss << " not supported"; - LOG(HAL, Debug) << ss.str(); - continue; - } - - ss << " supported"; - LOG(HAL, Debug) << ss.str(); + const PixelFormatInfo &info = PixelFormatInfo::info(mappedFormat); + if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) + continue; + std::vector resolutions = filterYUVResolutions(cameraConfig.get(), + mappedFormat, + cameraResolutions); + for (const Size &res : resolutions) { streamConfigurations_.push_back({ res, androidFormat }); /* diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 3934f194f1b5..359a163ebab9 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -93,6 +93,11 @@ private: }; int initializeStreamConfigurations(); + std::vector + filterYUVResolutions(libcamera::CameraConfiguration *cameraConfig, + const libcamera::PixelFormat &pixelFormat, + const std::vector &resolutions); + std::tuple calculateStaticMetadataSize(); libcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer); void notifyShutter(uint32_t frameNumber, uint64_t timestamp); From patchwork Wed Sep 2 15:22: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: 9466 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 62CD8BE174 for ; Wed, 2 Sep 2020 15:19:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 41533629B2; Wed, 2 Sep 2020 17:19:05 +0200 (CEST) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 20F57629B2 for ; Wed, 2 Sep 2020 17:19:04 +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 relay1-d.mail.gandi.net (Postfix) with ESMTPSA id F119E240011; Wed, 2 Sep 2020 15:19:02 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Sep 2020 17:22:29 +0200 Message-Id: <20200902152236.69770-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200902152236.69770-1-jacopo@jmondi.org> References: <20200902152236.69770-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 05/12] android: camera_device: Generate RAW resolutions 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: , Cc: tfiga@google.com, hiroh@google.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The resolutions supported for the RAW formats cannot be tested from a list of known sizes like the processed ones. This is mainly due to the fact RAW streams are produced by capturing frames at the CSI-2 receiver output and their size corresponds to the sensor's native sizes. In order to obtain the RAW frame size generate a temporary CameraConfiguration for the Role::StillCaptureRAW role and inspect the map of StreamFormats returned by the pipeline handler. Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 21 +++++++++++++++++---- src/android/camera_device.h | 2 ++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 58b2ad27c5e2..b110bfe43ece 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -314,6 +314,17 @@ std::vector CameraDevice::filterYUVResolutions(CameraConfiguration *camera return supportedResolutions; } +std::vector CameraDevice::filterRawResolutions(const libcamera::PixelFormat &pixelFormat) +{ + std::unique_ptr cameraConfig = + camera_->generateConfiguration({ StillCaptureRaw }); + StreamConfiguration &cfg = cameraConfig->at(0); + const StreamFormats &formats = cfg.formats(); + std::vector supportedResolutions = formats.sizes(pixelFormat); + + return supportedResolutions; +} + /* * Initialize the format conversion map to translate from Android format * identifier to libcamera pixel formats and fill in the list of supported @@ -466,13 +477,15 @@ int CameraDevice::initializeStreamConfigurations() << camera3Format.name << " to: " << mappedFormat.toString(); + std::vector resolutions; const PixelFormatInfo &info = PixelFormatInfo::info(mappedFormat); if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) - continue; + resolutions = filterRawResolutions(mappedFormat); + else + resolutions = filterYUVResolutions(cameraConfig.get(), + mappedFormat, + cameraResolutions); - std::vector resolutions = filterYUVResolutions(cameraConfig.get(), - mappedFormat, - cameraResolutions); for (const Size &res : resolutions) { streamConfigurations_.push_back({ res, androidFormat }); diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 359a163ebab9..dc0ee664d443 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -97,6 +97,8 @@ private: filterYUVResolutions(libcamera::CameraConfiguration *cameraConfig, const libcamera::PixelFormat &pixelFormat, const std::vector &resolutions); + std::vector + filterRawResolutions(const libcamera::PixelFormat &pixelFormat); std::tuple calculateStaticMetadataSize(); libcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer); From patchwork Wed Sep 2 15:22:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9467 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 850D3BE174 for ; Wed, 2 Sep 2020 15:19:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 631AB62984; Wed, 2 Sep 2020 17:19:06 +0200 (CEST) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 646A9629A3 for ; Wed, 2 Sep 2020 17:19:05 +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 relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 46E3024000F; Wed, 2 Sep 2020 15:19:04 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Sep 2020 17:22:30 +0200 Message-Id: <20200902152236.69770-7-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200902152236.69770-1-jacopo@jmondi.org> References: <20200902152236.69770-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 06/12] libcamera: camera_configuration: Return config index 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: , Cc: tfiga@google.com, hiroh@google.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When adding a new StreamConfiguration to a CameraConfiguration instance it might be useful to know how what is the index of the newly added item to be able to retrieve it later. Return the index of the newly inserted item, which corresponds to the 0-indexed number of items in the CameraConfiguration::config_ vector, from CameraConfiguration::addConfiguration(). Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Acked-by: Laurent Pinchart --- include/libcamera/camera.h | 2 +- src/libcamera/camera.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 272c12c3c473..53c32afa23a5 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -39,7 +39,7 @@ public: virtual ~CameraConfiguration(); - void addConfiguration(const StreamConfiguration &cfg); + int addConfiguration(const StreamConfiguration &cfg); virtual Status validate() = 0; StreamConfiguration &at(unsigned int index); diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 4a9c19c33cfb..9a8923620e24 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -104,10 +104,13 @@ CameraConfiguration::~CameraConfiguration() /** * \brief Add a stream configuration to the camera configuration * \param[in] cfg The stream configuration + * \return The index of the newly added stream configuration */ -void CameraConfiguration::addConfiguration(const StreamConfiguration &cfg) +int CameraConfiguration::addConfiguration(const StreamConfiguration &cfg) { config_.push_back(cfg); + + return config_.size() - 1; } /** From patchwork Wed Sep 2 15:22:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9468 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 A909BBE174 for ; Wed, 2 Sep 2020 15:19:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 87F9062984; Wed, 2 Sep 2020 17:19:08 +0200 (CEST) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9D1E1629A3 for ; Wed, 2 Sep 2020 17:19:06 +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 relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 83814240008; Wed, 2 Sep 2020 15:19:05 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Sep 2020 17:22:31 +0200 Message-Id: <20200902152236.69770-8-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200902152236.69770-1-jacopo@jmondi.org> References: <20200902152236.69770-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 07/12] android: camera_device: Get rid of stream counter 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: , Cc: tfiga@google.com, hiroh@google.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Now that CameraConfiguration::addConfiguration() returns the index of the newly added configuration, there's no need to use a custom counter to keep track of the StreamConfiguration index associated with a CameraStream. Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Acked-by: Laurent Pinchart --- src/android/camera_device.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index b110bfe43ece..ace7f6b17b4a 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1195,12 +1195,6 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) streams_.clear(); streams_.reserve(stream_list->num_streams); - /* - * Track actually created streams, as there may not be a 1:1 mapping of - * camera3 streams to libcamera streams. - */ - unsigned int streamIndex = 0; - /* First handle all non-MJPEG streams. */ for (unsigned int i = 0; i < stream_list->num_streams; ++i) { camera3_stream_t *stream = stream_list->streams[i]; @@ -1230,9 +1224,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) streamConfiguration.size = size; streamConfiguration.pixelFormat = format; - config_->addConfiguration(streamConfiguration); - - streams_[i].index = streamIndex++; + streams_[i].index = config_->addConfiguration(streamConfiguration); } /* Now handle MJPEG streams, adding a new stream if required. */ @@ -1280,8 +1272,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) LOG(HAL, Info) << "Adding " << streamConfiguration.toString() << " for MJPEG support"; - config_->addConfiguration(streamConfiguration); - streams_[i].index = streamIndex++; + streams_[i].index = config_->addConfiguration(streamConfiguration); } } From patchwork Wed Sep 2 15:22:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9469 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 CF15EBE174 for ; Wed, 2 Sep 2020 15:19:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ABFD7629B2; Wed, 2 Sep 2020 17:19:10 +0200 (CEST) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DEAB762931 for ; Wed, 2 Sep 2020 17:19:07 +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 relay1-d.mail.gandi.net (Postfix) with ESMTPSA id B991D240009; Wed, 2 Sep 2020 15:19:06 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Sep 2020 17:22:32 +0200 Message-Id: <20200902152236.69770-9-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200902152236.69770-1-jacopo@jmondi.org> References: <20200902152236.69770-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 08/12] android: camera_device: Use camera3 stream 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: , Cc: tfiga@google.com, hiroh@google.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When iterating the camera3_stream_t received from the Android camera framework to identify the MJPEG streams, the format check was performed on the CameraStream created when iterating the non-MJPEG streams and not on the format actually requested by Android. As the next patches will remove the creation of CameraStream instances for MJPEG streams, use the camera3_stream format to prepare for that. Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index ace7f6b17b4a..7fc61e3e4da7 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1230,9 +1230,10 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) /* Now handle MJPEG streams, adding a new stream if required. */ for (unsigned int i = 0; i < stream_list->num_streams; ++i) { camera3_stream_t *stream = stream_list->streams[i]; + PixelFormat format = toPixelFormat(stream->format); bool match = false; - if (streams_[i].format != formats::MJPEG) + if (format != formats::MJPEG) continue; /* Search for a compatible stream */ From patchwork Wed Sep 2 15:22:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9470 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 06F47BF6D3 for ; Wed, 2 Sep 2020 15:19:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D32D8629E8; Wed, 2 Sep 2020 17:19:10 +0200 (CEST) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 29E8562931 for ; Wed, 2 Sep 2020 17:19:09 +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 relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 0BD73240010; Wed, 2 Sep 2020 15:19:07 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Sep 2020 17:22:33 +0200 Message-Id: <20200902152236.69770-10-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200902152236.69770-1-jacopo@jmondi.org> References: <20200902152236.69770-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 09/12] android: camera_device: Use Android 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: , Cc: tfiga@google.com, hiroh@google.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" We assumed HAL_PIXEL_FORMAT_BLOB is always mapped to libcamera::MJPEG and at the moment this is true. To protect against future changes in the mapping, inspect the Android format instead of the libcamera one. Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 7fc61e3e4da7..3630e87e8814 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1216,7 +1216,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) stream->priv = static_cast(&streams_[i]); /* Defer handling of MJPEG streams until all others are known. */ - if (format == formats::MJPEG) + if (stream->format == HAL_PIXEL_FORMAT_BLOB) continue; StreamConfiguration streamConfiguration; @@ -1230,10 +1230,9 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) /* Now handle MJPEG streams, adding a new stream if required. */ for (unsigned int i = 0; i < stream_list->num_streams; ++i) { camera3_stream_t *stream = stream_list->streams[i]; - PixelFormat format = toPixelFormat(stream->format); bool match = false; - if (format != formats::MJPEG) + if (stream->format != HAL_PIXEL_FORMAT_BLOB) continue; /* Search for a compatible stream */ From patchwork Wed Sep 2 15:22:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9471 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 777E6BE174 for ; Wed, 2 Sep 2020 15:19:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4CD4F629DF; Wed, 2 Sep 2020 17:19:11 +0200 (CEST) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6F5C560374 for ; Wed, 2 Sep 2020 17:19:10 +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 relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 4F635240017; Wed, 2 Sep 2020 15:19:09 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Sep 2020 17:22:34 +0200 Message-Id: <20200902152236.69770-11-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200902152236.69770-1-jacopo@jmondi.org> References: <20200902152236.69770-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 10/12] android: camera_device: Rework CameraStream handling 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: , Cc: tfiga@google.com, hiroh@google.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The CameraDevice::streams_ vector of CameraStream instances is currently mostly accessed by index. The current implementation creates all the CameraStream during the first loop that inspects the camera3_stream instances, and the update the index of the StreamConfiguration associated with the CameraStream during a second loop that inspects MJPEG streams. A third loop creates the JPEG encoder associated with CameraStreams that produce MJPEG format. As the index-based association is hard to follow and rather fragile, rework the creation and handling of CameraStream: 1) Make the StreamConfiguration index a constructor parameter and a private struct member. This disallow the creation of CameraStream without a StreamConfiguration index assigned. 2) Create CameraStream only after the associated StreamConfiguration has been identified. The first loop creates CameraStream for non-JPEG streams, the second for the JPEG ones after having identified the associated StreamConfiguration. Since we have just created the CameraStream, create the JPEG encoder at the same time instead of deferring it. This change removes all accesses by index to the CameraDevice::streams_ vector. No functional changes intended, but this change aims to make the code easier to follow and more robust. Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 75 +++++++++++++++++++---------------- src/android/camera_device.h | 18 +++++---- 2 files changed, 51 insertions(+), 42 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 3630e87e8814..9bcd1d993c17 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -168,8 +168,8 @@ MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer, } } -CameraStream::CameraStream(PixelFormat f, Size s) - : index(-1), format(f), size(s), jpeg(nullptr) +CameraStream::CameraStream(PixelFormat f, Size s, unsigned int i) + : format(f), size(s), jpeg(nullptr), index_(i) { } @@ -1212,30 +1212,28 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) if (!format.isValid()) return -EINVAL; - streams_.emplace_back(format, size); - stream->priv = static_cast(&streams_[i]); - /* Defer handling of MJPEG streams until all others are known. */ if (stream->format == HAL_PIXEL_FORMAT_BLOB) continue; StreamConfiguration streamConfiguration; - streamConfiguration.size = size; streamConfiguration.pixelFormat = format; - streams_[i].index = config_->addConfiguration(streamConfiguration); + unsigned int index = config_->addConfiguration(streamConfiguration); + CameraStream &cameraStream = streams_.emplace_back(format, size, index); + stream->priv = static_cast(&cameraStream); } /* Now handle MJPEG streams, adding a new stream if required. */ for (unsigned int i = 0; i < stream_list->num_streams; ++i) { camera3_stream_t *stream = stream_list->streams[i]; - bool match = false; - if (stream->format != HAL_PIXEL_FORMAT_BLOB) continue; - /* Search for a compatible stream */ + /* Search for a compatible stream in the non-JPEG ones. */ + bool match = false; + unsigned int index; for (unsigned int j = 0; j < config_->size(); j++) { StreamConfiguration &cfg = config_->at(j); @@ -1243,13 +1241,15 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) * \todo The PixelFormat must also be compatible with * the encoder. */ - if (cfg.size == streams_[i].size) { - LOG(HAL, Info) << "Stream " << i - << " using libcamera stream " << j; + if (cfg.size.width != stream->width || + cfg.size.height != stream->height) + continue; - match = true; - streams_[i].index = j; - } + LOG(HAL, Info) << "Stream " << i + << " using libcamera stream " << j; + + index = j; + match = true; } /* @@ -1272,7 +1272,26 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) LOG(HAL, Info) << "Adding " << streamConfiguration.toString() << " for MJPEG support"; - streams_[i].index = config_->addConfiguration(streamConfiguration); + index = config_->addConfiguration(streamConfiguration); + } + + StreamConfiguration &cfg = config_->at(index); + PixelFormat format = formats::MJPEG; + Size size = cfg.size; + + CameraStream &cameraStream = streams_.emplace_back(format, size, index); + stream->priv = static_cast(&cameraStream); + + /* + * Construct a software encoder for MJPEG streams from the + * chosen libcamera source stream. + */ + cameraStream.jpeg = new EncoderLibJpeg(); + int ret = cameraStream.jpeg->configure(cfg); + if (ret) { + LOG(HAL, Error) + << "Failed to configure encoder"; + return ret; } } @@ -1295,25 +1314,11 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) for (unsigned int i = 0; i < stream_list->num_streams; ++i) { camera3_stream_t *stream = stream_list->streams[i]; - CameraStream *cameraStream = &streams_[i]; - StreamConfiguration &cfg = config_->at(cameraStream->index); + CameraStream *cameraStream = static_cast(stream->priv); + StreamConfiguration &cfg = config_->at(cameraStream->index()); /* Use the bufferCount confirmed by the validation process. */ stream->max_buffers = cfg.bufferCount; - - /* - * Construct a software encoder for MJPEG streams from the - * chosen libcamera source stream. - */ - if (cameraStream->format == formats::MJPEG) { - cameraStream->jpeg = new EncoderLibJpeg(); - int ret = cameraStream->jpeg->configure(cfg); - if (ret) { - LOG(HAL, Error) - << "Failed to configure encoder"; - return ret; - } - } } /* @@ -1427,7 +1432,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques } descriptor->frameBuffers.emplace_back(buffer); - StreamConfiguration *streamConfiguration = &config_->at(cameraStream->index); + StreamConfiguration *streamConfiguration = &config_->at(cameraStream->index()); Stream *stream = streamConfiguration->stream(); request->addBuffer(stream, buffer); @@ -1482,7 +1487,7 @@ void CameraDevice::requestComplete(Request *request) continue; } - StreamConfiguration *streamConfiguration = &config_->at(cameraStream->index); + StreamConfiguration *streamConfiguration = &config_->at(cameraStream->index()); Stream *stream = streamConfiguration->stream(); FrameBuffer *buffer = request->findBuffer(stream); if (!buffer) { diff --git a/src/android/camera_device.h b/src/android/camera_device.h index dc0ee664d443..f8f237203ce9 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -28,20 +28,24 @@ class CameraMetadata; struct CameraStream { - CameraStream(libcamera::PixelFormat, libcamera::Size); +public: + CameraStream(libcamera::PixelFormat, libcamera::Size, unsigned int i); ~CameraStream(); - /* - * The index of the libcamera StreamConfiguration as added during - * configureStreams(). A single libcamera Stream may be used to deliver - * one or more streams to the Android framework. - */ - unsigned int index; + unsigned int index() const { return index_; } libcamera::PixelFormat format; libcamera::Size size; Encoder *jpeg; + +private: + /* + * The index of the libcamera StreamConfiguration as added during + * configureStreams(). A single libcamera Stream may be used to deliver + * one or more streams to the Android framework. + */ + unsigned int index_; }; class CameraDevice : protected libcamera::Loggable From patchwork Wed Sep 2 15:22:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9472 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 9F610BE174 for ; Wed, 2 Sep 2020 15:19:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 798FA629C9; Wed, 2 Sep 2020 17:19:13 +0200 (CEST) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C062962931 for ; Wed, 2 Sep 2020 17:19:11 +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 relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 964B0240003; Wed, 2 Sep 2020 15:19:10 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Sep 2020 17:22:35 +0200 Message-Id: <20200902152236.69770-12-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200902152236.69770-1-jacopo@jmondi.org> References: <20200902152236.69770-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 11/12] android: camera_device: Set Encoder at construction 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: , Cc: tfiga@google.com, hiroh@google.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Make the CameraStream Encoder * a private struct member and require its initialization at construction time. This change dis-allow creating a CameraStream and set the Encoder later, which shall not happen now that we create CameraStream once we have all the required information in place. No functional changes intended but this change aims to make the code more robust enforcing a stricter CameraStream interface. Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 23 ++++++++++++----------- src/android/camera_device.h | 7 ++++--- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 9bcd1d993c17..28d8e081eab0 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -168,14 +168,14 @@ MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer, } } -CameraStream::CameraStream(PixelFormat f, Size s, unsigned int i) - : format(f), size(s), jpeg(nullptr), index_(i) +CameraStream::CameraStream(PixelFormat f, Size s, unsigned int i, Encoder *encoder) + : format(f), size(s), index_(i), encoder_(encoder) { } CameraStream::~CameraStream() { - delete jpeg; + delete encoder_; }; /* @@ -1279,20 +1279,21 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) PixelFormat format = formats::MJPEG; Size size = cfg.size; - CameraStream &cameraStream = streams_.emplace_back(format, size, index); - stream->priv = static_cast(&cameraStream); - /* * Construct a software encoder for MJPEG streams from the * chosen libcamera source stream. */ - cameraStream.jpeg = new EncoderLibJpeg(); - int ret = cameraStream.jpeg->configure(cfg); + Encoder *encoder = new EncoderLibJpeg(); + int ret = encoder->configure(cfg); if (ret) { - LOG(HAL, Error) - << "Failed to configure encoder"; + LOG(HAL, Error) << "Failed to configure encoder"; + delete encoder; return ret; } + + CameraStream &cameraStream = streams_.emplace_back(format, size, + index, encoder); + stream->priv = static_cast(&cameraStream); } switch (config_->validate()) { @@ -1481,7 +1482,7 @@ void CameraDevice::requestComplete(Request *request) if (cameraStream->format != formats::MJPEG) continue; - Encoder *encoder = cameraStream->jpeg; + Encoder *encoder = cameraStream->encoder(); if (!encoder) { LOG(HAL, Error) << "Failed to identify encoder"; continue; diff --git a/src/android/camera_device.h b/src/android/camera_device.h index f8f237203ce9..3c57ffec265d 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -29,16 +29,16 @@ class CameraMetadata; struct CameraStream { public: - CameraStream(libcamera::PixelFormat, libcamera::Size, unsigned int i); + CameraStream(libcamera::PixelFormat, libcamera::Size, unsigned int i, + Encoder *encoder = nullptr); ~CameraStream(); unsigned int index() const { return index_; } + Encoder *encoder() const { return encoder_; } libcamera::PixelFormat format; libcamera::Size size; - Encoder *jpeg; - private: /* * The index of the libcamera StreamConfiguration as added during @@ -46,6 +46,7 @@ private: * one or more streams to the Android framework. */ unsigned int index_; + Encoder *encoder_; }; class CameraDevice : protected libcamera::Loggable From patchwork Wed Sep 2 15:22: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: 9473 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 C76EEBE174 for ; Wed, 2 Sep 2020 15:19:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A1D12629B2; Wed, 2 Sep 2020 17:19:14 +0200 (CEST) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 13A78629E6 for ; Wed, 2 Sep 2020 17:19:13 +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 relay1-d.mail.gandi.net (Postfix) with ESMTPSA id E4E5F240016; Wed, 2 Sep 2020 15:19:11 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Sep 2020 17:22:36 +0200 Message-Id: <20200902152236.69770-13-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200902152236.69770-1-jacopo@jmondi.org> References: <20200902152236.69770-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 12/12] android: camera_device: Make CameraStream a 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: , Cc: tfiga@google.com, hiroh@google.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Complete the transformation of CameraStream into a class and provide a read-only interface that allows to access its parameters but not modify them at run-time. No functional changes intended but this change aims to make the code more robust by enforcing a stricter interface in the CameraStream class. Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Reviewed-by: Hirokazu Honda --- src/android/camera_device.cpp | 9 +++++---- src/android/camera_device.h | 14 ++++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 28d8e081eab0..88c85ad183d2 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -168,8 +168,9 @@ MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer, } } -CameraStream::CameraStream(PixelFormat f, Size s, unsigned int i, Encoder *encoder) - : format(f), size(s), index_(i), encoder_(encoder) +CameraStream::CameraStream(PixelFormat format, Size size, + unsigned int index, Encoder *encoder) + : format_(format), size_(size), index_(index), encoder_(encoder) { } @@ -1415,7 +1416,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques descriptor->buffers[i].buffer = camera3Buffers[i].buffer; /* Software streams are handled after hardware streams complete. */ - if (cameraStream->format == formats::MJPEG) + if (cameraStream->format() == formats::MJPEG) continue; /* @@ -1479,7 +1480,7 @@ void CameraDevice::requestComplete(Request *request) CameraStream *cameraStream = static_cast(descriptor->buffers[i].stream->priv); - if (cameraStream->format != formats::MJPEG) + if (cameraStream->format() != formats::MJPEG) continue; Encoder *encoder = cameraStream->encoder(); diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 3c57ffec265d..729b2556011b 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -27,19 +27,21 @@ class CameraMetadata; -struct CameraStream { +class CameraStream +{ public: - CameraStream(libcamera::PixelFormat, libcamera::Size, unsigned int i, - Encoder *encoder = nullptr); + CameraStream(libcamera::PixelFormat format, libcamera::Size size, + unsigned int index, Encoder *encoder = nullptr); ~CameraStream(); + libcamera::PixelFormat format() const { return format_; } + libcamera::Size size() const { return size_; } unsigned int index() const { return index_; } Encoder *encoder() const { return encoder_; } - libcamera::PixelFormat format; - libcamera::Size size; - private: + libcamera::PixelFormat format_; + libcamera::Size size_; /* * The index of the libcamera StreamConfiguration as added during * configureStreams(). A single libcamera Stream may be used to deliver