[libcamera-devel,v3,3/3] android: CameraDevice: Implement HAL3 API flush
diff mbox series

Message ID 20210426083830.2965095-4-hiroh@chromium.org
State Superseded
Headers show
Series
  • Support HAL3 API flush
Related show

Commit Message

Hirokazu Honda April 26, 2021, 8:38 a.m. UTC
This implements flush(). It is mostly the same as close()
though the canceled events are reported with error messages.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
---
 src/android/camera_device.cpp | 28 ++++++++++++++++++++++++++++
 src/android/camera_device.h   |  1 +
 src/android/camera_ops.cpp    |  8 ++++++--
 3 files changed, 35 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 96c8d4a9..fb89195e 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -750,6 +750,15 @@  void CameraDevice::close()
 	camera_->release();
 }
 
+int CameraDevice::flush()
+{
+	std::scoped_lock<std::mutex> halLock(halMutex_);
+
+	stop();
+
+	return 0;
+}
+
 void CameraDevice::stop()
 {
 	if (!running_)
@@ -760,6 +769,25 @@  void CameraDevice::stop()
 
 	{
 		std::scoped_lock<std::mutex> lock(mutex_);
+
+		for (auto &[cookie, descriptor] : descriptors_) {
+			LOG(HAL, Debug) << "request is canceled: " << cookie;
+
+			camera3_capture_result_t captureResult = {};
+			captureResult.frame_number = descriptor.frameNumber_;
+			captureResult.num_output_buffers = descriptor.buffers_.size();
+			for (camera3_stream_buffer_t &buffer : descriptor.buffers_) {
+				buffer.acquire_fence = -1;
+				buffer.release_fence = -1;
+				buffer.status = CAMERA3_BUFFER_STATUS_ERROR;
+			}
+			captureResult.output_buffers = descriptor.buffers_.data();
+
+			notifyError(descriptor.frameNumber_,
+				    descriptor.buffers_[0].stream);
+			callbacks_->process_capture_result(callbacks_, &captureResult);
+		}
+
 		descriptors_.clear();
 	}
 
diff --git a/src/android/camera_device.h b/src/android/camera_device.h
index 325fb967..fa652c3c 100644
--- a/src/android/camera_device.h
+++ b/src/android/camera_device.h
@@ -41,6 +41,7 @@  public:
 
 	int open(const hw_module_t *hardwareModule);
 	void close();
+	int flush();
 
 	unsigned int id() const { return id_; }
 	camera3_device_t *camera3Device() { return &camera3Device_; }
diff --git a/src/android/camera_ops.cpp b/src/android/camera_ops.cpp
index 696e8043..01458403 100644
--- a/src/android/camera_ops.cpp
+++ b/src/android/camera_ops.cpp
@@ -66,9 +66,13 @@  static void hal_dev_dump([[maybe_unused]] const struct camera3_device *dev,
 {
 }
 
-static int hal_dev_flush([[maybe_unused]] const struct camera3_device *dev)
+static int hal_dev_flush(const struct camera3_device *dev)
 {
-	return 0;
+	if (!dev)
+		return -EINVAL;
+
+	CameraDevice *camera = reinterpret_cast<CameraDevice *>(dev->priv);
+	return camera->flush();
 }
 
 int hal_dev_close(hw_device_t *hw_device)