/**
* Add ADTS header at the beginning of a raw AAC data packet.
**/
void addADTStoPacket(unsigned char* packet, int packetLen) {
int profile = 2; //AAC LC,MediaCodecInfo.CodecProfileLevel.AACObjectLC;
int freqIdx = 3; //48000, 见后面注释avpriv_mpeg4audio_sample_rates中48000对应的数组下标,来自ffmpeg源码
int chanCfg = 2; //见后面注释channel_configuration,Stero双声道立体声
/*int avpriv_mpeg4audio_sample_rates[] = {
96000, 88200, 64000, 48000, 44100, 32000,
24000, 22050, 16000, 12000, 11025, 8000, 7350
};
channel_configuration: 表示声道数chanCfg
0: Defined in AOT Specifc Config
1: 1 channel: front-center
2: 2 channels: front-left, front-right
3: 3 channels: front-center, front-left, front-right
4: 4 channels: front-center, front-left, front-right, back-center
5: 5 channels: front-center, front-left, front-right, back-left, back-right
6: 6 channels: front-center, front-left, front-right, back-left, back-right, LFE-channel
7: 8 channels: front-center, front-left, front-right, side-left, side-right, back-left, back-right, LFE-channel
8-15: Reserved*/
/* Sync point over a full byte */
packet[0] = 0xFF;
/* Sync point continued over first 4 bits + static 4 bits
* (ID, layer, protection)*/
packet[1] = 0xF9;
packet[2] = (unsigned char)(((profile-1)<<6) + (freqIdx<<2) +(chanCfg>>2));
packet[3] = (unsigned char)(((chanCfg&3)<<6) + (packetLen>>11));
packet[4] = (unsigned char)((packetLen&0x7FF) >> 3);
packet[5] = (unsigned char)(((packetLen&7)<<5) + 0x1F);
packet[6] = 0xFC;// one raw data blocks .
//int nblock = packetLen / 1024;
//packet[6] |= (unsigned char)(nblock & 0x03); //Set raw Data blocks. (number of raw data blocks)
}