[libcamera-devel] [PATCH 02/10] libcamera: pipeline: simple: Add sink and source pads to entity data

Laurent Pinchart laurent.pinchart at ideasonboard.com
Fri Aug 6 00:24:28 CEST 2021


Record the sink and source pads through which an entity is traversed in
the list of entities stored in the camera data. This prepares for
implementing mutually exclusive access to entities between cameras.

Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
 src/libcamera/pipeline/simple/simple.cpp | 38 ++++++++++++++++++++----
 1 file changed, 32 insertions(+), 6 deletions(-)

diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
index b29fff9820e5..e0695d052629 100644
--- a/src/libcamera/pipeline/simple/simple.cpp
+++ b/src/libcamera/pipeline/simple/simple.cpp
@@ -166,7 +166,22 @@ public:
 	}
 
 	struct Entity {
+		/* The media entity, always valid. */
 		MediaEntity *entity;
+		/*
+		 * The local sink pad connected to the upstream entity, null for
+		 * the camera sensor at the beginning of the pipeline.
+		 */
+		const MediaPad *sink;
+		/*
+		 * The local source pad connected to the downstream entity, null
+		 * for the video node at the end of the pipeline.
+		 */
+		const MediaPad *source;
+		/*
+		 * The link to the downstream entity, null for the video node at
+		 * the end of the pipeline.
+		 */
 		MediaLink *link;
 	};
 
@@ -288,16 +303,18 @@ SimpleCameraData::SimpleCameraData(SimplePipelineHandler *pipe,
 	 * encoders and image converters, and will end in a CSI capture device.
 	 */
 	std::unordered_set<MediaEntity *> visited;
-	std::queue<MediaEntity *> queue;
+	std::queue<std::tuple<MediaEntity *, MediaPad *>> queue;
 
 	/* Remember at each entity where we came from. */
 	std::unordered_map<MediaEntity *, Entity> parents;
 	MediaEntity *entity = nullptr;
 
-	queue.push(sensor);
+	queue.push({ sensor, nullptr });
 
 	while (!queue.empty()) {
-		entity = queue.front();
+		MediaPad *sinkPad;
+
+		std::tie(entity, sinkPad) = queue.front();
 		queue.pop();
 
 		/* Found the capture device. */
@@ -317,8 +334,8 @@ SimpleCameraData::SimpleCameraData(SimplePipelineHandler *pipe,
 			for (MediaLink *link : pad->links()) {
 				MediaEntity *next = link->sink()->entity();
 				if (visited.find(next) == visited.end()) {
-					queue.push(next);
-					parents.insert({ next, { entity, link } });
+					queue.push({ next, link->sink() });
+					parents.insert({ next, { entity, sinkPad, pad, link } });
 				}
 			}
 		}
@@ -349,7 +366,16 @@ SimpleCameraData::SimpleCameraData(SimplePipelineHandler *pipe,
 	LOG(SimplePipeline, Debug)
 		<< "Found pipeline: "
 		<< utils::join(entities_, " -> ",
-			       [](const Entity &e) { return e.entity->name(); });
+			       [](const Entity &e) {
+				       std::string s = "[";
+				       if (e.sink)
+					       s += std::to_string(e.sink->index()) + "|";
+				       s += e.entity->name();
+				       if (e.source)
+					       s += "|" + std::to_string(e.source->index());
+				       s += "]";
+				       return s;
+			       });
 }
 
 int SimpleCameraData::init()
-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list