{"id":9974,"url":"https://patchwork.libcamera.org/api/patches/9974/?format=json","web_url":"https://patchwork.libcamera.org/patch/9974/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20201006144432.22908-6-jacopo@jmondi.org>","date":"2020-10-06T14:44:24","name":"[libcamera-devel,v2,05/13] android: camera_device: Move processing to CameraStream","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"34496d0c9c953f1e9e0b8b6ff1d8c12a477dd178","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/9974/mbox/","series":[{"id":1356,"url":"https://patchwork.libcamera.org/api/series/1356/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1356","date":"2020-10-06T14:44:19","name":"CameraStream refactor","version":2,"mbox":"https://patchwork.libcamera.org/series/1356/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/9974/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9974/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 ADBE0BEEDF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  6 Oct 2020 14:40:46 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8B14D63CBF;\n\tTue,  6 Oct 2020 16:40:46 +0200 (CEST)","from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net\n\t[217.70.183.195])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 43E0B63C1B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  6 Oct 2020 16:40:45 +0200 (CEST)","from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 661CA60007;\n\tTue,  6 Oct 2020 14:40:44 +0000 (UTC)"],"X-Originating-IP":"93.34.118.233","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  6 Oct 2020 16:44:24 +0200","Message-Id":"<20201006144432.22908-6-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.28.0","In-Reply-To":"<20201006144432.22908-1-jacopo@jmondi.org>","References":"<20201006144432.22908-1-jacopo@jmondi.org>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v2 05/13] 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>"},"content":"Move the JPEG processing procedure to the individual CameraStream\nby augmenting the class with a CameraStream::process() method.\n\nThis allows removing the CameraStream::encoder() method.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nSigned-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   |  8 +++--\n 4 files changed, 80 insertions(+), 67 deletions(-)","diff":"diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex 68970eb4a94c..914e66b8f96a 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->camera3Stream().format != 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. */\ndiff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex 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();\ndiff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp\nindex b3d345afc61a..e86a7ba60d46 100644\n--- a/src/android/camera_stream.cpp\n+++ b/src/android/camera_stream.cpp\n@@ -8,11 +8,15 @@\n #include \"camera_stream.h\"\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 \n using namespace libcamera;\n \n+LOG_DECLARE_CATEGORY(HAL);\n+\n CameraStream::CameraStream(CameraDevice *cameraDevice,\n \t\t\t   camera3_stream_t *camera3Stream,\n \t\t\t   const libcamera::StreamConfiguration &cfg,\n@@ -36,3 +40,62 @@ int CameraStream::configure(const libcamera::StreamConfiguration &cfg)\n \n \treturn 0;\n }\n+\n+int CameraStream::process(const libcamera::FrameBuffer &source,\n+\t\t\t  MappedCamera3Buffer *dest, 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(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+}\ndiff --git a/src/android/camera_stream.h b/src/android/camera_stream.h\nindex ccc822b4980f..d95c2a3831b0 100644\n--- a/src/android/camera_stream.h\n+++ b/src/android/camera_stream.h\n@@ -11,12 +11,15 @@\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 \n-class CameraDevice;\n class Encoder;\n+class CameraDevice;\n+class CameraMetadata;\n+class MappedCamera3Buffer;\n \n class CameraStream\n {\n@@ -113,9 +116,10 @@ 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(const libcamera::FrameBuffer &source,\n+\t\t    MappedCamera3Buffer *dest, CameraMetadata *metadata);\n \n private:\n \tCameraDevice *cameraDevice_;\n","prefixes":["libcamera-devel","v2","05/13"]}