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