From patchwork Sat Sep 12 10:11:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9581 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 C094EC3B5B for ; Sat, 12 Sep 2020 10:07:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9C76062DAB; Sat, 12 Sep 2020 12:07:55 +0200 (CEST) Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D1BD562C8C for ; Sat, 12 Sep 2020 12:07:54 +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 relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 5C1101BF204; Sat, 12 Sep 2020 10:07:53 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 12 Sep 2020 12:11:20 +0200 Message-Id: <20200912101129.12625-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200912101129.12625-1-jacopo@jmondi.org> References: <20200912101129.12625-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 01/10] 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 --- 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 93659e91f980..ebebdac38e28 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -398,10 +398,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 Sat Sep 12 10:11:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9582 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 03901C3B5B for ; Sat, 12 Sep 2020 10:07:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D546162D86; Sat, 12 Sep 2020 12:07:57 +0200 (CEST) Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DDB5862D5B for ; Sat, 12 Sep 2020 12:07:56 +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 relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 08D191BF203; Sat, 12 Sep 2020 10:07:54 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 12 Sep 2020 12:11:21 +0200 Message-Id: <20200912101129.12625-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200912101129.12625-1-jacopo@jmondi.org> References: <20200912101129.12625-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 02/10] 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: Hirokazu Honda Reviewed-by: Niklas Söderlund Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- 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 ebebdac38e28..3be2dac28f9c 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -369,17 +369,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, @@ -422,19 +426,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 Sat Sep 12 10:11:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9583 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 2A231C3B5B for ; Sat, 12 Sep 2020 10:08:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0451D62DEF; Sat, 12 Sep 2020 12:08:00 +0200 (CEST) Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B6BBE62D5B for ; Sat, 12 Sep 2020 12:07:58 +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 relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 12A4B1BF204; Sat, 12 Sep 2020 10:07:56 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 12 Sep 2020 12:11:22 +0200 Message-Id: <20200912101129.12625-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200912101129.12625-1-jacopo@jmondi.org> References: <20200912101129.12625-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 03/10] 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: Hirokazu Honda Reviewed-by: Niklas Söderlund Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 3be2dac28f9c..d3a53c948ea8 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -369,12 +369,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; } @@ -385,6 +392,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. @@ -420,14 +429,22 @@ 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; CameraConfiguration::Status status = cameraConfig->validate(); - if (status != CameraConfiguration::Valid) + if (status != CameraConfiguration::Valid) { + LOG(HAL, Debug) << cfg.toString() + << " not supported"; continue; + } + + LOG(HAL, Debug) << cfg.toString() << " supported"; streamConfigurations_.push_back({ res, androidFormat }); From patchwork Sat Sep 12 10:11:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9584 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 514CEC3B5B for ; Sat, 12 Sep 2020 10:08:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2AAB762D5B; Sat, 12 Sep 2020 12:08:02 +0200 (CEST) Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 925B262D27 for ; Sat, 12 Sep 2020 12:08:00 +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 relay8-d.mail.gandi.net (Postfix) with ESMTPSA id DBD1E1BF203; Sat, 12 Sep 2020 10:07:58 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 12 Sep 2020 12:11:23 +0200 Message-Id: <20200912101129.12625-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200912101129.12625-1-jacopo@jmondi.org> References: <20200912101129.12625-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 04/10] 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: Hirokazu Honda Reviewed-by: Niklas Söderlund Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 42 ++++++++++++++++++++++++----------- src/android/camera_device.h | 5 +++++ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index d3a53c948ea8..0386287dc39d 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -289,6 +289,31 @@ int CameraDevice::initialize() return ret; } +std::vector CameraDevice::getYUVResolutions(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; + + CameraConfiguration::Status status = cameraConfig->validate(); + if (status != CameraConfiguration::Valid) { + LOG(HAL, Debug) << cfg.toString() << " not supported"; + continue; + } + + LOG(HAL, Debug) << cfg.toString() << " supported"; + + 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 @@ -433,19 +458,10 @@ int CameraDevice::initializeStreamConfigurations() << camera3Format.name << " to " << mappedFormat.toString(); - for (const Size &res : cameraResolutions) { - cfg.pixelFormat = mappedFormat; - cfg.size = res; - - CameraConfiguration::Status status = cameraConfig->validate(); - if (status != CameraConfiguration::Valid) { - LOG(HAL, Debug) << cfg.toString() - << " not supported"; - continue; - } - - LOG(HAL, Debug) << cfg.toString() << " supported"; - + std::vector resolutions = getYUVResolutions(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..1ff43327bab1 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -93,6 +93,11 @@ private: }; int initializeStreamConfigurations(); + std::vector + getYUVResolutions(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 Sat Sep 12 10:11:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9585 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 7C3DEC3B5B for ; Sat, 12 Sep 2020 10:08:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 51D8F62DB4; Sat, 12 Sep 2020 12:08:04 +0200 (CEST) Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 023A962C8C for ; Sat, 12 Sep 2020 12:08:03 +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 relay8-d.mail.gandi.net (Postfix) with ESMTPSA id B4AE81BF206; Sat, 12 Sep 2020 10:08:00 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 12 Sep 2020 12:11:24 +0200 Message-Id: <20200912101129.12625-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200912101129.12625-1-jacopo@jmondi.org> References: <20200912101129.12625-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 05/10] 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. Reviewed-by: Hirokazu Honda Reviewed-by: Niklas Söderlund Acked-by: Laurent Pinchart Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi --- 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 0386287dc39d..0608d026e4b0 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -314,6 +314,17 @@ std::vector CameraDevice::getYUVResolutions(CameraConfiguration *cameraCon return supportedResolutions; } +std::vector CameraDevice::getRawResolutions(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 @@ -458,9 +469,15 @@ int CameraDevice::initializeStreamConfigurations() << camera3Format.name << " to " << mappedFormat.toString(); - std::vector resolutions = getYUVResolutions(cameraConfig.get(), - mappedFormat, - cameraResolutions); + std::vector resolutions; + const PixelFormatInfo &info = PixelFormatInfo::info(mappedFormat); + if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) + resolutions = getRawResolutions(mappedFormat); + else + resolutions = getYUVResolutions(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 1ff43327bab1..c0732fb8ed7f 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -97,6 +97,8 @@ private: getYUVResolutions(libcamera::CameraConfiguration *cameraConfig, const libcamera::PixelFormat &pixelFormat, const std::vector &resolutions); + std::vector + getRawResolutions(const libcamera::PixelFormat &pixelFormat); std::tuple calculateStaticMetadataSize(); libcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer); From patchwork Sat Sep 12 10:11:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9586 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 A140CC3B5B for ; Sat, 12 Sep 2020 10:08:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7F6EA62D5B; Sat, 12 Sep 2020 12:08:06 +0200 (CEST) Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D32AB62D27 for ; Sat, 12 Sep 2020 12:08:04 +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 relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 2503A1BF204; Sat, 12 Sep 2020 10:08:02 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 12 Sep 2020 12:11:25 +0200 Message-Id: <20200912101129.12625-7-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200912101129.12625-1-jacopo@jmondi.org> References: <20200912101129.12625-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 06/10] 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. Reviewed-by: Niklas Söderlund Reviewed-by: Hirokazu Honda Acked-by: Laurent Pinchart Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi --- 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 0608d026e4b0..e2c73ff4c4ce 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1190,12 +1190,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]; @@ -1226,8 +1220,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. */ @@ -1276,7 +1269,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 Sat Sep 12 10:11:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9587 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 C8410C3B5B for ; Sat, 12 Sep 2020 10:08:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A5E8E62DFF; Sat, 12 Sep 2020 12:08:07 +0200 (CEST) Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B279062D27 for ; Sat, 12 Sep 2020 12:08: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 relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 0CC351BF206; Sat, 12 Sep 2020 10:08:04 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 12 Sep 2020 12:11:26 +0200 Message-Id: <20200912101129.12625-8-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200912101129.12625-1-jacopo@jmondi.org> References: <20200912101129.12625-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 07/10] 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" 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: Hirokazu Honda Reviewed-by: Niklas Söderlund Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index e2c73ff4c4ce..af2905007b28 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1211,7 +1211,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; @@ -1228,7 +1228,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) camera3_stream_t *stream = stream_list->streams[i]; bool match = false; - if (streams_[i].format != formats::MJPEG) + if (stream->format != HAL_PIXEL_FORMAT_BLOB) continue; /* Search for a compatible stream */ From patchwork Sat Sep 12 10:11: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: 9588 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 293F1C3B5B for ; Sat, 12 Sep 2020 10:08:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 01C8262DB4; Sat, 12 Sep 2020 12:08:10 +0200 (CEST) Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 582C162D27 for ; Sat, 12 Sep 2020 12:08: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 relay8-d.mail.gandi.net (Postfix) with ESMTPSA id DD6A51BF203; Sat, 12 Sep 2020 10:08:06 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 12 Sep 2020 12:11:27 +0200 Message-Id: <20200912101129.12625-9-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200912101129.12625-1-jacopo@jmondi.org> References: <20200912101129.12625-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 08/10] 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: Hirokazu Honda Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- 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 af2905007b28..59acfd762a89 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -169,8 +169,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) { } @@ -1191,6 +1191,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); @@ -1207,52 +1208,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; /* @@ -1261,15 +1260,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; } } @@ -1292,25 +1307,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; - } - } } /* @@ -1424,7 +1425,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); @@ -1479,7 +1480,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 c0732fb8ed7f..376d001ea7d7 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 Sat Sep 12 10:11:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9589 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 5DB85C3B5B for ; Sat, 12 Sep 2020 10:08:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 39C9062DFF; Sat, 12 Sep 2020 12:08:11 +0200 (CEST) Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 53FB662D5B for ; Sat, 12 Sep 2020 12:08: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 relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 830791BF204; Sat, 12 Sep 2020 10:08:08 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 12 Sep 2020 12:11:28 +0200 Message-Id: <20200912101129.12625-10-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200912101129.12625-1-jacopo@jmondi.org> References: <20200912101129.12625-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 09/10] 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: Hirokazu Honda Reviewed-by: Niklas Söderlund Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi --- 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 59acfd762a89..4d8847e72db5 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -169,16 +169,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 *e) + : format(f), size(s), index_(i), encoder_(e) { } -CameraStream::~CameraStream() -{ - delete jpeg; -}; - /* * \struct Camera3RequestDescriptor * @@ -1272,20 +1267,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()) { @@ -1474,7 +1470,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 376d001ea7d7..49a2e7f3f8bc 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 *e = 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 Sat Sep 12 10:11:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9590 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 A45CBC3B5B for ; Sat, 12 Sep 2020 10:08:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7FBA162DB4; Sat, 12 Sep 2020 12:08:13 +0200 (CEST) Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0F8D162D5B for ; Sat, 12 Sep 2020 12:08:12 +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 relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 7D6A11BF208; Sat, 12 Sep 2020 10:08:10 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 12 Sep 2020 12:11:29 +0200 Message-Id: <20200912101129.12625-11-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200912101129.12625-1-jacopo@jmondi.org> References: <20200912101129.12625-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 10/10] 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: Niklas Söderlund Reviewed-by: Hirokazu Honda Reviewed-by: Hirokazu Honda Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 11 ++++++----- src/android/camera_device.h | 14 ++++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 4d8847e72db5..7ecb2a4d82e6 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -169,8 +169,9 @@ MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer, } } -CameraStream::CameraStream(PixelFormat f, Size s, unsigned int i, Encoder *e) - : format(f), size(s), index_(i), encoder_(e) +CameraStream::CameraStream(PixelFormat format, Size size, + unsigned int index, Encoder *encoder) + : format_(format), size_(size), index_(index), encoder_(encoder) { } @@ -1403,7 +1404,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; /* @@ -1467,7 +1468,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(); @@ -1502,7 +1503,7 @@ void CameraDevice::requestComplete(Request *request) exif.setMake("libcamera"); exif.setModel("cameraModel"); exif.setOrientation(orientation_); - exif.setSize(cameraStream->size); + exif.setSize(cameraStream->size()); /* * We set the frame's EXIF timestamp as the time of encode. * Since the precision we need for EXIF timestamp is only one diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 49a2e7f3f8bc..1837748d2efc 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 *e = 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