{"id":11425,"url":"https://patchwork.libcamera.org/api/1.1/patches/11425/?format=json","web_url":"https://patchwork.libcamera.org/patch/11425/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210301150111.61791-8-jacopo@jmondi.org>","date":"2021-03-01T15:01:08","name":"[libcamera-devel,07/10] android: post_processor: Use CameraBuffer API","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"bb9496fa0d04789f3f53d8da2f47807884c99f93","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/11425/mbox/","series":[{"id":1735,"url":"https://patchwork.libcamera.org/api/1.1/series/1735/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1735","date":"2021-03-01T15:01:01","name":"Support memory backends","version":1,"mbox":"https://patchwork.libcamera.org/series/1735/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/11425/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/11425/checks/","tags":{},"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 37A8CBD80C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  1 Mar 2021 15:01:04 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E1A4C68A98;\n\tMon,  1 Mar 2021 16:01:03 +0100 (CET)","from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net\n\t[217.70.183.194])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5308868A7D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  1 Mar 2021 16:01:03 +0100 (CET)","from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay2-d.mail.gandi.net (Postfix) with ESMTPSA id ADE3140010;\n\tMon,  1 Mar 2021 15:01:01 +0000 (UTC)"],"X-Originating-IP":"93.61.96.190","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon,  1 Mar 2021 16:01:08 +0100","Message-Id":"<20210301150111.61791-8-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.30.0","In-Reply-To":"<20210301150111.61791-1-jacopo@jmondi.org>","References":"<20210301150111.61791-1-jacopo@jmondi.org>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH 07/10] android: post_processor: Use\n\tCameraBuffer API","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"Han-lin Chen <hanlinchen@chromium.org>,\n\tDaniel Hung-yu Wu <hywu@google.com>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Use the newly introduced CameraBuffer class as the type for the\ndestination buffer in the PostProcessor class hierarchy in place of the\nlibcamera::MappedFrameBuffer one and use its API to retrieve the length\nand the location of the CameraBuffer plane allocated for JPEG\npost-processing.\n\nRemove all the assumption on the underlying memory storage and only go\nthrough the CameraBuffer API when dealing with memory buffers. To do so\nrework the Encoder interface to use a raw pointer and an explicit size\nto remove access to the Span<uint8_t> maps that serve as memory storage\nfor the current implementation but might not be ideal for other memory\nbackend.\n\nNow that the whole PostProcessor hierarchy has been converted to use\nthe CameraBuffer API remove libcamera::MappedBuffer as base class\nof the CameraBuffer interface and only reply on its interface.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/android/camera_buffer.h              |  4 +---\n src/android/jpeg/post_processor_jpeg.cpp | 25 ++++++++----------------\n src/android/jpeg/post_processor_jpeg.h   |  2 +-\n src/android/mm/generic_camera_buffer.cpp |  1 +\n src/android/post_processor.h             |  4 +++-\n src/android/yuv/post_processor_yuv.cpp   | 20 +++++++++----------\n src/android/yuv/post_processor_yuv.h     |  6 ++++--\n 7 files changed, 28 insertions(+), 34 deletions(-)","diff":"diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h\nindex ca4f4527c690..2311cdaf96b2 100644\n--- a/src/android/camera_buffer.h\n+++ b/src/android/camera_buffer.h\n@@ -10,11 +10,9 @@\n #include <hardware/camera3.h>\n \n #include <libcamera/class.h>\n-#include <libcamera/internal/buffer.h>\n #include <libcamera/span.h>\n \n-class CameraBuffer final : public libcamera::Extensible,\n-\t\t\t   public libcamera::MappedBuffer\n+class CameraBuffer final : public libcamera::Extensible\n {\n \tLIBCAMERA_DECLARE_PRIVATE(CameraBuffer)\n \ndiff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp\nindex ab5b63844067..83244ce6769e 100644\n--- a/src/android/jpeg/post_processor_jpeg.cpp\n+++ b/src/android/jpeg/post_processor_jpeg.cpp\n@@ -83,13 +83,15 @@ void PostProcessorJpeg::generateThumbnail(const FrameBuffer &source,\n }\n \n int PostProcessorJpeg::process(const FrameBuffer &source,\n-\t\t\t       libcamera::MappedBuffer *destination,\n+\t\t\t       CameraBuffer *destination,\n \t\t\t       const CameraMetadata &requestMetadata,\n \t\t\t       CameraMetadata *resultMetadata)\n {\n \tif (!encoder_)\n \t\treturn 0;\n \n+\tASSERT(destination->numPlanes() == 1);\n+\n \tcamera_metadata_ro_entry_t entry;\n \tint ret;\n \n@@ -172,28 +174,17 @@ int PostProcessorJpeg::process(const FrameBuffer &source,\n \tconst uint8_t quality = ret ? *entry.data.u8 : 95;\n \tresultMetadata->addEntry(ANDROID_JPEG_QUALITY, &quality, 1);\n \n-\tint jpeg_size = encoder_->encode(source, destination->maps()[0],\n+\tint jpeg_size = encoder_->encode(source, destination->plane(0),\n \t\t\t\t\t exif.data(), quality);\n \tif (jpeg_size < 0) {\n \t\tLOG(JPEG, 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 = destination->maps()[0].data() +\n-\t\t\t     cameraDevice_->maxJpegBufferSize() -\n-\t\t\t     sizeof(struct camera3_jpeg_blob);\n+\t/* Fill in the JPEG blob header. */\n+\tuint8_t *resultPtr = destination->plane(0).data()\n+\t\t\t   + destination->plane(0).size()\n+\t\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;\ndiff --git a/src/android/jpeg/post_processor_jpeg.h b/src/android/jpeg/post_processor_jpeg.h\nindex 7689de73c664..5d2d4ab224b1 100644\n--- a/src/android/jpeg/post_processor_jpeg.h\n+++ b/src/android/jpeg/post_processor_jpeg.h\n@@ -25,7 +25,7 @@ public:\n \tint configure(const libcamera::StreamConfiguration &incfg,\n \t\t      const libcamera::StreamConfiguration &outcfg) override;\n \tint process(const libcamera::FrameBuffer &source,\n-\t\t    libcamera::MappedBuffer *destination,\n+\t\t    CameraBuffer *destination,\n \t\t    const CameraMetadata &requestMetadata,\n \t\t    CameraMetadata *resultMetadata) override;\n \ndiff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp\nindex eedf16b76542..ea85be805260 100644\n--- a/src/android/mm/generic_camera_buffer.cpp\n+++ b/src/android/mm/generic_camera_buffer.cpp\n@@ -7,6 +7,7 @@\n \n #include \"../camera_buffer.h\"\n \n+#include <libcamera/internal/buffer.h>\n #include \"libcamera/internal/log.h\"\n \n using namespace libcamera;\ndiff --git a/src/android/post_processor.h b/src/android/post_processor.h\nindex ac40d3414892..4944078b490c 100644\n--- a/src/android/post_processor.h\n+++ b/src/android/post_processor.h\n@@ -12,6 +12,8 @@\n \n #include <libcamera/internal/buffer.h>\n \n+#include \"camera_buffer.h\"\n+\n class CameraMetadata;\n \n class PostProcessor\n@@ -22,7 +24,7 @@ public:\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-\t\t\t    libcamera::MappedBuffer *destination,\n+\t\t\t    CameraBuffer *destination,\n \t\t\t    const CameraMetadata &requestMetadata,\n \t\t\t    CameraMetadata *resultMetadata) = 0;\n };\ndiff --git a/src/android/yuv/post_processor_yuv.cpp b/src/android/yuv/post_processor_yuv.cpp\nindex 1318349ad66b..b67364c8f147 100644\n--- a/src/android/yuv/post_processor_yuv.cpp\n+++ b/src/android/yuv/post_processor_yuv.cpp\n@@ -48,7 +48,7 @@ int PostProcessorYuv::configure(const StreamConfiguration &inCfg,\n }\n \n int PostProcessorYuv::process(const FrameBuffer &source,\n-\t\t\t      libcamera::MappedBuffer *destination,\n+\t\t\t      CameraBuffer *destination,\n \t\t\t      [[maybe_unused]] const CameraMetadata &requestMetadata,\n \t\t\t      [[maybe_unused]] CameraMetadata *metadata)\n {\n@@ -66,9 +66,9 @@ int PostProcessorYuv::process(const FrameBuffer &source,\n \t\t\t\t    sourceMapped.maps()[1].data(),\n \t\t\t\t    sourceStride_[1],\n \t\t\t\t    sourceSize_.width, sourceSize_.height,\n-\t\t\t\t    destination->maps()[0].data(),\n+\t\t\t\t    destination->plane(0).data(),\n \t\t\t\t    destinationStride_[0],\n-\t\t\t\t    destination->maps()[1].data(),\n+\t\t\t\t    destination->plane(1).data(),\n \t\t\t\t    destinationStride_[1],\n \t\t\t\t    destinationSize_.width,\n \t\t\t\t    destinationSize_.height,\n@@ -82,16 +82,16 @@ int PostProcessorYuv::process(const FrameBuffer &source,\n }\n \n bool PostProcessorYuv::isValidBuffers(const FrameBuffer &source,\n-\t\t\t\t      const libcamera::MappedBuffer &destination) const\n+\t\t\t\t      const CameraBuffer &destination) const\n {\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\treturn false;\n \t}\n-\tif (destination.maps().size() != 2) {\n+\tif (destination.numPlanes() != 2) {\n \t\tLOG(YUV, Error) << \"Invalid number of destination planes: \"\n-\t\t\t\t<< destination.maps().size();\n+\t\t\t\t<< destination.numPlanes();\n \t\treturn false;\n \t}\n \n@@ -106,12 +106,12 @@ bool PostProcessorYuv::isValidBuffers(const FrameBuffer &source,\n \t\t\t<< sourceLength_[1] << \"}\";\n \t\treturn false;\n \t}\n-\tif (destination.maps()[0].size() < destinationLength_[0] ||\n-\t    destination.maps()[1].size() < destinationLength_[1]) {\n+\tif (destination.plane(0).size() < destinationLength_[0] ||\n+\t    destination.plane(1).size() < destinationLength_[1]) {\n \t\tLOG(YUV, Error)\n \t\t\t<< \"The destination planes lengths are too small, actual size: {\"\n-\t\t\t<< destination.maps()[0].size() << \", \"\n-\t\t\t<< destination.maps()[1].size()\n+\t\t\t<< destination.plane(0).size() << \", \"\n+\t\t\t<< destination.plane(1).size()\n \t\t\t<< \"}, expected size: {\"\n \t\t\t<< sourceLength_[0] << \", \"\n \t\t\t<< sourceLength_[1] << \"}\";\ndiff --git a/src/android/yuv/post_processor_yuv.h b/src/android/yuv/post_processor_yuv.h\nindex c58b4cf790fc..94620dd0a870 100644\n--- a/src/android/yuv/post_processor_yuv.h\n+++ b/src/android/yuv/post_processor_yuv.h\n@@ -9,6 +9,8 @@\n \n #include \"../post_processor.h\"\n \n+#include \"../camera_buffer.h\"\n+\n #include <libcamera/geometry.h>\n \n class CameraDevice;\n@@ -21,13 +23,13 @@ public:\n \tint configure(const libcamera::StreamConfiguration &incfg,\n \t\t      const libcamera::StreamConfiguration &outcfg) override;\n \tint process(const libcamera::FrameBuffer &source,\n-\t\t    libcamera::MappedBuffer *destination,\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-\t\t\t    const libcamera::MappedBuffer &destination) const;\n+\t\t\t    const CameraBuffer &destination) const;\n \tvoid calculateLengths(const libcamera::StreamConfiguration &inCfg,\n \t\t\t      const libcamera::StreamConfiguration &outCfg);\n \n","prefixes":["libcamera-devel","07/10"]}