Do not start forawarding on out-of-order packet. (#3985)
It is posible that a subscriber joins when a publisher has reconnected and has received a flood of retransmitted packets due to NACKing the gap caused by the publisher reconnecting. Starting on that spurt means the subscriber gets a burst of unpaced packets that could lead to issues with calculating render time (especially obvious in cases like egress).
This commit is contained in:
+14
-2
@@ -42,7 +42,6 @@ import (
|
||||
"github.com/livekit/livekit-server/pkg/sfu/videolayerselector/temporallayerselector"
|
||||
)
|
||||
|
||||
// Forwarder
|
||||
const (
|
||||
FlagPauseOnDowngrade = true
|
||||
FlagFilterRTX = false
|
||||
@@ -55,6 +54,11 @@ const (
|
||||
SwitchAheadThresholdSeconds = float64(0.025) // 25ms
|
||||
)
|
||||
|
||||
var (
|
||||
errSkipStartOnOutOfOrderPacket = errors.New("skip start on out-of-order packet")
|
||||
errSwitchPointTooFarBehind = errors.New("switch point too far behind")
|
||||
)
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
type VideoPauseReason int
|
||||
@@ -1693,6 +1697,10 @@ func (f *Forwarder) getRefLayerRTPTimestamp(ts uint32, refLayer, targetLayer int
|
||||
|
||||
func (f *Forwarder) processSourceSwitch(extPkt *buffer.ExtPacket, layer int32) error {
|
||||
if !f.started {
|
||||
if extPkt.IsOutOfOrder {
|
||||
return errSkipStartOnOutOfOrderPacket
|
||||
}
|
||||
|
||||
f.started = true
|
||||
f.referenceLayerSpatial = layer
|
||||
f.rtpMunger.SetLastSnTs(extPkt)
|
||||
@@ -1708,6 +1716,10 @@ func (f *Forwarder) processSourceSwitch(extPkt *buffer.ExtPacket, layer int32) e
|
||||
)
|
||||
return nil
|
||||
} else if f.referenceLayerSpatial == buffer.InvalidLayerSpatial {
|
||||
if extPkt.IsOutOfOrder {
|
||||
return errSkipStartOnOutOfOrderPacket
|
||||
}
|
||||
|
||||
f.referenceLayerSpatial = layer
|
||||
f.codecMunger.SetLast(extPkt)
|
||||
f.logger.Debugw(
|
||||
@@ -1887,7 +1899,7 @@ func (f *Forwarder) processSourceSwitch(extPkt *buffer.ExtPacket, layer int32) e
|
||||
// (like "have waited for too long for layer switch, nothing available, switch to whatever is available" kind of condition).
|
||||
logTransition("layer switch, reference too far behind", extExpectedTS, extRefTS, extLastTS, diffSeconds)
|
||||
|
||||
return errors.New("switch point too far behind")
|
||||
return errSwitchPointTooFarBehind
|
||||
}
|
||||
|
||||
// use a nominal increase to ensure that timestamp is always moving forward
|
||||
|
||||
Reference in New Issue
Block a user