mirror of https://bitbucket.org/ausocean/av.git
protocol/rtp: better comment for NTPTimestamp and renamed fields
This commit is contained in:
parent
b43f6f8072
commit
4068aea207
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue