Source File
header.go
Belonging Package
github.com/pion/rtcp
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>// SPDX-License-Identifier: MITpackage rtcpimport ()// PacketType specifies the type of an RTCP packettype PacketType uint8// RTCP packet types registered with IANA. See: https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4const (TypeSenderReport PacketType = 200 // RFC 3550, 6.4.1TypeReceiverReport PacketType = 201 // RFC 3550, 6.4.2TypeSourceDescription PacketType = 202 // RFC 3550, 6.5TypeGoodbye PacketType = 203 // RFC 3550, 6.6TypeApplicationDefined PacketType = 204 // RFC 3550, 6.7 (unimplemented)TypeTransportSpecificFeedback PacketType = 205 // RFC 4585, 6051TypePayloadSpecificFeedback PacketType = 206 // RFC 4585, 6.3TypeExtendedReport PacketType = 207 // RFC 3611)// Transport and Payload specific feedback messages overload the count field to act as a message type. those are listed hereconst (FormatSLI uint8 = 2FormatPLI uint8 = 1FormatFIR uint8 = 4FormatTLN uint8 = 1FormatRRR uint8 = 5FormatCCFB uint8 = 11FormatREMB uint8 = 15// https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01#page-5FormatTCC uint8 = 15)func ( PacketType) () string {switch {case TypeSenderReport:return "SR"case TypeReceiverReport:return "RR"case TypeSourceDescription:return "SDES"case TypeGoodbye:return "BYE"case TypeApplicationDefined:return "APP"case TypeTransportSpecificFeedback:return "TSFB"case TypePayloadSpecificFeedback:return "PSFB"case TypeExtendedReport:return "XR"default:return string()}}const rtpVersion = 2// A Header is the common header shared by all RTCP packetstype Header struct {// If the padding bit is set, this individual RTCP packet contains// some additional padding octets at the end which are not part of// the control information but are included in the length field.Padding bool// The number of reception reports, sources contained or FMT in this packet (depending on the Type)Count uint8// The RTCP packet type for this packetType PacketType// The length of this RTCP packet in 32-bit words minus one,// including the header and any padding.Length uint16}const (headerLength = 4versionShift = 6versionMask = 0x3paddingShift = 5paddingMask = 0x1countShift = 0countMask = 0x1fcountMax = (1 << 5) - 1)// Marshal encodes the Header in binaryfunc ( Header) () ([]byte, error) {/** 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* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+* |V=2|P| RC | PT=SR=200 | length |* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/:= make([]byte, headerLength)[0] |= rtpVersion << versionShiftif .Padding {[0] |= 1 << paddingShift}if .Count > 31 {return nil, errInvalidHeader}[0] |= .Count << countShift[1] = uint8(.Type)binary.BigEndian.PutUint16([2:], .Length)return , nil}// Unmarshal decodes the Header from binaryfunc ( *Header) ( []byte) error {if len() < headerLength {return errPacketTooShort}/** 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* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+* |V=2|P| RC | PT | length |* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/:= [0] >> versionShift & versionMaskif != rtpVersion {return errBadVersion}.Padding = ([0] >> paddingShift & paddingMask) > 0.Count = [0] >> countShift & countMask.Type = PacketType([1]).Length = binary.BigEndian.Uint16([2:])return nil}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |