int ES_AAC::FindHeaders(uint8_t *buf, int buf_size) { if (es_found_frame) return -1; uint8_t *buf_ptr = buf; if (stream_type == STREAM_TYPE_AUDIO_AAC) { if (buf_ptr[0] == 0xFF && (buf_ptr[1] & 0xF0) == 0xF0) stream_type = STREAM_TYPE_AUDIO_AAC_ADTS; else if (buf_ptr[0] == 0x56 && (buf_ptr[1] & 0xE0) == 0xE0) stream_type = STREAM_TYPE_AUDIO_AAC_LATM; } // STREAM_TYPE_AUDIO_AAC_LATM if (stream_type == STREAM_TYPE_AUDIO_AAC_LATM) { if ((buf_ptr[0] == 0x56 && (buf_ptr[1] & 0xE0) == 0xE0)) { // TODO if (buf_size < 16) return -1; cBitstream bs(buf_ptr, 16 * 8); bs.skipBits(11); m_FrameSize = bs.readBits(13) + 3; if (!ParseLATMAudioMuxElement(&bs)) return 0; es_found_frame = true; m_DTS = c_pts; m_PTS = c_pts; c_pts += 90000 * 1024 / m_SampleRate; return -1; } } // STREAM_TYPE_AUDIO_AAC_ADTS else if (stream_type == STREAM_TYPE_AUDIO_AAC_ADTS) { if(buf_ptr[0] == 0xFF && (buf_ptr[1] & 0xF0) == 0xF0) { // need at least 7 bytes for header if (buf_size < 7) return -1; cBitstream bs(buf_ptr, 9 * 8); bs.skipBits(15); // check if CRC is present, means header is 9 byte long int noCrc = bs.readBits(1); if (!noCrc && (buf_size < 9)) return -1; bs.skipBits(2); // profile int SampleRateIndex = bs.readBits(4); bs.skipBits(1); // private m_Channels = bs.readBits(3); bs.skipBits(4); m_FrameSize = bs.readBits(13); m_SampleRate = aac_sample_rates[SampleRateIndex & 0x0E]; es_found_frame = true; m_DTS = c_pts; m_PTS = c_pts; c_pts += 90000 * 1024 / m_SampleRate; return -1; } } return 0; }
int cParserAAC::FindHeaders(uint8_t *buf, int buf_size) { if (m_FoundFrame) return -1; uint8_t *buf_ptr = buf; if (m_Stream->Type() == stAACLATM) { if ((buf_ptr[0] == 0x56 && (buf_ptr[1] & 0xE0) == 0xE0)) { // TODO if (buf_size < 16) return -1; cBitstream bs(buf_ptr, 16 * 8); bs.skipBits(11); m_FrameSize = bs.readBits(13) + 3; if (!ParseLATMAudioMuxElement(&bs)) return 0; m_FoundFrame = true; m_DTS = m_curPTS; m_PTS = m_curPTS; if(!m_SampleRate) m_SampleRate = aac_sample_rates[4]; m_curPTS += 90000 * 1024 / m_SampleRate; return -1; } else if (m_DetectMuxMode && buf_ptr[0] == 0xFF && (buf_ptr[1] & 0xF0) == 0xF0) { m_Stream->SetType(stAACADTS); INFOLOG("cParserAAC::FindHeaders - detected ADTS muxing mode"); return -1; } } else if (m_Stream->Type() == stAACADTS) { if(buf_ptr[0] == 0xFF && (buf_ptr[1] & 0xF0) == 0xF0) { // need at least 7 bytes for header if (buf_size < 7) return -1; cBitstream bs(buf_ptr, 9 * 8); bs.skipBits(15); // check if CRC is present, means header is 9 byte long int noCrc = bs.readBits(1); if (!noCrc && (buf_size < 9)) return -1; bs.skipBits(2); // profile int SampleRateIndex = bs.readBits(4); bs.skipBits(1); // private m_Channels = bs.readBits(3); bs.skipBits(4); m_FrameSize = bs.readBits(13); m_SampleRate = aac_sample_rates[SampleRateIndex & 0x0E]; m_FoundFrame = true; m_DTS = m_curPTS; m_PTS = m_curPTS; m_curPTS += 90000 * 1024 / m_SampleRate; return -1; } else if (m_DetectMuxMode && buf_ptr[0] == 0x56 && (buf_ptr[1] & 0xE0) == 0xE0) { m_Stream->SetType(stAACLATM); INFOLOG("cParserAAC::FindHeaders - detected LATM muxing mode"); return -1; } } return 0; }