From patchwork Tue Mar 2 11:51:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11441 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 C87DCBD808 for ; Tue, 2 Mar 2021 11:50:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A190E68AAB; Tue, 2 Mar 2021 12:50:58 +0100 (CET) Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CF5B868AB0 for ; Tue, 2 Mar 2021 12:50:56 +0100 (CET) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id AE5E7200003; Tue, 2 Mar 2021 11:50:55 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 2 Mar 2021 12:51:06 +0100 Message-Id: <20210302115108.103328-9-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210302115108.103328-1-jacopo@jmondi.org> References: <20210302115108.103328-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 08/10] android: camera_buffer: Add method to get the JPEG blob size 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: Han-lin Chen , Daniel Hung-yu Wu Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" To maintain compatibility with platforms that do not provide a memory backend implementation add a method to be return the size of the buffer used for JPEG encoding capped to a maximum size. Platforms that implement a memory backend will always calculate the correct buffer size. Signed-off-by: Jacopo Mondi --- src/android/camera_buffer.h | 2 ++ src/android/jpeg/post_processor_jpeg.cpp | 12 ++++++++++-- src/android/mm/generic_camera_buffer.cpp | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h index 2311cdaf96b2..342aac6d3f14 100644 --- a/src/android/camera_buffer.h +++ b/src/android/camera_buffer.h @@ -26,6 +26,8 @@ public: libcamera::Span plane(unsigned int plane) const; libcamera::Span plane(unsigned int plane); + + size_t jpegBlobSize(size_t maxJpegBlobSize); }; #endif /* __ANDROID_CAMERA_BUFFER_H__ */ diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp index 83244ce6769e..65ab6b196ad1 100644 --- a/src/android/jpeg/post_processor_jpeg.cpp +++ b/src/android/jpeg/post_processor_jpeg.cpp @@ -182,8 +182,16 @@ int PostProcessorJpeg::process(const FrameBuffer &source, } /* Fill in the JPEG blob header. */ - uint8_t *resultPtr = destination->plane(0).data() - + destination->plane(0).size() + /* + * \todo For backward compatibility reasons with the android_generic + * memory backend, continue using the maxJpegBufferSize in case the + * computed buffer size is larger. This can be dropped once all + * supported platforms will have a working memory backend that + * returns the correct buffer size. + */ + size_t blobSize = std::min(cameraDevice_->maxJpegBufferSize(), + destination->plane(0).size()); + uint8_t *resultPtr = destination->plane(0).data() + blobSize - sizeof(struct camera3_jpeg_blob); auto *blob = reinterpret_cast(resultPtr); blob->jpeg_blob_id = CAMERA3_JPEG_BLOB_ID; diff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp index 45a83c351266..5637b3f415eb 100644 --- a/src/android/mm/generic_camera_buffer.cpp +++ b/src/android/mm/generic_camera_buffer.cpp @@ -27,6 +27,8 @@ public: unsigned int numPlanes() const; Span plane(unsigned int plane); + + size_t jpegBlobSize(size_t maxJpegBlobSize); }; CameraBuffer::Private::Private(CameraBuffer *cameraBuffer, @@ -77,6 +79,12 @@ Span CameraBuffer::Private::plane(unsigned int plane) return maps_[plane]; } +size_t CameraBuffer::Private::jpegBlobSize(size_t maxJpegBlobSize) +{ + return std::min(plane(0).size(), + maxJpegBlobSize); +} + CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags) : Extensible(new Private(this, camera3Buffer, flags)) { @@ -109,3 +117,9 @@ Span CameraBuffer::plane(unsigned int plane) Private *const d = LIBCAMERA_D_PTR(); return d->plane(plane); } + +size_t CameraBuffer::jpegBlobSize(size_t maxJpegBlobSize) +{ + Private *const d = LIBCAMERA_D_PTR(); + return d->jpegBlobSize(maxJpegBlobSize); +}