rtp

package
v0.0.0-...-5d9d701 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// MaxAccessUnitBytes includes AVCC length prefixes for H.264/H.265.
	MaxAccessUnitBytes   = (16 << 20) + 4
	MaxAccessUnitPackets = 16384
)
View Source
const (
	RTCPTypeSR  = 200
	RTCPTypeRR  = 201
	RTCPTypeBYE = 203
)

RTCP packet type constants (RFC 3550).

View Source
const DefaultMTU = 1400

DefaultMTU is the default Maximum Transmission Unit for RTP packets.

Variables

This section is empty.

Functions

func AnnexBToAVCC

func AnnexBToAVCC(data []byte) []byte

AnnexBToAVCC converts Annex-B format (start codes) to AVCC format (4-byte length prefix). This is needed because the internal AVFrame format uses AVCC to match RTMP/FLV conventions.

func BuildAVCDecoderConfig

func BuildAVCDecoderConfig(annexB []byte) []byte

BuildAVCDecoderConfig builds an AVCDecoderConfigurationRecord from Annex-B data containing SPS and PPS NAL units. Returns nil if SPS or PPS not found.

func BuildBYE

func BuildBYE(ssrc uint32) []byte

BuildBYE builds an RTCP BYE packet (PT=203) per RFC 3550. It signals that the given SSRC is leaving the session.

func BuildRR

func BuildRR(ssrc uint32, reports []ReceptionReport) []byte

BuildRR builds an RTCP Receiver Report packet per RFC 3550.

func BuildSR

func BuildSR(ssrc uint32, ntpTime uint64, rtpTime, packetCount, octetCount uint32) []byte

BuildSR builds an RTCP Sender Report packet per RFC 3550.

func DepacketizeFrames

func DepacketizeFrames(depacketizer Depacketizer, pkt *pionrtp.Packet) ([]*avframe.AVFrame, error)

DepacketizeFrames returns every frame represented by a packet while keeping single-frame depacketizers compatible with the original interface.

func ExtractSPSPPS

func ExtractSPSPPS(config []byte) (sps, pps []byte)

ExtractSPSPPS extracts raw SPS and PPS NAL bytes from an AVCDecoderConfigurationRecord.

func ToAnnexB

func ToAnnexB(data []byte, isSequenceHeader bool) []byte

ToAnnexB converts payload to Annex-B format if it isn't already. Handles: Annex-B (pass-through), AVCC (4-byte length prefix), AVCDecoderConfigurationRecord.

func VideoToAnnexB

func VideoToAnnexB(codec avframe.CodecType, data []byte, isSequenceHeader bool) []byte

VideoToAnnexB converts an internal H.264 or H.265 payload to Annex-B. Sequence headers are parsed according to the declared codec instead of guessing from configurationVersion, which is 1 for both AVC and HEVC.

Types

type AACDepacketizer

type AACDepacketizer struct{}

AACDepacketizer reassembles RTP packets into AAC AVFrames.

func (*AACDepacketizer) Depacketize

func (d *AACDepacketizer) Depacketize(pkt *pionrtp.Packet) (*avframe.AVFrame, error)

Depacketize extracts an AAC frame from an RTP packet.

type AACPacketizer

type AACPacketizer struct{}

AACPacketizer packetizes AAC frames into RTP packets using RFC 3640 AAC-hbr mode.

func (*AACPacketizer) Packetize

func (p *AACPacketizer) Packetize(frame *avframe.AVFrame, mtu int) ([]*pionrtp.Packet, error)

Packetize splits an AAC AVFrame into RTP packets.

RFC 3640 AAC-hbr mode layout:

[AU-headers-length (2 bytes, value in bits)]
[AU-header (2 bytes: 13-bit AU-size | 3-bit AU-Index)]
[AAC frame data]

For a single AAC frame the AU-headers-length is 16 (one 16-bit AU-header).

type AV1Depacketizer

type AV1Depacketizer struct {
	// contains filtered or unexported fields
}

AV1Depacketizer reassembles RTP packets into AV1 frames.

func (*AV1Depacketizer) Depacketize

func (d *AV1Depacketizer) Depacketize(pkt *pionrtp.Packet) (*avframe.AVFrame, error)

Depacketize processes one RTP packet. It accumulates fragments and returns a completed AVFrame when the marker bit is set. Returns (nil, nil) for intermediate fragments.

type AV1Packetizer

type AV1Packetizer struct{}

AV1Packetizer packetizes AV1 OBU data into RTP packets. Uses a simplified aggregation header per draft-ietf-avt-rtp-av1.

func (*AV1Packetizer) Packetize

func (p *AV1Packetizer) Packetize(frame *avframe.AVFrame, mtu int) ([]*pionrtp.Packet, error)

Packetize splits AV1 OBU data into one or more RTP packets. Each packet carries a 1-byte aggregation header followed by OBU data.

Single OBU that fits in MTU: header = 0x10 (W=1), Marker=true. Fragmented: first fragment header = 0x00 (Z=0), continuations = 0x80 (Z=1). Last fragment gets Marker=true.

type AccessUnitAssembler

type AccessUnitAssembler struct {
	// contains filtered or unexported fields
}

AccessUnitAssembler combines video depacketizer output through the RTP marker. It is owned by one serialized receive loop, not shared concurrently.

func NewAccessUnitAssembler

func NewAccessUnitAssembler(codec avframe.CodecType, dp Depacketizer) *AccessUnitAssembler

NewAccessUnitAssembler wraps the track's existing video depacketizer. Audio packets must continue through their ordinary per-packet path.

func (*AccessUnitAssembler) Discard

func (a *AccessUnitAssembler) Discard()

Discard releases partial media and codec fragments. Remaining packets with the damaged timestamp/source/payload type are suppressed, including Marker.

func (*AccessUnitAssembler) Push

func (a *AccessUnitAssembler) Push(pkt *pionrtp.Packet) ([]*avframe.AVFrame, error)

Push returns valid sequence headers before any associated media. Media is emitted only after an intact access unit's actual RTP Marker is observed.

type Depacketizer

type Depacketizer interface {
	Depacketize(pkt *pionrtp.Packet) (*avframe.AVFrame, error)
}

Depacketizer reassembles RTP packets into AVFrames.

func NewDepacketizer

func NewDepacketizer(codec avframe.CodecType) (Depacketizer, error)

NewDepacketizer creates a Depacketizer for the given codec.

type G711Depacketizer

type G711Depacketizer struct {
	// Codec stores the specific G.711 variant (CodecG711U or CodecG711A).
	Codec avframe.CodecType
}

G711Depacketizer reassembles RTP packets into G.711 AVFrames.

func (*G711Depacketizer) Depacketize

func (d *G711Depacketizer) Depacketize(pkt *pionrtp.Packet) (*avframe.AVFrame, error)

Depacketize extracts a G.711 frame from an RTP packet.

type G711Packetizer

type G711Packetizer struct{}

G711Packetizer packetizes G.711 (PCMU/PCMA) frames into RTP packets. G.711 samples map directly to RTP payloads with no additional framing.

func (*G711Packetizer) Packetize

func (p *G711Packetizer) Packetize(frame *avframe.AVFrame, mtu int) ([]*pionrtp.Packet, error)

Packetize wraps a G.711 AVFrame into a single RTP packet.

type G722Depacketizer

type G722Depacketizer struct{}

G722Depacketizer reassembles RTP packets into G.722 AVFrames.

func (*G722Depacketizer) Depacketize

func (d *G722Depacketizer) Depacketize(pkt *pionrtp.Packet) (*avframe.AVFrame, error)

Depacketize extracts a G.722 frame from an RTP packet.

type G722Packetizer

type G722Packetizer struct{}

G722Packetizer packetizes G.722 frames into RTP packets. G.722 samples map directly to RTP payloads with no additional framing.

func (*G722Packetizer) Packetize

func (p *G722Packetizer) Packetize(frame *avframe.AVFrame, mtu int) ([]*pionrtp.Packet, error)

Packetize wraps a G.722 AVFrame into a single RTP packet.

type G729Depacketizer

type G729Depacketizer struct{}

G729Depacketizer reassembles RTP packets into G.729 AVFrames.

func (*G729Depacketizer) Depacketize

func (d *G729Depacketizer) Depacketize(pkt *pionrtp.Packet) (*avframe.AVFrame, error)

Depacketize extracts a G.729 frame from an RTP packet.

type G729Packetizer

type G729Packetizer struct{}

G729Packetizer packetizes G.729 frames into RTP packets. G.729 samples map directly to RTP payloads with no additional framing.

func (*G729Packetizer) Packetize

func (p *G729Packetizer) Packetize(frame *avframe.AVFrame, mtu int) ([]*pionrtp.Packet, error)

Packetize wraps a G.729 AVFrame into a single RTP packet.

type H264Depacketizer

type H264Depacketizer struct {
	// contains filtered or unexported fields
}

H264Depacketizer reassembles RTP packets into H.264 NAL units. Single NAL / STAP-A / FU-A input is validated before bounded assembly. Output is in AVCC format (4-byte length prefix) to match RTMP/FLV conventions.

func (*H264Depacketizer) Depacketize

func (d *H264Depacketizer) Depacketize(pkt *pionrtp.Packet) (*avframe.AVFrame, error)

Depacketize processes one RTP packet and returns an AVFrame when a complete NAL unit (or set of NALs) is available. Returns (nil, nil) for intermediate FU-A fragments. Output payload is in AVCC format.

func (*H264Depacketizer) DepacketizeFrames

func (d *H264Depacketizer) DepacketizeFrames(pkt *pionrtp.Packet) ([]*avframe.AVFrame, error)

DepacketizeFrames preserves SPS/PPS received in separate RTP packets and emits the AVC sequence header before the first media frame that uses it.

type H264Packetizer

type H264Packetizer struct{}

H264Packetizer packetizes H.264 NAL units into RTP packets. Delegates to pion's H264Payloader for correct Single NAL / FU-A handling.

func (*H264Packetizer) Packetize

func (p *H264Packetizer) Packetize(frame *avframe.AVFrame, mtu int) ([]*pionrtp.Packet, error)

Packetize splits an AVFrame into RTP packets using pion's H264Payloader. Accepts payloads in Annex-B, AVCC, or AVCDecoderConfigurationRecord format.

type H265Depacketizer

type H265Depacketizer struct {
	// contains filtered or unexported fields
}

H265Depacketizer reassembles RTP packets into H.265 NAL units.

func (*H265Depacketizer) Depacketize

func (d *H265Depacketizer) Depacketize(pkt *pionrtp.Packet) (*avframe.AVFrame, error)

Depacketize processes a single RTP packet and returns an AVFrame when a complete NAL unit has been reassembled. Returns (nil, nil) for intermediate FU fragments.

func (*H265Depacketizer) DepacketizeFrames

func (d *H265Depacketizer) DepacketizeFrames(pkt *pionrtp.Packet) (frames []*avframe.AVFrame, err error)

DepacketizeFrames processes one RTP packet and returns codec configuration before media when an aggregation packet contains both.

type H265Packetizer

type H265Packetizer struct{}

H265Packetizer splits H.265 NAL units into RTP packets.

func (*H265Packetizer) Packetize

func (p *H265Packetizer) Packetize(frame *avframe.AVFrame, mtu int) ([]*pionrtp.Packet, error)

Packetize splits a single H.265 NAL unit into one or more RTP packets. For NAL units that fit within the MTU, a single NAL unit packet is produced. For larger NAL units, FU (Fragmentation Unit) packets are produced per RFC 7798.

type MP3Depacketizer

type MP3Depacketizer struct{}

MP3Depacketizer reassembles RTP packets into MP3 AVFrames.

func (*MP3Depacketizer) Depacketize

func (d *MP3Depacketizer) Depacketize(pkt *pionrtp.Packet) (*avframe.AVFrame, error)

Depacketize extracts an MP3 frame from an RTP packet, stripping the RFC 2250 header.

type MP3Packetizer

type MP3Packetizer struct{}

MP3Packetizer packetizes MP3 frames into RTP packets per RFC 2250. Each packet carries a 4-byte header (2 bytes MBZ + 2 bytes fragment offset) followed by the MP3 frame data.

func (*MP3Packetizer) Packetize

func (p *MP3Packetizer) Packetize(frame *avframe.AVFrame, mtu int) ([]*pionrtp.Packet, error)

Packetize wraps an MP3 AVFrame into a single RTP packet with RFC 2250 header.

type MultiFrameDepacketizer

type MultiFrameDepacketizer interface {
	DepacketizeFrames(pkt *pionrtp.Packet) ([]*avframe.AVFrame, error)
}

MultiFrameDepacketizer is implemented by codecs where one RTP packet can contain codec configuration and media that must be emitted separately.

type OpusDepacketizer

type OpusDepacketizer struct{}

OpusDepacketizer reassembles RTP packets into Opus AVFrames.

func (*OpusDepacketizer) Depacketize

func (d *OpusDepacketizer) Depacketize(pkt *pionrtp.Packet) (*avframe.AVFrame, error)

Depacketize extracts an Opus frame from an RTP packet.

type OpusPacketizer

type OpusPacketizer struct{}

OpusPacketizer packetizes Opus frames into RTP packets. Opus frames map directly to RTP payloads with no additional framing.

func (*OpusPacketizer) Packetize

func (p *OpusPacketizer) Packetize(frame *avframe.AVFrame, mtu int) ([]*pionrtp.Packet, error)

Packetize wraps an Opus AVFrame into a single RTP packet.

type Packetizer

type Packetizer interface {
	Packetize(frame *avframe.AVFrame, mtu int) ([]*pionrtp.Packet, error)
}

Packetizer splits an AVFrame into RTP packets.

func NewPacketizer

func NewPacketizer(codec avframe.CodecType) (Packetizer, error)

NewPacketizer creates a Packetizer for the given codec.

type ReceiverReport

type ReceiverReport struct {
	SSRC    uint32
	Reports []ReceptionReport
}

ReceiverReport represents an RTCP Receiver Report (PT=201).

func ParseRR

func ParseRR(data []byte) (*ReceiverReport, error)

ParseRR parses an RTCP Receiver Report from raw bytes.

type ReceptionReport

type ReceptionReport struct {
	SSRC             uint32
	FractionLost     uint8
	TotalLost        uint32 // 24-bit value
	HighestSeq       uint32
	Jitter           uint32
	LastSR           uint32
	DelaySinceLastSR uint32
}

ReceptionReport represents a single reception report block within an RR.

type SenderReport

type SenderReport struct {
	SSRC        uint32
	NTPTime     uint64
	RTPTime     uint32
	PacketCount uint32
	OctetCount  uint32
}

SenderReport represents an RTCP Sender Report (PT=200).

func ParseSR

func ParseSR(data []byte) (*SenderReport, error)

ParseSR parses an RTCP Sender Report from raw bytes.

type Session

type Session struct {
	SSRC        uint32
	PayloadType uint8
	ClockRate   uint32
	// contains filtered or unexported fields
}

Session tracks RTP session state: SSRC, sequence numbers, and timestamps.

func NewSession

func NewSession(pt uint8, clockRate uint32) *Session

NewSession creates a new RTP session with a random SSRC.

func (*Session) WrapPackets

func (s *Session) WrapPackets(pkts []*pionrtp.Packet, dtsMsec int64) []*pionrtp.Packet

WrapPackets fills in SSRC, PayloadType, Timestamp, and sequential SequenceNumbers for the given packets. dtsMsec is the decode timestamp in milliseconds.

type SpeexDepacketizer

type SpeexDepacketizer struct{}

SpeexDepacketizer reassembles RTP packets into Speex AVFrames.

func (*SpeexDepacketizer) Depacketize

func (d *SpeexDepacketizer) Depacketize(pkt *pionrtp.Packet) (*avframe.AVFrame, error)

Depacketize extracts a Speex frame from an RTP packet.

type SpeexPacketizer

type SpeexPacketizer struct{}

SpeexPacketizer packetizes Speex frames into RTP packets. Speex frames map directly to RTP payloads with no additional framing.

func (*SpeexPacketizer) Packetize

func (p *SpeexPacketizer) Packetize(frame *avframe.AVFrame, mtu int) ([]*pionrtp.Packet, error)

Packetize wraps a Speex AVFrame into a single RTP packet.

type VP8Depacketizer

type VP8Depacketizer struct {
	// contains filtered or unexported fields
}

VP8Depacketizer reassembles RTP packets into VP8 frames.

func (*VP8Depacketizer) Depacketize

func (d *VP8Depacketizer) Depacketize(pkt *pionrtp.Packet) (frame *avframe.AVFrame, err error)

Depacketize processes one RTP packet. It accumulates fragments and returns a completed AVFrame when the marker bit is set. Returns (nil, nil) for intermediate fragments.

type VP8Packetizer

type VP8Packetizer struct{}

VP8Packetizer packetizes VP8 frames into RTP packets. Uses a simplified 1-byte payload descriptor per RFC 7741.

func (*VP8Packetizer) Packetize

func (p *VP8Packetizer) Packetize(frame *avframe.AVFrame, mtu int) ([]*pionrtp.Packet, error)

Packetize splits a VP8 frame into one or more RTP packets. Each packet carries a 1-byte payload descriptor followed by frame data. If the frame fits within mtu bytes (including descriptor), a single packet is produced. Otherwise the frame is fragmented across multiple packets.

type VP9Depacketizer

type VP9Depacketizer struct {
	// contains filtered or unexported fields
}

VP9Depacketizer reassembles RTP packets into VP9 frames.

func (*VP9Depacketizer) Depacketize

func (d *VP9Depacketizer) Depacketize(pkt *pionrtp.Packet) (*avframe.AVFrame, error)

Depacketize processes one RTP packet. It accumulates fragments and returns a completed AVFrame when the E bit is set. Returns (nil, nil) for intermediate fragments.

type VP9Packetizer

type VP9Packetizer struct{}

VP9Packetizer packetizes VP9 frames into RTP packets. Uses a simplified 1-byte payload descriptor per draft-ietf-payload-vp9.

func (*VP9Packetizer) Packetize

func (p *VP9Packetizer) Packetize(frame *avframe.AVFrame, mtu int) ([]*pionrtp.Packet, error)

Packetize splits a VP9 frame into one or more RTP packets. Each packet carries a 1-byte payload descriptor followed by frame data. Descriptor bits: I=0, P=0, L=0, F=0, B=beginning, E=end, V=0, Z=0. B is bit 3 (0x08), E is bit 2 (0x04).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL