mirror of
https://github.com/livekit/livekit.git
synced 2026-08-28 00:44:12 +00:00
rename videoFrameCacheLatestTS -> videoFrameCacheLatestETS.
This commit is contained in:
@@ -208,7 +208,7 @@ type BufferBase struct {
|
||||
videoFrameCacheHasKeyFrame bool
|
||||
videoFrameCacheKeyFrameESN uint64 // ext sequence number of the current video frame cache group's first key-frame packet
|
||||
videoFrameCacheKeyFrameETS uint64 // ext timestamp of the current video frame cache group's key frame
|
||||
videoFrameCacheLatestTS uint64 // maximum ext timestamp seen in the current video frame cache group (resets on a new key frame)
|
||||
videoFrameCacheLatestETS uint64 // maximum ext timestamp seen in the current video frame cache group (resets on a new key frame)
|
||||
|
||||
isPaused bool
|
||||
frameRateCalculator [DefaultMaxLayerSpatial + 1]FrameRateCalculator
|
||||
@@ -683,17 +683,17 @@ func (b *BufferBase) markVideoFrameCacheLocked(ep *ExtPacket) {
|
||||
// span to the key frame so a stale packet from the previous video frame cache group cannot stretch it
|
||||
b.videoFrameCacheKeyFrameESN = ep.ExtSequenceNumber
|
||||
b.videoFrameCacheKeyFrameETS = ep.ExtTimestamp
|
||||
b.videoFrameCacheLatestTS = ep.ExtTimestamp
|
||||
b.videoFrameCacheLatestETS = ep.ExtTimestamp
|
||||
b.videoFrameCacheHasKeyFrame = true
|
||||
b.logger.Debugw("video frame cache: marked key frame", "keyFrameSN", b.videoFrameCacheKeyFrameESN, "keyFrameTS", b.videoFrameCacheKeyFrameETS)
|
||||
return
|
||||
}
|
||||
// track the maximum timestamp seen in the current video frame cache group (not the last-written one) so an
|
||||
// out-of-order, older packet arriving last cannot shrink the measured span and let GetVideoFrameCache serve
|
||||
// more than videoFrameCacheMaxDuration. The head packet's timestamp is always <= videoFrameCacheLatestTS, so the
|
||||
// more than videoFrameCacheMaxDuration. The head packet's timestamp is always <= videoFrameCacheLatestETS, so the
|
||||
// duration gate in GetVideoFrameCache strictly bounds the served video frame cache group.
|
||||
if ep.ExtTimestamp > b.videoFrameCacheLatestTS {
|
||||
b.videoFrameCacheLatestTS = ep.ExtTimestamp
|
||||
if ep.ExtTimestamp > b.videoFrameCacheLatestETS {
|
||||
b.videoFrameCacheLatestETS = ep.ExtTimestamp
|
||||
}
|
||||
}
|
||||
|
||||
@@ -726,13 +726,13 @@ func (b *BufferBase) GetVideoFrameCache() ([]*ExtPacket, bool) {
|
||||
|
||||
if videoFrameCacheEnabled && b.clockRate > 0 {
|
||||
maxTicks := uint64(b.videoFrameCacheMaxDuration.Seconds() * float64(b.clockRate))
|
||||
if b.videoFrameCacheLatestTS > b.videoFrameCacheKeyFrameETS+maxTicks {
|
||||
if b.videoFrameCacheLatestETS > b.videoFrameCacheKeyFrameETS+maxTicks {
|
||||
// key-frame interval longer than the bound - too old to serve a complete replay
|
||||
b.logger.Debugw(
|
||||
"video frame cache miss: key-frame interval exceeds bound",
|
||||
"keyFrameETS", b.videoFrameCacheKeyFrameETS,
|
||||
"latestETS", b.videoFrameCacheLatestTS,
|
||||
"spanTicks", b.videoFrameCacheLatestTS-b.videoFrameCacheKeyFrameETS,
|
||||
"latestETS", b.videoFrameCacheLatestETS,
|
||||
"spanTicks", b.videoFrameCacheLatestETS-b.videoFrameCacheKeyFrameETS,
|
||||
"maxTicks", maxTicks,
|
||||
)
|
||||
return nil, false
|
||||
|
||||
@@ -142,7 +142,7 @@ func TestVideoFrameCacheKeyFrameEvicted(t *testing.T) {
|
||||
// mark a key frame at a sequence number that is not in the bucket
|
||||
addBucketPacket(t, b, 200, 1000)
|
||||
b.markVideoFrameCacheLocked(videoFrameCacheMarkPkt(100, 500, true)) // 100 was never stored / evicted
|
||||
b.videoFrameCacheLatestTS = 1000
|
||||
b.videoFrameCacheLatestETS = 1000
|
||||
|
||||
_, ok := b.GetVideoFrameCache()
|
||||
require.False(t, ok)
|
||||
@@ -157,12 +157,12 @@ func TestVideoFrameCacheDurationBound(t *testing.T) {
|
||||
b.markVideoFrameCacheLocked(videoFrameCacheMarkPkt(100, kfTS, true))
|
||||
|
||||
// within the bound
|
||||
b.videoFrameCacheLatestTS = kfTS + 90000 // +1s
|
||||
b.videoFrameCacheLatestETS = kfTS + 90000 // +1s
|
||||
_, ok := b.GetVideoFrameCache()
|
||||
require.True(t, ok)
|
||||
|
||||
// beyond the bound -> not served
|
||||
b.videoFrameCacheLatestTS = kfTS + 180001 // > 2s
|
||||
b.videoFrameCacheLatestETS = kfTS + 180001 // > 2s
|
||||
_, ok = b.GetVideoFrameCache()
|
||||
require.False(t, ok)
|
||||
}
|
||||
@@ -173,17 +173,17 @@ func TestVideoFrameCacheSpanUsesMaxTimestamp(t *testing.T) {
|
||||
// key frame at 1000, then a later packet at 1200 advances the span
|
||||
b.markVideoFrameCacheLocked(videoFrameCacheMarkPkt(100, 1000, true))
|
||||
b.markVideoFrameCacheLocked(videoFrameCacheMarkPkt(101, 1200, false))
|
||||
require.Equal(t, uint64(1200), b.videoFrameCacheLatestTS)
|
||||
require.Equal(t, uint64(1200), b.videoFrameCacheLatestETS)
|
||||
|
||||
// an out-of-order, older packet arriving last must not shrink the measured span
|
||||
b.markVideoFrameCacheLocked(videoFrameCacheMarkPkt(102, 1100, false))
|
||||
require.Equal(t, uint64(1200), b.videoFrameCacheLatestTS)
|
||||
require.Equal(t, uint64(1200), b.videoFrameCacheLatestETS)
|
||||
|
||||
// a new key frame resets the span to itself (a stale packet cannot stretch the new video frame cache group)
|
||||
b.markVideoFrameCacheLocked(videoFrameCacheMarkPkt(103, 5000, true))
|
||||
require.Equal(t, uint64(5000), b.videoFrameCacheLatestTS)
|
||||
require.Equal(t, uint64(5000), b.videoFrameCacheLatestETS)
|
||||
b.markVideoFrameCacheLocked(videoFrameCacheMarkPkt(104, 4000, false)) // stale, older than the new key frame
|
||||
require.Equal(t, uint64(5000), b.videoFrameCacheLatestTS)
|
||||
require.Equal(t, uint64(5000), b.videoFrameCacheLatestETS)
|
||||
}
|
||||
|
||||
func TestBucketGrowTarget(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user