[libcamera-devel] [PATCH] v4l2: v4l2_camera_proxy: Fix timestamp calculation

Kieran Bingham kieran.bingham at ideasonboard.com
Mon Feb 14 13:39:51 CET 2022


The V4L2 Compatibility layer is returning timestamps for buffers which
are incorrectly calculated from the frame metadata.

The sec component of the timestamp is correct, but the nsec component is
out, leaving frame captures reporting non-monotonically increasing
timestamps, and incorrect frame rate calculations.

Fix the usecs calculation reported by the V4L2 adaptation layer.

Bug: https://bugs.libcamera.org/show_bug.cgi?id=118
Fixes: 0ce8f2390b52 ("v4l2: v4l2_compat: Add V4L2 compatibility layer")
Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
---
 src/v4l2/v4l2_camera_proxy.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
index 45822feff317..67b2c50c0f7e 100644
--- a/src/v4l2/v4l2_camera_proxy.cpp
+++ b/src/v4l2/v4l2_camera_proxy.cpp
@@ -234,7 +234,7 @@ void V4L2CameraProxy::updateBuffers()
 							});
 			buf.field = V4L2_FIELD_NONE;
 			buf.timestamp.tv_sec = fmd.timestamp / 1000000000;
-			buf.timestamp.tv_usec = fmd.timestamp % 1000000;
+			buf.timestamp.tv_usec = fmd.timestamp / 1000 % 1000000;
 			buf.sequence = fmd.sequence;
 
 			buf.flags |= V4L2_BUF_FLAG_DONE;
-- 
2.32.0



More information about the libcamera-devel mailing list