Use a queue for add/remove subscribe operations. (#797)
* Use a queue for add/remove subscribe operations. If subscribe/unsubscribe happens very quickly, the subscription state gets mixed up as things are keyed off of subscriberID. Use a queue of subscribe operations and process it serially. * set up callback for down track added * move the queue on unexpected type * move the queue if removeSubscirber does not have a subscribed track
This commit is contained in:
@@ -91,6 +91,7 @@ func NewMediaTrackReceiver(params MediaTrackReceiverParams) *MediaTrackReceiver
|
||||
Telemetry: params.Telemetry,
|
||||
Logger: params.Logger,
|
||||
})
|
||||
t.MediaTrackSubscriptions.OnDownTrackCreated(t.onDownTrackCreated)
|
||||
|
||||
if t.trackInfo.Muted {
|
||||
t.SetMuted(true)
|
||||
@@ -381,17 +382,11 @@ func (t *MediaTrackReceiver) AddSubscriber(sub types.LocalParticipant) error {
|
||||
streamId = PackStreamID(t.PublisherID(), t.ID())
|
||||
}
|
||||
|
||||
downTrack, err := t.MediaTrackSubscriptions.AddSubscriber(sub, NewWrappedReceiver(receivers, t.ID(), streamId, potentialCodecs))
|
||||
err := t.MediaTrackSubscriptions.AddSubscriber(sub, NewWrappedReceiver(receivers, t.ID(), streamId, potentialCodecs))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if downTrack != nil {
|
||||
if t.Kind() == livekit.TrackType_AUDIO {
|
||||
downTrack.AddReceiverReportListener(t.handleMaxLossFeedback)
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -550,6 +545,12 @@ func (t *MediaTrackReceiver) GetAudioLevel() (float64, bool) {
|
||||
return receiver.GetAudioLevel()
|
||||
}
|
||||
|
||||
func (t *MediaTrackReceiver) onDownTrackCreated(downTrack *sfu.DownTrack) {
|
||||
if t.Kind() == livekit.TrackType_AUDIO {
|
||||
downTrack.AddReceiverReportListener(t.handleMaxLossFeedback)
|
||||
}
|
||||
}
|
||||
|
||||
// handles max loss for audio streams
|
||||
func (t *MediaTrackReceiver) handleMaxLossFeedback(_ *sfu.DownTrack, report *rtcp.ReceiverReport) {
|
||||
t.downFracLostLock.Lock()
|
||||
|
||||
Reference in New Issue
Block a user