[libcamera-devel] libcamera: v4l2_videodevice: Explain multiplanar bytesused reasoning
diff mbox series

Message ID 20211022100042.4187349-1-kieran.bingham@ideasonboard.com
State Accepted
Commit 1402152ad35017a817b1ead55e60ace9353efbdb
Headers show
Series
  • [libcamera-devel] libcamera: v4l2_videodevice: Explain multiplanar bytesused reasoning
Related show

Commit Message

Kieran Bingham Oct. 22, 2021, 10 a.m. UTC
The ternary operation used to get the total bytesused of a V4L2 single
planar format which is stored in a multiplanar buffer can easily be
mis-read to think it's a bug, and appears to be reading the value of the
first of N planes as the total.

Directly explain the reasoning for why it looks like the condition is
inverted, as it is correct that the total bytes used is stored in only
the first plane of the multiplanar buffer.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

---
v2:
 - Update with more descriptive text from Laurent

 src/libcamera/v4l2_videodevice.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Paul Elder Oct. 22, 2021, 10:21 a.m. UTC | #1
Hi Kieran,

On Fri, Oct 22, 2021 at 11:00:42AM +0100, Kieran Bingham wrote:
> The ternary operation used to get the total bytesused of a V4L2 single
> planar format which is stored in a multiplanar buffer can easily be
> mis-read to think it's a bug, and appears to be reading the value of the
> first of N planes as the total.
> 
> Directly explain the reasoning for why it looks like the condition is
> inverted, as it is correct that the total bytes used is stored in only
> the first plane of the multiplanar buffer.
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> 
> ---
> v2:
>  - Update with more descriptive text from Laurent
> 
>  src/libcamera/v4l2_videodevice.cpp | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> index 2745e5798419..0cc622f91f2d 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -1711,6 +1711,13 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer()
>  			return buffer;
>  		}
>  
> +		/*
> +		 * With a V4L2 single-planar format, all the data is stored in
> +		 * a single memory plane. The number of bytes used is conveyed
> +		 * through that plane when using the V4L2 multi-planar API, or
> +		 * set directly in the buffer when using the V4L2 single-planar
> +		 * API.
> +		 */
>  		unsigned int bytesused = multiPlanar ? planes[0].bytesused
>  				       : buf.bytesused;
>  		unsigned int remaining = bytesused;
> -- 
> 2.30.2
>

Patch
diff mbox series

diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index 2745e5798419..0cc622f91f2d 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -1711,6 +1711,13 @@  FrameBuffer *V4L2VideoDevice::dequeueBuffer()
 			return buffer;
 		}
 
+		/*
+		 * With a V4L2 single-planar format, all the data is stored in
+		 * a single memory plane. The number of bytes used is conveyed
+		 * through that plane when using the V4L2 multi-planar API, or
+		 * set directly in the buffer when using the V4L2 single-planar
+		 * API.
+		 */
 		unsigned int bytesused = multiPlanar ? planes[0].bytesused
 				       : buf.bytesused;
 		unsigned int remaining = bytesused;