Patch Detail
Show a patch.
GET /api/1.1/patches/12462/?format=api
{ "id": 12462, "url": "https://patchwork.libcamera.org/api/1.1/patches/12462/?format=api", "web_url": "https://patchwork.libcamera.org/patch/12462/", "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": "<20210527220359.30127-9-jacopo@jmondi.org>", "date": "2021-05-27T22:03:59", "name": "[libcamera-devel,v4,8/8] android: Implement flush() camera operation", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "7b8ae19b2de428eb5fd0d41a5f52f3192a3c67d9", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/1.1/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": { "id": 15, "url": "https://patchwork.libcamera.org/api/1.1/users/15/?format=api", "username": "jmondi", "first_name": "Jacopo", "last_name": "Mondi", "email": "jacopo@jmondi.org" }, "mbox": "https://patchwork.libcamera.org/patch/12462/mbox/", "series": [ { "id": 2088, "url": "https://patchwork.libcamera.org/api/1.1/series/2088/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2088", "date": "2021-05-27T22:03:51", "name": "Implement flush() camera operation", "version": 4, "mbox": "https://patchwork.libcamera.org/series/2088/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/12462/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/12462/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 C3DEFC3206\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 27 May 2021 22:03:35 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 65DF768937;\n\tFri, 28 May 2021 00:03:34 +0200 (CEST)", "from relay10.mail.gandi.net (relay10.mail.gandi.net\n\t[217.70.178.230])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 47BA268925\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 28 May 2021 00:03:27 +0200 (CEST)", "(Authenticated sender: jacopo@jmondi.org)\n\tby relay10.mail.gandi.net (Postfix) with ESMTPSA id 9276D240005;\n\tThu, 27 May 2021 22:03:26 +0000 (UTC)" ], "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Fri, 28 May 2021 00:03:59 +0200", "Message-Id": "<20210527220359.30127-9-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.31.1", "In-Reply-To": "<20210527220359.30127-1-jacopo@jmondi.org>", "References": "<20210527220359.30127-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v4 8/8] android: Implement flush() camera\n\toperation", "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": "Implement the flush() camera operation in the CameraDevice class\nand make it available to the camera framework by implementing the\noperation wrapper in camera_ops.cpp.\n\nIntroduce a new camera state State::Flushing to handle concurrent\nflush() and process_capture_request() calls.\n\nAs flush() can race with processCaptureRequest() protect it\nby introducing a new State::Flushing state that\nprocessCaptureRequest() inspects before queuing the Request to the\nCamera. If flush() is in progress while processCaptureRequest() is\ncalled, return the current Request immediately in error state. If\nflush() has completed and a new call to processCaptureRequest() is\nmade just after, start the camera again before queuing the request.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/android/camera_device.cpp | 74 ++++++++++++++++++++++++++++++++++-\n src/android/camera_device.h | 3 ++\n src/android/camera_ops.cpp | 8 +++-\n 3 files changed, 83 insertions(+), 2 deletions(-)", "diff": "diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex a20c3eaa0ff6..6a8d4d4d5f76 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -797,6 +797,23 @@ void CameraDevice::close()\n \tcamera_->release();\n }\n \n+void CameraDevice::flush()\n+{\n+\t{\n+\t\tMutexLocker stateLock(stateMutex_);\n+\t\tif (state_ != State::Running)\n+\t\t\treturn;\n+\n+\t\tstate_ = State::Flushing;\n+\t}\n+\n+\tworker_.stop();\n+\tcamera_->stop();\n+\n+\tMutexLocker stateLock(stateMutex_);\n+\tstate_ = State::Stopped;\n+}\n+\n void CameraDevice::stop()\n {\n \tMutexLocker stateLock(stateMutex_);\n@@ -1894,15 +1911,46 @@ int CameraDevice::processControls(Camera3RequestDescriptor *descriptor)\n \treturn 0;\n }\n \n+void CameraDevice::abortRequest(camera3_capture_request_t *request)\n+{\n+\tnotifyError(request->frame_number, nullptr, CAMERA3_MSG_ERROR_REQUEST);\n+\n+\tcamera3_capture_result_t result = {};\n+\tresult.num_output_buffers = request->num_output_buffers;\n+\tresult.frame_number = request->frame_number;\n+\tresult.partial_result = 0;\n+\n+\tstd::vector<camera3_stream_buffer_t> resultBuffers(result.num_output_buffers);\n+\tfor (auto [i, buffer] : utils::enumerate(resultBuffers)) {\n+\t\tbuffer = request->output_buffers[i];\n+\t\tbuffer.release_fence = request->output_buffers[i].acquire_fence;\n+\t\tbuffer.acquire_fence = -1;\n+\t\tbuffer.status = CAMERA3_BUFFER_STATUS_ERROR;\n+\t}\n+\tresult.output_buffers = resultBuffers.data();\n+\n+\tcallbacks_->process_capture_result(callbacks_, &result);\n+}\n+\n int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request)\n {\n \tif (!isValidRequest(camera3Request))\n \t\treturn -EINVAL;\n \n \t{\n+\t\t/*\n+\t\t * Start the camera if that's the first request we handle after\n+\t\t * a configuration or after a flush.\n+\t\t *\n+\t\t * If flush is in progress, return the pending request\n+\t\t * immediately in error state.\n+\t\t */\n \t\tMutexLocker stateLock(stateMutex_);\n+\t\tif (state_ == State::Flushing) {\n+\t\t\tabortRequest(camera3Request);\n+\t\t\treturn 0;\n+\t\t}\n \n-\t\t/* Start the camera if that's the first request we handle. */\n \t\tif (state_ == State::Stopped) {\n \t\t\tworker_.start();\n \n@@ -2004,6 +2052,30 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n \tif (ret)\n \t\treturn ret;\n \n+\t/*\n+\t * Just before queuing the request, make sure flush() has not\n+\t * been called while this function was running. If flush is in progress\n+\t * abort the request. If flush has completed and has stopped the camera\n+\t * we have to re-start it to be able to process the request.\n+\t */\n+\tMutexLocker stateLock(stateMutex_);\n+\tif (state_ == State::Flushing) {\n+\t\tabortRequest(camera3Request);\n+\t\treturn 0;\n+\t}\n+\n+\tif (state_ == State::Stopped) {\n+\t\tworker_.start();\n+\n+\t\tret = camera_->start();\n+\t\tif (ret) {\n+\t\t\tLOG(HAL, Error) << \"Failed to start camera\";\n+\t\t\treturn ret;\n+\t\t}\n+\n+\t\tstate_ = State::Running;\n+\t}\n+\n \tworker_.queueRequest(descriptor.request_.get());\n \n \t{\ndiff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex c949fa509ca4..4aadb27c562c 100644\n--- a/src/android/camera_device.h\n+++ b/src/android/camera_device.h\n@@ -43,6 +43,7 @@ public:\n \n \tint open(const hw_module_t *hardwareModule);\n \tvoid close();\n+\tvoid flush();\n \n \tunsigned int id() const { return id_; }\n \tcamera3_device_t *camera3Device() { return &camera3Device_; }\n@@ -92,6 +93,7 @@ private:\n \n \tenum class State {\n \t\tStopped,\n+\t\tFlushing,\n \t\tRunning,\n \t};\n \n@@ -106,6 +108,7 @@ private:\n \tgetRawResolutions(const libcamera::PixelFormat &pixelFormat);\n \n \tlibcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer);\n+\tvoid abortRequest(camera3_capture_request_t *request);\n \tvoid notifyShutter(uint32_t frameNumber, uint64_t timestamp);\n \tvoid notifyError(uint32_t frameNumber, camera3_stream_t *stream,\n \t\t\t camera3_error_msg_code code);\ndiff --git a/src/android/camera_ops.cpp b/src/android/camera_ops.cpp\nindex 696e80436821..8a3cfa175ff5 100644\n--- a/src/android/camera_ops.cpp\n+++ b/src/android/camera_ops.cpp\n@@ -66,8 +66,14 @@ static void hal_dev_dump([[maybe_unused]] const struct camera3_device *dev,\n {\n }\n \n-static int hal_dev_flush([[maybe_unused]] const struct camera3_device *dev)\n+static int hal_dev_flush(const struct camera3_device *dev)\n {\n+\tif (!dev)\n+\t\treturn -EINVAL;\n+\n+\tCameraDevice *camera = reinterpret_cast<CameraDevice *>(dev->priv);\n+\tcamera->flush();\n+\n \treturn 0;\n }\n \n", "prefixes": [ "libcamera-devel", "v4", "8/8" ] }