From 6696c1e63d5d8c0a3f1708cdc67ac27485865015 Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Sun, 25 Feb 2024 13:46:55 +0530 Subject: [PATCH] Close published track always. (#2508) Simplify and close published track always. Avoid the round about path of unbind to close. --- pkg/rtc/participant.go | 2 +- pkg/rtc/types/interfaces.go | 2 +- .../types/typesfakes/fake_local_participant.go | 18 ++++++++---------- pkg/rtc/types/typesfakes/fake_participant.go | 18 ++++++++---------- pkg/rtc/uptrackmanager.go | 12 ++++-------- pkg/service/wire_gen.go | 2 +- pkg/sfu/forwarder.go | 2 +- 7 files changed, 24 insertions(+), 32 deletions(-) diff --git a/pkg/rtc/participant.go b/pkg/rtc/participant.go index efdce9d6..1c8fe892 100644 --- a/pkg/rtc/participant.go +++ b/pkg/rtc/participant.go @@ -1384,7 +1384,7 @@ func (p *ParticipantImpl) onSubscriberOffer(offer webrtc.SessionDescription) err } func (p *ParticipantImpl) removePublishedTrack(track types.MediaTrack) { - p.RemovePublishedTrack(track, false, false) + p.RemovePublishedTrack(track, false) if p.ProtocolVersion().SupportsUnpublish() { p.sendTrackUnpublished(track.ID()) } else { diff --git a/pkg/rtc/types/interfaces.go b/pkg/rtc/types/interfaces.go index a08443d7..da5cc5e2 100644 --- a/pkg/rtc/types/interfaces.go +++ b/pkg/rtc/types/interfaces.go @@ -255,7 +255,7 @@ type Participant interface { IsPublisher() bool GetPublishedTrack(trackID livekit.TrackID) MediaTrack GetPublishedTracks() []MediaTrack - RemovePublishedTrack(track MediaTrack, willBeResumed bool, shouldClose bool) + RemovePublishedTrack(track MediaTrack, willBeResumed bool) GetAudioLevel() (smoothedLevel float64, active bool) diff --git a/pkg/rtc/types/typesfakes/fake_local_participant.go b/pkg/rtc/types/typesfakes/fake_local_participant.go index c20a1a1d..131e2f87 100644 --- a/pkg/rtc/types/typesfakes/fake_local_participant.go +++ b/pkg/rtc/types/typesfakes/fake_local_participant.go @@ -627,12 +627,11 @@ type FakeLocalParticipant struct { protocolVersionReturnsOnCall map[int]struct { result1 types.ProtocolVersion } - RemovePublishedTrackStub func(types.MediaTrack, bool, bool) + RemovePublishedTrackStub func(types.MediaTrack, bool) removePublishedTrackMutex sync.RWMutex removePublishedTrackArgsForCall []struct { arg1 types.MediaTrack arg2 bool - arg3 bool } RemoveTrackFromSubscriberStub func(*webrtc.RTPSender) error removeTrackFromSubscriberMutex sync.RWMutex @@ -4267,18 +4266,17 @@ func (fake *FakeLocalParticipant) ProtocolVersionReturnsOnCall(i int, result1 ty }{result1} } -func (fake *FakeLocalParticipant) RemovePublishedTrack(arg1 types.MediaTrack, arg2 bool, arg3 bool) { +func (fake *FakeLocalParticipant) RemovePublishedTrack(arg1 types.MediaTrack, arg2 bool) { fake.removePublishedTrackMutex.Lock() fake.removePublishedTrackArgsForCall = append(fake.removePublishedTrackArgsForCall, struct { arg1 types.MediaTrack arg2 bool - arg3 bool - }{arg1, arg2, arg3}) + }{arg1, arg2}) stub := fake.RemovePublishedTrackStub - fake.recordInvocation("RemovePublishedTrack", []interface{}{arg1, arg2, arg3}) + fake.recordInvocation("RemovePublishedTrack", []interface{}{arg1, arg2}) fake.removePublishedTrackMutex.Unlock() if stub != nil { - fake.RemovePublishedTrackStub(arg1, arg2, arg3) + fake.RemovePublishedTrackStub(arg1, arg2) } } @@ -4288,17 +4286,17 @@ func (fake *FakeLocalParticipant) RemovePublishedTrackCallCount() int { return len(fake.removePublishedTrackArgsForCall) } -func (fake *FakeLocalParticipant) RemovePublishedTrackCalls(stub func(types.MediaTrack, bool, bool)) { +func (fake *FakeLocalParticipant) RemovePublishedTrackCalls(stub func(types.MediaTrack, bool)) { fake.removePublishedTrackMutex.Lock() defer fake.removePublishedTrackMutex.Unlock() fake.RemovePublishedTrackStub = stub } -func (fake *FakeLocalParticipant) RemovePublishedTrackArgsForCall(i int) (types.MediaTrack, bool, bool) { +func (fake *FakeLocalParticipant) RemovePublishedTrackArgsForCall(i int) (types.MediaTrack, bool) { fake.removePublishedTrackMutex.RLock() defer fake.removePublishedTrackMutex.RUnlock() argsForCall := fake.removePublishedTrackArgsForCall[i] - return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 + return argsForCall.arg1, argsForCall.arg2 } func (fake *FakeLocalParticipant) RemoveTrackFromSubscriber(arg1 *webrtc.RTPSender) error { diff --git a/pkg/rtc/types/typesfakes/fake_participant.go b/pkg/rtc/types/typesfakes/fake_participant.go index 98fff9c8..14f5d4fc 100644 --- a/pkg/rtc/types/typesfakes/fake_participant.go +++ b/pkg/rtc/types/typesfakes/fake_participant.go @@ -158,12 +158,11 @@ type FakeParticipant struct { isRecorderReturnsOnCall map[int]struct { result1 bool } - RemovePublishedTrackStub func(types.MediaTrack, bool, bool) + RemovePublishedTrackStub func(types.MediaTrack, bool) removePublishedTrackMutex sync.RWMutex removePublishedTrackArgsForCall []struct { arg1 types.MediaTrack arg2 bool - arg3 bool } SetMetadataStub func(string) setMetadataMutex sync.RWMutex @@ -1008,18 +1007,17 @@ func (fake *FakeParticipant) IsRecorderReturnsOnCall(i int, result1 bool) { }{result1} } -func (fake *FakeParticipant) RemovePublishedTrack(arg1 types.MediaTrack, arg2 bool, arg3 bool) { +func (fake *FakeParticipant) RemovePublishedTrack(arg1 types.MediaTrack, arg2 bool) { fake.removePublishedTrackMutex.Lock() fake.removePublishedTrackArgsForCall = append(fake.removePublishedTrackArgsForCall, struct { arg1 types.MediaTrack arg2 bool - arg3 bool - }{arg1, arg2, arg3}) + }{arg1, arg2}) stub := fake.RemovePublishedTrackStub - fake.recordInvocation("RemovePublishedTrack", []interface{}{arg1, arg2, arg3}) + fake.recordInvocation("RemovePublishedTrack", []interface{}{arg1, arg2}) fake.removePublishedTrackMutex.Unlock() if stub != nil { - fake.RemovePublishedTrackStub(arg1, arg2, arg3) + fake.RemovePublishedTrackStub(arg1, arg2) } } @@ -1029,17 +1027,17 @@ func (fake *FakeParticipant) RemovePublishedTrackCallCount() int { return len(fake.removePublishedTrackArgsForCall) } -func (fake *FakeParticipant) RemovePublishedTrackCalls(stub func(types.MediaTrack, bool, bool)) { +func (fake *FakeParticipant) RemovePublishedTrackCalls(stub func(types.MediaTrack, bool)) { fake.removePublishedTrackMutex.Lock() defer fake.removePublishedTrackMutex.Unlock() fake.RemovePublishedTrackStub = stub } -func (fake *FakeParticipant) RemovePublishedTrackArgsForCall(i int) (types.MediaTrack, bool, bool) { +func (fake *FakeParticipant) RemovePublishedTrackArgsForCall(i int) (types.MediaTrack, bool) { fake.removePublishedTrackMutex.RLock() defer fake.removePublishedTrackMutex.RUnlock() argsForCall := fake.removePublishedTrackArgsForCall[i] - return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 + return argsForCall.arg1, argsForCall.arg2 } func (fake *FakeParticipant) SetMetadata(arg1 string) { diff --git a/pkg/rtc/uptrackmanager.go b/pkg/rtc/uptrackmanager.go index 65d0893d..9ec2f608 100644 --- a/pkg/rtc/uptrackmanager.go +++ b/pkg/rtc/uptrackmanager.go @@ -46,8 +46,8 @@ type UpTrackManager struct { closed bool // publishedTracks that participant is publishing - publishedTracks map[livekit.TrackID]types.MediaTrack - subscriptionPermission *livekit.SubscriptionPermission + publishedTracks map[livekit.TrackID]types.MediaTrack + subscriptionPermission *livekit.SubscriptionPermission // subscriber permission for published tracks subscriberPermissions map[livekit.ParticipantIdentity]*livekit.TrackPermission // subscriberIdentity => *livekit.TrackPermission @@ -268,12 +268,8 @@ func (u *UpTrackManager) AddPublishedTrack(track types.MediaTrack) { }) } -func (u *UpTrackManager) RemovePublishedTrack(track types.MediaTrack, willBeResumed bool, shouldClose bool) { - if shouldClose { - track.Close(willBeResumed) - } else { - track.ClearAllReceivers(willBeResumed) - } +func (u *UpTrackManager) RemovePublishedTrack(track types.MediaTrack, willBeResumed bool) { + track.Close(willBeResumed) u.lock.Lock() delete(u.publishedTracks, track.ID()) u.lock.Unlock() diff --git a/pkg/service/wire_gen.go b/pkg/service/wire_gen.go index 82d232e5..ea62d53f 100644 --- a/pkg/service/wire_gen.go +++ b/pkg/service/wire_gen.go @@ -1,6 +1,6 @@ // Code generated by Wire. DO NOT EDIT. -//go:generate go run -mod=mod github.com/google/wire/cmd/wire +//go:generate go run github.com/google/wire/cmd/wire //go:build !wireinject // +build !wireinject diff --git a/pkg/sfu/forwarder.go b/pkg/sfu/forwarder.go index fceebbdd..79d0c2ee 100644 --- a/pkg/sfu/forwarder.go +++ b/pkg/sfu/forwarder.go @@ -247,7 +247,7 @@ func (f *Forwarder) SetMaxPublishedLayer(maxPublishedLayer int32) bool { } f.vls.SetMaxSeenSpatial(maxPublishedLayer) - f.logger.Debugw("setting max published layer", "maxPublishedLayer", maxPublishedLayer) + f.logger.Debugw("setting max published layer", "layer", maxPublishedLayer) return true }