Files
engine/avformat/avpacket.go
2020-05-01 11:41:16 +08:00

62 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package avformat
import (
"sync"
)
var (
SendPacketPool = &sync.Pool{
New: func() interface{} {
return new(SendPacket)
},
}
)
// Video or Audio
type AVPacket struct {
Timestamp uint32
Type byte //8 audio,9 video
IsSequence bool //序列帧
IsKeyFrame bool//是否为关键帧
Payload []byte
Number int //编号audio和video独立编号
}
func (av *AVPacket) ADTS2ASC() (tagPacket *AVPacket) {
tagPacket = NewAVPacket(FLV_TAG_TYPE_AUDIO)
tagPacket.Payload = ADTSToAudioSpecificConfig(av.Payload)
tagPacket.IsSequence = true
ADTSLength := 7 + ((1 - int(av.Payload[1]&1)) << 1)
if len(av.Payload) > ADTSLength {
av.Payload[0] = 0xAF
av.Payload[1] = 0x01 //raw AAC
copy(av.Payload[2:], av.Payload[ADTSLength:])
av.Payload = av.Payload[:(len(av.Payload) - ADTSLength + 2)]
}
return
}
func NewAVPacket(avType byte) (p *AVPacket) {
p = new(AVPacket)
p.Type = avType
return
}
func (av AVPacket) Clone() *AVPacket {
return &av
}
type SendPacket struct {
*AVPacket
Timestamp uint32
}
func (packet *SendPacket) Recycle() {
SendPacketPool.Put(packet)
}
func NewSendPacket(p *AVPacket, timestamp uint32) (result *SendPacket) {
result = SendPacketPool.Get().(*SendPacket)
result.AVPacket = p
result.Timestamp = timestamp
return
}