packetizer

package
v0.0.0-...-392cdac Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 7 Imported by: ? modules, 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

Overview

Package packetizer provides RTP packetization for encoded media.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPacketizerClosed = errors.New("packetizer is closed")
	ErrBufferTooSmall   = errors.New("buffer too small")
	ErrInvalidData      = errors.New("invalid data")
)

Errors

Functions

This section is empty.

Types

type Config

type Config struct {
	Codec       codec.Type // Codec selects the RTP payloader and timestamp behavior.
	SSRC        uint32     // SSRC is the synchronization source written into output packets.
	PayloadType uint8      // PayloadType is the negotiated RTP payload type to emit.
	MTU         uint16     // Maximum transmission unit (typically 1200)
	ClockRate   uint32     // RTP clock rate (90000 for video, 48000 for Opus)
}

Config configures an RTP packetizer.

type PacketInfo

type PacketInfo struct {
	Offset int // Offset into the buffer where this packet starts
	Size   int // Size of this packet
}

PacketInfo describes a single RTP packet in the output buffer.

type Packetizer

type Packetizer interface {
	// PacketizeInto packetizes encoded data into RTP packets.
	// dst is a pre-allocated buffer to hold all packets contiguously.
	// packets is a pre-allocated slice to receive packet info (offset/size).
	// Returns the number of packets written.
	PacketizeInto(data []byte, timestamp uint32, isKeyframe bool, dst []byte, packets []PacketInfo) (int, error)

	// MaxPackets returns the maximum number of packets that could be generated
	// for a frame of the given size.
	MaxPackets(frameSize int) int

	// MaxPacketSize returns the maximum size of a single RTP packet.
	MaxPacketSize() int

	// SequenceNumber returns the next sequence number that will be used.
	SequenceNumber() uint16

	// Close releases resources.
	Close() error
}

Packetizer converts encoded frames into RTP packets. All operations are allocation-free from the caller's perspective - caller provides the output buffer and packet metadata slices.

func New

func New(cfg Config) (Packetizer, error)

New creates a new RTP packetizer.

Jump to

Keyboard shortcuts

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