AacBqToPcmCbRenderer.cpp revision b4393ef4ef3edb785746c37fd7b68950e85283ae
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 58145156a92c1d379e494cb69920d49b87f9c0e300Glenn Kasten 59145156a92c1d379e494cb69920d49b87f9c0e300Glenn Kasten // protectionAbsent is 0 if there is CRC 60145156a92c1d379e494cb69920d49b87f9c0e300Glenn Kasten static const size_t kAdtsHeaderLengthNoCrc = 7; 61145156a92c1d379e494cb69920d49b87f9c0e300Glenn Kasten static const size_t kAdtsHeaderLengthWithCrc = 9; 62145156a92c1d379e494cb69920d49b87f9c0e300Glenn Kasten size_t headSize = protectionAbsent ? kAdtsHeaderLengthNoCrc : kAdtsHeaderLengthWithCrc; 63145156a92c1d379e494cb69920d49b87f9c0e300Glenn Kasten if (headSize > frameSize) { 64145156a92c1d379e494cb69920d49b87f9c0e300Glenn Kasten SL_LOGE("AacBqToPcmCbRenderer::getAdtsFrameSize() returns 0 (frameSize %u < headSize %u)", 65145156a92c1d379e494cb69920d49b87f9c0e300Glenn Kasten frameSize, headSize); 66145156a92c1d379e494cb69920d49b87f9c0e300Glenn Kasten return 0; 67145156a92c1d379e494cb69920d49b87f9c0e300Glenn Kasten } 68bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 69bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGV("AacBqToPcmCbRenderer::getAdtsFrameSize() returns %u", frameSize); 70bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 71bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi return frameSize; 72bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi} 73bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 74bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi/** 75bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * Returns whether a block of memory starts and ends on AAC ADTS frame boundaries 76bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * @param data pointer to the compressed audio data 77bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * @param size the size in bytes of the data block to validate 78677c76347d9aaca4cf3746b3dbfc8a741281066bGlenn Kasten * @return SL_RESULT_SUCCESS if there is AAC ADTS data, and it starts and ends on frame boundaries, 79677c76347d9aaca4cf3746b3dbfc8a741281066bGlenn Kasten * or an appropriate error code otherwise: 80677c76347d9aaca4cf3746b3dbfc8a741281066bGlenn Kasten * SL_RESULT_PARAMETER_INVALID if not possible to attempt validation of even one frame 81677c76347d9aaca4cf3746b3dbfc8a741281066bGlenn Kasten * SL_RESULT_CONTENT_CORRUPTED if the frame contents are otherwise invalid 82bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi */ 83677c76347d9aaca4cf3746b3dbfc8a741281066bGlenn KastenSLresult AacBqToPcmCbRenderer::validateBufferStartEndOnFrameBoundaries(void* data, size_t size) 84bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi{ 85bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi off64_t offset = 0; 86bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi size_t frameSize = 0; 87bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 88bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi if ((NULL == data) || (size == 0)) { 89bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGE("No ADTS to validate"); 90677c76347d9aaca4cf3746b3dbfc8a741281066bGlenn Kasten return SL_RESULT_PARAMETER_INVALID; 91bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 92bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 93bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi while (offset < size) { 94bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi if ((frameSize = getAdtsFrameSize((uint8_t *)data, offset, size)) == 0) { 95bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGE("found ADTS frame of size 0 at offset %llu", offset); 96677c76347d9aaca4cf3746b3dbfc8a741281066bGlenn Kasten return SL_RESULT_CONTENT_CORRUPTED; 97bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 98bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi //SL_LOGV("last good offset %llu", offset); 99bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi offset += frameSize; 100bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi if (offset > size) { 101bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGE("found incomplete ADTS frame at end of data"); 102677c76347d9aaca4cf3746b3dbfc8a741281066bGlenn Kasten return SL_RESULT_CONTENT_CORRUPTED; 103bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 104bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 105bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi if (offset != size) { SL_LOGE("ADTS parsing error: reached end of incomplete frame"); } 106bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi assert(offset == size); 107677c76347d9aaca4cf3746b3dbfc8a741281066bGlenn Kasten return SL_RESULT_SUCCESS; 108bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi} 109bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 110bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi//-------------------------------------------------------------------------------------------------- 111bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel TriviAacBqToPcmCbRenderer::AacBqToPcmCbRenderer(AudioPlayback_Parameters* params) : 112bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi AudioToCbRenderer(params), 113bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mBqSource(0) 114bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi{ 115bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGD("AacBqToPcmCbRenderer::AacBqToPcmCbRenderer()"); 116bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 117bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi} 118bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 119bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 120bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel TriviAacBqToPcmCbRenderer::~AacBqToPcmCbRenderer() { 121bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGD("AacBqToPcmCbRenderer::~AacBqToPcmCbRenderer()"); 122bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 123bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi} 124bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 125bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 126bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi//-------------------------------------------------- 127bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivivoid AacBqToPcmCbRenderer::registerSourceQueueCallback( 128bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi const void* user, void *context, const void *caller) { 129bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGD("AacBqToPcmCbRenderer::registerQueueCallback"); 130bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 131bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi Mutex::Autolock _l(mBqSourceLock); 132bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 133bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mBqSource = new BufferQueueSource(user, context, caller); 134bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 135bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi CHECK(mBqSource != 0); 136bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGD("AacBqToPcmCbRenderer::registerSourceQueueCallback end"); 137bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi} 138bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 139bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 140bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi//-------------------------------------------------- 141bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi// Event handlers 142bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivivoid AacBqToPcmCbRenderer::onPrepare() { 143bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGD("AacBqToPcmCbRenderer::onPrepare()"); 144bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi Mutex::Autolock _l(mBufferSourceLock); 145bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 146bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi // Initialize the PCM format info with the known parameters before the start of the decode 147bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi { 148bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi android::Mutex::Autolock autoLock(mPcmFormatLock); 149bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_BITSPERSAMPLE] = SL_PCMSAMPLEFORMAT_FIXED_16; 150bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_CONTAINERSIZE] = 16; 151bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi //FIXME not true on all platforms 152bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_ENDIANNESS] = SL_BYTEORDER_LITTLEENDIAN; 153bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi // initialization with the default values: they will be replaced by the actual values 154bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi // once the decoder has figured them out 155b4393ef4ef3edb785746c37fd7b68950e85283aeGlenn Kasten mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_NUMCHANNELS] = UNKNOWN_NUMCHANNELS; 156b4393ef4ef3edb785746c37fd7b68950e85283aeGlenn Kasten mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_SAMPLERATE] = UNKNOWN_SAMPLERATE; 157b4393ef4ef3edb785746c37fd7b68950e85283aeGlenn Kasten mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_CHANNELMASK] = UNKNOWN_CHANNELMASK; 158bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 159bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 160bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi sp<DataSource> dataSource; 161bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi { 162bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi Mutex::Autolock _l(mBqSourceLock); 163bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi dataSource = mBqSource; 164bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 165bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi if (dataSource == 0) { 166bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGE("AacBqToPcmCbRenderer::onPrepare(): Error no data source"); 167bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi notifyPrepared(MEDIA_ERROR_BASE); 168bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi return; 169bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 170bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 171bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi sp<MediaExtractor> extractor = new AacAdtsExtractor(dataSource); 172bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi if (extractor == 0) { 173bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGE("AacBqToPcmCbRenderer::onPrepare: Could not instantiate AAC extractor."); 174bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi notifyPrepared(ERROR_UNSUPPORTED); 175bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi return; 176bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 177bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 178bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi // only decoding a single track of data 179bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi const size_t kTrackToDecode = 0; 180bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 181bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi sp<MediaSource> source = extractor->getTrack(kTrackToDecode); 182bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi if (source == 0) { 183bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGE("AacBqToPcmCbRenderer::onPrepare: error getting source from extractor"); 184bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi notifyPrepared(ERROR_UNSUPPORTED); 185bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi return; 186bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 187bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi sp<MetaData> meta = extractor->getTrackMetaData(kTrackToDecode); 188bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 189bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi // the audio content is not raw PCM, so we need a decoder 190bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi OMXClient client; 191bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi CHECK_EQ(client.connect(), (status_t)OK); 192bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 193bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi source = OMXCodec::Create( 194bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi client.interface(), meta, false /* createEncoder */, 195bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi source); 196bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 197bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi if (source == NULL) { 198377c6471dbefd6251c11d9c5633193cd57598991Glenn Kasten SL_LOGE("AacBqToPcmCbRenderer::onPrepare: Could not instantiate decoder."); 199bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi notifyPrepared(ERROR_UNSUPPORTED); 200bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi return; 201bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 202bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 203bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi meta = source->getFormat(); 204bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 205bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGD("AacBqToPcmCbRenderer::onPrepare() after instantiating decoder"); 206bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 207bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi if (source->start() != OK) { 208bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGE("AacBqToPcmCbRenderer::onPrepare() Failed to start source/decoder."); 209bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi notifyPrepared(MEDIA_ERROR_BASE); 210bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi return; 211bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 212bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 213bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi //--------------------------------- 214b4393ef4ef3edb785746c37fd7b68950e85283aeGlenn Kasten int32_t channelCount; 215b4393ef4ef3edb785746c37fd7b68950e85283aeGlenn Kasten CHECK(meta->findInt32(kKeyChannelCount, &channelCount)); 216bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi int32_t sr; 217bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi CHECK(meta->findInt32(kKeySampleRate, &sr)); 21820d9a1229c7647dd2c6f1bece715080ec6202ecaGlenn Kasten // FIXME similar to AudioSfDecoder::onPrepare() 21920d9a1229c7647dd2c6f1bece715080ec6202ecaGlenn Kasten 220457b9394608d48020d156e9525354b421f8f3e08Glenn Kasten // already "good to go" (compare to AudioSfDecoder::onPrepare) 221457b9394608d48020d156e9525354b421f8f3e08Glenn Kasten mCacheStatus = kStatusHigh; 222457b9394608d48020d156e9525354b421f8f3e08Glenn Kasten mCacheFill = 1000; 223457b9394608d48020d156e9525354b421f8f3e08Glenn Kasten notifyStatus(); 224457b9394608d48020d156e9525354b421f8f3e08Glenn Kasten notifyCacheFill(); 225457b9394608d48020d156e9525354b421f8f3e08Glenn Kasten 226bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi { 227b4393ef4ef3edb785746c37fd7b68950e85283aeGlenn Kasten android::Mutex::Autolock autoLock(mPcmFormatLock); 228b4393ef4ef3edb785746c37fd7b68950e85283aeGlenn Kasten mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_SAMPLERATE] = sr; 229b4393ef4ef3edb785746c37fd7b68950e85283aeGlenn Kasten mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_NUMCHANNELS] = channelCount; 230b4393ef4ef3edb785746c37fd7b68950e85283aeGlenn Kasten mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_CHANNELMASK] = 231b4393ef4ef3edb785746c37fd7b68950e85283aeGlenn Kasten channelCountToMask(channelCount); 232bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi } 233bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGV("AacBqToPcmCbRenderer::onPrepare() channel count=%d SR=%d", 234b4393ef4ef3edb785746c37fd7b68950e85283aeGlenn Kasten channelCount, sr); 235bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 236bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi //--------------------------------- 237bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi // The data source, and audio source (a decoder) are ready to be used 238bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mDataSource = dataSource; 239bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mAudioSource = source; 240bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mAudioSourceStarted = true; 241bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 242bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi //------------------------------------- 243bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi // signal successful completion of prepare 244bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi mStateFlags |= kFlagPrepared; 245bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 246bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi GenericPlayer::onPrepare(); 247bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 248bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi SL_LOGD("AacBqToPcmCbRenderer::onPrepare() done, mStateFlags=0x%x", mStateFlags); 249bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi} 250bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 251bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi} // namespace android 252