From patchwork Tue Sep 8 13:41:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9532 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 8BD99BDB1D for ; Tue, 8 Sep 2020 13:38:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 67B2962C74; Tue, 8 Sep 2020 15:38:07 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6E38B62C30 for ; Tue, 8 Sep 2020 15:38:05 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id EDD6D1C000B; Tue, 8 Sep 2020 13:38:03 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Sep 2020 15:41:32 +0200 Message-Id: <20200908134142.27470-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200908134142.27470-1-jacopo@jmondi.org> References: <20200908134142.27470-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 01/11] 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: hanlinchen@chromium.org 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: Hirokazu Honda Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- 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 25829918cd29..28fb3868c082 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 Tue Sep 8 13:41:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9533 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 E657CBDB1D for ; Tue, 8 Sep 2020 13:38:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BEABD62C4B; Tue, 8 Sep 2020 15:38:08 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EFED462C30 for ; Tue, 8 Sep 2020 15:38:06 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 938D71C000A; Tue, 8 Sep 2020 13:38:05 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Sep 2020 15:41:33 +0200 Message-Id: <20200908134142.27470-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200908134142.27470-1-jacopo@jmondi.org> References: <20200908134142.27470-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 02/11] 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: hanlinchen@chromium.org Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When producing the list of image resolutions 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 Reviewed-by: Niklas Söderlund Reviewed-by: Hirokazu Honda --- src/android/camera_device.cpp | 40 ++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 28fb3868c082..1b2e12d6d33c 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -363,17 +363,21 @@ int CameraDevice::initializeStreamConfigurations() const std::vector &libcameraFormats = camera3Format.libcameraFormats; + /* + * JPEG is always supported, either produced directly by the + * camera, or encoded in the HAL. + */ + 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 +420,25 @@ 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. + * + * \todo Support JPEG streams produced by the Camera + * natively. + */ + if (androidFormat == HAL_PIXEL_FORMAT_YCbCr_420_888) + streamConfigurations_.push_back( + { res, HAL_PIXEL_FORMAT_BLOB }); } } From patchwork Tue Sep 8 13:41:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9534 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 12B98BDB1D for ; Tue, 8 Sep 2020 13:38:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E226D62C30; Tue, 8 Sep 2020 15:38:10 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9A6A162C66 for ; Tue, 8 Sep 2020 15:38:08 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 1DFF31C0002; Tue, 8 Sep 2020 13:38:06 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Sep 2020 15:41:34 +0200 Message-Id: <20200908134142.27470-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200908134142.27470-1-jacopo@jmondi.org> References: <20200908134142.27470-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 03/11] 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: hanlinchen@chromium.org Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add debug printouts to the CameraDevice::initializeStreamConfigurations() function that help to follow the process of building the stream configurations map. Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund Reviewed-by: Hirokazu Honda --- src/android/camera_device.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 1b2e12d6d33c..17b5fd5f59eb 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -363,12 +363,19 @@ int CameraDevice::initializeStreamConfigurations() const std::vector &libcameraFormats = camera3Format.libcameraFormats; + LOG(HAL, Debug) << "Trying to map Android format " + << camera3Format.name; + /* * JPEG is always supported, either produced directly by the * camera, or encoded in the HAL. */ 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; } @@ -379,6 +386,8 @@ int CameraDevice::initializeStreamConfigurations() PixelFormat mappedFormat; for (const PixelFormat &pixelFormat : libcameraFormats) { + LOG(HAL, Debug) << "Testing " << pixelFormat.toString(); + /* * The stream configuration size can be adjusted, * not the pixel format. @@ -414,14 +423,26 @@ 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 " << cfg.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 Tue Sep 8 13:41:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9535 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 4F477BDB1D for ; Tue, 8 Sep 2020 13:38:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2363862C4B; Tue, 8 Sep 2020 15:38:12 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 40E346056C for ; Tue, 8 Sep 2020 15:38:10 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id BDD211C0004; Tue, 8 Sep 2020 13:38:08 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Sep 2020 15:41:35 +0200 Message-Id: <20200908134142.27470-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200908134142.27470-1-jacopo@jmondi.org> References: <20200908134142.27470-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 04/11] 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: hanlinchen@chromium.org 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 the procedure to calculate the processed (RGB/YUV) resolutions from initializeStreamConfigurations() in order to prepare for RAW sizes calculation. Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund Reviewed-by: Hirokazu Honda --- src/android/camera_device.cpp | 51 +++++++++++++++++++++++------------ src/android/camera_device.h | 5 ++++ 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 17b5fd5f59eb..9d460906ab08 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -283,6 +283,36 @@ 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 << "Testing " << cfg.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 @@ -427,23 +457,10 @@ int CameraDevice::initializeStreamConfigurations() << camera3Format.name << " to " << mappedFormat.toString(); - for (const Size &res : cameraResolutions) { - cfg.pixelFormat = mappedFormat; - cfg.size = res; - - std::stringstream ss; - ss << "Testing " << cfg.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(); - + 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 Tue Sep 8 13:41:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9536 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 6F6B0BDB1D for ; Tue, 8 Sep 2020 13:38:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4505A62C5E; Tue, 8 Sep 2020 15:38:13 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D98E06056C for ; Tue, 8 Sep 2020 15:38:11 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 651841C0002; Tue, 8 Sep 2020 13:38:10 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Sep 2020 15:41:36 +0200 Message-Id: <20200908134142.27470-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200908134142.27470-1-jacopo@jmondi.org> References: <20200908134142.27470-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 05/11] 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: hanlinchen@chromium.org 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. Acked-by: Laurent Pinchart Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund Reviewed-by: Hirokazu Honda --- src/android/camera_device.cpp | 23 ++++++++++++++++++++--- src/android/camera_device.h | 2 ++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 9d460906ab08..5f4b95987615 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -313,6 +313,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 @@ -457,9 +468,15 @@ int CameraDevice::initializeStreamConfigurations() << camera3Format.name << " to " << mappedFormat.toString(); - std::vector resolutions = filterYUVResolutions(cameraConfig.get(), - mappedFormat, - cameraResolutions); + std::vector resolutions; + const PixelFormatInfo &info = PixelFormatInfo::info(mappedFormat); + if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) + resolutions = filterRawResolutions(mappedFormat); + else + 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 Tue Sep 8 13:41:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9537 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 AA426BDB1D for ; Tue, 8 Sep 2020 13:38:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 833F862C9C; Tue, 8 Sep 2020 15:38:14 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9B05B62C30 for ; Tue, 8 Sep 2020 15:38:13 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 0ACE81C000B; Tue, 8 Sep 2020 13:38:11 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Sep 2020 15:41:37 +0200 Message-Id: <20200908134142.27470-7-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200908134142.27470-1-jacopo@jmondi.org> References: <20200908134142.27470-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 06/11] 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: hanlinchen@chromium.org Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Use the size() method of the CameraConfiguration class to retrieve the index of the StreamConfiguration associated with a CameraStream and get rid of the custom counter. Acked-by: Laurent Pinchart Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund Reviewed-by: Hirokazu Honda --- src/android/camera_device.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 5f4b95987615..562cbb3c415e 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1189,12 +1189,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]; @@ -1225,8 +1219,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) streamConfiguration.pixelFormat = format; config_->addConfiguration(streamConfiguration); - - streams_[i].index = streamIndex++; + streams_[i].index = config_->size() - 1; } /* Now handle MJPEG streams, adding a new stream if required. */ @@ -1275,7 +1268,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) << " for MJPEG support"; config_->addConfiguration(streamConfiguration); - streams_[i].index = streamIndex++; + streams_[i].index = config_->size() - 1; } } From patchwork Tue Sep 8 13:41:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9538 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 081FABDB1D for ; Tue, 8 Sep 2020 13:38:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C56A162C83; Tue, 8 Sep 2020 15:38:16 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 087E762C30 for ; Tue, 8 Sep 2020 15:38:15 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id BDE7E1C0017; Tue, 8 Sep 2020 13:38:13 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Sep 2020 15:41:38 +0200 Message-Id: <20200908134142.27470-8-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200908134142.27470-1-jacopo@jmondi.org> References: <20200908134142.27470-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 07/11] 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: hanlinchen@chromium.org 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: Laurent Pinchart Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund Reviewed-by: Hirokazu Honda --- 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 562cbb3c415e..2cad4fe76c3c 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1225,9 +1225,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 Tue Sep 8 13:41:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9539 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 530D7BDB1D for ; Tue, 8 Sep 2020 13:38:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1D3E962C74; Tue, 8 Sep 2020 15:38:18 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9375762C37 for ; Tue, 8 Sep 2020 15:38:16 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 3198F1C000F; Tue, 8 Sep 2020 13:38:15 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Sep 2020 15:41:39 +0200 Message-Id: <20200908134142.27470-9-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200908134142.27470-1-jacopo@jmondi.org> References: <20200908134142.27470-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 08/11] 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: hanlinchen@chromium.org 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: Laurent Pinchart Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund Reviewed-by: Hirokazu Honda --- 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 2cad4fe76c3c..eab01d808917 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1210,7 +1210,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; @@ -1225,10 +1225,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 Tue Sep 8 13:41:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9540 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 9B019BDB1D for ; Tue, 8 Sep 2020 13:38:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7879562C83; Tue, 8 Sep 2020 15:38:19 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1F27762C98 for ; Tue, 8 Sep 2020 15:38:18 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id B93A91C0015; Tue, 8 Sep 2020 13:38:16 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Sep 2020 15:41:40 +0200 Message-Id: <20200908134142.27470-10-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200908134142.27470-1-jacopo@jmondi.org> References: <20200908134142.27470-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 09/11] 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: hanlinchen@chromium.org 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 Reviewed-by: Hirokazu Honda --- src/android/camera_device.cpp | 91 ++++++++++++++++++----------------- src/android/camera_device.h | 18 ++++--- 2 files changed, 57 insertions(+), 52 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index eab01d808917..e0260c92246c 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) { } @@ -1190,6 +1190,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) streams_.reserve(stream_list->num_streams); /* First handle all non-MJPEG streams. */ + camera3_stream_t *jpegStream = nullptr; for (unsigned int i = 0; i < stream_list->num_streams; ++i) { camera3_stream_t *stream = stream_list->streams[i]; Size size(stream->width, stream->height); @@ -1206,52 +1207,50 @@ 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) + if (stream->format == HAL_PIXEL_FORMAT_BLOB) { + jpegStream = stream; continue; + } StreamConfiguration streamConfiguration; - streamConfiguration.size = size; streamConfiguration.pixelFormat = format; config_->addConfiguration(streamConfiguration); - streams_[i].index = config_->size() - 1; + unsigned int index = config_->size() - 1; + streams_.emplace_back(format, size, index); + stream->priv = static_cast(&streams_.back()); } /* 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; + if (jpegStream) { + int index = -1; - /* Search for a compatible stream */ - for (unsigned int j = 0; j < config_->size(); j++) { - StreamConfiguration &cfg = config_->at(j); + /* Search for a compatible stream in the non-JPEG ones. */ + for (unsigned int i = 0; i < config_->size(); i++) { + StreamConfiguration &cfg = config_->at(i); /* * \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 != jpegStream->width || + cfg.size.height != jpegStream->height) + continue; - match = true; - streams_[i].index = j; - } + LOG(HAL, Info) + << "Android JPEG stream mapped on stream " << i; + + index = i; + break; } /* * Without a compatible match for JPEG encoding we must * introduce a new stream to satisfy the request requirements. */ - if (!match) { + if (index < 0) { StreamConfiguration streamConfiguration; /* @@ -1260,15 +1259,31 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) * handled, and should be considered as part of any * stream configuration reworks. */ - streamConfiguration.size.width = stream->width; - streamConfiguration.size.height = stream->height; + streamConfiguration.size.width = jpegStream->width; + streamConfiguration.size.height = jpegStream->height; streamConfiguration.pixelFormat = formats::NV12; LOG(HAL, Info) << "Adding " << streamConfiguration.toString() << " for MJPEG support"; config_->addConfiguration(streamConfiguration); - streams_[i].index = config_->size() - 1; + index = config_->size() - 1; + } + + StreamConfiguration &cfg = config_->at(index); + CameraStream &cameraStream = + streams_.emplace_back(formats::MJPEG, cfg.size, index); + jpegStream->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; } } @@ -1291,25 +1306,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; - } - } } /* @@ -1423,7 +1424,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); @@ -1478,7 +1479,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 Tue Sep 8 13:41:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9541 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 09FF8BDB1D for ; Tue, 8 Sep 2020 13:38:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DB46762C74; Tue, 8 Sep 2020 15:38:20 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BF56262CA7 for ; Tue, 8 Sep 2020 15:38:19 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 437731C0003; Tue, 8 Sep 2020 13:38:18 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Sep 2020 15:41:41 +0200 Message-Id: <20200908134142.27470-11-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200908134142.27470-1-jacopo@jmondi.org> References: <20200908134142.27470-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 10/11] 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: hanlinchen@chromium.org Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Make the CameraStream encoder a private unique pointer and require its initialization at construction time. This ties the encoder lifetime to the CameraStream it has been created with, allowing to remove the CameraStream destructor. 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: Laurent Pinchart Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund Reviewed-by: Hirokazu Honda --- src/android/camera_device.cpp | 22 +++++++++------------- src/android/camera_device.h | 8 ++++---- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index e0260c92246c..4c1416913d00 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -168,16 +168,11 @@ 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; -}; - /* * \struct Camera3RequestDescriptor * @@ -1271,20 +1266,21 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) } StreamConfiguration &cfg = config_->at(index); - CameraStream &cameraStream = - streams_.emplace_back(formats::MJPEG, cfg.size, index); - jpegStream->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"; + delete encoder; return ret; } + + streams_.emplace_back(formats::MJPEG, cfg.size, index, encoder); + jpegStream->priv = static_cast(&streams_.back()); } switch (config_->validate()) { @@ -1473,7 +1469,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..5ac8f05e5a07 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -29,16 +29,15 @@ class CameraMetadata; struct CameraStream { public: - CameraStream(libcamera::PixelFormat, libcamera::Size, unsigned int i); - ~CameraStream(); + CameraStream(libcamera::PixelFormat, libcamera::Size, unsigned int i, + Encoder *encoder = nullptr); unsigned int index() const { return index_; } + Encoder *encoder() const { return encoder_.get(); } libcamera::PixelFormat format; libcamera::Size size; - Encoder *jpeg; - private: /* * The index of the libcamera StreamConfiguration as added during @@ -46,6 +45,7 @@ private: * one or more streams to the Android framework. */ unsigned int index_; + std::unique_ptr encoder_; }; class CameraDevice : protected libcamera::Loggable From patchwork Tue Sep 8 13:41:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9542 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 2CC56BDB1D for ; Tue, 8 Sep 2020 13:38:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0B44D62C74; Tue, 8 Sep 2020 15:38:23 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3981F62C5E for ; Tue, 8 Sep 2020 15:38:21 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id E12E81C000C; Tue, 8 Sep 2020 13:38:19 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Sep 2020 15:41:42 +0200 Message-Id: <20200908134142.27470-12-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200908134142.27470-1-jacopo@jmondi.org> References: <20200908134142.27470-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 11/11] 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: hanlinchen@chromium.org 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: Hirokazu Honda Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund 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 4c1416913d00..50923df22a8f 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) { } @@ -1402,7 +1403,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; /* @@ -1466,7 +1467,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 5ac8f05e5a07..912c59aeb5a8 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -27,18 +27,20 @@ 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); + const libcamera::PixelFormat &format() const { return format_; } + const libcamera::Size &size() const { return size_; } unsigned int index() const { return index_; } Encoder *encoder() const { return encoder_.get(); } - 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