Patch Detail
Show a patch.
GET /api/1.1/patches/12530/?format=api
{ "id": 12530, "url": "https://patchwork.libcamera.org/api/1.1/patches/12530/?format=api", "web_url": "https://patchwork.libcamera.org/patch/12530/", "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": "<20210608151633.73465-9-jacopo@jmondi.org>", "date": "2021-06-08T15:16:33", "name": "[libcamera-devel,v5,8/8] android: Implement flush() camera operation", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "47ff262e1f972c993ec0e0bd3a4a1042fdb60733", "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/12530/mbox/", "series": [ { "id": 2112, "url": "https://patchwork.libcamera.org/api/1.1/series/2112/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2112", "date": "2021-06-08T15:16:25", "name": "Implement flush() camera operation", "version": 5, "mbox": "https://patchwork.libcamera.org/series/2112/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/12530/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/12530/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 B844BC3213\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 8 Jun 2021 15:15:58 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 834806892E;\n\tTue, 8 Jun 2021 17:15:58 +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 2798F68932\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 8 Jun 2021 17:15:57 +0200 (CEST)", "(Authenticated sender: jacopo@jmondi.org)\n\tby relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 4459860006;\n\tTue, 8 Jun 2021 15:15:56 +0000 (UTC)" ], "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 8 Jun 2021 17:16:33 +0200", "Message-Id": "<20210608151633.73465-9-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.31.1", "In-Reply-To": "<20210608151633.73465-1-jacopo@jmondi.org>", "References": "<20210608151633.73465-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v5 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>\nReviewed-by: Hirokazu Honda <hiroh@chromium.org>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/android/camera_device.cpp | 77 +++++++++++++++++++++++++++--------\n src/android/camera_device.h | 3 ++\n src/android/camera_ops.cpp | 8 +++-\n 3 files changed, 71 insertions(+), 17 deletions(-)", "diff": "diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex b29c1edc9970..3adb657bfeca 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -798,6 +798,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@@ -1896,27 +1913,31 @@ int CameraDevice::processControls(Camera3RequestDescriptor *descriptor)\n \treturn 0;\n }\n \n-int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request)\n+void CameraDevice::abortRequest(camera3_capture_request_t *request)\n {\n-\tif (!isValidRequest(camera3Request))\n-\t\treturn -EINVAL;\n+\tnotifyError(request->frame_number, nullptr, CAMERA3_MSG_ERROR_REQUEST);\n \n-\t{\n-\t\tMutexLocker stateLock(stateMutex_);\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-\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+\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-\t\t\tint ret = camera_->start();\n-\t\t\tif (ret) {\n-\t\t\t\tLOG(HAL, Error) << \"Failed to start camera\";\n-\t\t\t\treturn ret;\n-\t\t\t}\n+\tcallbacks_->process_capture_result(callbacks_, &result);\n+}\n \n-\t\t\tstate_ = State::Running;\n-\t\t}\n-\t}\n+int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request)\n+{\n+\tif (!isValidRequest(camera3Request))\n+\t\treturn -EINVAL;\n \n \t/*\n \t * Save the request descriptors for use at completion time.\n@@ -2006,6 +2027,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", "v5", "8/8" ] }