sfu

package
v0.0.0-...-6941808 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RTPPaddingMaxPayloadSize      = 255
	RTPPaddingEstimatedHeaderSize = 20
	RTPBlankFramesMuteSeconds     = float32(1.0)
	RTPBlankFramesCloseSeconds    = float32(0.2)

	FlagStopRTXOnPLI = true
)
View Source
const (
	FlagPauseOnDowngrade  = true
	FlagFilterRTX         = false
	FlagFilterRTXLayers   = true
	TransitionCostSpatial = 10

	ResumeBehindThresholdSeconds      = float64(0.2)   // 200ms
	ResumeBehindHighThresholdSeconds  = float64(2.0)   // 2 seconds
	LayerSwitchBehindThresholdSeconds = float64(0.05)  // 50ms
	SwitchAheadThresholdSeconds       = float64(0.025) // 25ms
)

Forwarder

View Source
const (
	MimeTypeAudioRed = "audio/red"
)
View Source
const (
	RtxGateWindow = 2000
)

Variables

View Source
var (
	ErrUnknownKind                       = errors.New("unknown kind of codec")
	ErrOutOfOrderSequenceNumberCacheMiss = errors.New("out-of-order sequence number not found in cache")
	ErrPaddingOnlyPacket                 = errors.New("padding only packet that need not be forwarded")
	ErrDuplicatePacket                   = errors.New("duplicate packet")
	ErrPaddingNotOnFrameBoundary         = errors.New("padding cannot send on non-frame boundary")
	ErrDownTrackAlreadyBound             = errors.New("already bound")
	ErrPayloadOverflow                   = errors.New("payload overflow")
)
View Source
var (
	VP8KeyFrame8x8 = []byte{
		0x10, 0x02, 0x00, 0x9d, 0x01, 0x2a, 0x08, 0x00,
		0x08, 0x00, 0x00, 0x47, 0x08, 0x85, 0x85, 0x88,
		0x85, 0x84, 0x88, 0x02, 0x02, 0x00, 0x0c, 0x0d,
		0x60, 0x00, 0xfe, 0xff, 0xab, 0x50, 0x80,
	}

	H264KeyFrame2x2SPS = []byte{
		0x67, 0x42, 0xc0, 0x1f, 0x0f, 0xd9, 0x1f, 0x88,
		0x88, 0x84, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00,
		0x00, 0x03, 0x00, 0xc8, 0x3c, 0x60, 0xc9, 0x20,
	}
	H264KeyFrame2x2PPS = []byte{
		0x68, 0x87, 0xcb, 0x83, 0xcb, 0x20,
	}
	H264KeyFrame2x2IDR = []byte{
		0x65, 0x88, 0x84, 0x0a, 0xf2, 0x62, 0x80, 0x00,
		0xa7, 0xbe,
	}
	H264KeyFrame2x2 = [][]byte{H264KeyFrame2x2SPS, H264KeyFrame2x2PPS, H264KeyFrame2x2IDR}

	OpusSilenceFrame = []byte{
		0xf8, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	}
)
View Source
var (
	ErrReceiverClosed        = errors.New("receiver closed")
	ErrDownTrackAlreadyExist = errors.New("DownTrack already exist")
	ErrBufferNotFound        = errors.New("buffer not found")
	ErrDuplicateLayer        = errors.New("duplicate layer")
)
View Source
var (
	ErrIncompleteRedHeader = errors.New("incomplete red block header")
	ErrIncompleteRedBlock  = errors.New("incomplete red block payload")
)
View Source
var (
	PacketFactory *sync.Pool
)
View Source
var (
	VideoAllocationDefault = VideoAllocation{
		PauseReason:         VideoPauseReasonFeedDry,
		TargetLayer:         buffer.InvalidLayer,
		RequestLayerSpatial: buffer.InvalidLayerSpatial,
		MaxLayer:            buffer.InvalidLayer,
	}
)

Functions

This section is empty.

Types

type AudioLevelHandle

type AudioLevelHandle func(level uint8, duration uint32)

type DownTrack

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

DownTrack implements TrackLocal, is the track used to write packets to SFU Subscriber, the track handle the packets for simple, simulcast and SVC Publisher. A DownTrack has the following lifecycle - new - bound / unbound - closed once closed, a DownTrack cannot be re-used.

func NewDownTrack

func NewDownTrack(params DowntrackParams) (*DownTrack, error)

NewDownTrack returns a DownTrack.

func (*DownTrack) AddReceiverReportListener

func (d *DownTrack) AddReceiverReportListener(listener ReceiverReportListener)

func (*DownTrack) AllocateNextHigher

func (d *DownTrack) AllocateNextHigher(availableChannelCapacity int64, allowOvershoot bool) (VideoAllocation, bool)

func (*DownTrack) AllocateOptimal

func (d *DownTrack) AllocateOptimal(allowOvershoot bool) VideoAllocation

func (*DownTrack) BandwidthRequested

func (d *DownTrack) BandwidthRequested() int64

func (*DownTrack) Bind

func (d *DownTrack) Bind(t webrtc.TrackLocalContext) (webrtc.RTPCodecParameters, error)

Bind is called by the PeerConnection after negotiation is complete This asserts that the code requested is supported by the remote peer. If so it sets up all the state (SSRC and PayloadType) to have a call

func (*DownTrack) ClearStreamAllocatorReportInterval

func (d *DownTrack) ClearStreamAllocatorReportInterval()

func (*DownTrack) Close

func (d *DownTrack) Close()

func (*DownTrack) CloseWithFlush

func (d *DownTrack) CloseWithFlush(flush bool)

CloseWithFlush - flush used to indicate whether send blank frame to flush decoder of client.

  1. When transceiver is reused by other participant's video track, set flush=true to avoid previous video shows before new stream is displayed.
  2. in case of session migration, participant migrate from other node, video track should be resumed with same participant, set flush=false since we don't need to flush decoder.

func (*DownTrack) Codec

func (d *DownTrack) Codec() webrtc.RTPCodecCapability

Codec returns current track codec capability

func (*DownTrack) CreateSenderReport

func (d *DownTrack) CreateSenderReport() *rtcp.SenderReport

func (*DownTrack) CreateSourceDescriptionChunks

func (d *DownTrack) CreateSourceDescriptionChunks() []rtcp.SourceDescriptionChunk

func (*DownTrack) DebugInfo

func (d *DownTrack) DebugInfo() map[string]interface{}

func (*DownTrack) DistanceToDesired

func (d *DownTrack) DistanceToDesired() float64

func (*DownTrack) GetConnectionScoreAndQuality

func (d *DownTrack) GetConnectionScoreAndQuality() (float32, livekit.ConnectionQuality)

func (*DownTrack) GetDeltaStatsSender

func (d *DownTrack) GetDeltaStatsSender() map[uint32]*buffer.StreamStatsWithLayers

func (*DownTrack) GetLastReceiverReportTime

func (d *DownTrack) GetLastReceiverReportTime() time.Time

func (*DownTrack) GetNackStats

func (d *DownTrack) GetNackStats() (totalPackets uint32, totalRepeatedNACKs uint32)

func (*DownTrack) GetNextHigherTransition

func (d *DownTrack) GetNextHigherTransition(allowOvershoot bool) (VideoTransition, bool)

func (*DownTrack) GetState

func (d *DownTrack) GetState() DownTrackState

func (*DownTrack) GetTotalPacketsSent

func (d *DownTrack) GetTotalPacketsSent() uint64

func (*DownTrack) GetTrackStats

func (d *DownTrack) GetTrackStats() *livekit.RTPStats

func (*DownTrack) GetTransceiver

func (d *DownTrack) GetTransceiver() *webrtc.RTPTransceiver

func (*DownTrack) HandleRTCPSenderReportData

func (d *DownTrack) HandleRTCPSenderReportData(
	_payloadType webrtc.PayloadType,
	isSVC bool,
	layer int32,
	publisherSRData *livekit.RTCPSenderReportState,
) error

func (*DownTrack) ID

func (d *DownTrack) ID() string

ID is the unique identifier for this Track. This should be unique for the stream, but doesn't have to globally unique. A common example would be 'audio' or 'video' and StreamID would be 'desktop' or 'webcam'

func (*DownTrack) IsClosed

func (d *DownTrack) IsClosed() bool

func (*DownTrack) IsDeficient

func (d *DownTrack) IsDeficient() bool

func (*DownTrack) Kind

func (d *DownTrack) Kind() webrtc.RTPCodecType

Kind controls if this TrackLocal is audio or video

func (*DownTrack) MaxLayer

func (d *DownTrack) MaxLayer() buffer.VideoLayer

func (*DownTrack) Mute

func (d *DownTrack) Mute(muted bool)

Mute enables or disables media forwarding - subscriber triggered

func (*DownTrack) OnBinding

func (d *DownTrack) OnBinding(fn func(error))

func (*DownTrack) OnCloseHandler

func (d *DownTrack) OnCloseHandler(fn func(isExpectedToResume bool))

OnCloseHandler method to be called on remote tracked removed

func (*DownTrack) OnCodecNegotiated

func (d *DownTrack) OnCodecNegotiated(f func(webrtc.RTPCodecCapability))

func (*DownTrack) OnMaxLayerChanged

func (d *DownTrack) OnMaxLayerChanged(fn func(dt *DownTrack, layer int32))

func (*DownTrack) OnRttUpdate

func (d *DownTrack) OnRttUpdate(fn func(dt *DownTrack, rtt uint32))

func (*DownTrack) OnStatsUpdate

func (d *DownTrack) OnStatsUpdate(fn func(dt *DownTrack, stat *livekit.AnalyticsStat))

func (*DownTrack) Pause

func (d *DownTrack) Pause() VideoAllocation

func (*DownTrack) ProvisionalAllocate

func (d *DownTrack) ProvisionalAllocate(availableChannelCapacity int64, layers buffer.VideoLayer, allowPause bool, allowOvershoot bool) (bool, int64)

func (*DownTrack) ProvisionalAllocateCommit

func (d *DownTrack) ProvisionalAllocateCommit() VideoAllocation

func (*DownTrack) ProvisionalAllocateGetBestWeightedTransition

func (d *DownTrack) ProvisionalAllocateGetBestWeightedTransition() VideoTransition

func (*DownTrack) ProvisionalAllocateGetCooperativeTransition

func (d *DownTrack) ProvisionalAllocateGetCooperativeTransition(allowOvershoot bool) VideoTransition

func (*DownTrack) ProvisionalAllocatePrepare

func (d *DownTrack) ProvisionalAllocatePrepare()

func (*DownTrack) ProvisionalAllocateReset

func (d *DownTrack) ProvisionalAllocateReset()

func (*DownTrack) PubMute

func (d *DownTrack) PubMute(pubMuted bool)

PubMute enables or disables media forwarding - publisher side

func (*DownTrack) RID

func (d *DownTrack) RID() string

RID is required by `webrtc.TrackLocal` interface

func (*DownTrack) Resync

func (d *DownTrack) Resync()

func (*DownTrack) SSRC

func (d *DownTrack) SSRC() uint32

func (*DownTrack) SeedState

func (d *DownTrack) SeedState(state DownTrackState)

func (*DownTrack) SetActivePaddingOnMuteUpTrack

func (d *DownTrack) SetActivePaddingOnMuteUpTrack()

SetActivePaddingOnMuteUpTrack will enable padding on the track when its uptrack is muted. Pion will not fire OnTrack event until it receives packet for the track, so we send padding packets to help pion client (go-sdk) to fire the event.

func (*DownTrack) SetConnected

func (d *DownTrack) SetConnected()

func (*DownTrack) SetMaxSpatialLayer

func (d *DownTrack) SetMaxSpatialLayer(spatialLayer int32)

func (*DownTrack) SetMaxTemporalLayer

func (d *DownTrack) SetMaxTemporalLayer(temporalLayer int32)

func (*DownTrack) SetRTPHeaderExtensions

func (d *DownTrack) SetRTPHeaderExtensions(rtpHeaderExtensions []webrtc.RTPHeaderExtensionParameter)

Sets RTP header extensions for this track

func (*DownTrack) SetStreamAllocatorListener

func (d *DownTrack) SetStreamAllocatorListener(listener DownTrackStreamAllocatorListener)

func (*DownTrack) SetStreamAllocatorReportInterval

func (d *DownTrack) SetStreamAllocatorReportInterval(interval time.Duration)

func (*DownTrack) SetTransceiver

func (d *DownTrack) SetTransceiver(transceiver *webrtc.RTPTransceiver)

func (*DownTrack) Stop

func (d *DownTrack) Stop() error

func (*DownTrack) StopWriteAndGetState

func (d *DownTrack) StopWriteAndGetState() DownTrackState

func (*DownTrack) StreamID

func (d *DownTrack) StreamID() string

StreamID is the group this track belongs too. This must be unique

func (*DownTrack) SubscriberID

func (d *DownTrack) SubscriberID() livekit.ParticipantID

func (*DownTrack) Unbind

func (d *DownTrack) Unbind(_ webrtc.TrackLocalContext) error

Unbind implements the teardown logic when the track is no longer needed. This happens because a track has been stopped.

func (*DownTrack) UpTrackBitrateAvailabilityChange

func (d *DownTrack) UpTrackBitrateAvailabilityChange()

func (*DownTrack) UpTrackBitrateReport

func (d *DownTrack) UpTrackBitrateReport(availableLayers []int32, bitrates Bitrates)

func (*DownTrack) UpTrackLayersChange

func (d *DownTrack) UpTrackLayersChange()

func (*DownTrack) UpTrackMaxPublishedLayerChange

func (d *DownTrack) UpTrackMaxPublishedLayerChange(maxPublishedLayer int32)

func (*DownTrack) UpTrackMaxTemporalLayerSeenChange

func (d *DownTrack) UpTrackMaxTemporalLayerSeenChange(maxTemporalLayerSeen int32)

func (*DownTrack) WritePaddingRTP

func (d *DownTrack) WritePaddingRTP(bytesToSend int, paddingOnMute bool, forceMarker bool) int

WritePaddingRTP tries to write as many padding only RTP packets as necessary to satisfy given size to the DownTrack

func (*DownTrack) WriteRTP

func (d *DownTrack) WriteRTP(extPkt *buffer.ExtPacket, layer int32) error

WriteRTP writes an RTP Packet to the DownTrack

type DownTrackSpreader

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

func NewDownTrackSpreader

func NewDownTrackSpreader(params DownTrackSpreaderParams) *DownTrackSpreader

func (*DownTrackSpreader) Broadcast

func (d *DownTrackSpreader) Broadcast(writer func(TrackSender)) int

func (*DownTrackSpreader) DownTrackCount

func (d *DownTrackSpreader) DownTrackCount() int

func (*DownTrackSpreader) Free

func (d *DownTrackSpreader) Free(subscriberID livekit.ParticipantID)

func (*DownTrackSpreader) GetDownTracks

func (d *DownTrackSpreader) GetDownTracks() []TrackSender

func (*DownTrackSpreader) HasDownTrack

func (d *DownTrackSpreader) HasDownTrack(subscriberID livekit.ParticipantID) bool

func (*DownTrackSpreader) ResetAndGetDownTracks

func (d *DownTrackSpreader) ResetAndGetDownTracks() []TrackSender

func (*DownTrackSpreader) Store

func (d *DownTrackSpreader) Store(ts TrackSender)

type DownTrackSpreaderParams

type DownTrackSpreaderParams struct {
	Threshold int
	Logger    logger.Logger
}

type DownTrackState

type DownTrackState struct {
	RTPStats                   *rtpstats.RTPStatsSender
	DeltaStatsSenderSnapshotId uint32
	ForwarderState             *livekit.RTPForwarderState
}

func (DownTrackState) MarshalLogObject

func (d DownTrackState) MarshalLogObject(e zapcore.ObjectEncoder) error

type DownTrackStreamAllocatorListener

type DownTrackStreamAllocatorListener interface {
	// RTCP received
	OnREMB(dt *DownTrack, remb *rtcp.ReceiverEstimatedMaximumBitrate)
	OnTransportCCFeedback(dt *DownTrack, cc *rtcp.TransportLayerCC)

	// video layer availability changed
	OnAvailableLayersChanged(dt *DownTrack)

	// video layer bitrate availability changed
	OnBitrateAvailabilityChanged(dt *DownTrack)

	// max published spatial layer changed
	OnMaxPublishedSpatialChanged(dt *DownTrack)

	// max published temporal layer changed
	OnMaxPublishedTemporalChanged(dt *DownTrack)

	// subscription changed - mute/unmute
	OnSubscriptionChanged(dt *DownTrack)

	// subscribed max video layer changed
	OnSubscribedLayerChanged(dt *DownTrack, layers buffer.VideoLayer)

	// stream resumed
	OnResume(dt *DownTrack)

	// packet(s) sent
	OnPacketsSent(dt *DownTrack, size int)

	// check if track should participate in BWE
	IsBWEEnabled(dt *DownTrack) bool

	// check if subscription mute can be applied
	IsSubscribeMutable(dt *DownTrack) bool
}

type DowntrackParams

type DowntrackParams struct {
	Codecs                         []webrtc.RTPCodecParameters
	Source                         livekit.TrackSource
	Receiver                       TrackReceiver
	BufferFactory                  *buffer.Factory
	SubID                          livekit.ParticipantID
	StreamID                       string
	MaxTrack                       int
	PlayoutDelayLimit              *livekit.PlayoutDelay
	Pacer                          pacer.Pacer
	Logger                         logger.Logger
	Trailer                        []byte
	RTCPWriter                     func([]rtcp.Packet) error
	DisableSenderReportPassThrough bool
}

type ForwardStats

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

func NewForwardStats

func NewForwardStats(latencyUpdateInterval, reportInterval, latencyWindowLength time.Duration) *ForwardStats

func (*ForwardStats) GetLastStats

func (s *ForwardStats) GetLastStats(duration time.Duration) (latency, jitter time.Duration)

func (*ForwardStats) GetStats

func (s *ForwardStats) GetStats() (latency, jitter time.Duration)

func (*ForwardStats) Stop

func (s *ForwardStats) Stop()

func (*ForwardStats) Update

func (s *ForwardStats) Update(arrival, left int64)

type Forwarder

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

func NewForwarder

func NewForwarder(
	kind webrtc.RTPCodecType,
	logger logger.Logger,
	skipReferenceTS bool,
	getExpectedRTPTimestamp func(at time.Time) (uint64, error),
) *Forwarder

func (*Forwarder) AllocateNextHigher

func (f *Forwarder) AllocateNextHigher(availableChannelCapacity int64, availableLayers []int32, brs Bitrates, allowOvershoot bool) (VideoAllocation, bool)

func (*Forwarder) AllocateOptimal

func (f *Forwarder) AllocateOptimal(availableLayers []int32, brs Bitrates, allowOvershoot bool) VideoAllocation

func (*Forwarder) BandwidthRequested

func (f *Forwarder) BandwidthRequested(brs Bitrates) int64

func (*Forwarder) CheckSync

func (f *Forwarder) CheckSync() (bool, int32)

func (*Forwarder) CurrentLayer

func (f *Forwarder) CurrentLayer() buffer.VideoLayer

func (*Forwarder) DetermineCodec

func (f *Forwarder) DetermineCodec(codec webrtc.RTPCodecCapability, extensions []webrtc.RTPHeaderExtensionParameter)

func (*Forwarder) DistanceToDesired

func (f *Forwarder) DistanceToDesired(availableLayers []int32, brs Bitrates) float64

func (*Forwarder) FilterRTX

func (f *Forwarder) FilterRTX(nacks []uint16) (filtered []uint16, disallowedLayers [buffer.DefaultMaxLayerSpatial + 1]bool)

func (*Forwarder) GetMaxSubscribedSpatial

func (f *Forwarder) GetMaxSubscribedSpatial() int32

func (*Forwarder) GetNextHigherTransition

func (f *Forwarder) GetNextHigherTransition(brs Bitrates, allowOvershoot bool) (VideoTransition, bool)

func (*Forwarder) GetOptimalBandwidthNeeded

func (f *Forwarder) GetOptimalBandwidthNeeded(brs Bitrates) int64

func (*Forwarder) GetPadding

func (f *Forwarder) GetPadding(frameEndNeeded bool) ([]byte, error)

func (*Forwarder) GetSenderReportParams

func (f *Forwarder) GetSenderReportParams() (int32, uint64, *livekit.RTCPSenderReportState)

func (*Forwarder) GetSnTsForBlankFrames

func (f *Forwarder) GetSnTsForBlankFrames(frameRate uint32, numPackets int) ([]SnTs, bool, error)

func (*Forwarder) GetSnTsForPadding

func (f *Forwarder) GetSnTsForPadding(num int, forceMarker bool) ([]SnTs, error)

func (*Forwarder) GetState

func (f *Forwarder) GetState() *livekit.RTPForwarderState

func (*Forwarder) GetTranslationParams

func (f *Forwarder) GetTranslationParams(extPkt *buffer.ExtPacket, layer int32) (TranslationParams, error)

func (*Forwarder) IsAnyMuted

func (f *Forwarder) IsAnyMuted() bool

func (*Forwarder) IsDeficient

func (f *Forwarder) IsDeficient() bool

func (*Forwarder) IsMuted

func (f *Forwarder) IsMuted() bool

func (*Forwarder) IsPubMuted

func (f *Forwarder) IsPubMuted() bool

func (*Forwarder) MaxLayer

func (f *Forwarder) MaxLayer() buffer.VideoLayer

func (*Forwarder) Mute

func (f *Forwarder) Mute(muted bool, isSubscribeMutable bool) bool

func (*Forwarder) Pause

func (f *Forwarder) Pause(availableLayers []int32, brs Bitrates) VideoAllocation

func (*Forwarder) PauseReason

func (f *Forwarder) PauseReason() VideoPauseReason

func (*Forwarder) ProvisionalAllocate

func (f *Forwarder) ProvisionalAllocate(availableChannelCapacity int64, layer buffer.VideoLayer, allowPause bool, allowOvershoot bool) (bool, int64)

func (*Forwarder) ProvisionalAllocateCommit

func (f *Forwarder) ProvisionalAllocateCommit() VideoAllocation

func (*Forwarder) ProvisionalAllocateGetBestWeightedTransition

func (f *Forwarder) ProvisionalAllocateGetBestWeightedTransition() (VideoTransition, []int32, Bitrates)

func (*Forwarder) ProvisionalAllocateGetCooperativeTransition

func (f *Forwarder) ProvisionalAllocateGetCooperativeTransition(allowOvershoot bool) (VideoTransition, []int32, Bitrates)

func (*Forwarder) ProvisionalAllocatePrepare

func (f *Forwarder) ProvisionalAllocatePrepare(availableLayers []int32, bitrates Bitrates)

func (*Forwarder) ProvisionalAllocateReset

func (f *Forwarder) ProvisionalAllocateReset()

func (*Forwarder) PubMute

func (f *Forwarder) PubMute(pubMuted bool) bool

func (*Forwarder) RTPMungerDebugInfo

func (f *Forwarder) RTPMungerDebugInfo() map[string]interface{}

func (*Forwarder) Resync

func (f *Forwarder) Resync()

func (*Forwarder) SeedState

func (f *Forwarder) SeedState(state *livekit.RTPForwarderState)

func (*Forwarder) SetMaxPublishedLayer

func (f *Forwarder) SetMaxPublishedLayer(maxPublishedLayer int32) bool

func (*Forwarder) SetMaxSpatialLayer

func (f *Forwarder) SetMaxSpatialLayer(spatialLayer int32) (bool, buffer.VideoLayer)

func (*Forwarder) SetMaxTemporalLayer

func (f *Forwarder) SetMaxTemporalLayer(temporalLayer int32) (bool, buffer.VideoLayer)

func (*Forwarder) SetMaxTemporalLayerSeen

func (f *Forwarder) SetMaxTemporalLayerSeen(maxTemporalLayerSeen int32) bool

func (*Forwarder) SetRefSenderReport

func (f *Forwarder) SetRefSenderReport(isSVC bool, layer int32, srData *livekit.RTCPSenderReportState)

func (*Forwarder) TargetLayer

func (f *Forwarder) TargetLayer() buffer.VideoLayer

type PlayoutDelayController

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

func NewPlayoutDelayController

func NewPlayoutDelayController(minDelay, maxDelay uint32, logger logger.Logger, rtpStats *rtpstats.RTPStatsSender) (*PlayoutDelayController, error)

func (*PlayoutDelayController) GetDelayExtension

func (c *PlayoutDelayController) GetDelayExtension(seq uint16) []byte

func (*PlayoutDelayController) OnSeqAcked

func (c *PlayoutDelayController) OnSeqAcked(seq uint16)

func (*PlayoutDelayController) SetJitter

func (c *PlayoutDelayController) SetJitter(jitter uint32)

type PlayoutDelayState

type PlayoutDelayState int32
const (
	PlayoutDelayStateChanged PlayoutDelayState = iota
	PlayoutDelaySending
	PlayoutDelayAcked
)

func (PlayoutDelayState) String

func (s PlayoutDelayState) String() string

type RTPMunger

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

func NewRTPMunger

func NewRTPMunger(logger logger.Logger) *RTPMunger

func (*RTPMunger) DebugInfo

func (r *RTPMunger) DebugInfo() map[string]interface{}

func (*RTPMunger) FilterRTX

func (r *RTPMunger) FilterRTX(nacks []uint16) []uint16

func (*RTPMunger) GetState

func (r *RTPMunger) GetState() *livekit.RTPMungerState

func (*RTPMunger) GetTSOffset

func (r *RTPMunger) GetTSOffset() uint64

func (*RTPMunger) IsOnFrameBoundary

func (r *RTPMunger) IsOnFrameBoundary() bool

func (*RTPMunger) PacketDropped

func (r *RTPMunger) PacketDropped(extPkt *buffer.ExtPacket)

func (*RTPMunger) SeedState

func (r *RTPMunger) SeedState(state *livekit.RTPMungerState)

func (*RTPMunger) SetLastSnTs

func (r *RTPMunger) SetLastSnTs(extPkt *buffer.ExtPacket)

func (*RTPMunger) UpdateAndGetPaddingSnTs

func (r *RTPMunger) UpdateAndGetPaddingSnTs(num int, clockRate uint32, frameRate uint32, forceMarker bool, extRtpTimestamp uint64) ([]SnTs, error)

func (*RTPMunger) UpdateAndGetSnTs

func (r *RTPMunger) UpdateAndGetSnTs(extPkt *buffer.ExtPacket, marker bool) (TranslationParamsRTP, error)

func (*RTPMunger) UpdateSnTsOffsets

func (r *RTPMunger) UpdateSnTsOffsets(extPkt *buffer.ExtPacket, snAdjust uint64, tsAdjust uint64)

type ReceiverOpts

type ReceiverOpts func(w *WebRTCReceiver) *WebRTCReceiver

func WithAudioConfig

func WithAudioConfig(audioConfig config.AudioConfig) ReceiverOpts

WithAudioConfig sets up parameters for active speaker detection

func WithForwardStats

func WithForwardStats(forwardStats *ForwardStats) ReceiverOpts

func WithLoadBalanceThreshold

func WithLoadBalanceThreshold(downTracks int) ReceiverOpts

WithLoadBalanceThreshold enables parallelization of packet writes when downTracks exceeds threshold Value should be between 3 and 150. For a server handling a few large rooms, use a smaller value (required to handle very large (250+ participant) rooms). For a server handling many small rooms, use a larger value or disable. Set to 0 (disabled) by default.

func WithPliThrottleConfig

func WithPliThrottleConfig(pliThrottleConfig config.PLIThrottleConfig) ReceiverOpts

WithPliThrottleConfig indicates minimum time(ms) between sending PLIs

func WithStreamTrackers

func WithStreamTrackers() ReceiverOpts

WithStreamTrackers enables StreamTracker use for simulcast

type ReceiverReportListener

type ReceiverReportListener func(dt *DownTrack, report *rtcp.ReceiverReport)

type RedPrimaryReceiver

type RedPrimaryReceiver struct {
	TrackReceiver
	// contains filtered or unexported fields
}

func NewRedPrimaryReceiver

func NewRedPrimaryReceiver(receiver TrackReceiver, dsp DownTrackSpreaderParams) *RedPrimaryReceiver

func (*RedPrimaryReceiver) AddDownTrack

func (r *RedPrimaryReceiver) AddDownTrack(track TrackSender) error

func (*RedPrimaryReceiver) CanClose

func (r *RedPrimaryReceiver) CanClose() bool

func (*RedPrimaryReceiver) Close

func (r *RedPrimaryReceiver) Close()

func (*RedPrimaryReceiver) DeleteDownTrack

func (r *RedPrimaryReceiver) DeleteDownTrack(subscriberID livekit.ParticipantID)

func (*RedPrimaryReceiver) ForwardRTP

func (r *RedPrimaryReceiver) ForwardRTP(pkt *buffer.ExtPacket, spatialLayer int32) int

func (*RedPrimaryReceiver) IsClosed

func (r *RedPrimaryReceiver) IsClosed() bool

func (*RedPrimaryReceiver) ReadRTP

func (r *RedPrimaryReceiver) ReadRTP(buf []byte, layer uint8, esn uint64) (int, error)

type RedReceiver

type RedReceiver struct {
	TrackReceiver
	// contains filtered or unexported fields
}

func NewRedReceiver

func NewRedReceiver(receiver TrackReceiver, dsp DownTrackSpreaderParams) *RedReceiver

func (*RedReceiver) AddDownTrack

func (r *RedReceiver) AddDownTrack(track TrackSender) error

func (*RedReceiver) CanClose

func (r *RedReceiver) CanClose() bool

func (*RedReceiver) Close

func (r *RedReceiver) Close()

func (*RedReceiver) DeleteDownTrack

func (r *RedReceiver) DeleteDownTrack(subscriberID livekit.ParticipantID)

func (*RedReceiver) ForwardRTP

func (r *RedReceiver) ForwardRTP(pkt *buffer.ExtPacket, spatialLayer int32) int

func (*RedReceiver) IsClosed

func (r *RedReceiver) IsClosed() bool

func (*RedReceiver) ReadRTP

func (r *RedReceiver) ReadRTP(buf []byte, layer uint8, esn uint64) (int, error)

type SequenceNumberOrdering

type SequenceNumberOrdering int

RTPMunger

const (
	SequenceNumberOrderingContiguous SequenceNumberOrdering = iota
	SequenceNumberOrderingOutOfOrder
	SequenceNumberOrderingGap
	SequenceNumberOrderingDuplicate
)

type SnTs

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

type StreamTrackerManager

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

func NewStreamTrackerManager

func NewStreamTrackerManager(
	logger logger.Logger,
	trackInfo *livekit.TrackInfo,
	isSVC bool,
	clockRate uint32,
	trackersConfig config.StreamTrackersConfig,
) *StreamTrackerManager

func (*StreamTrackerManager) AddDependencyDescriptorTrackers

func (s *StreamTrackerManager) AddDependencyDescriptorTrackers()

func (*StreamTrackerManager) AddTracker

func (*StreamTrackerManager) Close

func (s *StreamTrackerManager) Close()

func (*StreamTrackerManager) DistanceToDesired

func (s *StreamTrackerManager) DistanceToDesired() float64

func (*StreamTrackerManager) GetLayeredBitrate

func (s *StreamTrackerManager) GetLayeredBitrate() ([]int32, Bitrates)

func (*StreamTrackerManager) GetMaxPublishedLayer

func (s *StreamTrackerManager) GetMaxPublishedLayer() int32

func (*StreamTrackerManager) GetMaxTemporalLayerSeen

func (s *StreamTrackerManager) GetMaxTemporalLayerSeen() int32

func (*StreamTrackerManager) GetTracker

func (*StreamTrackerManager) IsPaused

func (s *StreamTrackerManager) IsPaused() bool

func (*StreamTrackerManager) RemoveAllTrackers

func (s *StreamTrackerManager) RemoveAllTrackers()

func (*StreamTrackerManager) RemoveTracker

func (s *StreamTrackerManager) RemoveTracker(layer int32)

func (*StreamTrackerManager) SetListener

func (s *StreamTrackerManager) SetListener(listener StreamTrackerManagerListener)

func (*StreamTrackerManager) SetMaxExpectedSpatialLayer

func (s *StreamTrackerManager) SetMaxExpectedSpatialLayer(layer int32) int32

func (*StreamTrackerManager) SetPaused

func (s *StreamTrackerManager) SetPaused(paused bool)

func (*StreamTrackerManager) UpdateTrackInfo

func (s *StreamTrackerManager) UpdateTrackInfo(ti *livekit.TrackInfo)

type StreamTrackerManagerListener

type StreamTrackerManagerListener interface {
	OnAvailableLayersChanged()
	OnBitrateAvailabilityChanged()
	OnMaxPublishedLayerChanged(maxPublishedLayer int32)
	OnMaxTemporalLayerSeenChanged(maxTemporalLayerSeen int32)
	OnMaxAvailableLayerChanged(maxAvailableLayer int32)
	OnBitrateReport(availableLayers []int32, bitrates Bitrates)
}

type TrackReceiver

type TrackReceiver interface {
	TrackID() livekit.TrackID
	StreamID() string
	Codec() webrtc.RTPCodecParameters
	HeaderExtensions() []webrtc.RTPHeaderExtensionParameter
	IsClosed() bool

	ReadRTP(buf []byte, layer uint8, esn uint64) (int, error)
	GetLayeredBitrate() ([]int32, Bitrates)

	GetAudioLevel() (float64, bool)

	SendPLI(layer int32, force bool)

	SetUpTrackPaused(paused bool)
	SetMaxExpectedSpatialLayer(layer int32)

	AddDownTrack(track TrackSender) error
	DeleteDownTrack(participantID livekit.ParticipantID)

	DebugInfo() map[string]interface{}

	TrackInfo() *livekit.TrackInfo
	UpdateTrackInfo(ti *livekit.TrackInfo)

	// Get primary receiver if this receiver represents a RED codec; otherwise it will return itself
	GetPrimaryReceiverForRed() TrackReceiver

	// Get red receiver for primary codec, used by forward red encodings for opus only codec
	GetRedReceiver() TrackReceiver

	GetTemporalLayerFpsForSpatial(layer int32) []float32

	GetTrackStats() *livekit.RTPStats

	// AddOnReady adds a function to be called when the receiver is ready, the callback
	// could be called immediately if the receiver is ready when the callback is added
	AddOnReady(func())
}

TrackReceiver defines an interface receive media from remote peer

type TrackSender

type TrackSender interface {
	UpTrackLayersChange()
	UpTrackBitrateAvailabilityChange()
	UpTrackMaxPublishedLayerChange(maxPublishedLayer int32)
	UpTrackMaxTemporalLayerSeenChange(maxTemporalLayerSeen int32)
	UpTrackBitrateReport(availableLayers []int32, bitrates Bitrates)
	WriteRTP(p *buffer.ExtPacket, layer int32) error
	Close()
	IsClosed() bool
	// ID is the globally unique identifier for this Track.
	ID() string
	SubscriberID() livekit.ParticipantID
	HandleRTCPSenderReportData(
		payloadType webrtc.PayloadType,
		isSVC bool,
		layer int32,
		publisherSRData *livekit.RTCPSenderReportState,
	) error
	Resync()
}

TrackSender defines an interface send media to remote peer

type TranslationParams

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

type TranslationParamsRTP

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

type VideoAllocation

type VideoAllocation struct {
	PauseReason         VideoPauseReason
	IsDeficient         bool
	BandwidthRequested  int64
	BandwidthDelta      int64
	BandwidthNeeded     int64
	Bitrates            Bitrates
	TargetLayer         buffer.VideoLayer
	RequestLayerSpatial int32
	MaxLayer            buffer.VideoLayer
	DistanceToDesired   float64
}

func (*VideoAllocation) MarshalLogObject

func (v *VideoAllocation) MarshalLogObject(e zapcore.ObjectEncoder) error

func (*VideoAllocation) String

func (v *VideoAllocation) String() string

type VideoAllocationProvisional

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

type VideoPauseReason

type VideoPauseReason int
const (
	VideoPauseReasonNone VideoPauseReason = iota
	VideoPauseReasonMuted
	VideoPauseReasonPubMuted
	VideoPauseReasonFeedDry
	VideoPauseReasonBandwidth
)

func (VideoPauseReason) String

func (v VideoPauseReason) String() string

type VideoTransition

type VideoTransition struct {
	From           buffer.VideoLayer
	To             buffer.VideoLayer
	BandwidthDelta int64
}

func (*VideoTransition) MarshalLogObject

func (v *VideoTransition) MarshalLogObject(e zapcore.ObjectEncoder) error

func (*VideoTransition) String

func (v *VideoTransition) String() string

type WebRTCReceiver

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

WebRTCReceiver receives a media track

func NewWebRTCReceiver

func NewWebRTCReceiver(
	receiver *webrtc.RTPReceiver,
	track *webrtc.TrackRemote,
	trackInfo *livekit.TrackInfo,
	logger logger.Logger,
	onRTCP func([]rtcp.Packet),
	trackersConfig config.StreamTrackersConfig,
	opts ...ReceiverOpts,
) *WebRTCReceiver

NewWebRTCReceiver creates a new webrtc track receiver

func (*WebRTCReceiver) AddDownTrack

func (w *WebRTCReceiver) AddDownTrack(track TrackSender) error

func (*WebRTCReceiver) AddOnReady

func (w *WebRTCReceiver) AddOnReady(fn func())

func (*WebRTCReceiver) AddUpTrack

func (w *WebRTCReceiver) AddUpTrack(track *webrtc.TrackRemote, buff *buffer.Buffer) error

func (*WebRTCReceiver) Codec

func (w *WebRTCReceiver) Codec() webrtc.RTPCodecParameters

func (*WebRTCReceiver) DebugInfo

func (w *WebRTCReceiver) DebugInfo() map[string]interface{}

func (*WebRTCReceiver) DeleteDownTrack

func (w *WebRTCReceiver) DeleteDownTrack(subscriberID livekit.ParticipantID)

DeleteDownTrack removes a DownTrack from a Receiver

func (*WebRTCReceiver) GetAudioLevel

func (w *WebRTCReceiver) GetAudioLevel() (float64, bool)

func (*WebRTCReceiver) GetConnectionScoreAndQuality

func (w *WebRTCReceiver) GetConnectionScoreAndQuality() (float32, livekit.ConnectionQuality)

func (*WebRTCReceiver) GetDeltaStats

func (w *WebRTCReceiver) GetDeltaStats() map[uint32]*buffer.StreamStatsWithLayers

func (*WebRTCReceiver) GetLastSenderReportTime

func (w *WebRTCReceiver) GetLastSenderReportTime() time.Time

func (*WebRTCReceiver) GetLayeredBitrate

func (w *WebRTCReceiver) GetLayeredBitrate() ([]int32, Bitrates)

func (*WebRTCReceiver) GetPrimaryReceiverForRed

func (w *WebRTCReceiver) GetPrimaryReceiverForRed() TrackReceiver

func (*WebRTCReceiver) GetRedReceiver

func (w *WebRTCReceiver) GetRedReceiver() TrackReceiver

func (*WebRTCReceiver) GetTemporalLayerFpsForSpatial

func (w *WebRTCReceiver) GetTemporalLayerFpsForSpatial(layer int32) []float32

func (*WebRTCReceiver) GetTrackStats

func (w *WebRTCReceiver) GetTrackStats() *livekit.RTPStats

func (*WebRTCReceiver) HeaderExtensions

func (w *WebRTCReceiver) HeaderExtensions() []webrtc.RTPHeaderExtensionParameter

func (*WebRTCReceiver) IsClosed

func (w *WebRTCReceiver) IsClosed() bool

func (*WebRTCReceiver) Kind

func (w *WebRTCReceiver) Kind() webrtc.RTPCodecType

func (*WebRTCReceiver) OnAvailableLayersChanged

func (w *WebRTCReceiver) OnAvailableLayersChanged()

StreamTrackerManagerListener.OnAvailableLayersChanged

func (*WebRTCReceiver) OnBitrateAvailabilityChanged

func (w *WebRTCReceiver) OnBitrateAvailabilityChanged()

StreamTrackerManagerListener.OnBitrateAvailabilityChanged

func (*WebRTCReceiver) OnBitrateReport

func (w *WebRTCReceiver) OnBitrateReport(availableLayers []int32, bitrates Bitrates)

StreamTrackerManagerListener.OnBitrateReport

func (*WebRTCReceiver) OnCloseHandler

func (w *WebRTCReceiver) OnCloseHandler(fn func())

OnCloseHandler method to be called on remote tracked removed

func (*WebRTCReceiver) OnMaxAvailableLayerChanged

func (w *WebRTCReceiver) OnMaxAvailableLayerChanged(maxAvailableLayer int32)

StreamTrackerManagerListener.OnMaxAvailableLayerChanged

func (*WebRTCReceiver) OnMaxLayerChange

func (w *WebRTCReceiver) OnMaxLayerChange(fn func(maxLayer int32))

func (*WebRTCReceiver) OnMaxPublishedLayerChanged

func (w *WebRTCReceiver) OnMaxPublishedLayerChanged(maxPublishedLayer int32)

StreamTrackerManagerListener.OnMaxPublishedLayerChanged

func (*WebRTCReceiver) OnMaxTemporalLayerSeenChanged

func (w *WebRTCReceiver) OnMaxTemporalLayerSeenChanged(maxTemporalLayerSeen int32)

StreamTrackerManagerListener.OnMaxTemporalLayerSeenChanged

func (*WebRTCReceiver) OnStatsUpdate

func (w *WebRTCReceiver) OnStatsUpdate(fn func(w *WebRTCReceiver, stat *livekit.AnalyticsStat))

func (*WebRTCReceiver) ReadRTP

func (w *WebRTCReceiver) ReadRTP(buf []byte, layer uint8, esn uint64) (int, error)

func (*WebRTCReceiver) SendPLI

func (w *WebRTCReceiver) SendPLI(layer int32, force bool)

func (*WebRTCReceiver) SetMaxExpectedSpatialLayer

func (w *WebRTCReceiver) SetMaxExpectedSpatialLayer(layer int32)

func (*WebRTCReceiver) SetRTT

func (w *WebRTCReceiver) SetRTT(rtt uint32)

func (*WebRTCReceiver) SetUpTrackPaused

func (w *WebRTCReceiver) SetUpTrackPaused(paused bool)

SetUpTrackPaused indicates upstream will not be sending any data. this will reflect the "muted" status and will pause streamtracker to ensure we don't turn off the layer

func (*WebRTCReceiver) StreamID

func (w *WebRTCReceiver) StreamID() string

func (*WebRTCReceiver) TrackID

func (w *WebRTCReceiver) TrackID() livekit.TrackID

func (*WebRTCReceiver) TrackInfo

func (w *WebRTCReceiver) TrackInfo() *livekit.TrackInfo

func (*WebRTCReceiver) UpdateTrackInfo

func (w *WebRTCReceiver) UpdateTrackInfo(ti *livekit.TrackInfo)

Jump to

Keyboard shortcuts

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