Move subscribe/unsubscribe queue to participant. (#813)
* Move subscribe/unsubscribe queue to participant. As subscribe/unsubscribe operation can come from both local media track or remote media track, participant needs to have it. * Remove comment * Stop reneg timer on close * address comments
This commit is contained in:
@@ -38,6 +38,20 @@ func (r *simulcastReceiver) Priority() int {
|
||||
return r.priority
|
||||
}
|
||||
|
||||
type MediaTrackReceiverParams struct {
|
||||
TrackInfo *livekit.TrackInfo
|
||||
MediaTrack types.MediaTrack
|
||||
ParticipantID livekit.ParticipantID
|
||||
ParticipantIdentity livekit.ParticipantIdentity
|
||||
ParticipantVersion uint32
|
||||
BufferFactory *buffer.Factory
|
||||
ReceiverConfig ReceiverConfig
|
||||
SubscriberConfig DirectionConfig
|
||||
VideoConfig config.VideoConfig
|
||||
Telemetry telemetry.TelemetryService
|
||||
Logger logger.Logger
|
||||
}
|
||||
|
||||
type MediaTrackReceiver struct {
|
||||
params MediaTrackReceiverParams
|
||||
muted atomic.Bool
|
||||
@@ -62,19 +76,6 @@ type MediaTrackReceiver struct {
|
||||
*MediaTrackSubscriptions
|
||||
}
|
||||
|
||||
type MediaTrackReceiverParams struct {
|
||||
TrackInfo *livekit.TrackInfo
|
||||
MediaTrack types.MediaTrack
|
||||
ParticipantID livekit.ParticipantID
|
||||
ParticipantIdentity livekit.ParticipantIdentity
|
||||
BufferFactory *buffer.Factory
|
||||
ReceiverConfig ReceiverConfig
|
||||
SubscriberConfig DirectionConfig
|
||||
VideoConfig config.VideoConfig
|
||||
Telemetry telemetry.TelemetryService
|
||||
Logger logger.Logger
|
||||
}
|
||||
|
||||
func NewMediaTrackReceiver(params MediaTrackReceiverParams) *MediaTrackReceiver {
|
||||
t := &MediaTrackReceiver{
|
||||
params: params,
|
||||
@@ -92,6 +93,9 @@ func NewMediaTrackReceiver(params MediaTrackReceiverParams) *MediaTrackReceiver
|
||||
Logger: params.Logger,
|
||||
})
|
||||
t.MediaTrackSubscriptions.OnDownTrackCreated(t.onDownTrackCreated)
|
||||
t.MediaTrackSubscriptions.OnSubscriptionOperationComplete(func(sub types.LocalParticipant) {
|
||||
go sub.ClearInProgressAndProcessSubscriptionRequestsQueue(t.ID())
|
||||
})
|
||||
|
||||
if t.trackInfo.Muted {
|
||||
t.SetMuted(true)
|
||||
@@ -305,6 +309,10 @@ func (t *MediaTrackReceiver) PublisherIdentity() livekit.ParticipantIdentity {
|
||||
return t.params.ParticipantIdentity
|
||||
}
|
||||
|
||||
func (t *MediaTrackReceiver) PublisherVersion() uint32 {
|
||||
return t.params.ParticipantVersion
|
||||
}
|
||||
|
||||
func (t *MediaTrackReceiver) IsSimulcast() bool {
|
||||
return t.simulcasted.Load()
|
||||
}
|
||||
@@ -349,6 +357,12 @@ func (t *MediaTrackReceiver) AddOnClose(f func()) {
|
||||
|
||||
// AddSubscriber subscribes sub to current mediaTrack
|
||||
func (t *MediaTrackReceiver) AddSubscriber(sub types.LocalParticipant) error {
|
||||
trackID := t.ID()
|
||||
sub.EnqueueSubscribeTrack(trackID, t.addSubscriber)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *MediaTrackReceiver) addSubscriber(sub types.LocalParticipant) error {
|
||||
t.lock.RLock()
|
||||
receivers := t.receiversShadow
|
||||
potentialCodecs := make([]webrtc.RTPCodecParameters, len(t.potentialCodecs))
|
||||
@@ -390,6 +404,52 @@ func (t *MediaTrackReceiver) AddSubscriber(sub types.LocalParticipant) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemoveSubscriber removes participant from subscription
|
||||
// stop all forwarders to the client
|
||||
func (t *MediaTrackReceiver) RemoveSubscriber(subscriberID livekit.ParticipantID, willBeResumed bool) {
|
||||
subTrack := t.getSubscribedTrack(subscriberID)
|
||||
if subTrack == nil {
|
||||
return
|
||||
}
|
||||
|
||||
sub := subTrack.Subscriber()
|
||||
trackID := subTrack.ID()
|
||||
sub.EnqueueUnsubscribeTrack(trackID, willBeResumed, t.MediaTrackSubscriptions.RemoveSubscriber)
|
||||
}
|
||||
|
||||
func (t *MediaTrackReceiver) RemoveAllSubscribers(willBeResumed bool) {
|
||||
t.params.Logger.Debugw("removing all subscribers")
|
||||
for _, subscriberID := range t.MediaTrackSubscriptions.GetAllSubscribers() {
|
||||
t.RemoveSubscriber(subscriberID, willBeResumed)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *MediaTrackReceiver) RevokeDisallowedSubscribers(allowedSubscriberIdentities []livekit.ParticipantIdentity) []livekit.ParticipantIdentity {
|
||||
var revokedSubscriberIdentities []livekit.ParticipantIdentity
|
||||
|
||||
// LK-TODO: large number of subscribers needs to be solved for this loop
|
||||
for _, subTrack := range t.MediaTrackSubscriptions.getAllSubscribedTracks() {
|
||||
found := false
|
||||
for _, allowedIdentity := range allowedSubscriberIdentities {
|
||||
if subTrack.SubscriberIdentity() == allowedIdentity {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
t.params.Logger.Infow("revoking subscription",
|
||||
"subscriber", subTrack.SubscriberIdentity(),
|
||||
"subscriberID", subTrack.SubscriberID(),
|
||||
)
|
||||
t.RemoveSubscriber(subTrack.SubscriberID(), false)
|
||||
revokedSubscriberIdentities = append(revokedSubscriberIdentities, subTrack.SubscriberIdentity())
|
||||
}
|
||||
}
|
||||
|
||||
return revokedSubscriberIdentities
|
||||
}
|
||||
|
||||
func (t *MediaTrackReceiver) UpdateTrackInfo(ti *livekit.TrackInfo) {
|
||||
t.lock.Lock()
|
||||
t.trackInfo = proto.Clone(ti).(*livekit.TrackInfo)
|
||||
|
||||
Reference in New Issue
Block a user