Debian Codegraph @

picture_loss_indication.go

raw symbols SCIP
1 // SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
2 // SPDX-License-Identifier: MIT
3
4 package rtcp
5
6 import (
7 "encoding/binary"
8 "fmt"
9 )
10
11 // The PictureLossIndication packet informs the encoder about the loss of an undefined amount of
12 // coded video data belonging to one or more pictures.
13 type PictureLossIndication struct {
14 // SSRC of sender
15 SenderSSRC uint32
16
17 // SSRC where the loss was experienced
18 MediaSSRC uint32
19 }
20
21 const (
22 pliLength = 2
23 )
24
25 // Marshal encodes the PictureLossIndication in binary.
26 func (p PictureLossIndication) Marshal() ([]byte, error) {
27 /*
28 * PLI does not require parameters. Therefore, the length field MUST be
29 * 2, and there MUST NOT be any Feedback Control Information.
30 *
31 * The semantics of this FB message is independent of the payload type.
32 */
33 rawPacket := make([]byte, p.MarshalSize())
34 packetBody := rawPacket[headerLength:]
35
36 binary.BigEndian.PutUint32(packetBody, p.SenderSSRC)
37 binary.BigEndian.PutUint32(packetBody[4:], p.MediaSSRC)
38
39 h := Header{
40 Count: FormatPLI,
41 Type: TypePayloadSpecificFeedback,
42 Length: pliLength,
43 }
44 hData, err := h.Marshal()
45 if err != nil {
46 return nil, err
47 }
48 copy(rawPacket, hData)
49
50 return rawPacket, nil
51 }
52
53 // Unmarshal decodes the PictureLossIndication from binary.
54 func (p *PictureLossIndication) Unmarshal(rawPacket []byte) error {
55 if len(rawPacket) < (headerLength + (ssrcLength * 2)) {
56 return errPacketTooShort
57 }
58
59 var h Header
60 if err := h.Unmarshal(rawPacket); err != nil {
61 return err
62 }
63
64 if h.Type != TypePayloadSpecificFeedback || h.Count != FormatPLI {
65 return errWrongType
66 }
67
68 p.SenderSSRC = binary.BigEndian.Uint32(rawPacket[headerLength:])
69 p.MediaSSRC = binary.BigEndian.Uint32(rawPacket[headerLength+ssrcLength:])
70
71 return nil
72 }
73
74 // Header returns the Header associated with this packet.
75 func (p *PictureLossIndication) Header() Header {
76 return Header{
77 Count: FormatPLI,
78 Type: TypePayloadSpecificFeedback,
79 Length: pliLength,
80 }
81 }
82
83 // MarshalSize returns the size of the packet once marshaled.
84 func (p *PictureLossIndication) MarshalSize() int {
85 return headerLength + ssrcLength*2
86 }
87
88 func (p *PictureLossIndication) String() string {
89 return fmt.Sprintf("PictureLossIndication %x %x", p.SenderSSRC, p.MediaSSRC)
90 }
91
92 // DestinationSSRC returns an array of SSRC values that this packet refers to.
93 func (p *PictureLossIndication) DestinationSSRC() []uint32 {
94 return []uint32{p.MediaSSRC}
95 }