On 10/10/2021 04:23, Laurent Pinchart wrote:
Hi Tomi,
Thank you for the patch.
On Tue, Oct 05, 2021 at 11:57:50AM +0300, Tomi Valkeinen wrote:
Add a helper for verifying routing for the common case of
non-overlapping 1-to-1 streams.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@xxxxxxxxxxxxxxxx>
---
drivers/media/v4l2-core/v4l2-subdev.c | 24 ++++++++++++++++++++++++
include/media/v4l2-subdev.h | 14 ++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index 22a9bea0fa85..2a64ff003e4b 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -1569,3 +1569,27 @@ int v4l2_subdev_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *state,
return 0;
}
EXPORT_SYMBOL_GPL(v4l2_subdev_get_fmt);
+
+int v4l2_routing_simple_verify(const struct v4l2_subdev_krouting *routing)
+{
+ unsigned int i, j;
+
+ for (i = 0; i < routing->num_routes; ++i) {
+ const struct v4l2_subdev_route *route = &routing->routes[i];
+
+ for (j = i + 1; j < routing->num_routes; ++j) {
+ const struct v4l2_subdev_route *r = &routing->routes[j];
+
+ if (route->sink_pad == r->sink_pad &&
+ route->sink_stream == r->sink_stream)
+ return -EINVAL;
+
+ if (route->source_pad == r->source_pad &&
+ route->source_stream == r->source_stream)
+ return -EINVAL;
+ }
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(v4l2_routing_simple_verify);
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index 1a4df0aafe8a..5e50f2ded653 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -1565,4 +1565,18 @@ v4l2_state_get_opposite_stream_format(struct v4l2_subdev_state *state, u32 pad,
int v4l2_subdev_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *state,
struct v4l2_subdev_format *format);
+/**
+ * v4l2_routing_simple_verify() - Verify that all streams are non-overlapping
+ * 1-to-1 streams
Let's reflect this in the function name then, we can call it
v4l2_routing_verify_1_to_1(). This will make it possible to add a
v4l2_subdev_routing_validate_1_to_n() later.
Sounds fine to me.
I'd rename verify to validate though, and add subdev to the function
name, calling it v4l2_subdev_routing_validate_1_to_1().
I don't mind changing the name, but what's the difference with verify
and validate?
Tomi