fix deadlocks in track subscription
This commit is contained in:
@@ -212,8 +212,11 @@ func (t *MediaTrack) AddSubscriber(sub types.Participant) error {
|
|||||||
t.subscribedTracks[sub.ID()] = subTrack
|
t.subscribedTracks[sub.ID()] = subTrack
|
||||||
|
|
||||||
t.receiver.AddDownTrack(downTrack, true)
|
t.receiver.AddDownTrack(downTrack, true)
|
||||||
sub.AddSubscribedTrack(t.params.ParticipantID, subTrack)
|
// since sub will lock, run it in a gorountine to avoid deadlocks
|
||||||
sub.Negotiate()
|
go func() {
|
||||||
|
sub.AddSubscribedTrack(t.params.ParticipantID, subTrack)
|
||||||
|
sub.Negotiate()
|
||||||
|
}()
|
||||||
|
|
||||||
t.params.Stats.AddSubscribedTrack(t.kind.String())
|
t.params.Stats.AddSubscribedTrack(t.kind.String())
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
+5
-4
@@ -318,14 +318,12 @@ func (r *Room) OnParticipantChanged(f func(participant types.Participant)) {
|
|||||||
r.onParticipantChanged = f
|
r.onParticipantChanged = f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checks if participant should be autosubscribed to new tracks, assumes lock is already acquired
|
||||||
func (r *Room) autoSubscribe(participant types.Participant) bool {
|
func (r *Room) autoSubscribe(participant types.Participant) bool {
|
||||||
if !participant.CanSubscribe() {
|
if !participant.CanSubscribe() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
r.lock.RLock()
|
|
||||||
defer r.lock.RUnlock()
|
|
||||||
|
|
||||||
opts := r.participantOpts[participant.Identity()]
|
opts := r.participantOpts[participant.Identity()]
|
||||||
// default to true if no options are set
|
// default to true if no options are set
|
||||||
if opts != nil && !opts.AutoSubscribe {
|
if opts != nil && !opts.AutoSubscribe {
|
||||||
@@ -402,7 +400,10 @@ func (r *Room) onDataPacket(source types.Participant, dp *livekit.DataPacket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Room) subscribeToExistingTracks(p types.Participant) {
|
func (r *Room) subscribeToExistingTracks(p types.Participant) {
|
||||||
if !r.autoSubscribe(p) {
|
r.lock.RLock()
|
||||||
|
shouldSubscribe := r.autoSubscribe(p)
|
||||||
|
r.lock.RUnlock()
|
||||||
|
if !shouldSubscribe {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user