move TrackSubscribed trigger to MediaSubscription (#2916)
This commit is contained in:
@@ -285,7 +285,6 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Tra
|
|||||||
sfu.WithLoadBalanceThreshold(20),
|
sfu.WithLoadBalanceThreshold(20),
|
||||||
sfu.WithStreamTrackers(),
|
sfu.WithStreamTrackers(),
|
||||||
sfu.WithForwardStats(t.params.ForwardStats),
|
sfu.WithForwardStats(t.params.ForwardStats),
|
||||||
sfu.WithEverHasDownTrackAdded(t.handleReceiverEverAddDowntrack),
|
|
||||||
)
|
)
|
||||||
newWR.OnCloseHandler(func() {
|
newWR.OnCloseHandler(func() {
|
||||||
t.MediaTrackReceiver.SetClosing()
|
t.MediaTrackReceiver.SetClosing()
|
||||||
@@ -434,7 +433,7 @@ func (t *MediaTrack) SetMuted(muted bool) {
|
|||||||
t.MediaTrackReceiver.SetMuted(muted)
|
t.MediaTrackReceiver.SetMuted(muted)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MediaTrack) handleReceiverEverAddDowntrack() {
|
func (t *MediaTrack) OnTrackSubscribed() {
|
||||||
if !t.everSubscribed.Swap(true) && t.params.OnTrackEverSubscribed != nil {
|
if !t.everSubscribed.Swap(true) && t.params.OnTrackEverSubscribed != nil {
|
||||||
go t.params.OnTrackEverSubscribed(t.ID())
|
go t.params.OnTrackEverSubscribed(t.ID())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,6 +161,12 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, wr *
|
|||||||
AdaptiveStream: sub.GetAdaptiveStream(),
|
AdaptiveStream: sub.GetAdaptiveStream(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
subTrack.AddOnBind(func(err error) {
|
||||||
|
if err == nil {
|
||||||
|
t.params.MediaTrack.OnTrackSubscribed()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Bind callback can happen from replaceTrack, so set it up early
|
// Bind callback can happen from replaceTrack, so set it up early
|
||||||
var reusingTransceiver atomic.Bool
|
var reusingTransceiver atomic.Bool
|
||||||
var dtState sfu.DownTrackState
|
var dtState sfu.DownTrackState
|
||||||
|
|||||||
@@ -495,6 +495,7 @@ type MediaTrack interface {
|
|||||||
RevokeDisallowedSubscribers(allowedSubscriberIdentities []livekit.ParticipantIdentity) []livekit.ParticipantIdentity
|
RevokeDisallowedSubscribers(allowedSubscriberIdentities []livekit.ParticipantIdentity) []livekit.ParticipantIdentity
|
||||||
GetAllSubscribers() []livekit.ParticipantID
|
GetAllSubscribers() []livekit.ParticipantID
|
||||||
GetNumSubscribers() int
|
GetNumSubscribers() int
|
||||||
|
OnTrackSubscribed()
|
||||||
|
|
||||||
// returns quality information that's appropriate for width & height
|
// returns quality information that's appropriate for width & height
|
||||||
GetQualityForDimension(width, height uint32) livekit.VideoQuality
|
GetQualityForDimension(width, height uint32) livekit.VideoQuality
|
||||||
|
|||||||
@@ -221,6 +221,10 @@ type FakeLocalMediaTrack struct {
|
|||||||
arg1 livekit.NodeID
|
arg1 livekit.NodeID
|
||||||
arg2 uint8
|
arg2 uint8
|
||||||
}
|
}
|
||||||
|
OnTrackSubscribedStub func()
|
||||||
|
onTrackSubscribedMutex sync.RWMutex
|
||||||
|
onTrackSubscribedArgsForCall []struct {
|
||||||
|
}
|
||||||
PublisherIDStub func() livekit.ParticipantID
|
PublisherIDStub func() livekit.ParticipantID
|
||||||
publisherIDMutex sync.RWMutex
|
publisherIDMutex sync.RWMutex
|
||||||
publisherIDArgsForCall []struct {
|
publisherIDArgsForCall []struct {
|
||||||
@@ -1471,6 +1475,30 @@ func (fake *FakeLocalMediaTrack) NotifySubscriberNodeMediaLossArgsForCall(i int)
|
|||||||
return argsForCall.arg1, argsForCall.arg2
|
return argsForCall.arg1, argsForCall.arg2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalMediaTrack) OnTrackSubscribed() {
|
||||||
|
fake.onTrackSubscribedMutex.Lock()
|
||||||
|
fake.onTrackSubscribedArgsForCall = append(fake.onTrackSubscribedArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
stub := fake.OnTrackSubscribedStub
|
||||||
|
fake.recordInvocation("OnTrackSubscribed", []interface{}{})
|
||||||
|
fake.onTrackSubscribedMutex.Unlock()
|
||||||
|
if stub != nil {
|
||||||
|
fake.OnTrackSubscribedStub()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalMediaTrack) OnTrackSubscribedCallCount() int {
|
||||||
|
fake.onTrackSubscribedMutex.RLock()
|
||||||
|
defer fake.onTrackSubscribedMutex.RUnlock()
|
||||||
|
return len(fake.onTrackSubscribedArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalMediaTrack) OnTrackSubscribedCalls(stub func()) {
|
||||||
|
fake.onTrackSubscribedMutex.Lock()
|
||||||
|
defer fake.onTrackSubscribedMutex.Unlock()
|
||||||
|
fake.OnTrackSubscribedStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
func (fake *FakeLocalMediaTrack) PublisherID() livekit.ParticipantID {
|
func (fake *FakeLocalMediaTrack) PublisherID() livekit.ParticipantID {
|
||||||
fake.publisherIDMutex.Lock()
|
fake.publisherIDMutex.Lock()
|
||||||
ret, specificReturn := fake.publisherIDReturnsOnCall[len(fake.publisherIDArgsForCall)]
|
ret, specificReturn := fake.publisherIDReturnsOnCall[len(fake.publisherIDArgsForCall)]
|
||||||
@@ -2225,6 +2253,8 @@ func (fake *FakeLocalMediaTrack) Invocations() map[string][][]interface{} {
|
|||||||
defer fake.notifySubscriberNodeMaxQualityMutex.RUnlock()
|
defer fake.notifySubscriberNodeMaxQualityMutex.RUnlock()
|
||||||
fake.notifySubscriberNodeMediaLossMutex.RLock()
|
fake.notifySubscriberNodeMediaLossMutex.RLock()
|
||||||
defer fake.notifySubscriberNodeMediaLossMutex.RUnlock()
|
defer fake.notifySubscriberNodeMediaLossMutex.RUnlock()
|
||||||
|
fake.onTrackSubscribedMutex.RLock()
|
||||||
|
defer fake.onTrackSubscribedMutex.RUnlock()
|
||||||
fake.publisherIDMutex.RLock()
|
fake.publisherIDMutex.RLock()
|
||||||
defer fake.publisherIDMutex.RUnlock()
|
defer fake.publisherIDMutex.RUnlock()
|
||||||
fake.publisherIdentityMutex.RLock()
|
fake.publisherIdentityMutex.RLock()
|
||||||
|
|||||||
@@ -176,6 +176,10 @@ type FakeMediaTrack struct {
|
|||||||
nameReturnsOnCall map[int]struct {
|
nameReturnsOnCall map[int]struct {
|
||||||
result1 string
|
result1 string
|
||||||
}
|
}
|
||||||
|
OnTrackSubscribedStub func()
|
||||||
|
onTrackSubscribedMutex sync.RWMutex
|
||||||
|
onTrackSubscribedArgsForCall []struct {
|
||||||
|
}
|
||||||
PublisherIDStub func() livekit.ParticipantID
|
PublisherIDStub func() livekit.ParticipantID
|
||||||
publisherIDMutex sync.RWMutex
|
publisherIDMutex sync.RWMutex
|
||||||
publisherIDArgsForCall []struct {
|
publisherIDArgsForCall []struct {
|
||||||
@@ -1166,6 +1170,30 @@ func (fake *FakeMediaTrack) NameReturnsOnCall(i int, result1 string) {
|
|||||||
}{result1}
|
}{result1}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fake *FakeMediaTrack) OnTrackSubscribed() {
|
||||||
|
fake.onTrackSubscribedMutex.Lock()
|
||||||
|
fake.onTrackSubscribedArgsForCall = append(fake.onTrackSubscribedArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
stub := fake.OnTrackSubscribedStub
|
||||||
|
fake.recordInvocation("OnTrackSubscribed", []interface{}{})
|
||||||
|
fake.onTrackSubscribedMutex.Unlock()
|
||||||
|
if stub != nil {
|
||||||
|
fake.OnTrackSubscribedStub()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeMediaTrack) OnTrackSubscribedCallCount() int {
|
||||||
|
fake.onTrackSubscribedMutex.RLock()
|
||||||
|
defer fake.onTrackSubscribedMutex.RUnlock()
|
||||||
|
return len(fake.onTrackSubscribedArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeMediaTrack) OnTrackSubscribedCalls(stub func()) {
|
||||||
|
fake.onTrackSubscribedMutex.Lock()
|
||||||
|
defer fake.onTrackSubscribedMutex.Unlock()
|
||||||
|
fake.OnTrackSubscribedStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
func (fake *FakeMediaTrack) PublisherID() livekit.ParticipantID {
|
func (fake *FakeMediaTrack) PublisherID() livekit.ParticipantID {
|
||||||
fake.publisherIDMutex.Lock()
|
fake.publisherIDMutex.Lock()
|
||||||
ret, specificReturn := fake.publisherIDReturnsOnCall[len(fake.publisherIDArgsForCall)]
|
ret, specificReturn := fake.publisherIDReturnsOnCall[len(fake.publisherIDArgsForCall)]
|
||||||
@@ -1801,6 +1829,8 @@ func (fake *FakeMediaTrack) Invocations() map[string][][]interface{} {
|
|||||||
defer fake.kindMutex.RUnlock()
|
defer fake.kindMutex.RUnlock()
|
||||||
fake.nameMutex.RLock()
|
fake.nameMutex.RLock()
|
||||||
defer fake.nameMutex.RUnlock()
|
defer fake.nameMutex.RUnlock()
|
||||||
|
fake.onTrackSubscribedMutex.RLock()
|
||||||
|
defer fake.onTrackSubscribedMutex.RUnlock()
|
||||||
fake.publisherIDMutex.RLock()
|
fake.publisherIDMutex.RLock()
|
||||||
defer fake.publisherIDMutex.RUnlock()
|
defer fake.publisherIDMutex.RUnlock()
|
||||||
fake.publisherIdentityMutex.RLock()
|
fake.publisherIdentityMutex.RLock()
|
||||||
|
|||||||
+2
-20
@@ -120,10 +120,8 @@ type WebRTCReceiver struct {
|
|||||||
|
|
||||||
connectionStats *connectionquality.ConnectionStats
|
connectionStats *connectionquality.ConnectionStats
|
||||||
|
|
||||||
onStatsUpdate func(w *WebRTCReceiver, stat *livekit.AnalyticsStat)
|
onStatsUpdate func(w *WebRTCReceiver, stat *livekit.AnalyticsStat)
|
||||||
onMaxLayerChange func(maxLayer int32)
|
onMaxLayerChange func(maxLayer int32)
|
||||||
downTrackEverAdded atomic.Bool
|
|
||||||
onDownTrackEverAdded func()
|
|
||||||
|
|
||||||
primaryReceiver atomic.Pointer[RedPrimaryReceiver]
|
primaryReceiver atomic.Pointer[RedPrimaryReceiver]
|
||||||
redReceiver atomic.Pointer[RedReceiver]
|
redReceiver atomic.Pointer[RedReceiver]
|
||||||
@@ -177,13 +175,6 @@ func WithForwardStats(forwardStats *ForwardStats) ReceiverOpts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithEverHasDownTrackAdded(f func()) ReceiverOpts {
|
|
||||||
return func(w *WebRTCReceiver) *WebRTCReceiver {
|
|
||||||
w.onDownTrackEverAdded = f
|
|
||||||
return w
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewWebRTCReceiver creates a new webrtc track receiver
|
// NewWebRTCReceiver creates a new webrtc track receiver
|
||||||
func NewWebRTCReceiver(
|
func NewWebRTCReceiver(
|
||||||
receiver *webrtc.RTPReceiver,
|
receiver *webrtc.RTPReceiver,
|
||||||
@@ -420,16 +411,9 @@ func (w *WebRTCReceiver) AddDownTrack(track TrackSender) error {
|
|||||||
|
|
||||||
w.downTrackSpreader.Store(track)
|
w.downTrackSpreader.Store(track)
|
||||||
w.logger.Debugw("downtrack added", "subscriberID", track.SubscriberID())
|
w.logger.Debugw("downtrack added", "subscriberID", track.SubscriberID())
|
||||||
w.handleDowntrackAdded()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WebRTCReceiver) handleDowntrackAdded() {
|
|
||||||
if !w.downTrackEverAdded.Swap(true) && w.onDownTrackEverAdded != nil {
|
|
||||||
w.onDownTrackEverAdded()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *WebRTCReceiver) notifyMaxExpectedLayer(layer int32) {
|
func (w *WebRTCReceiver) notifyMaxExpectedLayer(layer int32) {
|
||||||
ti := w.TrackInfo()
|
ti := w.TrackInfo()
|
||||||
if ti == nil {
|
if ti == nil {
|
||||||
@@ -792,7 +776,6 @@ func (w *WebRTCReceiver) GetPrimaryReceiverForRed() TrackReceiver {
|
|||||||
w.bufferMu.Lock()
|
w.bufferMu.Lock()
|
||||||
w.redPktWriter = pr.ForwardRTP
|
w.redPktWriter = pr.ForwardRTP
|
||||||
w.bufferMu.Unlock()
|
w.bufferMu.Unlock()
|
||||||
w.handleDowntrackAdded()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return w.primaryReceiver.Load()
|
return w.primaryReceiver.Load()
|
||||||
@@ -812,7 +795,6 @@ func (w *WebRTCReceiver) GetRedReceiver() TrackReceiver {
|
|||||||
w.bufferMu.Lock()
|
w.bufferMu.Lock()
|
||||||
w.redPktWriter = pr.ForwardRTP
|
w.redPktWriter = pr.ForwardRTP
|
||||||
w.bufferMu.Unlock()
|
w.bufferMu.Unlock()
|
||||||
w.handleDowntrackAdded()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return w.redReceiver.Load()
|
return w.redReceiver.Load()
|
||||||
|
|||||||
Reference in New Issue
Block a user