Skip to content

Use host monotonic clock for timestamp#2802

Merged
chihchiachen merged 1 commit into
google:mainfrom
chihchiachen:host-monotonic-clock
Jul 2, 2026
Merged

Use host monotonic clock for timestamp#2802
chihchiachen merged 1 commit into
google:mainfrom
chihchiachen:host-monotonic-clock

Conversation

@chihchiachen

Copy link
Copy Markdown
Collaborator

Previously, outgoing buffer timestamps in emulated_camera_mplane and emulated_camera_splane were calculated directly from the frame sequence index:

tv_sec = (sequence + 1) / 1000
tv_usec = (sequence + 1) % 1000

This formula caused severe clock drift due to two issues:

  1. Incorrect Time Scaling: sequence increments by 1 per frame. Dividing by 1000 caused tv_sec to advance by 1 second only after 1,000 frames (~33.3 seconds of real wall-clock time at 30 FPS).
  2. Microsecond Miscalculation: In timeval, tv_usec is measured in microseconds (10^-6 s). Doing % 1000 without scaling caused the timestamp to advance by only 1 microsecond per frame.

This change replaces the sequence-based calculation with the host's actual monotonic clock, avoiding timestamp drift and buffer rejections in the guest.

Bug: b/474406105

Previously, outgoing buffer timestamps in emulated_camera_mplane and
emulated_camera_splane were calculated directly from the frame sequence
index:

tv_sec = (sequence + 1) / 1000
tv_usec = (sequence + 1) % 1000

This formula caused severe clock drift due to two issues:
1. Incorrect Time Scaling: sequence increments by 1 per frame. Dividing
   by 1000 caused tv_sec to advance by 1 second only after 1,000 frames
   (~33.3 seconds of real wall-clock time at 30 FPS).
2. Microsecond Miscalculation: In timeval, tv_usec is measured in
   microseconds (10^-6 s). Doing % 1000 without scaling caused the
   timestamp to advance by only 1 microsecond per frame.

This change replaces the sequence-based calculation with the host's
actual monotonic clock, avoiding timestamp drift and buffer rejections
in the guest.

Bug: b/474406105
@chihchiachen chihchiachen requested a review from ser-io July 1, 2026 19:16
@chihchiachen chihchiachen added the kokoro:run Run e2e tests. label Jul 1, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:run Run e2e tests. label Jul 1, 2026
@chihchiachen chihchiachen added this pull request to the merge queue Jul 2, 2026
Merged via the queue into google:main with commit e49ac90 Jul 2, 2026
45 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants