Added track success & muted events (#1308)
Related to livekit/protocol#273 This PR adds: - ParticipantResumed - for when ICE restart or migration had occurred - TrackPublishRequested - when we initiate a publication - TrackSubscribeRequested - when we initiate a subscription - TrackMuted - publisher muted track - TrackUnmuted - publisher unmuted track - TrackPublish/TrackSubcribe events will indicate when those actions have been successful, to differentiate.
This commit is contained in:
@@ -247,13 +247,6 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Tra
|
||||
if t.dynacastManager != nil {
|
||||
t.dynacastManager.Close()
|
||||
}
|
||||
t.params.Telemetry.TrackUnpublished(
|
||||
context.Background(),
|
||||
t.PublisherID(),
|
||||
t.PublisherIdentity(),
|
||||
t.ToProto(),
|
||||
uint32(track.SSRC()),
|
||||
)
|
||||
}
|
||||
})
|
||||
newWR.OnStatsUpdate(func(_ *sfu.WebRTCReceiver, stat *livekit.AnalyticsStat) {
|
||||
@@ -277,12 +270,6 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Tra
|
||||
t.params.Logger.Debugw("primary codec published, set potential codecs", "potential", potentialCodecs)
|
||||
t.MediaTrackReceiver.SetPotentialCodecs(potentialCodecs, parameters.HeaderExtensions)
|
||||
}
|
||||
t.params.Telemetry.TrackPublished(
|
||||
context.Background(),
|
||||
t.PublisherID(),
|
||||
t.PublisherIdentity(),
|
||||
t.ToProto(),
|
||||
)
|
||||
}
|
||||
|
||||
newWR.OnMaxLayerChange(t.onMaxLayerChange)
|
||||
|
||||
@@ -230,7 +230,7 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, wr *
|
||||
}
|
||||
}
|
||||
|
||||
// wthether re-using or stopping remove transceiver from cache
|
||||
// whether re-using or stopping remove transceiver from cache
|
||||
// NOTE: safety net, if somehow a cached transceiver is re-used by a different track
|
||||
sub.UncacheDownTrack(transceiver)
|
||||
|
||||
@@ -259,15 +259,6 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, wr *
|
||||
}
|
||||
}()
|
||||
|
||||
t.params.Telemetry.TrackSubscribed(
|
||||
context.Background(),
|
||||
subscriberID,
|
||||
t.params.MediaTrack.ToProto(),
|
||||
&livekit.ParticipantInfo{
|
||||
Sid: string(t.params.MediaTrack.PublisherID()),
|
||||
Identity: string(t.params.MediaTrack.PublisherIdentity()),
|
||||
},
|
||||
)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
+54
-7
@@ -608,7 +608,7 @@ func (p *ParticipantImpl) SetMigrateInfo(
|
||||
for _, t := range mediaTracks {
|
||||
ti := t.GetTrack()
|
||||
|
||||
p.supervisor.AddPublication(livekit.TrackID(ti.Sid), ti.Type)
|
||||
p.supervisor.AddPublication(livekit.TrackID(ti.Sid), nil)
|
||||
p.supervisor.SetPublicationMute(livekit.TrackID(ti.Sid), ti.Muted)
|
||||
|
||||
p.pendingTracks[t.GetCid()] = &pendingTrackInfo{trackInfos: []*livekit.TrackInfo{ti}, migrated: true}
|
||||
@@ -984,7 +984,16 @@ func (p *ParticipantImpl) AddSubscribedTrack(subTrack types.SubscribedTrack, sou
|
||||
onSubscribedTo := p.onSubscribedTo
|
||||
|
||||
p.subscribedTracks[subTrack.ID()] = subTrack
|
||||
// TODO: I believe we have yet to negotiate with the subscriber, so it's a bit early to consider the track been
|
||||
// successfully subscribed to
|
||||
// ideally we consider it's successful after the participant has answered that offer OR we've received the
|
||||
// first receiver report
|
||||
// will move the telemetry options when this is implemented
|
||||
p.supervisor.SetSubscribedTrack(subTrack.ID(), subTrack, sourceTrack)
|
||||
p.params.Telemetry.TrackSubscribed(context.Background(), p.ID(), sourceTrack.ToProto(), &livekit.ParticipantInfo{
|
||||
Identity: string(subTrack.PublisherIdentity()),
|
||||
Sid: string(subTrack.PublisherID()),
|
||||
})
|
||||
|
||||
settings := p.subscribedTracksSettings[subTrack.ID()]
|
||||
p.lock.Unlock()
|
||||
@@ -1567,10 +1576,17 @@ func (p *ParticipantImpl) addPendingTrackLocked(req *livekit.AddTrackRequest) *l
|
||||
})
|
||||
}
|
||||
|
||||
p.params.Telemetry.TrackPublishRequested(context.Background(), p.ID(), p.Identity(), ti)
|
||||
p.supervisor.AddPublication(livekit.TrackID(ti.Sid), func(t types.LocalMediaTrack) {
|
||||
p.params.Telemetry.TrackPublished(
|
||||
context.Background(),
|
||||
t.PublisherID(),
|
||||
t.PublisherIdentity(),
|
||||
t.ToProto(),
|
||||
)
|
||||
})
|
||||
p.supervisor.SetPublicationMute(livekit.TrackID(ti.Sid), ti.Muted)
|
||||
if p.getPublishedTrackBySignalCid(req.Cid) != nil || p.getPublishedTrackBySdpCid(req.Cid) != nil || p.pendingTracks[req.Cid] != nil {
|
||||
p.supervisor.AddPublication(livekit.TrackID(ti.Sid), ti.Type)
|
||||
p.supervisor.SetPublicationMute(livekit.TrackID(ti.Sid), ti.Muted)
|
||||
|
||||
if p.pendingTracks[req.Cid] == nil {
|
||||
p.pendingTracks[req.Cid] = &pendingTrackInfo{trackInfos: []*livekit.TrackInfo{ti}}
|
||||
} else {
|
||||
@@ -1580,9 +1596,6 @@ func (p *ParticipantImpl) addPendingTrackLocked(req *livekit.AddTrackRequest) *l
|
||||
return nil
|
||||
}
|
||||
|
||||
p.supervisor.AddPublication(livekit.TrackID(ti.Sid), ti.Type)
|
||||
p.supervisor.SetPublicationMute(livekit.TrackID(ti.Sid), ti.Muted)
|
||||
|
||||
p.pendingTracks[req.Cid] = &pendingTrackInfo{trackInfos: []*livekit.TrackInfo{ti}}
|
||||
p.params.Logger.Infow("pending track added", "trackID", ti.Sid, "track", ti.String(), "request", req.String())
|
||||
return ti
|
||||
@@ -1613,6 +1626,10 @@ func (p *ParticipantImpl) setTrackMuted(trackID livekit.TrackID, muted bool) {
|
||||
p.supervisor.SetPublicationMute(trackID, muted)
|
||||
|
||||
track := p.UpTrackManager.SetPublishedTrackMuted(trackID, muted)
|
||||
var trackInfo *livekit.TrackInfo
|
||||
if track != nil {
|
||||
trackInfo = track.ToProto()
|
||||
}
|
||||
|
||||
isPending := false
|
||||
p.pendingTracksLock.RLock()
|
||||
@@ -1621,11 +1638,20 @@ func (p *ParticipantImpl) setTrackMuted(trackID livekit.TrackID, muted bool) {
|
||||
if livekit.TrackID(ti.Sid) == trackID {
|
||||
ti.Muted = muted
|
||||
isPending = true
|
||||
trackInfo = ti
|
||||
}
|
||||
}
|
||||
}
|
||||
p.pendingTracksLock.RUnlock()
|
||||
|
||||
if trackInfo != nil {
|
||||
if muted {
|
||||
p.params.Telemetry.TrackMuted(context.Background(), p.ID(), trackInfo)
|
||||
} else {
|
||||
p.params.Telemetry.TrackUnmuted(context.Background(), p.ID(), trackInfo)
|
||||
}
|
||||
}
|
||||
|
||||
if !isPending && track == nil {
|
||||
p.params.Logger.Warnw("could not locate track", nil, "trackID", trackID)
|
||||
}
|
||||
@@ -1757,6 +1783,18 @@ func (p *ParticipantImpl) addMediaTrack(signalCid string, sdpCid string, ti *liv
|
||||
mt.AddOnClose(func() {
|
||||
p.supervisor.ClearPublishedTrack(livekit.TrackID(ti.Sid), mt)
|
||||
|
||||
// not logged when closing
|
||||
if !p.isClosed.Load() {
|
||||
p.params.Telemetry.TrackUnpublished(
|
||||
context.Background(),
|
||||
p.ID(),
|
||||
p.Identity(),
|
||||
mt.ToProto(),
|
||||
true,
|
||||
)
|
||||
}
|
||||
p.MigrateState()
|
||||
|
||||
// re-use track sid
|
||||
p.pendingTracksLock.Lock()
|
||||
if pti := p.pendingTracks[signalCid]; pti != nil {
|
||||
@@ -2085,6 +2123,15 @@ func (p *ParticipantImpl) EnqueueSubscribeTrack(trackID livekit.TrackID, sourceT
|
||||
p.params.Logger.Debugw("queuing subscribe", "trackID", trackID, "relayed", isRelayed)
|
||||
|
||||
p.supervisor.UpdateSubscription(trackID, true, sourceTrack)
|
||||
p.params.Telemetry.TrackSubscribeRequested(
|
||||
context.Background(),
|
||||
p.ID(),
|
||||
sourceTrack.ToProto(),
|
||||
&livekit.ParticipantInfo{
|
||||
Sid: string(sourceTrack.PublisherID()),
|
||||
Identity: string(sourceTrack.PublisherIdentity()),
|
||||
},
|
||||
)
|
||||
|
||||
p.lock.Lock()
|
||||
p.subscriptionRequestsQueue[trackID] = append(p.subscriptionRequestsQueue[trackID], SubscribeRequest{
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"go.uber.org/atomic"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/telemetry/telemetryfakes"
|
||||
"github.com/livekit/protocol/auth"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
@@ -481,6 +482,7 @@ func newParticipantForTestWithOpts(identity livekit.ParticipantIdentity, opts *p
|
||||
ClientConf: opts.clientConf,
|
||||
ClientInfo: ClientInfo{ClientInfo: opts.clientInfo},
|
||||
Logger: LoggerWithParticipant(logger.GetLogger(), identity, sid, false),
|
||||
Telemetry: &telemetryfakes.FakeTelemetryService{},
|
||||
})
|
||||
p.isPublisher.Store(opts.publisher)
|
||||
p.updateState(livekit.ParticipantInfo_ACTIVE)
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
monitorInterval = 3 * time.Second
|
||||
monitorInterval = 1 * time.Second
|
||||
)
|
||||
|
||||
type ParticipantSupervisorParams struct {
|
||||
@@ -92,7 +92,7 @@ func (p *ParticipantSupervisor) SetPublisherPeerConnectionConnected(isConnected
|
||||
p.lock.Unlock()
|
||||
}
|
||||
|
||||
func (p *ParticipantSupervisor) AddPublication(trackID livekit.TrackID, trackType livekit.TrackType) {
|
||||
func (p *ParticipantSupervisor) AddPublication(trackID livekit.TrackID, onSuccess func(track types.LocalMediaTrack)) {
|
||||
p.lock.Lock()
|
||||
pm, ok := p.publications[trackID]
|
||||
if !ok {
|
||||
@@ -102,12 +102,13 @@ func (p *ParticipantSupervisor) AddPublication(trackID livekit.TrackID, trackTyp
|
||||
TrackID: trackID,
|
||||
IsPeerConnectionConnected: p.isPublisherConnected,
|
||||
Logger: p.params.Logger,
|
||||
OnSuccess: onSuccess,
|
||||
},
|
||||
),
|
||||
}
|
||||
p.publications[trackID] = pm
|
||||
}
|
||||
pm.opMon.PostEvent(types.OperationMonitorEventAddPendingPublication, trackType.String())
|
||||
pm.opMon.PostEvent(types.OperationMonitorEventAddPendingPublication, nil)
|
||||
p.lock.Unlock()
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/gammazero/deque"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
)
|
||||
@@ -29,6 +28,7 @@ type PublicationMonitorParams struct {
|
||||
TrackID livekit.TrackID
|
||||
IsPeerConnectionConnected bool
|
||||
Logger logger.Logger
|
||||
OnSuccess func(t types.LocalMediaTrack)
|
||||
}
|
||||
|
||||
type PublicationMonitor struct {
|
||||
@@ -58,7 +58,7 @@ func (p *PublicationMonitor) PostEvent(ome types.OperationMonitorEvent, omd type
|
||||
case types.OperationMonitorEventPublisherPeerConnectionConnected:
|
||||
p.setConnected(omd.(bool))
|
||||
case types.OperationMonitorEventAddPendingPublication:
|
||||
p.addPending(omd.(string))
|
||||
p.addPending()
|
||||
case types.OperationMonitorEventSetPublicationMute:
|
||||
p.setMute(omd.(bool))
|
||||
case types.OperationMonitorEventSetPublishedTrack:
|
||||
@@ -68,9 +68,7 @@ func (p *PublicationMonitor) PostEvent(ome types.OperationMonitorEvent, omd type
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PublicationMonitor) addPending(trackType string) {
|
||||
prometheus.AddPublishAttempt(trackType)
|
||||
|
||||
func (p *PublicationMonitor) addPending() {
|
||||
p.lock.Lock()
|
||||
p.desiredPublishes.PushBack(
|
||||
&publish{
|
||||
@@ -171,7 +169,9 @@ func (p *PublicationMonitor) update() {
|
||||
}
|
||||
|
||||
if pub.isStart && p.publishedTrack != nil {
|
||||
prometheus.AddPublishSuccess(p.publishedTrack.Kind().String())
|
||||
if p.params.OnSuccess != nil {
|
||||
p.params.OnSuccess(p.publishedTrack)
|
||||
}
|
||||
}
|
||||
|
||||
if (pub.isStart && p.publishedTrack == nil) || (!pub.isStart && p.publishedTrack != nil) {
|
||||
|
||||
Reference in New Issue
Block a user