protocol/rtp: add Timestamp parsing function

This commit is contained in:
Dan Kortschak 2019-11-20 14:20:22 +10:30
parent 6e3f0f2a61
commit 830d8ea647
1 changed files with 10 additions and 0 deletions

View File

@ -82,6 +82,16 @@ func Sequence(d []byte) (uint16, error) {
return binary.BigEndian.Uint16(d[2:]), nil return binary.BigEndian.Uint16(d[2:]), nil
} }
// Timestamp returns the RTP timestamp of an RTP packet. An error is returned
// if the packet is not valid.
func Timestamp(d []byte) (uint32, error) {
err := checkPacket(d)
if err != nil {
return 0, err
}
return binary.BigEndian.Uint32(d[4:]), nil
}
// checkPacket checks the validity of the packet, firstly by checking size and // checkPacket checks the validity of the packet, firstly by checking size and
// then also checking that version is compatible with these utilities. // then also checking that version is compatible with these utilities.
func checkPacket(d []byte) error { func checkPacket(d []byte) error {