[{"id":15415,"web_url":"https://patchwork.libcamera.org/comment/15415/","msgid":"<YD4pjU0CXXtlfdv6@pendragon.ideasonboard.com>","date":"2021-03-02T12:03:25","subject":"Re: [libcamera-devel] [PATCH v3 08/10] android: camera_buffer: Add\n\tmethod to get the JPEG blob size","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Tue, Mar 02, 2021 at 12:51:06PM +0100, Jacopo Mondi wrote:\n> To maintain compatibility with platforms that do not provide a memory\n> backend implementation add a method to be return the size of the buffer\n> used for JPEG encoding capped to a maximum size.\n> \n> Platforms that implement a memory backend will always calculate the\n> correct buffer size.\n> \n> Signed-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(-)\n> \n> diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h\n> index 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\nYou can make this function const.\n\nI'd name the parameter maxJpegBufferSize, in this context \"blob\" refers\nto the small camera3_jpeg_blob structure at the end. Similarly, I'd\neither name the function jpegBufferSize(), or name it jpegBlobOffset()\nand include the - sizeof(struct camera3_jpeg_blob) there.\n\n>  };\n>  \n>  #endif /* __ANDROID_CAMERA_BUFFER_H__ */\n> diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp\n> index 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\nBad rebase ? I don't think this belongs to this patch (and I would\nexpect to see jpegBlobSize() used here :-)).\n\n>  \tauto *blob = reinterpret_cast<struct camera3_jpeg_blob *>(resultPtr);\n>  \tblob->jpeg_blob_id = CAMERA3_JPEG_BLOB_ID;\n> diff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp\n> index 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> +}","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 2FBABBD1F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  2 Mar 2021 12:03:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B891568AA1;\n\tTue,  2 Mar 2021 13:03:54 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9064068A9B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  2 Mar 2021 13:03:53 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F3CAB45D;\n\tTue,  2 Mar 2021 13:03:52 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"jH3PyYyk\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1614686633;\n\tbh=ZQZva+Y7aNhQAaRVHsYmTQnlpNHSK6rTG/iUmq7V0zg=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=jH3PyYykfWiXbYjCzz+4YZFZScdqgc8Evxwy5Ph9uhHkXj7nm9K11ZL41iAvKDN2a\n\tQ75o8hcBDUZ2tJGXL1x4GZsG3vIs6aOU/1VU5quzwzL0cJEvKAcPvvQQfxVQCrKrcT\n\t/eW8gWUdo4QMub2ObUX1zj96GMtnbyFzSDx/FH3g=","Date":"Tue, 2 Mar 2021 14:03:25 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<YD4pjU0CXXtlfdv6@pendragon.ideasonboard.com>","References":"<20210302115108.103328-1-jacopo@jmondi.org>\n\t<20210302115108.103328-9-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20210302115108.103328-9-jacopo@jmondi.org>","Subject":"Re: [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\tlibcamera-devel@lists.libcamera.org, Daniel 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>"}},{"id":15421,"web_url":"https://patchwork.libcamera.org/comment/15421/","msgid":"<20210302132728.gmqaqbzzydbacwqq@uno.localdomain>","date":"2021-03-02T13:27:28","subject":"Re: [libcamera-devel] [PATCH v3 08/10] android: camera_buffer: Add\n\tmethod to get the JPEG blob size","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent,\n\nOn Tue, Mar 02, 2021 at 02:03:25PM +0200, Laurent Pinchart wrote:\n> Hi Jacopo,\n>\n> Thank you for the patch.\n>\n> On Tue, Mar 02, 2021 at 12:51:06PM +0100, Jacopo Mondi wrote:\n> > To maintain compatibility with platforms that do not provide a memory\n> > backend implementation add a method to be return the size of the buffer\n> > used for JPEG encoding capped to a maximum size.\n> >\n> > Platforms that implement a memory backend will always calculate the\n> > correct buffer size.\n> >\n> > Signed-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(-)\n> >\n> > diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h\n> > index 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> You can make this function const.\n>\n> I'd name the parameter maxJpegBufferSize, in this context \"blob\" refers\n> to the small camera3_jpeg_blob structure at the end. Similarly, I'd\n> either name the function jpegBufferSize(), or name it jpegBlobOffset()\n> and include the - sizeof(struct camera3_jpeg_blob) there.\n>\n\nI don't know, I hope we can drop this method rather soon and replace\nit with a simpler plane(0).size() so I would leave the subtraction of\nthe struct camera3_jpeg_blob size outside of the CameraBuffer\nfunction.\n\n> >  };\n> >\n> >  #endif /* __ANDROID_CAMERA_BUFFER_H__ */\n> > diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp\n> > index 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>\n> Bad rebase ? I don't think this belongs to this patch (and I would\n> expect to see jpegBlobSize() used here :-)).\n\nAh ups.\nyes, that belongs to the old patch.\n\nI'll re-send a v4, as this patch will be broken in 2: one that\nintroduces the function the other that uses it.\n\n>\n> >  \tauto *blob = reinterpret_cast<struct camera3_jpeg_blob *>(resultPtr);\n> >  \tblob->jpeg_blob_id = CAMERA3_JPEG_BLOB_ID;\n> > diff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp\n> > index 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>\n> --\n> Regards,\n>\n> Laurent Pinchart","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 D66A8BD1F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  2 Mar 2021 13:27:01 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5B28268A99;\n\tTue,  2 Mar 2021 14:27:01 +0100 (CET)","from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net\n\t[217.70.183.201])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9C51768A93\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  2 Mar 2021 14:27:00 +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 relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 946271BF214;\n\tTue,  2 Mar 2021 13:26:59 +0000 (UTC)"],"X-Originating-IP":"93.61.96.190","Date":"Tue, 2 Mar 2021 14:27:28 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20210302132728.gmqaqbzzydbacwqq@uno.localdomain>","References":"<20210302115108.103328-1-jacopo@jmondi.org>\n\t<20210302115108.103328-9-jacopo@jmondi.org>\n\t<YD4pjU0CXXtlfdv6@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<YD4pjU0CXXtlfdv6@pendragon.ideasonboard.com>","Subject":"Re: [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\tlibcamera-devel@lists.libcamera.org, Daniel 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>"}}]