mirror of
https://github.com/aler9/gortsplib
synced 2025-10-06 07:37:07 +08:00
rtptimedec: fix timestamp decoding when there's an overflow and a negative time diff
This commit is contained in:
@@ -9,16 +9,32 @@ import (
|
||||
|
||||
func TestOverflow(t *testing.T) {
|
||||
d := New(90000)
|
||||
var pts time.Duration
|
||||
|
||||
for _, ts := range []uint32{
|
||||
4294877296,
|
||||
90001,
|
||||
3240090001,
|
||||
565122706,
|
||||
} {
|
||||
pts = d.Decode(ts)
|
||||
}
|
||||
pts := d.Decode(4294877295)
|
||||
require.Equal(t, time.Duration(0), pts)
|
||||
|
||||
require.Equal(t, 15*60*60*time.Second+2*time.Second, pts)
|
||||
pts = d.Decode(90000)
|
||||
require.Equal(t, 2*time.Second, pts)
|
||||
}
|
||||
|
||||
func TestOverflowAndBack(t *testing.T) {
|
||||
d := New(90000)
|
||||
|
||||
pts := d.Decode(4294877296)
|
||||
require.Equal(t, time.Duration(0), pts)
|
||||
|
||||
pts = d.Decode(90001)
|
||||
require.Equal(t, 2*time.Second, pts)
|
||||
|
||||
pts = d.Decode(4294877296)
|
||||
require.Equal(t, time.Duration(0), pts)
|
||||
|
||||
pts = d.Decode(4294877296 - 90000)
|
||||
require.Equal(t, -1*time.Second, pts)
|
||||
|
||||
pts = d.Decode(4294877296)
|
||||
require.Equal(t, time.Duration(0), pts)
|
||||
|
||||
pts = d.Decode(90001)
|
||||
require.Equal(t, 2*time.Second, pts)
|
||||
}
|
||||
|
Reference in New Issue
Block a user