#pragma once #include 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 ( ( 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