Complete Phase 1: add clock utility, unit test, build targets, and docs

This commit is contained in:
2026-08-28 21:57:43 +02:00
parent 742611b841
commit 975e3b2974
8 changed files with 67 additions and 16 deletions
+5 -1
View File
@@ -1 +1,5 @@
# Empty stub: tests will be added as modules land.
test_clock = executable('test_clock',
'utils/test_clock.cpp',
include_directories : sc_core_inc)
test('clock utils', test_clock)
+20
View File
@@ -0,0 +1,20 @@
#include "screencast/utils/clock.h"
#include <cassert>
#include <cstdint>
int main () {
assert ( sc::rtp_timestamp_from_ns ( 0 ) == 0u );
assert ( sc::rtp_timestamp_from_ns ( 1'000'000'000ULL ) == 90'000u );
assert ( sc::rtp_timestamp_from_ns ( 500'000'000ULL ) == 45'000u );
assert ( sc::rtp_timestamp_from_ns ( 16'666'667ULL ) == 1'500u );
// A multiple of the wrap period should wrap back to zero.
// Period in ns = ceil(2^32 * 100_000 / 9) because the helper uses
// integer floor division (ns * 9 / 100_000).
constexpr uint64_t period_ns = ( ( 1ULL << 32 ) * 100'000ULL + 9ULL - 1ULL ) / 9ULL;
static_assert ( sc::rtp_timestamp_from_ns ( period_ns ) == 0u );
static_assert ( sc::rtp_timestamp_from_ns ( period_ns + 1'000'000'000ULL ) == 90'000u );
return 0;
}