2019-04-12 11:32:27 +03:00
|
|
|
package rtcp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Timestamp gets the timestamp from a receiver report and returns as the most
|
|
|
|
// significant word, and the least significant word. If the given bytes do not
|
2019-04-15 07:31:38 +03:00
|
|
|
// represent a valid receiver report, an error is returned.
|
2019-04-12 11:32:27 +03:00
|
|
|
func Timestamp(buf []byte) (msw, lsw uint32, err error) {
|
2019-04-16 06:03:58 +03:00
|
|
|
if len(buf) < 4 {
|
|
|
|
return 0, 0, errors.New("bad RTCP packet, not of sufficient length")
|
|
|
|
}
|
2019-04-12 11:32:27 +03:00
|
|
|
if (buf[0] & 0xc0 >> 6) != 2 {
|
|
|
|
return 0, 0, errors.New("incompatible RTCP version")
|
|
|
|
}
|
|
|
|
|
|
|
|
if buf[1] != typeSenderReport {
|
2019-04-16 06:03:58 +03:00
|
|
|
return 0, 0, errors.New("RTCP packet is not of sender report type")
|
2019-04-12 11:32:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
msw = binary.BigEndian.Uint32(buf[8:])
|
|
|
|
lsw = binary.BigEndian.Uint32(buf[12:])
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|