Bring back soft close. (#2553)

Remote media track needs it.
This commit is contained in:
Raja Subramanian
2024-03-07 12:52:48 +05:30
committed by GitHub
parent d87f8aa299
commit 6c94185aa6
7 changed files with 107 additions and 20 deletions
+1 -1
View File
@@ -1406,7 +1406,7 @@ func (p *ParticipantImpl) onSubscriberOffer(offer webrtc.SessionDescription) err
}
func (p *ParticipantImpl) removePublishedTrack(track types.MediaTrack) {
p.RemovePublishedTrack(track, false)
p.RemovePublishedTrack(track, false, true)
if p.ProtocolVersion().SupportsUnpublish() {
p.sendTrackUnpublished(track.ID())
} else {
+2 -1
View File
@@ -255,7 +255,7 @@ type Participant interface {
IsPublisher() bool
GetPublishedTrack(trackID livekit.TrackID) MediaTrack
GetPublishedTracks() []MediaTrack
RemovePublishedTrack(track MediaTrack, willBeResumed bool)
RemovePublishedTrack(track MediaTrack, willBeResumed bool, shouldClose bool)
GetAudioLevel() (smoothedLevel float64, active bool)
@@ -485,6 +485,7 @@ type MediaTrack interface {
GetTemporalLayerForSpatialFps(spatial int32, fps uint32, mime string) int32
Receivers() []sfu.TrackReceiver
ClearAllReceivers(willBeResumed bool)
IsEncrypted() bool
}
@@ -28,6 +28,11 @@ type FakeLocalMediaTrack struct {
result1 types.SubscribedTrack
result2 error
}
ClearAllReceiversStub func(bool)
clearAllReceiversMutex sync.RWMutex
clearAllReceiversArgsForCall []struct {
arg1 bool
}
CloseStub func(bool)
closeMutex sync.RWMutex
closeArgsForCall []struct {
@@ -437,6 +442,38 @@ func (fake *FakeLocalMediaTrack) AddSubscriberReturnsOnCall(i int, result1 types
}{result1, result2}
}
func (fake *FakeLocalMediaTrack) ClearAllReceivers(arg1 bool) {
fake.clearAllReceiversMutex.Lock()
fake.clearAllReceiversArgsForCall = append(fake.clearAllReceiversArgsForCall, struct {
arg1 bool
}{arg1})
stub := fake.ClearAllReceiversStub
fake.recordInvocation("ClearAllReceivers", []interface{}{arg1})
fake.clearAllReceiversMutex.Unlock()
if stub != nil {
fake.ClearAllReceiversStub(arg1)
}
}
func (fake *FakeLocalMediaTrack) ClearAllReceiversCallCount() int {
fake.clearAllReceiversMutex.RLock()
defer fake.clearAllReceiversMutex.RUnlock()
return len(fake.clearAllReceiversArgsForCall)
}
func (fake *FakeLocalMediaTrack) ClearAllReceiversCalls(stub func(bool)) {
fake.clearAllReceiversMutex.Lock()
defer fake.clearAllReceiversMutex.Unlock()
fake.ClearAllReceiversStub = stub
}
func (fake *FakeLocalMediaTrack) ClearAllReceiversArgsForCall(i int) bool {
fake.clearAllReceiversMutex.RLock()
defer fake.clearAllReceiversMutex.RUnlock()
argsForCall := fake.clearAllReceiversArgsForCall[i]
return argsForCall.arg1
}
func (fake *FakeLocalMediaTrack) Close(arg1 bool) {
fake.closeMutex.Lock()
fake.closeArgsForCall = append(fake.closeArgsForCall, struct {
@@ -2116,6 +2153,8 @@ func (fake *FakeLocalMediaTrack) Invocations() map[string][][]interface{} {
defer fake.addOnCloseMutex.RUnlock()
fake.addSubscriberMutex.RLock()
defer fake.addSubscriberMutex.RUnlock()
fake.clearAllReceiversMutex.RLock()
defer fake.clearAllReceiversMutex.RUnlock()
fake.closeMutex.RLock()
defer fake.closeMutex.RUnlock()
fake.getAllSubscribersMutex.RLock()
@@ -631,11 +631,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
}
RemoveTrackFromSubscriberStub func(*webrtc.RTPSender) error
removeTrackFromSubscriberMutex sync.RWMutex
@@ -4305,17 +4306,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)
}
}
@@ -4325,17 +4327,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) RemoveTrackFromSubscriber(arg1 *webrtc.RTPSender) error {
@@ -28,6 +28,11 @@ type FakeMediaTrack struct {
result1 types.SubscribedTrack
result2 error
}
ClearAllReceiversStub func(bool)
clearAllReceiversMutex sync.RWMutex
clearAllReceiversArgsForCall []struct {
arg1 bool
}
CloseStub func(bool)
closeMutex sync.RWMutex
closeArgsForCall []struct {
@@ -373,6 +378,38 @@ func (fake *FakeMediaTrack) AddSubscriberReturnsOnCall(i int, result1 types.Subs
}{result1, result2}
}
func (fake *FakeMediaTrack) ClearAllReceivers(arg1 bool) {
fake.clearAllReceiversMutex.Lock()
fake.clearAllReceiversArgsForCall = append(fake.clearAllReceiversArgsForCall, struct {
arg1 bool
}{arg1})
stub := fake.ClearAllReceiversStub
fake.recordInvocation("ClearAllReceivers", []interface{}{arg1})
fake.clearAllReceiversMutex.Unlock()
if stub != nil {
fake.ClearAllReceiversStub(arg1)
}
}
func (fake *FakeMediaTrack) ClearAllReceiversCallCount() int {
fake.clearAllReceiversMutex.RLock()
defer fake.clearAllReceiversMutex.RUnlock()
return len(fake.clearAllReceiversArgsForCall)
}
func (fake *FakeMediaTrack) ClearAllReceiversCalls(stub func(bool)) {
fake.clearAllReceiversMutex.Lock()
defer fake.clearAllReceiversMutex.Unlock()
fake.ClearAllReceiversStub = stub
}
func (fake *FakeMediaTrack) ClearAllReceiversArgsForCall(i int) bool {
fake.clearAllReceiversMutex.RLock()
defer fake.clearAllReceiversMutex.RUnlock()
argsForCall := fake.clearAllReceiversArgsForCall[i]
return argsForCall.arg1
}
func (fake *FakeMediaTrack) Close(arg1 bool) {
fake.closeMutex.Lock()
fake.closeArgsForCall = append(fake.closeArgsForCall, struct {
@@ -1702,6 +1739,8 @@ func (fake *FakeMediaTrack) Invocations() map[string][][]interface{} {
defer fake.addOnCloseMutex.RUnlock()
fake.addSubscriberMutex.RLock()
defer fake.addSubscriberMutex.RUnlock()
fake.clearAllReceiversMutex.RLock()
defer fake.clearAllReceiversMutex.RUnlock()
fake.closeMutex.RLock()
defer fake.closeMutex.RUnlock()
fake.getAllSubscribersMutex.RLock()
+10 -8
View File
@@ -158,11 +158,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
}
SetMetadataStub func(string)
setMetadataMutex sync.RWMutex
@@ -1007,17 +1008,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)
}
}
@@ -1027,17 +1029,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) SetMetadata(arg1 string) {
+6 -2
View File
@@ -268,8 +268,12 @@ func (u *UpTrackManager) AddPublishedTrack(track types.MediaTrack) {
})
}
func (u *UpTrackManager) RemovePublishedTrack(track types.MediaTrack, willBeResumed bool) {
track.Close(willBeResumed)
func (u *UpTrackManager) RemovePublishedTrack(track types.MediaTrack, willBeResumed bool, shouldClose bool) {
if shouldClose {
track.Close(willBeResumed)
} else {
track.ClearAllReceivers(willBeResumed)
}
u.lock.Lock()
delete(u.publishedTracks, track.ID())
u.lock.Unlock()