Complete Phase 1: add clock utility, unit test, build targets, and docs
This commit is contained in:
+5
-1
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user