ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
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
6#ifdef __cplusplus
7extern "C" {
8#endif
9
21
23static inline void webcam_frame_clock_reset(webcam_frame_clock_t *clock) {
24 *clock = (webcam_frame_clock_t){0};
25}
26
28static inline uint64_t webcam_frame_clock_age(webcam_frame_clock_t *clock, int64_t sample, uint64_t wall) {
29 if (!clock->initialized || sample < clock->previous || wall < clock->wall) {
30 *clock = (webcam_frame_clock_t){.sample = sample, .previous = sample, .wall = wall, .initialized = true};
31 return 0;
32 }
33 clock->previous = sample;
34 // Bias signed device times before subtraction so crossing zero does not wrap.
35 uint64_t elapsed_ticks = ((uint64_t)sample ^ (UINT64_C(1) << 63)) - ((uint64_t)clock->sample ^ (UINT64_C(1) << 63));
36 uint64_t elapsed_wall = wall - clock->wall;
37 if (elapsed_ticks > UINT64_MAX / 100 || elapsed_ticks * 100 > elapsed_wall) {
38 clock->sample = sample;
39 clock->wall = wall;
40 return 0;
41 }
42 return elapsed_wall - elapsed_ticks * 100;
43}
44
45#ifdef __cplusplus
46}
47#endif
unsigned long long uint64_t
The useful part of webcam frame clock is in sample, previous, wall, initialized: together they descri...
Definition frame_clock.h:16