| 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 RapidResynchronizationRequest packet informs the encoder about the loss of |
| 12 | // an undefined amount of coded video data belonging to one or more pictures. |
| 13 | type RapidResynchronizationRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest# struct { |
| 14 | // SSRC of sender |
| 15 | SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#SenderSSRC. uint32 |
| 16 | |
| 17 | // SSRC of the media source |
| 18 | MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#MediaSSRC. uint32 |
| 19 | } |
| 20 | |
| 21 | // RapidResynchronisationRequest is provided as RFC 6051 spells resynchronization with an s. |
| 22 | // We provide both names to be consistent with other RFCs which spell resynchronization with a z. |
| 23 | type RapidResynchronisationRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronisationRequest# = RapidResynchronizationRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest# |
| 24 | |
| 25 | const ( |
| 26 | rrrLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/rrrLength. = 2 |
| 27 | rrrHeaderLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/rrrHeaderLength. = ssrcLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ssrcLength. * 2 |
| 28 | rrrMediaOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/rrrMediaOffset. = 4 |
| 29 | ) |
| 30 | |
| 31 | // Marshal encodes the RapidResynchronizationRequest in binary. |
| 32 | func (p RapidResynchronizationRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#) Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#Marshal().() ([]byte, error) { |
| 33 | /* |
| 34 | * RRR does not require parameters. Therefore, the length field MUST be |
| 35 | * 2, and there MUST NOT be any Feedback Control Information. |
| 36 | * |
| 37 | * The semantics of this FB message is independent of the payload type. |
| 38 | */ |
| 39 | rawPacket := make([]byte, p.MarshalSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#MarshalSize().()) |
| 40 | packetBody := rawPacket[headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength.:] |
| 41 | |
| 42 | 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`/RapidResynchronizationRequest#SenderSSRC.) |
| 43 | 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[rrrMediaOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/rrrMediaOffset.:], p.MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#MediaSSRC.) |
| 44 | |
| 45 | hData, err := p.Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#Header().().Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Marshal().() |
| 46 | if err != nil { |
| 47 | return nil, err |
| 48 | } |
| 49 | copy(rawPacket, hData) |
| 50 | |
| 51 | return rawPacket, nil |
| 52 | } |
| 53 | |
| 54 | // Unmarshal decodes the RapidResynchronizationRequest from binary. |
| 55 | func (p *RapidResynchronizationRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#) Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#Unmarshal().(rawPacket []byte) error { |
| 56 | 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)) { |
| 57 | return errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort. |
| 58 | } |
| 59 | |
| 60 | var h Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header# |
| 61 | if err := h.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Unmarshal().(rawPacket); err != nil { |
| 62 | return err |
| 63 | } |
| 64 | |
| 65 | if h.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. || h.Countscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Count. != FormatRRRscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FormatRRR. { |
| 66 | return errWrongTypescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errWrongType. |
| 67 | } |
| 68 | |
| 69 | p.SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#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.:]) |
| 70 | p.MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#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.:]) |
| 71 | |
| 72 | return nil |
| 73 | } |
| 74 | |
| 75 | // MarshalSize returns the size of the packet once marshaled. |
| 76 | func (p *RapidResynchronizationRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#) MarshalSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#MarshalSize().() int { |
| 77 | return headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength. + rrrHeaderLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/rrrHeaderLength. |
| 78 | } |
| 79 | |
| 80 | // Header returns the Header associated with this packet. |
| 81 | func (p *RapidResynchronizationRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#) Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#Header().() Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header# { |
| 82 | return Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#{ |
| 83 | Countscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Count.: FormatRRRscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FormatRRR., |
| 84 | 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., |
| 85 | Lengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Length.: rrrLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/rrrLength., |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | // DestinationSSRC returns an array of SSRC values that this packet refers to. |
| 90 | func (p *RapidResynchronizationRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#) DestinationSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#DestinationSSRC().() []uint32 { |
| 91 | return []uint32{p.MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#MediaSSRC.} |
| 92 | } |
| 93 | |
| 94 | func (p *RapidResynchronizationRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#) Stringscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#String().() string { |
| 95 | 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().("RapidResynchronizationRequest %x %x", p.SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#SenderSSRC., p.MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#MediaSSRC.) |
| 96 | } |