AacBqToPcmCbRenderer.cpp revision bb832e853d4afb11b0a3287b2eb0cad87696d631
1bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi/* 2bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * Copyright (C) 2011 The Android Open Source Project 3bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * 4bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * Licensed under the Apache License, Version 2.0 (the "License"); 5bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * you may not use this file except in compliance with the License. 6bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * You may obtain a copy of the License at 7bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * 8bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * http://www.apache.org/licenses/LICENSE-2.0 9bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * 10bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * Unless required by applicable law or agreed to in writing, software 11bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * distributed under the License is distributed on an "AS IS" BASIS, 12bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * See the License for the specific language governing permissions and 14bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * limitations under the License. 15bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi */ 16bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 17bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi//#define USE_LOG SLAndroidLogLevel_Debug 18bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 19bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#include "sles_allinclusive.h" 20bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#include "android/include/AacBqToPcmCbRenderer.h" 21bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#include <media/stagefright/foundation/ADebug.h> 22bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 23bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivinamespace android { 24bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 25bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi// ADTS header size is 7, but frame size information ends on byte 6 (when counting from byte 1) 26bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#define ADTS_HEADER_SIZE_UP_TO_FRAMESIZE 6 27bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 28bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi/** 29bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * Returns the size of an AAC ADTS frame. 30bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * Note that if the returned value + offset > size, it means that a partial frame starts at that 31bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * offset, but this function will still return the size of the full frame. 32bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * @param data pointer to the compressed audio data 33bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * @param offset offset in bytes relative to data of where the frame is supposed to start 34bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * @param size the size in bytes of the data block starting at data 35bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * @return the size in bytes of the AAC ADTS frame starting at the given offset of the given 36bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * memory address, 0 if the frame couldn't be parsed. 37bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi */ 38bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivistatic size_t getAdtsFrameSize(const uint8_t *data, off64_t offset, size_t size) { 39bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi size_t frameSize = 0; 40bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 41bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi if (!(offset + ADTS_HEADER_SIZE_UP_TO_FRAMESIZE < size)) { 42bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGE("AacBqToPcmCbRenderer::getAdtsFrameSize() returns 0 (can't read syncword or header)" 43bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi ); 44bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi return 0; 45bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 46bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 47bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi const uint8_t *syncword = data + offset; 48bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi if ((syncword[0] != 0xff) || ((syncword[1] & 0xf6) != 0xf0)) { 49bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGE("AacBqToPcmCbRenderer::getAdtsFrameSize() returns 0 (wrong syncword)"); 50bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi return 0; 51bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 52bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 53bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi const uint8_t protectionAbsent = data[offset+1] & 0x1; 54bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 55bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi const uint8_t* header = data + offset + 3; 56bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi frameSize = (header[0] & 0x3) << 11 | header[1] << 3 | header[2] >> 5; 57bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi // the frame size read already contains the size of the header, so no need to add it here 58bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi frameSize += protectionAbsent ? 0 : 2; 59bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 60bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGV("AacBqToPcmCbRenderer::getAdtsFrameSize() returns %u", frameSize); 61bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 62bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi return frameSize; 63bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi} 64bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 65bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi/** 66bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * Returns whether a block of memory starts and ends on AAC ADTS frame boundaries 67bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * @param data pointer to the compressed audio data 68bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * @param size the size in bytes of the data block to validate 69bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * @return true if there is AAC ADTS data, and it starts and ends on frame boundaries, 70bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * false otherwise 71bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi */ 72bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivibool AacBqToPcmCbRenderer::validateBufferStartEndOnFrameBoundaries(void* data, size_t size) 73bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi{ 74bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi off64_t offset = 0; 75bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi size_t frameSize = 0; 76bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 77bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi if ((NULL == data) || (size == 0)) { 78bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGE("No ADTS to validate"); 79bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi return false; 80bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 81bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 82bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi while (offset < size) { 83bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi if ((frameSize = getAdtsFrameSize((uint8_t *)data, offset, size)) == 0) { 84bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGE("found ADTS frame of size 0 at offset %llu", offset); 85bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi return false; 86bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 87bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi //SL_LOGV("last good offset %llu", offset); 88bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi offset += frameSize; 89bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi if (offset > size) { 90bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGE("found incomplete ADTS frame at end of data"); 91bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi return false; 92bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 93bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 94bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi if (offset != size) { SL_LOGE("ADTS parsing error: reached end of incomplete frame"); } 95bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi assert(offset == size); 96bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi return true; 97bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi} 98bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 99bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi//-------------------------------------------------------------------------------------------------- 100bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel TriviAacBqToPcmCbRenderer::AacBqToPcmCbRenderer(AudioPlayback_Parameters* params) : 101bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi AudioToCbRenderer(params), 102bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mBqSource(0) 103bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi{ 104bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGD("AacBqToPcmCbRenderer::AacBqToPcmCbRenderer()"); 105bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 106bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi} 107bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 108bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 109bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel TriviAacBqToPcmCbRenderer::~AacBqToPcmCbRenderer() { 110bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGD("AacBqToPcmCbRenderer::~AacBqToPcmCbRenderer()"); 111bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 112bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi} 113bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 114bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 115bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi//-------------------------------------------------- 116bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivivoid AacBqToPcmCbRenderer::registerSourceQueueCallback( 117bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi const void* user, void *context, const void *caller) { 118bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGD("AacBqToPcmCbRenderer::registerQueueCallback"); 119bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 120bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi Mutex::Autolock _l(mBqSourceLock); 121bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 122bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mBqSource = new BufferQueueSource(user, context, caller); 123bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 124bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi CHECK(mBqSource != 0); 125bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGD("AacBqToPcmCbRenderer::registerSourceQueueCallback end"); 126bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi} 127bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 128bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 129bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi//-------------------------------------------------- 130bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi// Event handlers 131bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivivoid AacBqToPcmCbRenderer::onPrepare() { 132bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGD("AacBqToPcmCbRenderer::onPrepare()"); 133bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi Mutex::Autolock _l(mBufferSourceLock); 134bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 135bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi // Initialize the PCM format info with the known parameters before the start of the decode 136bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi { 137bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi android::Mutex::Autolock autoLock(mPcmFormatLock); 138bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_BITSPERSAMPLE] = SL_PCMSAMPLEFORMAT_FIXED_16; 139bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_CONTAINERSIZE] = 16; 140bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi //FIXME not true on all platforms 141bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_ENDIANNESS] = SL_BYTEORDER_LITTLEENDIAN; 142bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_CHANNELMASK] = 0; 143bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi // initialization with the default values: they will be replaced by the actual values 144bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi // once the decoder has figured them out 145bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_NUMCHANNELS] = mChannelCount; 146bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_SAMPLESPERSEC] = mSampleRateHz; 147bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 148bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 149bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi sp<DataSource> dataSource; 150bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi { 151bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi Mutex::Autolock _l(mBqSourceLock); 152bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi dataSource = mBqSource; 153bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 154bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi if (dataSource == 0) { 155bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGE("AacBqToPcmCbRenderer::onPrepare(): Error no data source"); 156bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi notifyPrepared(MEDIA_ERROR_BASE); 157bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi return; 158bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 159bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 160bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi sp<MediaExtractor> extractor = new AacAdtsExtractor(dataSource); 161bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi if (extractor == 0) { 162bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGE("AacBqToPcmCbRenderer::onPrepare: Could not instantiate AAC extractor."); 163bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi notifyPrepared(ERROR_UNSUPPORTED); 164bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi return; 165bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 166bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 167bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi // only decoding a single track of data 168bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi const size_t kTrackToDecode = 0; 169bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 170bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi sp<MediaSource> source = extractor->getTrack(kTrackToDecode); 171bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi if (source == 0) { 172bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGE("AacBqToPcmCbRenderer::onPrepare: error getting source from extractor"); 173bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi notifyPrepared(ERROR_UNSUPPORTED); 174bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi return; 175bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 176bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi sp<MetaData> meta = extractor->getTrackMetaData(kTrackToDecode); 177bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 178bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi // the audio content is not raw PCM, so we need a decoder 179bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi OMXClient client; 180bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi CHECK_EQ(client.connect(), (status_t)OK); 181bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 182bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi source = OMXCodec::Create( 183bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi client.interface(), meta, false /* createEncoder */, 184bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi source); 185bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 186bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi if (source == NULL) { 187bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGE("AudioSfDecoder::onPrepare: Could not instantiate decoder."); 188bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi notifyPrepared(ERROR_UNSUPPORTED); 189bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi return; 190bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 191bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 192bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi meta = source->getFormat(); 193bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 194bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGD("AacBqToPcmCbRenderer::onPrepare() after instantiating decoder"); 195bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 196bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi if (source->start() != OK) { 197bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGE("AacBqToPcmCbRenderer::onPrepare() Failed to start source/decoder."); 198bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi notifyPrepared(MEDIA_ERROR_BASE); 199bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi return; 200bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 201bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 202bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi //--------------------------------- 203bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi CHECK(meta->findInt32(kKeyChannelCount, &mChannelCount)); 204bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi int32_t sr; 205bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi CHECK(meta->findInt32(kKeySampleRate, &sr)); 206bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mSampleRateHz = (uint32_t) sr; 207bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi { 208bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi android::Mutex::Autolock autoLock(mPcmFormatLock); 209bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_SAMPLESPERSEC] = mSampleRateHz; 210bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_NUMCHANNELS] = mChannelCount; 211bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 212bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGV("AacBqToPcmCbRenderer::onPrepare() channel count=%d SR=%d", 213bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mChannelCount, mSampleRateHz); 214bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 215bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi //--------------------------------- 216bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi // The data source, and audio source (a decoder) are ready to be used 217bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mDataSource = dataSource; 218bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mAudioSource = source; 219bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mAudioSourceStarted = true; 220bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 221bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi //------------------------------------- 222bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi // signal successful completion of prepare 223bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mStateFlags |= kFlagPrepared; 224bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 225bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi GenericPlayer::onPrepare(); 226bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 227bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGD("AacBqToPcmCbRenderer::onPrepare() done, mStateFlags=0x%x", mStateFlags); 228bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi} 229bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 230bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi} // namespace android 231