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 22 #include <media/stagefright/foundation/ADebug.h> 23 24 namespace android { 25 26 //-------------------------------------------------------------------------------------------------- 27 AudioToCbRenderer::AudioToCbRenderer(AudioPlayback_Parameters* params) : AudioSfDecoder(params), 28 mDecodeCbf(NULL), 29 mDecodeUser(NULL) 30 { 31 SL_LOGD("AudioToCbRenderer::AudioToCbRenderer()"); 32 33 } 34 35 36 AudioToCbRenderer::~AudioToCbRenderer() { 37 SL_LOGD("AudioToCbRenderer::~AudioToCbRenderer()"); 38 39 } 40 41 void AudioToCbRenderer::setDataPushListener(const data_push_cbf_t pushCbf, CAudioPlayer* pushUser) { 42 mDecodeCbf = pushCbf; 43 mDecodeUser = pushUser; 44 } 45 46 //-------------------------------------------------- 47 // Event handlers 48 49 void AudioToCbRenderer::onRender() { 50 SL_LOGV("AudioToCbRenderer::onRender"); 51 52 Mutex::Autolock _l(mBufferSourceLock); 53 54 if (NULL == mDecodeBuffer) { 55 // nothing to render, move along 56 //SL_LOGV("AudioToCbRenderer::onRender NULL buffer, exiting"); 57 return; 58 } 59 60 if (mStateFlags & kFlagPlaying) { 61 if (NULL != mDecodeCbf) { 62 size_t full = mDecodeBuffer->range_length(); 63 size_t consumed = 0; 64 size_t offset = 0; 65 while (offset < full) { 66 consumed = mDecodeCbf( 67 (const uint8_t *)mDecodeBuffer->data() 68 + offset + mDecodeBuffer->range_offset(), 69 mDecodeBuffer->range_length() - offset, 70 mDecodeUser); 71 offset += consumed; 72 //SL_LOGV("consumed=%u, offset=%u, full=%u", consumed, offset, full); 73 if (consumed == 0) { 74 // decoded data is not being consumed, skip this buffer 75 break; 76 } 77 } 78 } 79 (new AMessage(kWhatDecode, id()))->post(); 80 } 81 82 mDecodeBuffer->release(); 83 mDecodeBuffer = NULL; 84 85 updateOneShot(); 86 } 87 88 89 //-------------------------------------------------- 90 // Audio output 91 void AudioToCbRenderer::createAudioSink() { 92 SL_LOGD("AudioToCbRenderer::createAudioSink()"); 93 } 94 95 96 void AudioToCbRenderer::updateAudioSink() { 97 SL_LOGD("AudioToCbRenderer::updateAudioSink()"); 98 } 99 100 101 void AudioToCbRenderer::startAudioSink() { 102 SL_LOGD("AudioToCbRenderer::startAudioSink()"); 103 } 104 105 106 void AudioToCbRenderer::pauseAudioSink() { 107 SL_LOGD("AudioToCbRenderer::pauseAudioSink()"); 108 } 109 110 } // namespace android 111