[{"id":26222,"web_url":"https://patchwork.libcamera.org/comment/26222/","msgid":"<Y8SQ6s2FQaJMb9KD@pendragon.ideasonboard.com>","date":"2023-01-15T23:48:58","subject":"Re: [libcamera-devel] [PATCH v8 6/7] Pass StreamBuffer to\n\tEncoder::encoder","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Harvey,\n\nThank you for the patch.\n\nOn Wed, Dec 14, 2022 at 09:33:29AM +0000, Harvey Yang wrote:\n> From: Harvey Yang <chenghaoyang@chromium.org>\n> \n> To prepare for the JEA encoder in the following patches, StreamBuffer is\n> passed to Encoder::encoder, which contains the original FrameBuffer and\n> Span |destination|.\n\nWe can explain why:\n\nTo prepare for support of the JEA encoder in a following commit, which\nwill need to access the buffer_handle_t of the destination buffer, pass\nthe StreamBuffer to the Encoder::encoder() function. As the StreamBuffer\ncontains the source FrameBuffer and the destination Span, drop them from\nthe function arguments and access them directly from the StreamBuffer.\n\n> \n> Signed-off-by: Harvey Yang <chenghaoyang@chromium.org>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Reviewed-by: Han-Lin Chen <hanlinchen@chromium.org>\n> ---\n>  src/android/jpeg/encoder.h               |  5 +++--\n>  src/android/jpeg/encoder_libjpeg.cpp     | 11 +++++++----\n>  src/android/jpeg/encoder_libjpeg.h       |  3 +--\n>  src/android/jpeg/post_processor_jpeg.cpp |  3 +--\n>  4 files changed, 12 insertions(+), 10 deletions(-)\n> \n> diff --git a/src/android/jpeg/encoder.h b/src/android/jpeg/encoder.h\n> index 5f9ef890..14b1ab45 100644\n> --- a/src/android/jpeg/encoder.h\n> +++ b/src/android/jpeg/encoder.h\n> @@ -12,14 +12,15 @@\n>  #include <libcamera/framebuffer.h>\n>  #include <libcamera/stream.h>\n>  \n> +#include \"../camera_request.h\"\n> +\n>  class Encoder\n>  {\n>  public:\n>  \tvirtual ~Encoder() = default;\n>  \n>  \tvirtual int configure(const libcamera::StreamConfiguration &cfg) = 0;\n> -\tvirtual int encode(const libcamera::FrameBuffer &source,\n> -\t\t\t   libcamera::Span<uint8_t> destination,\n> +\tvirtual int encode(Camera3RequestDescriptor::StreamBuffer *streamBuffer,\n>  \t\t\t   libcamera::Span<const uint8_t> exifData,\n>  \t\t\t   unsigned int quality) = 0;\n>  \tvirtual void generateThumbnail(const libcamera::FrameBuffer &source,\n> diff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp\n> index cc5f37be..8bbba6e0 100644\n> --- a/src/android/jpeg/encoder_libjpeg.cpp\n> +++ b/src/android/jpeg/encoder_libjpeg.cpp\n> @@ -24,6 +24,8 @@\n>  #include \"libcamera/internal/formats.h\"\n>  #include \"libcamera/internal/mapped_framebuffer.h\"\n>  \n> +#include \"../camera_buffer.h\"\n> +\n>  using namespace libcamera;\n>  \n>  LOG_DECLARE_CATEGORY(JPEG)\n> @@ -187,17 +189,18 @@ void EncoderLibJpeg::Encoder::compressNV(const std::vector<Span<uint8_t>> &plane\n>  \t}\n>  }\n>  \n> -int EncoderLibJpeg::encode(const FrameBuffer &source, Span<uint8_t> dest,\n> -\t\t\t   Span<const uint8_t> exifData, unsigned int quality)\n> +int EncoderLibJpeg::encode(Camera3RequestDescriptor::StreamBuffer *streamBuffer,\n\nI'd name the parameter just `buffer` to shorten lines.\n\n> +\t\t\t   libcamera::Span<const uint8_t> exifData,\n> +\t\t\t   unsigned int quality)\n>  {\n> -\tMappedFrameBuffer frame(&source, MappedFrameBuffer::MapFlag::Read);\n> +\tMappedFrameBuffer frame(streamBuffer->srcBuffer, MappedFrameBuffer::MapFlag::Read);\n\nLine wrap.\n\n>  \tif (!frame.isValid()) {\n>  \t\tLOG(JPEG, Error) << \"Failed to map FrameBuffer : \"\n>  \t\t\t\t << strerror(frame.error());\n>  \t\treturn frame.error();\n>  \t}\n>  \n> -\treturn captureEncoder_.encode(frame.planes(), dest, exifData, quality);\n> +\treturn captureEncoder_.encode(frame.planes(), streamBuffer->dstBuffer->plane(0), exifData, quality);\n\nAnd here especially.\n\nAs before, no need to resubmit just for this, I can handle it and add my\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  }\n>  \n>  void EncoderLibJpeg::generateThumbnail(const libcamera::FrameBuffer &source,\n> diff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h\n> index fa077b8d..f4bf99ba 100644\n> --- a/src/android/jpeg/encoder_libjpeg.h\n> +++ b/src/android/jpeg/encoder_libjpeg.h\n> @@ -24,8 +24,7 @@ public:\n>  \t~EncoderLibJpeg();\n>  \n>  \tint configure(const libcamera::StreamConfiguration &cfg) override;\n> -\tint encode(const libcamera::FrameBuffer &source,\n> -\t\t   libcamera::Span<uint8_t> destination,\n> +\tint encode(Camera3RequestDescriptor::StreamBuffer *streamBuffer,\n>  \t\t   libcamera::Span<const uint8_t> exifData,\n>  \t\t   unsigned int quality) override;\n>  \tvoid generateThumbnail(const libcamera::FrameBuffer &source,\n> diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp\n> index 69b18a2e..918ab492 100644\n> --- a/src/android/jpeg/post_processor_jpeg.cpp\n> +++ b/src/android/jpeg/post_processor_jpeg.cpp\n> @@ -146,8 +146,7 @@ void PostProcessorJpeg::process(Camera3RequestDescriptor::StreamBuffer *streamBu\n>  \tconst uint8_t quality = ret ? *entry.data.u8 : 95;\n>  \tresultMetadata->addEntry(ANDROID_JPEG_QUALITY, quality);\n>  \n> -\tint jpeg_size = encoder_->encode(source, destination->plane(0),\n> -\t\t\t\t\t exif.data(), quality);\n> +\tint jpeg_size = encoder_->encode(streamBuffer, exif.data(), quality);\n>  \tif (jpeg_size < 0) {\n>  \t\tLOG(JPEG, Error) << \"Failed to encode stream image\";\n>  \t\tprocessComplete.emit(streamBuffer, PostProcessor::Status::Error);","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 7CBCABD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 15 Jan 2023 23:49:01 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C0584625E4;\n\tMon, 16 Jan 2023 00:49:00 +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 3F1AA625D0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Jan 2023 00:48:59 +0100 (CET)","from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi\n\t[213.243.189.158])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8583C997;\n\tMon, 16 Jan 2023 00:48:58 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1673826540;\n\tbh=uBXiYW3PFon7px+qzvouBhH6YOFdvx6YyOS43lXjedI=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=FMVn2RS2j8HGhMz9gDjlOJY//Qbuft0ibKlTQRO2dlaBUMZ3JBcbT+eE5sEGMj6MV\n\t32LIUuCt+opeL1KAY80JAOlAJ4S4g+BWgcNBBUKqZuhrchAaSHjMyRq/ENfMVjzQ9E\n\tnsYlFA+Qzwtca6wobkr+tMbbptcAkapkS/ISLt+0tkMZKws+LK2v/CT2YtxzZMHyHx\n\tAOA0SIwyGr/qC3OpKjgtSmgJhL3aeRxTC+AIw0hzbNW1yfYjFWNofu3EuOgAfVdk/B\n\tTO+Cn+iW6CsuPGcnD42+36bVMOkVe6OrRTmBJiz9ipfJJtnyzm7fggbEJ5DPQEn8aU\n\trOYXIq2ccUkag==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1673826538;\n\tbh=uBXiYW3PFon7px+qzvouBhH6YOFdvx6YyOS43lXjedI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=eJ+rjKxJV/XKhSswPk6y9uUSvsWJV9G9Qq7r3Ew8A+egibFZi3F8iyvmRz9cpYCc0\n\tlHyhIRAthGwLlsH275b9eAp/mlxgRSMQIGTtZkEQyLBlKYcDz85KCOitP3xRkwViWX\n\tJWFot8OlS9WmctxQE9f8n/1PK8lJKkiinn1zARH0="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"eJ+rjKxJ\"; dkim-atps=neutral","Date":"Mon, 16 Jan 2023 01:48:58 +0200","To":"Harvey Yang <chenghaoyang@chromium.org>","Message-ID":"<Y8SQ6s2FQaJMb9KD@pendragon.ideasonboard.com>","References":"<20221214093330.3345421-1-chenghaoyang@google.com>\n\t<20221214093330.3345421-7-chenghaoyang@google.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20221214093330.3345421-7-chenghaoyang@google.com>","Subject":"Re: [libcamera-devel] [PATCH v8 6/7] Pass StreamBuffer to\n\tEncoder::encoder","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]