From patchwork Mon Mar 1 15:01:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11426 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 411DFBD808 for ; Mon, 1 Mar 2021 15:01:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1E28368A91; Mon, 1 Mar 2021 16:01:07 +0100 (CET) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AAD4668A69 for ; Mon, 1 Mar 2021 16:01:05 +0100 (CET) X-Originating-IP: 93.61.96.190 Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 8A34340018; Mon, 1 Mar 2021 15:01:03 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Mar 2021 16:01:09 +0100 Message-Id: <20210301150111.61791-9-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210301150111.61791-1-jacopo@jmondi.org> References: <20210301150111.61791-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 08/10] android: jpeg: Use maxJpegBufferSize() for compatibility 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" Platforms that do not provide a memory backend implementation should keep using the maxJpegBufferSize() value to calculate the location where to place the JPEG blob id, as the android_generic backend returns the allocated buffer size as calculated using lseek which is larger than the maximum JPEG frame size, which is where the framework expects the JPEG blob to be placed. Signed-off-by: Jacopo Mondi --- src/android/jpeg/post_processor_jpeg.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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;