Restrict resume behind check to publisher mute only. (#1951)
A publisher mute is when the reference can fall behind because of replaceTrack(nil). On a subscriber mute, should not jump ahead to expected because publisher could still be lagging and behind. Also consolidate logging.
This commit is contained in:
+25
-9
@@ -188,8 +188,9 @@ type Forwarder struct {
|
|||||||
getReferenceLayerRTPTimestamp func(ts uint32, layer int32, referenceLayer int32) (uint32, error)
|
getReferenceLayerRTPTimestamp func(ts uint32, layer int32, referenceLayer int32) (uint32, error)
|
||||||
getExpectedRTPTimestamp func(at time.Time) (uint64, error)
|
getExpectedRTPTimestamp func(at time.Time) (uint64, error)
|
||||||
|
|
||||||
muted bool
|
muted bool
|
||||||
pubMuted bool
|
pubMuted bool
|
||||||
|
resumeBehindThreshold float64
|
||||||
|
|
||||||
started bool
|
started bool
|
||||||
preStartTime time.Time
|
preStartTime time.Time
|
||||||
@@ -1360,6 +1361,9 @@ func (f *Forwarder) Resync() {
|
|||||||
func (f *Forwarder) resyncLocked() {
|
func (f *Forwarder) resyncLocked() {
|
||||||
f.vls.SetCurrent(buffer.InvalidLayer)
|
f.vls.SetCurrent(buffer.InvalidLayer)
|
||||||
f.lastSSRC = 0
|
f.lastSSRC = 0
|
||||||
|
if f.pubMuted {
|
||||||
|
f.resumeBehindThreshold = ResumeBehindThresholdSeconds
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Forwarder) CheckSync() (locked bool, layer int32) {
|
func (f *Forwarder) CheckSync() (locked bool, layer int32) {
|
||||||
@@ -1435,6 +1439,17 @@ func (f *Forwarder) processSourceSwitch(extPkt *buffer.ExtPacket, layer int32) e
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logTransition := func(message string, expectedTS, refTS, lastTS uint32, diffSeconds float64) {
|
||||||
|
f.logger.Infow(
|
||||||
|
message,
|
||||||
|
"layer", layer,
|
||||||
|
"expectedTS", expectedTS,
|
||||||
|
"refTS", refTS,
|
||||||
|
"lastTS", lastTS,
|
||||||
|
"diffSeconds", math.Abs(diffSeconds),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if f.referenceLayerSpatial == buffer.InvalidLayerSpatial {
|
if f.referenceLayerSpatial == buffer.InvalidLayerSpatial {
|
||||||
// on a resume, reference layer may not be set, so only set when it is invalid
|
// on a resume, reference layer may not be set, so only set when it is invalid
|
||||||
f.referenceLayerSpatial = layer
|
f.referenceLayerSpatial = layer
|
||||||
@@ -1517,18 +1532,19 @@ func (f *Forwarder) processSourceSwitch(extPkt *buffer.ExtPacket, layer int32) e
|
|||||||
// for refTS > expectedTS
|
// for refTS > expectedTS
|
||||||
diffSeconds := float64(int32(expectedTS-refTS)) / float64(f.codec.ClockRate)
|
diffSeconds := float64(int32(expectedTS-refTS)) / float64(f.codec.ClockRate)
|
||||||
if diffSeconds >= 0.0 {
|
if diffSeconds >= 0.0 {
|
||||||
if diffSeconds > ResumeBehindThresholdSeconds {
|
if f.resumeBehindThreshold > 0 && diffSeconds > f.resumeBehindThreshold {
|
||||||
f.logger.Infow("resume, reference too far behind", "expectedTS", expectedTS, "refTS", refTS, "diffSeconds", diffSeconds)
|
logTransition("resume, reference too far behind", expectedTS, refTS, lastTS, diffSeconds)
|
||||||
nextTS = expectedTS
|
nextTS = expectedTS
|
||||||
} else {
|
} else {
|
||||||
nextTS = refTS
|
nextTS = refTS
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if math.Abs(diffSeconds) > SwitchAheadThresholdSeconds {
|
if math.Abs(diffSeconds) > SwitchAheadThresholdSeconds {
|
||||||
f.logger.Infow("resume, reference too far ahead", "expectedTS", expectedTS, "refTS", refTS, "diffSeconds", math.Abs(diffSeconds))
|
logTransition("resume, reference too far ahead", expectedTS, refTS, lastTS, diffSeconds)
|
||||||
}
|
}
|
||||||
nextTS = refTS
|
nextTS = refTS
|
||||||
}
|
}
|
||||||
|
f.resumeBehindThreshold = 0.0
|
||||||
} else {
|
} else {
|
||||||
// switching between layers, check if refTS is too far behind the last sent
|
// switching between layers, check if refTS is too far behind the last sent
|
||||||
diffSeconds := float64(int32(refTS-lastTS)) / float64(f.codec.ClockRate)
|
diffSeconds := float64(int32(refTS-lastTS)) / float64(f.codec.ClockRate)
|
||||||
@@ -1537,16 +1553,16 @@ func (f *Forwarder) processSourceSwitch(extPkt *buffer.ExtPacket, layer int32) e
|
|||||||
// this could be due to pacer trickling out this layer. Error out and wait for a more opportune time.
|
// this could be due to pacer trickling out this layer. Error out and wait for a more opportune time.
|
||||||
// AVSYNC-TODO: Consider some forcing function to do the switch
|
// AVSYNC-TODO: Consider some forcing function to do the switch
|
||||||
// (like "have waited for too long for layer switch, nothing available, switch to whatever is available" kind of condition).
|
// (like "have waited for too long for layer switch, nothing available, switch to whatever is available" kind of condition).
|
||||||
f.logger.Infow("layer switch, reference too far behind", "expectedTS", expectedTS, "refTS", refTS, "lastTS", lastTS, "diffSeconds", math.Abs(diffSeconds))
|
logTransition("layer switch, reference too far behind", expectedTS, refTS, lastTS, diffSeconds)
|
||||||
return errors.New("switch point too far behind")
|
return errors.New("switch point too far behind")
|
||||||
}
|
}
|
||||||
// use a nominal increase to ensure that timestamp is always moving forward
|
// use a nominal increase to ensure that timestamp is always moving forward
|
||||||
f.logger.Infow("layer switch, reference is slghtly behind", "expectedTS", expectedTS, "refTS", refTS, "lastTS", lastTS, "diffSeconds", math.Abs(diffSeconds))
|
logTransition("layer switch, reference is slightly behind", expectedTS, refTS, lastTS, diffSeconds)
|
||||||
nextTS = lastTS + 1
|
nextTS = lastTS + 1
|
||||||
} else {
|
} else {
|
||||||
diffSeconds = float64(int32(expectedTS-refTS)) / float64(f.codec.ClockRate)
|
diffSeconds = float64(int32(expectedTS-refTS)) / float64(f.codec.ClockRate)
|
||||||
if diffSeconds < 0.0 && math.Abs(diffSeconds) > SwitchAheadThresholdSeconds {
|
if diffSeconds < 0.0 && math.Abs(diffSeconds) > SwitchAheadThresholdSeconds {
|
||||||
f.logger.Infow("layer switch, reference too far ahead", "expectedTS", expectedTS, "refTS", refTS, "diffSeconds", math.Abs(diffSeconds))
|
logTransition("layer switch, reference too far ahead", expectedTS, refTS, lastTS, diffSeconds)
|
||||||
nextTS = expectedTS
|
nextTS = expectedTS
|
||||||
} else {
|
} else {
|
||||||
nextTS = refTS
|
nextTS = refTS
|
||||||
@@ -1585,7 +1601,7 @@ func (f *Forwarder) getTranslationParamsCommon(extPkt *buffer.ExtPacket, layer i
|
|||||||
if f.lastSSRC != extPkt.Packet.SSRC {
|
if f.lastSSRC != extPkt.Packet.SSRC {
|
||||||
if err := f.processSourceSwitch(extPkt, layer); err != nil {
|
if err := f.processSourceSwitch(extPkt, layer); err != nil {
|
||||||
tp.shouldDrop = true
|
tp.shouldDrop = true
|
||||||
return tp, err
|
return tp, 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)
|
||||||
f.lastSSRC = extPkt.Packet.SSRC
|
f.lastSSRC = extPkt.Packet.SSRC
|
||||||
|
|||||||
Reference in New Issue
Block a user