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
+19
View File
@@ -0,0 +1,19 @@
#pragma once
#include <cstdint>
namespace sc {
// RTP clock rate for video is 90 kHz. Convert a monotonic nanosecond timestamp
// into a 32-bit RTP timestamp. Overflows wrap around intentionally.
constexpr uint32_t rtp_timestamp_from_ns ( uint64_t nanoseconds ) noexcept {
// (nanoseconds * 90_000) / 1_000_000_000
// Simplify: 90_000 / 1_000_000_000 = 9 / 100_000
return static_cast<uint32_t> ( ( nanoseconds * 9ULL ) / 100'000ULL );
}
static_assert ( rtp_timestamp_from_ns ( 0 ) == 0 );
static_assert ( rtp_timestamp_from_ns ( 1'000'000'000ULL ) == 90'000 );
static_assert ( rtp_timestamp_from_ns ( 500'000'000ULL ) == 45'000 );
} // namespace sc