parse config一处判断无效value

This commit is contained in:
dexter
2023-02-15 09:35:00 +08:00
parent 04976bac16
commit 10a188a1ac
5 changed files with 21 additions and 5 deletions

View File

@@ -13,11 +13,12 @@ import (
) )
func SplitAnnexB[T ~[]byte](frame T, process func(T), delimiter []byte) { func SplitAnnexB[T ~[]byte](frame T, process func(T), delimiter []byte) {
for found, after := true, frame; len(frame) > 0 && found; frame = after { for after := frame; len(frame) > 0; frame = after {
frame, after, found = bytes.Cut(frame, delimiter) if frame, after, _ = bytes.Cut(frame, delimiter); len(frame) > 0 {
process(frame) process(frame)
} }
} }
}
type RTPFrame struct { type RTPFrame struct {
rtp.Packet rtp.Packet

View File

@@ -143,11 +143,13 @@ func (config Config) Unmarshal(s any) {
} }
fv.Set(s) fv.Set(s)
default: default:
if value.IsValid() {
fv.Set(value) fv.Set(value)
} }
} }
} }
} }
}
// 覆盖配置 // 覆盖配置
func (config Config) Assign(source Config) { func (config Config) Assign(source Config) {

View File

@@ -32,6 +32,7 @@ func (p *流速控制) 控制流速(绝对时间戳 uint32) {
// } // }
// 如果收到的帧的时间戳超过实际消耗的时间100ms就休息一下100ms作为一个弹性区间防止频繁调用sleep // 如果收到的帧的时间戳超过实际消耗的时间100ms就休息一下100ms作为一个弹性区间防止频繁调用sleep
if 过快 := (数据时间差 - 实际时间差); 过快 > 100*time.Millisecond { if 过快 := (数据时间差 - 实际时间差); 过快 > 100*time.Millisecond {
// fmt.Println("过快毫秒", 过快.Milliseconds())
// println("过快毫秒", p.name, 过快.Milliseconds()) // println("过快毫秒", p.name, 过快.Milliseconds())
if 过快 > p.等待上限 { if 过快 > p.等待上限 {
time.Sleep(p.等待上限) time.Sleep(p.等待上限)
@@ -224,6 +225,7 @@ func (av *Media) Flush() {
// av.Stream.Error("sub ring overflow", zap.Int("size", av.AVRing.Size), zap.String("name", av.Name)) // av.Stream.Error("sub ring overflow", zap.Int("size", av.AVRing.Size), zap.String("name", av.Name))
// } // }
} }
if av.起始时间.IsZero() { if av.起始时间.IsZero() {
curValue.DeltaTime = 0 curValue.DeltaTime = 0
av.重置(curValue.AbsTime) av.重置(curValue.AbsTime)
@@ -233,6 +235,7 @@ func (av *Media) Flush() {
} else { } else {
curValue.DeltaTime = curValue.AbsTime - preValue.AbsTime curValue.DeltaTime = curValue.AbsTime - preValue.AbsTime
} }
// fmt.Println(av.Name,curValue.DTS, curValue.AbsTime, curValue.DeltaTime)
if curValue.AUList.Length > 0 { if curValue.AUList.Length > 0 {
// 补完RTP // 补完RTP
if config.Global.EnableRTP && curValue.RTP.Length == 0 { if config.Global.EnableRTP && curValue.RTP.Length == 0 {

View File

@@ -93,7 +93,6 @@ func (vt *Video) writeAnnexBSlice(nalu []byte) {
} }
func (vt *Video) WriteAnnexB(pts uint32, dts uint32, frame []byte) { func (vt *Video) WriteAnnexB(pts uint32, dts uint32, frame []byte) {
// println("write annexb", len(frame), pts, dts)
if dts == 0 { if dts == 0 {
vt.generateTimestamp(pts) vt.generateTimestamp(pts)
} else { } else {

View File

@@ -2,12 +2,23 @@ package util
import ( import (
"encoding/binary" "encoding/binary"
"io"
"math" "math"
"net" "net"
) )
type Buffer []byte type Buffer []byte
func (b *Buffer) Read(buf []byte) (n int, err error) {
if !b.CanReadN(len(buf)) {
copy(buf, *b)
return b.Len(), io.EOF
}
ret := b.ReadN(len(buf))
copy(buf, ret)
return len(ret), err
}
func (b *Buffer) ReadN(n int) Buffer { func (b *Buffer) ReadN(n int) Buffer {
l := b.Len() l := b.Len()
r := (*b)[:n] r := (*b)[:n]