Annotate max subscribe layer change with events. (#2531)

Using events to understand what is causing max subscribed layer changes.
Seeing an edge case where all layers are disabled incorrectly.
This commit is contained in:
Raja Subramanian
2024-03-01 11:27:26 +05:30
committed by GitHub
parent 00db7bc79b
commit 95011d64f8
2 changed files with 13 additions and 10 deletions
+12 -9
View File
@@ -274,7 +274,7 @@ type DownTrack struct {
pacer pacer.Pacer pacer pacer.Pacer
maxLayerNotifierChMu sync.RWMutex maxLayerNotifierChMu sync.RWMutex
maxLayerNotifierCh chan struct{} maxLayerNotifierCh chan string
maxLayerNotifierChClosed bool maxLayerNotifierChClosed bool
keyFrameRequesterChMu sync.RWMutex keyFrameRequesterChMu sync.RWMutex
@@ -308,7 +308,7 @@ func NewDownTrack(params DowntrackParams) (*DownTrack, error) {
kind: kind, kind: kind,
codec: codecs[0].RTPCodecCapability, codec: codecs[0].RTPCodecCapability,
pacer: params.Pacer, pacer: params.Pacer,
maxLayerNotifierCh: make(chan struct{}, 1), maxLayerNotifierCh: make(chan string, 1),
keyFrameRequesterCh: make(chan struct{}, 1), keyFrameRequesterCh: make(chan struct{}, 1),
} }
d.forwarder = NewForwarder( d.forwarder = NewForwarder(
@@ -642,7 +642,7 @@ func (d *DownTrack) keyFrameRequester() {
} }
} }
func (d *DownTrack) postMaxLayerNotifierEvent() { func (d *DownTrack) postMaxLayerNotifierEvent(event string) {
if d.kind != webrtc.RTPCodecTypeVideo { if d.kind != webrtc.RTPCodecTypeVideo {
return return
} }
@@ -650,24 +650,27 @@ func (d *DownTrack) postMaxLayerNotifierEvent() {
d.maxLayerNotifierChMu.RLock() d.maxLayerNotifierChMu.RLock()
if !d.maxLayerNotifierChClosed { if !d.maxLayerNotifierChClosed {
select { select {
case d.maxLayerNotifierCh <- struct{}{}: case d.maxLayerNotifierCh <- event:
default: default:
d.params.Logger.Debugw("max layer notifier channel busy", "event", event)
} }
} }
d.maxLayerNotifierChMu.RUnlock() d.maxLayerNotifierChMu.RUnlock()
} }
func (d *DownTrack) maxLayerNotifierWorker() { func (d *DownTrack) maxLayerNotifierWorker() {
var event string
more := true more := true
for more { for more {
_, more = <-d.maxLayerNotifierCh event, more = <-d.maxLayerNotifierCh
maxLayerSpatial := buffer.InvalidLayerSpatial maxLayerSpatial := buffer.InvalidLayerSpatial
if more { if more {
maxLayerSpatial = d.forwarder.GetMaxSubscribedSpatial() maxLayerSpatial = d.forwarder.GetMaxSubscribedSpatial()
d.params.Logger.Debugw("max subscribed layer processed", "layer", maxLayerSpatial, "event", event)
} }
if onMaxSubscribedLayerChanged := d.getOnMaxLayerChanged(); onMaxSubscribedLayerChanged != nil { if onMaxSubscribedLayerChanged := d.getOnMaxLayerChanged(); onMaxSubscribedLayerChanged != nil {
d.params.Logger.Debugw("max subscribed layer changed", "maxLayerSpatial", maxLayerSpatial) d.params.Logger.Debugw("notifying max subscribed layer", "layer", maxLayerSpatial, "event", event)
onMaxSubscribedLayerChanged(d, maxLayerSpatial) onMaxSubscribedLayerChanged(d, maxLayerSpatial)
} }
} }
@@ -903,7 +906,7 @@ func (d *DownTrack) handleMute(muted bool, changed bool) {
// Note that while publisher mute is active, subscriber changes can also happen // Note that while publisher mute is active, subscriber changes can also happen
// and that could turn on/off layers on publisher side. // and that could turn on/off layers on publisher side.
// //
d.postMaxLayerNotifierEvent() d.postMaxLayerNotifierEvent("mute")
if sal := d.getStreamAllocatorListener(); sal != nil { if sal := d.getStreamAllocatorListener(); sal != nil {
sal.OnSubscriptionChanged(d) sal.OnSubscriptionChanged(d)
@@ -1015,7 +1018,7 @@ func (d *DownTrack) SetMaxSpatialLayer(spatialLayer int32) {
return return
} }
d.postMaxLayerNotifierEvent() d.postMaxLayerNotifierEvent("max-subscribed")
if sal := d.getStreamAllocatorListener(); sal != nil { if sal := d.getStreamAllocatorListener(); sal != nil {
sal.OnSubscribedLayerChanged(d, maxLayer) sal.OnSubscribedLayerChanged(d, maxLayer)
@@ -1961,7 +1964,7 @@ func (d *DownTrack) sendingPacket(hdr *rtp.Header, payloadSize int, spmd *sendPa
if spmd.tp != nil { if spmd.tp != nil {
if spmd.tp.isSwitching { if spmd.tp.isSwitching {
d.postMaxLayerNotifierEvent() d.postMaxLayerNotifierEvent("switching")
} }
if spmd.tp.isResuming { if spmd.tp.isResuming {
+1 -1
View File
@@ -456,7 +456,7 @@ func (f *Forwarder) PubMute(pubMuted bool) bool {
return false return false
} }
f.logger.Debugw("setting forwarder pub mute", "pubMuted", pubMuted) f.logger.Debugw("setting forwarder pub mute", "muted", pubMuted)
f.pubMuted = pubMuted f.pubMuted = pubMuted
// resync when pub muted so that sequence numbers do not jump on unmute // resync when pub muted so that sequence numbers do not jump on unmute