Indicate if track is expectd to be resumed in onClose callback. (#2800)

That is the main change. Changed variable name to `isExpectedToResume`
everywhere to be consistent.

Planning to use the callback value in relays to determine if the down
track should be closed or switched to a different up track.
This commit is contained in:
Raja Subramanian
2024-06-17 23:51:00 +05:30
committed by GitHub
parent aa72466ac8
commit ef838e4fa2
13 changed files with 99 additions and 97 deletions
+12 -12
View File
@@ -296,8 +296,8 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, wr *
// But, the subscription could be removed early if the published track is closed
// while adding subscription. In those cases, subscription manager would not have set
// the `OnClose` callback. So, set it here to handle cases of early close.
subTrack.OnClose(func(willBeResumed bool) {
if !willBeResumed {
subTrack.OnClose(func(isExpectedToResume bool) {
if !isExpectedToResume {
if err := sub.RemoveTrackFromSubscriber(sender); err != nil {
t.params.Logger.Warnw("could not remove track from peer connection", err)
}
@@ -306,8 +306,8 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, wr *
downTrack.SetTransceiver(transceiver)
downTrack.OnCloseHandler(func(willBeResumed bool) {
go t.downTrackClosed(sub, willBeResumed)
downTrack.OnCloseHandler(func(isExpectedToResume bool) {
go t.downTrackClosed(sub, isExpectedToResume)
})
t.subscribedTracksMu.Lock()
@@ -319,24 +319,24 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, wr *
// RemoveSubscriber removes participant from subscription
// stop all forwarders to the client
func (t *MediaTrackSubscriptions) RemoveSubscriber(subscriberID livekit.ParticipantID, willBeResumed bool) error {
func (t *MediaTrackSubscriptions) RemoveSubscriber(subscriberID livekit.ParticipantID, isExpectedToResume bool) error {
subTrack := t.getSubscribedTrack(subscriberID)
if subTrack == nil {
return errNotFound
}
t.params.Logger.Debugw("removing subscriber", "subscriberID", subscriberID, "willBeResumed", willBeResumed)
t.closeSubscribedTrack(subTrack, willBeResumed)
t.params.Logger.Debugw("removing subscriber", "subscriberID", subscriberID, "isExpectedToResume", isExpectedToResume)
t.closeSubscribedTrack(subTrack, isExpectedToResume)
return nil
}
func (t *MediaTrackSubscriptions) closeSubscribedTrack(subTrack types.SubscribedTrack, willBeResumed bool) {
func (t *MediaTrackSubscriptions) closeSubscribedTrack(subTrack types.SubscribedTrack, isExpectedToResume bool) {
dt := subTrack.DownTrack()
if dt == nil {
return
}
if willBeResumed {
if isExpectedToResume {
dt.CloseWithFlush(false)
} else {
// flushing blocks, avoid blocking when publisher removes all its subscribers
@@ -418,7 +418,7 @@ func (t *MediaTrackSubscriptions) DebugInfo() []map[string]interface{} {
func (t *MediaTrackSubscriptions) downTrackClosed(
sub types.LocalParticipant,
willBeResumed bool,
isExpectedToResume bool,
) {
subscriberID := sub.ID()
t.subscribedTracksMu.RLock()
@@ -429,7 +429,7 @@ func (t *MediaTrackSubscriptions) downTrackClosed(
// Cache transceiver for potential re-use on resume.
// To ensure subscription manager does not re-subscribe before caching,
// delete the subscribed track only after caching.
if willBeResumed {
if isExpectedToResume {
dt := subTrack.DownTrack()
tr := dt.GetTransceiver()
if tr != nil {
@@ -442,6 +442,6 @@ func (t *MediaTrackSubscriptions) downTrackClosed(
delete(t.subscribedTracks, subscriberID)
t.subscribedTracksMu.Unlock()
subTrack.Close(willBeResumed)
subTrack.Close(isExpectedToResume)
}
}