[v2,1/4] converter: converter_v4l2_m2m: Rectify streams sanity check
diff mbox series

Message ID 20240529070248.12186-2-umang.jain@ideasonboard.com
State Superseded
Headers show
Series
  • libcamera: converter: Replace usage of stream index by Stream pointer
Related show

Commit Message

Umang Jain May 29, 2024, 7:02 a.m. UTC
The streams sanity check tries to determine if all the stream indexes
passed in outputs std::map<> are unique. However, since the data
container is std::map<>, all its keys (stream indexes in this case),
are already unique.

Instead, rectify the sanity check to ensure all the framebuffers passed
in the outputs std::map<> are unique to each index. Hence, no two stream
indexes should have same framebuffer. Update the comment to reflect
the change.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
 src/libcamera/converter/converter_v4l2_m2m.cpp | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Comments

Kieran Bingham May 29, 2024, 11:01 a.m. UTC | #1
Quoting Umang Jain (2024-05-29 08:02:45)
> The streams sanity check tries to determine if all the stream indexes
> passed in outputs std::map<> are unique. However, since the data
> container is std::map<>, all its keys (stream indexes in this case),
> are already unique.

Good point ;-) So the current mask is fairly redundant...

> 
> Instead, rectify the sanity check to ensure all the framebuffers passed
> in the outputs std::map<> are unique to each index. Hence, no two stream
> indexes should have same framebuffer. Update the comment to reflect
> the change.

I was going to say surely this is just a precursor to the next patches,
but I do think it holds up on it's own now I realised the index is
indeed already a std::map key...


Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> ---
>  src/libcamera/converter/converter_v4l2_m2m.cpp | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/src/libcamera/converter/converter_v4l2_m2m.cpp b/src/libcamera/converter/converter_v4l2_m2m.cpp
> index d8929fc5..27a50e34 100644
> --- a/src/libcamera/converter/converter_v4l2_m2m.cpp
> +++ b/src/libcamera/converter/converter_v4l2_m2m.cpp
> @@ -403,13 +403,13 @@ void V4L2M2MConverter::stop()
>  int V4L2M2MConverter::queueBuffers(FrameBuffer *input,
>                                    const std::map<unsigned int, FrameBuffer *> &outputs)
>  {
> -       unsigned int mask = 0;
> +       std::set<FrameBuffer *> outputBufs;
>         int ret;
>  
>         /*
>          * Validate the outputs as a sanity check: at least one output is
>          * required, all outputs must reference a valid stream and no two
> -        * outputs can reference the same stream.
> +        * streams can reference same output framebuffers.
>          */
>         if (outputs.empty())
>                 return -EINVAL;
> @@ -419,12 +419,13 @@ int V4L2M2MConverter::queueBuffers(FrameBuffer *input,
>                         return -EINVAL;
>                 if (index >= streams_.size())
>                         return -EINVAL;
> -               if (mask & (1 << index))
> -                       return -EINVAL;
>  
> -               mask |= 1 << index;
> +               outputBufs.insert(buffer);
>         }
>  
> +       if (outputBufs.size() != streams_.size())
> +               return -EINVAL;
> +
>         /* Queue the input and output buffers to all the streams. */
>         for (auto [index, buffer] : outputs) {
>                 ret = streams_[index].queueBuffers(input, buffer);
> -- 
> 2.44.0
>

Patch
diff mbox series

diff --git a/src/libcamera/converter/converter_v4l2_m2m.cpp b/src/libcamera/converter/converter_v4l2_m2m.cpp
index d8929fc5..27a50e34 100644
--- a/src/libcamera/converter/converter_v4l2_m2m.cpp
+++ b/src/libcamera/converter/converter_v4l2_m2m.cpp
@@ -403,13 +403,13 @@  void V4L2M2MConverter::stop()
 int V4L2M2MConverter::queueBuffers(FrameBuffer *input,
 				   const std::map<unsigned int, FrameBuffer *> &outputs)
 {
-	unsigned int mask = 0;
+	std::set<FrameBuffer *> outputBufs;
 	int ret;
 
 	/*
 	 * Validate the outputs as a sanity check: at least one output is
 	 * required, all outputs must reference a valid stream and no two
-	 * outputs can reference the same stream.
+	 * streams can reference same output framebuffers.
 	 */
 	if (outputs.empty())
 		return -EINVAL;
@@ -419,12 +419,13 @@  int V4L2M2MConverter::queueBuffers(FrameBuffer *input,
 			return -EINVAL;
 		if (index >= streams_.size())
 			return -EINVAL;
-		if (mask & (1 << index))
-			return -EINVAL;
 
-		mask |= 1 << index;
+		outputBufs.insert(buffer);
 	}
 
+	if (outputBufs.size() != streams_.size())
+		return -EINVAL;
+
 	/* Queue the input and output buffers to all the streams. */
 	for (auto [index, buffer] : outputs) {
 		ret = streams_[index].queueBuffers(input, buffer);