Files
webrtc/pkg/rtcp/rapid_resynchronization_request.go
Woodrow Douglass af1b2c9520 Improve rtcp.TestUnmarshal to improve coverage
* Test polymorphic RTCP packet parser
* Add tests for more Unmarshal methods
Relates to #119
2018-11-29 12:30:34 -08:00

66 lines
1.6 KiB
Go

package rtcp
import (
"encoding/binary"
)
// The RapidResynchronizationRequest packet informs the encoder about the loss of an undefined amount of coded video data belonging to one or more pictures
type RapidResynchronizationRequest struct {
// SSRC of sender
SenderSSRC uint32
// SSRC of the media source
MediaSSRC uint32
}
const (
rrrFMT = 5
rrrLength = 2
)
// Marshal encodes the RapidResynchronizationRequest in binary
func (p RapidResynchronizationRequest) Marshal() ([]byte, error) {
/*
* RRR does not require parameters. Therefore, the length field MUST be
* 2, and there MUST NOT be any Feedback Control Information.
*
* The semantics of this FB message is independent of the payload type.
*/
rawPacket := make([]byte, 8)
binary.BigEndian.PutUint32(rawPacket, p.SenderSSRC)
binary.BigEndian.PutUint32(rawPacket[4:], p.MediaSSRC)
h := Header{
Count: rrrFMT,
Type: TypeTransportSpecificFeedback,
Length: rrrLength,
}
hData, err := h.Marshal()
if err != nil {
return nil, err
}
return append(hData, rawPacket...), nil
}
// Unmarshal decodes the RapidResynchronizationRequest from binary
func (p *RapidResynchronizationRequest) Unmarshal(rawPacket []byte) error {
if len(rawPacket) < (headerLength + (ssrcLength * 2)) {
return errPacketTooShort
}
var h Header
if err := h.Unmarshal(rawPacket); err != nil {
return err
}
if h.Type != TypeTransportSpecificFeedback || h.Count != rrrFMT {
return errWrongType
}
p.SenderSSRC = binary.BigEndian.Uint32(rawPacket[headerLength:])
p.MediaSSRC = binary.BigEndian.Uint32(rawPacket[headerLength+ssrcLength:])
return nil
}