Debian Codegraph @

slice_loss_indication.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 import (
7 "encoding/binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/"
8 "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/"
9 "mathscip-go gomod github.com/golang/go/src go1.24.0 math/"
10 )
11
12 // SLIEntry represents a single entry to the SLI packet's
13 // list of lost slices.
14 type SLIEntryscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SLIEntry# struct {
15 // ID of first lost slice
16 Firstscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SLIEntry#First. uint16
17
18 // Number of lost slices
19 Numberscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SLIEntry#Number. uint16
20
21 // ID of related picture
22 Picturescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SLIEntry#Picture. uint8
23 }
24
25 // The SliceLossIndication packet informs the encoder about the loss of a picture slice.
26 type SliceLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication# struct {
27 // SSRC of sender
28 SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#SenderSSRC. uint32
29
30 // SSRC of the media source
31 MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#MediaSSRC. uint32
32
33 SLIscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#SLI. []SLIEntryscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SLIEntry#
34 }
35
36 const (
37 sliLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sliLength. = 2
38 sliOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sliOffset. = 8
39 )
40
41 // Marshal encodes the SliceLossIndication in binary.
42 func (p SliceLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#) Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#Marshal().() ([]byte, error) {
43 if len(p.SLIscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#SLI.)+sliLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sliLength. > mathscip-go gomod github.com/golang/go/src go1.24.0 math/.MaxUint8scip-go gomod github.com/golang/go/src go1.24.0 math/MaxUint8. {
44 return nil, errTooManyReportsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errTooManyReports.
45 }
46
47 rawPacket := make([]byte, sliOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sliOffset.+(len(p.SLIscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#SLI.)*4))
48 binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/BigEndian..PutUint32scip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/bigEndian#PutUint32().(rawPacket, p.SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#SenderSSRC.)
49 binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/BigEndian..PutUint32scip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/bigEndian#PutUint32().(rawPacket[4:], p.MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#MediaSSRC.)
50 for i, s := range p.SLIscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#SLI. {
51 sli := ((uint32(s.Firstscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SLIEntry#First.) & 0x1FFF) << 19) |
52 ((uint32(s.Numberscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SLIEntry#Number.) & 0x1FFF) << 6) |
53 (uint32(s.Picturescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SLIEntry#Picture.) & 0x3F)
54 binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/BigEndian..PutUint32scip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/bigEndian#PutUint32().(rawPacket[sliOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sliOffset.+(4*i):], sli)
55 }
56 hData, err := p.Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#Header().().Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Marshal().()
57 if err != nil {
58 return nil, err
59 }
60
61 return append(hData, rawPacket...), nil
62 }
63
64 // Unmarshal decodes the SliceLossIndication from binary.
65 func (p *SliceLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#) Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#Unmarshal().(rawPacket []byte) error {
66 if len(rawPacket) < (headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength. + ssrcLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ssrcLength.) {
67 return errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort.
68 }
69
70 var header Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#
71 if err := header.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Unmarshal().(rawPacket); err != nil {
72 return err
73 }
74
75 if len(rawPacket) < (headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength. + 4*int(header.Lengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Length.)) {
76 return errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort.
77 }
78
79 if header.Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Type. != TypeTransportSpecificFeedbackscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTransportSpecificFeedback. || header.Countscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Count. != FormatSLIscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FormatSLI. {
80 return errWrongTypescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errWrongType.
81 }
82
83 p.SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#SenderSSRC. = binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/BigEndian..Uint32scip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/bigEndian#Uint32().(rawPacket[headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength.:])
84 p.MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#MediaSSRC. = binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/BigEndian..Uint32scip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/bigEndian#Uint32().(rawPacket[headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength.+ssrcLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ssrcLength.:])
85 for i := headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength. + sliOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sliOffset.; i < (headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength. + 4*int(header.Lengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Length.)); i += 4 {
86 sli := binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/BigEndian..Uint32scip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/bigEndian#Uint32().(rawPacket[i:])
87 p.SLIscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#SLI. = append(p.SLIscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#SLI., SLIEntryscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SLIEntry#{
88 Firstscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SLIEntry#First.: uint16((sli >> 19) & 0x1FFF), //nolint:gosec // G115
89 Numberscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SLIEntry#Number.: uint16((sli >> 6) & 0x1FFF), //nolint:gosec // G115
90 Picturescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SLIEntry#Picture.: uint8(sli & 0x3F), //nolint:gosec // G115
91 })
92 }
93
94 return nil
95 }
96
97 // MarshalSize returns the size of the packet once marshaled.
98 func (p *SliceLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#) MarshalSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#MarshalSize().() int {
99 return headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength. + sliOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sliOffset. + (len(p.SLIscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#SLI.) * 4)
100 }
101
102 // Header returns the Header associated with this packet.
103 func (p *SliceLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#) Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#Header().() Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header# {
104 return Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#{
105 Countscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Count.: FormatSLIscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FormatSLI.,
106 Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Type.: TypeTransportSpecificFeedbackscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTransportSpecificFeedback.,
107 Lengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Length.: uint16((p.MarshalSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#MarshalSize().() / 4) - 1), //nolint:gosec // G115
108 }
109 }
110
111 func (p *SliceLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#) Stringscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#String().() string {
112 return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintf().("SliceLossIndication %x %x %+v", p.SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#SenderSSRC., p.MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#MediaSSRC., p.SLIscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#SLI.)
113 }
114
115 // DestinationSSRC returns an array of SSRC values that this packet refers to.
116 func (p *SliceLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#) DestinationSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#DestinationSSRC().() []uint32 {
117 return []uint32{p.MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SliceLossIndication#MediaSSRC.}
118 }