mirror of https://github.com/q191201771/lal.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
6.1 KiB
Go
136 lines
6.1 KiB
Go
5 years ago
|
// Copyright 2020, Chef. All rights reserved.
|
||
|
// https://github.com/q191201771/lal
|
||
|
//
|
||
|
// Use of this source code is governed by a MIT-style license
|
||
|
// that can be found in the License file.
|
||
|
//
|
||
|
// Author: Chef (191201771@qq.com)
|
||
|
|
||
5 years ago
|
package rtprtcp
|
||
5 years ago
|
|
||
|
import (
|
||
|
"github.com/q191201771/naza/pkg/bele"
|
||
|
"github.com/q191201771/naza/pkg/nazalog"
|
||
|
)
|
||
|
|
||
5 years ago
|
// -------------------------------------------
|
||
|
// rfc3550 6.4.1 SR: Sender Report RTCP Packet
|
||
|
// -------------------------------------------
|
||
|
//
|
||
|
// 0 1 2 3
|
||
|
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
// header |V=2|P| RC | PT=SR=200 | length |
|
||
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
// | SSRC of sender |
|
||
|
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
|
||
|
// sender | NTP timestamp, most significant word |
|
||
|
// info +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
// | NTP timestamp, least significant word |
|
||
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
// | RTP timestamp |
|
||
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
// | sender's packet count |
|
||
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
// | sender's octet count |
|
||
|
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
|
||
|
// report | SSRC_1 (SSRC of first source) |
|
||
|
// block +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
// 1 | fraction lost | cumulative number of packets lost |
|
||
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
// | extended highest sequence number received |
|
||
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
// | interarrival jitter |
|
||
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
// | last SR (LSR) |
|
||
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
// | delay since last SR (DLSR) |
|
||
|
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
|
||
|
// report | SSRC_2 (SSRC of second source) |
|
||
|
// block +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
// 2 : ... :
|
||
|
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
|
||
|
// | profile-specific extensions |
|
||
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
|
||
|
// ---------------------------------------------
|
||
|
// rfc3550 6.4.2 RR: Receiver Report RTCP Packet
|
||
|
// ---------------------------------------------
|
||
|
//
|
||
|
// 0 1 2 3
|
||
|
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
// header |V=2|P| RC | PT=RR=201 | length |
|
||
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
// | SSRC of packet sender |
|
||
|
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
|
||
|
// report | SSRC_1 (SSRC of first source) |
|
||
|
// block +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
// 1 | fraction lost | cumulative number of packets lost |
|
||
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
// | extended highest sequence number received |
|
||
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
// | interarrival jitter |
|
||
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
// | last SR (LSR) |
|
||
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
// | delay since last SR (DLSR) |
|
||
|
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
|
||
|
// report | SSRC_2 (SSRC of second source) |
|
||
|
// block +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
|
// 2 : ... :
|
||
|
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
|
||
|
// | profile-specific extensions |
|
||
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||
5 years ago
|
|
||
|
const (
|
||
5 years ago
|
RTCPPacketTypeSR = 200 // Sender Report
|
||
|
RTCPPacketTypeRR = 201 // Receiver Report
|
||
5 years ago
|
)
|
||
|
|
||
|
type RTCPHeader struct {
|
||
|
version uint8 // 2b
|
||
|
padding uint8 // 1b
|
||
|
countOrFormat uint8 // 5b
|
||
|
packetType uint8 // 8b
|
||
|
length uint16 // 16b, byte length = (length+1) * 4
|
||
|
}
|
||
|
|
||
|
type SR struct {
|
||
|
senderSSRC uint32
|
||
|
msw uint32
|
||
|
lsw uint32
|
||
|
ts uint32
|
||
|
pktCnt uint32
|
||
|
octetCnt uint32
|
||
|
}
|
||
|
|
||
5 years ago
|
func ParseRTCPPacket(b []byte) {
|
||
5 years ago
|
var h RTCPHeader
|
||
|
h.version = b[0] >> 6
|
||
|
h.padding = (b[0] >> 5) & 0x1
|
||
|
h.countOrFormat = b[0] & 0x1F
|
||
|
h.packetType = b[1]
|
||
|
h.length = bele.BEUint16(b[2:])
|
||
5 years ago
|
//nazalog.Debugf("%+v", h)
|
||
5 years ago
|
|
||
|
switch h.packetType {
|
||
5 years ago
|
case RTCPPacketTypeSR:
|
||
5 years ago
|
parseSR(b)
|
||
|
default:
|
||
|
nazalog.Warnf("unknown packet type. type=%d", h.packetType)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// rfc3550 6.4.1
|
||
|
func parseSR(b []byte) {
|
||
|
var s SR
|
||
|
s.senderSSRC = bele.BEUint32(b[4:])
|
||
|
s.msw = bele.BEUint32(b[8:])
|
||
|
s.lsw = bele.BEUint32(b[12:])
|
||
|
s.ts = bele.BEUint32(b[16:])
|
||
|
s.pktCnt = bele.BEUint32(b[20:])
|
||
|
s.octetCnt = bele.BEUint32(b[24:])
|
||
5 years ago
|
nazalog.Debugf("sr=%+v", s)
|
||
5 years ago
|
}
|