Fix timestamp processing for HTTP-FLV
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
package flv
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTimeToRTP(t *testing.T) {
|
||||||
|
// Reolink camera has 20 FPS
|
||||||
|
// Video timestamp increases by 50ms, SampleRate 90000, RTP timestamp increases by 4500
|
||||||
|
// Audio timestamp increases by 64ms, SampleRate 16000, RTP timestamp increases by 1024
|
||||||
|
frameN := 1
|
||||||
|
for i := 0; i < 32; i++ {
|
||||||
|
// 1000ms/(90000/4500) = 50ms
|
||||||
|
require.Equal(t, uint32(frameN*4500), TimeToRTP(uint32(frameN*50), 90000))
|
||||||
|
// 1000ms/(16000/1024) = 64ms
|
||||||
|
require.Equal(t, uint32(frameN*1024), TimeToRTP(uint32(frameN*64), 16000))
|
||||||
|
frameN *= 2
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-2
@@ -299,8 +299,12 @@ func (c *Producer) readPacket() (*rtp.Packet, error) {
|
|||||||
return pkt, nil
|
return pkt, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TimeToRTP(timeMS uint32, clockRate uint32) uint32 {
|
// TimeToRTP convert time in milliseconds to RTP time
|
||||||
return timeMS * clockRate / 1000
|
func TimeToRTP(timeMS, clockRate uint32) uint32 {
|
||||||
|
// for clockRates 90000, 16000, 8000, etc. - we can use:
|
||||||
|
// return timeMS * (clockRate / 1000)
|
||||||
|
// but for clockRates 44100, 22050, 11025 - we should use:
|
||||||
|
return uint32(uint64(timeMS) * uint64(clockRate) / 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isExHeader(data []byte) bool {
|
func isExHeader(data []byte) bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user