samplebuilder

package module
v0.0.0-...-76c654a Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: MIT Imports: 3 Imported by: 1

README

This is a drop-in replacement for Pion's samplebuilder that is faster and
has slightly different behaviour.  It is used by Galene <https://galene.org>.

Differences from Pion:

  * the `Pop` family make slightly different decisions about when to
    release a packet that is blocked by an incomplete packet, with the
    goal to minimise latency in the lossless case while avoiding spurious
    packet drops (it's a tricky decision, and Pion itself behaves
    differently depending on the exact version);

  * the `ForcePopWithTimestamp` function can be used to flush any
    packets remaining at the end of the stream;

  * we're about 30% faster.

Documentation

Overview

Package samplebuilder builds media frames from RTP packets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(o *SampleBuilder)

An Option configures a SampleBuilder

func WithPacketReleaseHandler

func WithPacketReleaseHandler(h func(*rtp.Packet)) Option

WithPacketReleaseHandler sets a callback that is called when the builder is about to release some packet.

type SampleBuilder

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

SampleBuilder buffers packets and produces media frames

func New

func New(maxLate uint16, depacketizer rtp.Depacketizer, sampleRate uint32, opts ...Option) *SampleBuilder

New constructs a new SampleBuilder.

maxLate is the maximum delay, in RTP sequence numbers, that the samplebuilder will wait before dropping a frame. The actual buffer size is twice as large in order to compensate for delays between Push and Pop.

func (*SampleBuilder) ForcePopWithTimestamp

func (s *SampleBuilder) ForcePopWithTimestamp() (*media.Sample, uint32)

ForcePopWithTimestamp is like PopWithTimestamp, but will always pops a sample if any are available, even if it's being blocked by a missing packet. This is useful when the stream ends, or after a link outage. After ForcePopWithTimestamp returns nil, the samplebuilder is guaranteed to be empty.

func (*SampleBuilder) Len

func (s *SampleBuilder) Len() int

Len returns the difference minus one between the smallest and the largest sequence number stored in the SampleBuilder.

func (*SampleBuilder) Pop

func (s *SampleBuilder) Pop() *media.Sample

Pop returns a completed packet. If the oldest packet is incomplete and hasn't reached MaxLate yet, Pop returns nil.

func (*SampleBuilder) PopWithTimestamp

func (s *SampleBuilder) PopWithTimestamp() (*media.Sample, uint32)

PopWithTimestamp returns a completed packet and its RTP timestamp. If the oldest packet is incomplete and hasn't reached MaxLate yet, Pop returns nil.

func (*SampleBuilder) Push

func (s *SampleBuilder) Push(p *rtp.Packet)

Push adds an RTP Packet to s's buffer.

Push does not copy the input: the packet will be retained by s. If you plan to reuse the packet or its buffer, make sure to perform a copy.

Jump to

Keyboard shortcuts

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