VideoFrame和AudioFrame增加track的指针方便访问track,rtp写入采用内存复用机制

This commit is contained in:
dexter
2023-02-26 10:36:37 +08:00
parent 4d008cfc5e
commit fd2c7b8cb6
11 changed files with 78 additions and 110 deletions

View File

@@ -1,18 +1,13 @@
package util
type CloneType[T any] interface {
Clone() T
comparable
}
var RTPReorderBufferLen uint16 = 50
// RTPReorder RTP包乱序重排
type RTPReorder[T CloneType[T]] struct {
type RTPReorder[T comparable] struct {
lastSeq uint16 //最新收到的rtp包序号
queue []T // 缓存队列,0号元素位置代表lastReq+1永远保持为空
Total uint32 // 总共收到的包数量
Drop uint32 // 丢弃的包数量
Total uint32 // 总共收到的包数量
Drop uint32 // 丢弃的包数量
}
func (p *RTPReorder[T]) Push(seq uint16, v T) (result T) {
@@ -48,7 +43,7 @@ func (p *RTPReorder[T]) Push(seq uint16, v T) (result T) {
head := p.pop()
// 可以放得进去了
if delta == RTPReorderBufferLen {
p.queue[RTPReorderBufferLen-1] = v.Clone()
p.queue[RTPReorderBufferLen-1] = v
p.queue[0] = result
return head
} else if head != result {
@@ -57,7 +52,7 @@ func (p *RTPReorder[T]) Push(seq uint16, v T) (result T) {
}
} else {
// 出现后面的包先到达,缓存起来
p.queue[delta-1] = v.Clone()
p.queue[delta-1] = v
return
}
}