diff --git a/protocol/rtcp/client.go b/protocol/rtcp/client.go index 06261ef1..ce2ad88d 100644 --- a/protocol/rtcp/client.go +++ b/protocol/rtcp/client.go @@ -263,8 +263,8 @@ func (c *Client) jitter() uint32 { // setSenderTs allows us to safely set the current sender report timestamp. func (c *Client) setSenderTs(t NTPTimestamp) { c.mu.Lock() - binary.BigEndian.PutUint32(c.senderTs[:], t.MSW) - binary.BigEndian.PutUint32(c.senderTs[4:], t.LSW) + binary.BigEndian.PutUint32(c.senderTs[:], t.Seconds) + binary.BigEndian.PutUint32(c.senderTs[4:], t.Fraction) c.mu.Unlock() } @@ -285,7 +285,7 @@ func (c *Client) delay() uint32 { return uint32(time.Now().Sub(t).Seconds() / delayUnit) } -// received is called when a sender report is received to mark the receive time. +// markReceivedTime is called when a sender report is received to mark the receive time. func (c *Client) markReceivedTime() { c.mu.Lock() c.receiveTime = time.Now() diff --git a/protocol/rtcp/parse.go b/protocol/rtcp/parse.go index 159d739c..271af761 100644 --- a/protocol/rtcp/parse.go +++ b/protocol/rtcp/parse.go @@ -32,10 +32,20 @@ import ( "errors" ) -// NTPTimestamp describes the NTP timestamp format (http://www.beaglesoft.com/Manual/page53.htm) +// NTPTimestamp describes an NTP timestamp. +// +// NTP timestamps are represented as a 64-bit unsigned fixed- +// point number, in seconds relative to 0h on 1 January 1900. The integer +// part is in the first 32 bits and the fraction part in the last 32 bits. +// This format allows convenient multiple-precision arithmetic and +// conversion to Time Protocol representation (seconds), but does +// complicate the conversion to ICMP Timestamp message representation +// (milliseconds). The precision of this representation is about 200 +// picoseconds, which should be adequate for even the most exotic +// requirements. type NTPTimestamp struct { - MSW uint32 - LSW uint32 + Seconds uint32 + Fraction uint32 } // Timestamp gets the timestamp from a receiver report and returns it as the most @@ -54,7 +64,7 @@ func Timestamp(buf []byte) (NTPTimestamp, error) { } return NTPTimestamp{ - MSW: binary.BigEndian.Uint32(buf[8:]), - LSW: binary.BigEndian.Uint32(buf[12:]), + Seconds: binary.BigEndian.Uint32(buf[8:]), + Fraction: binary.BigEndian.Uint32(buf[12:]), }, nil } diff --git a/protocol/rtcp/parse_test.go b/protocol/rtcp/parse_test.go index 2777bddb..66e0f18a 100644 --- a/protocol/rtcp/parse_test.go +++ b/protocol/rtcp/parse_test.go @@ -51,11 +51,11 @@ func TestTimestamp(t *testing.T) { t.Fatalf("did not expect error: %v", err) } - if ts.MSW != expectedMSW { - t.Errorf("most significant word of timestamp is not what's expected. \nGot: %v\n Want: %v\n", ts.MSW, expectedMSW) + if ts.Seconds != expectedMSW { + t.Errorf("most significant word of timestamp is not what's expected. \nGot: %v\n Want: %v\n", ts.Seconds, expectedMSW) } - if ts.LSW != expectedLSW { - t.Errorf("least significant word of timestamp is not what's expected. \nGot: %v\n Want: %v\n", ts.LSW, expectedLSW) + if ts.Fraction != expectedLSW { + t.Errorf("least significant word of timestamp is not what's expected. \nGot: %v\n Want: %v\n", ts.Fraction, expectedLSW) } }