CAudioPlayer.c revision 13837cf3f7be0eb8b1a9552bd99a89f98c987720
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 24SLresult CAudioPlayer_Realize(void *self, SLboolean async) 25{ 26 CAudioPlayer *thiz = (CAudioPlayer *) self; 27 SLresult result = SL_RESULT_SUCCESS; 28 29#ifdef ANDROID 30 result = android_audioPlayer_realize(thiz, async); 31#endif 32 33#ifdef USE_SNDFILE 34 result = SndFile_Realize(thiz); 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 47SLresult 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 55void CAudioPlayer_Destroy(void *self) 56{ 57 CAudioPlayer *thiz = (CAudioPlayer *) self; 58#ifdef ANDROID 59 android_audioPlayer_destroy(thiz); 60#endif 61 freeDataLocatorFormat(&thiz->mDataSource); 62 freeDataLocatorFormat(&thiz->mDataSink); 63#ifdef USE_SNDFILE 64 SndFile_Destroy(thiz); 65#endif 66} 67 68 69/** \brief Hook called by Object::Destroy before an audio player is about to be destroyed */ 70 71predestroy_t CAudioPlayer_PreDestroy(void *self) 72{ 73#ifdef USE_OUTPUTMIXEXT 74 CAudioPlayer *thiz = (CAudioPlayer *) self; 75 // Safe to proceed immediately if a track has not yet been assigned 76 Track *track = thiz->mTrack; 77 if (NULL == track) { 78 return predestroy_ok; 79 } 80 CAudioPlayer *audioPlayer = track->mAudioPlayer; 81 if (NULL == audioPlayer) { 82 return predestroy_ok; 83 } 84 assert(audioPlayer == thiz); 85 // Request the mixer thread to unlink this audio player's track 86 thiz->mDestroyRequested = true; 87 while (thiz->mDestroyRequested) { 88 object_cond_wait(self); 89 } 90 // Mixer thread has acknowledged the request 91#endif 92 return predestroy_ok; 93} 94 95 96/** \brief Given an audio player, return its data sink, which is guaranteed to be a non-NULL output 97 * mix. This function is used by effect send. 98 */ 99 100COutputMix *CAudioPlayer_GetOutputMix(CAudioPlayer *audioPlayer) 101{ 102 assert(NULL != audioPlayer); 103 assert(SL_DATALOCATOR_OUTPUTMIX == audioPlayer->mDataSink.mLocator.mLocatorType); 104 SLObjectItf outputMix = audioPlayer->mDataSink.mLocator.mOutputMix.outputMix; 105 assert(NULL != outputMix); 106 return (COutputMix *) outputMix; 107} 108