[{"id":12974,"web_url":"https://patchwork.libcamera.org/comment/12974/","msgid":"<20201005120837.GG3931@pendragon.ideasonboard.com>","date":"2020-10-05T12:08:37","subject":"Re: [libcamera-devel] [PATCH 05/15] android: camera_device: Move\n\tprocessing to CameraStream","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 Mon, Oct 05, 2020 at 01:46:39PM +0300, Laurent Pinchart wrote:\n> From: Jacopo Mondi <jacopo@jmondi.org>\n> \n> Move the JPEG processing procedure to the individual CameraStream\n> by augmenting the class with a CameraStream::process() method.\n> \n> This allows removing the CameraStream::encoder() method.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/android/camera_device.cpp | 68 ++---------------------------------\n>  src/android/camera_device.h   |  8 +++++\n>  src/android/camera_stream.cpp | 63 ++++++++++++++++++++++++++++++++\n>  src/android/camera_stream.h   |  7 +++-\n>  4 files changed, 80 insertions(+), 66 deletions(-)\n> \n> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n> index 2c4dd4dee28c..c44904300e0a 100644\n> --- a/src/android/camera_device.cpp\n> +++ b/src/android/camera_device.cpp\n> @@ -23,9 +23,6 @@\n>  #include \"camera_metadata.h\"\n>  #include \"system/graphics.h\"\n>  \n> -#include \"jpeg/encoder_libjpeg.h\"\n> -#include \"jpeg/exif.h\"\n> -\n>  using namespace libcamera;\n>  \n>  namespace {\n> @@ -133,12 +130,6 @@ const std::map<int, const Camera3Format> camera3FormatsMap = {\n>  \n>  LOG_DECLARE_CATEGORY(HAL);\n>  \n> -class MappedCamera3Buffer : public MappedBuffer\n> -{\n> -public:\n> -\tMappedCamera3Buffer(const buffer_handle_t camera3buffer, int flags);\n> -};\n> -\n>  MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer,\n>  \t\t\t\t\t int flags)\n>  {\n> @@ -1471,12 +1462,6 @@ void CameraDevice::requestComplete(Request *request)\n>  \t\tif (cameraStream->outputFormat() != HAL_PIXEL_FORMAT_BLOB)\n>  \t\t\tcontinue;\n>  \n> -\t\tEncoder *encoder = cameraStream->encoder();\n> -\t\tif (!encoder) {\n> -\t\t\tLOG(HAL, Error) << \"Failed to identify encoder\";\n> -\t\t\tcontinue;\n> -\t\t}\n> -\n>  \t\tStreamConfiguration *streamConfiguration = &config_->at(cameraStream->index());\n>  \t\tStream *stream = streamConfiguration->stream();\n>  \t\tFrameBuffer *buffer = request->findBuffer(stream);\n> @@ -1497,59 +1482,12 @@ void CameraDevice::requestComplete(Request *request)\n>  \t\t\tcontinue;\n>  \t\t}\n>  \n> -\t\t/* Set EXIF metadata for various tags. */\n> -\t\tExif exif;\n> -\t\t/* \\todo Set Make and Model from external vendor tags. */\n> -\t\texif.setMake(\"libcamera\");\n> -\t\texif.setModel(\"cameraModel\");\n> -\t\texif.setOrientation(orientation_);\n> -\t\texif.setSize(cameraStream->size());\n> -\t\t/*\n> -\t\t * We set the frame's EXIF timestamp as the time of encode.\n> -\t\t * Since the precision we need for EXIF timestamp is only one\n> -\t\t * second, it is good enough.\n> -\t\t */\n> -\t\texif.setTimestamp(std::time(nullptr));\n> -\t\tif (exif.generate() != 0)\n> -\t\t\tLOG(HAL, Error) << \"Failed to generate valid EXIF data\";\n> -\n> -\t\tint jpeg_size = encoder->encode(buffer, mapped.maps()[0], exif.data());\n> -\t\tif (jpeg_size < 0) {\n> -\t\t\tLOG(HAL, Error) << \"Failed to encode stream image\";\n> +\t\tint ret = cameraStream->process(buffer, &mapped,\n> +\t\t\t\t\t\tresultMetadata.get());\n> +\t\tif (ret) {\n>  \t\t\tstatus = CAMERA3_BUFFER_STATUS_ERROR;\n>  \t\t\tcontinue;\n>  \t\t}\n> -\n> -\t\t/*\n> -\t\t * Fill in the JPEG blob header.\n> -\t\t *\n> -\t\t * The mapped size of the buffer is being returned as\n> -\t\t * substantially larger than the requested JPEG_MAX_SIZE\n> -\t\t * (which is referenced from maxJpegBufferSize_). Utilise\n> -\t\t * this static size to ensure the correct offset of the blob is\n> -\t\t * determined.\n> -\t\t *\n> -\t\t * \\todo Investigate if the buffer size mismatch is an issue or\n> -\t\t * expected behaviour.\n> -\t\t */\n> -\t\tuint8_t *resultPtr = mapped.maps()[0].data() +\n> -\t\t\t\t     maxJpegBufferSize_ -\n> -\t\t\t\t     sizeof(struct camera3_jpeg_blob);\n> -\t\tauto *blob = reinterpret_cast<struct camera3_jpeg_blob *>(resultPtr);\n> -\t\tblob->jpeg_blob_id = CAMERA3_JPEG_BLOB_ID;\n> -\t\tblob->jpeg_size = jpeg_size;\n> -\n> -\t\t/* Update the JPEG result Metadata. */\n> -\t\tresultMetadata->addEntry(ANDROID_JPEG_SIZE,\n> -\t\t\t\t\t &jpeg_size, 1);\n> -\n> -\t\tconst uint32_t jpeg_quality = 95;\n> -\t\tresultMetadata->addEntry(ANDROID_JPEG_QUALITY,\n> -\t\t\t\t\t &jpeg_quality, 1);\n> -\n> -\t\tconst uint32_t jpeg_orientation = 0;\n> -\t\tresultMetadata->addEntry(ANDROID_JPEG_ORIENTATION,\n> -\t\t\t\t\t &jpeg_orientation, 1);\n>  \t}\n>  \n>  \t/* Prepare to call back the Android camera stack. */\n> diff --git a/src/android/camera_device.h b/src/android/camera_device.h\n> index 4e326fa3e1fb..826023b453f7 100644\n> --- a/src/android/camera_device.h\n> +++ b/src/android/camera_device.h\n> @@ -20,6 +20,7 @@\n>  #include <libcamera/request.h>\n>  #include <libcamera/stream.h>\n>  \n> +#include \"libcamera/internal/buffer.h\"\n>  #include \"libcamera/internal/log.h\"\n>  #include \"libcamera/internal/message.h\"\n>  \n> @@ -28,6 +29,12 @@\n>  \n>  class CameraMetadata;\n>  \n> +class MappedCamera3Buffer : public libcamera::MappedBuffer\n> +{\n> +public:\n> +\tMappedCamera3Buffer(const buffer_handle_t camera3buffer, int flags);\n> +};\n> +\n>  class CameraDevice : protected libcamera::Loggable\n>  {\n>  public:\n> @@ -50,6 +57,7 @@ public:\n>  \n>  \tint facing() const { return facing_; }\n>  \tint orientation() const { return orientation_; }\n> +\tunsigned int maxJpegBufferSize() const { return maxJpegBufferSize_; }\n>  \n>  \tvoid setCallbacks(const camera3_callback_ops_t *callbacks);\n>  \tconst camera_metadata_t *getStaticMetadata();\n> diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp\n> index 5c1f1d7da416..072edc9457bb 100644\n> --- a/src/android/camera_stream.cpp\n> +++ b/src/android/camera_stream.cpp\n> @@ -8,10 +8,14 @@\n>  #include \"camera_stream.h\"\n>  \n>  #include \"camera_device.h\"\n> +#include \"camera_metadata.h\"\n>  #include \"jpeg/encoder_libjpeg.h\"\n> +#include \"jpeg/exif.h\"\n>  \n>  using namespace libcamera;\n>  \n> +LOG_DECLARE_CATEGORY(HAL);\n> +\n>  CameraStream::CameraStream(CameraDevice *cameraDev,\n>  \t\t\t   camera3_stream_t *androidStream,\n>  \t\t\t   const libcamera::StreamConfiguration &cfg,\n> @@ -35,3 +39,62 @@ int CameraStream::configure(const libcamera::StreamConfiguration &cfg)\n>  \n>  \treturn 0;\n>  }\n> +\n> +int CameraStream::process(libcamera::FrameBuffer *source, MappedCamera3Buffer *dest,\n> +\t\t\t  CameraMetadata *metadata)\n> +{\n> +\tif (!encoder_)\n> +\t\treturn -EINVAL;\n\nMaybe that's addressed by subsequent patches in this series, but down\nthe line I would envision process() being called for all CameraStream\ninstances, so if no processing is required, this should then return 0.\n\n> +\n> +\t/* Set EXIF metadata for various tags. */\n> +\tExif exif;\n> +\t/* \\todo Set Make and Model from external vendor tags. */\n> +\texif.setMake(\"libcamera\");\n> +\texif.setModel(\"cameraModel\");\n> +\texif.setOrientation(cameraDevice_->orientation());\n> +\texif.setSize(size_);\n> +\t/*\n> +\t * We set the frame's EXIF timestamp as the time of encode.\n> +\t * Since the precision we need for EXIF timestamp is only one\n> +\t * second, it is good enough.\n> +\t */\n> +\texif.setTimestamp(std::time(nullptr));\n> +\tif (exif.generate() != 0)\n> +\t\tLOG(HAL, Error) << \"Failed to generate valid EXIF data\";\n> +\n> +\tint jpeg_size = encoder_->encode(source, dest->maps()[0], exif.data());\n> +\tif (jpeg_size < 0) {\n> +\t\tLOG(HAL, Error) << \"Failed to encode stream image\";\n> +\t\treturn jpeg_size;\n> +\t}\n> +\n> +\t/*\n> +\t * Fill in the JPEG blob header.\n> +\t *\n> +\t * The mapped size of the buffer is being returned as\n> +\t * substantially larger than the requested JPEG_MAX_SIZE\n> +\t * (which is referenced from maxJpegBufferSize_). Utilise\n> +\t * this static size to ensure the correct offset of the blob is\n> +\t * determined.\n> +\t *\n> +\t * \\todo Investigate if the buffer size mismatch is an issue or\n> +\t * expected behaviour.\n> +\t */\n> +\tuint8_t *resultPtr = dest->maps()[0].data() +\n> +\t\t\t     cameraDevice_->maxJpegBufferSize() -\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;\n> +\tblob->jpeg_size = jpeg_size;\n> +\n> +\t/* Update the JPEG result Metadata. */\n> +\tmetadata->addEntry(ANDROID_JPEG_SIZE, &jpeg_size, 1);\n> +\n> +\tconst uint32_t jpeg_quality = 95;\n> +\tmetadata->addEntry(ANDROID_JPEG_QUALITY, &jpeg_quality, 1);\n> +\n> +\tconst uint32_t jpeg_orientation = 0;\n> +\tmetadata->addEntry(ANDROID_JPEG_ORIENTATION, &jpeg_orientation, 1);\n> +\n> +\treturn 0;\n> +}\n> diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h\n> index 2d71a50c78a4..dbcd1e53219f 100644\n> --- a/src/android/camera_stream.h\n> +++ b/src/android/camera_stream.h\n> @@ -11,6 +11,7 @@\n>  \n>  #include <hardware/camera3.h>\n>  \n> +#include <libcamera/buffer.h>\n>  #include <libcamera/camera.h>\n>  #include <libcamera/geometry.h>\n>  #include <libcamera/pixel_format.h>\n> @@ -18,6 +19,8 @@\n>  #include \"jpeg/encoder.h\"\n>  \n>  class CameraDevice;\n> +class CameraMetadata;\n> +class MappedCamera3Buffer;\n>  \n>  class CameraStream\n>  {\n> @@ -114,9 +117,11 @@ public:\n>  \tconst libcamera::Size &size() const { return size_; }\n>  \tType type() const { return type_; }\n>  \tunsigned int index() const { return index_; }\n> -\tEncoder *encoder() const { return encoder_.get(); }\n>  \n>  \tint configure(const libcamera::StreamConfiguration &cfg);\n> +\tint process(libcamera::FrameBuffer *source,\n\nCan source be const ?\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\t\t    MappedCamera3Buffer *dest,\n> +\t\t    CameraMetadata *metadata);\n>  \n>  private:\n>  \tCameraDevice *cameraDevice_;","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 6EBB5C3B5C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  5 Oct 2020 12:09:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id ED59163BED;\n\tMon,  5 Oct 2020 14:09:18 +0200 (CEST)","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 018D163BD5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  5 Oct 2020 14:09:16 +0200 (CEST)","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 6B0913B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  5 Oct 2020 14:09:16 +0200 (CEST)"],"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=\"KHFIvk0V\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1601899756;\n\tbh=ZM2Jiz+w2XRzfufqa0fR1ZyQfc896mIKZNR9POtMwjI=;\n\th=Date:From:To:Subject:References:In-Reply-To:From;\n\tb=KHFIvk0V7Nu0POV1tpwJkD3Hqt54Y+ih23Yu8IgMvyF6UETfNrXptde+3jaBl8oiK\n\tcNUaIyW7fh67nGeb7izUxq6UmuApgpXsFplmlWmfuVIgqGGbyF9rcBT4M/e055BF7g\n\tgGZLq8XwSon9XnLa1ANLFgbIBcrUWrgQGQ5w+EGM=","Date":"Mon, 5 Oct 2020 15:08:37 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Message-ID":"<20201005120837.GG3931@pendragon.ideasonboard.com>","References":"<20201005104649.10812-1-laurent.pinchart@ideasonboard.com>\n\t<20201005104649.10812-6-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20201005104649.10812-6-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 05/15] android: camera_device: Move\n\tprocessing to CameraStream","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>","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":12997,"web_url":"https://patchwork.libcamera.org/comment/12997/","msgid":"<6f8f6f9d-6898-f258-57da-ea66240baba8@ideasonboard.com>","date":"2020-10-05T21:42:25","subject":"Re: [libcamera-devel] [PATCH 05/15] android: camera_device: Move\n\tprocessing to CameraStream","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn 05/10/2020 13:08, Laurent Pinchart wrote:\n> Hi Jacopo,\n> \n> Thank you for the patch.\n> \n> On Mon, Oct 05, 2020 at 01:46:39PM +0300, Laurent Pinchart wrote:\n>> From: Jacopo Mondi <jacopo@jmondi.org>\n>>\n>> Move the JPEG processing procedure to the individual CameraStream\n>> by augmenting the class with a CameraStream::process() method.\n\nIt sounds like it just keeps getting better and better ;-)\n\n\n>> This allows removing the CameraStream::encoder() method.>>\n>> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n>> ---\n>>  src/android/camera_device.cpp | 68 ++---------------------------------\n>>  src/android/camera_device.h   |  8 +++++\n>>  src/android/camera_stream.cpp | 63 ++++++++++++++++++++++++++++++++\n>>  src/android/camera_stream.h   |  7 +++-\n>>  4 files changed, 80 insertions(+), 66 deletions(-)\n>>\n>> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n>> index 2c4dd4dee28c..c44904300e0a 100644\n>> --- a/src/android/camera_device.cpp\n>> +++ b/src/android/camera_device.cpp\n>> @@ -23,9 +23,6 @@\n>>  #include \"camera_metadata.h\"\n>>  #include \"system/graphics.h\"\n>>  \n>> -#include \"jpeg/encoder_libjpeg.h\"\n>> -#include \"jpeg/exif.h\"\n>> -\n>>  using namespace libcamera;\n>>  \n>>  namespace {\n>> @@ -133,12 +130,6 @@ const std::map<int, const Camera3Format> camera3FormatsMap = {\n>>  \n>>  LOG_DECLARE_CATEGORY(HAL);\n>>  \n>> -class MappedCamera3Buffer : public MappedBuffer\n>> -{\n>> -public:\n>> -\tMappedCamera3Buffer(const buffer_handle_t camera3buffer, int flags);\n>> -};\n>> -\n>>  MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer,\n>>  \t\t\t\t\t int flags)\n>>  {\n>> @@ -1471,12 +1462,6 @@ void CameraDevice::requestComplete(Request *request)\n>>  \t\tif (cameraStream->outputFormat() != HAL_PIXEL_FORMAT_BLOB)\n>>  \t\t\tcontinue;\n>>  \n>> -\t\tEncoder *encoder = cameraStream->encoder();\n>> -\t\tif (!encoder) {\n>> -\t\t\tLOG(HAL, Error) << \"Failed to identify encoder\";\n>> -\t\t\tcontinue;\n>> -\t\t}\n>> -\n>>  \t\tStreamConfiguration *streamConfiguration = &config_->at(cameraStream->index());\n>>  \t\tStream *stream = streamConfiguration->stream();\n>>  \t\tFrameBuffer *buffer = request->findBuffer(stream);\n>> @@ -1497,59 +1482,12 @@ void CameraDevice::requestComplete(Request *request)\n>>  \t\t\tcontinue;\n>>  \t\t}\n>>  \n>> -\t\t/* Set EXIF metadata for various tags. */\n>> -\t\tExif exif;\n>> -\t\t/* \\todo Set Make and Model from external vendor tags. */\n>> -\t\texif.setMake(\"libcamera\");\n>> -\t\texif.setModel(\"cameraModel\");\n>> -\t\texif.setOrientation(orientation_);\n>> -\t\texif.setSize(cameraStream->size());\n>> -\t\t/*\n>> -\t\t * We set the frame's EXIF timestamp as the time of encode.\n>> -\t\t * Since the precision we need for EXIF timestamp is only one\n>> -\t\t * second, it is good enough.\n>> -\t\t */\n>> -\t\texif.setTimestamp(std::time(nullptr));\n>> -\t\tif (exif.generate() != 0)\n>> -\t\t\tLOG(HAL, Error) << \"Failed to generate valid EXIF data\";\n>> -\n>> -\t\tint jpeg_size = encoder->encode(buffer, mapped.maps()[0], exif.data());\n>> -\t\tif (jpeg_size < 0) {\n>> -\t\t\tLOG(HAL, Error) << \"Failed to encode stream image\";\n>> +\t\tint ret = cameraStream->process(buffer, &mapped,\n>> +\t\t\t\t\t\tresultMetadata.get());\n>> +\t\tif (ret) {\n>>  \t\t\tstatus = CAMERA3_BUFFER_STATUS_ERROR;\n>>  \t\t\tcontinue;\n>>  \t\t}\n>> -\n>> -\t\t/*\n>> -\t\t * Fill in the JPEG blob header.\n>> -\t\t *\n>> -\t\t * The mapped size of the buffer is being returned as\n>> -\t\t * substantially larger than the requested JPEG_MAX_SIZE\n>> -\t\t * (which is referenced from maxJpegBufferSize_). Utilise\n>> -\t\t * this static size to ensure the correct offset of the blob is\n>> -\t\t * determined.\n>> -\t\t *\n>> -\t\t * \\todo Investigate if the buffer size mismatch is an issue or\n>> -\t\t * expected behaviour.\n>> -\t\t */\n>> -\t\tuint8_t *resultPtr = mapped.maps()[0].data() +\n>> -\t\t\t\t     maxJpegBufferSize_ -\n>> -\t\t\t\t     sizeof(struct camera3_jpeg_blob);\n>> -\t\tauto *blob = reinterpret_cast<struct camera3_jpeg_blob *>(resultPtr);\n>> -\t\tblob->jpeg_blob_id = CAMERA3_JPEG_BLOB_ID;\n>> -\t\tblob->jpeg_size = jpeg_size;\n>> -\n>> -\t\t/* Update the JPEG result Metadata. */\n>> -\t\tresultMetadata->addEntry(ANDROID_JPEG_SIZE,\n>> -\t\t\t\t\t &jpeg_size, 1);\n>> -\n>> -\t\tconst uint32_t jpeg_quality = 95;\n>> -\t\tresultMetadata->addEntry(ANDROID_JPEG_QUALITY,\n>> -\t\t\t\t\t &jpeg_quality, 1);\n>> -\n>> -\t\tconst uint32_t jpeg_orientation = 0;\n>> -\t\tresultMetadata->addEntry(ANDROID_JPEG_ORIENTATION,\n>> -\t\t\t\t\t &jpeg_orientation, 1);\n>>  \t}\n>>  \n>>  \t/* Prepare to call back the Android camera stack. */\n>> diff --git a/src/android/camera_device.h b/src/android/camera_device.h\n>> index 4e326fa3e1fb..826023b453f7 100644\n>> --- a/src/android/camera_device.h\n>> +++ b/src/android/camera_device.h\n>> @@ -20,6 +20,7 @@\n>>  #include <libcamera/request.h>\n>>  #include <libcamera/stream.h>\n>>  \n>> +#include \"libcamera/internal/buffer.h\"\n>>  #include \"libcamera/internal/log.h\"\n>>  #include \"libcamera/internal/message.h\"\n>>  \n>> @@ -28,6 +29,12 @@\n>>  \n>>  class CameraMetadata;\n>>  \n>> +class MappedCamera3Buffer : public libcamera::MappedBuffer\n>> +{\n>> +public:\n>> +\tMappedCamera3Buffer(const buffer_handle_t camera3buffer, int flags);\n>> +};\n>> +\n>>  class CameraDevice : protected libcamera::Loggable\n>>  {\n>>  public:\n>> @@ -50,6 +57,7 @@ public:\n>>  \n>>  \tint facing() const { return facing_; }\n>>  \tint orientation() const { return orientation_; }\n>> +\tunsigned int maxJpegBufferSize() const { return maxJpegBufferSize_; }\n>>  \n>>  \tvoid setCallbacks(const camera3_callback_ops_t *callbacks);\n>>  \tconst camera_metadata_t *getStaticMetadata();\n>> diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp\n>> index 5c1f1d7da416..072edc9457bb 100644\n>> --- a/src/android/camera_stream.cpp\n>> +++ b/src/android/camera_stream.cpp\n>> @@ -8,10 +8,14 @@\n>>  #include \"camera_stream.h\"\n>>  \n>>  #include \"camera_device.h\"\n>> +#include \"camera_metadata.h\"\n>>  #include \"jpeg/encoder_libjpeg.h\"\n>> +#include \"jpeg/exif.h\"\n>>  \n>>  using namespace libcamera;\n>>  \n>> +LOG_DECLARE_CATEGORY(HAL);\n>> +\n>>  CameraStream::CameraStream(CameraDevice *cameraDev,\n>>  \t\t\t   camera3_stream_t *androidStream,\n>>  \t\t\t   const libcamera::StreamConfiguration &cfg,\n>> @@ -35,3 +39,62 @@ int CameraStream::configure(const libcamera::StreamConfiguration &cfg)\n>>  \n>>  \treturn 0;\n>>  }\n>> +\n>> +int CameraStream::process(libcamera::FrameBuffer *source, MappedCamera3Buffer *dest,\n>> +\t\t\t  CameraMetadata *metadata)\n>> +{\n>> +\tif (!encoder_)\n>> +\t\treturn -EINVAL;\n> \n> Maybe that's addressed by subsequent patches in this series, but down\n> the line I would envision process() being called for all CameraStream\n> instances, so if no processing is required, this should then return 0.\n\nI agree here, The CameraDevice shouldn't know/care 'if/what' processing\nis required by a CameraStream. The CameraStream will deal with it all.\n\nOf course, in the current implementation, it might likely still require\nthe CameraDevice to notify the CameraStream that a request has completed.\n\nAt some point, I could see the notification being the Buffer complete\nnotification, which might be earlier than the Request complete ... (to\nreduce delays) - however we will need to make all of this asynchronous\nbefore we go there.\n\n\n>> +\n>> +\t/* Set EXIF metadata for various tags. */\n>> +\tExif exif;\n>> +\t/* \\todo Set Make and Model from external vendor tags. */\n>> +\texif.setMake(\"libcamera\");\n>> +\texif.setModel(\"cameraModel\");\n>> +\texif.setOrientation(cameraDevice_->orientation());\n>> +\texif.setSize(size_);\n>> +\t/*\n>> +\t * We set the frame's EXIF timestamp as the time of encode.\n>> +\t * Since the precision we need for EXIF timestamp is only one\n>> +\t * second, it is good enough.\n>> +\t */\n>> +\texif.setTimestamp(std::time(nullptr));\n>> +\tif (exif.generate() != 0)\n>> +\t\tLOG(HAL, Error) << \"Failed to generate valid EXIF data\";\n>> +\n>> +\tint jpeg_size = encoder_->encode(source, dest->maps()[0], exif.data());\n>> +\tif (jpeg_size < 0) {\n>> +\t\tLOG(HAL, Error) << \"Failed to encode stream image\";\n>> +\t\treturn jpeg_size;\n>> +\t}\n>> +\n>> +\t/*\n>> +\t * Fill in the JPEG blob header.\n>> +\t *\n>> +\t * The mapped size of the buffer is being returned as\n>> +\t * substantially larger than the requested JPEG_MAX_SIZE\n>> +\t * (which is referenced from maxJpegBufferSize_). Utilise\n>> +\t * this static size to ensure the correct offset of the blob is\n>> +\t * determined.\n>> +\t *\n>> +\t * \\todo Investigate if the buffer size mismatch is an issue or\n>> +\t * expected behaviour.\n>> +\t */\n>> +\tuint8_t *resultPtr = dest->maps()[0].data() +\n>> +\t\t\t     cameraDevice_->maxJpegBufferSize() -\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;\n>> +\tblob->jpeg_size = jpeg_size;\n>> +\n>> +\t/* Update the JPEG result Metadata. */\n>> +\tmetadata->addEntry(ANDROID_JPEG_SIZE, &jpeg_size, 1);\n>> +\n>> +\tconst uint32_t jpeg_quality = 95;\n>> +\tmetadata->addEntry(ANDROID_JPEG_QUALITY, &jpeg_quality, 1);\n>> +\n>> +\tconst uint32_t jpeg_orientation = 0;\n>> +\tmetadata->addEntry(ANDROID_JPEG_ORIENTATION, &jpeg_orientation, 1);\n\nI can see further refactoring of this to move JPEG specific handling to\na JPEG specific CameraStream instance or such - but that's not needed now.\n\nThis is all looking like good progress to me.\n\n\n>> +\n>> +\treturn 0;\n>> +}\n>> diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h\n>> index 2d71a50c78a4..dbcd1e53219f 100644\n>> --- a/src/android/camera_stream.h\n>> +++ b/src/android/camera_stream.h\n>> @@ -11,6 +11,7 @@\n>>  \n>>  #include <hardware/camera3.h>\n>>  \n>> +#include <libcamera/buffer.h>\n>>  #include <libcamera/camera.h>\n>>  #include <libcamera/geometry.h>\n>>  #include <libcamera/pixel_format.h>\n>> @@ -18,6 +19,8 @@\n>>  #include \"jpeg/encoder.h\"\n>>  \n>>  class CameraDevice;\n>> +class CameraMetadata;\n>> +class MappedCamera3Buffer;\n>>  \n>>  class CameraStream\n>>  {\n>> @@ -114,9 +117,11 @@ public:\n>>  \tconst libcamera::Size &size() const { return size_; }\n>>  \tType type() const { return type_; }\n>>  \tunsigned int index() const { return index_; }\n>> -\tEncoder *encoder() const { return encoder_.get(); }\n>>  \n>>  \tint configure(const libcamera::StreamConfiguration &cfg);\n>> +\tint process(libcamera::FrameBuffer *source,\n> \n> Can source be const ?\n> \n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n+1\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> \n>> +\t\t    MappedCamera3Buffer *dest,\n>> +\t\t    CameraMetadata *metadata);\n>>  \n>>  private:\n>>  \tCameraDevice *cameraDevice_;\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 B25B1C3B5D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  5 Oct 2020 21:42:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3FAF163BED;\n\tMon,  5 Oct 2020 23:42:31 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1811263BE4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  5 Oct 2020 23:42:29 +0200 (CEST)","from [192.168.0.20]\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6C1CE3B;\n\tMon,  5 Oct 2020 23:42:28 +0200 (CEST)"],"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=\"CibdUkQK\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1601934148;\n\tbh=7W1k3jvsUyUQNKpf01n0XoXeWCNAbDmMvrnYf0JooKY=;\n\th=Reply-To:Subject:To:References:From:Date:In-Reply-To:From;\n\tb=CibdUkQKPrd0ycA+t+i2mCRN85AhSY4ZW1is/qbmVj1VU2aXGbl5HEY7CTU0ZomRK\n\t5MA4sxHr3LkC9VxXq/QDMqHNeQXGzLgkF36Aku5tQx5tDTbIUQqLyqN0v+zTiNvb91\n\tlmvIKQDm1VJ2nxby80z/1baGoqfztfBWdlB7oqGk=","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20201005104649.10812-1-laurent.pinchart@ideasonboard.com>\n\t<20201005104649.10812-6-laurent.pinchart@ideasonboard.com>\n\t<20201005120837.GG3931@pendragon.ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\t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\n\tWZw01QYHU/GUV/zHJSFk","Organization":"Ideas on Board","Message-ID":"<6f8f6f9d-6898-f258-57da-ea66240baba8@ideasonboard.com>","Date":"Mon, 5 Oct 2020 22:42:25 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101\n\tThunderbird/68.10.0","MIME-Version":"1.0","In-Reply-To":"<20201005120837.GG3931@pendragon.ideasonboard.com>","Content-Language":"en-GB","Subject":"Re: [libcamera-devel] [PATCH 05/15] android: camera_device: Move\n\tprocessing to CameraStream","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>","Reply-To":"kieran.bingham@ideasonboard.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":13018,"web_url":"https://patchwork.libcamera.org/comment/13018/","msgid":"<1ed0243a-884c-14ee-ea87-4b40c63091fb@uajain.com>","date":"2020-10-06T18:17:12","subject":"Re: [libcamera-devel] [PATCH 05/15] android: camera_device: Move\n\tprocessing to CameraStream","submitter":{"id":1,"url":"https://patchwork.libcamera.org/api/people/1/","name":"Umang Jain","email":"email@uajain.com"},"content":"Hi all,\n\nOn 10/6/20 3:12 AM, Kieran Bingham wrote:\n> Hi Jacopo,\n>\n> On 05/10/2020 13:08, Laurent Pinchart wrote:\n>> Hi Jacopo,\n>>\n>> Thank you for the patch.\n>>\n>> On Mon, Oct 05, 2020 at 01:46:39PM +0300, Laurent Pinchart wrote:\n>>> From: Jacopo Mondi <jacopo@jmondi.org>\n>>>\n>>> Move the JPEG processing procedure to the individual CameraStream\n>>> by augmenting the class with a CameraStream::process() method.\n> It sounds like it just keeps getting better and better ;-)\n>\n>\n>>> This allows removing the CameraStream::encoder() method.>>\n>>> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n>>> ---\n>>>   src/android/camera_device.cpp | 68 ++---------------------------------\n>>>   src/android/camera_device.h   |  8 +++++\n>>>   src/android/camera_stream.cpp | 63 ++++++++++++++++++++++++++++++++\n>>>   src/android/camera_stream.h   |  7 +++-\n>>>   4 files changed, 80 insertions(+), 66 deletions(-)\n>>>\n>>> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n>>> index 2c4dd4dee28c..c44904300e0a 100644\n>>> --- a/src/android/camera_device.cpp\n>>> +++ b/src/android/camera_device.cpp\n>>> @@ -23,9 +23,6 @@\n>>>   #include \"camera_metadata.h\"\n>>>   #include \"system/graphics.h\"\n>>>   \n>>> -#include \"jpeg/encoder_libjpeg.h\"\n>>> -#include \"jpeg/exif.h\"\n>>> -\n>>>   using namespace libcamera;\n>>>   \n>>>   namespace {\n>>> @@ -133,12 +130,6 @@ const std::map<int, const Camera3Format> camera3FormatsMap = {\n>>>   \n>>>   LOG_DECLARE_CATEGORY(HAL);\n>>>   \n>>> -class MappedCamera3Buffer : public MappedBuffer\n>>> -{\n>>> -public:\n>>> -\tMappedCamera3Buffer(const buffer_handle_t camera3buffer, int flags);\n>>> -};\n>>> -\n>>>   MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer,\n>>>   \t\t\t\t\t int flags)\n>>>   {\n>>> @@ -1471,12 +1462,6 @@ void CameraDevice::requestComplete(Request *request)\n>>>   \t\tif (cameraStream->outputFormat() != HAL_PIXEL_FORMAT_BLOB)\n>>>   \t\t\tcontinue;\n>>>   \n>>> -\t\tEncoder *encoder = cameraStream->encoder();\n>>> -\t\tif (!encoder) {\n>>> -\t\t\tLOG(HAL, Error) << \"Failed to identify encoder\";\n>>> -\t\t\tcontinue;\n>>> -\t\t}\n>>> -\n>>>   \t\tStreamConfiguration *streamConfiguration = &config_->at(cameraStream->index());\n>>>   \t\tStream *stream = streamConfiguration->stream();\n>>>   \t\tFrameBuffer *buffer = request->findBuffer(stream);\n>>> @@ -1497,59 +1482,12 @@ void CameraDevice::requestComplete(Request *request)\n>>>   \t\t\tcontinue;\n>>>   \t\t}\n>>>   \n>>> -\t\t/* Set EXIF metadata for various tags. */\n>>> -\t\tExif exif;\n>>> -\t\t/* \\todo Set Make and Model from external vendor tags. */\n>>> -\t\texif.setMake(\"libcamera\");\n>>> -\t\texif.setModel(\"cameraModel\");\n>>> -\t\texif.setOrientation(orientation_);\n>>> -\t\texif.setSize(cameraStream->size());\n>>> -\t\t/*\n>>> -\t\t * We set the frame's EXIF timestamp as the time of encode.\n>>> -\t\t * Since the precision we need for EXIF timestamp is only one\n>>> -\t\t * second, it is good enough.\n>>> -\t\t */\n>>> -\t\texif.setTimestamp(std::time(nullptr));\n>>> -\t\tif (exif.generate() != 0)\n>>> -\t\t\tLOG(HAL, Error) << \"Failed to generate valid EXIF data\";\n>>> -\n>>> -\t\tint jpeg_size = encoder->encode(buffer, mapped.maps()[0], exif.data());\n>>> -\t\tif (jpeg_size < 0) {\n>>> -\t\t\tLOG(HAL, Error) << \"Failed to encode stream image\";\n>>> +\t\tint ret = cameraStream->process(buffer, &mapped,\n>>> +\t\t\t\t\t\tresultMetadata.get());\n>>> +\t\tif (ret) {\n>>>   \t\t\tstatus = CAMERA3_BUFFER_STATUS_ERROR;\n>>>   \t\t\tcontinue;\n>>>   \t\t}\n>>> -\n>>> -\t\t/*\n>>> -\t\t * Fill in the JPEG blob header.\n>>> -\t\t *\n>>> -\t\t * The mapped size of the buffer is being returned as\n>>> -\t\t * substantially larger than the requested JPEG_MAX_SIZE\n>>> -\t\t * (which is referenced from maxJpegBufferSize_). Utilise\n>>> -\t\t * this static size to ensure the correct offset of the blob is\n>>> -\t\t * determined.\n>>> -\t\t *\n>>> -\t\t * \\todo Investigate if the buffer size mismatch is an issue or\n>>> -\t\t * expected behaviour.\n>>> -\t\t */\n>>> -\t\tuint8_t *resultPtr = mapped.maps()[0].data() +\n>>> -\t\t\t\t     maxJpegBufferSize_ -\n>>> -\t\t\t\t     sizeof(struct camera3_jpeg_blob);\n>>> -\t\tauto *blob = reinterpret_cast<struct camera3_jpeg_blob *>(resultPtr);\n>>> -\t\tblob->jpeg_blob_id = CAMERA3_JPEG_BLOB_ID;\n>>> -\t\tblob->jpeg_size = jpeg_size;\n>>> -\n>>> -\t\t/* Update the JPEG result Metadata. */\n>>> -\t\tresultMetadata->addEntry(ANDROID_JPEG_SIZE,\n>>> -\t\t\t\t\t &jpeg_size, 1);\n>>> -\n>>> -\t\tconst uint32_t jpeg_quality = 95;\n>>> -\t\tresultMetadata->addEntry(ANDROID_JPEG_QUALITY,\n>>> -\t\t\t\t\t &jpeg_quality, 1);\n>>> -\n>>> -\t\tconst uint32_t jpeg_orientation = 0;\n>>> -\t\tresultMetadata->addEntry(ANDROID_JPEG_ORIENTATION,\n>>> -\t\t\t\t\t &jpeg_orientation, 1);\n>>>   \t}\n>>>   \n>>>   \t/* Prepare to call back the Android camera stack. */\n>>> diff --git a/src/android/camera_device.h b/src/android/camera_device.h\n>>> index 4e326fa3e1fb..826023b453f7 100644\n>>> --- a/src/android/camera_device.h\n>>> +++ b/src/android/camera_device.h\n>>> @@ -20,6 +20,7 @@\n>>>   #include <libcamera/request.h>\n>>>   #include <libcamera/stream.h>\n>>>   \n>>> +#include \"libcamera/internal/buffer.h\"\n>>>   #include \"libcamera/internal/log.h\"\n>>>   #include \"libcamera/internal/message.h\"\n>>>   \n>>> @@ -28,6 +29,12 @@\n>>>   \n>>>   class CameraMetadata;\n>>>   \n>>> +class MappedCamera3Buffer : public libcamera::MappedBuffer\n>>> +{\n>>> +public:\n>>> +\tMappedCamera3Buffer(const buffer_handle_t camera3buffer, int flags);\n>>> +};\n>>> +\n>>>   class CameraDevice : protected libcamera::Loggable\n>>>   {\n>>>   public:\n>>> @@ -50,6 +57,7 @@ public:\n>>>   \n>>>   \tint facing() const { return facing_; }\n>>>   \tint orientation() const { return orientation_; }\n>>> +\tunsigned int maxJpegBufferSize() const { return maxJpegBufferSize_; }\n>>>   \n>>>   \tvoid setCallbacks(const camera3_callback_ops_t *callbacks);\n>>>   \tconst camera_metadata_t *getStaticMetadata();\n>>> diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp\n>>> index 5c1f1d7da416..072edc9457bb 100644\n>>> --- a/src/android/camera_stream.cpp\n>>> +++ b/src/android/camera_stream.cpp\n>>> @@ -8,10 +8,14 @@\n>>>   #include \"camera_stream.h\"\n>>>   \n>>>   #include \"camera_device.h\"\n>>> +#include \"camera_metadata.h\"\n>>>   #include \"jpeg/encoder_libjpeg.h\"\n>>> +#include \"jpeg/exif.h\"\n>>>   \n>>>   using namespace libcamera;\n>>>   \n>>> +LOG_DECLARE_CATEGORY(HAL);\n>>> +\n>>>   CameraStream::CameraStream(CameraDevice *cameraDev,\n>>>   \t\t\t   camera3_stream_t *androidStream,\n>>>   \t\t\t   const libcamera::StreamConfiguration &cfg,\n>>> @@ -35,3 +39,62 @@ int CameraStream::configure(const libcamera::StreamConfiguration &cfg)\n>>>   \n>>>   \treturn 0;\n>>>   }\n>>> +\n>>> +int CameraStream::process(libcamera::FrameBuffer *source, MappedCamera3Buffer *dest,\n>>> +\t\t\t  CameraMetadata *metadata)\n>>> +{\n>>> +\tif (!encoder_)\n>>> +\t\treturn -EINVAL;\n>> Maybe that's addressed by subsequent patches in this series, but down\n>> the line I would envision process() being called for all CameraStream\n>> instances, so if no processing is required, this should then return 0.\n> I agree here, The CameraDevice shouldn't know/care 'if/what' processing\n> is required by a CameraStream. The CameraStream will deal with it all.\nBroadly agree with the direction. This is where I en-vision the \nPostProcessor layer comes into play.\n> Of course, in the current implementation, it might likely still require\n> the CameraDevice to notify the CameraStream that a request has completed.\n>\n> At some point, I could see the notification being the Buffer complete\n> notification, which might be earlier than the Request complete ... (to\n> reduce delays) - however we will need to make all of this asynchronous\n> before we go there.\n>\n>\n>>> +\n>>> +\t/* Set EXIF metadata for various tags. */\n>>> +\tExif exif;\n>>> +\t/* \\todo Set Make and Model from external vendor tags. */\n>>> +\texif.setMake(\"libcamera\");\n>>> +\texif.setModel(\"cameraModel\");\n>>> +\texif.setOrientation(cameraDevice_->orientation());\n>>> +\texif.setSize(size_);\n>>> +\t/*\n>>> +\t * We set the frame's EXIF timestamp as the time of encode.\n>>> +\t * Since the precision we need for EXIF timestamp is only one\n>>> +\t * second, it is good enough.\n>>> +\t */\n>>> +\texif.setTimestamp(std::time(nullptr));\n>>> +\tif (exif.generate() != 0)\n>>> +\t\tLOG(HAL, Error) << \"Failed to generate valid EXIF data\";\n>>> +\n>>> +\tint jpeg_size = encoder_->encode(source, dest->maps()[0], exif.data());\n>>> +\tif (jpeg_size < 0) {\n>>> +\t\tLOG(HAL, Error) << \"Failed to encode stream image\";\n>>> +\t\treturn jpeg_size;\n>>> +\t}\n>>> +\n>>> +\t/*\n>>> +\t * Fill in the JPEG blob header.\n>>> +\t *\n>>> +\t * The mapped size of the buffer is being returned as\n>>> +\t * substantially larger than the requested JPEG_MAX_SIZE\n>>> +\t * (which is referenced from maxJpegBufferSize_). Utilise\n>>> +\t * this static size to ensure the correct offset of the blob is\n>>> +\t * determined.\n>>> +\t *\n>>> +\t * \\todo Investigate if the buffer size mismatch is an issue or\n>>> +\t * expected behaviour.\n>>> +\t */\n>>> +\tuint8_t *resultPtr = dest->maps()[0].data() +\n>>> +\t\t\t     cameraDevice_->maxJpegBufferSize() -\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;\n>>> +\tblob->jpeg_size = jpeg_size;\n>>> +\n>>> +\t/* Update the JPEG result Metadata. */\n>>> +\tmetadata->addEntry(ANDROID_JPEG_SIZE, &jpeg_size, 1);\n>>> +\n>>> +\tconst uint32_t jpeg_quality = 95;\n>>> +\tmetadata->addEntry(ANDROID_JPEG_QUALITY, &jpeg_quality, 1);\n>>> +\n>>> +\tconst uint32_t jpeg_orientation = 0;\n>>> +\tmetadata->addEntry(ANDROID_JPEG_ORIENTATION, &jpeg_orientation, 1);\n> I can see further refactoring of this to move JPEG specific handling to\n> a JPEG specific CameraStream instance or such - but that's not needed now.\n>\n> This is all looking like good progress to me.\n>\n>\n>>> +\n>>> +\treturn 0;\n>>> +}\n>>> diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h\n>>> index 2d71a50c78a4..dbcd1e53219f 100644\n>>> --- a/src/android/camera_stream.h\n>>> +++ b/src/android/camera_stream.h\n>>> @@ -11,6 +11,7 @@\n>>>   \n>>>   #include <hardware/camera3.h>\n>>>   \n>>> +#include <libcamera/buffer.h>\n>>>   #include <libcamera/camera.h>\n>>>   #include <libcamera/geometry.h>\n>>>   #include <libcamera/pixel_format.h>\n>>> @@ -18,6 +19,8 @@\n>>>   #include \"jpeg/encoder.h\"\n>>>   \n>>>   class CameraDevice;\n>>> +class CameraMetadata;\n>>> +class MappedCamera3Buffer;\n>>>   \n>>>   class CameraStream\n>>>   {\n>>> @@ -114,9 +117,11 @@ public:\n>>>   \tconst libcamera::Size &size() const { return size_; }\n>>>   \tType type() const { return type_; }\n>>>   \tunsigned int index() const { return index_; }\n>>> -\tEncoder *encoder() const { return encoder_.get(); }\n>>>   \n>>>   \tint configure(const libcamera::StreamConfiguration &cfg);\n>>> +\tint process(libcamera::FrameBuffer *source,\n>> Can source be const ?\n>>\n>> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> +1\n>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>\n>>> +\t\t    MappedCamera3Buffer *dest,\n>>> +\t\t    CameraMetadata *metadata);\n>>>   \n>>>   private:\n>>>   \tCameraDevice *cameraDevice_;","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 1C8EABEEE0\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  6 Oct 2020 18:17:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9034163C1B;\n\tTue,  6 Oct 2020 20:17:18 +0200 (CEST)","from mail.uajain.com (static.126.159.217.95.clients.your-server.de\n\t[95.217.159.126])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2145760363\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  6 Oct 2020 20:17:17 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=uajain.com header.i=@uajain.com\n\theader.b=\"qH+NbvIb\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=uajain.com; s=mail;\n\tt=1602008236; bh=E/jgQnW2MNqzk7goVPrXipnQ7jud0UQpJdqpy0PQA6w=;\n\th=Subject:To:References:From:In-Reply-To;\n\tb=qH+NbvIbyLJZgXG6MZj/x2hNyDsdZq2wycQM4bI2KlYopM+SktMofmgH8HslAMFuk\n\t2NDc3MI+GB4AGV3rRwxd/st8/aRekZxljTxoOCf/T5DTKGTk1hIe9IIGgLrkf7Ydvg\n\tJ3+ef2ELZe0RL354oCYejWs0Z5DWcIw5CnO7F+1S7kCmBgf7VYP0sqUvEj3mm/5vFb\n\tJHTKBz4t22Ipem8S5ULMuV4XEKdr25W5EWZ1rTQwwzSrzPSRkQEAgUUaRGEDok493/\n\ts143idW6E43Gn6Wz9zzZsM58TdtfR0SWvggc25xl4qYcNtGEuF3o8U/Dt16ea/rXb4\n\tEjrVsAGDyIqQA==","To":"kieran.bingham@ideasonboard.com,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20201005104649.10812-1-laurent.pinchart@ideasonboard.com>\n\t<20201005104649.10812-6-laurent.pinchart@ideasonboard.com>\n\t<20201005120837.GG3931@pendragon.ideasonboard.com>\n\t<6f8f6f9d-6898-f258-57da-ea66240baba8@ideasonboard.com>","From":"Umang Jain <email@uajain.com>","Message-ID":"<1ed0243a-884c-14ee-ea87-4b40c63091fb@uajain.com>","Date":"Tue, 6 Oct 2020 23:47:12 +0530","Mime-Version":"1.0","In-Reply-To":"<6f8f6f9d-6898-f258-57da-ea66240baba8@ideasonboard.com>","Content-Language":"en-US","Subject":"Re: [libcamera-devel] [PATCH 05/15] android: camera_device: Move\n\tprocessing to CameraStream","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>","Content-Transfer-Encoding":"7bit","Content-Type":"text/plain; charset=\"us-ascii\"; Format=\"flowed\"","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]