[libcamera-devel,v1.1,12/13] libcamera: pipeline: simple: Don't disable links carrying other streams
diff mbox series

Message ID 20220802103410.2735-1-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • Untitled series #3358
Related show

Commit Message

Laurent Pinchart Aug. 2, 2022, 10:34 a.m. UTC
If a subdev supports the internal routing API, pads unrelated to the
pipeline for a given camera sensor may carry streams for other cameras.
The link setup logic is updated to take this into account, by avoiding
disabling links to unrelated pads.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
Changes since v1:

- Simplify a condition
- Fix author
---
 src/libcamera/pipeline/simple/simple.cpp | 26 +++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

Comments

Jacopo Mondi Aug. 3, 2022, 12:05 p.m. UTC | #1
Hi Laurent

On Tue, Aug 02, 2022 at 01:34:10PM +0300, Laurent Pinchart via libcamera-devel wrote:
> If a subdev supports the internal routing API, pads unrelated to the
> pipeline for a given camera sensor may carry streams for other cameras.
> The link setup logic is updated to take this into account, by avoiding
> disabling links to unrelated pads.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

Thanks
  j

> ---
> Changes since v1:
>
> - Simplify a condition
> - Fix author
> ---
>  src/libcamera/pipeline/simple/simple.cpp | 26 +++++++++++++++++++++---
>  1 file changed, 23 insertions(+), 3 deletions(-)
>
> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
> index 2a8811183907..0e169fbec1b5 100644
> --- a/src/libcamera/pipeline/simple/simple.cpp
> +++ b/src/libcamera/pipeline/simple/simple.cpp
> @@ -221,6 +221,11 @@ public:
>  	struct Entity {
>  		/* The media entity, always valid. */
>  		MediaEntity *entity;
> +		/*
> +		 * Whether or not the entity is a subdev that supports the
> +		 * routing API.
> +		 */
> +		bool supportsRouting;
>  		/*
>  		 * The local sink pad connected to the upstream entity, null for
>  		 * the camera sensor at the beginning of the pipeline.
> @@ -404,9 +409,13 @@ SimpleCameraData::SimpleCameraData(SimplePipelineHandler *pipe,
>  		 */
>
>  		std::vector<const MediaPad *> pads;
> +		bool supportsRouting = false;
>
> -		if (sinkPad)
> +		if (sinkPad) {
>  			pads = routedSourcePads(sinkPad);
> +			if (!pads.empty())
> +				supportsRouting = true;
> +		}
>
>  		if (pads.empty()) {
>  			for (const MediaPad *pad : entity->pads()) {
> @@ -421,7 +430,9 @@ SimpleCameraData::SimpleCameraData(SimplePipelineHandler *pipe,
>  				MediaEntity *next = link->sink()->entity();
>  				if (visited.find(next) == visited.end()) {
>  					queue.push({ next, link->sink() });
> -					parents.insert({ next, { entity, sinkPad, pad, link } });
> +
> +					Entity e{ entity, supportsRouting, sinkPad, pad, link };
> +					parents.insert({ next, e });
>  				}
>  			}
>  		}
> @@ -435,7 +446,7 @@ SimpleCameraData::SimpleCameraData(SimplePipelineHandler *pipe,
>  	 * to the sensor. Store all the entities in the pipeline, from the
>  	 * camera sensor to the video node, in entities_.
>  	 */
> -	entities_.push_front({ entity, sinkPad, nullptr, nullptr });
> +	entities_.push_front({ entity, false, sinkPad, nullptr, nullptr });
>
>  	for (auto it = parents.find(entity); it != parents.end();
>  	     it = parents.find(entity)) {
> @@ -617,6 +628,15 @@ int SimpleCameraData::setupLinks()
>  		}
>
>  		for (MediaPad *pad : e.entity->pads()) {
> +			/*
> +			 * If the entity supports the V4L2 internal routing API,
> +			 * assume that it may carry multiple independent streams
> +			 * concurrently, and only disable links on the sink and
> +			 * source pads used by the pipeline.
> +			 */
> +			if (e.supportsRouting && pad != e.sink && pad != e.source)
> +				continue;
> +
>  			for (MediaLink *link : pad->links()) {
>  				if (link == sinkLink)
>  					continue;
> --
> Regards,
>
> Laurent Pinchart
>

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
index 2a8811183907..0e169fbec1b5 100644
--- a/src/libcamera/pipeline/simple/simple.cpp
+++ b/src/libcamera/pipeline/simple/simple.cpp
@@ -221,6 +221,11 @@  public:
 	struct Entity {
 		/* The media entity, always valid. */
 		MediaEntity *entity;
+		/*
+		 * Whether or not the entity is a subdev that supports the
+		 * routing API.
+		 */
+		bool supportsRouting;
 		/*
 		 * The local sink pad connected to the upstream entity, null for
 		 * the camera sensor at the beginning of the pipeline.
@@ -404,9 +409,13 @@  SimpleCameraData::SimpleCameraData(SimplePipelineHandler *pipe,
 		 */
 
 		std::vector<const MediaPad *> pads;
+		bool supportsRouting = false;
 
-		if (sinkPad)
+		if (sinkPad) {
 			pads = routedSourcePads(sinkPad);
+			if (!pads.empty())
+				supportsRouting = true;
+		}
 
 		if (pads.empty()) {
 			for (const MediaPad *pad : entity->pads()) {
@@ -421,7 +430,9 @@  SimpleCameraData::SimpleCameraData(SimplePipelineHandler *pipe,
 				MediaEntity *next = link->sink()->entity();
 				if (visited.find(next) == visited.end()) {
 					queue.push({ next, link->sink() });
-					parents.insert({ next, { entity, sinkPad, pad, link } });
+
+					Entity e{ entity, supportsRouting, sinkPad, pad, link };
+					parents.insert({ next, e });
 				}
 			}
 		}
@@ -435,7 +446,7 @@  SimpleCameraData::SimpleCameraData(SimplePipelineHandler *pipe,
 	 * to the sensor. Store all the entities in the pipeline, from the
 	 * camera sensor to the video node, in entities_.
 	 */
-	entities_.push_front({ entity, sinkPad, nullptr, nullptr });
+	entities_.push_front({ entity, false, sinkPad, nullptr, nullptr });
 
 	for (auto it = parents.find(entity); it != parents.end();
 	     it = parents.find(entity)) {
@@ -617,6 +628,15 @@  int SimpleCameraData::setupLinks()
 		}
 
 		for (MediaPad *pad : e.entity->pads()) {
+			/*
+			 * If the entity supports the V4L2 internal routing API,
+			 * assume that it may carry multiple independent streams
+			 * concurrently, and only disable links on the sink and
+			 * source pads used by the pipeline.
+			 */
+			if (e.supportsRouting && pad != e.sink && pad != e.source)
+				continue;
+
 			for (MediaLink *link : pad->links()) {
 				if (link == sinkLink)
 					continue;