mediamtx/internal/hls/mpegts/timedecoder_test.go
Alessandro Ros e5ab731d14
Improve HLS client (#1179)
* hls source: support fMP4s video streams

* hls source: start reading live streams from (end of playlist - starting point)

* hls client: wait processing of current fMP4 segment before downloading another one

* hls client: support fmp4 trun boxes with default sample duration, flags and size

* hls client: merge fmp4 init file reader and writer

* hls client: merge fmp4 part reader and writer

* hls client: improve precision of go <-> mp4 time conversion

* hls client: fix esds generation in go-mp4

* hls client: support audio in separate playlist

* hls client: support an arbitrary number of tracks in fmp4 init files

* hls client: support EXT-X-BYTERANGE

* hls client: support fmp4 segments with multiple parts at once

* hls client: support an arbitrary number of mpeg-ts tracks

* hls client: synchronize tracks around a primary track

* update go-mp4

* hls: synchronize track reproduction around a leading one

* hls client: reset stream if playback is too late

* hls client: add limit on DTS-RTC difference

* hls client: support again streams that don't provide codecs in master playlist
2022-10-23 14:04:33 +02:00

79 lines
1.6 KiB
Go

package mpegts
import (
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestTimeDecoderNegativeDiff(t *testing.T) {
d := NewTimeDecoder()
i := int64(0)
pts := d.Decode(i)
require.Equal(t, time.Duration(0), pts)
i += 90000 * 2
pts = d.Decode(i)
require.Equal(t, 2*time.Second, pts)
i -= 90000 * 1
pts = d.Decode(i)
require.Equal(t, 1*time.Second, pts)
i += 90000 * 2
pts = d.Decode(i)
require.Equal(t, 3*time.Second, pts)
}
func TestTimeDecoderOverflow(t *testing.T) {
d := NewTimeDecoder()
i := int64(0x1FFFFFFFF - 20)
secs := time.Duration(0)
pts := d.Decode(i)
require.Equal(t, time.Duration(0), pts)
const stride = 150
lim := int64(uint64(0x1FFFFFFFF - (stride * 90000)))
for n := 0; n < 100; n++ {
// overflow
i += 90000 * stride
secs += stride
pts = d.Decode(i)
require.Equal(t, secs*time.Second, pts)
// reach 2^32 slowly
secs += stride
i += 90000 * stride
for ; i < lim; i += 90000 * stride {
pts = d.Decode(i)
require.Equal(t, secs*time.Second, pts)
secs += stride
}
}
}
func TestTimeDecoderOverflowAndBack(t *testing.T) {
d := NewTimeDecoder()
pts := d.Decode(0x1FFFFFFFF - 90000 + 1)
require.Equal(t, time.Duration(0), pts)
pts = d.Decode(90000)
require.Equal(t, 2*time.Second, pts)
pts = d.Decode(0x1FFFFFFFF - 90000 + 1)
require.Equal(t, time.Duration(0), pts)
pts = d.Decode(0x1FFFFFFFF - 90000*2 + 1)
require.Equal(t, -1*time.Second, pts)
pts = d.Decode(0x1FFFFFFFF - 90000 + 1)
require.Equal(t, time.Duration(0), pts)
pts = d.Decode(90000)
require.Equal(t, 2*time.Second, pts)
}