Log roll back reason. (#2865)

There are cases of subscriber of a FF publisher not able to lock onto
layer 0 and kept rolling back till it switched to a higher layer and
then it could switch to layer 0. Must have been due to not having a
sender report. Can't think of a reason why that would be missing.
Logging more to debug this further.

Also, using a wrapping logger because of this bug: https://github.com/uber-go/zap/issues/836
Tried using `json:"" yaml:""` tag for `refInfos` field and all fields
inside `refInfo` struct. But, they were still logging nils. So, using
the wrapper logger.
This commit is contained in:
Raja Subramanian
2024-07-15 23:54:45 +05:30
committed by GitHub
parent affcd1ffdb
commit e815c99eac
+25 -1
View File
@@ -221,6 +221,29 @@ type refInfo struct {
isTSOffsetValid bool
}
func (r refInfo) MarshalLogObject(e zapcore.ObjectEncoder) error {
e.AddObject("senderReport", r.senderReport)
e.AddUint64("tsOffset", r.tsOffset)
e.AddBool("isTSOffsetValid", r.isTSOffsetValid)
return nil
}
// -------------------------------------------------------------------
type wrappedRefInfoLogger struct {
*Forwarder
}
func (w wrappedRefInfoLogger) MarshalLogObject(e zapcore.ObjectEncoder) error {
for i, refInfo := range w.Forwarder.refInfos {
e.AddObject(fmt.Sprintf("%d", i), refInfo)
}
return nil
}
// -------------------------------------------------------------------
type Forwarder struct {
lock sync.RWMutex
codec webrtc.RTPCodecCapability
@@ -1848,11 +1871,12 @@ func (f *Forwarder) processSourceSwitch(extPkt *buffer.ExtPacket, layer int32) e
func (f *Forwarder) getTranslationParamsCommon(extPkt *buffer.ExtPacket, layer int32, tp *TranslationParams) error {
if f.lastSSRC != extPkt.Packet.SSRC {
if err := f.processSourceSwitch(extPkt, layer); err != nil {
f.logger.Debugw("could not switch feed", "error", err, "refInfos", wrappedRefInfoLogger{f})
tp.shouldDrop = true
f.vls.Rollback()
return nil
}
f.logger.Debugw("switching feed", "from", f.lastSSRC, "to", extPkt.Packet.SSRC)
f.logger.Debugw("switching feed", "from", f.lastSSRC, "to", extPkt.Packet.SSRC, "refInfos", wrappedRefInfoLogger{f})
f.lastSSRC = extPkt.Packet.SSRC
f.lastSwitchExtIncomingTS = extPkt.ExtTimestamp
}