inline void RtmpParser::onGetAAC(const char* pcData, int iLen, uint32_t ui32TimeStamp) { //添加adts头 memcpy(m_adts.data + 7, pcData, iLen); m_adts.aac_frame_length = 7 + iLen; m_adts.timeStamp = ui32TimeStamp; writeAdtsHeader(m_adts, m_adts.data); { lock_guard<recursive_mutex> lck(m_mtxCB); if (onAudio) { onAudio(m_adts); } } m_adts.aac_frame_length = 7; }
status_t AACWriter::threadFunc() { mEstimatedDurationUs = 0; mEstimatedSizeBytes = 0; int64_t previousPausedDurationUs = 0; int64_t maxTimestampUs = 0; status_t err = OK; prctl(PR_SET_NAME, (unsigned long)"AACWriterThread", 0, 0, 0); while (!mDone && err == OK) { MediaBuffer *buffer; err = mSource->read(&buffer); if (err != OK) { break; } if (mPaused) { buffer->release(); buffer = NULL; continue; } mEstimatedSizeBytes += kAdtsHeaderLength + buffer->range_length(); if (exceedsFileSizeLimit()) { buffer->release(); buffer = NULL; notify(MEDIA_RECORDER_EVENT_INFO, MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED, 0); break; } int32_t isCodecSpecific = 0; if (buffer->meta_data()->findInt32(kKeyIsCodecConfig, &isCodecSpecific) && isCodecSpecific) { ALOGV("Drop codec specific info buffer"); buffer->release(); buffer = NULL; continue; } int64_t timestampUs; CHECK(buffer->meta_data()->findInt64(kKeyTime, ×tampUs)); if (timestampUs > mEstimatedDurationUs) { mEstimatedDurationUs = timestampUs; } if (mResumed) { previousPausedDurationUs += (timestampUs - maxTimestampUs - mFrameDurationUs); mResumed = false; } timestampUs -= previousPausedDurationUs; ALOGV("time stamp: %lld, previous paused duration: %lld", timestampUs, previousPausedDurationUs); if (timestampUs > maxTimestampUs) { maxTimestampUs = timestampUs; } if (exceedsFileDurationLimit()) { buffer->release(); buffer = NULL; notify(MEDIA_RECORDER_EVENT_INFO, MEDIA_RECORDER_INFO_MAX_DURATION_REACHED, 0); break; } // Each output AAC audio frame to the file contains // 1. an ADTS header, followed by // 2. the compressed audio data. ssize_t dataLength = buffer->range_length(); uint8_t *data = (uint8_t *)buffer->data() + buffer->range_offset(); if (writeAdtsHeader(kAdtsHeaderLength + dataLength) != OK || dataLength != write(mFd, data, dataLength)) { err = ERROR_IO; } buffer->release(); buffer = NULL; } close(mFd); mFd = -1; mReachedEOS = true; if (err == ERROR_END_OF_STREAM) { return OK; } return err; }