samplebuilder

package
v2.1.12 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package samplebuilder builds media frames from RTP packets. it re-orders incoming packets to be in order, and notifies callback when packets are dropped

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 WithPacketDroppedHandler

func WithPacketDroppedHandler(h func()) Option

WithPacketDroppedHandler sets a callback that's called when a packet is dropped. This signifies packet loss.

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) ForcePopPackets

func (s *SampleBuilder) ForcePopPackets() []*rtp.Packet

ForcePopPackets returns rtp packets of all remaining completed packets (frames of audio/video). Any incomplete packets are dropped. After ForcePopPackets returns, the SampleBuilder is guaranteed to be empty.

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) 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) PopPackets

func (s *SampleBuilder) PopPackets() []*rtp.Packet

PopPackets returns rtp packets of a completed packet (a frame of audio/video). If the oldest packet is incomplete and hasn't reached MaxLate yet, PopPackets returns nil. rtp packets returned is not called release handle by SampleBuilder, so caller is responsible for release these packets if required.

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