Patch Detail
Show a patch.
GET /api/patches/10059/?format=api
{ "id": 10059, "url": "https://patchwork.libcamera.org/api/patches/10059/?format=api", "web_url": "https://patchwork.libcamera.org/patch/10059/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20201015171457.75678-3-email@uajain.com>", "date": "2020-10-15T17:14:56", "name": "[libcamera-devel,2/3] android: jpeg: Port to PostProcessor interface", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "699b8e77776bd504e680cd2b27408cf3f89f2c6c", "submitter": { "id": 1, "url": "https://patchwork.libcamera.org/api/people/1/?format=api", "name": "Umang Jain", "email": "email@uajain.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/10059/mbox/", "series": [ { "id": 1375, "url": "https://patchwork.libcamera.org/api/series/1375/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1375", "date": "2020-10-15T17:14:54", "name": "android: Introduce PostProcessor interface", "version": 1, "mbox": "https://patchwork.libcamera.org/series/1375/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/10059/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/10059/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 BF5D6BE905\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 15 Oct 2020 17:15:09 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8443261075;\n\tThu, 15 Oct 2020 19:15:09 +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 ADDB060E5A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 15 Oct 2020 19:15:08 +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=\"mKlDsauU\"; dkim-atps=neutral", "From": "Umang Jain <email@uajain.com>", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=uajain.com; s=mail;\n\tt=1602782108; bh=6q7kEJduKJ/0bhn70+8yYyh1yVDMiVD9Or1GarsLOcg=;\n\th=From:To:Cc:Subject:In-Reply-To:References;\n\tb=mKlDsauU7VAhzW7ecykbwqeqwUCvZMH+dPBBIFKVwm5yIYabVZmWC5NveRCrnkZFG\n\tN5a5j9tKLifN+EspMDE8nMcpvLXlRrEL9fkghN2xJqnj+1ALa6rhyjlf1qvZZTjAUw\n\tzntcUL4lJov5DPur9k7WdDzlkHTcxxT0rUNX4i+Fsj44YUVIHAUNHymtg06vJfXFeU\n\t7p2aHb7sd+JHw7coyAPDpgHOKSjoFT9mGg/3Q6XcfI5RNXt+ngXhlwj5Pm/cWWxQcY\n\thJaefPfQmMjhp8yXTQ1BGTv8pC+Q+f3Z1cu9AHKDogEPxJtvuVI/Ig8JclCMlCDmvo\n\triN9IwljR8LpQ==", "To": "libcamera-devel@lists.libcamera.org", "Date": "Thu, 15 Oct 2020 22:44:56 +0530", "Message-Id": "<20201015171457.75678-3-email@uajain.com>", "In-Reply-To": "<20201015171457.75678-1-email@uajain.com>", "References": "<20201015171457.75678-1-email@uajain.com>", "Mime-Version": "1.0", "Subject": "[libcamera-devel] [PATCH 2/3] android: jpeg: Port to PostProcessor\n\tinterface", "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>" }, "content": "Port the CameraStream's JPEG-encoding bits to PostProcessorJpeg.\nThis encapsulates the encoder and EXIF generation code into the\nPostProcessorJpeg layer and removes these specifics related to JPEG,\nfrom the CameraStream itself.\n\nSigned-off-by: Umang Jain <email@uajain.com>\n---\n src/android/camera_device.cpp | 1 +\n src/android/camera_stream.cpp | 77 ++++------------\n src/android/camera_stream.h | 4 +-\n src/android/jpeg/encoder_libjpeg.cpp | 2 +-\n src/android/jpeg/post_processor_jpeg.cpp | 110 +++++++++++++++++++++++\n src/android/jpeg/post_processor_jpeg.h | 36 ++++++++\n src/android/meson.build | 1 +\n 7 files changed, 169 insertions(+), 62 deletions(-)\n create mode 100644 src/android/jpeg/post_processor_jpeg.cpp\n create mode 100644 src/android/jpeg/post_processor_jpeg.h", "diff": "diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex c29fcb4..d6a8acb 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -7,6 +7,7 @@\n \n #include \"camera_device.h\"\n #include \"camera_ops.h\"\n+#include \"post_processor.h\"\n \n #include <sys/mman.h>\n #include <tuple>\ndiff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp\nindex eac1480..2a0ba16 100644\n--- a/src/android/camera_stream.cpp\n+++ b/src/android/camera_stream.cpp\n@@ -9,9 +9,9 @@\n \n #include \"camera_device.h\"\n #include \"camera_metadata.h\"\n-#include \"jpeg/encoder.h\"\n-#include \"jpeg/encoder_libjpeg.h\"\n-#include \"jpeg/exif.h\"\n+#include \"jpeg/post_processor_jpeg.h\"\n+\n+#include <libcamera/formats.h>\n \n using namespace libcamera;\n \n@@ -24,8 +24,15 @@ CameraStream::CameraStream(CameraDevice *cameraDevice, Type type,\n {\n \tconfig_ = cameraDevice_->cameraConfiguration();\n \n-\tif (type_ == Type::Internal || type_ == Type::Mapped)\n-\t\tencoder_ = std::make_unique<EncoderLibJpeg>();\n+\tif (type_ == Type::Internal || type_ == Type::Mapped) {\n+\t\t/*\n+\t\t * \\todo There might be multiple post-processors. The logic\n+\t\t * which should be instantiated here, is deferred for future.\n+\t\t * For now, we only have PostProcessorJpeg and that is what we\n+\t\t * will instantiate here.\n+\t\t */\n+\t\tpostProcessor_ = std::make_unique<PostProcessorJpeg>(cameraDevice_);\n+\t}\n \n \tif (type == Type::Internal) {\n \t\tallocator_ = std::make_unique<FrameBufferAllocator>(cameraDevice_->camera());\n@@ -45,8 +52,10 @@ Stream *CameraStream::stream() const\n \n int CameraStream::configure()\n {\n-\tif (encoder_) {\n-\t\tint ret = encoder_->configure(configuration());\n+\tif (postProcessor_) {\n+\t\tStreamConfiguration output = configuration();\n+\t\toutput.pixelFormat == formats::MJPEG;\n+\t\tint ret = postProcessor_->configure(configuration(), output);\n \t\tif (ret)\n \t\t\treturn ret;\n \t}\n@@ -69,60 +78,10 @@ int CameraStream::configure()\n int CameraStream::process(const libcamera::FrameBuffer &source,\n \t\t\t MappedCamera3Buffer *dest, CameraMetadata *metadata)\n {\n-\tif (!encoder_)\n+\tif (!postProcessor_)\n \t\treturn 0;\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(configuration().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+\treturn postProcessor_->process(&source, dest->maps()[0], metadata);\n }\n \n FrameBuffer *CameraStream::getBuffer()\ndiff --git a/src/android/camera_stream.h b/src/android/camera_stream.h\nindex 8df0101..c55d90b 100644\n--- a/src/android/camera_stream.h\n+++ b/src/android/camera_stream.h\n@@ -19,10 +19,10 @@\n #include <libcamera/geometry.h>\n #include <libcamera/pixel_format.h>\n \n-class Encoder;\n class CameraDevice;\n class CameraMetadata;\n class MappedCamera3Buffer;\n+class PostProcessor;\n \n class CameraStream\n {\n@@ -135,7 +135,6 @@ private:\n \t */\n \tunsigned int index_;\n \n-\tstd::unique_ptr<Encoder> encoder_;\n \tstd::unique_ptr<libcamera::FrameBufferAllocator> allocator_;\n \tstd::vector<libcamera::FrameBuffer *> buffers_;\n \t/*\n@@ -143,6 +142,7 @@ private:\n \t * an std::vector in CameraDevice.\n \t */\n \t std::unique_ptr<std::mutex> mutex_;\n+\tstd::unique_ptr<PostProcessor> postProcessor_;\n };\n \n #endif /* __ANDROID_CAMERA_STREAM__ */\ndiff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp\nindex a77f5b2..8995ba5 100644\n--- a/src/android/jpeg/encoder_libjpeg.cpp\n+++ b/src/android/jpeg/encoder_libjpeg.cpp\n@@ -25,7 +25,7 @@\n \n using namespace libcamera;\n \n-LOG_DEFINE_CATEGORY(JPEG)\n+LOG_DECLARE_CATEGORY(JPEG);\n \n namespace {\n \ndiff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp\nnew file mode 100644\nindex 0000000..d1ec95b\n--- /dev/null\n+++ b/src/android/jpeg/post_processor_jpeg.cpp\n@@ -0,0 +1,110 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * post_processor_jpeg.cpp - JPEG Post Processor\n+ */\n+\n+#include \"post_processor_jpeg.h\"\n+\n+#include \"../camera_device.h\"\n+#include \"../camera_metadata.h\"\n+#include \"encoder_libjpeg.h\"\n+#include \"exif.h\"\n+\n+#include <libcamera/formats.h>\n+\n+#include \"libcamera/internal/log.h\"\n+\n+using namespace libcamera;\n+\n+LOG_DEFINE_CATEGORY(JPEG);\n+\n+PostProcessorJpeg::PostProcessorJpeg(CameraDevice *device)\n+\t: cameraDevice_(device)\n+{\n+}\n+\n+int PostProcessorJpeg::configure(const StreamConfiguration &inCfg,\n+\t\t\t\t const StreamConfiguration &outCfg)\n+{\n+\tint ret = 0;\n+\n+\tif (inCfg.size != outCfg.size) {\n+\t\tLOG(JPEG, Error) << \"Mismatch of input and output stream sizes\";\n+\t\treturn -1;\n+\t}\n+\n+\tif (outCfg.pixelFormat != formats::MJPEG) {\n+\t\tLOG(JPEG, Error) << \"Output stream pixel format is not JPEG\";\n+\t\treturn -1;\n+\t}\n+\n+\tstreamSize_ = outCfg.size;\n+\tencoder_ = std::make_unique<EncoderLibJpeg>();\n+\n+\tif (encoder_)\n+\t\tret = encoder_->configure(inCfg);\n+\n+\treturn ret;\n+}\n+\n+int PostProcessorJpeg::process(const libcamera::FrameBuffer *source,\n+\t\t\t const libcamera::Span<uint8_t> &destination,\n+\t\t\t CameraMetadata *metadata)\n+{\n+\tif (!encoder_)\n+\t\treturn 0;\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(streamSize_);\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(JPEG, Error) << \"Failed to generate valid EXIF data\";\n+\n+\tint jpeg_size = encoder_->encode(source, destination, exif.data());\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.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+}\ndiff --git a/src/android/jpeg/post_processor_jpeg.h b/src/android/jpeg/post_processor_jpeg.h\nnew file mode 100644\nindex 0000000..72aca9b\n--- /dev/null\n+++ b/src/android/jpeg/post_processor_jpeg.h\n@@ -0,0 +1,36 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * post_processor_jpeg.h - JPEG Post Processor\n+ */\n+#ifndef __ANDROID_POST_PROCESSOR_JPEG_H__\n+#define __ANDROID_POST_PROCESSOR_JPEG_H__\n+\n+#include \"../post_processor.h\"\n+#include \"libcamera/internal/buffer.h\"\n+\n+#include <libcamera/geometry.h>\n+\n+class Encoder;\n+class CameraDevice;\n+\n+class PostProcessorJpeg : public PostProcessor\n+{\n+public:\n+\tPostProcessorJpeg(CameraDevice *device);\n+\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 const libcamera::Span<uint8_t> &destination,\n+\t\t CameraMetadata *metadata) override;\n+\n+\n+private:\n+\tCameraDevice *cameraDevice_;\n+\tstd::unique_ptr<Encoder> encoder_;\n+\tlibcamera::Size streamSize_;\n+};\n+\n+#endif /* __ANDROID_POST_PROCESSOR_JPEG_H__ */\ndiff --git a/src/android/meson.build b/src/android/meson.build\nindex 802bb89..eacd544 100644\n--- a/src/android/meson.build\n+++ b/src/android/meson.build\n@@ -23,6 +23,7 @@ android_hal_sources = files([\n 'camera_stream.cpp',\n 'jpeg/encoder_libjpeg.cpp',\n 'jpeg/exif.cpp',\n+ 'jpeg/post_processor_jpeg.cpp',\n ])\n \n android_camera_metadata_sources = files([\n", "prefixes": [ "libcamera-devel", "2/3" ] }