rtp音视频时间戳都减去起始偏移值

This commit is contained in:
langhuihui
2021-07-12 23:19:52 +08:00
parent 3724b878ca
commit 2fb116bd00
2 changed files with 45 additions and 36 deletions

View File

@@ -17,7 +17,7 @@ import (
. "github.com/logrusorgru/aurora"
)
const Version = "3.1.2"
const Version = "3.1.4"
var (
config = &struct {

21
rtp.go
View File

@@ -49,8 +49,13 @@ func (v *RTPVideo) push(payload []byte) {
if err := v.Unmarshal(payload); err != nil {
return
}
t := v.Timestamp / 90
if t < vt.Prev().Value.(*RingItem).Value.(*VideoPack).Timestamp {
t0 := v.Timestamp
v.Push = func(payload []byte) {
if err := v.Unmarshal(payload); err != nil {
return
}
t1 := (v.Timestamp - t0)/90
if t1 < vt.Prev().Value.(*RingItem).Value.(*VideoPack).Timestamp {
if vt.WaitIDR.Err() == nil {
return
}
@@ -80,7 +85,7 @@ func (v *RTPVideo) push(payload []byte) {
return
}
r := tmpVT.Ring
t := v.Timestamp / 90
t := (v.Timestamp - t0) / 90
if tmpVT.PushNalu(t, 0, v.Payload); r != tmpVT.Ring {
ts = append(ts, t)
}
@@ -88,13 +93,16 @@ func (v *RTPVideo) push(payload []byte) {
v.Push(payload)
return
}
vt.PushNalu(t, 0, v.Payload)
vt.PushNalu(t1, 0, v.Payload)
}
v.Push(payload)
}
func (v *RTPAudio) push(payload []byte) {
at := v.AudioTrack
if err := v.Unmarshal(payload); err != nil {
return
}
startTime := v.Timestamp
switch at.CodecID {
case 10:
v.Push = func(payload []byte) {
@@ -102,7 +110,7 @@ func (v *RTPAudio) push(payload []byte) {
return
}
for _, payload = range codec.ParseRTPAAC(v.Payload) {
at.PushRaw(v.Timestamp/90, payload)
at.PushRaw((v.Timestamp-startTime)/90, payload)
}
}
case 7, 8:
@@ -110,7 +118,8 @@ func (v *RTPAudio) push(payload []byte) {
if err := v.Unmarshal(payload); err != nil {
return
}
at.PushRaw(v.Timestamp/8, v.Payload)
at.PushRaw((v.Timestamp-startTime)/8, v.Payload)
}
}
v.Push(payload)
}