ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
frame_clock.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdbool.h>
4#include <stdint.h>
5
15
17static inline void webcam_frame_clock_reset(webcam_frame_clock_t *clock) {
18 *clock = (webcam_frame_clock_t){0};
19}
20
22static inline uint64_t webcam_frame_clock_age(webcam_frame_clock_t *clock, int64_t sample, uint64_t wall) {
23 if (!clock->initialized || sample < clock->previous || wall < clock->wall) {
24 *clock = (webcam_frame_clock_t){.sample = sample, .previous = sample, .wall = wall, .initialized = true};
25 return 0;
26 }
27 clock->previous = sample;
28 // Bias signed device times before subtraction so crossing zero does not wrap.
29 uint64_t elapsed_ticks = ((uint64_t)sample ^ (UINT64_C(1) << 63)) - ((uint64_t)clock->sample ^ (UINT64_C(1) << 63));
30 uint64_t elapsed_wall = wall - clock->wall;
31 if (elapsed_ticks > UINT64_MAX / 100 || elapsed_ticks * 100 > elapsed_wall) {
32 clock->sample = sample;
33 clock->wall = wall;
34 return 0;
35 }
36 return elapsed_wall - elapsed_ticks * 100;
37}
unsigned long long uint64_t
Definition common.h:63
The useful part of webcam frame clock is in sample, previous, wall, initialized: together they descri...
Definition frame_clock.h:10