Documentation
¶
Overview ¶
Package clock provides type-safe time abstractions for SRT.
SRT uses microsecond-precision timestamps. On the wire, timestamps are 32-bit unsigned integers that wrap every ~71.6 minutes (2^32 microseconds). This package provides a Clock interface to enable deterministic testing.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock interface {
Now() Timestamp
}
Clock provides the current time. Use RealClock for production and MockClock for testing.
type Microseconds ¶
type Microseconds int64
Microseconds represents a duration in microseconds.
const ( Millisecond Microseconds = 1000 Second Microseconds = 1000 * Millisecond Minute Microseconds = 60 * Second )
Common duration constants.
func FromDuration ¶
func FromDuration(d time.Duration) Microseconds
FromDuration converts a time.Duration to Microseconds.
func SRTTimestampWrapPeriod ¶
func SRTTimestampWrapPeriod() Microseconds
SRTTimestampWrapPeriod returns the wrap period for 32-bit SRT timestamps.
func (Microseconds) Abs ¶
func (d Microseconds) Abs() Microseconds
Abs returns the absolute value of d.
func (Microseconds) Duration ¶
func (d Microseconds) Duration() time.Duration
Duration converts to a standard time.Duration.
type MockClock ¶
type MockClock struct {
// contains filtered or unexported fields
}
MockClock is a clock for testing that advances only when told to.
func NewMockClock ¶
func NewMockClock() *MockClock
NewMockClock returns a mock clock starting at time 0.
func (*MockClock) Advance ¶
func (c *MockClock) Advance(d Microseconds)
Advance moves the mock clock forward by d microseconds.
type RealClock ¶
type RealClock struct {
// contains filtered or unexported fields
}
RealClock uses the system clock.
func NewRealClock ¶
func NewRealClock() *RealClock
NewRealClock returns a Clock based on the system clock. The epoch is set to the time of creation; all timestamps are relative to this epoch.
type Timestamp ¶
type Timestamp int64
Timestamp represents an absolute point in time in microseconds since an arbitrary epoch (typically connection start).
func FromSRTTimestamp ¶
FromSRTTimestamp reconstructs a full Timestamp from a 32-bit SRT timestamp and a reference timestamp. It picks the interpretation closest to the reference (handling wrap-around).
func (Timestamp) SRTTimestamp ¶
SRTTimestamp returns the lower 32 bits of the timestamp for the SRT wire format. SRT timestamps are 32-bit unsigned microsecond values that wrap every ~71.6 minutes (2^32 microseconds ≈ 4295 seconds).
func (Timestamp) Sub ¶
func (t Timestamp) Sub(other Timestamp) Microseconds
Sub returns the duration between t and other (t - other).