codec.MakeADTSHeader -> aacparser.MakeADTSHeader; remove ReadADTSHeader
This commit is contained in:
parent
4fbd234bbf
commit
a18779ff4c
@ -147,54 +147,6 @@ func SplitADTSFrames(frames []byte) (config MPEG4AudioConfig, payload [][]byte,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadADTSHeader(data []byte) (config MPEG4AudioConfig, frameLength int) {
|
|
||||||
br := &bits.Reader{R: bytes.NewReader(data)}
|
|
||||||
var i uint
|
|
||||||
|
|
||||||
//Structure
|
|
||||||
//AAAAAAAA AAAABCCD EEFFFFGH HHIJKLMM MMMMMMMM MMMOOOOO OOOOOOPP (QQQQQQQQ QQQQQQQQ)
|
|
||||||
//Header consists of 7 or 9 bytes (without or with CRC).
|
|
||||||
|
|
||||||
// 2 bytes
|
|
||||||
//A 12 syncword 0xFFF, all bits must be 1
|
|
||||||
br.ReadBits(12)
|
|
||||||
//B 1 MPEG Version: 0 for MPEG-4, 1 for MPEG-2
|
|
||||||
br.ReadBits(1)
|
|
||||||
//C 2 Layer: always 0
|
|
||||||
br.ReadBits(2)
|
|
||||||
//D 1 protection absent, Warning, set to 1 if there is no CRC and 0 if there is CRC
|
|
||||||
br.ReadBits(1)
|
|
||||||
|
|
||||||
//E 2 profile, the MPEG-4 Audio Object Type minus 1
|
|
||||||
config.ObjectType, _ = br.ReadBits(2)
|
|
||||||
config.ObjectType++
|
|
||||||
//F 4 MPEG-4 Sampling Frequency Index (15 is forbidden)
|
|
||||||
config.SampleRateIndex, _ = br.ReadBits(4)
|
|
||||||
//G 1 private bit, guaranteed never to be used by MPEG, set to 0 when encoding, ignore when decoding
|
|
||||||
br.ReadBits(1)
|
|
||||||
//H 3 MPEG-4 Channel Configuration (in the case of 0, the channel configuration is sent via an inband PCE)
|
|
||||||
config.ChannelConfig, _ = br.ReadBits(3)
|
|
||||||
//I 1 originality, set to 0 when encoding, ignore when decoding
|
|
||||||
br.ReadBits(1)
|
|
||||||
//J 1 home, set to 0 when encoding, ignore when decoding
|
|
||||||
br.ReadBits(1)
|
|
||||||
//K 1 copyrighted id bit, the next bit of a centrally registered copyright identifier, set to 0 when encoding, ignore when decoding
|
|
||||||
br.ReadBits(1)
|
|
||||||
//L 1 copyright id start, signals that this frame's copyright id bit is the first bit of the copyright id, set to 0 when encoding, ignore when decoding
|
|
||||||
br.ReadBits(1)
|
|
||||||
|
|
||||||
//M 13 frame length, this value must include 7 or 9 bytes of header length: FrameLength = (ProtectionAbsent == 1 ? 7 : 9) + size(AACFrame)
|
|
||||||
i, _ = br.ReadBits(13)
|
|
||||||
frameLength = int(i)
|
|
||||||
//O 11 Buffer fullness
|
|
||||||
br.ReadBits(11)
|
|
||||||
//P 2 Number of AAC frames (RDBs) in ADTS frame minus 1, for maximum compatibility always use 1 AAC frame per ADTS frame
|
|
||||||
br.ReadBits(2)
|
|
||||||
|
|
||||||
//Q 16 CRC if protection absent is 0
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func readObjectType(r *bits.Reader) (objectType uint, err error) {
|
func readObjectType(r *bits.Reader) (objectType uint, err error) {
|
||||||
if objectType, err = r.ReadBits(5); err != nil {
|
if objectType, err = r.ReadBits(5); err != nil {
|
||||||
return
|
return
|
||||||
@ -359,10 +311,6 @@ func (self CodecData) PacketDuration(data []byte) (dur time.Duration, err error)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self CodecData) MakeADTSHeader(samples int, payloadLength int) []byte {
|
|
||||||
return MakeADTSHeader(self.Config, samples, payloadLength)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewCodecDataFromMPEG4AudioConfigBytes(config []byte) (self CodecData, err error) {
|
func NewCodecDataFromMPEG4AudioConfigBytes(config []byte) (self CodecData, err error) {
|
||||||
self.ConfigBytes = config
|
self.ConfigBytes = config
|
||||||
if self.Config, err = ParseMPEG4AudioConfig(config); err != nil {
|
if self.Config, err = ParseMPEG4AudioConfig(config); err != nil {
|
||||||
|
@ -146,7 +146,7 @@ func (self *Muxer) writePacket(pkt av.Packet) (err error) {
|
|||||||
case av.AAC:
|
case av.AAC:
|
||||||
codec := stream.CodecData.(aacparser.CodecData)
|
codec := stream.CodecData.(aacparser.CodecData)
|
||||||
data := pkt.Data
|
data := pkt.Data
|
||||||
data = append(codec.MakeADTSHeader(1024, len(data)), data...)
|
data = append(aacparser.MakeADTSHeader(codec.Config, 1024, len(data)), data...)
|
||||||
|
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
pes := PESHeader{
|
pes := PESHeader{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user