Show a patch.

GET /api/patches/9952/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 9952,
    "url": "https://patchwork.libcamera.org/api/patches/9952/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/9952/",
    "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": "<20201005104649.10812-6-laurent.pinchart@ideasonboard.com>",
    "date": "2020-10-05T10:46:39",
    "name": "[libcamera-devel,05/15] android: camera_device: Move processing to CameraStream",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "12331d0deff9e3b9b14bfa7e9e7402c3355862cb",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/9952/mbox/",
    "series": [
        {
            "id": 1349,
            "url": "https://patchwork.libcamera.org/api/series/1349/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1349",
            "date": "2020-10-05T10:46:34",
            "name": "CameraStream refactoring",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/1349/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/9952/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/9952/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 0DF6AC3B5D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  5 Oct 2020 10:47:40 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CA4A663C44;\n\tMon,  5 Oct 2020 12:47:39 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 93CC563BBF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  5 Oct 2020 12:47:35 +0200 (CEST)",
            "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1CD3259E;\n\tMon,  5 Oct 2020 12:47:35 +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=\"T1+HbHJ4\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1601894855;\n\tbh=RManH8pi/+sohgrxew2NU1NnADGx9e/kDN5YNFRFAvY=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=T1+HbHJ4GEmZ4ZEjxMhTg4HG6Bj4RA/Y3f7GPHfn3j+QSQKKi+Ghi626jao7X2Da6\n\tUUQrnvKhsmW6trPBLLODExkkrNzq1NKsnqgD/jIRCwITNHRb0KGl8DXRtAcbq9N1sa\n\t3rCnynyS7IUi6/+auMk63YXs3pHF6LJmOh3B1JlI=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon,  5 Oct 2020 13:46:39 +0300",
        "Message-Id": "<20201005104649.10812-6-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.27.0",
        "In-Reply-To": "<20201005104649.10812-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20201005104649.10812-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Subject": "[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>"
    },
    "content": "From: Jacopo Mondi <jacopo@jmondi.org>\n\nMove 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\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   |  7 +++-\n 4 files changed, 80 insertions(+), 66 deletions(-)",
    "diff": "diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex 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. */\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 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+\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 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+\t\t    MappedCamera3Buffer *dest,\n+\t\t    CameraMetadata *metadata);\n \n private:\n \tCameraDevice *cameraDevice_;\n",
    "prefixes": [
        "libcamera-devel",
        "05/15"
    ]
}