libcamera: v4l2_videodevice: Improve readability
diff mbox series

Message ID 20240808173041.2505335-1-kieran.bingham@ideasonboard.com
State Accepted
Commit 33a49ce4a265c88ade6cc7e94d5124f5d6ebaea0
Headers show
Series
  • libcamera: v4l2_videodevice: Improve readability
Related show

Commit Message

Kieran Bingham Aug. 8, 2024, 5:30 p.m. UTC
From: Stefan Klug <stefan.klug@ideasonboard.com>

The handling for the sequence number validation within
V4L2VideoDevice::dequeueBuffer makes use of a std::optional, which can
be used as a boolean in conditional statements. This has the impact in
this use case that it can be mis-read to be interpretting the value for
firstFrame_ which is assigned as teh buf.sequence.

Remove this potential for confusion by making it clear that the first
frame handling is only performed when firstFrame_ does not have a value
assigned.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
[Kieran: Rework commit message]
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 src/libcamera/v4l2_videodevice.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Laurent Pinchart Aug. 10, 2024, 12:28 p.m. UTC | #1
Hi Kieran and Stefan,

Thank you for the patch.

On Thu, Aug 08, 2024 at 06:30:41PM +0100, Kieran Bingham wrote:
> From: Stefan Klug <stefan.klug@ideasonboard.com>
> 
> The handling for the sequence number validation within
> V4L2VideoDevice::dequeueBuffer makes use of a std::optional, which can
> be used as a boolean in conditional statements. This has the impact in
> this use case that it can be mis-read to be interpretting the value fo

s/interpretting/interpreting/

> firstFrame_ which is assigned as teh buf.sequence.

s/teh/the/

> 
> Remove this potential for confusion by making it clear that the first
> frame handling is only performed when firstFrame_ does not have a value
> assigned.
> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
> [Kieran: Rework commit message]
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/libcamera/v4l2_videodevice.cpp | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> index 6f32521f3d6f..59379308d5b3 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -1841,7 +1841,7 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer()
>  	 * Detect kernel drivers which do not reset the sequence number to zero
>  	 * on stream start.
>  	 */
> -	if (!firstFrame_) {
> +	if (!firstFrame_.has_value()) {
>  		if (buf.sequence)
>  			LOG(V4L2, Info)
>  				<< "Zero sequence expected for first frame (got "

Patch
diff mbox series

diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index 6f32521f3d6f..59379308d5b3 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -1841,7 +1841,7 @@  FrameBuffer *V4L2VideoDevice::dequeueBuffer()
 	 * Detect kernel drivers which do not reset the sequence number to zero
 	 * on stream start.
 	 */
-	if (!firstFrame_) {
+	if (!firstFrame_.has_value()) {
 		if (buf.sequence)
 			LOG(V4L2, Info)
 				<< "Zero sequence expected for first frame (got "