Key frames (#522)

* Key frames

- Keep track of key frame stats
- Split out PLI from down track used for purpose of layer locking.
This will give us a good picture of down stream issues forcing a PLI.
- Use key frame requester whenever there is a layer lock required.
Not just the first key frame. With the synchronous thing, the counter
was just ridiculously high like 150 or something because of all
the initial padding packets. Also, use RTT in key frame requester.

* send first PLI before waiting

* Turn off key frame requester when disabled

* simplify
This commit is contained in:
Raja Subramanian
2022-03-16 19:55:12 +05:30
committed by GitHub
parent 82192f524e
commit 33f9726b79
8 changed files with 127 additions and 36 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ require (
github.com/google/wire v0.5.0 github.com/google/wire v0.5.0
github.com/gorilla/websocket v1.4.2 github.com/gorilla/websocket v1.4.2
github.com/hashicorp/golang-lru v0.5.4 github.com/hashicorp/golang-lru v0.5.4
github.com/livekit/protocol v0.11.14-0.20220314072422-5cea5d444f36 github.com/livekit/protocol v0.11.14-0.20220316120321-6f2a49e44914
github.com/magefile/mage v1.11.0 github.com/magefile/mage v1.11.0
github.com/maxbrunsfeld/counterfeiter/v6 v6.3.0 github.com/maxbrunsfeld/counterfeiter/v6 v6.3.0
github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/go-homedir v1.1.0
+2 -2
View File
@@ -134,8 +134,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lithammer/shortuuid/v3 v3.0.6 h1:pr15YQyvhiSX/qPxncFtqk+v4xLEpOZObbsY/mKrcvA= github.com/lithammer/shortuuid/v3 v3.0.6 h1:pr15YQyvhiSX/qPxncFtqk+v4xLEpOZObbsY/mKrcvA=
github.com/lithammer/shortuuid/v3 v3.0.6/go.mod h1:vMk8ke37EmiewwolSO1NLW8vP4ZaKlRuDIi8tWWmAts= github.com/lithammer/shortuuid/v3 v3.0.6/go.mod h1:vMk8ke37EmiewwolSO1NLW8vP4ZaKlRuDIi8tWWmAts=
github.com/livekit/protocol v0.11.14-0.20220314072422-5cea5d444f36 h1:D3lWDCvyMuHNVgP4cjscDdK8DBQQykIJFHnx3ragxhk= github.com/livekit/protocol v0.11.14-0.20220316120321-6f2a49e44914 h1:zD7PFc1Qjrr+bzAMKwmA/sjBpaSDWh0mboKRB4XJLBA=
github.com/livekit/protocol v0.11.14-0.20220314072422-5cea5d444f36/go.mod h1:3pHsWUtQmWaH8mG0cXrQWpbf3Vo+kj0U+In77CEXu90= github.com/livekit/protocol v0.11.14-0.20220316120321-6f2a49e44914/go.mod h1:3pHsWUtQmWaH8mG0cXrQWpbf3Vo+kj0U+In77CEXu90=
github.com/magefile/mage v1.11.0 h1:C/55Ywp9BpgVVclD3lRnSYCwXTYxmSppIgLeDYlNuls= github.com/magefile/mage v1.11.0 h1:C/55Ywp9BpgVVclD3lRnSYCwXTYxmSppIgLeDYlNuls=
github.com/magefile/mage v1.11.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= github.com/magefile/mage v1.11.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
+3
View File
@@ -460,6 +460,9 @@ func (b *Buffer) getExtPacket(rawPacket []byte, rtpPacket *rtp.Packet, arrivalTi
} }
if ep.KeyFrame { if ep.KeyFrame {
b.logger.Debugw("key frame received") b.logger.Debugw("key frame received")
if b.rtpStats != nil {
b.rtpStats.UpdateKeyFrame(1)
}
} }
return ep, temporalLayer return ep, temporalLayer
+59 -4
View File
@@ -98,9 +98,15 @@ type RTPStats struct {
plis uint32 plis uint32
lastPli time.Time lastPli time.Time
layerLockPlis uint32
lastLayerLockPli time.Time
firs uint32 firs uint32
lastFir time.Time lastFir time.Time
keyFrames uint32
lastKeyFrame time.Time
rtt uint32 rtt uint32
maxRtt uint32 maxRtt uint32
@@ -396,6 +402,18 @@ func (r *RTPStats) TimeSinceLastPli() int64 {
return time.Now().UnixNano() - r.lastPli.UnixNano() return time.Now().UnixNano() - r.lastPli.UnixNano()
} }
func (r *RTPStats) UpdateLayerLockPliAndTime(pliCount uint32) {
r.lock.Lock()
defer r.lock.Unlock()
if !r.endTime.IsZero() {
return
}
r.layerLockPlis += pliCount
r.lastLayerLockPli = time.Now()
}
func (r *RTPStats) UpdateFir(firCount uint32) { func (r *RTPStats) UpdateFir(firCount uint32) {
r.lock.Lock() r.lock.Lock()
defer r.lock.Unlock() defer r.lock.Unlock()
@@ -418,6 +436,18 @@ func (r *RTPStats) UpdateFirTime() {
r.lastFir = time.Now() r.lastFir = time.Now()
} }
func (r *RTPStats) UpdateKeyFrame(kfCount uint32) {
r.lock.Lock()
defer r.lock.Unlock()
if !r.endTime.IsZero() {
return
}
r.keyFrames += kfCount
r.lastKeyFrame = time.Now()
}
func (r *RTPStats) UpdateRtt(rtt uint32) { func (r *RTPStats) UpdateRtt(rtt uint32) {
r.lock.Lock() r.lock.Lock()
defer r.lock.Unlock() defer r.lock.Unlock()
@@ -427,8 +457,8 @@ func (r *RTPStats) UpdateRtt(rtt uint32) {
} }
r.rtt = rtt r.rtt = rtt
if r.rtt > r.maxRtt { if rtt > r.maxRtt {
r.maxRtt = r.rtt r.maxRtt = rtt
} }
for _, s := range r.snapshots { for _, s := range r.snapshots {
@@ -586,7 +616,7 @@ func (r *RTPStats) ToString() string {
str += fmt.Sprintf(", p: %d|%.2f/s", p.Packets, p.PacketRate) str += fmt.Sprintf(", p: %d|%.2f/s", p.Packets, p.PacketRate)
str += fmt.Sprintf(", l: %d|%.1f/s|%.2f%%", p.PacketsLost, p.PacketLossRate, p.PacketLossPercentage) str += fmt.Sprintf(", l: %d|%.1f/s|%.2f%%", p.PacketsLost, p.PacketLossRate, p.PacketLossPercentage)
str += fmt.Sprintf(", b: %d|%.1fbps", p.Bytes, p.Bitrate) str += fmt.Sprintf(", b: %d|%.1fbps", p.Bytes, p.Bitrate)
str += fmt.Sprintf(", f: %d|%.1f/s", p.Frames, p.FrameRate) str += fmt.Sprintf(", f: %d|%.1f/s / %d|%+v", p.Frames, p.FrameRate, p.KeyFrames, p.LastKeyFrame.AsTime().Format(time.UnixDate))
str += fmt.Sprintf(", d: %d|%.2f/s", p.PacketsDuplicate, p.PacketDuplicateRate) str += fmt.Sprintf(", d: %d|%.2f/s", p.PacketsDuplicate, p.PacketDuplicateRate)
str += fmt.Sprintf(", bd: %d|%.1fbps", p.BytesDuplicate, p.BitrateDuplicate) str += fmt.Sprintf(", bd: %d|%.1fbps", p.BytesDuplicate, p.BitrateDuplicate)
@@ -621,7 +651,10 @@ func (r *RTPStats) ToString() string {
str += fmt.Sprintf("%d|%d", p.Nacks, p.NackMisses) str += fmt.Sprintf("%d|%d", p.Nacks, p.NackMisses)
str += ", pli:" str += ", pli:"
str += fmt.Sprintf("%d|%+v", p.Plis, p.LastPli.AsTime().Format(time.UnixDate)) str += fmt.Sprintf("%d|%+v / %d|%+v",
p.Plis, p.LastPli.AsTime().Format(time.UnixDate),
p.LayerLockPlis, p.LastLayerLockPli.AsTime().Format(time.UnixDate),
)
str += ", fir:" str += ", fir:"
str += fmt.Sprintf("%d|%+v", p.Firs, p.LastFir.AsTime().Format(time.UnixDate)) str += fmt.Sprintf("%d|%+v", p.Firs, p.LastFir.AsTime().Format(time.UnixDate))
@@ -704,12 +737,16 @@ func (r *RTPStats) ToProto() *livekit.RTPStats {
PacketsOutOfOrder: r.packetsOutOfOrder, PacketsOutOfOrder: r.packetsOutOfOrder,
Frames: r.frames, Frames: r.frames,
FrameRate: frameRate, FrameRate: frameRate,
KeyFrames: r.keyFrames,
LastKeyFrame: timestamppb.New(r.lastKeyFrame),
JitterCurrent: jitterTime, JitterCurrent: jitterTime,
JitterMax: maxJitterTime, JitterMax: maxJitterTime,
Nacks: r.nacks, Nacks: r.nacks,
NackMisses: r.nackMisses, NackMisses: r.nackMisses,
Plis: r.plis, Plis: r.plis,
LastPli: timestamppb.New(r.lastPli), LastPli: timestamppb.New(r.lastPli),
LayerLockPlis: r.layerLockPlis,
LastLayerLockPli: timestamppb.New(r.lastLayerLockPli),
Firs: r.firs, Firs: r.firs,
LastFir: timestamppb.New(r.lastFir), LastFir: timestamppb.New(r.lastFir),
RttCurrent: r.rtt, RttCurrent: r.rtt,
@@ -873,6 +910,8 @@ func AggregateRTPStats(statses []*livekit.RTPStats) *livekit.RTPStats {
bytesPadding := uint64(0) bytesPadding := uint64(0)
packetsOutOfOrder := uint32(0) packetsOutOfOrder := uint32(0)
frames := uint32(0) frames := uint32(0)
keyFrames := uint32(0)
lastKeyFrame := time.Time{}
jitter := float64(0.0) jitter := float64(0.0)
maxJitter := float64(0) maxJitter := float64(0)
gapHistogram := make(map[int32]uint32, GapHistogramNumBins) gapHistogram := make(map[int32]uint32, GapHistogramNumBins)
@@ -880,6 +919,8 @@ func AggregateRTPStats(statses []*livekit.RTPStats) *livekit.RTPStats {
nackMisses := uint32(0) nackMisses := uint32(0)
plis := uint32(0) plis := uint32(0)
lastPli := time.Time{} lastPli := time.Time{}
layerLockPlis := uint32(0)
lastLayerLockPli := time.Time{}
firs := uint32(0) firs := uint32(0)
lastFir := time.Time{} lastFir := time.Time{}
rtt := uint32(0) rtt := uint32(0)
@@ -909,6 +950,11 @@ func AggregateRTPStats(statses []*livekit.RTPStats) *livekit.RTPStats {
frames += stats.Frames frames += stats.Frames
keyFrames += stats.KeyFrames
if lastKeyFrame.IsZero() || lastKeyFrame.Before(stats.LastKeyFrame.AsTime()) {
lastKeyFrame = stats.LastKeyFrame.AsTime()
}
jitter += stats.JitterCurrent jitter += stats.JitterCurrent
if stats.JitterMax > maxJitter { if stats.JitterMax > maxJitter {
maxJitter = stats.JitterMax maxJitter = stats.JitterMax
@@ -926,6 +972,11 @@ func AggregateRTPStats(statses []*livekit.RTPStats) *livekit.RTPStats {
lastPli = stats.LastPli.AsTime() lastPli = stats.LastPli.AsTime()
} }
layerLockPlis += stats.LayerLockPlis
if lastLayerLockPli.IsZero() || lastLayerLockPli.Before(stats.LastLayerLockPli.AsTime()) {
lastLayerLockPli = stats.LastLayerLockPli.AsTime()
}
firs += stats.Firs firs += stats.Firs
if lastFir.IsZero() || lastPli.Before(stats.LastFir.AsTime()) { if lastFir.IsZero() || lastPli.Before(stats.LastFir.AsTime()) {
lastFir = stats.LastFir.AsTime() lastFir = stats.LastFir.AsTime()
@@ -977,6 +1028,8 @@ func AggregateRTPStats(statses []*livekit.RTPStats) *livekit.RTPStats {
PacketsOutOfOrder: packetsOutOfOrder, PacketsOutOfOrder: packetsOutOfOrder,
Frames: frames, Frames: frames,
FrameRate: frameRate, FrameRate: frameRate,
KeyFrames: keyFrames,
LastKeyFrame: timestamppb.New(lastKeyFrame),
JitterCurrent: jitter / float64(len(statses)), JitterCurrent: jitter / float64(len(statses)),
JitterMax: maxJitter, JitterMax: maxJitter,
GapHistogram: gapHistogram, GapHistogram: gapHistogram,
@@ -984,6 +1037,8 @@ func AggregateRTPStats(statses []*livekit.RTPStats) *livekit.RTPStats {
NackMisses: nackMisses, NackMisses: nackMisses,
Plis: plis, Plis: plis,
LastPli: timestamppb.New(lastPli), LastPli: timestamppb.New(lastPli),
LayerLockPlis: layerLockPlis,
LastLayerLockPli: timestamppb.New(lastLayerLockPli),
Firs: firs, Firs: firs,
LastFir: timestamppb.New(lastFir), LastFir: timestamppb.New(lastFir),
RttCurrent: rtt / uint32(len(statses)), RttCurrent: rtt / uint32(len(statses)),
+48 -23
View File
@@ -39,9 +39,10 @@ const (
RTPPaddingEstimatedHeaderSize = 20 RTPPaddingEstimatedHeaderSize = 20
RTPBlankFramesMax = 6 RTPBlankFramesMax = 6
firstKeyFramePLIInterval = 500 * time.Millisecond
FlagStopRTXOnPLI = true FlagStopRTXOnPLI = true
keyFrameIntervalMin = 200
keyFrameIntervalMax = 1000
) )
var ( var (
@@ -103,6 +104,8 @@ type DownTrack struct {
statsLock sync.RWMutex statsLock sync.RWMutex
totalRepeatedNACKs uint32 totalRepeatedNACKs uint32
keyFrameRequestGeneration atomic.Uint32
connectionStats *connectionquality.ConnectionStats connectionStats *connectionquality.ConnectionStats
connectionQualitySnapshotId uint32 connectionQualitySnapshotId uint32
@@ -140,8 +143,6 @@ type DownTrack struct {
// update rtt // update rtt
onRttUpdate func(dt *DownTrack, rtt uint32) onRttUpdate func(dt *DownTrack, rtt uint32)
closed chan struct{}
} }
// NewDownTrack returns a DownTrack. // NewDownTrack returns a DownTrack.
@@ -175,7 +176,6 @@ func NewDownTrack(
kind: kind, kind: kind,
forwarder: NewForwarder(c, kind, logger), forwarder: NewForwarder(c, kind, logger),
callbacksQueue: utils.NewOpsQueue(logger), callbacksQueue: utils.NewOpsQueue(logger),
closed: make(chan struct{}),
} }
d.connectionStats = connectionquality.NewConnectionStats(connectionquality.ConnectionStatsParams{ d.connectionStats = connectionquality.NewConnectionStats(connectionquality.ConnectionStatsParams{
@@ -235,8 +235,6 @@ func (d *DownTrack) Bind(t webrtc.TrackLocalContext) (webrtc.RTPCodecParameters,
} }
d.bound.Store(true) d.bound.Store(true)
go d.requestFirstKeyframe()
d.connectionStats.Start() d.connectionStats.Start()
return codec, nil return codec, nil
@@ -293,17 +291,38 @@ func (d *DownTrack) SetTransceiver(transceiver *webrtc.RTPTransceiver) {
d.transceiver = transceiver d.transceiver = transceiver
} }
func (d *DownTrack) requestFirstKeyframe() { func (d *DownTrack) maybeStartKeyFrameRequester() {
ticker := time.NewTicker(firstKeyFramePLIInterval) //
for !d.forwarder.ReceivedFirstKeyFrame() { // Always move to next generation to abandon any running key frame requester
select { // This ensures that it is stopped if forwarding is disabled due to mute
case <-d.closed: // or paused due to bandwidth constraints. A new key frame requester is
return // started if a layer lock is required.
//
gen := d.keyFrameRequestGeneration.Inc()
case <-ticker.C: locked, layer := d.forwarder.CheckSync()
if l := d.forwarder.TargetLayers(); l != InvalidLayers { if !locked {
d.receiver.SendPLI(l.spatial) go d.keyFrameRequester(gen, layer)
} }
}
func (d *DownTrack) keyFrameRequester(generation uint32, layer int32) {
interval := 2 * d.rtpStats.GetRtt()
if interval < keyFrameIntervalMin {
interval = keyFrameIntervalMin
}
if interval > keyFrameIntervalMax {
interval = keyFrameIntervalMax
}
ticker := time.NewTicker(time.Duration(interval) * time.Millisecond)
for {
d.logger.Debugw("sending PLI for layer lock", "generation", generation, "layer", layer)
d.receiver.SendPLI(layer)
d.rtpStats.UpdateLayerLockPliAndTime(1)
<-ticker.C
if generation != d.keyFrameRequestGeneration.Load() {
return
} }
} }
} }
@@ -323,11 +342,6 @@ func (d *DownTrack) WriteRTP(extPkt *buffer.ExtPacket, layer int32) error {
} }
tp, err := d.forwarder.GetTranslationParams(extPkt, layer) tp, err := d.forwarder.GetTranslationParams(extPkt, layer)
if tp.shouldSendPLI {
d.receiver.SendPLI(layer)
d.rtpStats.UpdatePli(1)
d.rtpStats.UpdatePliTime()
}
if tp.shouldDrop { if tp.shouldDrop {
if tp.isDroppingRelevant { if tp.isDroppingRelevant {
d.pktsDropped.Inc() d.pktsDropped.Inc()
@@ -379,6 +393,13 @@ func (d *DownTrack) WriteRTP(extPkt *buffer.ExtPacket, layer int32) error {
if extPkt.KeyFrame { if extPkt.KeyFrame {
d.isNACKThrottled.Store(false) d.isNACKThrottled.Store(false)
d.rtpStats.UpdateKeyFrame(1)
locked, _ := d.forwarder.CheckSync()
if locked {
// move generator to stop key frame requester
d.keyFrameRequestGeneration.Inc()
}
} }
d.rtpStats.Update(hdr, len(payload), 0, time.Now().UnixNano()) d.rtpStats.Update(hdr, len(payload), 0, time.Now().UnixNano())
@@ -557,7 +578,7 @@ func (d *DownTrack) CloseWithFlush(flush bool) {
} }
d.callbacksQueue.Stop() d.callbacksQueue.Stop()
close(d.closed) d.keyFrameRequestGeneration.Inc()
}) })
} }
@@ -689,6 +710,7 @@ func (d *DownTrack) DistanceToDesired() int32 {
func (d *DownTrack) Allocate(availableChannelCapacity int64, allowPause bool) VideoAllocation { func (d *DownTrack) Allocate(availableChannelCapacity int64, allowPause bool) VideoAllocation {
allocation := d.forwarder.Allocate(availableChannelCapacity, allowPause, d.receiver.GetBitrateTemporalCumulative()) allocation := d.forwarder.Allocate(availableChannelCapacity, allowPause, d.receiver.GetBitrateTemporalCumulative())
d.logger.Debugw("stream: allocation", "channel", availableChannelCapacity, "allocation", allocation) d.logger.Debugw("stream: allocation", "channel", availableChannelCapacity, "allocation", allocation)
d.maybeStartKeyFrameRequester()
return allocation return allocation
} }
@@ -715,6 +737,7 @@ func (d *DownTrack) ProvisionalAllocateGetBestWeightedTransition() VideoTransiti
func (d *DownTrack) ProvisionalAllocateCommit() VideoAllocation { func (d *DownTrack) ProvisionalAllocateCommit() VideoAllocation {
allocation := d.forwarder.ProvisionalAllocateCommit() allocation := d.forwarder.ProvisionalAllocateCommit()
d.logger.Debugw("stream: allocation commit", "allocation", allocation) d.logger.Debugw("stream: allocation commit", "allocation", allocation)
d.maybeStartKeyFrameRequester()
return allocation return allocation
} }
@@ -725,6 +748,7 @@ func (d *DownTrack) FinalizeAllocate() VideoAllocation {
func (d *DownTrack) AllocateNextHigher(availableChannelCapacity int64) (VideoAllocation, bool) { func (d *DownTrack) AllocateNextHigher(availableChannelCapacity int64) (VideoAllocation, bool) {
allocation, available := d.forwarder.AllocateNextHigher(availableChannelCapacity, d.receiver.GetBitrateTemporalCumulative()) allocation, available := d.forwarder.AllocateNextHigher(availableChannelCapacity, d.receiver.GetBitrateTemporalCumulative())
d.logger.Debugw("stream: allocation next higher layer", "allocation", allocation, "available", available) d.logger.Debugw("stream: allocation next higher layer", "allocation", allocation, "available", available)
d.maybeStartKeyFrameRequester()
return allocation, available return allocation, available
} }
@@ -737,6 +761,7 @@ func (d *DownTrack) GetNextHigherTransition() (VideoTransition, bool) {
func (d *DownTrack) Pause() VideoAllocation { func (d *DownTrack) Pause() VideoAllocation {
allocation := d.forwarder.Pause(d.receiver.GetBitrateTemporalCumulative()) allocation := d.forwarder.Pause(d.receiver.GetBitrateTemporalCumulative())
d.logger.Debugw("stream: pause", "allocation", allocation) d.logger.Debugw("stream: pause", "allocation", allocation)
d.maybeStartKeyFrameRequester()
return allocation return allocation
} }
+10 -4
View File
@@ -121,7 +121,6 @@ const (
type TranslationParams struct { type TranslationParams struct {
shouldDrop bool shouldDrop bool
isDroppingRelevant bool isDroppingRelevant bool
shouldSendPLI bool
isSwitchingToMaxLayer bool isSwitchingToMaxLayer bool
rtp *TranslationParamsRTP rtp *TranslationParamsRTP
vp8 *TranslationParamsVP8 vp8 *TranslationParamsVP8
@@ -1144,6 +1143,16 @@ func (f *Forwarder) resyncLocked() {
f.lastSSRC = 0 f.lastSSRC = 0
} }
func (f *Forwarder) CheckSync() (locked bool, layer int32) {
f.lock.RLock()
defer f.lock.RUnlock()
layer = f.targetLayers.spatial
locked = f.targetLayers.spatial == f.currentLayers.spatial
return
}
func (f *Forwarder) FilterRTX(nacks []uint16) (filtered []uint16, disallowedLayers [DefaultMaxLayerSpatial + 1]bool) { func (f *Forwarder) FilterRTX(nacks []uint16) (filtered []uint16, disallowedLayers [DefaultMaxLayerSpatial + 1]bool) {
if !FlagFilterRTX { if !FlagFilterRTX {
filtered = nacks filtered = nacks
@@ -1247,7 +1256,6 @@ func (f *Forwarder) getTranslationParamsVideo(extPkt *buffer.ExtPacket, layer in
return tp, nil return tp, nil
} }
tp.shouldSendPLI = false
if f.targetLayers.spatial != f.currentLayers.spatial { if f.targetLayers.spatial != f.currentLayers.spatial {
if f.targetLayers.spatial == layer { if f.targetLayers.spatial == layer {
if extPkt.KeyFrame { if extPkt.KeyFrame {
@@ -1258,8 +1266,6 @@ func (f *Forwarder) getTranslationParamsVideo(extPkt *buffer.ExtPacket, layer in
tp.isSwitchingToMaxLayer = true tp.isSwitchingToMaxLayer = true
} }
f.receivedFirstKeyFrame.Store(true) f.receivedFirstKeyFrame.Store(true)
} else {
tp.shouldSendPLI = true
} }
} }
} }
+1 -2
View File
@@ -1167,8 +1167,7 @@ func TestForwarderGetTranslationParamsVideo(t *testing.T) {
temporal: 1, temporal: 1,
} }
expectedTP = TranslationParams{ expectedTP = TranslationParams{
shouldDrop: true, shouldDrop: true,
shouldSendPLI: true,
} }
actualTP, err = f.GetTranslationParams(extPkt, 0) actualTP, err = f.GetTranslationParams(extPkt, 0)
require.NoError(t, err) require.NoError(t, err)
+3
View File
@@ -48,6 +48,9 @@ func getRttMs(report *rtcp.ReceptionReport) uint32 {
// middle 32-bits of current NTP time // middle 32-bits of current NTP time
now := uint32(buffer.ToNtpTime(time.Now()) >> 16) now := uint32(buffer.ToNtpTime(time.Now()) >> 16)
if now < (report.LastSenderReport + report.Delay) {
return 0
}
ntpDiff := now - report.LastSenderReport - report.Delay ntpDiff := now - report.LastSenderReport - report.Delay
return uint32(math.Ceil(float64(ntpDiff) * 1000.0 / 65536.0)) return uint32(math.Ceil(float64(ntpDiff) * 1000.0 / 65536.0))
} }