protocol/rtcp: wrote struct for RTCP sender report

This commit is contained in:
Saxon 2019-04-15 15:53:06 +09:30
parent af664b0661
commit 2669862ced
1 changed files with 33 additions and 1 deletions

View File

@ -18,7 +18,8 @@ const (
// MISC.
const (
reportBlockSize = 6
reportBlockSize = 6
senderReportSize = 28
)
// ReceiverReport describes an RTCP receiver report packet.
@ -115,6 +116,37 @@ func (d *SourceDescription) bodyLen() int {
return l
}
// SenderReport describes an RTCP sender report.
type SenderReport struct {
Header // Standard RTCP header.
SSRC uint32 // SSRC of sender.
TimestampMSW uint32 // Most significant word of timestamp.
TimestampLSW uint32 // Least significant word of timestamp.
RTPTimestamp uint32 // Current RTP timestamp.
PacketCount uint32 // Senders packet count.
OctetCount uint32 // Senders octet count.
// Report blocks (unimplemented)
// ...
}
// Bytes returns a []byte of the SenderReport.
func (r *SenderReport) Bytes() []byte {
buf := make([]byte, senderReportSize)
r.writeHeader(buf, senderReportSize-1)
for i, w := range []uint32{
r.SSRC,
r.TimestampMSW,
r.TimestampLSW,
r.RTPTimestamp,
r.PacketCount,
r.OctetCount,
} {
binary.BigEndian.PutUint32(buf[i+1:], w)
}
return buf
}
// Header describes a standard RTCP packet header.
type Header struct {
Version uint8 // RTCP version.