package extend import ( "context" "m7s.live/engine/v4/codec" "m7s.live/engine/v4/common" "m7s.live/engine/v4/track" "m7s.live/engine/v4/util" "net" ) func ReadRing(vt *track.Video) *common.RingBuffer[common.AVFrame] { return util.Clone(vt.Media.RingBuffer) } func Read(r *common.RingBuffer[common.AVFrame], ctx context.Context) (item *common.AVFrame) { for item = &r.Value; ctx.Err() == nil && !item.CanRead; { } return } // PlayFullAnnexB 订阅annex-b格式的流数据,每一个I帧增加sps、pps头 func PlayFullAnnexB(vt *track.Video, ctx context.Context, onMedia func(net.Buffers) error) error { for vr := ReadRing(vt); ctx.Err() == nil; vr.MoveNext() { vp := Read(vr, ctx) var data net.Buffers if vp.IFrame { for _, nalu := range vt.ParamaterSets { data = append(data, codec.NALU_Delimiter2, nalu) } } data = append(data, codec.NALU_Delimiter2) i := 0 vp.AUList.Range(func(au *util.BLL) bool { if i > 0 { data = append(data, codec.NALU_Delimiter1, au.ToBytes()) } else { data = append(data, au.ToBuffers()...) } i++ return true }) if err := onMedia(data); err != nil { // TODO: log err return err } } return ctx.Err() }