Show a patch.

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

{
    "id": 13874,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/13874/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/13874/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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": "<20210920173752.1346190-11-umang.jain@ideasonboard.com>",
    "date": "2021-09-20T17:37:52",
    "name": "[libcamera-devel,v3,10/10] android: camera_stream: Run post processor in a thread",
    "commit_ref": null,
    "pull_url": null,
    "state": "rfc",
    "archived": false,
    "hash": "783f984cb92bf068a274022597ef15a349eba8da",
    "submitter": {
        "id": 86,
        "url": "https://patchwork.libcamera.org/api/1.1/people/86/?format=api",
        "name": "Umang Jain",
        "email": "umang.jain@ideasonboard.com"
    },
    "delegate": {
        "id": 12,
        "url": "https://patchwork.libcamera.org/api/1.1/users/12/?format=api",
        "username": "uajain",
        "first_name": "Umang",
        "last_name": "Jain",
        "email": "umang.jain@ideasonboard.com"
    },
    "mbox": "https://patchwork.libcamera.org/patch/13874/mbox/",
    "series": [
        {
            "id": 2539,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2539/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2539",
            "date": "2021-09-20T17:37:42",
            "name": "Async post processor",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/2539/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/13874/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/13874/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 0564BBF01C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 20 Sep 2021 17:38:23 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AF2686918E;\n\tMon, 20 Sep 2021 19:38:22 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 36B356918F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 Sep 2021 19:38:20 +0200 (CEST)",
            "from perceval.ideasonboard.com (unknown [103.251.226.144])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2FEA745E;\n\tMon, 20 Sep 2021 19:38:19 +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=\"lUyrnocf\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1632159500;\n\tbh=0TR32C93mMbOXb1KbT3dgwFoknIVPBIG8oc9sLKNYUQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=lUyrnocfHkZrfkUxRVoIA9lLQLh+XRSbqwRIN9qdY250NllpJj5zv9y9+xMorn9dq\n\tfBpRb/npwk7S5rGbxB2Uf0kr9qbxALIdyFG8fQpmrtacdwx/tMNQoqNIgR9cStN7z3\n\tLRKwj7VKC/edj9JqxUSCpSpXNr48fLWIdaNfHtQM=",
        "From": "Umang Jain <umang.jain@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 20 Sep 2021 23:07:52 +0530",
        "Message-Id": "<20210920173752.1346190-11-umang.jain@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.31.1",
        "In-Reply-To": "<20210920173752.1346190-1-umang.jain@ideasonboard.com>",
        "References": "<20210920173752.1346190-1-umang.jain@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v3 10/10] android: camera_stream: Run post\n\tprocessor in a thread",
        "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>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "This commit makes the post processor run in a separate thread.\nTo enable the move to a separate thread, he post processor\nneeds to be inherited from libcamera::Object and use the\nObject::moveToThread() API to execute the move.\n\nA user defined destructor is introduced to stop the thread for cleanup.\nSince CameraStream is move-constructible and compiler implicitly\ngenerates its constructor, defining a destructor will prevent the\ncompiler from adding an implicitly-declared move constructor. Therefore,\nwe need to explicitly add a move constructor as well.\n\nAlso, the destination buffer for post-processing needs to be alive and\nstored as a part of overall context, hence a CameraBuffer unique-pointer\nmember is introduced in the Camera3RequestDescriptor struct.\n\n---\n /* \\todo Use ConnectionTypeQueued instead of ConnectionTypeBlocking */\n---\n\nSigned-off-by: Umang Jain <umang.jain@ideasonboard.com>\n---\n src/android/camera_device.h   |  2 ++\n src/android/camera_stream.cpp | 29 +++++++++++++++++++++--------\n src/android/camera_stream.h   |  5 +++++\n src/android/post_processor.h  |  3 ++-\n 4 files changed, 30 insertions(+), 9 deletions(-)",
    "diff": "diff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex 0bd570a1..e3f3fe7c 100644\n--- a/src/android/camera_device.h\n+++ b/src/android/camera_device.h\n@@ -27,6 +27,7 @@\n #include <libcamera/request.h>\n #include <libcamera/stream.h>\n \n+#include \"camera_buffer.h\"\n #include \"camera_capabilities.h\"\n #include \"camera_metadata.h\"\n #include \"camera_stream.h\"\n@@ -55,6 +56,7 @@ struct Camera3RequestDescriptor {\n \tCameraMetadata settings_;\n \tstd::unique_ptr<CaptureRequest> request_;\n \tstd::unique_ptr<CameraMetadata> resultMetadata_;\n+\tstd::unique_ptr<CameraBuffer> destBuffer_;\n \n \tcamera3_capture_result_t captureResult_ = {};\n \tlibcamera::FrameBuffer *internalBuffer_;\ndiff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp\nindex c18c7041..6578ce09 100644\n--- a/src/android/camera_stream.cpp\n+++ b/src/android/camera_stream.cpp\n@@ -55,6 +55,9 @@ CameraStream::CameraStream(CameraDevice *const cameraDevice,\n \t\t * is what we instantiate here.\n \t\t */\n \t\tpostProcessor_ = std::make_unique<PostProcessorJpeg>(cameraDevice_);\n+\t\tthread_ = std::make_unique<libcamera::Thread>();\n+\t\tpostProcessor_->moveToThread(thread_.get());\n+\t\tthread_->start();\n \t}\n \n \tif (type == Type::Internal) {\n@@ -63,6 +66,14 @@ CameraStream::CameraStream(CameraDevice *const cameraDevice,\n \t}\n }\n \n+CameraStream::~CameraStream()\n+{\n+\tif (thread_) {\n+\t\tthread_->exit();\n+\t\tthread_->wait();\n+\t}\n+}\n+\n const StreamConfiguration &CameraStream::configuration() const\n {\n \treturn config_->at(index_);\n@@ -111,21 +122,23 @@ void CameraStream::process(const FrameBuffer *source,\n \t\treturn;\n \t}\n \n-\t/*\n-\t * \\todo Buffer mapping and processing should be moved to a\n-\t * separate thread.\n-\t */\n \tconst StreamConfiguration &output = configuration();\n-\tCameraBuffer dest(camera3Dest, formats::MJPEG, output.size,\n-\t\t\t  PROT_READ | PROT_WRITE);\n-\tif (!dest.isValid()) {\n+\tstd::unique_ptr<CameraBuffer> dest =\n+\t\tstd::make_unique<CameraBuffer>(camera3Dest, formats::MJPEG,\n+\t\t\t\t\t       output.size, PROT_READ | PROT_WRITE);\n+\n+\tif (!dest->isValid()) {\n \t\tLOG(HAL, Error) << \"Failed to map android blob buffer\";\n \t\trequest->status_ = Camera3RequestDescriptor::ProcessStatus::Error;\n \t\thandleProcessComplete(request);\n \t\treturn;\n \t}\n+\trequest->destBuffer_ = std::move(dest);\n \n-\tpostProcessor_->process(source, &dest, request);\n+\t/* \\todo Use ConnectionTypeQueued instead of ConnectionTypeBlocking */\n+\tpostProcessor_->invokeMethod(&PostProcessor::process,\n+\t\t\t\t     ConnectionTypeBlocking, source,\n+\t\t\t\t     request->destBuffer_.get(), request);\n }\n \n void CameraStream::handleProcessComplete(Camera3RequestDescriptor *request)\ndiff --git a/src/android/camera_stream.h b/src/android/camera_stream.h\nindex d4ec5c25..42db72d8 100644\n--- a/src/android/camera_stream.h\n+++ b/src/android/camera_stream.h\n@@ -13,6 +13,8 @@\n \n #include <hardware/camera3.h>\n \n+#include <libcamera/base/thread.h>\n+\n #include <libcamera/camera.h>\n #include <libcamera/framebuffer.h>\n #include <libcamera/framebuffer_allocator.h>\n@@ -113,6 +115,8 @@ public:\n \tCameraStream(CameraDevice *const cameraDevice,\n \t\t     libcamera::CameraConfiguration *config, Type type,\n \t\t     camera3_stream_t *camera3Stream, unsigned int index);\n+\tCameraStream(CameraStream &&other) = default;\n+\t~CameraStream();\n \n \tType type() const { return type_; }\n \tconst camera3_stream_t &camera3Stream() const { return *camera3Stream_; }\n@@ -143,6 +147,7 @@ private:\n \t */\n \tstd::unique_ptr<std::mutex> mutex_;\n \tstd::unique_ptr<PostProcessor> postProcessor_;\n+\tstd::unique_ptr<libcamera::Thread> thread_;\n };\n \n #endif /* __ANDROID_CAMERA_STREAM__ */\ndiff --git a/src/android/post_processor.h b/src/android/post_processor.h\nindex 48ddd8ac..fdfd52d3 100644\n--- a/src/android/post_processor.h\n+++ b/src/android/post_processor.h\n@@ -7,6 +7,7 @@\n #ifndef __ANDROID_POST_PROCESSOR_H__\n #define __ANDROID_POST_PROCESSOR_H__\n \n+#include <libcamera/base/object.h>\n #include <libcamera/base/signal.h>\n \n #include <libcamera/framebuffer.h>\n@@ -18,7 +19,7 @@ class CameraMetadata;\n \n struct Camera3RequestDescriptor;\n \n-class PostProcessor\n+class PostProcessor : public libcamera::Object\n {\n public:\n \tvirtual ~PostProcessor() = default;\n",
    "prefixes": [
        "libcamera-devel",
        "v3",
        "10/10"
    ]
}