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 authored and GitHub committed 2022-09-26 15:32:22 +05:30
1 parent 572dd43329
commit dfc71d5bf8
7 files changed
+88 -19

No files matched your search

+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
if !canPublish {
for _, track := range p.GetPublishedTracks() {
p.RemovePublishedTrack(track, false)
p.RemovePublishedTrack(track, false, false)
if p.ProtocolVersion().SupportsUnpublish() {
p.sendTrackUnpublished(track.ID())
} else {
+3 -1
View File
@@ -178,7 +178,7 @@ type Participant interface {
GetPublishedTrack(sid livekit.TrackID) MediaTrack
GetPublishedTracks() []MediaTrack
RemovePublishedTrack(track MediaTrack, willBeResumed bool)
RemovePublishedTrack(track MediaTrack, willBeResumed bool, shouldClose bool)
AddSubscriber(op LocalParticipant, params AddSubscriberParams) (int, error)
RemoveSubscriber(op LocalParticipant, trackID livekit.TrackID, resume bool)
@@ -363,6 +363,8 @@ type MediaTrack interface {
UpdateVideoLayers(layers []*livekit.VideoLayer)
IsSimulcast() bool
Close()
// callbacks
AddOnClose(func())
@@ -26,6 +26,10 @@ type FakeLocalMediaTrack struct {
addSubscriberReturnsOnCall map[int]struct {
result1 error
}
CloseStub func()
closeMutex sync.RWMutex
closeArgsForCall []struct {
}
GetAllSubscribersStub func() []livekit.ParticipantID
getAllSubscribersMutex sync.RWMutex
getAllSubscribersArgsForCall []struct {
@@ -372,6 +376,30 @@ func (fake *FakeLocalMediaTrack) AddSubscriberReturnsOnCall(i int, result1 error
}{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 {
fake.getAllSubscribersMutex.Lock()
ret, specificReturn := fake.getAllSubscribersReturnsOnCall[len(fake.getAllSubscribersArgsForCall)]
@@ -1741,6 +1769,8 @@ func (fake *FakeLocalMediaTrack) Invocations() map[string][][]interface{} {
defer fake.addOnCloseMutex.RUnlock()
fake.addSubscriberMutex.RLock()
defer fake.addSubscriberMutex.RUnlock()
fake.closeMutex.RLock()
defer fake.closeMutex.RUnlock()
fake.getAllSubscribersMutex.RLock()
defer fake.getAllSubscribersMutex.RUnlock()
fake.getAudioLevelMutex.RLock()
@@ -465,11 +465,12 @@ type FakeLocalParticipant struct {
protocolVersionReturnsOnCall map[int]struct {
result1 types.ProtocolVersion
}
RemovePublishedTrackStub func(types.MediaTrack, bool)
RemovePublishedTrackStub func(types.MediaTrack, bool, bool)
removePublishedTrackMutex sync.RWMutex
removePublishedTrackArgsForCall []struct {
arg1 types.MediaTrack
arg2 bool
arg3 bool
}
RemoveSubscribedTrackStub func(types.SubscribedTrack)
removeSubscribedTrackMutex sync.RWMutex
@@ -3180,17 +3181,18 @@ func (fake *FakeLocalParticipant) ProtocolVersionReturnsOnCall(i int, result1 ty
}{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.removePublishedTrackArgsForCall = append(fake.removePublishedTrackArgsForCall, struct {
arg1 types.MediaTrack
arg2 bool
}{arg1, arg2})
arg3 bool
}{arg1, arg2, arg3})
stub := fake.RemovePublishedTrackStub
fake.recordInvocation("RemovePublishedTrack", []interface{}{arg1, arg2})
fake.recordInvocation("RemovePublishedTrack", []interface{}{arg1, arg2, arg3})
fake.removePublishedTrackMutex.Unlock()
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)
}
func (fake *FakeLocalParticipant) RemovePublishedTrackCalls(stub func(types.MediaTrack, bool)) {
func (fake *FakeLocalParticipant) RemovePublishedTrackCalls(stub func(types.MediaTrack, bool, bool)) {
fake.removePublishedTrackMutex.Lock()
defer fake.removePublishedTrackMutex.Unlock()
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()
defer fake.removePublishedTrackMutex.RUnlock()
argsForCall := fake.removePublishedTrackArgsForCall[i]
return argsForCall.arg1, argsForCall.arg2
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
}
func (fake *FakeLocalParticipant) RemoveSubscribedTrack(arg1 types.SubscribedTrack) {
@@ -26,6 +26,10 @@ type FakeMediaTrack struct {
addSubscriberReturnsOnCall map[int]struct {
result1 error
}
CloseStub func()
closeMutex sync.RWMutex
closeArgsForCall []struct {
}
GetAllSubscribersStub func() []livekit.ParticipantID
getAllSubscribersMutex sync.RWMutex
getAllSubscribersArgsForCall []struct {
@@ -308,6 +312,30 @@ func (fake *FakeMediaTrack) AddSubscriberReturnsOnCall(i int, result1 error) {
}{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 {
fake.getAllSubscribersMutex.Lock()
ret, specificReturn := fake.getAllSubscribersReturnsOnCall[len(fake.getAllSubscribersArgsForCall)]
@@ -1327,6 +1355,8 @@ func (fake *FakeMediaTrack) Invocations() map[string][][]interface{} {
defer fake.addOnCloseMutex.RUnlock()
fake.addSubscriberMutex.RLock()
defer fake.addSubscriberMutex.RUnlock()
fake.closeMutex.RLock()
defer fake.closeMutex.RUnlock()
fake.getAllSubscribersMutex.RLock()
defer fake.getAllSubscribersMutex.RUnlock()
fake.getNumSubscribersMutex.RLock()
+10 -8
View File
@@ -106,11 +106,12 @@ type FakeParticipant struct {
isRecorderReturnsOnCall map[int]struct {
result1 bool
}
RemovePublishedTrackStub func(types.MediaTrack, bool)
RemovePublishedTrackStub func(types.MediaTrack, bool, bool)
removePublishedTrackMutex sync.RWMutex
removePublishedTrackArgsForCall []struct {
arg1 types.MediaTrack
arg2 bool
arg3 bool
}
RemoveSubscriberStub func(types.LocalParticipant, livekit.TrackID, bool)
removeSubscriberMutex sync.RWMutex
@@ -685,17 +686,18 @@ func (fake *FakeParticipant) IsRecorderReturnsOnCall(i int, result1 bool) {
}{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.removePublishedTrackArgsForCall = append(fake.removePublishedTrackArgsForCall, struct {
arg1 types.MediaTrack
arg2 bool
}{arg1, arg2})
arg3 bool
}{arg1, arg2, arg3})
stub := fake.RemovePublishedTrackStub
fake.recordInvocation("RemovePublishedTrack", []interface{}{arg1, arg2})
fake.recordInvocation("RemovePublishedTrack", []interface{}{arg1, arg2, arg3})
fake.removePublishedTrackMutex.Unlock()
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)
}
func (fake *FakeParticipant) RemovePublishedTrackCalls(stub func(types.MediaTrack, bool)) {
func (fake *FakeParticipant) RemovePublishedTrackCalls(stub func(types.MediaTrack, bool, bool)) {
fake.removePublishedTrackMutex.Lock()
defer fake.removePublishedTrackMutex.Unlock()
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()
defer fake.removePublishedTrackMutex.RUnlock()
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) {
+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)
if shouldClose {
track.Close()
}
u.lock.Lock()
delete(u.publishedTracks, track.ID())
u.lock.Unlock()