android_AudioToCbRenderer.cpp revision 2b06e20ae32388f6e1dfd088d9773c34e6b1cb45
1/* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17//#define USE_LOG SLAndroidLogLevel_Verbose 18 19#include "sles_allinclusive.h" 20#include "android/android_AudioToCbRenderer.h" 21 22namespace android { 23 24//-------------------------------------------------------------------------------------------------- 25AudioToCbRenderer::AudioToCbRenderer(AudioPlayback_Parameters* params) : AudioSfDecoder(params), 26 mDecodeCbf(NULL), 27 mDecodeUser(NULL) 28{ 29 SL_LOGD("AudioToCbRenderer::AudioToCbRenderer()"); 30 31} 32 33 34AudioToCbRenderer::~AudioToCbRenderer() { 35 SL_LOGD("AudioToCbRenderer::~AudioToCbRenderer()"); 36 37} 38 39void AudioToCbRenderer::setDataPushListener(const data_push_cbf_t pushCbf, void* pushUser) { 40 mDecodeCbf = pushCbf; 41 mDecodeUser = pushUser; 42} 43 44//-------------------------------------------------- 45// Event handlers 46void AudioToCbRenderer::onPrepare() { 47 SL_LOGD("AudioToCbRenderer::onPrepare()"); 48 AudioSfDecoder::onPrepare(); 49 SL_LOGD("AudioToCbRenderer::onPrepare() done, mStateFlags=0x%x", mStateFlags); 50} 51 52 53void AudioToCbRenderer::onRender() { 54 SL_LOGV("AudioToCbRenderer::onRender"); 55 56 Mutex::Autolock _l(mDecodeBufferLock); 57 58 if (NULL == mDecodeBuffer) { 59 // nothing to render, move along 60 //SL_LOGV("AudioToCbRenderer::onRender NULL buffer, exiting"); 61 return; 62 } 63 64 if (mStateFlags & kFlagPlaying) { 65 if (NULL != mDecodeCbf) { 66 size_t full = mDecodeBuffer->range_length(); 67 size_t consumed = 0; 68 size_t offset = 0; 69 while (offset < full) { 70 consumed = mDecodeCbf( 71 (const uint8_t *)mDecodeBuffer->data() 72 + offset + mDecodeBuffer->range_offset(), 73 mDecodeBuffer->range_length() - offset, 74 mDecodeUser); 75 offset += consumed; 76 //SL_LOGV("consumed=%lu, offset=%lu, full=%lu", consumed, offset, full); 77 if (consumed == 0) { 78 // decoded data is not being consumed, skip this buffer 79 break; 80 } 81 } 82 } 83 (new AMessage(kWhatDecode, id()))->post(); 84 } 85 86 mDecodeBuffer->release(); 87 mDecodeBuffer = NULL; 88} 89 90 91//-------------------------------------------------- 92// Audio output 93void AudioToCbRenderer::createAudioSink() { 94 SL_LOGD("AudioToCbRenderer::createAudioSink()"); 95 SL_LOGV("sample rate = %d nb channels = %d", mSampleRateHz, mNumChannels); 96} 97 98 99void AudioToCbRenderer::updateAudioSink() { 100 SL_LOGD("AudioToCbRenderer::updateAudioSink()"); 101 if (mAudioSource != 0) { 102 sp<MetaData> meta = mAudioSource->getFormat(); 103 104 SL_LOGV("old sample rate = %d", mSampleRateHz); 105 CHECK(meta->findInt32(kKeyChannelCount, &mNumChannels)); 106 CHECK(meta->findInt32(kKeySampleRate, &mSampleRateHz)); 107 SL_LOGV("new sample rate = %d", mSampleRateHz); 108 109 } 110} 111 112 113void AudioToCbRenderer::startAudioSink() { 114 SL_LOGD("AudioToCbRenderer::startAudioSink()"); 115} 116 117 118void AudioToCbRenderer::pauseAudioSink() { 119 SL_LOGD("AudioToCbRenderer::pauseAudioSink()"); 120} 121 122} // namespace android 123