// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>// SPDX-License-Identifier: MITpackage rtcpimport ()// A CompoundPacket is a collection of RTCP packets transmitted as a single packet with// the underlying protocol (for example UDP).//// To maximize the resolution of receiption statistics, the first Packet in a CompoundPacket// must always be either a SenderReport or a ReceiverReport. This is true even if no data// has been sent or received, in which case an empty ReceiverReport must be sent, and even// if the only other RTCP packet in the compound packet is a Goodbye.//// Next, a SourceDescription containing a CNAME item must be included in each CompoundPacket// to identify the source and to begin associating media for purposes such as lip-sync.//// Other RTCP packet types may follow in any order. Packet types may appear more than once.typeCompoundPacket []Packet// Validate returns an error if this is not an RFC-compliant CompoundPacket.func ( CompoundPacket) () error {iflen() == 0 {returnerrEmptyCompound }// SenderReport and ReceiverReport are the only types that // are allowed to be the first packet in a compound datagramswitch [0].(type) {case *SenderReport, *ReceiverReport:// okdefault:returnerrBadFirstPacket }for , := range [1:] {switch p := .(type) {// If the number of RecetpionReports exceeds 31 additional ReceiverReports // can be included here.case *ReceiverReport:continue// A SourceDescription containing a CNAME must be included in every // CompoundPacket.case *SourceDescription:varboolfor , := range .Chunks {for , := range .Items {if .Type == SDESCNAME { = true } } }if ! {returnerrMissingCNAME }returnnil// Other packets are not permitted before the CNAMEdefault:returnerrPacketBeforeCNAME } }// CNAME never reachedreturnerrMissingCNAME}// CNAME returns the CNAME that *must* be present in every CompoundPacketfunc ( CompoundPacket) () (string, error) {varerroriflen() < 1 {return"", errEmptyCompound }for , := range [1:] { , := .(*SourceDescription)if {for , := range .Chunks {for , := range .Items {if .Type == SDESCNAME {return .Text, } } } } else { , := .(*ReceiverReport)if ! { = errPacketBeforeCNAME } } }return"", errMissingCNAME}// Marshal encodes the CompoundPacket as binary.func ( CompoundPacket) () ([]byte, error) {if := .Validate(); != nil {returnnil, } := []Packet()returnMarshal()}// MarshalSize returns the size of the packet once marshaledfunc ( CompoundPacket) () int { := 0for , := range { += .MarshalSize() }return}// Unmarshal decodes a CompoundPacket from binary.func ( *CompoundPacket) ( []byte) error { := make(CompoundPacket, 0)forlen() != 0 { , , := unmarshal()if != nil {return } = append(, ) = [:] } * = return .Validate()}// DestinationSSRC returns the synchronization sources associated with this// CompoundPacket's reception report.func ( CompoundPacket) () []uint32 {iflen() == 0 {returnnil }return [0].DestinationSSRC()}func ( CompoundPacket) () string { := "CompoundPacket\n"for , := range { , := .(fmt.Stringer)if { += .String() } else { += stringify() } } = strings.TrimSuffix(strings.ReplaceAll(, "\n", "\n\t"), "\t")return}
The pages are generated with Goldsv0.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.