mirror of https://bitbucket.org/ausocean/av.git
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
/*
|
|
NAME
|
|
parse.go
|
|
|
|
DESCRIPTION
|
|
parse.go contains functionality for parsing RTCP packets.
|
|
|
|
AUTHORS
|
|
Saxon A. Nelson-Milton <saxon@ausocean.org>
|
|
|
|
LICENSE
|
|
This is Copyright (C) 2019 the Australian Ocean Lab (AusOcean)
|
|
|
|
It is free software: you can redistribute it and/or modify them
|
|
under the terms of the GNU General Public License as published by the
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
|
option) any later version.
|
|
|
|
It is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
in gpl.txt. If not, see http://www.gnu.org/licenses.
|
|
*/
|
|
|
|
package rtcp
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"errors"
|
|
)
|
|
|
|
// NTPTimestamp describes the NTP timestamp format (http://www.beaglesoft.com/Manual/page53.htm)
|
|
type NTPTimestamp struct {
|
|
MSW uint32
|
|
LSW uint32
|
|
}
|
|
|
|
// 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) {
|
|
if len(buf) < 4 {
|
|
return NTPTimestamp{}, errors.New("bad RTCP packet, not of sufficient length")
|
|
}
|
|
if (buf[0]&0xc0)>>6 != rtcpVer {
|
|
return NTPTimestamp{}, errors.New("incompatible RTCP version")
|
|
}
|
|
|
|
if buf[1] != typeSenderReport {
|
|
return NTPTimestamp{}, errors.New("RTCP packet is not of sender report type")
|
|
}
|
|
|
|
return NTPTimestamp{
|
|
MSW: binary.BigEndian.Uint32(buf[8:]),
|
|
LSW: binary.BigEndian.Uint32(buf[12:]),
|
|
}, nil
|
|
}
|