[v1] libcamera: camera_sensor: Fix imageStream() for CameraSensorLegacy class
diff mbox series

Message ID 20251016152738.2708250-1-julien.vuillaumier@nxp.com
State New
Headers show
Series
  • [v1] libcamera: camera_sensor: Fix imageStream() for CameraSensorLegacy class
Related show

Commit Message

Julien Vuillaumier Oct. 16, 2025, 3:27 p.m. UTC
The CameraSensor::imageStream() function has a default implementation
in the base class that returns {0, 0} as {pad, stream}, assuming that
the image pad is located on the pad index 0.
This assumption is correct most of the time, but not in some other
cases, for instance when an external ISP entity acts as the sensor.
Such entity would typically have sink pad(s) connected to the actual
sensor and source pad(s) connected to the downstream graph. Associated
pad indexes would likely be different from zero.

CameraSensorLegacy subclass correctly handles this case in its
functions, using the pad_ variable discovered at init() time to access
the source pad index, instead of using a hardcoded zero value.
Exception is imageStream() that is not overriden in the
CameraSensorLegacy definition so keeps the default implementation of
the parent class, hardcoding the returned source pad index to zero.

This change declares CameraSensor::imageStream() as a pure virtual to
let the subclasses provide an implementation. Implementation for
CameraSensorLegacy is added, based on pad_ variable usage.

Signed-off-by: Julien Vuillaumier <julien.vuillaumier@nxp.com>
---
 include/libcamera/internal/camera_sensor.h    | 2 +-
 src/libcamera/sensor/camera_sensor.cpp        | 4 ----
 src/libcamera/sensor/camera_sensor_legacy.cpp | 6 ++++++
 3 files changed, 7 insertions(+), 5 deletions(-)

Patch
diff mbox series

diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
index f6ef4df1..eed919a1 100644
--- a/include/libcamera/internal/camera_sensor.h
+++ b/include/libcamera/internal/camera_sensor.h
@@ -64,7 +64,7 @@  public:
 				       Transform transform = Transform::Identity,
 				       V4L2SubdeviceFormat *sensorFormat = nullptr) = 0;
 
-	virtual V4L2Subdevice::Stream imageStream() const;
+	virtual V4L2Subdevice::Stream imageStream() const = 0;
 	virtual std::optional<V4L2Subdevice::Stream> embeddedDataStream() const;
 	virtual V4L2SubdeviceFormat embeddedDataFormat() const;
 	virtual int setEmbeddedDataEnabled(bool enable);
diff --git a/src/libcamera/sensor/camera_sensor.cpp b/src/libcamera/sensor/camera_sensor.cpp
index 4f2fd269..50f2b98d 100644
--- a/src/libcamera/sensor/camera_sensor.cpp
+++ b/src/libcamera/sensor/camera_sensor.cpp
@@ -209,10 +209,6 @@  CameraSensor::~CameraSensor() = default;
  *
  * \return The image source stream
  */
-V4L2Subdevice::Stream CameraSensor::imageStream() const
-{
-	return { 0, 0 };
-}
 
 /**
  * \brief Retrieve the embedded data source stream
diff --git a/src/libcamera/sensor/camera_sensor_legacy.cpp b/src/libcamera/sensor/camera_sensor_legacy.cpp
index f9e685a9..a75c8457 100644
--- a/src/libcamera/sensor/camera_sensor_legacy.cpp
+++ b/src/libcamera/sensor/camera_sensor_legacy.cpp
@@ -84,6 +84,7 @@  public:
 			       Transform transform = Transform::Identity,
 			       V4L2SubdeviceFormat *sensorFormat = nullptr) override;
 
+	V4L2Subdevice::Stream imageStream() const override;
 	const ControlList &properties() const override { return properties_; }
 	int sensorInfo(IPACameraSensorInfo *info) const override;
 	Transform computeTransform(Orientation *orientation) const override;
@@ -855,6 +856,11 @@  int CameraSensorLegacy::applyConfiguration(const SensorConfiguration &config,
 	return 0;
 }
 
+V4L2Subdevice::Stream CameraSensorLegacy::imageStream() const
+{
+	return { pad_, 0 };
+}
+
 int CameraSensorLegacy::sensorInfo(IPACameraSensorInfo *info) const
 {
 	if (!bayerFormat_)