[libcamera-devel] [PATCH] pipeline: simple: Rework the supportedDevices list

Phi-Bang Nguyen pnguyen at baylibre.com
Mon May 3 14:25:17 CEST 2021


There is a usecase that the same driver may go with a converter
on a platform and with another converter on another platform.

Currently, the simple pipeline handler only takes the 1st driver
it can acquire in the supported devices list and skip the rest.
This makes it take the wrong converter for the above usecase.

So, make the changes to support the above usecase.

Signed-off-by: Phi-Bang Nguyen <pnguyen at baylibre.com>
---
 src/libcamera/pipeline/simple/simple.cpp | 34 +++++++++++++++---------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
index f6095d38..9a572694 100644
--- a/src/libcamera/pipeline/simple/simple.cpp
+++ b/src/libcamera/pipeline/simple/simple.cpp
@@ -127,16 +127,19 @@ class SimplePipelineHandler;
 
 struct SimplePipelineInfo {
 	const char *driver;
-	const char *converter;
-	unsigned int numStreams;
+	/*
+	 * Each converter in the list contains the name
+	 * and the number of streams it supports.
+	 */
+	std::vector<std::pair<const char *, unsigned int>> converters;
 };
 
 namespace {
 
 static const SimplePipelineInfo supportedDevices[] = {
-	{ "imx7-csi", "pxp", 1 },
-	{ "qcom-camss", nullptr, 1 },
-	{ "sun6i-csi", nullptr, 1 },
+	{ "imx7-csi", { { "pxp", 1 } } },
+	{ "qcom-camss", { { nullptr, 1 } } },
+	{ "sun6i-csi", { { nullptr, 1 } } },
 };
 
 } /* namespace */
@@ -145,7 +148,7 @@ class SimpleCameraData : public CameraData
 {
 public:
 	SimpleCameraData(SimplePipelineHandler *pipe,
-			 const SimplePipelineInfo *info,
+			 unsigned int numStreams,
 			 MediaEntity *sensor);
 
 	bool isValid() const { return sensor_ != nullptr; }
@@ -266,9 +269,9 @@ private:
  */
 
 SimpleCameraData::SimpleCameraData(SimplePipelineHandler *pipe,
-				   const SimplePipelineInfo *info,
+				   unsigned int numStreams,
 				   MediaEntity *sensor)
-	: CameraData(pipe), streams_(info->numStreams)
+	: CameraData(pipe), streams_(numStreams)
 {
 	int ret;
 
@@ -934,6 +937,7 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator)
 {
 	const SimplePipelineInfo *info = nullptr;
 	MediaDevice *converter = nullptr;
+	unsigned int numStreams = 1;
 
 	for (const SimplePipelineInfo &inf : supportedDevices) {
 		DeviceMatch dm(inf.driver);
@@ -947,9 +951,15 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator)
 	if (!media_)
 		return false;
 
-	if (info->converter) {
-		DeviceMatch converterMatch(info->converter);
-		converter = acquireMediaDevice(enumerator, converterMatch);
+	for (const auto &cvt : info->converters) {
+		if (cvt.first) {
+			DeviceMatch converterMatch(cvt.first);
+			converter = acquireMediaDevice(enumerator, converterMatch);
+			if (converter) {
+				numStreams = cvt.second;
+				break;
+			}
+		}
 	}
 
 	/* Locate the sensors. */
@@ -983,7 +993,7 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator)
 
 	for (MediaEntity *sensor : sensors) {
 		std::unique_ptr<SimpleCameraData> data =
-			std::make_unique<SimpleCameraData>(this, info, sensor);
+			std::make_unique<SimpleCameraData>(this, numStreams, sensor);
 		if (!data->isValid()) {
 			LOG(SimplePipeline, Error)
 				<< "No valid pipeline for sensor '"
-- 
2.25.1



More information about the libcamera-devel mailing list