mirror of https://bitbucket.org/ausocean/av.git
protocol/rtcp: renamed NTPTimestamp to Timestamp
Renamed NTPTimestamp and referenced specifications rather than quoting. Renamed Timestamp func to ParseTimestamp.
This commit is contained in:
parent
63da7dbb59
commit
e00c959a84
|
@ -231,7 +231,7 @@ func (c *Client) formPayload(r *ReceiverReport, d *Description) []byte {
|
|||
// parse will read important statistics from sender reports.
|
||||
func (c *Client) parse(buf []byte) {
|
||||
c.markReceivedTime()
|
||||
t, err := Timestamp(buf)
|
||||
t, err := ParseTimestamp(buf)
|
||||
if err != nil {
|
||||
c.err <- errors.New(fmt.Sprintf("could not get timestamp from sender report, failed with error: %v", err))
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ func (c *Client) jitter() uint32 {
|
|||
}
|
||||
|
||||
// setSenderTs allows us to safely set the current sender report timestamp.
|
||||
func (c *Client) setSenderTs(t NTPTimestamp) {
|
||||
func (c *Client) setSenderTs(t Timestamp) {
|
||||
c.mu.Lock()
|
||||
binary.BigEndian.PutUint32(c.senderTs[:], t.Seconds)
|
||||
binary.BigEndian.PutUint32(c.senderTs[4:], t.Fraction)
|
||||
|
|
|
@ -32,18 +32,8 @@ import (
|
|||
"errors"
|
||||
)
|
||||
|
||||
// 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 {
|
||||
// Timestamp describes an NTP timestamp, see https://tools.ietf.org/html/rfc1305
|
||||
type Timestamp struct {
|
||||
Seconds uint32
|
||||
Fraction uint32
|
||||
}
|
||||
|
@ -51,19 +41,19 @@ type NTPTimestamp struct {
|
|||
// Timestamp gets the timestamp from a receiver report and returns it as the most
|
||||
// significant word, and the least significant word. If the given bytes do not
|
||||
// represent a valid receiver report, an error is returned.
|
||||
func Timestamp(buf []byte) (NTPTimestamp, error) {
|
||||
func ParseTimestamp(buf []byte) (Timestamp, error) {
|
||||
if len(buf) < 4 {
|
||||
return NTPTimestamp{}, errors.New("bad RTCP packet, not of sufficient length")
|
||||
return Timestamp{}, errors.New("bad RTCP packet, not of sufficient length")
|
||||
}
|
||||
if (buf[0]&0xc0)>>6 != rtcpVer {
|
||||
return NTPTimestamp{}, errors.New("incompatible RTCP version")
|
||||
return Timestamp{}, errors.New("incompatible RTCP version")
|
||||
}
|
||||
|
||||
if buf[1] != typeSenderReport {
|
||||
return NTPTimestamp{}, errors.New("RTCP packet is not of sender report type")
|
||||
return Timestamp{}, errors.New("RTCP packet is not of sender report type")
|
||||
}
|
||||
|
||||
return NTPTimestamp{
|
||||
return Timestamp{
|
||||
Seconds: binary.BigEndian.Uint32(buf[8:]),
|
||||
Fraction: binary.BigEndian.Uint32(buf[12:]),
|
||||
}, nil
|
||||
|
|
|
@ -46,7 +46,7 @@ func TestTimestamp(t *testing.T) {
|
|||
0x00, 0x01, 0xc2, 0xc5,
|
||||
}
|
||||
|
||||
ts, err := Timestamp(report)
|
||||
ts, err := ParseTimestamp(report)
|
||||
if err != nil {
|
||||
t.Fatalf("did not expect error: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue