diff --git a/common/frame.go b/common/frame.go index 8b0e991..83d6253 100644 --- a/common/frame.go +++ b/common/frame.go @@ -13,9 +13,10 @@ import ( ) func SplitAnnexB[T ~[]byte](frame T, process func(T), delimiter []byte) { - for found, after := true, frame; len(frame) > 0 && found; frame = after { - frame, after, found = bytes.Cut(frame, delimiter) - process(frame) + for after := frame; len(frame) > 0; frame = after { + if frame, after, _ = bytes.Cut(frame, delimiter); len(frame) > 0 { + process(frame) + } } } diff --git a/config/config.go b/config/config.go index bd4e712..c413afd 100644 --- a/config/config.go +++ b/config/config.go @@ -143,7 +143,9 @@ func (config Config) Unmarshal(s any) { } fv.Set(s) default: - fv.Set(value) + if value.IsValid() { + fv.Set(value) + } } } } diff --git a/track/base.go b/track/base.go index f27069d..f317e0e 100644 --- a/track/base.go +++ b/track/base.go @@ -32,6 +32,7 @@ func (p *流速控制) 控制流速(绝对时间戳 uint32) { // } // 如果收到的帧的时间戳超过实际消耗的时间100ms就休息一下,100ms作为一个弹性区间防止频繁调用sleep if 过快 := (数据时间差 - 实际时间差); 过快 > 100*time.Millisecond { + // fmt.Println("过快毫秒", 过快.Milliseconds()) // println("过快毫秒", p.name, 过快.Milliseconds()) if 过快 > 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)) // } } + if av.起始时间.IsZero() { curValue.DeltaTime = 0 av.重置(curValue.AbsTime) @@ -233,6 +235,7 @@ func (av *Media) Flush() { } else { curValue.DeltaTime = curValue.AbsTime - preValue.AbsTime } + // fmt.Println(av.Name,curValue.DTS, curValue.AbsTime, curValue.DeltaTime) if curValue.AUList.Length > 0 { // 补完RTP if config.Global.EnableRTP && curValue.RTP.Length == 0 { diff --git a/track/video.go b/track/video.go index 313e514..754aea2 100644 --- a/track/video.go +++ b/track/video.go @@ -93,7 +93,6 @@ func (vt *Video) writeAnnexBSlice(nalu []byte) { } func (vt *Video) WriteAnnexB(pts uint32, dts uint32, frame []byte) { - // println("write annexb", len(frame), pts, dts) if dts == 0 { vt.generateTimestamp(pts) } else { diff --git a/util/buffer.go b/util/buffer.go index 26a14db..8a94f01 100644 --- a/util/buffer.go +++ b/util/buffer.go @@ -2,12 +2,23 @@ package util import ( "encoding/binary" + "io" "math" "net" ) 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 { l := b.Len() r := (*b)[:n]