Reduce lock scope, avoid callbacks under lock (#462)
This commit is contained in:
@@ -158,11 +158,10 @@ func (t *MediaTrackReceiver) IsMuted() bool {
|
|||||||
func (t *MediaTrackReceiver) SetMuted(muted bool) {
|
func (t *MediaTrackReceiver) SetMuted(muted bool) {
|
||||||
t.muted.TrySet(muted)
|
t.muted.TrySet(muted)
|
||||||
|
|
||||||
t.lock.RLock()
|
receiver := t.Receiver()
|
||||||
if t.receiver != nil {
|
if receiver != nil {
|
||||||
t.receiver.SetUpTrackPaused(muted)
|
receiver.SetUpTrackPaused(muted)
|
||||||
}
|
}
|
||||||
t.lock.RUnlock()
|
|
||||||
|
|
||||||
t.MediaTrackSubscriptions.SetMuted(muted)
|
t.MediaTrackSubscriptions.SetMuted(muted)
|
||||||
}
|
}
|
||||||
@@ -179,10 +178,9 @@ func (t *MediaTrackReceiver) AddOnClose(f func()) {
|
|||||||
|
|
||||||
// AddSubscriber subscribes sub to current mediaTrack
|
// AddSubscriber subscribes sub to current mediaTrack
|
||||||
func (t *MediaTrackReceiver) AddSubscriber(sub types.LocalParticipant) error {
|
func (t *MediaTrackReceiver) AddSubscriber(sub types.LocalParticipant) error {
|
||||||
t.lock.RLock()
|
receiver := t.Receiver()
|
||||||
defer t.lock.RUnlock()
|
|
||||||
|
|
||||||
if t.receiver == nil {
|
if receiver == nil {
|
||||||
// cannot add, no receiver
|
// cannot add, no receiver
|
||||||
return errors.New("cannot subscribe without a receiver in place")
|
return errors.New("cannot subscribe without a receiver in place")
|
||||||
}
|
}
|
||||||
@@ -195,7 +193,7 @@ func (t *MediaTrackReceiver) AddSubscriber(sub types.LocalParticipant) error {
|
|||||||
streamId = PackStreamID(t.PublisherID(), t.ID())
|
streamId = PackStreamID(t.PublisherID(), t.ID())
|
||||||
}
|
}
|
||||||
|
|
||||||
downTrack, err := t.MediaTrackSubscriptions.AddSubscriber(sub, t.receiver.Codec(), NewWrappedReceiver(t.receiver, t.ID(), streamId))
|
downTrack, err := t.MediaTrackSubscriptions.AddSubscriber(sub, receiver.Codec(), NewWrappedReceiver(receiver, t.ID(), streamId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -205,7 +203,7 @@ func (t *MediaTrackReceiver) AddSubscriber(sub types.LocalParticipant) error {
|
|||||||
downTrack.AddReceiverReportListener(t.handleMaxLossFeedback)
|
downTrack.AddReceiverReportListener(t.handleMaxLossFeedback)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.receiver.AddDownTrack(downTrack)
|
receiver.AddDownTrack(downTrack)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -346,15 +344,13 @@ func (t *MediaTrackReceiver) DebugInfo() map[string]interface{} {
|
|||||||
|
|
||||||
info["DownTracks"] = t.MediaTrackSubscriptions.DebugInfo()
|
info["DownTracks"] = t.MediaTrackSubscriptions.DebugInfo()
|
||||||
|
|
||||||
t.lock.RLock()
|
receiver := t.Receiver()
|
||||||
if t.receiver != nil {
|
if receiver != nil {
|
||||||
receiverInfo := t.receiver.DebugInfo()
|
receiverInfo := receiver.DebugInfo()
|
||||||
for k, v := range receiverInfo {
|
for k, v := range receiverInfo {
|
||||||
info[k] = v
|
info[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.lock.RUnlock()
|
|
||||||
|
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,12 +366,10 @@ func (t *MediaTrackReceiver) OnSubscribedMaxQualityChange(f func(trackID livekit
|
|||||||
if f != nil && !t.IsMuted() {
|
if f != nil && !t.IsMuted() {
|
||||||
_ = f(t.ID(), subscribedQualities, maxSubscribedQuality)
|
_ = f(t.ID(), subscribedQualities, maxSubscribedQuality)
|
||||||
}
|
}
|
||||||
|
receiver := t.Receiver()
|
||||||
t.lock.RLock()
|
if receiver != nil {
|
||||||
if t.receiver != nil {
|
receiver.SetMaxExpectedSpatialLayer(SpatialLayerForQuality(maxSubscribedQuality))
|
||||||
t.receiver.SetMaxExpectedSpatialLayer(SpatialLayerForQuality(maxSubscribedQuality))
|
|
||||||
}
|
}
|
||||||
t.lock.RUnlock()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user