1 /* 2 * Copyright (C) 2010 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 /** \file CAudioPlayer.c AudioPlayer class */ 18 19 #include "sles_allinclusive.h" 20 21 22 /** \brief Hook called by Object::Realize when an audio player is realized */ 23 24 SLresult CAudioPlayer_Realize(void *self, SLboolean async) 25 { 26 CAudioPlayer *this = (CAudioPlayer *) self; 27 SLresult result = SL_RESULT_SUCCESS; 28 29 #ifdef ANDROID 30 result = android_audioPlayer_realize(this, async); 31 #endif 32 33 #ifdef USE_SNDFILE 34 result = SndFile_Realize(this); 35 #endif 36 37 // At this point the channel count and sample rate might still be unknown, 38 // depending on the data source and the platform implementation. 39 // If they are unknown here, then they will be determined during prefetch. 40 41 return result; 42 } 43 44 45 /** \brief Hook called by Object::Resume when an audio player is resumed */ 46 47 SLresult CAudioPlayer_Resume(void *self, SLboolean async) 48 { 49 return SL_RESULT_SUCCESS; 50 } 51 52 53 /** \brief Hook called by Object::Destroy when an audio player is destroyed */ 54 55 void CAudioPlayer_Destroy(void *self) 56 { 57 CAudioPlayer *this = (CAudioPlayer *) self; 58 freeDataLocatorFormat(&this->mDataSource); 59 freeDataLocatorFormat(&this->mDataSink); 60 #ifdef USE_SNDFILE 61 SndFile_Destroy(this); 62 #endif 63 #ifdef ANDROID 64 android_audioPlayer_destroy(this); 65 #endif 66 } 67 68 69 /** \brief Hook called by Object::Destroy before an audio player is about to be destroyed */ 70 71 bool CAudioPlayer_PreDestroy(void *self) 72 { 73 #ifdef USE_OUTPUTMIXEXT 74 CAudioPlayer *this = (CAudioPlayer *) self; 75 // Safe to proceed immediately if a track has not yet been assigned 76 Track *track = this->mTrack; 77 if (NULL == track) 78 return true; 79 CAudioPlayer *audioPlayer = track->mAudioPlayer; 80 if (NULL == audioPlayer) 81 return true; 82 assert(audioPlayer == this); 83 // Request the mixer thread to unlink this audio player's track 84 this->mDestroyRequested = true; 85 while (this->mDestroyRequested) { 86 object_cond_wait(self); 87 } 88 // Mixer thread has acknowledged the request 89 #endif 90 return true; 91 } 92 93 94 /** \brief Given an audio player, return its data sink, which is guaranteed to be a non-NULL output 95 * mix. This function is used by effect send. 96 */ 97 98 COutputMix *CAudioPlayer_GetOutputMix(CAudioPlayer *audioPlayer) 99 { 100 assert(NULL != audioPlayer); 101 assert(SL_DATALOCATOR_OUTPUTMIX == audioPlayer->mDataSink.mLocator.mLocatorType); 102 SLObjectItf outputMix = audioPlayer->mDataSink.mLocator.mOutputMix.outputMix; 103 assert(NULL != outputMix); 104 return (COutputMix *) outputMix; 105 } 106