rtcp

package module
Version: v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2019 License: MIT Imports: 6 Imported by: 165

README


Pion RTCP

A Go implementation of RTCP

Pion RTCP Sourcegraph Widget Slack Widget
Build Status GoDoc Coverage Status Go Report Card


See DESIGN.md for an overview of features and future goals.

Roadmap

The library is used as a part of our WebRTC implementation. Please refer to that roadmap to track our major milestones.

Community

Pion has an active community on the Golang Slack. Sign up and join the #pion channel for discussions and support. You can also use Pion mailing list.

We are always looking to support your projects. Please reach out if you have something to build!

If you need commercial support or don't want to use public methods you can contact us at team@pion.ly

Contributing

Check out the contributing wiki to join the group of amazing people making this project possible:

License

MIT License - see LICENSE for full text

Documentation

Overview

Package rtcp implements encoding and decoding of RTCP packets according to RFCs 3550 and 5506.

RTCP is a sister protocol of the Real-time Transport Protocol (RTP). Its basic functionality and packet structure is defined in RFC 3550. RTCP provides out-of-band statistics and control information for an RTP session. It partners with RTP in the delivery and packaging of multimedia data, but does not transport any media data itself.

The primary function of RTCP is to provide feedback on the quality of service (QoS) in media distribution by periodically sending statistics information such as transmitted octet and packet counts, packet loss, packet delay variation, and round-trip delay time to participants in a streaming multimedia session. An application may use this information to control quality of service parameters, perhaps by limiting flow, or using a different codec.

Decoding RTCP packets:

pkt, err := rtcp.Unmarshal(rtcpData)
// ...

switch p := pkt.(type) {
case *rtcp.CompoundPacket:
	...
case *rtcp.PictureLossIndication:
	...
default:
	...
}

Encoding RTCP packets:

pkt := &rtcp.PictureLossIndication{
	SenderSSRC: senderSSRC,
	MediaSSRC: mediaSSRC
}
pliData, err := pkt.Marshal()
// ...

Index

Constants

View Source
const (
	FormatSLI  uint8 = 2
	FormatPLI  uint8 = 1
	FormatTLN  uint8 = 1
	FormatRRR  uint8 = 5
	FormatREMB uint8 = 15
)

Transport and Payload specific feedback messages overload the count field to act as a message type. those are listed here

Variables

This section is empty.

Functions

func Marshal

func Marshal(packets []Packet) ([]byte, error)

Marshal takes an array of Packets and serializes them to a single buffer

Types

type CompoundPacket

type CompoundPacket []Packet

A CompoundPacket is a collection of RTCP packets transmitted as a single packet with the underlying protocol (for example UDP).

To maximize the resolution of receiption statistics, the first Packet in a CompoundPacket must always be either a SenderReport or a ReceiverReport. This is true even if no data has been sent or received, in which case an empty ReceiverReport must be sent, and even if the only other RTCP packet in the compound packet is a Goodbye.

Next, a SourceDescription containing a CNAME item must be included in each CompoundPacket to identify the source and to begin associating media for purposes such as lip-sync.

Other RTCP packet types may follow in any order. Packet types may appear more than once.

func (CompoundPacket) CNAME

func (c CompoundPacket) CNAME() (string, error)

CNAME returns the CNAME that *must* be present in every CompoundPacket

func (CompoundPacket) DestinationSSRC

func (c CompoundPacket) DestinationSSRC() []uint32

DestinationSSRC returns the synchronization sources associated with this CompoundPacket's reception report.

func (CompoundPacket) Marshal

func (c CompoundPacket) Marshal() ([]byte, error)

Marshal encodes the CompoundPacket as binary.

func (*CompoundPacket) Unmarshal

func (c *CompoundPacket) Unmarshal(rawData []byte) error

Unmarshal decodes a CompoundPacket from binary.

func (CompoundPacket) Validate

func (c CompoundPacket) Validate() error

Validate returns an error if this is not an RFC-compliant CompoundPacket.

type Goodbye

type Goodbye struct {
	// The SSRC/CSRC identifiers that are no longer active
	Sources []uint32
	// Optional text indicating the reason for leaving, e.g., "camera malfunction" or "RTP loop detected"
	Reason string
}

The Goodbye packet indicates that one or more sources are no longer active.

func (*Goodbye) DestinationSSRC

func (g *Goodbye) DestinationSSRC() []uint32

DestinationSSRC returns an array of SSRC values that this packet refers to.

func (*Goodbye) Header

func (g *Goodbye) Header() Header

Header returns the Header associated with this packet.

func (Goodbye) Marshal

func (g Goodbye) Marshal() ([]byte, error)

Marshal encodes the Goodbye packet in binary

func (*Goodbye) Unmarshal

func (g *Goodbye) Unmarshal(rawPacket []byte) error

Unmarshal decodes the Goodbye packet from binary

type Header struct {
	// If the padding bit is set, this individual RTCP packet contains
	// some additional padding octets at the end which are not part of
	// the control information but are included in the length field.
	Padding bool
	// The number of reception reports, sources contained or FMT in this packet (depending on the Type)
	Count uint8
	// The RTCP packet type for this packet
	Type PacketType
	// The length of this RTCP packet in 32-bit words minus one,
	// including the header and any padding.
	Length uint16
}

A Header is the common header shared by all RTCP packets

func (Header) Marshal

func (h Header) Marshal() ([]byte, error)

Marshal encodes the Header in binary

func (*Header) Unmarshal

func (h *Header) Unmarshal(rawPacket []byte) error

Unmarshal decodes the Header from binary

type NackPair

type NackPair struct {
	// ID of lost packets
	PacketID uint16

	// Bitmask of following lost packets
	LostPackets PacketBitmap
}

NackPair is a wire-representation of a collection of Lost RTP packets

func (*NackPair) PacketList

func (n *NackPair) PacketList() []uint16

PacketList returns a list of Nack'd packets that's referenced by a NackPair

type Packet

type Packet interface {
	// DestinationSSRC returns an array of SSRC values that this packet refers to.
	DestinationSSRC() []uint32

	Marshal() ([]byte, error)
	Unmarshal(rawPacket []byte) error
}

Packet represents an RTCP packet, a protocol used for out-of-band statistics and control information for an RTP session

func Unmarshal

func Unmarshal(rawData []byte) ([]Packet, error)

Unmarshal takes an entire udp datagram (which may consist of multiple RTCP packets) and returns the unmarshaled packets it contains.

If this is a reduced-size RTCP packet a feedback packet (Goodbye, SliceLossIndication, etc) will be returned. Otherwise, the underlying type of the returned packet will be CompoundPacket.

type PacketBitmap

type PacketBitmap uint16

PacketBitmap shouldn't be used like a normal integral, so it's type is masked here. Access it with PacketList().

type PacketType

type PacketType uint8

PacketType specifies the type of an RTCP packet

const (
	TypeSenderReport              PacketType = 200 // RFC 3550, 6.4.1
	TypeReceiverReport            PacketType = 201 // RFC 3550, 6.4.2
	TypeSourceDescription         PacketType = 202 // RFC 3550, 6.5
	TypeGoodbye                   PacketType = 203 // RFC 3550, 6.6
	TypeApplicationDefined        PacketType = 204 // RFC 3550, 6.7 (unimplemented)
	TypeTransportSpecificFeedback PacketType = 205 // RFC 4585, 6051
	TypePayloadSpecificFeedback   PacketType = 206 // RFC 4585, 6.3

)

RTCP packet types registered with IANA. See: https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4

func (PacketType) String

func (p PacketType) String() string

type PictureLossIndication

type PictureLossIndication struct {
	// SSRC of sender
	SenderSSRC uint32

	// SSRC where the loss was experienced
	MediaSSRC uint32
}

The PictureLossIndication packet informs the encoder about the loss of an undefined amount of coded video data belonging to one or more pictures

func (*PictureLossIndication) DestinationSSRC

func (p *PictureLossIndication) DestinationSSRC() []uint32

DestinationSSRC returns an array of SSRC values that this packet refers to.

func (*PictureLossIndication) Header

func (p *PictureLossIndication) Header() Header

Header returns the Header associated with this packet.

func (PictureLossIndication) Marshal

func (p PictureLossIndication) Marshal() ([]byte, error)

Marshal encodes the PictureLossIndication in binary

func (*PictureLossIndication) String

func (p *PictureLossIndication) String() string

func (*PictureLossIndication) Unmarshal

func (p *PictureLossIndication) Unmarshal(rawPacket []byte) error

Unmarshal decodes the PictureLossIndication from binary

type RapidResynchronizationRequest

type RapidResynchronizationRequest struct {
	// SSRC of sender
	SenderSSRC uint32

	// SSRC of the media source
	MediaSSRC uint32
}

The RapidResynchronizationRequest packet informs the encoder about the loss of an undefined amount of coded video data belonging to one or more pictures

func (*RapidResynchronizationRequest) DestinationSSRC

func (p *RapidResynchronizationRequest) DestinationSSRC() []uint32

DestinationSSRC returns an array of SSRC values that this packet refers to.

func (*RapidResynchronizationRequest) Header

Header returns the Header associated with this packet.

func (RapidResynchronizationRequest) Marshal

func (p RapidResynchronizationRequest) Marshal() ([]byte, error)

Marshal encodes the RapidResynchronizationRequest in binary

func (*RapidResynchronizationRequest) String

func (*RapidResynchronizationRequest) Unmarshal

func (p *RapidResynchronizationRequest) Unmarshal(rawPacket []byte) error

Unmarshal decodes the RapidResynchronizationRequest from binary

type RawPacket

type RawPacket []byte

RawPacket represents an unparsed RTCP packet. It's returned by Unmarshal when a packet with an unknown type is encountered.

func (*RawPacket) DestinationSSRC

func (r *RawPacket) DestinationSSRC() []uint32

DestinationSSRC returns an array of SSRC values that this packet refers to.

func (RawPacket) Header

func (r RawPacket) Header() Header

Header returns the Header associated with this packet.

func (RawPacket) Marshal

func (r RawPacket) Marshal() ([]byte, error)

Marshal encodes the packet in binary.

func (RawPacket) String

func (r RawPacket) String() string

func (*RawPacket) Unmarshal

func (r *RawPacket) Unmarshal(b []byte) error

Unmarshal decodes the packet from binary.

type ReceiverEstimatedMaximumBitrate

type ReceiverEstimatedMaximumBitrate struct {
	// SSRC of sender
	SenderSSRC uint32

	// Estimated maximum bitrate
	Bitrate uint64

	// SSRC entries which this packet applies to
	SSRCs []uint32
}

ReceiverEstimatedMaximumBitrate contains the receiver's estimated maximum bitrate. see: https://tools.ietf.org/html/draft-alvestrand-rmcat-remb-03

func (*ReceiverEstimatedMaximumBitrate) DestinationSSRC

func (p *ReceiverEstimatedMaximumBitrate) DestinationSSRC() []uint32

DestinationSSRC returns an array of SSRC values that this packet refers to.

func (*ReceiverEstimatedMaximumBitrate) Header

Header returns the Header associated with this packet.

func (ReceiverEstimatedMaximumBitrate) Marshal

func (p ReceiverEstimatedMaximumBitrate) Marshal() (buf []byte, err error)

Marshal serializes the packet and returns a byte slice.

func (ReceiverEstimatedMaximumBitrate) MarshalSize

func (p ReceiverEstimatedMaximumBitrate) MarshalSize() (n int)

MarshalSize returns the size of the packet when marshaled. This can be used in conjunction with `MarshalTo` to avoid allocations.

func (ReceiverEstimatedMaximumBitrate) MarshalTo

func (p ReceiverEstimatedMaximumBitrate) MarshalTo(buf []byte) (n int, err error)

MarshalTo serializes the packet to the given byte slice.

func (*ReceiverEstimatedMaximumBitrate) String

String prints the REMB packet in a human-readable format.

func (*ReceiverEstimatedMaximumBitrate) Unmarshal

func (p *ReceiverEstimatedMaximumBitrate) Unmarshal(buf []byte) (err error)

Unmarshal reads a REMB packet from the given byte slice.

type ReceiverReport

type ReceiverReport struct {
	// The synchronization source identifier for the originator of this RR packet.
	SSRC uint32
	// Zero or more reception report blocks depending on the number of other
	// sources heard by this sender since the last report. Each reception report
	// block conveys statistics on the reception of RTP packets from a
	// single synchronization source.
	Reports []ReceptionReport
	// Extension contains additional, payload-specific information that needs to
	// be reported regularly about the receiver.
	ProfileExtensions []byte
}

A ReceiverReport (RR) packet provides reception quality feedback for an RTP stream

func (*ReceiverReport) DestinationSSRC

func (r *ReceiverReport) DestinationSSRC() []uint32

DestinationSSRC returns an array of SSRC values that this packet refers to.

func (*ReceiverReport) Header

func (r *ReceiverReport) Header() Header

Header returns the Header associated with this packet.

func (ReceiverReport) Marshal

func (r ReceiverReport) Marshal() ([]byte, error)

Marshal encodes the ReceiverReport in binary

func (ReceiverReport) String

func (r ReceiverReport) String() string

func (*ReceiverReport) Unmarshal

func (r *ReceiverReport) Unmarshal(rawPacket []byte) error

Unmarshal decodes the ReceiverReport from binary

type ReceptionReport

type ReceptionReport struct {
	// The SSRC identifier of the source to which the information in this
	// reception report block pertains.
	SSRC uint32
	// The fraction of RTP data packets from source SSRC lost since the
	// previous SR or RR packet was sent, expressed as a fixed point
	// number with the binary point at the left edge of the field.
	FractionLost uint8
	// The total number of RTP data packets from source SSRC that have
	// been lost since the beginning of reception.
	TotalLost uint32
	// The low 16 bits contain the highest sequence number received in an
	// RTP data packet from source SSRC, and the most significant 16
	// bits extend that sequence number with the corresponding count of
	// sequence number cycles.
	LastSequenceNumber uint32
	// An estimate of the statistical variance of the RTP data packet
	// interarrival time, measured in timestamp units and expressed as an
	// unsigned integer.
	Jitter uint32
	// The middle 32 bits out of 64 in the NTP timestamp received as part of
	// the most recent RTCP sender report (SR) packet from source SSRC. If no
	// SR has been received yet, the field is set to zero.
	LastSenderReport uint32
	// The delay, expressed in units of 1/65536 seconds, between receiving the
	// last SR packet from source SSRC and sending this reception report block.
	// If no SR packet has been received yet from SSRC, the field is set to zero.
	Delay uint32
}

A ReceptionReport block conveys statistics on the reception of RTP packets from a single synchronization source.

func (ReceptionReport) Marshal

func (r ReceptionReport) Marshal() ([]byte, error)

Marshal encodes the ReceptionReport in binary

func (*ReceptionReport) Unmarshal

func (r *ReceptionReport) Unmarshal(rawPacket []byte) error

Unmarshal decodes the ReceptionReport from binary

type SDESType

type SDESType uint8

SDESType is the item type used in the RTCP SDES control packet.

const (
	SDESEnd      SDESType = iota // end of SDES list                RFC 3550, 6.5
	SDESCNAME                    // canonical name                  RFC 3550, 6.5.1
	SDESName                     // user name                       RFC 3550, 6.5.2
	SDESEmail                    // user's electronic mail address  RFC 3550, 6.5.3
	SDESPhone                    // user's phone number             RFC 3550, 6.5.4
	SDESLocation                 // geographic user location        RFC 3550, 6.5.5
	SDESTool                     // name of application or tool     RFC 3550, 6.5.6
	SDESNote                     // notice about the source         RFC 3550, 6.5.7
	SDESPrivate                  // private extensions              RFC 3550, 6.5.8  (not implemented)
)

RTP SDES item types registered with IANA. See: https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-5

func (SDESType) String

func (s SDESType) String() string

type SLIEntry

type SLIEntry struct {
	// ID of first lost slice
	First uint16

	// Number of lost slices
	Number uint16

	// ID of related picture
	Picture uint8
}

SLIEntry represents a single entry to the SLI packet's list of lost slices.

type SenderReport

type SenderReport struct {
	// The synchronization source identifier for the originator of this SR packet.
	SSRC uint32
	// The wallclock time when this report was sent so that it may be used in
	// combination with timestamps returned in reception reports from other
	// receivers to measure round-trip propagation to those receivers.
	NTPTime uint64
	// Corresponds to the same time as the NTP timestamp (above), but in
	// the same units and with the same random offset as the RTP
	// timestamps in data packets. This correspondence may be used for
	// intra- and inter-media synchronization for sources whose NTP
	// timestamps are synchronized, and may be used by media-independent
	// receivers to estimate the nominal RTP clock frequency.
	RTPTime uint32
	// The total number of RTP data packets transmitted by the sender
	// since starting transmission up until the time this SR packet was
	// generated.
	PacketCount uint32
	// The total number of payload octets (i.e., not including header or
	// padding) transmitted in RTP data packets by the sender since
	// starting transmission up until the time this SR packet was
	// generated.
	OctetCount uint32
	// Zero or more reception report blocks depending on the number of other
	// sources heard by this sender since the last report. Each reception report
	// block conveys statistics on the reception of RTP packets from a
	// single synchronization source.
	Reports []ReceptionReport
	// ProfileExtensions contains additional, payload-specific information that needs to
	// be reported regularly about the sender.
	ProfileExtensions []byte
}

A SenderReport (SR) packet provides reception quality feedback for an RTP stream

func (*SenderReport) DestinationSSRC

func (r *SenderReport) DestinationSSRC() []uint32

DestinationSSRC returns an array of SSRC values that this packet refers to.

func (*SenderReport) Header

func (r *SenderReport) Header() Header

Header returns the Header associated with this packet.

func (SenderReport) Marshal

func (r SenderReport) Marshal() ([]byte, error)

Marshal encodes the SenderReport in binary

func (SenderReport) String

func (r SenderReport) String() string

func (*SenderReport) Unmarshal

func (r *SenderReport) Unmarshal(rawPacket []byte) error

Unmarshal decodes the SenderReport from binary

type SliceLossIndication

type SliceLossIndication struct {
	// SSRC of sender
	SenderSSRC uint32

	// SSRC of the media source
	MediaSSRC uint32

	SLI []SLIEntry
}

The SliceLossIndication packet informs the encoder about the loss of a picture slice

func (*SliceLossIndication) DestinationSSRC

func (p *SliceLossIndication) DestinationSSRC() []uint32

DestinationSSRC returns an array of SSRC values that this packet refers to.

func (*SliceLossIndication) Header

func (p *SliceLossIndication) Header() Header

Header returns the Header associated with this packet.

func (SliceLossIndication) Marshal

func (p SliceLossIndication) Marshal() ([]byte, error)

Marshal encodes the SliceLossIndication in binary

func (*SliceLossIndication) String

func (p *SliceLossIndication) String() string

func (*SliceLossIndication) Unmarshal

func (p *SliceLossIndication) Unmarshal(rawPacket []byte) error

Unmarshal decodes the SliceLossIndication from binary

type SourceDescription

type SourceDescription struct {
	Chunks []SourceDescriptionChunk
}

A SourceDescription (SDES) packet describes the sources in an RTP stream.

func (*SourceDescription) DestinationSSRC

func (s *SourceDescription) DestinationSSRC() []uint32

DestinationSSRC returns an array of SSRC values that this packet refers to.

func (*SourceDescription) Header

func (s *SourceDescription) Header() Header

Header returns the Header associated with this packet.

func (SourceDescription) Marshal

func (s SourceDescription) Marshal() ([]byte, error)

Marshal encodes the SourceDescription in binary

func (*SourceDescription) String

func (s *SourceDescription) String() string

func (*SourceDescription) Unmarshal

func (s *SourceDescription) Unmarshal(rawPacket []byte) error

Unmarshal decodes the SourceDescription from binary

type SourceDescriptionChunk

type SourceDescriptionChunk struct {
	// The source (ssrc) or contributing source (csrc) identifier this packet describes
	Source uint32
	Items  []SourceDescriptionItem
}

A SourceDescriptionChunk contains items describing a single RTP source

func (SourceDescriptionChunk) Marshal

func (s SourceDescriptionChunk) Marshal() ([]byte, error)

Marshal encodes the SourceDescriptionChunk in binary

func (*SourceDescriptionChunk) Unmarshal

func (s *SourceDescriptionChunk) Unmarshal(rawPacket []byte) error

Unmarshal decodes the SourceDescriptionChunk from binary

type SourceDescriptionItem

type SourceDescriptionItem struct {
	// The type identifier for this item. eg, SDESCNAME for canonical name description.
	//
	// Type zero or SDESEnd is interpreted as the end of an item list and cannot be used.
	Type SDESType
	// Text is a unicode text blob associated with the item. Its meaning varies based on the item's Type.
	Text string
}

A SourceDescriptionItem is a part of a SourceDescription that describes a stream.

func (SourceDescriptionItem) Marshal

func (s SourceDescriptionItem) Marshal() ([]byte, error)

Marshal encodes the SourceDescriptionItem in binary

func (*SourceDescriptionItem) Unmarshal

func (s *SourceDescriptionItem) Unmarshal(rawPacket []byte) error

Unmarshal decodes the SourceDescriptionItem from binary

type TransportLayerNack

type TransportLayerNack struct {
	// SSRC of sender
	SenderSSRC uint32

	// SSRC of the media source
	MediaSSRC uint32

	Nacks []NackPair
}

The TransportLayerNack packet informs the encoder about the loss of a transport packet IETF RFC 4585, Section 6.2.1 https://tools.ietf.org/html/rfc4585#section-6.2.1

func (*TransportLayerNack) DestinationSSRC

func (p *TransportLayerNack) DestinationSSRC() []uint32

DestinationSSRC returns an array of SSRC values that this packet refers to.

func (*TransportLayerNack) Header

func (p *TransportLayerNack) Header() Header

Header returns the Header associated with this packet.

func (TransportLayerNack) Marshal

func (p TransportLayerNack) Marshal() ([]byte, error)

Marshal encodes the TransportLayerNack in binary

func (TransportLayerNack) String

func (p TransportLayerNack) String() string

func (*TransportLayerNack) Unmarshal

func (p *TransportLayerNack) Unmarshal(rawPacket []byte) error

Unmarshal decodes the TransportLayerNack from binary

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto