[RFC,v1,1/2] libcamera: camera_sensor: Enable routes to query stream formats
diff mbox series

Message ID 20251024151058.1523308-2-julien.vuillaumier@nxp.com
State New
Headers show
Series
  • libcamera: camera_sensor: Add support for an additional image stream
Related show

Commit Message

Julien Vuillaumier Oct. 24, 2025, 3:10 p.m. UTC
When a V4L2 device supports streams, the route activating a stream
needs to be active so that this stream format can be queried.
For a raw camera sensor, an internal route may be inactive by default
when it is mutable.

Implementation of CameraSensorRaw::init() probes at startup time the
format of the pads/streams attached to the internal routes of a camera
subdevice, in order to identify the streams it exposes and their type.
To make sure the format of the streams can be retrieved, activate the
internal routes of the subdevice before querying, and restore the
initial route states when finished.

Signed-off-by: Julien Vuillaumier <julien.vuillaumier@nxp.com>
---
 src/libcamera/sensor/camera_sensor_raw.cpp | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

Patch
diff mbox series

diff --git a/src/libcamera/sensor/camera_sensor_raw.cpp b/src/libcamera/sensor/camera_sensor_raw.cpp
index 8ea44236..ad4a94ad 100644
--- a/src/libcamera/sensor/camera_sensor_raw.cpp
+++ b/src/libcamera/sensor/camera_sensor_raw.cpp
@@ -261,6 +261,21 @@  std::optional<int> CameraSensorRaw::init()
 	if (ret)
 		return { ret };
 
+	/* Activate all routes to query pads formats */
+	V4L2Subdevice::Routing routingActive = routing;
+	for (V4L2Subdevice::Route &route : routingActive) {
+		if (route.source.pad != sourcePad) {
+			LOG(CameraSensor, Error) << "Invalid route " << route;
+			return { -EINVAL };
+		}
+		route.flags = V4L2_SUBDEV_ROUTE_FL_ACTIVE;
+	}
+	ret = subdev_->setRouting(&routingActive);
+	if (ret) {
+		LOG(CameraSensor, Error) << "Could not set routes to active";
+		return { -EINVAL };
+	}
+
 	bool imageStreamFound = false;
 
 	for (const V4L2Subdevice::Route &route : routing) {
@@ -348,6 +363,13 @@  std::optional<int> CameraSensorRaw::init()
 			<< "Found embedded data stream " << streams_.edata->sink
 			<< " -> " << streams_.edata->source;
 
+	/* Restore the routes to their initial state */
+	ret = subdev_->setRouting(&routing);
+	if (ret) {
+		LOG(CameraSensor, Error) << "Could not restore routes state";
+		return { -EINVAL };
+	}
+
 	/*
 	 * 2. Enumerate and cache the media bus codes, sizes and colour filter
 	 * array order for the image stream.