Lines Matching refs:ap

52 inline void audioManagerPlayerEvent(CAudioPlayer* ap, android::player_state_t event) {
53 if (ap->mObject.mEngine->mAudioManager != 0) {
54 ap->mObject.mEngine->mAudioManager->playerEvent(ap->mPIId, event);
86 SLresult aplayer_setPlayState(const android::sp<android::GenericPlayer> &ap, SLuint32 playState,
94 ap->stop();
101 ap->prepare();
106 ap->pause();
119 ap->prepare();
124 ap->play();
147 static size_t adecoder_writeToBufferQueue(const uint8_t *data, size_t size, CAudioPlayer* ap) {
148 if (!android::CallbackProtector::enterCbIfOk(ap->mCallbackProtector)) {
158 object_lock_exclusive(&ap->mObject);
160 if (ap->mBufferQueue.mState.count != 0) {
161 assert(ap->mBufferQueue.mFront != ap->mBufferQueue.mRear);
163 BufferHeader *oldFront = ap->mBufferQueue.mFront;
166 uint8_t *pDest = (uint8_t *)oldFront->mBuffer + ap->mBufferQueue.mSizeConsumed;
167 if (ap->mBufferQueue.mSizeConsumed + size < oldFront->mSize) {
169 ap->mBufferQueue.mSizeConsumed += size;
175 sizeConsumed = oldFront->mSize - ap->mBufferQueue.mSizeConsumed;
178 ap->mBufferQueue.mSizeConsumed = 0;
179 if (newFront == &ap->mBufferQueue.mArray[ap->mBufferQueue.mNumBuffers + 1]) {
180 newFront = ap->mBufferQueue.mArray;
182 ap->mBufferQueue.mFront = newFront;
184 ap->mBufferQueue.mState.count--;
185 ap->mBufferQueue.mState.playIndex++;
190 callback = ap->mBufferQueue.mCallback;
192 callbackPContext = ap->mBufferQueue.mContext;
200 object_unlock_exclusive(&ap->mObject);
203 (*callback)(&ap->mBufferQueue.mItf, callbackPContext);
206 ap->mCallbackProtector->exitCb();
215 void android_audioPlayer_volumeUpdate(CAudioPlayer* ap)
217 assert(ap != NULL);
220 SLuint8 channelCount = ap->mNumChannels;
227 if (ap->mMuteMask & LEFT_CHANNEL_MASK) {
232 if (ap->mSoloMask & LEFT_CHANNEL_MASK) {
237 if (ap->mSoloMask & RIGHT_CHANNEL_MASK) {
247 if (ap->mMuteMask & RIGHT_CHANNEL_MASK) {
252 if (ap->mSoloMask & RIGHT_CHANNEL_MASK) {
257 if (ap->mSoloMask & LEFT_CHANNEL_MASK) {
276 android_player_volumeUpdate(volumes, &ap->mVolume, channelCount, ap->mAmplFromDirectLevel,
281 if (ap->mAPlayer != 0) {
282 ap->mAPlayer->setVolume(leftVol, rightVol);
283 } else if (ap->mTrackPlayer != 0) {
284 ap->mTrackPlayer->setPlayerVolume(leftVol, rightVol);
290 if (NULL != ap->mEffectSend.mItf) {
292 if (ap->mEffectSend.mEnableLevels[i].mEnable) {
293 android_fxSend_setSendLevel(ap,
294 ap->mEffectSend.mEnableLevels[i].mSendLevel + ap->mVolume.mLevel);
300 } else if (NULL != ap->mAndroidEffectSend.mItf) {
301 android_fxSend_setSendLevel(ap, ap->mAndroidEffectSend.mSendLevel + ap->mVolume.mLevel);
381 void audioTrack_handleMarker_lockPlay(CAudioPlayer* ap) {
386 interface_lock_shared(&ap->mPlay);
387 callback = ap->mPlay.mCallback;
388 callbackPContext = ap->mPlay.mContext;
389 interface_unlock_shared(&ap->mPlay);
393 (*callback)(&ap->mPlay.mItf, callbackPContext, SL_PLAYEVENT_HEADATMARKER);
398 void audioTrack_handleNewPos_lockPlay(CAudioPlayer* ap) {
403 interface_lock_shared(&ap->mPlay);
404 callback = ap->mPlay.mCallback;
405 callbackPContext = ap->mPlay.mContext;
406 interface_unlock_shared(&ap->mPlay);
410 (*callback)(&ap->mPlay.mItf, callbackPContext, SL_PLAYEVENT_HEADATNEWPOS);
416 void audioTrack_handleUnderrun_lockPlay(CAudioPlayer* ap) {
420 interface_lock_shared(&ap->mPlay);
421 callback = ap->mPlay.mCallback;
422 callbackPContext = ap->mPlay.mContext;
423 bool headStalled = (ap->mPlay.mEventFlags & SL_PLAYEVENT_HEADSTALLED) != 0;
424 interface_unlock_shared(&ap->mPlay);
427 (*callback)(&ap->mPlay.mItf, callbackPContext, SL_PLAYEVENT_HEADSTALLED);
446 void audioPlayer_dispatch_headAtEnd_lockPlay(CAudioPlayer *ap, bool setPlayStateToPaused,
448 //SL_LOGV("ap=%p, setPlayStateToPaused=%d, needToLock=%d", ap, setPlayStateToPaused,
454 interface_lock_exclusive(&ap->mPlay);
456 if (ap->mPlay.mEventFlags & SL_PLAYEVENT_HEADATEND) {
457 playCallback = ap->mPlay.mCallback;
458 playContext = ap->mPlay.mContext;
461 ap->mPlay.mState = SL_PLAYSTATE_PAUSED;
464 interface_unlock_exclusive(&ap->mPlay);
469 (*playCallback)(&ap->mPlay.mItf, playContext, SL_PLAYEVENT_HEADATEND);
471 SLresult result = EnqueueAsyncCallback_ppi(ap, playCallback, &ap->mPlay.mItf, playContext,
475 &ap->mPlay.mItf, playContext);
484 SLresult audioPlayer_setStreamType(CAudioPlayer* ap, SLint32 type) {
515 // (ap->mTrackPlayer->mAudioTrack is supposed to be NULL until then)
516 if (SL_OBJECT_STATE_UNREALIZED != ap->mObject.mState) {
520 ap->mStreamType = newStreamType;
527 SLresult audioPlayer_setPerformanceMode(CAudioPlayer* ap, SLuint32 mode) {
552 // (ap->mTrackPlayer->mAudioTrack is supposed to be NULL until then)
553 if (SL_OBJECT_STATE_UNREALIZED != ap->mObject.mState) {
557 ap->mPerformanceMode = perfMode;
564 SLresult audioPlayer_getStreamType(CAudioPlayer* ap, SLint32 *pType) {
567 switch (ap->mStreamType) {
597 SLresult audioPlayer_getPerformanceMode(CAudioPlayer* ap, SLuint32 *pMode) {
600 switch (ap->mPerformanceMode) {
623 void audioPlayer_auxEffectUpdate(CAudioPlayer* ap) {
624 if ((ap->mTrackPlayer->mAudioTrack != 0) && (ap->mAuxEffect != 0)) {
625 android_fxSend_attach(ap, true, ap->mAuxEffect, ap->mVolume.mLevel + ap->mAuxSendLevel);
671 AndroidObjectType audioPlayer_getAndroidObjectTypeForSourceSink(const CAudioPlayer *ap) {
673 const SLDataSource *pAudioSrc = &ap->mDataSource.u.mSource;
674 const SLDataSink *pAudioSnk = &ap->mDataSink.u.mSink;
766 CAudioPlayer *ap = (CAudioPlayer *)user;
767 if (!android::CallbackProtector::enterCbIfOk(ap->mCallbackProtector)) {
781 SL_LOGV("Received GenericPlayer::kEventPrepared for CAudioPlayer %p", ap);
788 object_lock_exclusive(&ap->mObject);
791 assert(ap->mAndroidObjState == ANDROID_PREPARING);
792 ap->mAndroidObjState = ANDROID_READY;
795 // Most of successful prepare completion for ap->mAPlayer
803 if (IsInterfaceInitialized(&ap->mObject, MPH_PREFETCHSTATUS)) {
804 ap->mPrefetchStatus.mLevel = 0;
805 ap->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_UNDERFLOW;
806 if (!(~ap->mPrefetchStatus.mCallbackEventsMask &
808 callback = ap->mPrefetchStatus.mCallback;
809 callbackPContext = ap->mPrefetchStatus.mContext;
815 object_unlock_exclusive(&ap->mObject);
819 (*callback)(&ap->mPrefetchStatus.mItf, callbackPContext, events);
826 if (!IsInterfaceInitialized(&ap->mObject, MPH_PREFETCHSTATUS)) {
833 interface_lock_exclusive(&ap->mPrefetchStatus);
834 if (ap->mPrefetchStatus.mCallbackEventsMask & SL_PREFETCHEVENT_FILLLEVELCHANGE) {
835 callback = ap->mPrefetchStatus.mCallback;
836 callbackPContext = ap->mPrefetchStatus.mContext;
838 ap->mPrefetchStatus.mLevel = (SLpermille)data1;
839 interface_unlock_exclusive(&ap->mPrefetchStatus);
843 (*callback)(&ap->mPrefetchStatus.mItf, callbackPContext,
850 if (!IsInterfaceInitialized(&ap->mObject, MPH_PREFETCHSTATUS)) {
857 object_lock_exclusive(&ap->mObject);
858 if (ap->mPrefetchStatus.mCallbackEventsMask & SL_PREFETCHEVENT_STATUSCHANGE) {
859 callback = ap->mPrefetchStatus.mCallback;
860 callbackPContext = ap->mPrefetchStatus.mContext;
863 ap->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_SUFFICIENTDATA;
865 ap->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_UNDERFLOW;
867 object_unlock_exclusive(&ap->mObject);
871 (*callback)(&ap->mPrefetchStatus.mItf, callbackPContext, SL_PREFETCHEVENT_STATUSCHANGE);
877 audioPlayer_dispatch_headAtEnd_lockPlay(ap, true /*set state to paused?*/, true);
878 if ((ap->mTrackPlayer->mAudioTrack != 0) && (!ap->mSeek.mLoopEnabled)) {
879 ap->mTrackPlayer->mAudioTrack->stop();
881 ap->mTrackPlayer->reportEvent(android::PLAYER_STATE_STOPPED);
886 object_lock_exclusive(&ap->mObject);
887 if (UNKNOWN_NUMCHANNELS == ap->mNumChannels && UNKNOWN_NUMCHANNELS != data1) {
888 ap->mNumChannels = data1;
889 android_audioPlayer_volumeUpdate(ap);
891 object_unlock_exclusive(&ap->mObject);
899 interface_lock_shared(&ap->mPlay);
900 callback = ap->mPlay.mCallback;
901 callbackPContext = ap->mPlay.mContext;
902 interface_unlock_shared(&ap->mPlay);
908 (*callback)(&ap->mPlay.mItf, callbackPContext, event);
911 SLresult result = EnqueueAsyncCallback_ppi(ap, callback, &ap->mPlay.mItf,
915 &ap->mPlay.mItf, callbackPContext, event);
929 object_lock_exclusive(&ap->mObject);
930 if (IsInterfaceInitialized(&ap->mObject, MPH_PREFETCHSTATUS)) {
931 ap->mPrefetchStatus.mLevel = 0;
932 ap->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_UNDERFLOW;
933 if (!(~ap->mPrefetchStatus.mCallbackEventsMask &
935 callback = ap->mPrefetchStatus.mCallback;
936 callbackPContext = ap->mPrefetchStatus.mContext;
939 object_unlock_exclusive(&ap->mObject);
946 (*callback)(&ap->mPrefetchStatus.mItf, callbackPContext,
961 ap->mCallbackProtector->exitCb();
1235 CAudioPlayer *ap = (CAudioPlayer *)user;
1237 if (!android::CallbackProtector::enterCbIfOk(ap->mCallbackProtector)) {
1253 interface_lock_exclusive(&ap->mBufferQueue);
1255 if (ap->mBufferQueue.mCallbackPending) {
1257 slBufferQueueCallback callback = ap->mBufferQueue.mCallback;
1259 callbackPContext = ap->mBufferQueue.mContext;
1260 interface_unlock_exclusive(&ap->mBufferQueue);
1261 (*callback)(&ap->mBufferQueue.mItf, callbackPContext);
1262 interface_lock_exclusive(&ap->mBufferQueue);
1263 ap->mBufferQueue.mCallbackPending = false;
1267 if (ap->mBufferQueue.mState.count != 0) {
1268 //SL_LOGV("nbBuffers in queue = %u",ap->mBufferQueue.mState.count);
1269 assert(ap->mBufferQueue.mFront != ap->mBufferQueue.mRear);
1271 BufferHeader *oldFront = ap->mBufferQueue.mFront;
1274 size_t availSource = oldFront->mSize - ap->mBufferQueue.mSizeConsumed;
1277 void *pSrc = (char *)oldFront->mBuffer + ap->mBufferQueue.mSizeConsumed;
1281 ap->mBufferQueue.mSizeConsumed += bytesToCopy;
1286 ap->mBufferQueue.mSizeConsumed = 0;
1288 &ap->mBufferQueue.mArray
1289 [ap->mBufferQueue.mNumBuffers + 1])
1291 newFront = ap->mBufferQueue.mArray;
1293 ap->mBufferQueue.mFront = newFront;
1295 ap->mBufferQueue.mState.count--;
1296 ap->mBufferQueue.mState.playIndex++;
1297 ap->mBufferQueue.mCallbackPending = true;
1304 audioPlayer_dispatch_headAtEnd_lockPlay(ap, false /*set state to paused?*/, false);
1307 if (IsInterfaceInitialized(&ap->mObject, MPH_PREFETCHSTATUS)) {
1308 ap->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_UNDERFLOW;
1309 ap->mPrefetchStatus.mLevel = 0;
1311 prefetchEvents = ap->mPrefetchStatus.mCallbackEventsMask &
1314 prefetchCallback = ap->mPrefetchStatus.mCallback;
1315 prefetchContext = ap->mPrefetchStatus.mContext;
1320 ap->mTrackPlayer->stop();
1322 interface_unlock_exclusive(&ap->mBufferQueue);
1329 (*prefetchCallback)(&ap->mPrefetchStatus.mItf, prefetchContext,
1333 (*prefetchCallback)(&ap->mPrefetchStatus.mItf, prefetchContext,
1342 audioTrack_handleMarker_lockPlay(ap);
1347 audioTrack_handleNewPos_lockPlay(ap);
1352 audioTrack_handleUnderrun_lockPlay(ap);
1370 ap->mCallbackProtector->exitCb();
1429 SLresult android_audioPlayer_setConfig(CAudioPlayer *ap, const SLchar *configKey,
1434 assert(NULL != ap && NULL != configKey && NULL != pConfigValue);
1442 result = audioPlayer_setStreamType(ap, *(SLuint32*)pConfigValue);
1451 result = audioPlayer_setPerformanceMode(ap, *(SLuint32*)pConfigValue);
1464 SLresult android_audioPlayer_getConfig(CAudioPlayer* ap, const SLchar *configKey,
1469 assert(NULL != ap && NULL != configKey && NULL != pValueSize);
1479 result = audioPlayer_getStreamType(ap, (SLint32*)pConfigValue);
1492 result = audioPlayer_getPerformanceMode(ap, (SLuint32*)pConfigValue);
2001 SLresult android_audioPlayer_setPlaybackRateAndConstraints(CAudioPlayer *ap, SLpermille rate,
2004 switch (ap->mAndroidObjType) {
2011 uint32_t contentRate = sles_to_android_sampleRate(ap->mSampleRateMilliHz);
2013 if (ap->mTrackPlayer->mAudioTrack != 0) {
2014 ap->mTrackPlayer->mAudioTrack->setSampleRate(contentRate * (rate/1000.0f));
2023 if (ap->mAPlayer != 0) {
2024 ap->mAPlayer->setPlaybackRate((int16_t)rate);
2030 SL_LOGE("Unexpected object type %d", ap->mAndroidObjType);
2041 // ap != NULL
2043 SLresult android_audioPlayer_metadata_getItemCount(CAudioPlayer *ap, SLuint32 *pItemCount) {
2044 if (ap->mAPlayer == 0) {
2047 switch (ap->mAndroidObjType) {
2052 static_cast<android::AudioSfDecoder*>(ap->mAPlayer.get());
2067 // ap != NULL
2069 SLresult android_audioPlayer_metadata_getKeySize(CAudioPlayer *ap,
2071 if (ap->mAPlayer == 0) {
2075 switch (ap->mAndroidObjType) {
2080 static_cast<android::AudioSfDecoder*>(ap->mAPlayer.get());
2103 // ap != NULL
2105 SLresult android_audioPlayer_metadata_getKey(CAudioPlayer *ap,
2107 if (ap->mAPlayer == 0) {
2111 switch (ap->mAndroidObjType) {
2116 static_cast<android::AudioSfDecoder*>(ap->mAPlayer.get());
2140 // ap != NULL
2142 SLresult android_audioPlayer_metadata_getValueSize(CAudioPlayer *ap,
2144 if (ap->mAPlayer == 0) {
2148 switch (ap->mAndroidObjType) {
2153 static_cast<android::AudioSfDecoder*>(ap->mAPlayer.get());
2176 // ap != NULL
2178 SLresult android_audioPlayer_metadata_getValue(CAudioPlayer *ap,
2180 if (ap->mAPlayer == 0) {
2184 switch (ap->mAndroidObjType) {
2189 static_cast<android::AudioSfDecoder*>(ap->mAPlayer.get());
2212 // ap != NULL
2215 void android_audioPlayer_setPlayState(CAudioPlayer *ap) {
2217 SLuint32 playState = ap->mPlay.mState;
2219 switch (ap->mAndroidObjType) {
2224 ap->mTrackPlayer->stop();
2228 ap->mTrackPlayer->pause();
2232 if (ap->mTrackPlayer->mAudioTrack != 0) {
2233 // instead of ap->mTrackPlayer->mAudioTrack->start();
2234 if (!ap->mDeferredStart) {
2236 ap->mTrackPlayer->reportEvent(android::PLAYER_STATE_STARTED);
2238 ap->mDeferredStart = true;
2250 aplayer_setPlayState(ap->mAPlayer, playState, &ap->mAndroidObjState);
2251 audioManagerPlayerEvent(ap, android::PLAYER_STATE_STOPPED);
2254 aplayer_setPlayState(ap->mAPlayer, playState, &ap->mAndroidObjState);
2255 audioManagerPlayerEvent(ap, android::PLAYER_STATE_PAUSED);
2258 audioManagerPlayerEvent(ap, android::PLAYER_STATE_STARTED);
2259 aplayer_setPlayState(ap->mAPlayer, playState, &ap->mAndroidObjState);
2269 aplayer_setPlayState(ap->mAPlayer, playState, &ap->mAndroidObjState);
2272 SL_LOGE(ERROR_PLAYERSETPLAYSTATE_UNEXPECTED_OBJECT_TYPE_D, ap->mAndroidObjType);
2280 void android_audioPlayer_usePlayEventMask(CAudioPlayer *ap) {
2281 IPlay *pPlayItf = &ap->mPlay;
2283 /*switch (ap->mAndroidObjType) {
2286 if (ap->mAPlayer != 0) {
2287 assert(ap->mTrackPlayer->mAudioTrack == 0);
2288 ap->mAPlayer->setPlayEvents((int32_t) eventFlags, (int32_t) pPlayItf->mMarkerPosition,
2293 if (ap->mTrackPlayer->mAudioTrack == 0) {
2298 ap->mTrackPlayer->mAudioTrack->setMarkerPosition(
2301 sles_to_android_sampleRate(ap->mSampleRateMilliHz) /
2306 ap->mTrackPlayer->mAudioTrack->setMarkerPosition(0);
2310 ap->mTrackPlayer->mAudioTrack->setPositionUpdatePeriod(
2312 * sles_to_android_sampleRate(ap->mSampleRateMilliHz)))/1000));
2315 ap->mTrackPlayer->mAudioTrack->setPositionUpdatePeriod(0);
2336 CAudioPlayer *ap = (CAudioPlayer *)pPlayItf->mThis;
2337 switch (ap->mAndroidObjType) {
2342 if (ap->mAPlayer != 0) {
2343 ap->mAPlayer->getDurationMsec(&durationMsec);
2362 CAudioPlayer *ap = (CAudioPlayer *)pPlayItf->mThis;
2363 switch (ap->mAndroidObjType) {
2366 if (ap->mSampleRateMilliHz == UNKNOWN_SAMPLERATE || ap->mTrackPlayer->mAudioTrack == 0) {
2370 ap->mTrackPlayer->mAudioTrack->getPosition(&positionInFrames);
2372 sles_to_android_sampleRate(ap->mSampleRateMilliHz);
2381 if (ap->mAPlayer != 0) {
2382 ap->mAPlayer->getPositionMsec(&posMsec);
2395 SLresult android_audioPlayer_seek(CAudioPlayer *ap, SLmillisecond posMsec) {
2398 switch (ap->mAndroidObjType) {
2408 if (ap->mAPlayer != 0) {
2409 ap->mAPlayer->seek(posMsec);
2421 SLresult android_audioPlayer_loop(CAudioPlayer *ap, SLboolean loopEnable) {
2424 switch (ap->mAndroidObjType) {
2428 if (ap->mAPlayer != 0) {
2429 ap->mAPlayer->loop((bool)loopEnable);
2441 SLresult android_audioPlayer_setBufferingUpdateThresholdPerMille(CAudioPlayer *ap,
2445 switch (ap->mAndroidObjType) {
2447 if (ap->mAPlayer != 0) {
2448 ap->mAPlayer->setBufferingUpdateThreshold(threshold / 10);
2460 void android_audioPlayer_bufferQueue_onRefilled_l(CAudioPlayer *ap) {
2464 if (ap->mTrackPlayer->mAudioTrack != 0) {
2465 ap->mTrackPlayer->reportEvent(android::PLAYER_STATE_STARTED);
2466 // instead of ap->mTrackPlayer->mAudioTrack->start();
2467 ap->mDeferredStart = true;
2472 if (IsInterfaceInitialized(&ap->mObject, MPH_PREFETCHSTATUS)) {
2474 assert(SL_PREFETCHSTATUS_UNDERFLOW == ap->mPrefetchStatus.mStatus);
2475 assert(0 == ap->mPrefetchStatus.mLevel);
2476 ap->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_SUFFICIENTDATA;
2477 ap->mPrefetchStatus.mLevel = 1000;
2479 SLuint32 prefetchEvents = ap->mPrefetchStatus.mCallbackEventsMask &
2482 ap->mPrefetchStatus.mDeferredPrefetchCallback = ap->mPrefetchStatus.mCallback;
2483 ap->mPrefetchStatus.mDeferredPrefetchContext = ap->mPrefetchStatus.mContext;
2484 ap->mPrefetchStatus.mDeferredPrefetchEvents = prefetchEvents;
2494 SLresult android_audioPlayer_bufferQueue_onClear(CAudioPlayer *ap) {
2497 switch (ap->mAndroidObjType) {
2501 if (ap->mTrackPlayer->mAudioTrack != 0) {
2502 ap->mTrackPlayer->mAudioTrack->flush();
2515 void android_audioPlayer_androidBufferQueue_clear_l(CAudioPlayer *ap) {
2516 switch (ap->mAndroidObjType) {
2518 if (ap->mAPlayer != 0) {
2519 android::StreamPlayer* splr = static_cast<android::StreamPlayer*>(ap->mAPlayer.get());
2529 void android_audioPlayer_androidBufferQueue_onRefilled_l(CAudioPlayer *ap) {
2530 switch (ap->mAndroidObjType) {
2532 if (ap->mAPlayer != 0) {
2533 android::StreamPlayer* splr = static_cast<android::StreamPlayer*>(ap->mAPlayer.get());