track

package
v0.0.0-...-f8853a5 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AudioSampleProvider

type AudioSampleProvider interface {
	SampleProvider
	// CurrentAudioLevel is the level in -dBov, 0 loudest and 127 silent.
	CurrentAudioLevel() uint8
}

AudioSampleProvider is an audio provider that reports the level of what it last produced, written to the audio-level header extension when negotiated.

type BaseSampleProvider

type BaseSampleProvider struct{}

BaseSampleProvider gives a provider no-op OnBind, OnUnbind and Close.

func (*BaseSampleProvider) Close

func (p *BaseSampleProvider) Close() error

Close does nothing.

func (*BaseSampleProvider) OnBind

func (p *BaseSampleProvider) OnBind() error

OnBind does nothing.

func (*BaseSampleProvider) OnUnbind

func (p *BaseSampleProvider) OnUnbind() error

OnUnbind does nothing.

type KeyFramer

type KeyFramer interface {
	ForceKeyFrame() error
}

KeyFramer is implemented by video providers that can produce a key frame on demand. The default RTCP handler calls it on PLI and FIR.

type Local

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

Local is a track published to the SFU. Given a SampleProvider it paces, packetizes and timestamps the samples itself, and it stamps the header extensions the SFU needs.

func NewAudioTrack

func NewAudioTrack(trackInfo *sfu_models.TrackInfo, sampleProvider AudioSampleProvider, codec webrtc.RTPCodecCapability, opts ...Option) (*Local, error)

NewAudioTrack creates an audio track, named after trackInfo, that starts writing from sampleProvider once it is bound.

func NewLocalTrack

func NewLocalTrack(info *sfu_models.TrackInfo, c webrtc.RTPCodecCapability, opts ...Option) (*Local, error)

NewLocalTrack creates a track for the codec. Audio tracks get their own copy of info, with Red set to match WithRedTranscodingEnabledForAudio.

func NewVideoTrack

func NewVideoTrack(trackInfo *sfu_models.TrackInfo, provider SampleProvider, codec webrtc.RTPCodecCapability, opts ...Option) (*Local, error)

NewVideoTrack creates a video track, named after trackInfo, that starts writing from provider once it is bound. A provider that implements KeyFramer gets key frame requests from the SFU.

func (*Local) Bind

Bind is part of webrtc.TrackLocal and is called by pion on negotiation.

func (*Local) Close

func (s *Local) Close() error

Close stops the write loop and closes the provider.

func (*Local) Codec

func (s *Local) Codec() webrtc.RTPCodecCapability

Codec is the codec the track offers.

func (*Local) ID

func (s *Local) ID() string

ID is the track ID.

func (*Local) IsBound

func (s *Local) IsBound() bool

IsBound reports whether the track is negotiated on a peer connection.

func (*Local) Kind

func (s *Local) Kind() webrtc.RTPCodecType

Kind is audio or video, from the codec.

func (*Local) Muted

func (s *Local) Muted() bool

Muted reports whether this track is currently dropping its samples.

func (*Local) OnBind

func (s *Local) OnBind(f func())

OnBind sets a callback run after the track is bound.

func (*Local) OnUnbind

func (s *Local) OnUnbind(f func())

OnUnbind sets a callback run after the track is unbound.

func (*Local) RID

func (s *Local) RID() string

RID is the RTP stream ID, empty unless the track is a simulcast layer.

func (*Local) SSRC

func (s *Local) SSRC() webrtc.SSRC

SSRC is the negotiated SSRC, or 0 while unbound.

func (*Local) SetMuted

func (s *Local) SetMuted(muted bool)

SetMuted stops or resumes putting this track's samples on the wire.

The sample provider keeps running and its samples are discarded, rather than the write loop being stopped, so the track resumes in place with no renegotiation. That is what makes this the right primitive for switching a simulcast layer off when the SFU asks for less bandwidth.

func (*Local) SetTransceiver

func (s *Local) SetTransceiver(transceiver *webrtc.RTPTransceiver)

SetTransceiver records the transceiver the track is sent on; its mid is stamped on simulcast packets.

func (*Local) StartWrite

func (s *Local) StartWrite(provider SampleProvider, onComplete func()) error

StartWrite makes provider the source of the track. It starts writing once the track is bound, or straight away if it already is, replacing the current provider. onComplete runs when the write loop ends.

func (*Local) StreamID

func (s *Local) StreamID() string

StreamID is the stream ID, derived from the track ID.

func (*Local) Track

func (s *Local) Track() *webrtc.TrackLocalStaticRTP

Track returns the underlying pion track.

func (*Local) TrackInfo

func (s *Local) TrackInfo() *sfu_models.TrackInfo

TrackInfo returns what the SFU is told about the track.

func (*Local) Transceiver

func (s *Local) Transceiver() *webrtc.RTPTransceiver

Transceiver returns the transceiver set by SetTransceiver.

func (*Local) Unbind

func (s *Local) Unbind(ctx webrtc.TrackLocalContext) error

Unbind is part of webrtc.TrackLocal and is called by pion when the track leaves its peer connection.

func (*Local) VideoLayer

func (s *Local) VideoLayer() *sfu_models.VideoLayer

VideoLayer returns the simulcast layer, or nil.

func (*Local) WriteRTP

func (s *Local) WriteRTP(p *rtp.Packet, opts *SampleWriteOptions) error

WriteRTP stamps the negotiated header extensions on p and writes it.

func (*Local) WriteSample

func (s *Local) WriteSample(sample media.Sample, opts *SampleWriteOptions) error

WriteSample packetizes a sample and writes it. It is dropped while the track is unbound.

The sample's RTP time comes from PacketTimestamp if set, else from the wall clock Timestamp, else from Duration. It never lands closer to the previous sample than that sample's length, and PrevDroppedPackets leaves a gap of that many sequence numbers.

type NullSampleProvider

type NullSampleProvider struct {
	BaseSampleProvider
	BytesPerSample uint32
	SampleDuration time.Duration
}

NullSampleProvider produces zeroed samples sized to meet a bitrate.

func NewNullSampleProvider

func NewNullSampleProvider(bitrate uint32) *NullSampleProvider

NewNullSampleProvider returns a provider that sends bitrate bits a second.

func (*NullSampleProvider) NextSample

func (p *NullSampleProvider) NextSample(context.Context) (media.Sample, error)

NextSample returns a zeroed sample.

type Option

type Option func(s *options)

Option configures a Local track.

func WithLogger

func WithLogger(l logger.ILogger) Option

WithLogger sets the logger for write and RTCP failures.

func WithRTCPHandler

func WithRTCPHandler(cb func(SampleProvider, rtcp.Packet) error) Option

WithRTCPHandler replaces the default RTCP handler, which asks a KeyFramer provider for a key frame on PLI and FIR.

func WithRedTranscodingEnabledForAudio

func WithRedTranscodingEnabledForAudio() Option

WithRedTranscodingEnabledForAudio sends opus audio wrapped in RED (RFC 2198), so each packet also carries the frames before it.

func WithSimulcast

func WithSimulcast(layer *sfu_models.VideoLayer) Option

WithSimulcast publishes the track as one simulcast layer. All layers of a track must share the same track ID.

func WithTrackID

func WithTrackID(trackID string) Option

WithTrackID sets the track ID; the stream ID is derived from it.

type SampleProvider

type SampleProvider interface {
	// NextSample blocks until the next sample is ready. io.EOF ends the track
	// cleanly; it must return promptly once ctx is done.
	NextSample(ctx context.Context) (media.Sample, error)
	// OnBind is called when the track is negotiated and about to be written.
	OnBind() error
	// OnUnbind is called when the track leaves its peer connection.
	OnUnbind() error
	// Close is called once, when the track is closed.
	Close() error
}

SampleProvider feeds a Local track. The track calls NextSample from a single goroutine and paces the calls by each sample's Duration.

type SampleWriteOptions

type SampleWriteOptions struct {
	AudioLevel *uint8
}

SampleWriteOptions carries per-sample header extension values.

Jump to

Keyboard shortcuts

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