Fix publish track count on migration in. (#4740)
* Fix publish track count on migration in. https://github.com/livekit/livekit/pull/4707 addressed the case of publish tracks overcounting due to synthesised track publish on migrate in. But, it introduced an issue where published tracks count could go negative because unpublish subtracted the counter irrespective of the track actually migrated in or not. Fix it by keeping track of local publish. Also, the older code was skipping publisher track count increase if the synthesised publish was handled first. Address it by checking if the track is actually new (i. e. fresh local publish) when the track was already created in the migrate in path. * fix pub time for tracks published after migration * test * prevent multiple track egresses
This commit is contained in:
+26
-15
@@ -125,6 +125,7 @@ type Room struct {
|
||||
participantOpts map[livekit.ParticipantIdentity]*ParticipantOptions
|
||||
participantRequestSources map[livekit.ParticipantIdentity]routing.MessageSource
|
||||
hasPublished map[livekit.ParticipantIdentity]bool
|
||||
launchedTrackEgresses map[livekit.ParticipantIdentity][]livekit.TrackID
|
||||
agentParticpants map[livekit.ParticipantIdentity]*agentJob
|
||||
bufferFactory *buffer.FactoryOfBufferFactory
|
||||
|
||||
@@ -273,6 +274,7 @@ func NewRoom(
|
||||
participantOpts: make(map[livekit.ParticipantIdentity]*ParticipantOptions),
|
||||
participantRequestSources: make(map[livekit.ParticipantIdentity]routing.MessageSource),
|
||||
hasPublished: make(map[livekit.ParticipantIdentity]bool),
|
||||
launchedTrackEgresses: make(map[livekit.ParticipantIdentity][]livekit.TrackID),
|
||||
agentParticpants: make(map[livekit.ParticipantIdentity]*agentJob),
|
||||
bufferFactory: buffer.NewFactoryOfBufferFactory(config.Receiver.PacketBufferSizeVideo, config.Receiver.PacketBufferSizeAudio),
|
||||
batchedUpdates: make(map[livekit.ParticipantIdentity]*ParticipantUpdate),
|
||||
@@ -1133,19 +1135,27 @@ func (r *Room) onTrackPublished(participant types.Participant, track types.Media
|
||||
}
|
||||
}
|
||||
if participant.Kind() != livekit.ParticipantInfo_EGRESS && r.internal != nil && r.internal.TrackEgress != nil {
|
||||
go func() {
|
||||
if err := StartTrackEgress(
|
||||
context.Background(),
|
||||
r.egressLauncher,
|
||||
r.telemetry,
|
||||
r.internal.TrackEgress,
|
||||
track,
|
||||
r.Name(),
|
||||
r.ID(),
|
||||
); err != nil {
|
||||
r.logger.Errorw("failed to launch track egress", err)
|
||||
}
|
||||
}()
|
||||
r.lock.Lock()
|
||||
launchedTrackEgress := slices.Contains(r.launchedTrackEgresses[participant.Identity()], track.ID())
|
||||
if !launchedTrackEgress {
|
||||
r.launchedTrackEgresses[participant.Identity()] = append(r.launchedTrackEgresses[participant.Identity()], track.ID())
|
||||
}
|
||||
r.lock.Unlock()
|
||||
if !launchedTrackEgress {
|
||||
go func() {
|
||||
if err := StartTrackEgress(
|
||||
context.Background(),
|
||||
r.egressLauncher,
|
||||
r.telemetry,
|
||||
r.internal.TrackEgress,
|
||||
track,
|
||||
r.Name(),
|
||||
r.ID(),
|
||||
); err != nil {
|
||||
r.logger.Errorw("failed to launch track egress", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1417,6 +1427,7 @@ func (r *Room) RemoveParticipant(
|
||||
delete(r.participantOpts, identity)
|
||||
delete(r.participantRequestSources, identity)
|
||||
delete(r.hasPublished, identity)
|
||||
delete(r.launchedTrackEgresses, identity)
|
||||
delete(r.agentParticpants, identity)
|
||||
if !p.Hidden() {
|
||||
r.protoRoom.NumParticipants--
|
||||
@@ -2047,8 +2058,8 @@ func (l participantTelemetryListener) OnTrackPublished(pID livekit.ParticipantID
|
||||
l.room.telemetry.TrackPublished(context.Background(), l.eventRoom(), pID, identity, ti, shouldSendEvent)
|
||||
}
|
||||
|
||||
func (l participantTelemetryListener) OnTrackUnpublished(pID livekit.ParticipantID, identity livekit.ParticipantIdentity, ti *livekit.TrackInfo, shouldSendEvent bool) {
|
||||
l.room.telemetry.TrackUnpublished(context.Background(), l.eventRoom(), pID, identity, ti, shouldSendEvent)
|
||||
func (l participantTelemetryListener) OnTrackUnpublished(pID livekit.ParticipantID, identity livekit.ParticipantIdentity, ti *livekit.TrackInfo, wasPublishedLocally bool, shouldSendEvent bool) {
|
||||
l.room.telemetry.TrackUnpublished(context.Background(), l.eventRoom(), pID, identity, ti, wasPublishedLocally, shouldSendEvent)
|
||||
}
|
||||
|
||||
func (l participantTelemetryListener) OnTrackSubscribeRequested(pID livekit.ParticipantID, ti *livekit.TrackInfo) {
|
||||
|
||||
Reference in New Issue
Block a user