Add a flag to signal need to close underlying media track. (#1038)

With migration in, once the local track is published, the
remote track should be closed. Add a flag to `RemovePublishedTrack`
to control the close behaviour. Invoke `Close` if specified.

Without, the remote track is not closed if it is waiting to resolve,
i. e. not yet attached. That remote track is left hanging.
This commit is contained in:
Raja Subramanian
2022-09-26 15:32:22 +05:30
committed by GitHub
parent 572dd43329
commit dfc71d5bf8
7 changed files with 88 additions and 19 deletions
+1 -1
View File
@@ -308,7 +308,7 @@ func (p *ParticipantImpl) SetPermission(permission *livekit.ParticipantPermissio
// publish permission has been revoked then remove all published tracks // publish permission has been revoked then remove all published tracks
if !canPublish { if !canPublish {
for _, track := range p.GetPublishedTracks() { for _, track := range p.GetPublishedTracks() {
p.RemovePublishedTrack(track, false) p.RemovePublishedTrack(track, false, false)
if p.ProtocolVersion().SupportsUnpublish() { if p.ProtocolVersion().SupportsUnpublish() {
p.sendTrackUnpublished(track.ID()) p.sendTrackUnpublished(track.ID())
} else { } else {
+3 -1
View File
@@ -178,7 +178,7 @@ type Participant interface {
GetPublishedTrack(sid livekit.TrackID) MediaTrack GetPublishedTrack(sid livekit.TrackID) MediaTrack
GetPublishedTracks() []MediaTrack GetPublishedTracks() []MediaTrack
RemovePublishedTrack(track MediaTrack, willBeResumed bool) RemovePublishedTrack(track MediaTrack, willBeResumed bool, shouldClose bool)
AddSubscriber(op LocalParticipant, params AddSubscriberParams) (int, error) AddSubscriber(op LocalParticipant, params AddSubscriberParams) (int, error)
RemoveSubscriber(op LocalParticipant, trackID livekit.TrackID, resume bool) RemoveSubscriber(op LocalParticipant, trackID livekit.TrackID, resume bool)
@@ -363,6 +363,8 @@ type MediaTrack interface {
UpdateVideoLayers(layers []*livekit.VideoLayer) UpdateVideoLayers(layers []*livekit.VideoLayer)
IsSimulcast() bool IsSimulcast() bool
Close()
// callbacks // callbacks
AddOnClose(func()) AddOnClose(func())
@@ -26,6 +26,10 @@ type FakeLocalMediaTrack struct {
addSubscriberReturnsOnCall map[int]struct { addSubscriberReturnsOnCall map[int]struct {
result1 error result1 error
} }
CloseStub func()
closeMutex sync.RWMutex
closeArgsForCall []struct {
}
GetAllSubscribersStub func() []livekit.ParticipantID GetAllSubscribersStub func() []livekit.ParticipantID
getAllSubscribersMutex sync.RWMutex getAllSubscribersMutex sync.RWMutex
getAllSubscribersArgsForCall []struct { getAllSubscribersArgsForCall []struct {
@@ -372,6 +376,30 @@ func (fake *FakeLocalMediaTrack) AddSubscriberReturnsOnCall(i int, result1 error
}{result1} }{result1}
} }
func (fake *FakeLocalMediaTrack) Close() {
fake.closeMutex.Lock()
fake.closeArgsForCall = append(fake.closeArgsForCall, struct {
}{})
stub := fake.CloseStub
fake.recordInvocation("Close", []interface{}{})
fake.closeMutex.Unlock()
if stub != nil {
fake.CloseStub()
}
}
func (fake *FakeLocalMediaTrack) CloseCallCount() int {
fake.closeMutex.RLock()
defer fake.closeMutex.RUnlock()
return len(fake.closeArgsForCall)
}
func (fake *FakeLocalMediaTrack) CloseCalls(stub func()) {
fake.closeMutex.Lock()
defer fake.closeMutex.Unlock()
fake.CloseStub = stub
}
func (fake *FakeLocalMediaTrack) GetAllSubscribers() []livekit.ParticipantID { func (fake *FakeLocalMediaTrack) GetAllSubscribers() []livekit.ParticipantID {
fake.getAllSubscribersMutex.Lock() fake.getAllSubscribersMutex.Lock()
ret, specificReturn := fake.getAllSubscribersReturnsOnCall[len(fake.getAllSubscribersArgsForCall)] ret, specificReturn := fake.getAllSubscribersReturnsOnCall[len(fake.getAllSubscribersArgsForCall)]
@@ -1741,6 +1769,8 @@ func (fake *FakeLocalMediaTrack) Invocations() map[string][][]interface{} {
defer fake.addOnCloseMutex.RUnlock() defer fake.addOnCloseMutex.RUnlock()
fake.addSubscriberMutex.RLock() fake.addSubscriberMutex.RLock()
defer fake.addSubscriberMutex.RUnlock() defer fake.addSubscriberMutex.RUnlock()
fake.closeMutex.RLock()
defer fake.closeMutex.RUnlock()
fake.getAllSubscribersMutex.RLock() fake.getAllSubscribersMutex.RLock()
defer fake.getAllSubscribersMutex.RUnlock() defer fake.getAllSubscribersMutex.RUnlock()
fake.getAudioLevelMutex.RLock() fake.getAudioLevelMutex.RLock()
@@ -465,11 +465,12 @@ type FakeLocalParticipant struct {
protocolVersionReturnsOnCall map[int]struct { protocolVersionReturnsOnCall map[int]struct {
result1 types.ProtocolVersion result1 types.ProtocolVersion
} }
RemovePublishedTrackStub func(types.MediaTrack, bool) RemovePublishedTrackStub func(types.MediaTrack, bool, bool)
removePublishedTrackMutex sync.RWMutex removePublishedTrackMutex sync.RWMutex
removePublishedTrackArgsForCall []struct { removePublishedTrackArgsForCall []struct {
arg1 types.MediaTrack arg1 types.MediaTrack
arg2 bool arg2 bool
arg3 bool
} }
RemoveSubscribedTrackStub func(types.SubscribedTrack) RemoveSubscribedTrackStub func(types.SubscribedTrack)
removeSubscribedTrackMutex sync.RWMutex removeSubscribedTrackMutex sync.RWMutex
@@ -3180,17 +3181,18 @@ func (fake *FakeLocalParticipant) ProtocolVersionReturnsOnCall(i int, result1 ty
}{result1} }{result1}
} }
func (fake *FakeLocalParticipant) RemovePublishedTrack(arg1 types.MediaTrack, arg2 bool) { func (fake *FakeLocalParticipant) RemovePublishedTrack(arg1 types.MediaTrack, arg2 bool, arg3 bool) {
fake.removePublishedTrackMutex.Lock() fake.removePublishedTrackMutex.Lock()
fake.removePublishedTrackArgsForCall = append(fake.removePublishedTrackArgsForCall, struct { fake.removePublishedTrackArgsForCall = append(fake.removePublishedTrackArgsForCall, struct {
arg1 types.MediaTrack arg1 types.MediaTrack
arg2 bool arg2 bool
}{arg1, arg2}) arg3 bool
}{arg1, arg2, arg3})
stub := fake.RemovePublishedTrackStub stub := fake.RemovePublishedTrackStub
fake.recordInvocation("RemovePublishedTrack", []interface{}{arg1, arg2}) fake.recordInvocation("RemovePublishedTrack", []interface{}{arg1, arg2, arg3})
fake.removePublishedTrackMutex.Unlock() fake.removePublishedTrackMutex.Unlock()
if stub != nil { if stub != nil {
fake.RemovePublishedTrackStub(arg1, arg2) fake.RemovePublishedTrackStub(arg1, arg2, arg3)
} }
} }
@@ -3200,17 +3202,17 @@ func (fake *FakeLocalParticipant) RemovePublishedTrackCallCount() int {
return len(fake.removePublishedTrackArgsForCall) return len(fake.removePublishedTrackArgsForCall)
} }
func (fake *FakeLocalParticipant) RemovePublishedTrackCalls(stub func(types.MediaTrack, bool)) { func (fake *FakeLocalParticipant) RemovePublishedTrackCalls(stub func(types.MediaTrack, bool, bool)) {
fake.removePublishedTrackMutex.Lock() fake.removePublishedTrackMutex.Lock()
defer fake.removePublishedTrackMutex.Unlock() defer fake.removePublishedTrackMutex.Unlock()
fake.RemovePublishedTrackStub = stub fake.RemovePublishedTrackStub = stub
} }
func (fake *FakeLocalParticipant) RemovePublishedTrackArgsForCall(i int) (types.MediaTrack, bool) { func (fake *FakeLocalParticipant) RemovePublishedTrackArgsForCall(i int) (types.MediaTrack, bool, bool) {
fake.removePublishedTrackMutex.RLock() fake.removePublishedTrackMutex.RLock()
defer fake.removePublishedTrackMutex.RUnlock() defer fake.removePublishedTrackMutex.RUnlock()
argsForCall := fake.removePublishedTrackArgsForCall[i] argsForCall := fake.removePublishedTrackArgsForCall[i]
return argsForCall.arg1, argsForCall.arg2 return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
} }
func (fake *FakeLocalParticipant) RemoveSubscribedTrack(arg1 types.SubscribedTrack) { func (fake *FakeLocalParticipant) RemoveSubscribedTrack(arg1 types.SubscribedTrack) {
@@ -26,6 +26,10 @@ type FakeMediaTrack struct {
addSubscriberReturnsOnCall map[int]struct { addSubscriberReturnsOnCall map[int]struct {
result1 error result1 error
} }
CloseStub func()
closeMutex sync.RWMutex
closeArgsForCall []struct {
}
GetAllSubscribersStub func() []livekit.ParticipantID GetAllSubscribersStub func() []livekit.ParticipantID
getAllSubscribersMutex sync.RWMutex getAllSubscribersMutex sync.RWMutex
getAllSubscribersArgsForCall []struct { getAllSubscribersArgsForCall []struct {
@@ -308,6 +312,30 @@ func (fake *FakeMediaTrack) AddSubscriberReturnsOnCall(i int, result1 error) {
}{result1} }{result1}
} }
func (fake *FakeMediaTrack) Close() {
fake.closeMutex.Lock()
fake.closeArgsForCall = append(fake.closeArgsForCall, struct {
}{})
stub := fake.CloseStub
fake.recordInvocation("Close", []interface{}{})
fake.closeMutex.Unlock()
if stub != nil {
fake.CloseStub()
}
}
func (fake *FakeMediaTrack) CloseCallCount() int {
fake.closeMutex.RLock()
defer fake.closeMutex.RUnlock()
return len(fake.closeArgsForCall)
}
func (fake *FakeMediaTrack) CloseCalls(stub func()) {
fake.closeMutex.Lock()
defer fake.closeMutex.Unlock()
fake.CloseStub = stub
}
func (fake *FakeMediaTrack) GetAllSubscribers() []livekit.ParticipantID { func (fake *FakeMediaTrack) GetAllSubscribers() []livekit.ParticipantID {
fake.getAllSubscribersMutex.Lock() fake.getAllSubscribersMutex.Lock()
ret, specificReturn := fake.getAllSubscribersReturnsOnCall[len(fake.getAllSubscribersArgsForCall)] ret, specificReturn := fake.getAllSubscribersReturnsOnCall[len(fake.getAllSubscribersArgsForCall)]
@@ -1327,6 +1355,8 @@ func (fake *FakeMediaTrack) Invocations() map[string][][]interface{} {
defer fake.addOnCloseMutex.RUnlock() defer fake.addOnCloseMutex.RUnlock()
fake.addSubscriberMutex.RLock() fake.addSubscriberMutex.RLock()
defer fake.addSubscriberMutex.RUnlock() defer fake.addSubscriberMutex.RUnlock()
fake.closeMutex.RLock()
defer fake.closeMutex.RUnlock()
fake.getAllSubscribersMutex.RLock() fake.getAllSubscribersMutex.RLock()
defer fake.getAllSubscribersMutex.RUnlock() defer fake.getAllSubscribersMutex.RUnlock()
fake.getNumSubscribersMutex.RLock() fake.getNumSubscribersMutex.RLock()
+10 -8
View File
@@ -106,11 +106,12 @@ type FakeParticipant struct {
isRecorderReturnsOnCall map[int]struct { isRecorderReturnsOnCall map[int]struct {
result1 bool result1 bool
} }
RemovePublishedTrackStub func(types.MediaTrack, bool) RemovePublishedTrackStub func(types.MediaTrack, bool, bool)
removePublishedTrackMutex sync.RWMutex removePublishedTrackMutex sync.RWMutex
removePublishedTrackArgsForCall []struct { removePublishedTrackArgsForCall []struct {
arg1 types.MediaTrack arg1 types.MediaTrack
arg2 bool arg2 bool
arg3 bool
} }
RemoveSubscriberStub func(types.LocalParticipant, livekit.TrackID, bool) RemoveSubscriberStub func(types.LocalParticipant, livekit.TrackID, bool)
removeSubscriberMutex sync.RWMutex removeSubscriberMutex sync.RWMutex
@@ -685,17 +686,18 @@ func (fake *FakeParticipant) IsRecorderReturnsOnCall(i int, result1 bool) {
}{result1} }{result1}
} }
func (fake *FakeParticipant) RemovePublishedTrack(arg1 types.MediaTrack, arg2 bool) { func (fake *FakeParticipant) RemovePublishedTrack(arg1 types.MediaTrack, arg2 bool, arg3 bool) {
fake.removePublishedTrackMutex.Lock() fake.removePublishedTrackMutex.Lock()
fake.removePublishedTrackArgsForCall = append(fake.removePublishedTrackArgsForCall, struct { fake.removePublishedTrackArgsForCall = append(fake.removePublishedTrackArgsForCall, struct {
arg1 types.MediaTrack arg1 types.MediaTrack
arg2 bool arg2 bool
}{arg1, arg2}) arg3 bool
}{arg1, arg2, arg3})
stub := fake.RemovePublishedTrackStub stub := fake.RemovePublishedTrackStub
fake.recordInvocation("RemovePublishedTrack", []interface{}{arg1, arg2}) fake.recordInvocation("RemovePublishedTrack", []interface{}{arg1, arg2, arg3})
fake.removePublishedTrackMutex.Unlock() fake.removePublishedTrackMutex.Unlock()
if stub != nil { if stub != nil {
fake.RemovePublishedTrackStub(arg1, arg2) fake.RemovePublishedTrackStub(arg1, arg2, arg3)
} }
} }
@@ -705,17 +707,17 @@ func (fake *FakeParticipant) RemovePublishedTrackCallCount() int {
return len(fake.removePublishedTrackArgsForCall) return len(fake.removePublishedTrackArgsForCall)
} }
func (fake *FakeParticipant) RemovePublishedTrackCalls(stub func(types.MediaTrack, bool)) { func (fake *FakeParticipant) RemovePublishedTrackCalls(stub func(types.MediaTrack, bool, bool)) {
fake.removePublishedTrackMutex.Lock() fake.removePublishedTrackMutex.Lock()
defer fake.removePublishedTrackMutex.Unlock() defer fake.removePublishedTrackMutex.Unlock()
fake.RemovePublishedTrackStub = stub fake.RemovePublishedTrackStub = stub
} }
func (fake *FakeParticipant) RemovePublishedTrackArgsForCall(i int) (types.MediaTrack, bool) { func (fake *FakeParticipant) RemovePublishedTrackArgsForCall(i int) (types.MediaTrack, bool, bool) {
fake.removePublishedTrackMutex.RLock() fake.removePublishedTrackMutex.RLock()
defer fake.removePublishedTrackMutex.RUnlock() defer fake.removePublishedTrackMutex.RUnlock()
argsForCall := fake.removePublishedTrackArgsForCall[i] argsForCall := fake.removePublishedTrackArgsForCall[i]
return argsForCall.arg1, argsForCall.arg2 return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
} }
func (fake *FakeParticipant) RemoveSubscriber(arg1 types.LocalParticipant, arg2 livekit.TrackID, arg3 bool) { func (fake *FakeParticipant) RemoveSubscriber(arg1 types.LocalParticipant, arg2 livekit.TrackID, arg3 bool) {
+4 -1
View File
@@ -327,8 +327,11 @@ func (u *UpTrackManager) AddPublishedTrack(track types.MediaTrack) {
}) })
} }
func (u *UpTrackManager) RemovePublishedTrack(track types.MediaTrack, willBeResumed bool) { func (u *UpTrackManager) RemovePublishedTrack(track types.MediaTrack, willBeResumed bool, shouldClose bool) {
track.InitiateClose(willBeResumed) track.InitiateClose(willBeResumed)
if shouldClose {
track.Close()
}
u.lock.Lock() u.lock.Lock()
delete(u.publishedTracks, track.ID()) delete(u.publishedTracks, track.ID())
u.lock.Unlock() u.lock.Unlock()