Files
livekit-3d/pkg/rtc/subscribedtrack.go
T
98695cdd22 downstream allocator (#155)
* WIP branch to hash out down stream allocator.

* Plug more bits of stream allocator

* update protocol

* remove SignalRequest_Simulcast (#154)

* Plug more bits of stream allocator

* Handle simulcast track available layers change

* WIP branch to hash out down stream allocator.

* Plug more bits of stream allocator

* Handle simulcast track available layers change

* Adopt signature of call to AdjustAllocation

* Move StreamAllocator to PCTransport and allocate only for subscriber.

* Move streamallocator to ion-sfu

* Start/Stop of streamallocator

* Use StreamAllocator for subscriber bandwidth management.

* Do not allocate in ADD_TRACK

* Set payload in constructor

* - Add some logging
- Protocol message to notify clients of paused/resumed streams

* named return

* oops correct sense of isPausing

* Update pkg/sfu/streamallocator.go

Committing David's suggestion.

Co-authored-by: David Zhao <david@davidzhao.com>

* - Log estimate changes/commits.
- Catch more than epsilon change oscillating for long time.

Co-authored-by: David Colburn <xero73@gmail.com>
Co-authored-by: David Zhao <david@davidzhao.com>
2021-11-26 09:11:04 +05:30

85 lines
1.9 KiB
Go

package rtc
import (
"time"
"github.com/bep/debounce"
"github.com/livekit/livekit-server/pkg/sfu"
livekit "github.com/livekit/protocol/proto"
"github.com/livekit/protocol/utils"
"github.com/pion/webrtc/v3"
)
const (
subscriptionDebounceInterval = 100 * time.Millisecond
)
type SubscribedTrack struct {
dt *sfu.DownTrack
publisherIdentity string
subMuted utils.AtomicFlag
pubMuted utils.AtomicFlag
debouncer func(func())
}
func NewSubscribedTrack(publisherIdentity string, dt *sfu.DownTrack) *SubscribedTrack {
return &SubscribedTrack{
publisherIdentity: publisherIdentity,
dt: dt,
debouncer: debounce.New(subscriptionDebounceInterval),
}
}
func (t *SubscribedTrack) ID() string {
return t.dt.ID()
}
func (t *SubscribedTrack) PublisherIdentity() string {
return t.publisherIdentity
}
func (t *SubscribedTrack) DownTrack() *sfu.DownTrack {
return t.dt
}
func (t *SubscribedTrack) SubscribeLossPercentage() uint32 {
return FixedPointToPercent(t.DownTrack().CurrentMaxLossFraction())
}
// has subscriber indicated it wants to mute this track
func (t *SubscribedTrack) IsMuted() bool {
return t.subMuted.Get()
}
func (t *SubscribedTrack) SetPublisherMuted(muted bool) {
t.pubMuted.TrySet(muted)
t.updateDownTrackMute()
}
func (t *SubscribedTrack) UpdateSubscriberSettings(enabled bool, quality livekit.VideoQuality) {
t.debouncer(func() {
t.subMuted.TrySet(!enabled)
t.updateDownTrackMute()
if enabled && t.dt.Kind() == webrtc.RTPCodecTypeVideo {
t.dt.SetMaxSpatialLayer(spatialLayerForQuality(quality))
}
})
}
func (t *SubscribedTrack) updateDownTrackMute() {
muted := t.subMuted.Get() || t.pubMuted.Get()
t.dt.Mute(muted)
}
func spatialLayerForQuality(quality livekit.VideoQuality) int32 {
switch quality {
case livekit.VideoQuality_LOW:
return 0
case livekit.VideoQuality_MEDIUM:
return 1
default:
return 2
}
}