rtp判断空包,音频rtp包不判断marker

This commit is contained in:
dexter
2023-02-21 21:32:07 +08:00
parent 64e8412946
commit 18fe901a0e
6 changed files with 57 additions and 8 deletions

View File

@@ -62,6 +62,10 @@ func (aac *AAC) WriteADTS(ts uint32, adts []byte) {
// https://datatracker.ietf.org/doc/html/rfc3640#section-3.2.1 // https://datatracker.ietf.org/doc/html/rfc3640#section-3.2.1
func (aac *AAC) WriteRTPFrame(frame *RTPFrame) { func (aac *AAC) WriteRTPFrame(frame *RTPFrame) {
if aac.SampleRate != 90000 {
aac.generateTimestamp(uint32(uint64(frame.Timestamp) * 90000 / uint64(aac.SampleRate)))
}
defer aac.Flush()
auHeaderLen := util.ReadBE[int](frame.Payload[:aac.Mode]) >> 3 //通常为2即一个AU Header的长度 auHeaderLen := util.ReadBE[int](frame.Payload[:aac.Mode]) >> 3 //通常为2即一个AU Header的长度
// auHeaderCount := auHeaderLen >> 1 // AU Header的个数, 通常为1 // auHeaderCount := auHeaderLen >> 1 // AU Header的个数, 通常为1
if auHeaderLen == 0 { if auHeaderLen == 0 {

View File

@@ -54,5 +54,9 @@ func (g711 *G711) WriteAVCC(ts uint32, frame *util.BLL) error {
} }
func (g711 *G711) WriteRTPFrame(frame *RTPFrame) { func (g711 *G711) WriteRTPFrame(frame *RTPFrame) {
if g711.SampleRate != 90000 {
g711.generateTimestamp(uint32(uint64(frame.Timestamp) * 90000 / uint64(g711.SampleRate)))
}
g711.AppendAuBytes(frame.Payload) g711.AppendAuBytes(frame.Payload)
g711.Flush()
} }

View File

@@ -123,6 +123,10 @@ func (vt *H264) WriteRTPFrame(frame *RTPFrame) {
} }
} }
frame.SequenceNumber += vt.rtpSequence //增加偏移需要增加rtp包后需要顺延 frame.SequenceNumber += vt.rtpSequence //增加偏移需要增加rtp包后需要顺延
if frame.Marker {
vt.generateTimestamp(frame.Timestamp)
vt.Flush()
}
} }
// RTP格式补完 // RTP格式补完

View File

@@ -115,6 +115,10 @@ func (vt *H265) WriteRTPFrame(frame *RTPFrame) {
vt.WriteSliceBytes(frame.Payload) vt.WriteSliceBytes(frame.Payload)
} }
frame.SequenceNumber += vt.rtpSequence //增加偏移需要增加rtp包后需要顺延 frame.SequenceNumber += vt.rtpSequence //增加偏移需要增加rtp包后需要顺延
if frame.Marker {
vt.generateTimestamp(frame.Timestamp)
vt.Flush()
}
} }
// RTP格式补完 // RTP格式补完

View File

@@ -33,16 +33,11 @@ func (av *Media) UnmarshalRTP(raw []byte) (frame *RTPFrame) {
} }
func (av *Media) writeRTPFrame(frame *RTPFrame) { func (av *Media) writeRTPFrame(frame *RTPFrame) {
if len(frame.Payload) == 0 {
return
}
av.Value.RTP.PushValue(*frame) av.Value.RTP.PushValue(*frame)
av.WriteRTPFrame(frame) av.WriteRTPFrame(frame)
if frame.Marker {
if av.SampleRate != 90000 {
av.SpesificTrack.generateTimestamp(uint32(uint64(frame.Timestamp) * 90000 / uint64(av.SampleRate)))
} else {
av.SpesificTrack.generateTimestamp(frame.Timestamp)
}
av.SpesificTrack.Flush()
}
} }
// WriteRTPPack 写入已反序列化的RTP包 // WriteRTPPack 写入已反序列化的RTP包

38
util/reorder_test.go Normal file
View File

@@ -0,0 +1,38 @@
package util
import (
"testing"
)
type stuff struct {
seq uint16
}
func (s *stuff) Clone() *stuff {
return s
}
func TestReorder(t *testing.T) {
t.Run(t.Name(), func(t *testing.T) {
var recoder RTPReorder[*stuff]
for i := (uint16)(0); i < 25; i++ {
recoder.Push(i*2, &stuff{seq: i * 2})
}
if recoder.Pop() != nil {
t.Error("pop nil")
}
for i := (uint16)(0); i < 25; i++ {
x := recoder.Push(i*2+1, &stuff{seq: i*2 + 1})
if x != nil {
t.Logf("%d", x.seq)
}
for {
if x = recoder.Pop(); x == nil {
break
} else {
t.Logf("%d", x.seq)
}
}
}
})
}