mirror of
https://github.com/Monibuca/engine.git
synced 2025-10-05 16:46:58 +08:00
VideoFrame和AudioFrame增加track的指针方便访问track,rtp写入采用内存复用机制
This commit is contained in:
12
memory-ts.go
12
memory-ts.go
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"m7s.live/engine/v4/codec"
|
||||
"m7s.live/engine/v4/codec/mpegts"
|
||||
"m7s.live/engine/v4/common"
|
||||
"m7s.live/engine/v4/util"
|
||||
)
|
||||
|
||||
@@ -141,11 +140,11 @@ func (ts *MemoryTs) WritePESPacket(frame *mpegts.MpegtsPESFrame, packet mpegts.M
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ts *MemoryTs) WriteAudioFrame(frame *AudioFrame, aac_asc *codec.AudioSpecificConfig, pes *mpegts.MpegtsPESFrame) (err error) {
|
||||
func (ts *MemoryTs) WriteAudioFrame(frame AudioFrame, pes *mpegts.MpegtsPESFrame) (err error) {
|
||||
adtsItem := ts.Get(7)
|
||||
defer adtsItem.Recycle()
|
||||
adts := adtsItem.Value
|
||||
aac_asc.ToADTS(frame.AUList.ByteLength, adts)
|
||||
frame.AudioSpecificConfig.ToADTS(frame.AUList.ByteLength, adts)
|
||||
// packetLength = 原始音频流长度 + adts(7) + MpegTsOptionalPESHeader长度(8 bytes, 因为只含有pts)
|
||||
pktLength := len(adts) + frame.AUList.ByteLength + 8
|
||||
var packet mpegts.MpegTsPESPacket
|
||||
@@ -161,17 +160,14 @@ func (ts *MemoryTs) WriteAudioFrame(frame *AudioFrame, aac_asc *codec.AudioSpeci
|
||||
return ts.WritePESPacket(pes, packet)
|
||||
}
|
||||
|
||||
func (ts *MemoryTs) WriteVideoFrame(frame *VideoFrame, paramaterSets common.ParamaterSets, pes *mpegts.MpegtsPESFrame) (err error) {
|
||||
func (ts *MemoryTs) WriteVideoFrame(frame VideoFrame, pes *mpegts.MpegtsPESFrame) (err error) {
|
||||
var buffer net.Buffers
|
||||
//需要对原始数据(ES),进行一些预处理,视频需要分割nalu(H264编码),并且打上sps,pps,nalu_aud信息.
|
||||
if len(paramaterSets) == 2 {
|
||||
if len(frame.ParamaterSets) == 2 {
|
||||
buffer = append(buffer, codec.NALU_AUD_BYTE)
|
||||
} else {
|
||||
buffer = append(buffer, codec.AudNalu)
|
||||
}
|
||||
if frame.IFrame {
|
||||
buffer = append(buffer, paramaterSets.GetAnnexB()...)
|
||||
}
|
||||
buffer = append(buffer, frame.GetAnnexB()...)
|
||||
pktLength := util.SizeOfBuffers(buffer) + 10 + 3
|
||||
if pktLength > 0xffff {
|
||||
|
Reference in New Issue
Block a user