Documentation
¶
Index ¶
- Constants
- func AnnexBToAVCC(data []byte) []byte
- func BuildAVCDecoderConfig(annexB []byte) []byte
- func BuildBYE(ssrc uint32) []byte
- func BuildRR(ssrc uint32, reports []ReceptionReport) []byte
- func BuildSR(ssrc uint32, ntpTime uint64, rtpTime, packetCount, octetCount uint32) []byte
- func DepacketizeFrames(depacketizer Depacketizer, pkt *pionrtp.Packet) ([]*avframe.AVFrame, error)
- func ExtractSPSPPS(config []byte) (sps, pps []byte)
- func ToAnnexB(data []byte, isSequenceHeader bool) []byte
- func VideoToAnnexB(codec avframe.CodecType, data []byte, isSequenceHeader bool) []byte
- type AACDepacketizer
- type AACPacketizer
- type AV1Depacketizer
- type AV1Packetizer
- type AccessUnitAssembler
- type Depacketizer
- type G711Depacketizer
- type G711Packetizer
- type G722Depacketizer
- type G722Packetizer
- type G729Depacketizer
- type G729Packetizer
- type H264Depacketizer
- type H264Packetizer
- type H265Depacketizer
- type H265Packetizer
- type MP3Depacketizer
- type MP3Packetizer
- type MultiFrameDepacketizer
- type OpusDepacketizer
- type OpusPacketizer
- type Packetizer
- type ReceiverReport
- type ReceptionReport
- type SenderReport
- type Session
- type SpeexDepacketizer
- type SpeexPacketizer
- type VP8Depacketizer
- type VP8Packetizer
- type VP9Depacketizer
- type VP9Packetizer
Constants ¶
const ( // MaxAccessUnitBytes includes AVCC length prefixes for H.264/H.265. MaxAccessUnitBytes = (16 << 20) + 4 MaxAccessUnitPackets = 16384 )
const ( RTCPTypeSR = 200 RTCPTypeRR = 201 RTCPTypeBYE = 203 )
RTCP packet type constants (RFC 3550).
const DefaultMTU = 1400
DefaultMTU is the default Maximum Transmission Unit for RTP packets.
Variables ¶
This section is empty.
Functions ¶
func AnnexBToAVCC ¶
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 ¶
BuildAVCDecoderConfig builds an AVCDecoderConfigurationRecord from Annex-B data containing SPS and PPS NAL units. Returns nil if SPS or PPS not found.
func BuildBYE ¶
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 DepacketizeFrames ¶
DepacketizeFrames returns every frame represented by a packet while keeping single-frame depacketizers compatible with the original interface.
func ExtractSPSPPS ¶
ExtractSPSPPS extracts raw SPS and PPS NAL bytes from an AVCDecoderConfigurationRecord.
func ToAnnexB ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
type Depacketizer ¶
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 ¶
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.
type G722Depacketizer ¶
type G722Depacketizer struct{}
G722Depacketizer reassembles RTP packets into G.722 AVFrames.
func (*G722Depacketizer) Depacketize ¶
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.
type G729Depacketizer ¶
type G729Depacketizer struct{}
G729Depacketizer reassembles RTP packets into G.729 AVFrames.
func (*G729Depacketizer) Depacketize ¶
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.
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 ¶
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 ¶
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.
type H265Depacketizer ¶
type H265Depacketizer struct {
// contains filtered or unexported fields
}
H265Depacketizer reassembles RTP packets into H.265 NAL units.
func (*H265Depacketizer) Depacketize ¶
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.
type MP3Depacketizer ¶
type MP3Depacketizer struct{}
MP3Depacketizer reassembles RTP packets into MP3 AVFrames.
func (*MP3Depacketizer) Depacketize ¶
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.
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 ¶
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.
type Packetizer ¶
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 ¶
NewSession creates a new RTP session with a random SSRC.
type SpeexDepacketizer ¶
type SpeexDepacketizer struct{}
SpeexDepacketizer reassembles RTP packets into Speex AVFrames.
func (*SpeexDepacketizer) Depacketize ¶
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.
type VP8Depacketizer ¶
type VP8Depacketizer struct {
// contains filtered or unexported fields
}
VP8Depacketizer reassembles RTP packets into VP8 frames.
func (*VP8Depacketizer) Depacketize ¶
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 ¶
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 ¶
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.