| 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 | ) |
| 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 PictureLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication# struct { |
| 14 | // SSRC of sender |
| 15 | SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#SenderSSRC. uint32 |
| 16 | |
| 17 | // SSRC where the loss was experienced |
| 18 | MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#MediaSSRC. uint32 |
| 19 | } |
| 20 | |
| 21 | const ( |
| 22 | pliLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/pliLength. = 2 |
| 23 | ) |
| 24 | |
| 25 | // Marshal encodes the PictureLossIndication in binary. |
| 26 | func (p PictureLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#) Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/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.MarshalSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#MarshalSize().()) |
| 34 | packetBody := rawPacket[headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength.:] |
| 35 | |
| 36 | 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().(packetBody, p.SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#SenderSSRC.) |
| 37 | 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().(packetBody[4:], p.MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#MediaSSRC.) |
| 38 | |
| 39 | h := Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#{ |
| 40 | Countscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Count.: FormatPLIscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FormatPLI., |
| 41 | Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Type.: TypePayloadSpecificFeedbackscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypePayloadSpecificFeedback., |
| 42 | Lengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Length.: pliLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/pliLength., |
| 43 | } |
| 44 | hData, err := h.Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#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 *PictureLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#) Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#Unmarshal().(rawPacket []byte) error { |
| 55 | 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. * 2)) { |
| 56 | return errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort. |
| 57 | } |
| 58 | |
| 59 | var h Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header# |
| 60 | if err := h.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Unmarshal().(rawPacket); err != nil { |
| 61 | return err |
| 62 | } |
| 63 | |
| 64 | if h.Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Type. != TypePayloadSpecificFeedbackscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypePayloadSpecificFeedback. || h.Countscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Count. != FormatPLIscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FormatPLI. { |
| 65 | return errWrongTypescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errWrongType. |
| 66 | } |
| 67 | |
| 68 | p.SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#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.:]) |
| 69 | p.MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#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.:]) |
| 70 | |
| 71 | return nil |
| 72 | } |
| 73 | |
| 74 | // Header returns the Header associated with this packet. |
| 75 | func (p *PictureLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#) Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#Header().() Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header# { |
| 76 | return Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#{ |
| 77 | Countscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Count.: FormatPLIscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FormatPLI., |
| 78 | Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Type.: TypePayloadSpecificFeedbackscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypePayloadSpecificFeedback., |
| 79 | Lengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Length.: pliLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/pliLength., |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | // MarshalSize returns the size of the packet once marshaled. |
| 84 | func (p *PictureLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#) MarshalSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#MarshalSize().() int { |
| 85 | return headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength. + ssrcLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ssrcLength.*2 |
| 86 | } |
| 87 | |
| 88 | func (p *PictureLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#) Stringscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#String().() string { |
| 89 | 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().("PictureLossIndication %x %x", p.SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#SenderSSRC., p.MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#MediaSSRC.) |
| 90 | } |
| 91 | |
| 92 | // DestinationSSRC returns an array of SSRC values that this packet refers to. |
| 93 | func (p *PictureLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#) DestinationSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#DestinationSSRC().() []uint32 { |
| 94 | return []uint32{p.MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#MediaSSRC.} |
| 95 | } |