libcamera: clock_recovery: Use nanoseconds in addSample()
diff mbox series

Message ID 20250825114435.570351-1-paul.elder@ideasonboard.com
State New
Headers show
Series
  • libcamera: clock_recovery: Use nanoseconds in addSample()
Related show

Commit Message

Paul Elder Aug. 25, 2025, 11:44 a.m. UTC
FrameWallClock was recently changed to nanoseconds, and all users of
ClockRecovery use SensorTimestamp directly, which is also in
nanoseconds. Thus addSample() should also use nanoseconds. Fix this.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
---
 src/libcamera/clock_recovery.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Barnabás Pőcze Aug. 25, 2025, 11:58 a.m. UTC | #1
Hi

2025. 08. 25. 13:44 keltezéssel, Paul Elder írta:
> FrameWallClock was recently changed to nanoseconds, and all users of
> ClockRecovery use SensorTimestamp directly, which is also in
> nanoseconds. Thus addSample() should also use nanoseconds. Fix this.
> 
> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
> ---

Maybe
   Fixes: 29a88d85b730b ("libcamera: controls: Use nanoseconds units for FrameWallClock")


Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>


>   src/libcamera/clock_recovery.cpp | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/src/libcamera/clock_recovery.cpp b/src/libcamera/clock_recovery.cpp
> index abacf444fbf8..f9ccb6ae2144 100644
> --- a/src/libcamera/clock_recovery.cpp
> +++ b/src/libcamera/clock_recovery.cpp
> @@ -118,10 +118,10 @@ void ClockRecovery::addSample()
>   	clock_gettime(CLOCK_BOOTTIME, &bootTime1);
>   	clock_gettime(CLOCK_REALTIME, &wallTime);
>   	clock_gettime(CLOCK_BOOTTIME, &bootTime2);
> -	uint64_t boot1 = bootTime1.tv_sec * 1000000ULL + bootTime1.tv_nsec / 1000;
> -	uint64_t boot2 = bootTime2.tv_sec * 1000000ULL + bootTime2.tv_nsec / 1000;
> +	uint64_t boot1 = bootTime1.tv_sec * 1000000000ULL + bootTime1.tv_nsec;
> +	uint64_t boot2 = bootTime2.tv_sec * 1000000000ULL + bootTime2.tv_nsec;
>   	uint64_t boot = (boot1 + boot2) / 2;
> -	uint64_t wall = wallTime.tv_sec * 1000000ULL + wallTime.tv_nsec / 1000;
> +	uint64_t wall = wallTime.tv_sec * 1000000000ULL + wallTime.tv_nsec;
>   
>   	addSample(boot, wall);
>   }

Patch
diff mbox series

diff --git a/src/libcamera/clock_recovery.cpp b/src/libcamera/clock_recovery.cpp
index abacf444fbf8..f9ccb6ae2144 100644
--- a/src/libcamera/clock_recovery.cpp
+++ b/src/libcamera/clock_recovery.cpp
@@ -118,10 +118,10 @@  void ClockRecovery::addSample()
 	clock_gettime(CLOCK_BOOTTIME, &bootTime1);
 	clock_gettime(CLOCK_REALTIME, &wallTime);
 	clock_gettime(CLOCK_BOOTTIME, &bootTime2);
-	uint64_t boot1 = bootTime1.tv_sec * 1000000ULL + bootTime1.tv_nsec / 1000;
-	uint64_t boot2 = bootTime2.tv_sec * 1000000ULL + bootTime2.tv_nsec / 1000;
+	uint64_t boot1 = bootTime1.tv_sec * 1000000000ULL + bootTime1.tv_nsec;
+	uint64_t boot2 = bootTime2.tv_sec * 1000000000ULL + bootTime2.tv_nsec;
 	uint64_t boot = (boot1 + boot2) / 2;
-	uint64_t wall = wallTime.tv_sec * 1000000ULL + wallTime.tv_nsec / 1000;
+	uint64_t wall = wallTime.tv_sec * 1000000000ULL + wallTime.tv_nsec;
 
 	addSample(boot, wall);
 }