diff --git a/rtptime/rtptime.go b/rtptime/rtptime.go index 658c7e7..4efad55 100644 --- a/rtptime/rtptime.go +++ b/rtptime/rtptime.go @@ -22,6 +22,13 @@ func Microseconds() uint64 { return Now(1000000) } +// JiffiesPerSec is the LCM of 48000, 96000 and 65536 +const JiffiesPerSec = 24576000 + +func Jiffies() uint64 { + return Now(JiffiesPerSec) +} + var ntpEpoch = time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC) func NTPToTime(ntp uint64) time.Time { diff --git a/rtptime/rtptime_test.go b/rtptime/rtptime_test.go index 2fbd951..3304e5e 100644 --- a/rtptime/rtptime_test.go +++ b/rtptime/rtptime_test.go @@ -24,7 +24,7 @@ func differs(a, b, delta uint64) bool { return a - b >= delta } -func TestMono(t *testing.T) { +func TestTime(t *testing.T) { a := Now(48000) time.Sleep(4 * time.Millisecond) b := Now(48000) - a @@ -38,6 +38,13 @@ func TestMono(t *testing.T) { if differs(d, 4000, 1000) { t.Errorf("Expected %v, got %v", 4000, d) } + + c = Jiffies() + time.Sleep(time.Second * 100000 / JiffiesPerSec) + d = Jiffies() - c + if differs(d, 100000, 10000) { + t.Errorf("Expected %v, got %v", 4000, d) + } } func TestNTP(t *testing.T) {