Show a patch.

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

{
    "id": 13614,
    "url": "https://patchwork.libcamera.org/api/patches/13614/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/13614/",
    "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": "<20210902213128.1064018-5-umang.jain@ideasonboard.com>",
    "date": "2021-09-02T21:31:27",
    "name": "[libcamera-devel,RFC,v2,4/5] android: camera_device: Add a queue for sending capture results",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "7deed29d0f997f6298e57156cba2baa5c86b0d28",
    "submitter": {
        "id": 86,
        "url": "https://patchwork.libcamera.org/api/people/86/?format=api",
        "name": "Umang Jain",
        "email": "umang.jain@ideasonboard.com"
    },
    "delegate": {
        "id": 12,
        "url": "https://patchwork.libcamera.org/api/users/12/?format=api",
        "username": "uajain",
        "first_name": "Umang",
        "last_name": "Jain",
        "email": "umang.jain@ideasonboard.com"
    },
    "mbox": "https://patchwork.libcamera.org/patch/13614/mbox/",
    "series": [
        {
            "id": 2443,
            "url": "https://patchwork.libcamera.org/api/series/2443/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2443",
            "date": "2021-09-02T21:31:23",
            "name": "Async PostProcessor",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/2443/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/13614/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/13614/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 D92F7C3243\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  2 Sep 2021 21:31:46 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4254269173;\n\tThu,  2 Sep 2021 23:31:45 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BEA7469169\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  2 Sep 2021 23:31:43 +0200 (CEST)",
            "from perceval.ideasonboard.com (unknown [103.251.226.107])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id BD2A345E;\n\tThu,  2 Sep 2021 23:31:42 +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=\"C2YFmUYN\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1630618303;\n\tbh=ZbWBamVyZ7VmqidwcfsdOY96apBwoOJL/Xb4cIg33/Y=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=C2YFmUYNPVMxcI4klyNBX1Rei3yFJBrH0p2i26sG+SOPEv4aQQDbSQiBwFaT4iexH\n\tSPXtE7ZhncAlUjkmxiQ4nUpe3kwvK/FOa56jzdTFj/rE3kzZ2p9BB7HbojDXUmStF9\n\thHN8LElDooKa1hnk2JaM+WSbWXkxS3Ay0IlofAPo=",
        "From": "Umang Jain <umang.jain@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri,  3 Sep 2021 03:01:27 +0530",
        "Message-Id": "<20210902213128.1064018-5-umang.jain@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.31.1",
        "In-Reply-To": "<20210902213128.1064018-1-umang.jain@ideasonboard.com>",
        "References": "<20210902213128.1064018-1-umang.jain@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [RFC PATCH v2 4/5] android: camera_device: Add a\n\tqueue for sending capture results",
        "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": "When a camera capture request completes, the next step is to send the\ncapture results to the framework via process_capture_results(). All\nthe capture associated result metadata is prepared and populated. If\nany post-processing is required, it will also take place in the same\nthread (which can be blocking for a subtaintial amount of time) before\nthe results can be sent back to the framework.\n\nA follow up commit will move the post-processing to run in a separate\nthread. In order to do so, there is few bits of groundwork which this\npatch entails. Mainly, we need to preserve the order of sending\nthe capture results back in which they were queued by the framework\nto the HAL (i.e. the order is sequential). Hence, we need to add a queue\nin which capture results can be queued with context.\n\nAs per this patch, the post-processor still runs synchronously as\nbefore, but it will queue up the current capture results with context.\nLater down the line, the capture results are dequeud in order and\nsent back to the framework.\n\nThe context is preserved using Camera3RequestDescriptor utility\nstructure. It has been expanded accordingly to address the needs of\nthe functionality.\n\nSigned-off-by: Umang Jain <umang.jain@ideasonboard.com>\n---\n src/android/camera_device.cpp | 113 +++++++++++++++++++++++++++++++---\n src/android/camera_device.h   |  23 +++++++\n 2 files changed, 126 insertions(+), 10 deletions(-)",
    "diff": "diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex 0b324ff5..fd07c9bd 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -240,6 +240,8 @@ CameraDevice::Camera3RequestDescriptor::Camera3RequestDescriptor(\n \t/* Clone the controls associated with the camera3 request. */\n \tsettings_ = CameraMetadata(camera3Request->settings);\n \n+\tinternalBuffer_ = nullptr;\n+\n \t/*\n \t * Create the CaptureRequest, stored as a unique_ptr<> to tie its\n \t * lifetime to the descriptor.\n@@ -1002,6 +1004,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n \t\t\t * once it has been processed.\n \t\t\t */\n \t\t\tbuffer = cameraStream->getBuffer();\n+\t\t\tdescriptor.internalBuffer_ = buffer;\n \t\t\tLOG(HAL, Debug) << ss.str() << \" (internal)\";\n \t\t\tbreak;\n \t\t}\n@@ -1161,25 +1164,115 @@ void CameraDevice::requestComplete(Request *request)\n \t\t\tcontinue;\n \t\t}\n \n+\t\t/*\n+\t\t * Save the current context of capture result and queue the\n+\t\t * descriptor before processing the camera stream.\n+\t\t *\n+\t\t * When the processing completes, the descriptor will be\n+\t\t * dequeued and capture results will be sent to the framework.\n+\t\t */\n+\t\tdescriptor.status_ = Camera3RequestDescriptor::NOT_FINISHED;\n+\t\tdescriptor.resultMetadata_ = std::move(resultMetadata);\n+\t\tdescriptor.captureResult_ = captureResult;\n+\n+\t\tstd::unique_ptr<Camera3RequestDescriptor> reqDescriptor =\n+\t\t\tstd::make_unique<Camera3RequestDescriptor>();\n+\t\t*reqDescriptor = std::move(descriptor);\n+\t\tqueuedDescriptor_.push_back(std::move(reqDescriptor));\n+\t\tCamera3RequestDescriptor *currentDescriptor = queuedDescriptor_.back().get();\n+\n+\t\tCameraMetadata *metadata = currentDescriptor->resultMetadata_.get();\n+\t\tcameraStream->processComplete.connect(\n+\t\t\tthis, [=](CameraStream::ProcessStatus status) {\n+\t\t\t\tstreamProcessingComplete(cameraStream, status,\n+\t\t\t\t\t\t\t metadata);\n+\t\t\t});\n+\n \t\tint ret = cameraStream->process(src, *buffer.buffer,\n-\t\t\t\t\t\tdescriptor.settings_,\n-\t\t\t\t\t\tresultMetadata.get());\n+\t\t\t\t\t\tcurrentDescriptor->settings_,\n+\t\t\t\t\t\tmetadata);\n+\t\treturn;\n+\t}\n+\n+\tif (queuedDescriptor_.empty()) {\n+\t\tcaptureResult.result = resultMetadata->get();\n+\t\tcallbacks_->process_capture_result(callbacks_, &captureResult);\n+\t} else {\n+\t\t/*\n+\t\t * Previous capture results waiting to be sent to framework\n+\t\t * hence, queue the current capture results as well. After that,\n+\t\t * check if any results are ready to be sent back to the\n+\t\t * framework.\n+\t\t */\n+\t\tdescriptor.status_ = Camera3RequestDescriptor::FINISHED_SUCCESS;\n+\t\tdescriptor.resultMetadata_ = std::move(resultMetadata);\n+\t\tdescriptor.captureResult_ = captureResult;\n+\t\tstd::unique_ptr<Camera3RequestDescriptor> reqDescriptor =\n+\t\t\tstd::make_unique<Camera3RequestDescriptor>();\n+\t\t*reqDescriptor = std::move(descriptor);\n+\t\tqueuedDescriptor_.push_back(std::move(reqDescriptor));\n+\n+\t\tsendQueuedCaptureResults();\n+\t}\n+}\n+\n+void CameraDevice::streamProcessingComplete(CameraStream *cameraStream,\n+\t\t\t\t\t    CameraStream::ProcessStatus status,\n+\t\t\t\t\t    CameraMetadata *resultMetadata)\n+{\n+\tfor (auto &d : queuedDescriptor_) {\n+\t\tif (d->resultMetadata_.get() != resultMetadata)\n+\t\t\tcontinue;\n+\n \t\t/*\n \t\t * Return the FrameBuffer to the CameraStream now that we're\n \t\t * done processing it.\n \t\t */\n \t\tif (cameraStream->type() == CameraStream::Type::Internal)\n-\t\t\tcameraStream->putBuffer(src);\n-\n-\t\tif (ret) {\n-\t\t\tbuffer.status = CAMERA3_BUFFER_STATUS_ERROR;\n-\t\t\tnotifyError(descriptor.frameNumber_, buffer.stream,\n-\t\t\t\t    CAMERA3_MSG_ERROR_BUFFER);\n+\t\t\tcameraStream->putBuffer(d->internalBuffer_);\n+\n+\t\tif (status == CameraStream::ProcessStatus::Success) {\n+\t\t\td->status_ = Camera3RequestDescriptor::FINISHED_SUCCESS;\n+\t\t} else {\n+\t\t\td->status_ = Camera3RequestDescriptor::FINISHED_FAILED;\n+\t\t\td->captureResult_.partial_result = 0;\n+\t\t\tfor (camera3_stream_buffer_t &buffer : d->buffers_) {\n+\t\t\t\tCameraStream *cs = static_cast<CameraStream *>(buffer.stream->priv);\n+\n+\t\t\t\tif (cs->camera3Stream().format != HAL_PIXEL_FORMAT_BLOB)\n+\t\t\t\t\tcontinue;\n+\n+\t\t\t\tbuffer.status = CAMERA3_BUFFER_STATUS_ERROR;\n+\t\t\t\tnotifyError(d->frameNumber_, buffer.stream,\n+\t\t\t\t\t    CAMERA3_MSG_ERROR_BUFFER);\n+\t\t\t}\n \t\t}\n+\n+\t\tbreak;\n \t}\n \n-\tcaptureResult.result = resultMetadata->get();\n-\tcallbacks_->process_capture_result(callbacks_, &captureResult);\n+\t/*\n+\t * Send back capture results to the framework by inspecting the queue.\n+\t * The framework can defer queueing further requests to the HAL (via\n+\t * process_capture_request) unless until it receives the capture results\n+\t * for already queued requests.\n+\t */\n+\tsendQueuedCaptureResults();\n+}\n+\n+void CameraDevice::sendQueuedCaptureResults()\n+{\n+\twhile (!queuedDescriptor_.empty()) {\n+\t\tstd::unique_ptr<Camera3RequestDescriptor> &d = queuedDescriptor_.front();\n+\t\tif (d->status_ != Camera3RequestDescriptor::NOT_FINISHED) {\n+\t\t\td->captureResult_.result = d->resultMetadata_->get();\n+\t\t\tcallbacks_->process_capture_result(callbacks_,\n+\t\t\t\t\t\t\t   &(d->captureResult_));\n+\t\t\tqueuedDescriptor_.pop_front();\n+\t\t} else {\n+\t\t\tbreak;\n+\t\t}\n+\t}\n }\n \n std::string CameraDevice::logPrefix() const\ndiff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex a5576927..36425773 100644\n--- a/src/android/camera_device.h\n+++ b/src/android/camera_device.h\n@@ -7,6 +7,7 @@\n #ifndef __ANDROID_CAMERA_DEVICE_H__\n #define __ANDROID_CAMERA_DEVICE_H__\n \n+#include <deque>\n #include <map>\n #include <memory>\n #include <mutex>\n@@ -83,6 +84,21 @@ private:\n \t\tstd::vector<std::unique_ptr<libcamera::FrameBuffer>> frameBuffers_;\n \t\tCameraMetadata settings_;\n \t\tstd::unique_ptr<CaptureRequest> request_;\n+\n+\t\t/*\n+\t\t * Below are utility placeholders used when a capture result\n+\t\t * needs to be queued before completion via\n+\t\t * process_capture_result() callback.\n+\t\t */\n+\t\tenum completionStatus {\n+\t\t\tNOT_FINISHED,\n+\t\t\tFINISHED_SUCCESS,\n+\t\t\tFINISHED_FAILED,\n+\t\t};\n+\t\tstd::unique_ptr<CameraMetadata> resultMetadata_;\n+\t\tcamera3_capture_result_t captureResult_;\n+\t\tlibcamera::FrameBuffer *internalBuffer_;\n+\t\tcompletionStatus status_;\n \t};\n \n \tenum class State {\n@@ -105,6 +121,11 @@ private:\n \tstd::unique_ptr<CameraMetadata> getResultMetadata(\n \t\tconst Camera3RequestDescriptor &descriptor) const;\n \n+\tvoid sendQueuedCaptureResults();\n+\tvoid streamProcessingComplete(CameraStream *stream,\n+\t\t\t\t      CameraStream::ProcessStatus status,\n+\t\t\t\t      CameraMetadata *resultMetadata);\n+\n \tunsigned int id_;\n \tcamera3_device_t camera3Device_;\n \n@@ -125,6 +146,8 @@ private:\n \tlibcamera::Mutex descriptorsMutex_; /* Protects descriptors_. */\n \tstd::map<uint64_t, Camera3RequestDescriptor> descriptors_;\n \n+\tstd::deque<std::unique_ptr<Camera3RequestDescriptor>> queuedDescriptor_;\n+\n \tstd::string maker_;\n \tstd::string model_;\n \n",
    "prefixes": [
        "libcamera-devel",
        "RFC",
        "v2",
        "4/5"
    ]
}