uptrackmanager reuse (#318)
* WIP commit * Remove the double lock * Remove unused variable * WIP commit * Fix test * WIP commit * Split out MediaTrackReceiver * Address comments from David
This commit is contained in:
+34
-26
@@ -23,7 +23,6 @@ import (
|
||||
"github.com/livekit/livekit-server/pkg/routing"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
"github.com/livekit/livekit-server/pkg/sfu"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/twcc"
|
||||
"github.com/livekit/livekit-server/pkg/telemetry"
|
||||
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
|
||||
"github.com/livekit/livekit-server/version"
|
||||
@@ -74,10 +73,7 @@ type ParticipantImpl struct {
|
||||
// JSON encoded metadata to pass to clients
|
||||
metadata string
|
||||
|
||||
// hold reference for MediaTrack
|
||||
twcc *twcc.Responder
|
||||
|
||||
*UptrackManager
|
||||
*LocalParticipant
|
||||
|
||||
// tracks the current participant is subscribed to, map of sid => DownTrack
|
||||
subscribedTracks map[livekit.TrackID]types.SubscribedTrack
|
||||
@@ -189,7 +185,7 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
||||
|
||||
p.subscriber.OnStreamStateChange(p.onStreamStateChange)
|
||||
|
||||
p.setupUptrackManager()
|
||||
p.setupLocalParticipant()
|
||||
|
||||
return p, nil
|
||||
}
|
||||
@@ -243,7 +239,7 @@ func (p *ParticipantImpl) ToProto() *livekit.ParticipantInfo {
|
||||
Hidden: p.Hidden(),
|
||||
Recorder: p.IsRecorder(),
|
||||
}
|
||||
info.Tracks = p.UptrackManager.ToProto()
|
||||
info.Tracks = p.LocalParticipant.ToProto()
|
||||
|
||||
return info
|
||||
}
|
||||
@@ -341,7 +337,7 @@ func (p *ParticipantImpl) HandleOffer(sdp webrtc.SessionDescription) (answer web
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) AddMigratedTrack(cid string, ti *livekit.TrackInfo) {
|
||||
p.UptrackManager.AddMigratedTrack(cid, ti)
|
||||
p.LocalParticipant.AddMigratedTrack(cid, ti)
|
||||
}
|
||||
|
||||
// AddTrack is called when client intends to publish track.
|
||||
@@ -355,7 +351,7 @@ func (p *ParticipantImpl) AddTrack(req *livekit.AddTrackRequest) {
|
||||
return
|
||||
}
|
||||
|
||||
ti := p.UptrackManager.AddTrack(req)
|
||||
ti := p.LocalParticipant.AddTrack(req)
|
||||
if ti == nil {
|
||||
return
|
||||
}
|
||||
@@ -398,7 +394,7 @@ func (p *ParticipantImpl) AddICECandidate(candidate webrtc.ICECandidateInit, tar
|
||||
|
||||
func (p *ParticipantImpl) Start() {
|
||||
p.once.Do(func() {
|
||||
p.UptrackManager.Start()
|
||||
p.LocalParticipant.Start()
|
||||
go p.downTracksRTCPWorker()
|
||||
})
|
||||
}
|
||||
@@ -416,7 +412,7 @@ func (p *ParticipantImpl) Close() error {
|
||||
},
|
||||
})
|
||||
|
||||
p.UptrackManager.Close()
|
||||
p.LocalParticipant.Close()
|
||||
|
||||
p.lock.Lock()
|
||||
disallowedSubscriptions := make(map[livekit.TrackID]livekit.ParticipantID)
|
||||
@@ -471,7 +467,7 @@ func (p *ParticipantImpl) SetMigrateState(s types.MigrateState) {
|
||||
var pendingOffer *webrtc.SessionDescription
|
||||
p.migrateState.Store(s)
|
||||
if s == types.MigrateStateSync {
|
||||
if !p.UptrackManager.HasPendingMigratedTrack() {
|
||||
if !p.LocalParticipant.HasPendingMigratedTrack() {
|
||||
p.migrateState.Store(types.MigrateComplete)
|
||||
}
|
||||
pendingOffer = p.pendingOffer
|
||||
@@ -636,12 +632,12 @@ func (p *ParticipantImpl) SetTrackMuted(trackID livekit.TrackID, muted bool, fro
|
||||
})
|
||||
}
|
||||
|
||||
p.UptrackManager.SetTrackMuted(trackID, muted)
|
||||
p.LocalParticipant.SetTrackMuted(trackID, muted)
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) GetConnectionQuality() *livekit.ConnectionQualityInfo {
|
||||
// avg loss across all tracks, weigh published the same as subscribed
|
||||
scores, numTracks := p.UptrackManager.GetConnectionQuality()
|
||||
scores, numTracks := p.LocalParticipant.GetConnectionQuality()
|
||||
|
||||
p.lock.RLock()
|
||||
for _, subTrack := range p.subscribedTracks {
|
||||
@@ -812,8 +808,8 @@ func (p *ParticipantImpl) SubscriptionPermissionUpdate(publisherID livekit.Parti
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) setupUptrackManager() {
|
||||
p.UptrackManager = NewUptrackManager(UptrackManagerParams{
|
||||
func (p *ParticipantImpl) setupLocalParticipant() {
|
||||
p.LocalParticipant = NewLocalParticipant(LocalParticipantParams{
|
||||
Identity: p.params.Identity,
|
||||
SID: p.params.SID,
|
||||
Config: p.params.Config,
|
||||
@@ -823,16 +819,17 @@ func (p *ParticipantImpl) setupUptrackManager() {
|
||||
Logger: p.params.Logger,
|
||||
})
|
||||
|
||||
p.UptrackManager.OnTrackPublished(func(track types.PublishedTrack) {
|
||||
if !p.UptrackManager.HasPendingMigratedTrack() {
|
||||
p.LocalParticipant.OnTrackPublished(func(track types.PublishedTrack) {
|
||||
if !p.LocalParticipant.HasPendingMigratedTrack() {
|
||||
p.SetMigrateState(types.MigrateComplete)
|
||||
}
|
||||
|
||||
if p.onTrackPublished != nil {
|
||||
p.onTrackPublished(p, track)
|
||||
}
|
||||
})
|
||||
|
||||
p.UptrackManager.OnTrackUpdated(func(track types.PublishedTrack, onlyIfReady bool) {
|
||||
p.LocalParticipant.OnTrackUpdated(func(track types.PublishedTrack, onlyIfReady bool) {
|
||||
if onlyIfReady && !p.IsReady() {
|
||||
return
|
||||
}
|
||||
@@ -842,13 +839,13 @@ func (p *ParticipantImpl) setupUptrackManager() {
|
||||
}
|
||||
})
|
||||
|
||||
p.UptrackManager.OnWriteRTCP(func(pkts []rtcp.Packet) {
|
||||
p.LocalParticipant.OnWriteRTCP(func(pkts []rtcp.Packet) {
|
||||
if err := p.publisher.pc.WriteRTCP(pkts); err != nil {
|
||||
p.params.Logger.Errorw("could not write RTCP to participant", err)
|
||||
}
|
||||
})
|
||||
|
||||
p.UptrackManager.OnSubscribedMaxQualityChange(p.onSubscribedMaxQualityChange)
|
||||
p.LocalParticipant.OnSubscribedMaxQualityChange(p.onSubscribedMaxQualityChange)
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) sendIceCandidate(c *webrtc.ICECandidate, target livekit.SignalTarget) {
|
||||
@@ -939,7 +936,18 @@ func (p *ParticipantImpl) onMediaTrack(track *webrtc.TrackRemote, rtpReceiver *w
|
||||
return
|
||||
}
|
||||
|
||||
p.UptrackManager.MediaTrackReceived(track, rtpReceiver, p)
|
||||
var mid string
|
||||
for _, tr := range p.publisher.pc.GetTransceivers() {
|
||||
if tr.Receiver() == rtpReceiver {
|
||||
mid = tr.Mid()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
publishedTrack, isNewTrack := p.LocalParticipant.MediaTrackReceived(track, rtpReceiver, mid)
|
||||
if !isNewTrack && publishedTrack != nil && p.IsReady() && p.onTrackUpdated != nil {
|
||||
p.onTrackUpdated(p, publishedTrack)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) onDataChannel(dc *webrtc.DataChannel) {
|
||||
@@ -1097,7 +1105,7 @@ func (p *ParticipantImpl) configureReceiverDTX() {
|
||||
// multiple audio tracks. At that point, there might be a need to
|
||||
// rely on something like order of tracks. TODO
|
||||
//
|
||||
enableDTX := p.UptrackManager.GetDTX()
|
||||
enableDTX := p.LocalParticipant.GetDTX()
|
||||
transceivers := p.publisher.pc.GetTransceivers()
|
||||
for _, transceiver := range transceivers {
|
||||
if transceiver.Kind() != webrtc.RTPCodecTypeAudio {
|
||||
@@ -1170,7 +1178,7 @@ func (p *ParticipantImpl) onStreamStateChange(update *sfu.StreamStateUpdate) err
|
||||
})
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) onSubscribedMaxQualityChange(trackID livekit.TrackID, subscribedQualities []*livekit.SubscribedQuality) error {
|
||||
func (p *ParticipantImpl) onSubscribedMaxQualityChange(trackID livekit.TrackID, subscribedQualities []*livekit.SubscribedQuality, _maxSubscribedQuality livekit.VideoQuality) error {
|
||||
if len(subscribedQualities) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -1193,7 +1201,7 @@ func (p *ParticipantImpl) DebugInfo() map[string]interface{} {
|
||||
"State": p.State().String(),
|
||||
}
|
||||
|
||||
uptrackManagerInfo := p.UptrackManager.DebugInfo()
|
||||
localParticipantInfo := p.LocalParticipant.DebugInfo()
|
||||
|
||||
subscribedTrackInfo := make(map[livekit.TrackID]interface{})
|
||||
p.lock.RLock()
|
||||
@@ -1204,7 +1212,7 @@ func (p *ParticipantImpl) DebugInfo() map[string]interface{} {
|
||||
}
|
||||
p.lock.RUnlock()
|
||||
|
||||
info["UptrackManager"] = uptrackManagerInfo
|
||||
info["LocalParticipant"] = localParticipantInfo
|
||||
info["SubscribedTracks"] = subscribedTrackInfo
|
||||
|
||||
return info
|
||||
|
||||
Reference in New Issue
Block a user