mirror of
https://github.com/livekit/livekit.git
synced 2026-08-24 18:19:45 +00:00
fix framenumber test (#2942)
This commit is contained in:
@@ -41,7 +41,7 @@ func (f *FrameNumberWrapper) UpdateAndGet(new uint64, updateOffset bool) uint64
|
||||
new16 := uint16(new + f.offset)
|
||||
last16 := uint16(f.last + f.offset)
|
||||
// if new frame number wraps around and is considered as earlier by client, increase offset to make it later
|
||||
if diff := new16 - last16; diff > 0x8000 || (diff == 0x8000 && new16 <= last16) {
|
||||
if diff := new16 - last16; diff > 0x8000 || (diff == 0x8000 && new16 < last16) {
|
||||
// increase offset by 6000, nearly 10 seconds for 30fps video with 3 spatial layers
|
||||
prevOffset := f.offset
|
||||
f.offset += uint64(65535 - diff + 6000)
|
||||
|
||||
@@ -65,6 +65,12 @@ func TestFrameNumberWrapper(t *testing.T) {
|
||||
// frame out of order
|
||||
firstF = secondF
|
||||
secondF = getFrame(firstF, false)
|
||||
// it is possile that an out of order non-keyframe has been converted to in order frame number if the diff is 32768
|
||||
// that is ok because the client can't decode in such case and always need to wait for the key frame.
|
||||
// so it is just a failure of test case and increase the frame number here.
|
||||
if secondF-firstF == 0x8000 {
|
||||
secondF++
|
||||
}
|
||||
testFrameOrder(firstF, false, secondF, false, false)
|
||||
|
||||
// key frame in order
|
||||
@@ -92,5 +98,11 @@ func getFrame(base uint16, inorder bool) uint16 {
|
||||
if inorder {
|
||||
return base + uint16(rand.Intn(0x8000))
|
||||
}
|
||||
return base + uint16(rand.Intn(0x8000)) + 0x8000
|
||||
|
||||
for {
|
||||
ret := base + uint16(rand.Intn(0x8000)) + 0x8000
|
||||
if !inOrder(ret, base) {
|
||||
return ret
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user