Debian Codegraph @

packet.go

raw symbols SCIP
1 // SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
2 // SPDX-License-Identifier: MIT
3
4 package rtcpscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/
5
6 // Packet represents an RTCP packet, a protocol used for out-of-band statistics
7 // and control information for an RTP session.
8 type Packetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Packet# interface {
9 // DestinationSSRC returns an array of SSRC values that this packet refers to.
10 DestinationSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Packet#DestinationSSRC.() []uint32
11
12 Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Packet#Marshal.() ([]byte, error)
13 Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Packet#Unmarshal.(rawPacket []byte) error
14 MarshalSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Packet#MarshalSize.() int
15 }
16
17 // Unmarshal takes an entire udp datagram (which may consist of multiple RTCP packets) and
18 // returns the unmarshaled packets it contains.
19 //
20 // If this is a reduced-size RTCP packet a feedback packet (Goodbye, SliceLossIndication, etc)
21 // will be returned. Otherwise, the underlying type of the returned packet will be
22 // CompoundPacket.
23 func Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Unmarshal().(rawData []byte) ([]Packetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Packet#, error) {
24 var packets []Packetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Packet#
25 for len(rawData) != 0 {
26 p, processed, err := unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/unmarshal().(rawData)
27 if err != nil {
28 return nil, err
29 }
30
31 packets = append(packets, p)
32 rawData = rawData[processed:]
33 }
34
35 switch len(packets) {
36 // Empty packet
37 case 0:
38 return nil, errInvalidHeaderscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errInvalidHeader.
39 // Multiple Packets
40 default:
41 return packets, nil
42 }
43 }
44
45 // Marshal takes an array of Packets and serializes them to a single buffer.
46 func Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Marshal().(packets []Packetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Packet#) ([]byte, error) {
47 out := make([]byte, 0)
48 for _, p := range packets {
49 data, err := p.Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Packet#Marshal.()
50 if err != nil {
51 return nil, err
52 }
53 out = append(out, data...)
54 }
55
56 return out, nil
57 }
58
59 // unmarshal is a factory which pulls the first RTCP packet from a bytestream,
60 // and returns it's parsed representation, and the amount of data that was processed.
61 //
62 //nolint:cyclop
63 func unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/unmarshal().(rawData []byte) (packet Packetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Packet#, bytesprocessed int, err error) {
64 var header Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#
65
66 err = header.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Unmarshal().(rawData)
67 if err != nil {
68 return nil, 0, err
69 }
70
71 bytesprocessed = (int(header.Lengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Length.) + 1) * 4
72 if bytesprocessed > len(rawData) {
73 return nil, 0, errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort.
74 }
75 inPacket := rawData[:bytesprocessed]
76
77 switch header.Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Type. {
78 case TypeSenderReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeSenderReport.:
79 packet = new(SenderReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SenderReport#)
80
81 case TypeReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeReceiverReport.:
82 packet = new(ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#)
83
84 case TypeSourceDescriptionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeSourceDescription.:
85 packet = new(SourceDescriptionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#)
86
87 case TypeGoodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeGoodbye.:
88 packet = new(Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#)
89
90 case TypeTransportSpecificFeedbackscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTransportSpecificFeedback.:
91 switch header.Countscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Count. {
92 case FormatTLNscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FormatTLN.:
93 packet = new(TransportLayerNackscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerNack#)
94 case FormatRRRscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FormatRRR.:
95 packet = new(RapidResynchronizationRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#)
96 case FormatTCCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FormatTCC.:
97 packet = new(TransportLayerCCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#)
98 case FormatCCFBscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FormatCCFB.:
99 packet = new(CCFeedbackReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#)
100 default:
101 packet = new(RawPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RawPacket#)
102 }
103
104 case TypePayloadSpecificFeedbackscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypePayloadSpecificFeedback.:
105 switch header.Countscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Count. {
106 case FormatPLIscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FormatPLI.:
107 packet = new(PictureLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#)
108 case FormatSLIscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FormatSLI.:
109 packet = new(SliceLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#)
110 case FormatREMBscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FormatREMB.:
111 packet = new(ReceiverEstimatedMaximumBitratescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverEstimatedMaximumBitrate#)
112 case FormatFIRscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FormatFIR.:
113 packet = new(FullIntraRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#)
114 default:
115 packet = new(RawPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RawPacket#)
116 }
117
118 case TypeExtendedReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeExtendedReport.:
119 packet = new(ExtendedReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ExtendedReport#)
120
121 case TypeApplicationDefinedscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeApplicationDefined.:
122 packet = new(ApplicationDefinedscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ApplicationDefined#)
123
124 default:
125 packet = new(RawPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RawPacket#)
126 }
127
128 err = packet.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Packet#Unmarshal.(inPacket)
129
130 return packet, bytesprocessed, err
131 }