// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>// SPDX-License-Identifier: MITpackage rtcpimport ()// ApplicationDefined represents an RTCP application-defined packet.typeApplicationDefinedstruct { SubType uint8 SSRC uint32 Name string Data []byte}// DestinationSSRC returns the SSRC value for this packet.func ( ApplicationDefined) () []uint32 {return []uint32{.SSRC}}// Marshal serializes the application-defined struct into a byte slice with padding.func ( ApplicationDefined) () ([]byte, error) { := len(.Data)if > 0xFFFF-12 {returnnil, errAppDefinedDataTooLarge }iflen(.Name) != 4 {returnnil, errAppDefinedInvalidName }// Calculate the padding size to be added to make the packet length a multiple of 4 bytes. := 4 - ( % 4)if == 4 { = 0 } := .MarshalSize() := Header{Type: TypeApplicationDefined,Length: uint16(( / 4) - 1),Padding: != 0,Count: .SubType, } , := .Marshal()if != nil {returnnil, } := make([]byte, )copy(, )binary.BigEndian.PutUint32([4:8], .SSRC)copy([8:12], .Name)copy([12:], .Data)// Add padding if necessary.if > 0 {for := 0; < ; ++ { [12++] = byte() } }return , nil}// Unmarshal parses the given raw packet into an application-defined struct, handling padding.func ( *ApplicationDefined) ( []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| subtype | PT=APP=204 | length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | SSRC/CSRC | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | name (ASCII) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | application-dependent data ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ := Header{} := .Unmarshal()if != nil {return }iflen() < 12 {returnerrPacketTooShort }ifint(.Length+1)*4 != len() {returnerrAppDefinedInvalidLength } .SubType = .Count .SSRC = binary.BigEndian.Uint32([4:8]) .Name = string([8:12])// Check for padding. := 0if .Padding { = int([len()-1])if > len()-12 {returnerrWrongPadding } } .Data = [12 : len()-]returnnil}// MarshalSize returns the size of the packet once marshaledfunc ( *ApplicationDefined) () int { := len(.Data)// Calculate the padding size to be added to make the packet length a multiple of 4 bytes. := 4 - ( % 4)if == 4 { = 0 }return12 + + }
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.