Code cleanup (#353)
This commit is contained in:
+1
-1
@@ -4,13 +4,13 @@ import (
|
||||
"errors"
|
||||
"net"
|
||||
|
||||
logging "github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/pion/ice/v2"
|
||||
"github.com/pion/sdp/v3"
|
||||
"github.com/pion/webrtc/v3"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
logging "github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
||||
)
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ type MediaTrack struct {
|
||||
numUpTracks uint32
|
||||
buffer *buffer.Buffer
|
||||
|
||||
layerSsrcs [livekit.VideoQuality_HIGH + 1]uint32
|
||||
layerSSRCs [livekit.VideoQuality_HIGH + 1]uint32
|
||||
|
||||
audioLevelMu sync.RWMutex
|
||||
audioLevel *AudioLevel
|
||||
@@ -116,8 +116,8 @@ func (t *MediaTrack) ToProto() *livekit.TrackInfo {
|
||||
info.Simulcast = t.IsSimulcast()
|
||||
layers := t.MediaTrackReceiver.GetVideoLayers()
|
||||
for _, layer := range layers {
|
||||
if int(layer.Quality) < len(t.layerSsrcs) {
|
||||
layer.Ssrc = t.layerSsrcs[layer.Quality]
|
||||
if int(layer.Quality) < len(t.layerSSRCs) {
|
||||
layer.Ssrc = t.layerSSRCs[layer.Quality]
|
||||
}
|
||||
}
|
||||
info.Layers = layers
|
||||
@@ -228,8 +228,8 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Tra
|
||||
|
||||
if t.IsSimulcast() {
|
||||
layer := sfu.RidToLayer(track.RID())
|
||||
if int(layer) < len(t.layerSsrcs) {
|
||||
t.layerSsrcs[layer] = uint32(track.SSRC())
|
||||
if int(layer) < len(t.layerSSRCs) {
|
||||
t.layerSSRCs[layer] = uint32(track.SSRC())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,8 +239,8 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Tra
|
||||
}
|
||||
|
||||
func (t *MediaTrack) TrySetSimulcastSSRC(layer uint8, ssrc uint32) {
|
||||
if int(layer) < len(t.layerSsrcs) && t.layerSsrcs[layer] == 0 {
|
||||
t.layerSsrcs[layer] = ssrc
|
||||
if int(layer) < len(t.layerSSRCs) && t.layerSSRCs[layer] == 0 {
|
||||
t.layerSSRCs[layer] = ssrc
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,7 +262,7 @@ func (t *MediaTrack) handlePublisherFeedback(packets []rtcp.Packet) {
|
||||
var totalLost uint32
|
||||
var maxSeqNum uint32
|
||||
|
||||
//forward to telemetry
|
||||
// forward to telemetry
|
||||
t.params.Telemetry.HandleRTCP(livekit.StreamType_UPSTREAM, t.params.ParticipantID, t.ID(), packets)
|
||||
|
||||
for _, p := range packets {
|
||||
|
||||
+20
-20
@@ -129,7 +129,7 @@ func TestSubscribedMaxQuality(t *testing.T) {
|
||||
mt.NotifySubscriberMaxQuality("s1", livekit.VideoQuality_HIGH)
|
||||
|
||||
actualTrackID := livekit.TrackID("")
|
||||
actualSubscribedQualities := []*livekit.SubscribedQuality{}
|
||||
actualSubscribedQualities := make([]*livekit.SubscribedQuality, 0)
|
||||
mt.OnSubscribedMaxQualityChange(func(trackID livekit.TrackID, subscribedQualities []*livekit.SubscribedQuality, _maxSubscribedQuality livekit.VideoQuality) error {
|
||||
actualTrackID = trackID
|
||||
actualSubscribedQualities = subscribedQualities
|
||||
@@ -140,9 +140,9 @@ func TestSubscribedMaxQuality(t *testing.T) {
|
||||
mt.NotifySubscriberMaxQuality("s1", livekit.VideoQuality_OFF)
|
||||
|
||||
expectedSubscribedQualities := []*livekit.SubscribedQuality{
|
||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_LOW, Enabled: false},
|
||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_MEDIUM, Enabled: false},
|
||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_HIGH, Enabled: false},
|
||||
{Quality: livekit.VideoQuality_LOW, Enabled: false},
|
||||
{Quality: livekit.VideoQuality_MEDIUM, Enabled: false},
|
||||
{Quality: livekit.VideoQuality_HIGH, Enabled: false},
|
||||
}
|
||||
require.Equal(t, livekit.TrackID("v1"), actualTrackID)
|
||||
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
||||
@@ -174,7 +174,7 @@ func TestSubscribedMaxQuality(t *testing.T) {
|
||||
}})
|
||||
|
||||
actualTrackID := livekit.TrackID("")
|
||||
actualSubscribedQualities := []*livekit.SubscribedQuality{}
|
||||
actualSubscribedQualities := make([]*livekit.SubscribedQuality, 0)
|
||||
mt.OnSubscribedMaxQualityChange(func(trackID livekit.TrackID, subscribedQualities []*livekit.SubscribedQuality, _maxSubscribedQuality livekit.VideoQuality) error {
|
||||
actualTrackID = trackID
|
||||
actualSubscribedQualities = subscribedQualities
|
||||
@@ -185,9 +185,9 @@ func TestSubscribedMaxQuality(t *testing.T) {
|
||||
mt.NotifySubscriberMaxQuality("s2", livekit.VideoQuality_MEDIUM)
|
||||
|
||||
expectedSubscribedQualities := []*livekit.SubscribedQuality{
|
||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_LOW, Enabled: true},
|
||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_MEDIUM, Enabled: true},
|
||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_HIGH, Enabled: true},
|
||||
{Quality: livekit.VideoQuality_LOW, Enabled: true},
|
||||
{Quality: livekit.VideoQuality_MEDIUM, Enabled: true},
|
||||
{Quality: livekit.VideoQuality_HIGH, Enabled: true},
|
||||
}
|
||||
require.Equal(t, livekit.TrackID("v1"), actualTrackID)
|
||||
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
||||
@@ -196,9 +196,9 @@ func TestSubscribedMaxQuality(t *testing.T) {
|
||||
mt.NotifySubscriberMaxQuality("s1", livekit.VideoQuality_MEDIUM)
|
||||
|
||||
expectedSubscribedQualities = []*livekit.SubscribedQuality{
|
||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_LOW, Enabled: true},
|
||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_MEDIUM, Enabled: true},
|
||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_HIGH, Enabled: false},
|
||||
{Quality: livekit.VideoQuality_LOW, Enabled: true},
|
||||
{Quality: livekit.VideoQuality_MEDIUM, Enabled: true},
|
||||
{Quality: livekit.VideoQuality_HIGH, Enabled: false},
|
||||
}
|
||||
require.Equal(t, livekit.TrackID("v1"), actualTrackID)
|
||||
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
||||
@@ -208,9 +208,9 @@ func TestSubscribedMaxQuality(t *testing.T) {
|
||||
mt.NotifySubscriberMaxQuality("s2", livekit.VideoQuality_LOW)
|
||||
|
||||
expectedSubscribedQualities = []*livekit.SubscribedQuality{
|
||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_LOW, Enabled: true},
|
||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_MEDIUM, Enabled: false},
|
||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_HIGH, Enabled: false},
|
||||
{Quality: livekit.VideoQuality_LOW, Enabled: true},
|
||||
{Quality: livekit.VideoQuality_MEDIUM, Enabled: false},
|
||||
{Quality: livekit.VideoQuality_HIGH, Enabled: false},
|
||||
}
|
||||
require.Equal(t, livekit.TrackID("v1"), actualTrackID)
|
||||
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
||||
@@ -219,9 +219,9 @@ func TestSubscribedMaxQuality(t *testing.T) {
|
||||
mt.NotifySubscriberMaxQuality("s2", livekit.VideoQuality_OFF)
|
||||
|
||||
expectedSubscribedQualities = []*livekit.SubscribedQuality{
|
||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_LOW, Enabled: true},
|
||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_MEDIUM, Enabled: false},
|
||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_HIGH, Enabled: false},
|
||||
{Quality: livekit.VideoQuality_LOW, Enabled: true},
|
||||
{Quality: livekit.VideoQuality_MEDIUM, Enabled: false},
|
||||
{Quality: livekit.VideoQuality_HIGH, Enabled: false},
|
||||
}
|
||||
require.Equal(t, livekit.TrackID("v1"), actualTrackID)
|
||||
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
||||
@@ -230,9 +230,9 @@ func TestSubscribedMaxQuality(t *testing.T) {
|
||||
mt.NotifySubscriberMaxQuality("s1", livekit.VideoQuality_OFF)
|
||||
|
||||
expectedSubscribedQualities = []*livekit.SubscribedQuality{
|
||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_LOW, Enabled: false},
|
||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_MEDIUM, Enabled: false},
|
||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_HIGH, Enabled: false},
|
||||
{Quality: livekit.VideoQuality_LOW, Enabled: false},
|
||||
{Quality: livekit.VideoQuality_MEDIUM, Enabled: false},
|
||||
{Quality: livekit.VideoQuality_HIGH, Enabled: false},
|
||||
}
|
||||
require.Equal(t, livekit.TrackID("v1"), actualTrackID)
|
||||
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
||||
|
||||
@@ -360,7 +360,7 @@ func (t *MediaTrackReceiver) OnSubscribedMaxQualityChange(f func(trackID livekit
|
||||
})
|
||||
}
|
||||
|
||||
//---------------------------
|
||||
// ---------------------------
|
||||
|
||||
func SpatialLayerForQuality(quality livekit.VideoQuality) int32 {
|
||||
switch quality {
|
||||
|
||||
@@ -201,7 +201,7 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, code
|
||||
return
|
||||
}
|
||||
|
||||
// if the source has been terminated, we'll need to terminate all of the subscribedtracks
|
||||
// if the source has been terminated, we'll need to terminate all the subscribed tracks
|
||||
// however, if the dest sub has disconnected, then we can skip
|
||||
if sender == nil {
|
||||
return
|
||||
@@ -321,7 +321,7 @@ func (t *MediaTrackSubscriptions) getSubscribedTrack(subscriberID livekit.Partic
|
||||
return t.subscribedTracks[subscriberID]
|
||||
}
|
||||
|
||||
// TODO: send for all downtracks from the source participant
|
||||
// TODO: send for all down tracks from the source participant
|
||||
// https://tools.ietf.org/html/rfc7941
|
||||
func (t *MediaTrackSubscriptions) sendDownTrackBindingReports(sub types.LocalParticipant) {
|
||||
var sd []rtcp.SourceDescriptionChunk
|
||||
|
||||
+20
-20
@@ -89,7 +89,7 @@ type ParticipantImpl struct {
|
||||
pendingTracksLock sync.RWMutex
|
||||
pendingTracks map[string]*pendingTrackInfo
|
||||
|
||||
*UptrackManager
|
||||
*UpTrackManager
|
||||
|
||||
// tracks the current participant is subscribed to, map of sid => DownTrack
|
||||
subscribedTracks map[livekit.TrackID]types.SubscribedTrack
|
||||
@@ -204,7 +204,7 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
||||
|
||||
p.subscriber.OnStreamStateChange(p.onStreamStateChange)
|
||||
|
||||
p.setupUptrackManager()
|
||||
p.setupUpTrackManager()
|
||||
|
||||
return p, nil
|
||||
}
|
||||
@@ -258,7 +258,7 @@ func (p *ParticipantImpl) ToProto() *livekit.ParticipantInfo {
|
||||
Hidden: p.Hidden(),
|
||||
Recorder: p.IsRecorder(),
|
||||
}
|
||||
info.Tracks = p.UptrackManager.ToProto()
|
||||
info.Tracks = p.UpTrackManager.ToProto()
|
||||
|
||||
return info
|
||||
}
|
||||
@@ -416,7 +416,7 @@ func (p *ParticipantImpl) AddICECandidate(candidate webrtc.ICECandidateInit, tar
|
||||
|
||||
func (p *ParticipantImpl) Start() {
|
||||
p.once.Do(func() {
|
||||
p.UptrackManager.Start()
|
||||
p.UpTrackManager.Start()
|
||||
go p.rtcpSendWorker()
|
||||
go p.downTracksRTCPWorker()
|
||||
})
|
||||
@@ -437,7 +437,7 @@ func (p *ParticipantImpl) Close(sendLeave bool) error {
|
||||
})
|
||||
}
|
||||
|
||||
p.UptrackManager.Close()
|
||||
p.UpTrackManager.Close()
|
||||
|
||||
p.pendingTracksLock.Lock()
|
||||
p.pendingTracks = make(map[string]*pendingTrackInfo)
|
||||
@@ -449,14 +449,14 @@ func (p *ParticipantImpl) Close(sendLeave bool) error {
|
||||
disallowedSubscriptions[trackID] = publisherID
|
||||
}
|
||||
|
||||
// remove all downtracks
|
||||
var downtracksToClose []*sfu.DownTrack
|
||||
// remove all down tracks
|
||||
var downTracksToClose []*sfu.DownTrack
|
||||
for _, st := range p.subscribedTracks {
|
||||
downtracksToClose = append(downtracksToClose, st.DownTrack())
|
||||
downTracksToClose = append(downTracksToClose, st.DownTrack())
|
||||
}
|
||||
p.lock.Unlock()
|
||||
|
||||
for _, dt := range downtracksToClose {
|
||||
for _, dt := range downTracksToClose {
|
||||
dt.Close()
|
||||
}
|
||||
|
||||
@@ -812,7 +812,7 @@ func (p *ParticipantImpl) RemoveSubscribedTrack(subTrack types.SubscribedTrack)
|
||||
Message: &livekit.SignalResponse_SpeakersChanged{
|
||||
SpeakersChanged: &livekit.SpeakersChanged{
|
||||
Speakers: []*livekit.SpeakerInfo{
|
||||
&livekit.SpeakerInfo{
|
||||
{
|
||||
Sid: string(subTrack.PublisherID()),
|
||||
Level: 0,
|
||||
Active: false,
|
||||
@@ -848,13 +848,13 @@ func (p *ParticipantImpl) SubscriptionPermissionUpdate(publisherID livekit.Parti
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) setupUptrackManager() {
|
||||
p.UptrackManager = NewUptrackManager(UptrackManagerParams{
|
||||
func (p *ParticipantImpl) setupUpTrackManager() {
|
||||
p.UpTrackManager = NewUpTrackManager(UpTrackManagerParams{
|
||||
SID: p.params.SID,
|
||||
Logger: p.params.Logger,
|
||||
})
|
||||
|
||||
p.UptrackManager.OnPublishedTrackUpdated(func(track types.MediaTrack, onlyIfReady bool) {
|
||||
p.UpTrackManager.OnPublishedTrackUpdated(func(track types.MediaTrack, onlyIfReady bool) {
|
||||
if onlyIfReady && !p.IsReady() {
|
||||
return
|
||||
}
|
||||
@@ -864,7 +864,7 @@ func (p *ParticipantImpl) setupUptrackManager() {
|
||||
}
|
||||
})
|
||||
|
||||
p.UptrackManager.OnUptrackManagerClose(p.onUptrackManagerClose)
|
||||
p.UpTrackManager.OnUpTrackManagerClose(p.onUpTrackManagerClose)
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) sendIceCandidate(c *webrtc.ICECandidate, target livekit.SignalTarget) {
|
||||
@@ -1070,7 +1070,7 @@ func (p *ParticipantImpl) downTracksRTCPWorker() {
|
||||
if err == io.EOF || err == io.ErrClosedPipe {
|
||||
return
|
||||
}
|
||||
logger.Errorw("could not send downtrack reports", err)
|
||||
logger.Errorw("could not send down track reports", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1241,9 +1241,9 @@ func (p *ParticipantImpl) addPendingTrack(req *livekit.AddTrackRequest) *livekit
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) setTrackMuted(trackID livekit.TrackID, muted bool) {
|
||||
track := p.UptrackManager.SetPublishedTrackMuted(trackID, muted)
|
||||
track := p.UpTrackManager.SetPublishedTrackMuted(trackID, muted)
|
||||
if track != nil {
|
||||
// handled in UptrackManager for a published track, no need to update state of pending track
|
||||
// handled in UpTrackManager for a published track, no need to update state of pending track
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1348,7 +1348,7 @@ func (p *ParticipantImpl) mediaTrackReceived(track *webrtc.TrackRemote, rtpRecei
|
||||
mt.OnSubscribedMaxQualityChange(p.onSubscribedMaxQualityChange)
|
||||
|
||||
// add to published and clean up pending
|
||||
p.UptrackManager.AddPublishedTrack(mt)
|
||||
p.UpTrackManager.AddPublishedTrack(mt)
|
||||
delete(p.pendingTracks, signalCid)
|
||||
|
||||
newTrack = true
|
||||
@@ -1398,7 +1398,7 @@ func (p *ParticipantImpl) hasPendingMigratedTrack() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) onUptrackManagerClose() {
|
||||
func (p *ParticipantImpl) onUpTrackManagerClose() {
|
||||
close(p.rtcpCh)
|
||||
}
|
||||
|
||||
@@ -1505,7 +1505,7 @@ func (p *ParticipantImpl) DebugInfo() map[string]interface{} {
|
||||
p.pendingTracksLock.RUnlock()
|
||||
info["PendingTracks"] = pendingTrackInfo
|
||||
|
||||
info["UptrackManager"] = p.UptrackManager.DebugInfo()
|
||||
info["UpTrackManager"] = p.UpTrackManager.DebugInfo()
|
||||
|
||||
subscribedTrackInfo := make(map[livekit.TrackID]interface{})
|
||||
p.lock.RLock()
|
||||
|
||||
@@ -80,15 +80,15 @@ func TestTrackPublishing(t *testing.T) {
|
||||
p.OnTrackPublished(func(p types.LocalParticipant, track types.MediaTrack) {
|
||||
published = true
|
||||
})
|
||||
p.UptrackManager.AddPublishedTrack(track)
|
||||
p.UpTrackManager.AddPublishedTrack(track)
|
||||
p.handleTrackPublished(track)
|
||||
|
||||
require.True(t, published)
|
||||
require.False(t, updated)
|
||||
require.Len(t, p.UptrackManager.publishedTracks, 1)
|
||||
require.Len(t, p.UpTrackManager.publishedTracks, 1)
|
||||
|
||||
track.AddOnCloseArgsForCall(0)()
|
||||
require.Len(t, p.UptrackManager.publishedTracks, 0)
|
||||
require.Len(t, p.UpTrackManager.publishedTracks, 0)
|
||||
require.True(t, updated)
|
||||
})
|
||||
|
||||
@@ -137,7 +137,7 @@ func TestTrackPublishing(t *testing.T) {
|
||||
track := &typesfakes.FakeLocalMediaTrack{}
|
||||
track.SignalCidReturns("cid")
|
||||
// directly add to publishedTracks without lock - for testing purpose only
|
||||
p.UptrackManager.publishedTracks["cid"] = track
|
||||
p.UpTrackManager.publishedTracks["cid"] = track
|
||||
|
||||
p.AddTrack(&livekit.AddTrackRequest{
|
||||
Cid: "cid",
|
||||
@@ -154,7 +154,7 @@ func TestTrackPublishing(t *testing.T) {
|
||||
track := &typesfakes.FakeLocalMediaTrack{}
|
||||
track.SdpCidReturns("cid")
|
||||
// directly add to publishedTracks without lock - for testing purpose only
|
||||
p.UptrackManager.publishedTracks["cid"] = track
|
||||
p.UpTrackManager.publishedTracks["cid"] = track
|
||||
|
||||
p.AddTrack(&livekit.AddTrackRequest{
|
||||
Cid: "cid",
|
||||
@@ -203,7 +203,7 @@ func TestDisconnectTiming(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
track := &typesfakes.FakeMediaTrack{}
|
||||
p.UptrackManager.AddPublishedTrack(track)
|
||||
p.UpTrackManager.AddPublishedTrack(track)
|
||||
p.handleTrackPublished(track)
|
||||
|
||||
// close channel and then try to Negotiate
|
||||
@@ -284,30 +284,30 @@ func TestConnectionQuality(t *testing.T) {
|
||||
|
||||
t.Run("smooth sailing", func(t *testing.T) {
|
||||
p := newParticipantForTest("test")
|
||||
p.UptrackManager.publishedTracks["video"] = testPublishedVideoTrack(2, 3, 3)
|
||||
p.UptrackManager.publishedTracks["audio"] = testPublishedAudioTrack(1000, 0)
|
||||
p.UpTrackManager.publishedTracks["video"] = testPublishedVideoTrack(2, 3, 3)
|
||||
p.UpTrackManager.publishedTracks["audio"] = testPublishedAudioTrack(1000, 0)
|
||||
|
||||
require.Equal(t, livekit.ConnectionQuality_EXCELLENT, p.GetConnectionQuality().GetQuality())
|
||||
})
|
||||
|
||||
t.Run("reduced publishing", func(t *testing.T) {
|
||||
p := newParticipantForTest("test")
|
||||
p.UptrackManager.publishedTracks["video"] = testPublishedVideoTrack(3, 2, 3)
|
||||
p.UptrackManager.publishedTracks["audio"] = testPublishedAudioTrack(1000, 100)
|
||||
p.UpTrackManager.publishedTracks["video"] = testPublishedVideoTrack(3, 2, 3)
|
||||
p.UpTrackManager.publishedTracks["audio"] = testPublishedAudioTrack(1000, 100)
|
||||
|
||||
require.Equal(t, livekit.ConnectionQuality_GOOD, p.GetConnectionQuality().GetQuality())
|
||||
})
|
||||
|
||||
t.Run("audio smooth publishing", func(t *testing.T) {
|
||||
p := newParticipantForTest("test")
|
||||
p.UptrackManager.publishedTracks["audio"] = testPublishedAudioTrack(1000, 10)
|
||||
p.UpTrackManager.publishedTracks["audio"] = testPublishedAudioTrack(1000, 10)
|
||||
|
||||
require.Equal(t, livekit.ConnectionQuality_EXCELLENT, p.GetConnectionQuality().GetQuality())
|
||||
})
|
||||
|
||||
t.Run("audio reduced publishing", func(t *testing.T) {
|
||||
p := newParticipantForTest("test")
|
||||
p.UptrackManager.publishedTracks["audio"] = testPublishedAudioTrack(1000, 100)
|
||||
p.UpTrackManager.publishedTracks["audio"] = testPublishedAudioTrack(1000, 100)
|
||||
|
||||
require.Equal(t, livekit.ConnectionQuality_GOOD, p.GetConnectionQuality().GetQuality())
|
||||
})
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/bep/debounce"
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/pion/interceptor"
|
||||
@@ -16,6 +15,7 @@ import (
|
||||
"github.com/pion/webrtc/v3"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
serverlogger "github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
"github.com/livekit/livekit-server/pkg/sfu"
|
||||
"github.com/livekit/livekit-server/pkg/telemetry"
|
||||
@@ -352,10 +352,10 @@ func (t *PCTransport) preparePC(previousAnswer webrtc.SessionDescription) error
|
||||
return err
|
||||
}
|
||||
|
||||
// for pion generate unmatched sdp, it always append data channel to last m-lines,
|
||||
// for pion generate unmatched sdp, it always appends data channel to last m-lines,
|
||||
// that is not consistent with our subscribe offer which data channel is first m-lines,
|
||||
// so use a dumb pc to negotiate sdp with only data channel then the data channel will
|
||||
// sticky to first m-lines(subsequent sdp negotiation will keep m-lines's sequence)
|
||||
// sticky to first m-lines(subsequent sdp negotiation will keep m-lines' sequence)
|
||||
offer, err := t.pc.CreateOffer(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -375,7 +375,7 @@ func (t *PCTransport) preparePC(previousAnswer webrtc.SessionDescription) error
|
||||
}
|
||||
|
||||
// replace client's fingerprint into dump pc's answer, for pion's dtls process, it will
|
||||
// keep the firgerprint at first call of SetRemoteDescription, if dumb pc and client pc use
|
||||
// keep the fingerprint at first call of SetRemoteDescription, if dumb pc and client pc use
|
||||
// different fingerprint, that will cause pion denied dtls data after handshake with client
|
||||
// complete (can't pass fingerprint change).
|
||||
// in this step, we don't established connection with dump pc(no candidate swap), just use
|
||||
@@ -481,7 +481,7 @@ func getMidValue(media *sdp.MediaDescription) string {
|
||||
}
|
||||
|
||||
func extractFingerprint(desc *sdp.SessionDescription) (string, string, error) {
|
||||
fingerprints := []string{}
|
||||
fingerprints := make([]string, 0)
|
||||
|
||||
if fingerprint, haveFingerprint := desc.Attribute("fingerprint"); haveFingerprint {
|
||||
fingerprints = append(fingerprints, fingerprint)
|
||||
|
||||
@@ -135,7 +135,7 @@ type LocalParticipant interface {
|
||||
SetPreviousAnswer(previous *webrtc.SessionDescription)
|
||||
}
|
||||
|
||||
// Room is a container of participants, and can provide room level actions
|
||||
// Room is a container of participants, and can provide room-level actions
|
||||
//counterfeiter:generate . Room
|
||||
type Room interface {
|
||||
Name() livekit.RoomName
|
||||
|
||||
@@ -107,8 +107,8 @@ func getHeaderExtensionID(extensions []interceptor.RTPHeaderExtension, extension
|
||||
func (u *UnhandleSimulcastInterceptor) BindRemoteStream(info *interceptor.StreamInfo, reader interceptor.RTPReader) interceptor.RTPReader {
|
||||
if t, ok := u.simTracks[info.SSRC]; ok {
|
||||
// if we support fec for simulcast streams at future, should get rsid extensions
|
||||
midExtensionID := getHeaderExtensionID(info.RTPHeaderExtensions, webrtc.RTPHeaderExtensionCapability{sdp.SDESMidURI})
|
||||
streamIDExtensionID := getHeaderExtensionID(info.RTPHeaderExtensions, webrtc.RTPHeaderExtensionCapability{sdp.SDESRTPStreamIDURI})
|
||||
midExtensionID := getHeaderExtensionID(info.RTPHeaderExtensions, webrtc.RTPHeaderExtensionCapability{URI: sdp.SDESMidURI})
|
||||
streamIDExtensionID := getHeaderExtensionID(info.RTPHeaderExtensions, webrtc.RTPHeaderExtensionCapability{URI: sdp.SDESRTPStreamIDURI})
|
||||
if midExtensionID == 0 || streamIDExtensionID == 0 {
|
||||
return reader
|
||||
}
|
||||
|
||||
+31
-31
@@ -10,13 +10,13 @@ import (
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
)
|
||||
|
||||
type UptrackManagerParams struct {
|
||||
type UpTrackManagerParams struct {
|
||||
SID livekit.ParticipantID
|
||||
Logger logger.Logger
|
||||
}
|
||||
|
||||
type UptrackManager struct {
|
||||
params UptrackManagerParams
|
||||
type UpTrackManager struct {
|
||||
params UpTrackManagerParams
|
||||
|
||||
closed bool
|
||||
|
||||
@@ -34,18 +34,18 @@ type UptrackManager struct {
|
||||
onTrackUpdated func(track types.MediaTrack, onlyIfReady bool)
|
||||
}
|
||||
|
||||
func NewUptrackManager(params UptrackManagerParams) *UptrackManager {
|
||||
return &UptrackManager{
|
||||
func NewUpTrackManager(params UpTrackManagerParams) *UpTrackManager {
|
||||
return &UpTrackManager{
|
||||
params: params,
|
||||
publishedTracks: make(map[livekit.TrackID]types.MediaTrack, 0),
|
||||
pendingSubscriptions: make(map[livekit.TrackID][]livekit.ParticipantID),
|
||||
}
|
||||
}
|
||||
|
||||
func (u *UptrackManager) Start() {
|
||||
func (u *UpTrackManager) Start() {
|
||||
}
|
||||
|
||||
func (u *UptrackManager) Close() {
|
||||
func (u *UpTrackManager) Close() {
|
||||
u.lock.Lock()
|
||||
u.closed = true
|
||||
|
||||
@@ -62,11 +62,11 @@ func (u *UptrackManager) Close() {
|
||||
}
|
||||
}
|
||||
|
||||
func (u *UptrackManager) OnUptrackManagerClose(f func()) {
|
||||
func (u *UpTrackManager) OnUpTrackManagerClose(f func()) {
|
||||
u.onClose = f
|
||||
}
|
||||
|
||||
func (u *UptrackManager) ToProto() []*livekit.TrackInfo {
|
||||
func (u *UpTrackManager) ToProto() []*livekit.TrackInfo {
|
||||
u.lock.RLock()
|
||||
defer u.lock.RUnlock()
|
||||
|
||||
@@ -78,12 +78,12 @@ func (u *UptrackManager) ToProto() []*livekit.TrackInfo {
|
||||
return trackInfos
|
||||
}
|
||||
|
||||
func (u *UptrackManager) OnPublishedTrackUpdated(f func(track types.MediaTrack, onlyIfReady bool)) {
|
||||
func (u *UpTrackManager) OnPublishedTrackUpdated(f func(track types.MediaTrack, onlyIfReady bool)) {
|
||||
u.onTrackUpdated = f
|
||||
}
|
||||
|
||||
// AddSubscriber subscribes op to all publishedTracks
|
||||
func (u *UptrackManager) AddSubscriber(sub types.LocalParticipant, params types.AddSubscriberParams) (int, error) {
|
||||
func (u *UpTrackManager) AddSubscriber(sub types.LocalParticipant, params types.AddSubscriberParams) (int, error) {
|
||||
var tracks []types.MediaTrack
|
||||
if params.AllTracks {
|
||||
tracks = u.GetPublishedTracks()
|
||||
@@ -127,7 +127,7 @@ func (u *UptrackManager) AddSubscriber(sub types.LocalParticipant, params types.
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (u *UptrackManager) RemoveSubscriber(sub types.LocalParticipant, trackID livekit.TrackID) {
|
||||
func (u *UpTrackManager) RemoveSubscriber(sub types.LocalParticipant, trackID livekit.TrackID) {
|
||||
track := u.GetPublishedTrack(trackID)
|
||||
if track != nil {
|
||||
track.RemoveSubscriber(sub.ID())
|
||||
@@ -138,7 +138,7 @@ func (u *UptrackManager) RemoveSubscriber(sub types.LocalParticipant, trackID li
|
||||
u.lock.Unlock()
|
||||
}
|
||||
|
||||
func (u *UptrackManager) SetPublishedTrackMuted(trackID livekit.TrackID, muted bool) types.MediaTrack {
|
||||
func (u *UpTrackManager) SetPublishedTrackMuted(trackID livekit.TrackID, muted bool) types.MediaTrack {
|
||||
u.lock.RLock()
|
||||
track := u.publishedTracks[trackID]
|
||||
u.lock.RUnlock()
|
||||
@@ -158,14 +158,14 @@ func (u *UptrackManager) SetPublishedTrackMuted(trackID livekit.TrackID, muted b
|
||||
return track
|
||||
}
|
||||
|
||||
func (u *UptrackManager) GetPublishedTrack(trackID livekit.TrackID) types.MediaTrack {
|
||||
func (u *UpTrackManager) GetPublishedTrack(trackID livekit.TrackID) types.MediaTrack {
|
||||
u.lock.RLock()
|
||||
defer u.lock.RUnlock()
|
||||
|
||||
return u.getPublishedTrack(trackID)
|
||||
}
|
||||
|
||||
func (u *UptrackManager) GetPublishedTracks() []types.MediaTrack {
|
||||
func (u *UpTrackManager) GetPublishedTracks() []types.MediaTrack {
|
||||
u.lock.RLock()
|
||||
defer u.lock.RUnlock()
|
||||
|
||||
@@ -176,7 +176,7 @@ func (u *UptrackManager) GetPublishedTracks() []types.MediaTrack {
|
||||
return tracks
|
||||
}
|
||||
|
||||
func (u *UptrackManager) UpdateSubscriptionPermissions(
|
||||
func (u *UpTrackManager) UpdateSubscriptionPermissions(
|
||||
permissions *livekit.UpdateSubscriptionPermissions,
|
||||
resolver func(participantID livekit.ParticipantID) types.LocalParticipant,
|
||||
) error {
|
||||
@@ -192,7 +192,7 @@ func (u *UptrackManager) UpdateSubscriptionPermissions(
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *UptrackManager) UpdateVideoLayers(updateVideoLayers *livekit.UpdateVideoLayers) error {
|
||||
func (u *UpTrackManager) UpdateVideoLayers(updateVideoLayers *livekit.UpdateVideoLayers) error {
|
||||
track := u.GetPublishedTrack(livekit.TrackID(updateVideoLayers.TrackSid))
|
||||
if track == nil {
|
||||
u.params.Logger.Warnw("could not find track", nil, "trackID", livekit.TrackID(updateVideoLayers.TrackSid))
|
||||
@@ -203,7 +203,7 @@ func (u *UptrackManager) UpdateVideoLayers(updateVideoLayers *livekit.UpdateVide
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *UptrackManager) UpdateSubscribedQuality(nodeID string, trackID livekit.TrackID, maxQuality livekit.VideoQuality) error {
|
||||
func (u *UpTrackManager) UpdateSubscribedQuality(nodeID string, trackID livekit.TrackID, maxQuality livekit.VideoQuality) error {
|
||||
track := u.GetPublishedTrack(trackID)
|
||||
if track == nil {
|
||||
u.params.Logger.Warnw("could not find track", nil, "trackID", trackID)
|
||||
@@ -214,7 +214,7 @@ func (u *UptrackManager) UpdateSubscribedQuality(nodeID string, trackID livekit.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *UptrackManager) UpdateMediaLoss(nodeID string, trackID livekit.TrackID, fractionalLoss uint32) error {
|
||||
func (u *UpTrackManager) UpdateMediaLoss(nodeID string, trackID livekit.TrackID, fractionalLoss uint32) error {
|
||||
track := u.GetPublishedTrack(trackID)
|
||||
if track == nil {
|
||||
u.params.Logger.Warnw("could not find track", nil, "trackID", trackID)
|
||||
@@ -225,7 +225,7 @@ func (u *UptrackManager) UpdateMediaLoss(nodeID string, trackID livekit.TrackID,
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *UptrackManager) AddPublishedTrack(track types.MediaTrack) {
|
||||
func (u *UpTrackManager) AddPublishedTrack(track types.MediaTrack) {
|
||||
u.lock.Lock()
|
||||
if _, ok := u.publishedTracks[track.ID()]; !ok {
|
||||
u.publishedTracks[track.ID()] = track
|
||||
@@ -258,16 +258,16 @@ func (u *UptrackManager) AddPublishedTrack(track types.MediaTrack) {
|
||||
})
|
||||
}
|
||||
|
||||
func (u *UptrackManager) RemovePublishedTrack(track types.MediaTrack) {
|
||||
func (u *UpTrackManager) RemovePublishedTrack(track types.MediaTrack) {
|
||||
track.RemoveAllSubscribers()
|
||||
}
|
||||
|
||||
// should be called with lock held
|
||||
func (u *UptrackManager) getPublishedTrack(trackID livekit.TrackID) types.MediaTrack {
|
||||
func (u *UpTrackManager) getPublishedTrack(trackID livekit.TrackID) types.MediaTrack {
|
||||
return u.publishedTracks[trackID]
|
||||
}
|
||||
|
||||
func (u *UptrackManager) updateSubscriptionPermissions(permissions *livekit.UpdateSubscriptionPermissions) {
|
||||
func (u *UpTrackManager) updateSubscriptionPermissions(permissions *livekit.UpdateSubscriptionPermissions) {
|
||||
// every update overrides the existing
|
||||
|
||||
// all_participants takes precedence
|
||||
@@ -284,7 +284,7 @@ func (u *UptrackManager) updateSubscriptionPermissions(permissions *livekit.Upda
|
||||
}
|
||||
}
|
||||
|
||||
func (u *UptrackManager) hasPermission(trackID livekit.TrackID, subscriberID livekit.ParticipantID) bool {
|
||||
func (u *UpTrackManager) hasPermission(trackID livekit.TrackID, subscriberID livekit.ParticipantID) bool {
|
||||
if u.subscriptionPermissions == nil {
|
||||
return true
|
||||
}
|
||||
@@ -307,12 +307,12 @@ func (u *UptrackManager) hasPermission(trackID livekit.TrackID, subscriberID liv
|
||||
return false
|
||||
}
|
||||
|
||||
func (u *UptrackManager) getAllowedSubscribers(trackID livekit.TrackID) []livekit.ParticipantID {
|
||||
func (u *UpTrackManager) getAllowedSubscribers(trackID livekit.TrackID) []livekit.ParticipantID {
|
||||
if u.subscriptionPermissions == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
allowed := []livekit.ParticipantID{}
|
||||
allowed := make([]livekit.ParticipantID, 0)
|
||||
for subscriberID, perms := range u.subscriptionPermissions {
|
||||
if perms.AllTracks {
|
||||
allowed = append(allowed, subscriberID)
|
||||
@@ -330,7 +330,7 @@ func (u *UptrackManager) getAllowedSubscribers(trackID livekit.TrackID) []liveki
|
||||
return allowed
|
||||
}
|
||||
|
||||
func (u *UptrackManager) maybeAddPendingSubscription(trackID livekit.TrackID, sub types.LocalParticipant) {
|
||||
func (u *UpTrackManager) maybeAddPendingSubscription(trackID livekit.TrackID, sub types.LocalParticipant) {
|
||||
subscriberID := sub.ID()
|
||||
|
||||
pending := u.pendingSubscriptions[trackID]
|
||||
@@ -345,7 +345,7 @@ func (u *UptrackManager) maybeAddPendingSubscription(trackID livekit.TrackID, su
|
||||
go sub.SubscriptionPermissionUpdate(u.params.SID, trackID, false)
|
||||
}
|
||||
|
||||
func (u *UptrackManager) maybeRemovePendingSubscription(trackID livekit.TrackID, sub types.LocalParticipant) {
|
||||
func (u *UpTrackManager) maybeRemovePendingSubscription(trackID livekit.TrackID, sub types.LocalParticipant) {
|
||||
subscriberID := sub.ID()
|
||||
|
||||
pending := u.pendingSubscriptions[trackID]
|
||||
@@ -362,7 +362,7 @@ func (u *UptrackManager) maybeRemovePendingSubscription(trackID livekit.TrackID,
|
||||
}
|
||||
}
|
||||
|
||||
func (u *UptrackManager) processPendingSubscriptions(resolver func(participantID livekit.ParticipantID) types.LocalParticipant) {
|
||||
func (u *UpTrackManager) processPendingSubscriptions(resolver func(participantID livekit.ParticipantID) types.LocalParticipant) {
|
||||
updatedPendingSubscriptions := make(map[livekit.TrackID][]livekit.ParticipantID)
|
||||
for trackID, pending := range u.pendingSubscriptions {
|
||||
track := u.getPublishedTrack(trackID)
|
||||
@@ -402,7 +402,7 @@ func (u *UptrackManager) processPendingSubscriptions(resolver func(participantID
|
||||
u.pendingSubscriptions = updatedPendingSubscriptions
|
||||
}
|
||||
|
||||
func (u *UptrackManager) maybeRevokeSubscriptions(resolver func(participantID livekit.ParticipantID) types.LocalParticipant) {
|
||||
func (u *UpTrackManager) maybeRevokeSubscriptions(resolver func(participantID livekit.ParticipantID) types.LocalParticipant) {
|
||||
for _, track := range u.publishedTracks {
|
||||
trackID := track.ID()
|
||||
allowed := u.getAllowedSubscribers(trackID)
|
||||
@@ -426,7 +426,7 @@ func (u *UptrackManager) maybeRevokeSubscriptions(resolver func(participantID li
|
||||
}
|
||||
}
|
||||
|
||||
func (u *UptrackManager) DebugInfo() map[string]interface{} {
|
||||
func (u *UpTrackManager) DebugInfo() map[string]interface{} {
|
||||
info := map[string]interface{}{}
|
||||
publishedTrackInfo := make(map[livekit.TrackID]interface{})
|
||||
|
||||
|
||||
@@ -3,14 +3,15 @@ package rtc
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types/typesfakes"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types/typesfakes"
|
||||
)
|
||||
|
||||
func TestUpdateSubscriptionPermissions(t *testing.T) {
|
||||
t.Run("updates permissions", func(t *testing.T) {
|
||||
um := NewUptrackManager(UptrackManagerParams{})
|
||||
um := NewUpTrackManager(UpTrackManagerParams{})
|
||||
|
||||
tra := &typesfakes.FakeMediaTrack{}
|
||||
tra.IDReturns("audio")
|
||||
@@ -85,7 +86,7 @@ func TestUpdateSubscriptionPermissions(t *testing.T) {
|
||||
|
||||
func TestPermissions(t *testing.T) {
|
||||
t.Run("checks permissions", func(t *testing.T) {
|
||||
um := NewUptrackManager(UptrackManagerParams{})
|
||||
um := NewUpTrackManager(UpTrackManagerParams{})
|
||||
|
||||
tra := &typesfakes.FakeMediaTrack{}
|
||||
tra.IDReturns("audio")
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package rtc
|
||||
|
||||
import (
|
||||
"github.com/livekit/livekit-server/pkg/sfu"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/sfu"
|
||||
)
|
||||
|
||||
// wrapper around WebRTC receiver, overriding its ID
|
||||
|
||||
Reference in New Issue
Block a user