Do not block on down track close with flush. (#2201)

* Do not block on down track close with flush.

When publisher removes all subscribers, publisher side should
not be blocked for long. With close with flush, it could happen
if there a lot of bunch of subscribers.

So, when is expected, run it in a goroutine like it is done in
subscription manager.

Not moving the entire `RemoveSubscriber` bit to subscription manager as
there are two bits which are not tracked now
- mime type
- willBeResumed
Those two would have to be tracked in track manager and notified to
subscription manager so that it can act for that mine and if the track
will be resumed or not. As that touch more parts and could get
complicated, doing the simpler thing of cloning behaviour from
subscription manager for now.

* clean up

* code readability
This commit is contained in:
Raja Subramanian
2023-10-30 12:31:00 +05:30
committed by GitHub
parent 7578f9cbf5
commit dc9f16f350
+6 -2
View File
@@ -304,14 +304,18 @@ func (t *MediaTrackSubscriptions) closeSubscribedTrack(subTrack types.Subscribed
return
}
dt.CloseWithFlush(!willBeResumed)
if willBeResumed {
dt.CloseWithFlush(false)
// cache transceiver for potential re-use on resume
tr := dt.GetTransceiver()
if tr != nil {
sub := subTrack.Subscriber()
sub.CacheDownTrack(subTrack.ID(), tr, dt.GetState())
}
} else {
// flushing blocks, avoid blocking when publisher removes all its subscribers
go dt.CloseWithFlush(true)
}
}