Allow publishers to set layer availability (#51)
* support client message to update active layers * update to match new protocol
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/pion/rtcp"
|
"github.com/pion/rtcp"
|
||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
"github.com/pion/webrtc/v3/pkg/rtcerr"
|
"github.com/pion/webrtc/v3/pkg/rtcerr"
|
||||||
|
"github.com/thoas/go-funk"
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/config"
|
"github.com/livekit/livekit-server/pkg/config"
|
||||||
"github.com/livekit/livekit-server/pkg/logger"
|
"github.com/livekit/livekit-server/pkg/logger"
|
||||||
@@ -105,6 +106,17 @@ func (t *MediaTrack) SetMuted(muted bool) {
|
|||||||
t.lock.RUnlock()
|
t.lock.RUnlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *MediaTrack) SetSimulcastLayers(layers []livekit.VideoQuality) {
|
||||||
|
t.lock.RLock()
|
||||||
|
defer t.lock.RUnlock()
|
||||||
|
if t.receiver != nil {
|
||||||
|
layers16 := funk.Map(layers, func(l livekit.VideoQuality) uint16 {
|
||||||
|
return uint16(spatialLayerForQuality(l))
|
||||||
|
}).([]uint16)
|
||||||
|
t.receiver.SetAvailableLayers(layers16)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (t *MediaTrack) OnClose(f func()) {
|
func (t *MediaTrack) OnClose(f func()) {
|
||||||
t.onClose = f
|
t.onClose = f
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ type PublishedTrack interface {
|
|||||||
Name() string
|
Name() string
|
||||||
IsMuted() bool
|
IsMuted() bool
|
||||||
SetMuted(muted bool)
|
SetMuted(muted bool)
|
||||||
|
SetSimulcastLayers(layers []livekit.VideoQuality)
|
||||||
AddSubscriber(participant Participant) error
|
AddSubscriber(participant Participant) error
|
||||||
RemoveSubscriber(participantId string)
|
RemoveSubscriber(participantId string)
|
||||||
IsSubscriber(subId string) bool
|
IsSubscriber(subId string) bool
|
||||||
|
|||||||
@@ -90,6 +90,11 @@ type FakePublishedTrack struct {
|
|||||||
setMutedArgsForCall []struct {
|
setMutedArgsForCall []struct {
|
||||||
arg1 bool
|
arg1 bool
|
||||||
}
|
}
|
||||||
|
SetSimulcastLayersStub func([]livekit.VideoQuality)
|
||||||
|
setSimulcastLayersMutex sync.RWMutex
|
||||||
|
setSimulcastLayersArgsForCall []struct {
|
||||||
|
arg1 []livekit.VideoQuality
|
||||||
|
}
|
||||||
StartStub func()
|
StartStub func()
|
||||||
startMutex sync.RWMutex
|
startMutex sync.RWMutex
|
||||||
startArgsForCall []struct {
|
startArgsForCall []struct {
|
||||||
@@ -562,6 +567,43 @@ func (fake *FakePublishedTrack) SetMutedArgsForCall(i int) bool {
|
|||||||
return argsForCall.arg1
|
return argsForCall.arg1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fake *FakePublishedTrack) SetSimulcastLayers(arg1 []livekit.VideoQuality) {
|
||||||
|
var arg1Copy []livekit.VideoQuality
|
||||||
|
if arg1 != nil {
|
||||||
|
arg1Copy = make([]livekit.VideoQuality, len(arg1))
|
||||||
|
copy(arg1Copy, arg1)
|
||||||
|
}
|
||||||
|
fake.setSimulcastLayersMutex.Lock()
|
||||||
|
fake.setSimulcastLayersArgsForCall = append(fake.setSimulcastLayersArgsForCall, struct {
|
||||||
|
arg1 []livekit.VideoQuality
|
||||||
|
}{arg1Copy})
|
||||||
|
stub := fake.SetSimulcastLayersStub
|
||||||
|
fake.recordInvocation("SetSimulcastLayers", []interface{}{arg1Copy})
|
||||||
|
fake.setSimulcastLayersMutex.Unlock()
|
||||||
|
if stub != nil {
|
||||||
|
fake.SetSimulcastLayersStub(arg1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakePublishedTrack) SetSimulcastLayersCallCount() int {
|
||||||
|
fake.setSimulcastLayersMutex.RLock()
|
||||||
|
defer fake.setSimulcastLayersMutex.RUnlock()
|
||||||
|
return len(fake.setSimulcastLayersArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakePublishedTrack) SetSimulcastLayersCalls(stub func([]livekit.VideoQuality)) {
|
||||||
|
fake.setSimulcastLayersMutex.Lock()
|
||||||
|
defer fake.setSimulcastLayersMutex.Unlock()
|
||||||
|
fake.SetSimulcastLayersStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakePublishedTrack) SetSimulcastLayersArgsForCall(i int) []livekit.VideoQuality {
|
||||||
|
fake.setSimulcastLayersMutex.RLock()
|
||||||
|
defer fake.setSimulcastLayersMutex.RUnlock()
|
||||||
|
argsForCall := fake.setSimulcastLayersArgsForCall[i]
|
||||||
|
return argsForCall.arg1
|
||||||
|
}
|
||||||
|
|
||||||
func (fake *FakePublishedTrack) Start() {
|
func (fake *FakePublishedTrack) Start() {
|
||||||
fake.startMutex.Lock()
|
fake.startMutex.Lock()
|
||||||
fake.startArgsForCall = append(fake.startArgsForCall, struct {
|
fake.startArgsForCall = append(fake.startArgsForCall, struct {
|
||||||
@@ -662,6 +704,8 @@ func (fake *FakePublishedTrack) Invocations() map[string][][]interface{} {
|
|||||||
defer fake.removeSubscriberMutex.RUnlock()
|
defer fake.removeSubscriberMutex.RUnlock()
|
||||||
fake.setMutedMutex.RLock()
|
fake.setMutedMutex.RLock()
|
||||||
defer fake.setMutedMutex.RUnlock()
|
defer fake.setMutedMutex.RUnlock()
|
||||||
|
fake.setSimulcastLayersMutex.RLock()
|
||||||
|
defer fake.setSimulcastLayersMutex.RUnlock()
|
||||||
fake.startMutex.RLock()
|
fake.startMutex.RLock()
|
||||||
defer fake.startMutex.RUnlock()
|
defer fake.startMutex.RUnlock()
|
||||||
fake.toProtoMutex.RLock()
|
fake.toProtoMutex.RLock()
|
||||||
|
|||||||
@@ -442,6 +442,16 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.Partici
|
|||||||
}
|
}
|
||||||
case *livekit.SignalRequest_Leave:
|
case *livekit.SignalRequest_Leave:
|
||||||
_ = participant.Close()
|
_ = participant.Close()
|
||||||
|
case *livekit.SignalRequest_Simulcast:
|
||||||
|
for _, track := range participant.GetPublishedTracks() {
|
||||||
|
if track.ID() == msg.Simulcast.TrackSid {
|
||||||
|
logger.Debugw("updating simulcast layers",
|
||||||
|
"participant", participant.Identity(),
|
||||||
|
"track", track.ID(),
|
||||||
|
"layers", msg.Simulcast.Layers)
|
||||||
|
track.SetSimulcastLayers(msg.Simulcast.Layers)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user