void Adts2Asc(uint8_t* pData, int nSize) {
// 判断是否为adts格式的aac数据,如果不是则返回失败
if (nSize < 7 || pData[0] != 0xFF || (pData[1] & 0xF0) != 0xF0) {
JmixcLogError("Invalid aac frame, only support adts format");
return nSize;
}
int adtsHeaderLen = 7;
if (0 == pData[1] & 0x01) {
adtsHeaderLen = 9; // 包含2字节的crc校验码
}
// 1、adts解析
/*pData[0] << 8 | pData[1] & 0xF0; // 0xFFF0 同步字段 总是0xFFF,代表一个ADTS帧的开始,作为分界符,用于同步每帧起始位置
(pData[1] & 0x08) >> 3; // 0/1 ID 0 for MPEG-4, 1 for MPEG-2
(pData[1] & 0x06) >> 1; // 0/1/2 Layer 总是0
pData[1] & 0x01; // 0/1 Protection absent set to 1 if there is no CRC and 0 if there is CRC
(pData[2] & 0xC0) >> 6; // 0~3 Profile 0 Main, 1 LC, 2 SSR, 3 LTP,profile的值等于 Audio Object Type的值减1
(pData[2] & 0x3C) >> 2; // 0~15 Sampling Frequency Index MPEG-4 Sampling Frequency Index (15 is forbidden)
(pData[2] & 0x02) >> 1; // 0/1 Private bit 总是0
(pData[2] & 0x01) << 2 | (pData[3] & 0xC0) >> 6; // 0/1 Channel Configuration MPEG-4 Channel Configuration (in case of AAC Main: 0 = 1 Channel: Front-center channel)
(pData[3] & 0x20) >> 5; // 0/1 Originality 总是0
(pData[3] & 0x10) >> 4; // 0/1 Home 总是0
(pData[3] & 0x08) >> 3; // 0/1 Copyright identification bit 总是0
(pData[3] & 0x04) >> 2; // 0/1 Copyright identification start 总是0
(pData[3] & 0x03) << 11 | pData[4] << 3 |(pData[5] & 0xE0) >> 5; // Frame length 一个 ADTS 帧的长度包括 ADTS 头和 AAC 原始流.this value must include 7 or 9 bytes of header length FrameLength = (ProtectionAbsent == 1 ? 7 : 9) + size(AACFrame)
(pData[5] & 0x1F) << 6 | (pData[6] & 0xFC) >> 2; // Buffer fullness 0x7FF indicates that this frame uses the full available bit rate.
pData[6] & 0x03; // Number of raw data blocks in frame 1 to 4,ADTS 帧中有 number_of_raw_data_blocks_in_frame + 1 个 AAC 原始帧
*/
// asc
int profile = ((pData[2] & 0xC0) >> 6) + 1;
int sampleFrequencyIndex = (pData[2] & 0x3C) >> 2;
int channelConfig = ((pData[2] & 0x01) << 2) | ((pData[3] & 0xC0) >> 6);
uint8_t asc[2] = {0};
asc[0] = (profile << 3) | ((sampleFrequencyIndex >> 1) & 0x07);
asc[1] = ((sampleFrequencyIndex & 0x01) << 7) | ((channelConfig & 0x0F) << 3) | (0 << 2) | (0 << 1) | 0;
}
06-14
633
633
11-06
884
884
10-15
2988
2988

被折叠的 条评论
为什么被折叠?



