mirror of
https://github.com/Monibuca/engine.git
synced 2025-10-18 14:40:40 +08:00
4.0初步改造
This commit is contained in:
56
track/base.go
Normal file
56
track/base.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package track
|
||||
|
||||
import (
|
||||
. "github.com/Monibuca/engine/v4/common"
|
||||
"github.com/Monibuca/engine/v4/util"
|
||||
"github.com/pion/rtp"
|
||||
)
|
||||
|
||||
// Base 基础Track类
|
||||
type Base struct {
|
||||
Name string
|
||||
Stream IStream `json:"-"`
|
||||
BPS
|
||||
}
|
||||
|
||||
func (bt *Base) Flush(bf *BaseFrame) {
|
||||
bt.ComputeBPS(bf.BytesIn)
|
||||
bf.SeqInStream = bt.Stream.Update()
|
||||
}
|
||||
|
||||
// Media 基础媒体Track类
|
||||
type Media[T RawSlice] struct {
|
||||
Base
|
||||
AVRing[T] `json:"-"`
|
||||
CodecID byte
|
||||
SampleRate HZ
|
||||
DecoderConfiguration AVFrame[T] `json:"-"` //H264(SPS、PPS) H265(VPS、SPS、PPS) AAC(config)
|
||||
util.BytesPool //无锁内存池,用于发布者(在同一个协程中)复用小块的内存,通常是解包时需要临时使用
|
||||
}
|
||||
|
||||
func (av *Media[T]) WriteRTP(raw []byte) {
|
||||
av.Value.AppendRTP(raw)
|
||||
var packet rtp.Packet
|
||||
if err := packet.Unmarshal(raw); err != nil {
|
||||
return
|
||||
}
|
||||
av.Value.AppendRTPPackets(packet)
|
||||
if packet.Marker {
|
||||
av.Flush()
|
||||
}
|
||||
}
|
||||
|
||||
func (av *Media[T]) WriteSlice(slice T) {
|
||||
av.Value.AppendRaw(slice)
|
||||
}
|
||||
func (av *Media[T]) WriteAVCC(ts uint32, frame AVCCFrame) {
|
||||
av.Value.BytesIn = len(frame)
|
||||
av.Value.AppendAVCC(frame)
|
||||
av.Value.DTS = av.SampleRate.ToNTS(ts)
|
||||
av.Value.PTS = av.SampleRate.ToNTS(ts + frame.CTS())
|
||||
}
|
||||
|
||||
func (av *Media[T]) Flush() {
|
||||
av.Base.Flush(&av.Value.BaseFrame)
|
||||
av.Step()
|
||||
}
|
Reference in New Issue
Block a user