CacheDowntrack synchronously on DownTrack.Close (#2981)
Avoid repeat adding local/remote downtracks when migration after #2970 allow remote track can be subscribed before resolved.
This commit is contained in:
@@ -324,7 +324,7 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, wr *
|
|||||||
downTrack.SetTransceiver(transceiver)
|
downTrack.SetTransceiver(transceiver)
|
||||||
|
|
||||||
downTrack.OnCloseHandler(func(isExpectedToResume bool) {
|
downTrack.OnCloseHandler(func(isExpectedToResume bool) {
|
||||||
go t.downTrackClosed(sub, isExpectedToResume)
|
t.downTrackClosed(sub, subTrack, isExpectedToResume)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.subscribedTracksMu.Lock()
|
t.subscribedTracksMu.Lock()
|
||||||
@@ -435,30 +435,24 @@ func (t *MediaTrackSubscriptions) DebugInfo() []map[string]interface{} {
|
|||||||
|
|
||||||
func (t *MediaTrackSubscriptions) downTrackClosed(
|
func (t *MediaTrackSubscriptions) downTrackClosed(
|
||||||
sub types.LocalParticipant,
|
sub types.LocalParticipant,
|
||||||
|
subTrack types.SubscribedTrack,
|
||||||
isExpectedToResume bool,
|
isExpectedToResume bool,
|
||||||
) {
|
) {
|
||||||
subscriberID := sub.ID()
|
// Cache transceiver for potential re-use on resume.
|
||||||
t.subscribedTracksMu.RLock()
|
// To ensure subscription manager does not re-subscribe before caching,
|
||||||
subTrack := t.subscribedTracks[subscriberID]
|
// delete the subscribed track only after caching.
|
||||||
t.subscribedTracksMu.RUnlock()
|
if isExpectedToResume {
|
||||||
|
dt := subTrack.DownTrack()
|
||||||
if subTrack != nil {
|
tr := dt.GetTransceiver()
|
||||||
// Cache transceiver for potential re-use on resume.
|
if tr != nil {
|
||||||
// To ensure subscription manager does not re-subscribe before caching,
|
sub.CacheDownTrack(subTrack.ID(), tr, dt.GetState())
|
||||||
// delete the subscribed track only after caching.
|
|
||||||
if isExpectedToResume {
|
|
||||||
dt := subTrack.DownTrack()
|
|
||||||
tr := dt.GetTransceiver()
|
|
||||||
if tr != nil {
|
|
||||||
sub := subTrack.Subscriber()
|
|
||||||
sub.CacheDownTrack(subTrack.ID(), tr, dt.GetState())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t.subscribedTracksMu.Lock()
|
|
||||||
delete(t.subscribedTracks, subscriberID)
|
|
||||||
t.subscribedTracksMu.Unlock()
|
|
||||||
|
|
||||||
subTrack.Close(isExpectedToResume)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
t.subscribedTracksMu.Lock()
|
||||||
|
delete(t.subscribedTracks, sub.ID())
|
||||||
|
t.subscribedTracksMu.Unlock()
|
||||||
|
subTrack.Close(isExpectedToResume)
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user