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