{"id":11441,"url":"https://patchwork.libcamera.org/api/patches/11441/?format=json","web_url":"https://patchwork.libcamera.org/patch/11441/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210302115108.103328-9-jacopo@jmondi.org>","date":"2021-03-02T11:51:06","name":"[libcamera-devel,v3,08/10] android: camera_buffer: Add method to get the JPEG blob size","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"91a3403df52169bbbd8a9073525a4bbefbb1a148","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/11441/mbox/","series":[{"id":1738,"url":"https://patchwork.libcamera.org/api/series/1738/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1738","date":"2021-03-02T11:50:58","name":"android: Supports memory backends","version":3,"mbox":"https://patchwork.libcamera.org/series/1738/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/11441/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/11441/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id C87DCBD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  2 Mar 2021 11:50:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A190E68AAB;\n\tTue,  2 Mar 2021 12:50:58 +0100 (CET)","from relay12.mail.gandi.net (relay12.mail.gandi.net\n\t[217.70.178.232])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CF5B868AB0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  2 Mar 2021 12:50:56 +0100 (CET)","from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay12.mail.gandi.net (Postfix) with ESMTPSA id AE5E7200003;\n\tTue,  2 Mar 2021 11:50:55 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","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\n\tmethod to get the JPEG blob size","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"Han-lin Chen <hanlinchen@chromium.org>,\n\tDaniel Hung-yu Wu <hywu@google.com>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"To maintain compatibility with platforms that do not provide a memory\nbackend implementation add a method to be return the size of the buffer\nused for JPEG encoding capped to a maximum size.\n\nPlatforms that implement a memory backend will always calculate the\ncorrect buffer size.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/android/camera_buffer.h              |  2 ++\n src/android/jpeg/post_processor_jpeg.cpp | 12 ++++++++++--\n src/android/mm/generic_camera_buffer.cpp | 14 ++++++++++++++\n 3 files changed, 26 insertions(+), 2 deletions(-)","diff":"diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h\nindex 2311cdaf96b2..342aac6d3f14 100644\n--- a/src/android/camera_buffer.h\n+++ b/src/android/camera_buffer.h\n@@ -26,6 +26,8 @@ public:\n \n \tlibcamera::Span<const uint8_t> plane(unsigned int plane) const;\n \tlibcamera::Span<uint8_t> plane(unsigned int plane);\n+\n+\tsize_t jpegBlobSize(size_t maxJpegBlobSize);\n };\n \n #endif /* __ANDROID_CAMERA_BUFFER_H__ */\ndiff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp\nindex 83244ce6769e..65ab6b196ad1 100644\n--- a/src/android/jpeg/post_processor_jpeg.cpp\n+++ b/src/android/jpeg/post_processor_jpeg.cpp\n@@ -182,8 +182,16 @@ int PostProcessorJpeg::process(const FrameBuffer &source,\n \t}\n \n \t/* Fill in the JPEG blob header. */\n-\tuint8_t *resultPtr = destination->plane(0).data()\n-\t\t\t   + destination->plane(0).size()\n+\t/*\n+\t * \\todo For backward compatibility reasons with the android_generic\n+\t * memory backend, continue using the maxJpegBufferSize in case the\n+\t * computed buffer size is larger. This can be dropped once all\n+\t * supported platforms will have a working memory backend that\n+\t * returns the correct buffer size.\n+\t */\n+\tsize_t blobSize = std::min<unsigned int>(cameraDevice_->maxJpegBufferSize(),\n+\t\t\t\t\t\t destination->plane(0).size());\n+\tuint8_t *resultPtr = destination->plane(0).data() + blobSize\n \t\t\t   - sizeof(struct camera3_jpeg_blob);\n \tauto *blob = reinterpret_cast<struct camera3_jpeg_blob *>(resultPtr);\n \tblob->jpeg_blob_id = CAMERA3_JPEG_BLOB_ID;\ndiff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp\nindex 45a83c351266..5637b3f415eb 100644\n--- a/src/android/mm/generic_camera_buffer.cpp\n+++ b/src/android/mm/generic_camera_buffer.cpp\n@@ -27,6 +27,8 @@ public:\n \tunsigned int numPlanes() const;\n \n \tSpan<uint8_t> plane(unsigned int plane);\n+\n+\tsize_t jpegBlobSize(size_t maxJpegBlobSize);\n };\n \n CameraBuffer::Private::Private(CameraBuffer *cameraBuffer,\n@@ -77,6 +79,12 @@ Span<uint8_t> CameraBuffer::Private::plane(unsigned int plane)\n \treturn maps_[plane];\n }\n \n+size_t CameraBuffer::Private::jpegBlobSize(size_t maxJpegBlobSize)\n+{\n+\treturn std::min<unsigned int>(plane(0).size(),\n+\t\t\t\t      maxJpegBlobSize);\n+}\n+\n CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags)\n \t: Extensible(new Private(this, camera3Buffer, flags))\n {\n@@ -109,3 +117,9 @@ Span<uint8_t> CameraBuffer::plane(unsigned int plane)\n \tPrivate *const d = LIBCAMERA_D_PTR();\n \treturn d->plane(plane);\n }\n+\n+size_t CameraBuffer::jpegBlobSize(size_t maxJpegBlobSize)\n+{\n+\tPrivate *const d = LIBCAMERA_D_PTR();\n+\treturn d->jpegBlobSize(maxJpegBlobSize);\n+}\n","prefixes":["libcamera-devel","v3","08/10"]}