Documentation
¶
Index ¶
- type AudioSampleProvider
- type BaseSampleProvider
- type KeyFramer
- type Local
- func NewAudioTrack(trackInfo *sfu_models.TrackInfo, sampleProvider AudioSampleProvider, ...) (*Local, error)
- func NewLocalTrack(info *sfu_models.TrackInfo, c webrtc.RTPCodecCapability, opts ...Option) (*Local, error)
- func NewVideoTrack(trackInfo *sfu_models.TrackInfo, provider SampleProvider, ...) (*Local, error)
- func (s *Local) Bind(ctx webrtc.TrackLocalContext) (webrtc.RTPCodecParameters, error)
- func (s *Local) Close() error
- func (s *Local) Codec() webrtc.RTPCodecCapability
- func (s *Local) ID() string
- func (s *Local) IsBound() bool
- func (s *Local) Kind() webrtc.RTPCodecType
- func (s *Local) Muted() bool
- func (s *Local) OnBind(f func())
- func (s *Local) OnUnbind(f func())
- func (s *Local) RID() string
- func (s *Local) SSRC() webrtc.SSRC
- func (s *Local) SetMuted(muted bool)
- func (s *Local) SetTransceiver(transceiver *webrtc.RTPTransceiver)
- func (s *Local) StartWrite(provider SampleProvider, onComplete func()) error
- func (s *Local) StreamID() string
- func (s *Local) Track() *webrtc.TrackLocalStaticRTP
- func (s *Local) TrackInfo() *sfu_models.TrackInfo
- func (s *Local) Transceiver() *webrtc.RTPTransceiver
- func (s *Local) Unbind(ctx webrtc.TrackLocalContext) error
- func (s *Local) VideoLayer() *sfu_models.VideoLayer
- func (s *Local) WriteRTP(p *rtp.Packet, opts *SampleWriteOptions) error
- func (s *Local) WriteSample(sample media.Sample, opts *SampleWriteOptions) error
- type NullSampleProvider
- type Option
- type SampleProvider
- type SampleWriteOptions
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) 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 ¶
func (s *Local) Bind(ctx webrtc.TrackLocalContext) (webrtc.RTPCodecParameters, error)
Bind is part of webrtc.TrackLocal and is called by pion on negotiation.
func (*Local) Codec ¶
func (s *Local) Codec() webrtc.RTPCodecCapability
Codec is the codec the track offers.
func (*Local) Kind ¶
func (s *Local) Kind() webrtc.RTPCodecType
Kind is audio or video, from the codec.
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) SetMuted ¶
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) 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 ¶
NextSample returns a zeroed sample.
type Option ¶
type Option func(s *options)
Option configures a Local track.
func WithLogger ¶
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 ¶
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.