sfu

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 37 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

func IsRedCodec added in v1.2.0

func IsRedCodec(mime string) bool

func IsSvcCodec added in v1.1.0

func IsSvcCodec(mime string) bool

SVC-TODO: Have to use more conditions to differentiate between SVC-TODO: SVC and non-SVC (could be single layer or simulcast). SVC-TODO: May only need to differentiate between simulcast and non-simulcast SVC-TODO: i. e. may be possible to treat single layer as SVC to get proper/intended functionality.

Types

type AudioLevelHandle added in v0.15.3

type AudioLevelHandle func(level uint8, duration uint32)

type Bitrates added in v0.15.0

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 added in v0.15.0

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

func (*DownTrack) AllocateOptimal added in v0.15.6

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

func (*DownTrack) BandwidthRequested added in v0.15.0

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 added in v1.4.0

func (d *DownTrack) ClearStreamAllocatorReportInterval()

func (*DownTrack) Close

func (d *DownTrack) Close()

func (*DownTrack) CloseWithFlush added in v0.15.3

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 added in v0.15.0

func (d *DownTrack) DistanceToDesired() float64

func (*DownTrack) GetConnectionScoreAndQuality added in v1.4.0

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

func (*DownTrack) GetDeltaStatsSender added in v1.5.0

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

func (*DownTrack) GetLastReceiverReportTime added in v1.5.0

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

func (*DownTrack) GetNackStats added in v0.15.5

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

func (*DownTrack) GetNextHigherTransition added in v0.15.5

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

func (*DownTrack) GetState added in v1.2.4

func (d *DownTrack) GetState() DownTrackState

func (*DownTrack) GetTotalPacketsSent added in v1.5.0

func (d *DownTrack) GetTotalPacketsSent() uint64

func (*DownTrack) GetTrackStats added in v0.15.6

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

func (*DownTrack) GetTransceiver added in v1.1.1

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

func (*DownTrack) HandleRTCPSenderReportData added in v1.3.3

func (d *DownTrack) HandleRTCPSenderReportData(
	_payloadType webrtc.PayloadType,
	isSVC bool,
	layer int32,
	publisherSRData *buffer.RTCPSenderReportData,
) 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 added in v1.1.0

func (d *DownTrack) IsClosed() bool

func (*DownTrack) IsDeficient added in v0.15.0

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 added in v1.4.2

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 added in v1.3.4

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

func (*DownTrack) OnCloseHandler

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

OnCloseHandler method to be called on remote tracked removed

func (*DownTrack) OnMaxLayerChanged added in v0.15.4

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

func (*DownTrack) OnRttUpdate added in v0.15.4

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

func (*DownTrack) OnStatsUpdate added in v0.15.3

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

func (*DownTrack) Pause added in v0.15.0

func (d *DownTrack) Pause() VideoAllocation

func (*DownTrack) ProvisionalAllocate added in v0.15.0

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

func (*DownTrack) ProvisionalAllocateCommit added in v0.15.0

func (d *DownTrack) ProvisionalAllocateCommit() VideoAllocation

func (*DownTrack) ProvisionalAllocateGetBestWeightedTransition added in v0.15.0

func (d *DownTrack) ProvisionalAllocateGetBestWeightedTransition() VideoTransition

func (*DownTrack) ProvisionalAllocateGetCooperativeTransition added in v0.15.0

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

func (*DownTrack) ProvisionalAllocatePrepare added in v0.15.0

func (d *DownTrack) ProvisionalAllocatePrepare()

func (*DownTrack) ProvisionalAllocateReset added in v1.4.5

func (d *DownTrack) ProvisionalAllocateReset()

func (*DownTrack) PubMute added in v1.3.4

func (d *DownTrack) PubMute(pubMuted bool)

PubMute enables or disables media forwarding - publisher side

func (*DownTrack) RID added in v0.15.3

func (d *DownTrack) RID() string

RID is required by `webrtc.TrackLocal` interface

func (*DownTrack) Resync added in v0.15.4

func (d *DownTrack) Resync()

func (*DownTrack) SSRC

func (d *DownTrack) SSRC() uint32

func (*DownTrack) SeedState added in v1.2.4

func (d *DownTrack) SeedState(state DownTrackState)

func (*DownTrack) SetActivePaddingOnMuteUpTrack added in v1.3.3

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 added in v1.1.0

func (d *DownTrack) SetConnected()

func (*DownTrack) SetMaxSpatialLayer added in v0.15.0

func (d *DownTrack) SetMaxSpatialLayer(spatialLayer int32)

func (*DownTrack) SetMaxTemporalLayer added in v0.15.0

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 added in v1.4.0

func (d *DownTrack) SetStreamAllocatorListener(listener DownTrackStreamAllocatorListener)

func (*DownTrack) SetStreamAllocatorReportInterval added in v1.4.0

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

func (d *DownTrack) StreamID() string

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

func (*DownTrack) SubscriberID added in v1.1.0

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

func (*DownTrack) TrackInfoAvailable added in v1.2.0

func (d *DownTrack) TrackInfoAvailable()

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 added in v0.15.6

func (d *DownTrack) UpTrackBitrateAvailabilityChange()

func (*DownTrack) UpTrackBitrateReport added in v1.4.0

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

func (*DownTrack) UpTrackLayersChange added in v0.15.3

func (d *DownTrack) UpTrackLayersChange()

func (*DownTrack) UpTrackMaxPublishedLayerChange added in v1.3.5

func (d *DownTrack) UpTrackMaxPublishedLayerChange(maxPublishedLayer int32)

func (*DownTrack) UpTrackMaxTemporalLayerSeenChange added in v1.4.0

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 added in v0.15.7

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

func NewDownTrackSpreader added in v0.15.7

func NewDownTrackSpreader(params DownTrackSpreaderParams) *DownTrackSpreader

func (*DownTrackSpreader) Broadcast added in v0.15.7

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

func (*DownTrackSpreader) DownTrackCount added in v1.1.0

func (d *DownTrackSpreader) DownTrackCount() int

func (*DownTrackSpreader) Free added in v0.15.7

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

func (*DownTrackSpreader) GetDownTracks added in v0.15.7

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

func (*DownTrackSpreader) HasDownTrack added in v0.15.7

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

func (*DownTrackSpreader) ResetAndGetDownTracks added in v0.15.7

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

func (*DownTrackSpreader) Store added in v0.15.7

func (d *DownTrackSpreader) Store(ts TrackSender)

type DownTrackSpreaderParams added in v0.15.7

type DownTrackSpreaderParams struct {
	Threshold int
	Logger    logger.Logger
}

type DownTrackState added in v1.2.4

type DownTrackState struct {
	RTPStats                   *buffer.RTPStatsSender
	DeltaStatsSenderSnapshotId uint32
	ForwarderState             ForwarderState
}

func (DownTrackState) String added in v1.2.4

func (d DownTrackState) String() string

type DownTrackStreamAllocatorListener added in v1.4.0

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 added in v1.4.5

type DowntrackParams struct {
	Codecs            []webrtc.RTPCodecParameters
	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
}

type Forwarder added in v0.15.0

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

func NewForwarder added in v0.15.0

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

func (*Forwarder) AllocateNextHigher added in v0.15.0

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

func (*Forwarder) AllocateOptimal added in v0.15.6

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

func (*Forwarder) BandwidthRequested added in v0.15.0

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

func (*Forwarder) CheckSync added in v0.15.6

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

func (*Forwarder) CurrentLayer added in v1.4.2

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

func (*Forwarder) DetermineCodec added in v1.1.0

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

func (*Forwarder) DistanceToDesired added in v0.15.0

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

func (*Forwarder) FilterRTX added in v0.15.5

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

func (*Forwarder) GetMaxSubscribedSpatial added in v1.4.5

func (f *Forwarder) GetMaxSubscribedSpatial() int32

func (*Forwarder) GetNextHigherTransition added in v0.15.5

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

func (*Forwarder) GetOptimalBandwidthNeeded added in v1.4.0

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

func (*Forwarder) GetPadding added in v1.4.2

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

func (*Forwarder) GetSenderReportParams added in v1.6.0

func (f *Forwarder) GetSenderReportParams() (int32, uint64, *buffer.RTCPSenderReportData)

func (*Forwarder) GetSnTsForBlankFrames added in v0.15.0

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

func (*Forwarder) GetSnTsForPadding added in v0.15.0

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

func (*Forwarder) GetState added in v1.1.1

func (f *Forwarder) GetState() ForwarderState

func (*Forwarder) GetTranslationParams added in v0.15.0

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

func (*Forwarder) IsAnyMuted added in v1.3.5

func (f *Forwarder) IsAnyMuted() bool

func (*Forwarder) IsDeficient added in v0.15.0

func (f *Forwarder) IsDeficient() bool

func (*Forwarder) IsMuted added in v0.15.4

func (f *Forwarder) IsMuted() bool

func (*Forwarder) IsPubMuted added in v1.3.4

func (f *Forwarder) IsPubMuted() bool

func (*Forwarder) MaxLayer added in v1.4.2

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

func (*Forwarder) Mute added in v0.15.0

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

func (*Forwarder) Pause added in v0.15.0

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

func (*Forwarder) PauseReason added in v1.4.5

func (f *Forwarder) PauseReason() VideoPauseReason

func (*Forwarder) ProvisionalAllocate added in v0.15.0

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

func (*Forwarder) ProvisionalAllocateCommit added in v0.15.0

func (f *Forwarder) ProvisionalAllocateCommit() VideoAllocation

func (*Forwarder) ProvisionalAllocateGetBestWeightedTransition added in v0.15.0

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

func (*Forwarder) ProvisionalAllocateGetCooperativeTransition added in v0.15.0

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

func (*Forwarder) ProvisionalAllocatePrepare added in v0.15.0

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

func (*Forwarder) ProvisionalAllocateReset added in v1.4.5

func (f *Forwarder) ProvisionalAllocateReset()

func (*Forwarder) PubMute added in v1.3.4

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

func (*Forwarder) RTPMungerDebugInfo added in v1.5.0

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

func (*Forwarder) Resync added in v0.15.4

func (f *Forwarder) Resync()

func (*Forwarder) SeedState added in v1.1.1

func (f *Forwarder) SeedState(state ForwarderState)

func (*Forwarder) SetMaxPublishedLayer added in v1.3.5

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

func (*Forwarder) SetMaxSpatialLayer added in v0.15.0

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

func (*Forwarder) SetMaxTemporalLayer added in v0.15.0

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

func (*Forwarder) SetMaxTemporalLayerSeen added in v1.4.0

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

func (*Forwarder) SetRefSenderReport added in v1.6.0

func (f *Forwarder) SetRefSenderReport(isSVC bool, layer int32, srData *buffer.RTCPSenderReportData)

func (*Forwarder) TargetLayer added in v1.4.2

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

func (*Forwarder) TranslateCodecHeader added in v1.6.0

func (f *Forwarder) TranslateCodecHeader(extPkt *buffer.ExtPacket, tpr *TranslationParamsRTP, outputBuffer []byte) (bool, int, int, error)

type ForwarderState added in v1.1.1

type ForwarderState struct {
	Started               bool
	ReferenceLayerSpatial int32
	PreStartTime          time.Time
	ExtFirstTS            uint64
	RefTSOffset           uint64
	RTP                   RTPMungerState
	Codec                 interface{}
}

func (ForwarderState) String added in v1.2.4

func (f ForwarderState) String() string

type PlayoutDelayController added in v1.5.3

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

func NewPlayoutDelayController added in v1.5.3

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

func (*PlayoutDelayController) GetDelayExtension added in v1.5.3

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

func (*PlayoutDelayController) OnSeqAcked added in v1.5.3

func (c *PlayoutDelayController) OnSeqAcked(seq uint16)

func (*PlayoutDelayController) SetJitter added in v1.5.3

func (c *PlayoutDelayController) SetJitter(jitter uint32)

type PlayoutDelayState added in v1.5.3

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

func (PlayoutDelayState) String added in v1.5.3

func (s PlayoutDelayState) String() string

type RTPMunger added in v0.15.0

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

func NewRTPMunger added in v0.15.0

func NewRTPMunger(logger logger.Logger) *RTPMunger

func (*RTPMunger) DebugInfo added in v1.5.0

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

func (*RTPMunger) FilterRTX added in v0.15.5

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

func (*RTPMunger) GetLast added in v1.1.1

func (r *RTPMunger) GetLast() RTPMungerState

func (*RTPMunger) GetPinnedTSOffset added in v1.6.0

func (r *RTPMunger) GetPinnedTSOffset() uint64

func (*RTPMunger) IsOnFrameBoundary added in v0.15.0

func (r *RTPMunger) IsOnFrameBoundary() bool

func (*RTPMunger) PacketDropped added in v0.15.0

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

func (*RTPMunger) SeedLast added in v1.1.1

func (r *RTPMunger) SeedLast(state RTPMungerState)

func (*RTPMunger) SetLastSnTs added in v0.15.0

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

func (*RTPMunger) UpdateAndGetPaddingSnTs added in v0.15.0

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

func (*RTPMunger) UpdateAndGetSnTs added in v0.15.0

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

func (*RTPMunger) UpdateSnTsOffsets added in v0.15.0

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

type RTPMungerState added in v1.1.1

type RTPMungerState struct {
	ExtLastSN        uint64
	ExtSecondLastSN  uint64
	ExtLastTS        uint64
	ExtSecondLastTS  uint64
	LastMarker       bool
	SecondLastMarker bool
}

func (RTPMungerState) String added in v1.2.4

func (r RTPMungerState) String() string

type ReceiverOpts

type ReceiverOpts func(w *WebRTCReceiver) *WebRTCReceiver

func WithAudioConfig added in v0.15.7

func WithAudioConfig(audioConfig config.AudioConfig) ReceiverOpts

WithAudioConfig sets up parameters for active speaker detection

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 added in v0.15.7

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 added in v1.2.0

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

func NewRedPrimaryReceiver added in v1.2.0

func NewRedPrimaryReceiver(receiver TrackReceiver, dsp DownTrackSpreaderParams) *RedPrimaryReceiver

func (*RedPrimaryReceiver) AddDownTrack added in v1.2.0

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

func (*RedPrimaryReceiver) CanClose added in v1.2.0

func (r *RedPrimaryReceiver) CanClose() bool

func (*RedPrimaryReceiver) Close added in v1.2.0

func (r *RedPrimaryReceiver) Close()

func (*RedPrimaryReceiver) DeleteDownTrack added in v1.2.0

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

func (*RedPrimaryReceiver) ForwardRTP added in v1.2.0

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

func (*RedPrimaryReceiver) IsClosed added in v1.3.5

func (r *RedPrimaryReceiver) IsClosed() bool

func (*RedPrimaryReceiver) ReadRTP added in v1.2.0

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

type RedReceiver added in v1.3.0

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

func NewRedReceiver added in v1.3.0

func NewRedReceiver(receiver TrackReceiver, dsp DownTrackSpreaderParams) *RedReceiver

func (*RedReceiver) AddDownTrack added in v1.3.0

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

func (*RedReceiver) CanClose added in v1.3.0

func (r *RedReceiver) CanClose() bool

func (*RedReceiver) Close added in v1.3.0

func (r *RedReceiver) Close()

func (*RedReceiver) DeleteDownTrack added in v1.3.0

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

func (*RedReceiver) ForwardRTP added in v1.3.0

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

func (*RedReceiver) IsClosed added in v1.3.5

func (r *RedReceiver) IsClosed() bool

func (*RedReceiver) ReadRTP added in v1.3.0

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

type SequenceNumberOrdering

type SequenceNumberOrdering int

RTPMunger

const (
	SequenceNumberOrderingContiguous SequenceNumberOrdering = iota
	SequenceNumberOrderingOutOfOrder
	SequenceNumberOrderingGap
	SequenceNumberOrderingDuplicate
)

type SnTs added in v0.15.0

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

type StreamTrackerManager added in v0.15.4

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

func NewStreamTrackerManager added in v0.15.4

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

func (*StreamTrackerManager) AddDependencyDescriptorTrackers added in v1.4.4

func (s *StreamTrackerManager) AddDependencyDescriptorTrackers()

func (*StreamTrackerManager) AddTracker added in v0.15.4

func (*StreamTrackerManager) Close added in v1.4.0

func (s *StreamTrackerManager) Close()

func (*StreamTrackerManager) DistanceToDesired added in v1.2.0

func (s *StreamTrackerManager) DistanceToDesired() float64

func (*StreamTrackerManager) GetLayeredBitrate added in v1.2.4

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

func (*StreamTrackerManager) GetMaxPublishedLayer added in v1.3.5

func (s *StreamTrackerManager) GetMaxPublishedLayer() int32

func (*StreamTrackerManager) GetMaxTemporalLayerSeen added in v1.4.0

func (s *StreamTrackerManager) GetMaxTemporalLayerSeen() int32

func (*StreamTrackerManager) GetTracker added in v0.15.4

func (*StreamTrackerManager) IsPaused added in v1.3.3

func (s *StreamTrackerManager) IsPaused() bool

func (*StreamTrackerManager) RemoveAllTrackers added in v0.15.4

func (s *StreamTrackerManager) RemoveAllTrackers()

func (*StreamTrackerManager) RemoveTracker added in v0.15.4

func (s *StreamTrackerManager) RemoveTracker(layer int32)

func (*StreamTrackerManager) SetListener added in v1.4.0

func (s *StreamTrackerManager) SetListener(listener StreamTrackerManagerListener)

func (*StreamTrackerManager) SetMaxExpectedSpatialLayer added in v0.15.4

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

func (*StreamTrackerManager) SetPaused added in v0.15.4

func (s *StreamTrackerManager) SetPaused(paused bool)

func (*StreamTrackerManager) UpdateTrackInfo added in v1.5.2

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

type StreamTrackerManagerListener added in v1.4.0

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

type TrackReceiver added in v0.15.0

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

	ReadRTP(buf []byte, layer uint8, sn uint16) (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
}

TrackReceiver defines an interface receive media from remote peer

type TrackSender added in v0.15.0

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
	TrackInfoAvailable()
	HandleRTCPSenderReportData(
		payloadType webrtc.PayloadType,
		isSVC bool,
		layer int32,
		publisherSRData *buffer.RTCPSenderReportData,
	) error
}

TrackSender defines an interface send media to remote peer

type TranslationParams added in v0.15.0

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

type TranslationParamsRTP added in v0.15.0

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

type VideoAllocation added in v0.15.0

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 added in v1.6.0

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

func (*VideoAllocation) String added in v0.15.0

func (v *VideoAllocation) String() string

type VideoAllocationProvisional added in v0.15.0

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

type VideoPauseReason added in v1.3.4

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

func (VideoPauseReason) String added in v1.3.4

func (v VideoPauseReason) String() string

type VideoTransition added in v0.15.0

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

func (*VideoTransition) MarshalLogObject added in v1.6.0

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

func (*VideoTransition) String added in v1.2.4

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) 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 added in v0.15.7

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

func (*WebRTCReceiver) GetConnectionScoreAndQuality added in v1.4.0

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

func (*WebRTCReceiver) GetDeltaStats added in v1.5.0

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

func (*WebRTCReceiver) GetLayeredBitrate added in v1.2.4

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

func (*WebRTCReceiver) GetPrimaryReceiverForRed added in v1.2.0

func (w *WebRTCReceiver) GetPrimaryReceiverForRed() TrackReceiver

func (*WebRTCReceiver) GetRedReceiver added in v1.3.0

func (w *WebRTCReceiver) GetRedReceiver() TrackReceiver

func (*WebRTCReceiver) GetTemporalLayerFpsForSpatial added in v1.3.0

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

func (*WebRTCReceiver) GetTrackStats added in v0.15.6

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

func (*WebRTCReceiver) HeaderExtensions added in v1.1.0

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

func (*WebRTCReceiver) IsClosed added in v1.3.5

func (w *WebRTCReceiver) IsClosed() bool

func (*WebRTCReceiver) Kind

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

func (*WebRTCReceiver) OnAvailableLayersChanged added in v1.4.0

func (w *WebRTCReceiver) OnAvailableLayersChanged()

StreamTrackerManagerListener.OnAvailableLayersChanged

func (*WebRTCReceiver) OnBitrateAvailabilityChanged added in v1.4.0

func (w *WebRTCReceiver) OnBitrateAvailabilityChanged()

StreamTrackerManagerListener.OnBitrateAvailabilityChanged

func (*WebRTCReceiver) OnBitrateReport added in v1.4.0

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 added in v1.4.0

func (w *WebRTCReceiver) OnMaxAvailableLayerChanged(maxAvailableLayer int32)

StreamTrackerManagerListener.OnMaxAvailableLayerChanged

func (*WebRTCReceiver) OnMaxLayerChange added in v1.1.0

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

func (*WebRTCReceiver) OnMaxPublishedLayerChanged added in v1.4.0

func (w *WebRTCReceiver) OnMaxPublishedLayerChanged(maxPublishedLayer int32)

StreamTrackerManagerListener.OnMaxPublishedLayerChanged

func (*WebRTCReceiver) OnMaxTemporalLayerSeenChanged added in v1.4.0

func (w *WebRTCReceiver) OnMaxTemporalLayerSeenChanged(maxTemporalLayerSeen int32)

StreamTrackerManagerListener.OnMaxTemporalLayerSeenChanged

func (*WebRTCReceiver) OnStatsUpdate added in v0.15.4

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

func (*WebRTCReceiver) ReadRTP added in v0.15.0

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

func (*WebRTCReceiver) SendPLI added in v0.15.0

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

func (*WebRTCReceiver) SetMaxExpectedSpatialLayer added in v0.15.2

func (w *WebRTCReceiver) SetMaxExpectedSpatialLayer(layer int32)

func (*WebRTCReceiver) SetRTT added in v0.15.4

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 added in v1.2.0

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

func (*WebRTCReceiver) UpdateTrackInfo added in v1.5.2

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