[libcamera-devel,v4,07/16] android: capabilities: Initialize camera state when building properties
diff mbox series

Message ID 20211014174208.50509-8-jacopo@jmondi.org
State Accepted
Headers show
Series
  • IPU3 control info update and HAL frame durations
Related show

Commit Message

Jacopo Mondi Oct. 14, 2021, 5:41 p.m. UTC
Now that building the list of supported stream configuration requires
applying a configuration to the Camera, re-initialize the camera
controls by applying a configuration generated for the Viewfinder stream
role before building the list of static metadata.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/android/camera_capabilities.cpp | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

Patch
diff mbox series

diff --git a/src/android/camera_capabilities.cpp b/src/android/camera_capabilities.cpp
index 1583a0a09cee..a98e6099bb77 100644
--- a/src/android/camera_capabilities.cpp
+++ b/src/android/camera_capabilities.cpp
@@ -394,11 +394,14 @@  int CameraCapabilities::initialize(std::shared_ptr<Camera> camera,
 	}
 
 	ret = initializeStreamConfigurations();
-	camera_->release();
-	if (ret)
+	if (ret) {
+		camera_->release();
 		return ret;
+	}
 
-	return initializeStaticMetadata();
+	ret = initializeStaticMetadata();
+	camera_->release();
+	return ret;
 }
 
 std::vector<Size>
@@ -696,6 +699,25 @@  int CameraCapabilities::initializeStaticMetadata()
 		return -EINVAL;
 	}
 
+	/*
+	 * Generate and apply a new configuration for the Viewfinder role to
+	 * collect control limits and properties from a known state.
+	 */
+	std::unique_ptr<CameraConfiguration> cameraConfig =
+		camera_->generateConfiguration({ StreamRole::Viewfinder });
+	if (!cameraConfig) {
+		LOG(HAL, Error) << "Failed to generate camera configuration";
+		staticMetadata_.reset();
+		return -ENODEV;
+	}
+
+	int ret = camera_->configure(cameraConfig.get());
+	if (ret) {
+		LOG(HAL, Error) << "Failed to initialize the camera state";
+		staticMetadata_.reset();
+		return ret;
+	}
+
 	const ControlInfoMap &controlsInfo = camera_->controls();
 	const ControlList &properties = camera_->properties();