[{"id":19622,"web_url":"https://patchwork.libcamera.org/comment/19622/","msgid":"<YT6TQXp/1UzsbCzz@pendragon.ideasonboard.com>","date":"2021-09-12T23:54:41","subject":"Re: [libcamera-devel] [PATCH v2 1/9] android: camera_stream: Pass\n\tFrameBuffer pointer instead of reference","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Umang,\n\nThank you for the patch.\n\nOn Fri, Sep 10, 2021 at 12:36:30PM +0530, Umang Jain wrote:\n> Pass the libcamera::FrameBuffer pointer to the post-processor instead\n> of passing it by reference. Passing by reference is fine as long as\n> the post processing is done synchronously.\n> \n> However in subsequent commits, the post processing is planned to be\n> moved to a separate thread. This will conflict as the reference\n> argument (in current case 'source') is copied when we will try to\n> invoke a method on separate thread(which will run the post-processor)\n\ns/thread(/thread (/\n\n> using Object::invokeMethod(). The cause of conflict is the\n> LIBCAMERA_DISABLE_COPY_AND_MOVE rule applied on the FrameBuffer class.\n> \n> To resolve the conflict, pass in the FrameBuffer pointer instead of\n> reference. This requires changes to the existing PostProcessor interface\n> and all its implemented classes.\n\nIt's not really a \"conflict\" issue, it's the fact that passing an\nargument by reference to invokeMethod() will cause the argument to be\ncopied, and FrameBuffer instance should not be copied (as enforced by\nLIBCAMERA_DISABLE_COPY_AND_MOVE).\n\n> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n\nThe patch itself looks fine, so\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nI haven't checked the rest of the series though, so this assumes that\nturning the reference into a pointer is the best solution for the\nproblem that will be introduced later.\n\n> ---\n>  src/android/camera_device.cpp            |  2 +-\n>  src/android/camera_stream.cpp            |  2 +-\n>  src/android/camera_stream.h              |  2 +-\n>  src/android/jpeg/encoder.h               |  2 +-\n>  src/android/jpeg/encoder_libjpeg.cpp     |  4 ++--\n>  src/android/jpeg/encoder_libjpeg.h       |  2 +-\n>  src/android/jpeg/post_processor_jpeg.cpp |  4 ++--\n>  src/android/jpeg/post_processor_jpeg.h   |  4 ++--\n>  src/android/jpeg/thumbnailer.cpp         |  4 ++--\n>  src/android/jpeg/thumbnailer.h           |  2 +-\n>  src/android/post_processor.h             |  2 +-\n>  src/android/yuv/post_processor_yuv.cpp   | 18 +++++++++---------\n>  src/android/yuv/post_processor_yuv.h     |  4 ++--\n>  13 files changed, 26 insertions(+), 26 deletions(-)\n> \n> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n> index ab31bdda..f2f36f32 100644\n> --- a/src/android/camera_device.cpp\n> +++ b/src/android/camera_device.cpp\n> @@ -1148,7 +1148,7 @@ void CameraDevice::requestComplete(Request *request)\n>  \t\t\tcontinue;\n>  \t\t}\n>  \n> -\t\tint ret = cameraStream->process(*src, *buffer.buffer,\n> +\t\tint ret = cameraStream->process(src, *buffer.buffer,\n>  \t\t\t\t\t\tdescriptor.settings_,\n>  \t\t\t\t\t\tresultMetadata.get());\n>  \t\t/*\n> diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp\n> index 0f5ae947..0fed5382 100644\n> --- a/src/android/camera_stream.cpp\n> +++ b/src/android/camera_stream.cpp\n> @@ -98,7 +98,7 @@ int CameraStream::configure()\n>  \treturn 0;\n>  }\n>  \n> -int CameraStream::process(const FrameBuffer &source,\n> +int CameraStream::process(const FrameBuffer *source,\n>  \t\t\t  buffer_handle_t camera3Dest,\n>  \t\t\t  const CameraMetadata &requestMetadata,\n>  \t\t\t  CameraMetadata *resultMetadata)\n> diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h\n> index 2dab6c3a..5c232cb6 100644\n> --- a/src/android/camera_stream.h\n> +++ b/src/android/camera_stream.h\n> @@ -118,7 +118,7 @@ public:\n>  \tlibcamera::Stream *stream() const;\n>  \n>  \tint configure();\n> -\tint process(const libcamera::FrameBuffer &source,\n> +\tint process(const libcamera::FrameBuffer *source,\n>  \t\t    buffer_handle_t camera3Dest,\n>  \t\t    const CameraMetadata &requestMetadata,\n>  \t\t    CameraMetadata *resultMetadata);\n> diff --git a/src/android/jpeg/encoder.h b/src/android/jpeg/encoder.h\n> index a28522f4..7b6140e7 100644\n> --- a/src/android/jpeg/encoder.h\n> +++ b/src/android/jpeg/encoder.h\n> @@ -18,7 +18,7 @@ public:\n>  \tvirtual ~Encoder() = default;\n>  \n>  \tvirtual int configure(const libcamera::StreamConfiguration &cfg) = 0;\n> -\tvirtual int encode(const libcamera::FrameBuffer &source,\n> +\tvirtual int encode(const libcamera::FrameBuffer *source,\n>  \t\t\t   libcamera::Span<uint8_t> destination,\n>  \t\t\t   libcamera::Span<const uint8_t> exifData,\n>  \t\t\t   unsigned int quality) = 0;\n> diff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp\n> index 21a3b33d..3114ed4b 100644\n> --- a/src/android/jpeg/encoder_libjpeg.cpp\n> +++ b/src/android/jpeg/encoder_libjpeg.cpp\n> @@ -178,10 +178,10 @@ void EncoderLibJpeg::compressNV(const std::vector<Span<uint8_t>> &planes)\n>  \t}\n>  }\n>  \n> -int EncoderLibJpeg::encode(const FrameBuffer &source, Span<uint8_t> dest,\n> +int EncoderLibJpeg::encode(const FrameBuffer *source, Span<uint8_t> dest,\n>  \t\t\t   Span<const uint8_t> exifData, unsigned int quality)\n>  {\n> -\tMappedFrameBuffer frame(&source, MappedFrameBuffer::MapFlag::Read);\n> +\tMappedFrameBuffer frame(source, MappedFrameBuffer::MapFlag::Read);\n>  \tif (!frame.isValid()) {\n>  \t\tLOG(JPEG, Error) << \"Failed to map FrameBuffer : \"\n>  \t\t\t\t << strerror(frame.error());\n> diff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h\n> index 45ffbd7f..ae4e1e32 100644\n> --- a/src/android/jpeg/encoder_libjpeg.h\n> +++ b/src/android/jpeg/encoder_libjpeg.h\n> @@ -22,7 +22,7 @@ public:\n>  \t~EncoderLibJpeg();\n>  \n>  \tint configure(const libcamera::StreamConfiguration &cfg) override;\n> -\tint encode(const libcamera::FrameBuffer &source,\n> +\tint encode(const libcamera::FrameBuffer *source,\n>  \t\t   libcamera::Span<uint8_t> destination,\n>  \t\t   libcamera::Span<const uint8_t> exifData,\n>  \t\t   unsigned int quality) override;\n> diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp\n> index ef2d98cc..cb45f86b 100644\n> --- a/src/android/jpeg/post_processor_jpeg.cpp\n> +++ b/src/android/jpeg/post_processor_jpeg.cpp\n> @@ -50,7 +50,7 @@ int PostProcessorJpeg::configure(const StreamConfiguration &inCfg,\n>  \treturn encoder_->configure(inCfg);\n>  }\n>  \n> -void PostProcessorJpeg::generateThumbnail(const FrameBuffer &source,\n> +void PostProcessorJpeg::generateThumbnail(const FrameBuffer *source,\n>  \t\t\t\t\t  const Size &targetSize,\n>  \t\t\t\t\t  unsigned int quality,\n>  \t\t\t\t\t  std::vector<unsigned char> *thumbnail)\n> @@ -97,7 +97,7 @@ void PostProcessorJpeg::generateThumbnail(const FrameBuffer &source,\n>  \t}\n>  }\n>  \n> -int PostProcessorJpeg::process(const FrameBuffer &source,\n> +int PostProcessorJpeg::process(const FrameBuffer *source,\n>  \t\t\t       CameraBuffer *destination,\n>  \t\t\t       const CameraMetadata &requestMetadata,\n>  \t\t\t       CameraMetadata *resultMetadata)\n> diff --git a/src/android/jpeg/post_processor_jpeg.h b/src/android/jpeg/post_processor_jpeg.h\n> index 6fd31022..c4b2e9ef 100644\n> --- a/src/android/jpeg/post_processor_jpeg.h\n> +++ b/src/android/jpeg/post_processor_jpeg.h\n> @@ -22,13 +22,13 @@ public:\n>  \n>  \tint configure(const libcamera::StreamConfiguration &incfg,\n>  \t\t      const libcamera::StreamConfiguration &outcfg) override;\n> -\tint process(const libcamera::FrameBuffer &source,\n> +\tint process(const libcamera::FrameBuffer *source,\n>  \t\t    CameraBuffer *destination,\n>  \t\t    const CameraMetadata &requestMetadata,\n>  \t\t    CameraMetadata *resultMetadata) override;\n>  \n>  private:\n> -\tvoid generateThumbnail(const libcamera::FrameBuffer &source,\n> +\tvoid 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);\n> diff --git a/src/android/jpeg/thumbnailer.cpp b/src/android/jpeg/thumbnailer.cpp\n> index 1fab8072..ffac6a15 100644\n> --- a/src/android/jpeg/thumbnailer.cpp\n> +++ b/src/android/jpeg/thumbnailer.cpp\n> @@ -37,11 +37,11 @@ void Thumbnailer::configure(const Size &sourceSize, PixelFormat pixelFormat)\n>  \tvalid_ = true;\n>  }\n>  \n> -void Thumbnailer::createThumbnail(const FrameBuffer &source,\n> +void Thumbnailer::createThumbnail(const FrameBuffer *source,\n>  \t\t\t\t  const Size &targetSize,\n>  \t\t\t\t  std::vector<unsigned char> *destination)\n>  {\n> -\tMappedFrameBuffer frame(&source, MappedFrameBuffer::MapFlag::Read);\n> +\tMappedFrameBuffer frame(source, MappedFrameBuffer::MapFlag::Read);\n>  \tif (!frame.isValid()) {\n>  \t\tLOG(Thumbnailer, Error)\n>  \t\t\t<< \"Failed to map FrameBuffer : \"\n> diff --git a/src/android/jpeg/thumbnailer.h b/src/android/jpeg/thumbnailer.h\n> index 4d086c49..0f3caf40 100644\n> --- a/src/android/jpeg/thumbnailer.h\n> +++ b/src/android/jpeg/thumbnailer.h\n> @@ -19,7 +19,7 @@ public:\n>  \n>  \tvoid configure(const libcamera::Size &sourceSize,\n>  \t\t       libcamera::PixelFormat pixelFormat);\n> -\tvoid createThumbnail(const libcamera::FrameBuffer &source,\n> +\tvoid createThumbnail(const libcamera::FrameBuffer *source,\n>  \t\t\t     const libcamera::Size &targetSize,\n>  \t\t\t     std::vector<unsigned char> *dest);\n>  \tconst libcamera::PixelFormat &pixelFormat() const { return pixelFormat_; }\n> diff --git a/src/android/post_processor.h b/src/android/post_processor.h\n> index ab2b2c60..61dfb6d4 100644\n> --- a/src/android/post_processor.h\n> +++ b/src/android/post_processor.h\n> @@ -21,7 +21,7 @@ public:\n>  \n>  \tvirtual int configure(const libcamera::StreamConfiguration &inCfg,\n>  \t\t\t      const libcamera::StreamConfiguration &outCfg) = 0;\n> -\tvirtual int process(const libcamera::FrameBuffer &source,\n> +\tvirtual int process(const libcamera::FrameBuffer *source,\n>  \t\t\t    CameraBuffer *destination,\n>  \t\t\t    const CameraMetadata &requestMetadata,\n>  \t\t\t    CameraMetadata *resultMetadata) = 0;\n> diff --git a/src/android/yuv/post_processor_yuv.cpp b/src/android/yuv/post_processor_yuv.cpp\n> index 7b3b4960..0a874886 100644\n> --- a/src/android/yuv/post_processor_yuv.cpp\n> +++ b/src/android/yuv/post_processor_yuv.cpp\n> @@ -49,7 +49,7 @@ int PostProcessorYuv::configure(const StreamConfiguration &inCfg,\n>  \treturn 0;\n>  }\n>  \n> -int PostProcessorYuv::process(const FrameBuffer &source,\n> +int PostProcessorYuv::process(const FrameBuffer *source,\n>  \t\t\t      CameraBuffer *destination,\n>  \t\t\t      [[maybe_unused]] const CameraMetadata &requestMetadata,\n>  \t\t\t      [[maybe_unused]] CameraMetadata *metadata)\n> @@ -57,7 +57,7 @@ int PostProcessorYuv::process(const FrameBuffer &source,\n>  \tif (!isValidBuffers(source, *destination))\n>  \t\treturn -EINVAL;\n>  \n> -\tconst MappedFrameBuffer sourceMapped(&source, MappedFrameBuffer::MapFlag::Read);\n> +\tconst MappedFrameBuffer sourceMapped(source, MappedFrameBuffer::MapFlag::Read);\n>  \tif (!sourceMapped.isValid()) {\n>  \t\tLOG(YUV, Error) << \"Failed to mmap camera frame buffer\";\n>  \t\treturn -EINVAL;\n> @@ -83,12 +83,12 @@ int PostProcessorYuv::process(const FrameBuffer &source,\n>  \treturn 0;\n>  }\n>  \n> -bool PostProcessorYuv::isValidBuffers(const FrameBuffer &source,\n> +bool PostProcessorYuv::isValidBuffers(const FrameBuffer *source,\n>  \t\t\t\t      const CameraBuffer &destination) const\n>  {\n> -\tif (source.planes().size() != 2) {\n> +\tif (source->planes().size() != 2) {\n>  \t\tLOG(YUV, Error) << \"Invalid number of source planes: \"\n> -\t\t\t\t<< source.planes().size();\n> +\t\t\t\t<< source->planes().size();\n>  \t\treturn false;\n>  \t}\n>  \tif (destination.numPlanes() != 2) {\n> @@ -97,12 +97,12 @@ bool PostProcessorYuv::isValidBuffers(const FrameBuffer &source,\n>  \t\treturn false;\n>  \t}\n>  \n> -\tif (source.planes()[0].length < sourceLength_[0] ||\n> -\t    source.planes()[1].length < sourceLength_[1]) {\n> +\tif (source->planes()[0].length < sourceLength_[0] ||\n> +\t    source->planes()[1].length < sourceLength_[1]) {\n>  \t\tLOG(YUV, Error)\n>  \t\t\t<< \"The source planes lengths are too small, actual size: {\"\n> -\t\t\t<< source.planes()[0].length << \", \"\n> -\t\t\t<< source.planes()[1].length\n> +\t\t\t<< source->planes()[0].length << \", \"\n> +\t\t\t<< source->planes()[1].length\n>  \t\t\t<< \"}, expected size: {\"\n>  \t\t\t<< sourceLength_[0] << \", \"\n>  \t\t\t<< sourceLength_[1] << \"}\";\n> diff --git a/src/android/yuv/post_processor_yuv.h b/src/android/yuv/post_processor_yuv.h\n> index f8b1ba23..44a04113 100644\n> --- a/src/android/yuv/post_processor_yuv.h\n> +++ b/src/android/yuv/post_processor_yuv.h\n> @@ -20,13 +20,13 @@ public:\n>  \n>  \tint configure(const libcamera::StreamConfiguration &incfg,\n>  \t\t      const libcamera::StreamConfiguration &outcfg) override;\n> -\tint process(const libcamera::FrameBuffer &source,\n> +\tint process(const libcamera::FrameBuffer *source,\n>  \t\t    CameraBuffer *destination,\n>  \t\t    const CameraMetadata &requestMetadata,\n>  \t\t    CameraMetadata *metadata) override;\n>  \n>  private:\n> -\tbool isValidBuffers(const libcamera::FrameBuffer &source,\n> +\tbool isValidBuffers(const libcamera::FrameBuffer *source,\n>  \t\t\t    const CameraBuffer &destination) const;\n>  \tvoid calculateLengths(const libcamera::StreamConfiguration &inCfg,\n>  \t\t\t      const libcamera::StreamConfiguration &outCfg);","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 B36F8BDB1D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 12 Sep 2021 23:55:09 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B439269186;\n\tMon, 13 Sep 2021 01:55:08 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CB51860250\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Sep 2021 01:55:05 +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 4D86D9E;\n\tMon, 13 Sep 2021 01:55:05 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"cmZy/RC5\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1631490905;\n\tbh=2r8ODrTq8h94kXZDgn4/0rZ90nkWjhOw90ACEBux6TY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=cmZy/RC5nSSUHeE+W21IsUy7nCgrv6H18MbUApXjwoHpK9sTybrXTJbUhd/mxX7Hy\n\tHNjSDqRPwNy4dTX0WWIb5AyIQDFKu/zPJYADIF+/am0Niln7sj7+VBMNZ04HbrCiZl\n\tvEq5gPgM7trSrhnJT4sK6meak7HmeAxGsXbrNTYM=","Date":"Mon, 13 Sep 2021 02:54:41 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Umang Jain <umang.jain@ideasonboard.com>","Message-ID":"<YT6TQXp/1UzsbCzz@pendragon.ideasonboard.com>","References":"<20210910070638.467294-1-umang.jain@ideasonboard.com>\n\t<20210910070638.467294-2-umang.jain@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20210910070638.467294-2-umang.jain@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2 1/9] android: camera_stream: Pass\n\tFrameBuffer pointer instead of reference","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":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]