[{"id":26015,"web_url":"https://patchwork.libcamera.org/comment/26015/","msgid":"<Y5AgsHJjbMBrt6MR@pendragon.ideasonboard.com>","date":"2022-12-07T05:12:16","subject":"Re: [libcamera-devel] [PATCH v7 6/6] Add JEA implementation","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 Thu, Dec 01, 2022 at 09:27:33AM +0000, Harvey Yang via libcamera-devel wrote:\n> From: Harvey Yang <chenghaoyang@chromium.org>\n> \n> This patch adds JEA implementation to replace Lib Jpeg in cros platform,\n\ns/Lib Jpeg/libjpeg/\ns/cros/CrOS/\n\n> where HW accelerator is available.\n\ns/HW/hardware/\n\n> Signed-off-by: Harvey Yang <chenghaoyang@chromium.org>\n> ---\n>  src/android/cros/camera3_hal.cpp         |  2 +\n>  src/android/cros_mojo_token.h            | 12 +++\n>  src/android/jpeg/encoder_jea.cpp         | 93 ++++++++++++++++++++++++\n>  src/android/jpeg/encoder_jea.h           | 35 +++++++++\n>  src/android/jpeg/meson.build             | 12 ++-\n>  src/android/jpeg/post_processor_jpeg.cpp |  8 ++\n>  6 files changed, 160 insertions(+), 2 deletions(-)\n>  create mode 100644 src/android/cros_mojo_token.h\n>  create mode 100644 src/android/jpeg/encoder_jea.cpp\n>  create mode 100644 src/android/jpeg/encoder_jea.h\n> \n> diff --git a/src/android/cros/camera3_hal.cpp b/src/android/cros/camera3_hal.cpp\n> index fb863b5f..d75afccb 100644\n> --- a/src/android/cros/camera3_hal.cpp\n> +++ b/src/android/cros/camera3_hal.cpp\n> @@ -8,9 +8,11 @@\n>  #include <cros-camera/cros_camera_hal.h>\n>  \n>  #include \"../camera_hal_manager.h\"\n> +#include \"../cros_mojo_token.h\"\n>  \n>  static void set_up([[maybe_unused]] cros::CameraMojoChannelManagerToken *token)\n\nYou can drop [[maybe_unused]].\n\n>  {\n> +\tgCrosMojoToken = token;\n>  }\n>  \n>  static void tear_down()\n> diff --git a/src/android/cros_mojo_token.h b/src/android/cros_mojo_token.h\n> new file mode 100644\n> index 00000000..043c752a\n> --- /dev/null\n> +++ b/src/android/cros_mojo_token.h\n> @@ -0,0 +1,12 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2022, Google Inc.\n> + *\n> + * cros_mojo_token.h - cros-specific mojo token\n> + */\n> +\n> +#pragma once\n> +\n> +#include <cros-camera/cros_camera_hal.h>\n> +\n> +inline cros::CameraMojoChannelManagerToken *gCrosMojoToken = nullptr;\n> diff --git a/src/android/jpeg/encoder_jea.cpp b/src/android/jpeg/encoder_jea.cpp\n> new file mode 100644\n> index 00000000..66a854c4\n> --- /dev/null\n> +++ b/src/android/jpeg/encoder_jea.cpp\n> @@ -0,0 +1,93 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2022, Google Inc.\n> + *\n> + * encoder_jea.cpp - JPEG encoding using CrOS JEA\n> + */\n> +\n> +#include \"encoder_jea.h\"\n> +\n> +#include \"libcamera/internal/mapped_framebuffer.h\"\n> +\n> +#include <cros-camera/camera_mojo_channel_manager_token.h>\n> +\n> +#include \"../cros_mojo_token.h\"\n> +#include \"../hal_framebuffer.h\"\n> +\n> +EncoderJea::EncoderJea() = default;\n> +\n> +EncoderJea::~EncoderJea() = default;\n> +\n> +int EncoderJea::configure(const libcamera::StreamConfiguration &cfg)\n> +{\n> +\tsize_ = cfg.size;\n> +\n> +\tif (jpegCompressor_)\n> +\t\treturn 0;\n> +\n> +\tif (gCrosMojoToken == nullptr)\n> +\t\treturn -ENOTSUP;\n> +\n> +\tjpegCompressor_ = cros::JpegCompressor::GetInstance(gCrosMojoToken);\n> +\n> +\treturn 0;\n> +}\n> +\n> +int EncoderJea::encode(Camera3RequestDescriptor::StreamBuffer *streamBuffer,\n> +\t\t       libcamera::Span<const uint8_t> exifData,\n> +\t\t       unsigned int quality)\n> +{\n> +\tif (!jpegCompressor_)\n> +\t\treturn -ENOTSUP;\n> +\n> +\tuint32_t outDataSize = 0;\n> +\tconst HALFrameBuffer *fb = dynamic_cast<const HALFrameBuffer *>(\n> +\t\tstreamBuffer->srcBuffer);\n\nIt looks like we could avoid subclassing FrameBuffer (basically dropping\npatches 1/6 and 2/6) if we stored the handle in the StreamBuffer class\ninstead of in HALFrameBuffer. We can keep it as-is for now, I'm\ninterested in experimenting with inheriting from FrameBuffer, but maybe\nthat will change in the future.\n\n> +\n> +\tif (!jpegCompressor_->CompressImageFromHandle(fb->handle(),\n> +\t\t\t\t\t\t      *streamBuffer->camera3Buffer,\n> +\t\t\t\t\t\t      size_.width, size_.height,\n> +\t\t\t\t\t\t      quality, exifData.data(),\n> +\t\t\t\t\t\t      exifData.size(),\n> +\t\t\t\t\t\t      &outDataSize))\n> +\t\treturn -EBUSY;\n> +\n> +\treturn outDataSize;\n> +}\n> +\n> +int EncoderJea::generateThumbnail(const libcamera::FrameBuffer &source,\n> +\t\t\t\t  const libcamera::Size &targetSize,\n> +\t\t\t\t  unsigned int quality,\n> +\t\t\t\t  std::vector<unsigned char> *thumbnail)\n> +{\n> +\tif (!jpegCompressor_)\n> +\t\treturn -ENOTSUP;\n> +\n> +\tlibcamera::MappedFrameBuffer frame(&source,\n> +\t\t\t\t\t   libcamera::MappedFrameBuffer::MapFlag::Read);\n> +\n> +\tif (frame.planes().empty())\n> +\t\treturn -ENODATA;\n> +\n> +\tuint32_t outDataSize = 0;\n> +\n> +\t// Since the structure of the App1 segment is like:\n> +\t//   0xFF [1 byte marker] [2 bytes size] [data]\n> +\t// And it should not be larger than 64K.\n\nC-style comments.\n\n> +\tconst int kApp1MaxDataSize = 65532;\n\nconstexpr\n\n> +\tthumbnail->resize(kApp1MaxDataSize);\n> +\n> +\tif (!jpegCompressor_->GenerateThumbnail(frame.planes()[0].data(),\n> +\t\t\t\t\t\tsize_.width, size_.height,\n> +\t\t\t\t\t\ttargetSize.width,\n> +\t\t\t\t\t\ttargetSize.height, quality,\n> +\t\t\t\t\t\tthumbnail->size(),\n> +\t\t\t\t\t\tthumbnail->data(),\n> +\t\t\t\t\t\t&outDataSize)) {\n> +\t\tthumbnail->clear();\n> +\t\treturn -EBUSY;\n> +\t}\n> +\n> +\tthumbnail->resize(outDataSize);\n> +\treturn outDataSize;\n> +}\n> diff --git a/src/android/jpeg/encoder_jea.h b/src/android/jpeg/encoder_jea.h\n> new file mode 100644\n> index 00000000..2eba31c2\n> --- /dev/null\n> +++ b/src/android/jpeg/encoder_jea.h\n> @@ -0,0 +1,35 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2022, Google Inc.\n> + *\n> + * encoder_jea.h - JPEG encoding using CrOS JEA\n> + */\n> +\n> +#pragma once\n> +\n> +#include <libcamera/geometry.h>\n> +\n> +#include <cros-camera/jpeg_compressor.h>\n> +\n> +#include \"encoder.h\"\n> +\n> +class EncoderJea : public Encoder\n> +{\n> +public:\n> +\tEncoderJea();\n> +\t~EncoderJea();\n> +\n> +\tint configure(const libcamera::StreamConfiguration &cfg) override;\n> +\tint encode(Camera3RequestDescriptor::StreamBuffer *streamBuffer,\n> +\t\t   libcamera::Span<const uint8_t> exifData,\n> +\t\t   unsigned int quality) override;\n> +\tint generateThumbnail(const libcamera::FrameBuffer &source,\n> +\t\t\t      const libcamera::Size &targetSize,\n> +\t\t\t      unsigned int quality,\n> +\t\t\t      std::vector<unsigned char> *thumbnail) override;\n> +\n> +private:\n> +\tlibcamera::Size size_;\n> +\n> +\tstd::unique_ptr<cros::JpegCompressor> jpegCompressor_;\n> +};\n> diff --git a/src/android/jpeg/meson.build b/src/android/jpeg/meson.build\n> index 08397a87..d25016b1 100644\n> --- a/src/android/jpeg/meson.build\n> +++ b/src/android/jpeg/meson.build\n> @@ -1,8 +1,16 @@\n>  # SPDX-License-Identifier: CC0-1.0\n>  \n>  android_hal_sources += files([\n> -    'encoder_libjpeg.cpp',\n>      'exif.cpp',\n>      'post_processor_jpeg.cpp',\n> -    'thumbnailer.cpp'\n>  ])\n> +\n> +platform = get_option('android_platform')\n> +if platform == 'generic'\n> +    android_hal_sources += files(['encoder_libjpeg.cpp',\n> +                                  'thumbnailer.cpp'\n> +    ])\n\n    android_hal_sources += files([\n        'encoder_libjpeg.cpp',\n        'thumbnailer.cpp',\n    ])\n\n> +elif platform == 'cros'\n> +    android_hal_sources += files(['encoder_jea.cpp'])\n> +    android_deps += [dependency('libcros_camera')]\n> +endif\n> diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp\n> index 10ac4666..15115424 100644\n> --- a/src/android/jpeg/post_processor_jpeg.cpp\n> +++ b/src/android/jpeg/post_processor_jpeg.cpp\n> @@ -12,7 +12,11 @@\n>  #include \"../camera_device.h\"\n>  #include \"../camera_metadata.h\"\n>  #include \"../camera_request.h\"\n> +#if defined(OS_CHROMEOS)\n> +#include \"encoder_jea.h\"\n> +#else // !defined(OS_CHROMEOS)\n\nC-style comments.\n\n>  #include \"encoder_libjpeg.h\"\n> +#endif\n>  #include \"exif.h\"\n>  \n>  #include <libcamera/base/log.h>\n> @@ -44,7 +48,11 @@ int PostProcessorJpeg::configure(const StreamConfiguration &inCfg,\n>  \n>  \tstreamSize_ = outCfg.size;\n>  \n> +#if defined(OS_CHROMEOS)\n> +\tencoder_ = std::make_unique<EncoderJea>();\n> +#else // !defined(OS_CHROMEOS)\n\nSame here.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  \tencoder_ = std::make_unique<EncoderLibJpeg>();\n> +#endif\n>  \n>  \treturn encoder_->configure(inCfg);\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 ADA15BE08B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  7 Dec 2022 05:12:21 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 24FDD63336;\n\tWed,  7 Dec 2022 06:12:21 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6BC2761F1C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  7 Dec 2022 06:12:19 +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 BC2FC3D7;\n\tWed,  7 Dec 2022 06:12:18 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1670389941;\n\tbh=43DgCbB0/GABvUh0gbbgKPmt3E6qjOzL3Rz1/F8z3ew=;\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=DhyxSqoVy/SxIcQwilw6eVG1oWUVyUHc6mgk/IxbDXPfUCLA2RvAMum+CSzjA9Ynb\n\tGABQloZ1xz+YrDZi3B+vPKiFf0eI26WCv9j5lypgziPUe/8Jz2Oisy6q2QEkZ1iuOS\n\tc8uG+LI0Faz2nB39g/VhD6b6vACJ8hWQ5qlw2OaSqDhmU21VjnKOIhxVCpSUyzhvTZ\n\tRHv8c6S5bVLJoZAQzpyeL1Y6vxVgIqu7nxn6ax7lqM4Ys6EMBWNGr7Kv4fLx6ZcVdd\n\tUMzGG+EJKz5DZDoN5O2UZX7oqrTLhOdqYuz6hJbRNNg2GgD0XBOUj7co2ZZTWIsoZz\n\ttqgFgmzeyzPkA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1670389939;\n\tbh=43DgCbB0/GABvUh0gbbgKPmt3E6qjOzL3Rz1/F8z3ew=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=QvFl9NdWBAl/iNKdK7ctgi8b3hD3Pytj93eaooTrh1tefOWAmy5I01jrtijws5f5b\n\tPeIftQi2Qb7oEDbX1yG1PJnzQOx4ubVdDOSnPcgL9u32FTTH3spuqp+/cXUdkgdpf3\n\t0Z4nNkF2nufoF5DxwP0v+ow9wyV/hNMlERlB8NRU="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"QvFl9NdW\"; dkim-atps=neutral","Date":"Wed, 7 Dec 2022 07:12:16 +0200","To":"Harvey Yang <chenghaoyang@chromium.org>","Message-ID":"<Y5AgsHJjbMBrt6MR@pendragon.ideasonboard.com>","References":"<20221201092733.2042078-1-chenghaoyang@google.com>\n\t<20221201092733.2042078-7-chenghaoyang@google.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20221201092733.2042078-7-chenghaoyang@google.com>","Subject":"Re: [libcamera-devel] [PATCH v7 6/6] Add JEA implementation","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>"}},{"id":26069,"web_url":"https://patchwork.libcamera.org/comment/26069/","msgid":"<CAEB1ahu3VUrEb0rkMVBSZsE64Zw5r0jt6BuipVX5gzM6xjBsyg@mail.gmail.com>","date":"2022-12-14T09:36:06","subject":"Re: [libcamera-devel] [PATCH v7 6/6] Add JEA implementation","submitter":{"id":117,"url":"https://patchwork.libcamera.org/api/people/117/","name":"Cheng-Hao Yang","email":"chenghaoyang@chromium.org"},"content":"Thanks Laurent!\n\nI added some code in |EncoderJea::generateThumbnail| to fix\na memory issue (that JEA needs the memory of the frame to\nbe consecutive).\n\nPlease check again and I'll add your reviewed tag. Thanks again!\n\nOn Wed, Dec 7, 2022 at 1:12 PM Laurent Pinchart <\nlaurent.pinchart@ideasonboard.com> wrote:\n\n> Hi Harvey,\n>\n> Thank you for the patch.\n>\n> On Thu, Dec 01, 2022 at 09:27:33AM +0000, Harvey Yang via libcamera-devel\n> wrote:\n> > From: Harvey Yang <chenghaoyang@chromium.org>\n> >\n> > This patch adds JEA implementation to replace Lib Jpeg in cros platform,\n>\n> s/Lib Jpeg/libjpeg/\n> s/cros/CrOS/\n>\n>\nDone.\n\n\n> > where HW accelerator is available.\n>\n> s/HW/hardware/\n>\n>\nDone.\n\n\n> > Signed-off-by: Harvey Yang <chenghaoyang@chromium.org>\n> > ---\n> >  src/android/cros/camera3_hal.cpp         |  2 +\n> >  src/android/cros_mojo_token.h            | 12 +++\n> >  src/android/jpeg/encoder_jea.cpp         | 93 ++++++++++++++++++++++++\n> >  src/android/jpeg/encoder_jea.h           | 35 +++++++++\n> >  src/android/jpeg/meson.build             | 12 ++-\n> >  src/android/jpeg/post_processor_jpeg.cpp |  8 ++\n> >  6 files changed, 160 insertions(+), 2 deletions(-)\n> >  create mode 100644 src/android/cros_mojo_token.h\n> >  create mode 100644 src/android/jpeg/encoder_jea.cpp\n> >  create mode 100644 src/android/jpeg/encoder_jea.h\n> >\n> > diff --git a/src/android/cros/camera3_hal.cpp\n> b/src/android/cros/camera3_hal.cpp\n> > index fb863b5f..d75afccb 100644\n> > --- a/src/android/cros/camera3_hal.cpp\n> > +++ b/src/android/cros/camera3_hal.cpp\n> > @@ -8,9 +8,11 @@\n> >  #include <cros-camera/cros_camera_hal.h>\n> >\n> >  #include \"../camera_hal_manager.h\"\n> > +#include \"../cros_mojo_token.h\"\n> >\n> >  static void set_up([[maybe_unused]] cros::CameraMojoChannelManagerToken\n> *token)\n>\n> You can drop [[maybe_unused]].\n>\n>\nDone.\n\n\n> >  {\n> > +     gCrosMojoToken = token;\n> >  }\n> >\n> >  static void tear_down()\n> > diff --git a/src/android/cros_mojo_token.h\n> b/src/android/cros_mojo_token.h\n> > new file mode 100644\n> > index 00000000..043c752a\n> > --- /dev/null\n> > +++ b/src/android/cros_mojo_token.h\n> > @@ -0,0 +1,12 @@\n> > +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> > +/*\n> > + * Copyright (C) 2022, Google Inc.\n> > + *\n> > + * cros_mojo_token.h - cros-specific mojo token\n> > + */\n> > +\n> > +#pragma once\n> > +\n> > +#include <cros-camera/cros_camera_hal.h>\n> > +\n> > +inline cros::CameraMojoChannelManagerToken *gCrosMojoToken = nullptr;\n> > diff --git a/src/android/jpeg/encoder_jea.cpp\n> b/src/android/jpeg/encoder_jea.cpp\n> > new file mode 100644\n> > index 00000000..66a854c4\n> > --- /dev/null\n> > +++ b/src/android/jpeg/encoder_jea.cpp\n> > @@ -0,0 +1,93 @@\n> > +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> > +/*\n> > + * Copyright (C) 2022, Google Inc.\n> > + *\n> > + * encoder_jea.cpp - JPEG encoding using CrOS JEA\n> > + */\n> > +\n> > +#include \"encoder_jea.h\"\n> > +\n> > +#include \"libcamera/internal/mapped_framebuffer.h\"\n> > +\n> > +#include <cros-camera/camera_mojo_channel_manager_token.h>\n> > +\n> > +#include \"../cros_mojo_token.h\"\n> > +#include \"../hal_framebuffer.h\"\n> > +\n> > +EncoderJea::EncoderJea() = default;\n> > +\n> > +EncoderJea::~EncoderJea() = default;\n> > +\n> > +int EncoderJea::configure(const libcamera::StreamConfiguration &cfg)\n> > +{\n> > +     size_ = cfg.size;\n> > +\n> > +     if (jpegCompressor_)\n> > +             return 0;\n> > +\n> > +     if (gCrosMojoToken == nullptr)\n> > +             return -ENOTSUP;\n> > +\n> > +     jpegCompressor_ =\n> cros::JpegCompressor::GetInstance(gCrosMojoToken);\n> > +\n> > +     return 0;\n> > +}\n> > +\n> > +int EncoderJea::encode(Camera3RequestDescriptor::StreamBuffer\n> *streamBuffer,\n> > +                    libcamera::Span<const uint8_t> exifData,\n> > +                    unsigned int quality)\n> > +{\n> > +     if (!jpegCompressor_)\n> > +             return -ENOTSUP;\n> > +\n> > +     uint32_t outDataSize = 0;\n> > +     const HALFrameBuffer *fb = dynamic_cast<const HALFrameBuffer *>(\n> > +             streamBuffer->srcBuffer);\n>\n> It looks like we could avoid subclassing FrameBuffer (basically dropping\n> patches 1/6 and 2/6) if we stored the handle in the StreamBuffer class\n> instead of in HALFrameBuffer. We can keep it as-is for now, I'm\n> interested in experimenting with inheriting from FrameBuffer, but maybe\n> that will change in the future.\n>\n>\nSeems cool, while I'm not sure how to elegantly pass the handle from\n|PlatformFrameBufferAllocator| :p\n\n\n> > +\n> > +     if (!jpegCompressor_->CompressImageFromHandle(fb->handle(),\n> > +\n>  *streamBuffer->camera3Buffer,\n> > +                                                   size_.width,\n> size_.height,\n> > +                                                   quality,\n> exifData.data(),\n> > +                                                   exifData.size(),\n> > +                                                   &outDataSize))\n> > +             return -EBUSY;\n> > +\n> > +     return outDataSize;\n> > +}\n> > +\n> > +int EncoderJea::generateThumbnail(const libcamera::FrameBuffer &source,\n> > +                               const libcamera::Size &targetSize,\n> > +                               unsigned int quality,\n> > +                               std::vector<unsigned char> *thumbnail)\n> > +{\n> > +     if (!jpegCompressor_)\n> > +             return -ENOTSUP;\n> > +\n> > +     libcamera::MappedFrameBuffer frame(&source,\n> > +\n> libcamera::MappedFrameBuffer::MapFlag::Read);\n> > +\n> > +     if (frame.planes().empty())\n> > +             return -ENODATA;\n> > +\n> > +     uint32_t outDataSize = 0;\n> > +\n> > +     // Since the structure of the App1 segment is like:\n> > +     //   0xFF [1 byte marker] [2 bytes size] [data]\n> > +     // And it should not be larger than 64K.\n>\n> C-style comments.\n>\n>\nDo you mean I should wrap it with '/*' & '*/' ?\n\n> > +     const int kApp1MaxDataSize = 65532;\n>\n> constexpr\n>\n>\nDone.\n\n\n> > +     thumbnail->resize(kApp1MaxDataSize);\n> > +\n> > +     if (!jpegCompressor_->GenerateThumbnail(frame.planes()[0].data(),\n> > +                                             size_.width, size_.height,\n> > +                                             targetSize.width,\n> > +                                             targetSize.height, quality,\n> > +                                             thumbnail->size(),\n> > +                                             thumbnail->data(),\n> > +                                             &outDataSize)) {\n> > +             thumbnail->clear();\n> > +             return -EBUSY;\n> > +     }\n> > +\n> > +     thumbnail->resize(outDataSize);\n> > +     return outDataSize;\n> > +}\n> > diff --git a/src/android/jpeg/encoder_jea.h\n> b/src/android/jpeg/encoder_jea.h\n> > new file mode 100644\n> > index 00000000..2eba31c2\n> > --- /dev/null\n> > +++ b/src/android/jpeg/encoder_jea.h\n> > @@ -0,0 +1,35 @@\n> > +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> > +/*\n> > + * Copyright (C) 2022, Google Inc.\n> > + *\n> > + * encoder_jea.h - JPEG encoding using CrOS JEA\n> > + */\n> > +\n> > +#pragma once\n> > +\n> > +#include <libcamera/geometry.h>\n> > +\n> > +#include <cros-camera/jpeg_compressor.h>\n> > +\n> > +#include \"encoder.h\"\n> > +\n> > +class EncoderJea : public Encoder\n> > +{\n> > +public:\n> > +     EncoderJea();\n> > +     ~EncoderJea();\n> > +\n> > +     int configure(const libcamera::StreamConfiguration &cfg) override;\n> > +     int encode(Camera3RequestDescriptor::StreamBuffer *streamBuffer,\n> > +                libcamera::Span<const uint8_t> exifData,\n> > +                unsigned int quality) override;\n> > +     int generateThumbnail(const libcamera::FrameBuffer &source,\n> > +                           const libcamera::Size &targetSize,\n> > +                           unsigned int quality,\n> > +                           std::vector<unsigned char> *thumbnail)\n> override;\n> > +\n> > +private:\n> > +     libcamera::Size size_;\n> > +\n> > +     std::unique_ptr<cros::JpegCompressor> jpegCompressor_;\n> > +};\n> > diff --git a/src/android/jpeg/meson.build b/src/android/jpeg/meson.build\n> > index 08397a87..d25016b1 100644\n> > --- a/src/android/jpeg/meson.build\n> > +++ b/src/android/jpeg/meson.build\n> > @@ -1,8 +1,16 @@\n> >  # SPDX-License-Identifier: CC0-1.0\n> >\n> >  android_hal_sources += files([\n> > -    'encoder_libjpeg.cpp',\n> >      'exif.cpp',\n> >      'post_processor_jpeg.cpp',\n> > -    'thumbnailer.cpp'\n> >  ])\n> > +\n> > +platform = get_option('android_platform')\n> > +if platform == 'generic'\n> > +    android_hal_sources += files(['encoder_libjpeg.cpp',\n> > +                                  'thumbnailer.cpp'\n> > +    ])\n>\n>     android_hal_sources += files([\n>         'encoder_libjpeg.cpp',\n>         'thumbnailer.cpp',\n>     ])\n>\n>\nDone.\n\n\n> > +elif platform == 'cros'\n> > +    android_hal_sources += files(['encoder_jea.cpp'])\n> > +    android_deps += [dependency('libcros_camera')]\n> > +endif\n> > diff --git a/src/android/jpeg/post_processor_jpeg.cpp\n> b/src/android/jpeg/post_processor_jpeg.cpp\n> > index 10ac4666..15115424 100644\n> > --- a/src/android/jpeg/post_processor_jpeg.cpp\n> > +++ b/src/android/jpeg/post_processor_jpeg.cpp\n> > @@ -12,7 +12,11 @@\n> >  #include \"../camera_device.h\"\n> >  #include \"../camera_metadata.h\"\n> >  #include \"../camera_request.h\"\n> > +#if defined(OS_CHROMEOS)\n> > +#include \"encoder_jea.h\"\n> > +#else // !defined(OS_CHROMEOS)\n>\n> C-style comments.\n>\n>\nSorry, I don't get what you mean. Could you elaborate? :p\n\n\n> >  #include \"encoder_libjpeg.h\"\n> > +#endif\n> >  #include \"exif.h\"\n> >\n> >  #include <libcamera/base/log.h>\n> > @@ -44,7 +48,11 @@ int PostProcessorJpeg::configure(const\n> StreamConfiguration &inCfg,\n> >\n> >       streamSize_ = outCfg.size;\n> >\n> > +#if defined(OS_CHROMEOS)\n> > +     encoder_ = std::make_unique<EncoderJea>();\n> > +#else // !defined(OS_CHROMEOS)\n>\n> Same here.\n>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n>\n> >       encoder_ = std::make_unique<EncoderLibJpeg>();\n> > +#endif\n> >\n> >       return encoder_->configure(inCfg);\n> >  }\n>\n> --\n> Regards,\n>\n> Laurent Pinchart\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 B7E44C31E9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 14 Dec 2022 09:36:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7411463362;\n\tWed, 14 Dec 2022 10:36:20 +0100 (CET)","from mail-vk1-xa2b.google.com (mail-vk1-xa2b.google.com\n\t[IPv6:2607:f8b0:4864:20::a2b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9CC3C603D0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 14 Dec 2022 10:36:18 +0100 (CET)","by mail-vk1-xa2b.google.com with SMTP id f24so2858159vkl.9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 14 Dec 2022 01:36:18 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1671010580;\n\tbh=MKVP47HdMVL8l9qobd5thIE0gT9v78ph5sKax2G4xlU=;\n\th=References:In-Reply-To:Date:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=O0ZPysN0EQsU6MCvR1/KL3ED5p3PXpTAGOMJPiZLGavHKr+lf0H5HEoQxzsCd1ySo\n\tmnm2nJKV0DI/hhrDeaoLdcS9IgxAlV+2rG8fybLnk/iWruC6p9HXo3zJHNAZ+ip1kH\n\tw69Ll2oq6YsCa1R4F5Oqd51UsTqhbW0Za8riIiCf+BVLjeKtH9rTPdY93cVjF1m+aq\n\tYnRfNtUSvoBsnt9PWe64iAbPv//WLIrsW/KRtyLj2r5eSf3iN9pcMcJYrF/L1UNHAv\n\tMiJmwigDA/v4a/6X5qH6W66gKcWgh+AzT8qLkMSzZwXqL+uHyfn6QNNC5vzNo33Sgl\n\tKF+vKVxXt3JWg==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=2zrAAjaA+Slis89VYw8UaZF7jupGKxyoQVFi2aM6cqs=;\n\tb=WfPN5v4JXQrwipLjNtOvjlTuViOA+anA5TZuG6PJZ4kOHDTph3cReaXaaonn8Zr3wy\n\tnQtwinYzDegmlpxsmwyP5GC98W5wAM1pSXmhK5KU/CT8Zm4skEJDCL9OSiRhHFtwmGKz\n\tOVt3lGu8CfinI1RPGT4XPHhgM1CzQtD0EUcWA="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=chromium.org\n\theader.i=@chromium.org header.b=\"WfPN5v4J\"; \n\tdkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=2zrAAjaA+Slis89VYw8UaZF7jupGKxyoQVFi2aM6cqs=;\n\tb=tUoFWwg64+nR3N/alg8iHDl/aJyA2gnvLTgTrw6z/qRCPgk0HetaSaol/9YTuN7+iC\n\tCvZd7uv7MkX4pM51BdrAK0MMvfVDlaA5sZCexqpGfSuaTwWDecrpoAAzob6oW8fOQKac\n\tpCtU6j06jHpXgO5yjCQKEVoXzPPn9zDh1SHomymHfQqBRBbXhjxuoEXEeQKLXRLNad3d\n\tg4GPOiFiPdzfh7SRRV3/E1Wx+xqRRhZA0Iatr3RrdKdD0ffNJOsDyswmP0s9c0SZEdQw\n\tXs4p5DcdCZMv1jxqgLAeIZHgO38Z4lV6DtkKYY5cdHUYtEtU8rZL3NEkrBvDhvEwR5Er\n\tZu/A==","X-Gm-Message-State":"ANoB5pkm2JaB6jK7LFn20QSA79HhzNjvo8BiOlprn89ohzpUahtDSEkE\n\tZe0lWs68wv5vsBqLqJsrjaC4K8DxccEKyRFPjyMvSQTlRCb7DA==","X-Google-Smtp-Source":"AA0mqf6ZnTTOBj1Jm+N6V8u71TjgomnbjrvmrHAtEXPwuNoc0fpXtQdOEiGh075EqN+JkUMqymzDhABJvb/zWu77dzE=","X-Received":"by 2002:a1f:61c5:0:b0:3bd:1956:f892 with SMTP id\n\tv188-20020a1f61c5000000b003bd1956f892mr23284350vkb.16.1671010577558;\n\tWed, 14 Dec 2022 01:36:17 -0800 (PST)","MIME-Version":"1.0","References":"<20221201092733.2042078-1-chenghaoyang@google.com>\n\t<20221201092733.2042078-7-chenghaoyang@google.com>\n\t<Y5AgsHJjbMBrt6MR@pendragon.ideasonboard.com>","In-Reply-To":"<Y5AgsHJjbMBrt6MR@pendragon.ideasonboard.com>","Date":"Wed, 14 Dec 2022 17:36:06 +0800","Message-ID":"<CAEB1ahu3VUrEb0rkMVBSZsE64Zw5r0jt6BuipVX5gzM6xjBsyg@mail.gmail.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Content-Type":"multipart/alternative; boundary=\"000000000000e4473f05efc677e9\"","Subject":"Re: [libcamera-devel] [PATCH v7 6/6] Add JEA implementation","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":"Cheng-Hao Yang via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Cheng-Hao Yang <chenghaoyang@chromium.org>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]