Home | History | Annotate | Download | only in libopensles

Lines Matching defs:ap

54 static void android_audioPlayer_updateStereoVolume(CAudioPlayer* ap) {
57 if (NULL == ap->mAudioTrack) {
61 if (SL_BOOLEAN_TRUE == ap->mMute) {
65 int channelCount = ap->mNumChannels;
71 if (ap->mMuteMask & LEFT_CHANNEL_MASK) {
76 if (ap->mSoloMask & LEFT_CHANNEL_MASK) {
81 if (ap->mSoloMask & RIGHT_CHANNEL_MASK) {
91 if (ap->mMuteMask & RIGHT_CHANNEL_MASK) {
96 if (ap->mSoloMask & RIGHT_CHANNEL_MASK) {
101 if (ap->mSoloMask & LEFT_CHANNEL_MASK) {
114 ap->mAmplFromVolLevel = sles_to_android_amplification(ap->mVolume.mLevel);
116 leftVol *= ap->mAmplFromVolLevel * ap->mAmplFromDirectLevel;
117 rightVol *= ap->mAmplFromVolLevel * ap->mAmplFromDirectLevel;
120 if (ap->mVolume.mEnableStereoPosition) {
124 double theta = (1000+ap->mVolume.mStereoPosition)*M_PI_4/1000.0f; // 0 <= theta <= Pi/2
125 ap->mAmplFromStereoPos[0] = cos(theta);
126 ap->mAmplFromStereoPos[1] = sin(theta);
129 if (ap->mVolume.mStereoPosition > 0) {
130 ap->mAmplFromStereoPos[0] = (1000-ap->mVolume.mStereoPosition)/1000.0f;
131 ap->mAmplFromStereoPos[1] = 1.0f;
133 ap->mAmplFromStereoPos[0] = 1.0f;
134 ap->mAmplFromStereoPos[1] = (1000+ap->mVolume.mStereoPosition)/1000.0f;
137 leftVol *= ap->mAmplFromStereoPos[0];
138 rightVol *= ap->mAmplFromStereoPos[1];
141 ap->mAudioTrack->setVolume(leftVol * leftAudibilityFactor, rightVol * rightAudibilityFactor);
146 if (NULL != ap->mEffectSend.mItf) {
148 if (ap->mEffectSend.mEnableLevels[i].mEnable) {
149 android_fxSend_setSendLevel(ap,
150 ap->mEffectSend.mEnableLevels[i].mSendLevel + ap->mVolume.mLevel);
156 } else if (NULL != ap->mAndroidEffectSend.mItf) {
157 android_fxSend_setSendLevel(ap, ap->mAndroidEffectSend.mSendLevel + ap->mVolume.mLevel);
162 void audioTrack_handleMarker_lockPlay(CAudioPlayer* ap) {
167 interface_lock_shared(&ap->mPlay);
168 callback = ap->mPlay.mCallback;
169 callbackPContext = ap->mPlay.mContext;
170 interface_unlock_shared(&ap->mPlay);
174 (*callback)(&ap->mPlay.mItf, callbackPContext, SL_PLAYEVENT_HEADATMARKER);
179 void audioTrack_handleNewPos_lockPlay(CAudioPlayer* ap) {
184 interface_lock_shared(&ap->mPlay);
185 callback = ap->mPlay.mCallback;
186 callbackPContext = ap->mPlay.mContext;
187 interface_unlock_shared(&ap->mPlay);
191 (*callback)(&ap->mPlay.mItf, callbackPContext, SL_PLAYEVENT_HEADATNEWPOS);
197 void audioTrack_handleUnderrun_lockPlay(CAudioPlayer* ap) {
201 interface_lock_shared(&ap->mPlay);
202 callback = ap->mPlay.mCallback;
203 callbackPContext = ap->mPlay.mContext;
204 bool headStalled = (ap->mPlay.mEventFlags & SL_PLAYEVENT_HEADSTALLED) != 0;
205 interface_unlock_shared(&ap->mPlay);
208 (*callback)(&ap->mPlay.mItf, callbackPContext, SL_PLAYEVENT_HEADSTALLED);
227 void audioPlayer_dispatch_headAtEnd_lockPlay(CAudioPlayer *ap, bool setPlayStateToPaused,
229 //SL_LOGV("ap=%p, setPlayStateToPaused=%d, needToLock=%d", ap, setPlayStateToPaused,
235 interface_lock_exclusive(&ap->mPlay);
237 if (ap->mPlay.mEventFlags & SL_PLAYEVENT_HEADATEND) {
238 playCallback = ap->mPlay.mCallback;
239 playContext = ap->mPlay.mContext;
242 ap->mPlay.mState = SL_PLAYSTATE_PAUSED;
245 interface_unlock_exclusive(&ap->mPlay);
249 (*playCallback)(&ap->mPlay.mItf, playContext, SL_PLAYEVENT_HEADATEND);
259 * - ap->mPrefetchStatus.mStatus == status
263 void audioPlayer_dispatch_prefetchStatus_lockPrefetch(CAudioPlayer *ap, SLuint32 status,
269 interface_lock_exclusive(&ap->mPrefetchStatus);
272 if (ap->mPrefetchStatus.mStatus != status) {
273 ap->mPrefetchStatus.mStatus = status;
275 if (ap->mPrefetchStatus.mCallbackEventsMask & SL_PREFETCHEVENT_STATUSCHANGE) {
276 prefetchCallback = ap->mPrefetchStatus.mCallback;
277 prefetchContext = ap->mPrefetchStatus.mContext;
281 interface_unlock_exclusive(&ap->mPrefetchStatus);
286 (*prefetchCallback)(&ap->mPrefetchStatus.mItf, prefetchContext, status);
292 SLresult audioPlayer_setStreamType(CAudioPlayer* ap, SLint32 type) {
323 // (ap->mAudioTrack is supposed to be NULL until then)
324 if (SL_OBJECT_STATE_UNREALIZED != ap->mObject.mState) {
328 ap->mStreamType = newStreamType;
336 SLresult audioPlayer_getStreamType(CAudioPlayer* ap, SLint32 *pType) {
339 switch(ap->mStreamType) {
370 void audioPlayer_auxEffectUpdate(CAudioPlayer* ap) {
371 if ((NULL != ap->mAudioTrack) && (ap->mAuxEffect != 0)) {
372 android_fxSend_attach(ap, true, ap->mAuxEffect, ap->mVolume.mLevel + ap->mAuxSendLevel);
379 static void sfplayer_prepare(CAudioPlayer *ap, bool lockAP) {
381 if (lockAP) { object_lock_exclusive(&ap->mObject); }
382 ap->mAndroidObjState = ANDROID_PREPARING;
383 if (lockAP) { object_unlock_exclusive(&ap->mObject); }
385 if (ap->mSfPlayer != 0) {
386 ap->mSfPlayer->prepare();
400 CAudioPlayer *ap = (CAudioPlayer *)user;
407 object_lock_exclusive(&ap->mObject);
409 ap->mAudioTrack = NULL;
410 ap->mNumChannels = 0;
411 ap->mSampleRateMilliHz = 0;
412 ap->mAndroidObjState = ANDROID_UNINITIALIZED;
414 object_unlock_exclusive(&ap->mObject);
421 if (!IsInterfaceInitialized(&(ap->mObject), MPH_PREFETCHSTATUS)) {
428 interface_lock_exclusive(&ap->mPrefetchStatus);
429 ap->mPrefetchStatus.mLevel = 0;
430 ap->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_UNDERFLOW;
431 if ((ap->mPrefetchStatus.mCallbackEventsMask & SL_PREFETCHEVENT_FILLLEVELCHANGE)
432 && (ap->mPrefetchStatus.mCallbackEventsMask & SL_PREFETCHEVENT_STATUSCHANGE)) {
433 callback = ap->mPrefetchStatus.mCallback;
434 callbackPContext = ap->mPrefetchStatus.mContext;
436 ap->mPrefetchStatus);
440 (*callback)(&ap->mPrefetchStatus.mItf, callbackPContext,
446 object_lock_exclusive(&ap->mObject);
448 ap->mAudioTrack = ap->mSfPlayer->getAudioTrack();
449 ap->mNumChannels = ap->mSfPlayer->getNumChannels();
450 ap->mSampleRateMilliHz = android_to_sles_sampleRate(ap->mSfPlayer->getSampleRateHz());
451 ap->mSfPlayer->startPrefetch_async();
454 audioPlayer_auxEffectUpdate(ap);
455 android_audioPlayer_useEventMask(ap);
456 android_audioPlayer_volumeUpdate(ap);
457 android_audioPlayer_setPlayRate(ap, ap->mPlaybackRate.mRate, false /*lockAP*/);
459 ap->mAndroidObjState = ANDROID_READY;
461 object_unlock_exclusive(&ap->mObject);
467 object_lock_exclusive(&ap->mObject);
475 if (NULL != ap->mAudioTrack) {
476 delete ap->mAudioTrack;
477 ap->mAudioTrack = NULL;
480 ap->mAudioTrack = ap->mSfPlayer->getAudioTrack();
481 ap->mNumChannels = ap->mSfPlayer->getNumChannels();
482 ap->mSampleRateMilliHz = android_to_sles_sampleRate(ap->mSfPlayer->getSampleRateHz());
485 audioPlayer_auxEffectUpdate(ap);
486 android_audioPlayer_useEventMask(ap);
487 android_audioPlayer_volumeUpdate(ap);
488 android_audioPlayer_setPlayRate(ap, ap->mPlaybackRate.mRate, false /*lockAP*/);
490 object_unlock_exclusive(&ap->mObject);
494 if (!IsInterfaceInitialized(&(ap->mObject), MPH_PREFETCHSTATUS)) {
501 interface_lock_exclusive(&ap->mPrefetchStatus);
502 if (ap->mPrefetchStatus.mCallbackEventsMask & SL_PREFETCHEVENT_FILLLEVELCHANGE) {
503 callback = ap->mPrefetchStatus.mCallback;
504 callbackPContext = ap->mPrefetchStatus.mContext;
506 ap->mPrefetchStatus.mLevel = (SLpermille)data1;
507 interface_unlock_exclusive(&ap->mPrefetchStatus);
511 (*callback)(&ap->mPrefetchStatus.mItf, callbackPContext,
517 if (!IsInterfaceInitialized(&(ap->mObject), MPH_PREFETCHSTATUS)) {
524 object_lock_exclusive(&ap->mObject);
525 if (ap->mPrefetchStatus.mCallbackEventsMask & SL_PREFETCHEVENT_STATUSCHANGE) {
526 callback = ap->mPrefetchStatus.mCallback;
527 callbackPContext = ap->mPrefetchStatus.mContext;
530 ap->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_SUFFICIENTDATA;
532 ap->mPrefetchStatus.mLevel = 1000;
533 ap->mAndroidObjState = ANDROID_READY;
535 ap->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_UNDERFLOW;
537 ap->mPrefetchStatus.mLevel = 0;
539 object_unlock_exclusive(&ap->mObject);
543 (*callback)(&ap->mPrefetchStatus.mItf, callbackPContext, SL_PREFETCHEVENT_STATUSCHANGE);
548 audioPlayer_dispatch_headAtEnd_lockPlay(ap, true /*set state to paused?*/, true);
549 if ((NULL != ap->mAudioTrack) && (!ap->mSeek.mLoopEnabled)) {
550 ap->mAudioTrack->stop();
770 CAudioPlayer *ap = (CAudioPlayer *)user;
779 interface_lock_exclusive(&ap->mBufferQueue);
780 if (ap->mBufferQueue.mState.count != 0) {
781 //SL_LOGV("nbBuffers in queue = %lu",ap->mBufferQueue.mState.count);
782 assert(ap->mBufferQueue.mFront != ap->mBufferQueue.mRear);
784 BufferHeader *oldFront = ap->mBufferQueue.mFront;
789 + ap->mBufferQueue.mSizeConsumed);
790 if (ap->mBufferQueue.mSizeConsumed + pBuff->size < oldFront->mSize) {
792 ap->mBufferQueue.mSizeConsumed += pBuff->size;
799 pBuff->size = oldFront->mSize - ap->mBufferQueue.mSizeConsumed;
800 ap->mBufferQueue.mSizeConsumed = 0;
803 &ap->mBufferQueue.mArray
804 [ap->mBufferQueue.mNumBuffers + 1])
806 newFront = ap->mBufferQueue.mArray;
808 ap->mBufferQueue.mFront = newFront;
810 ap->mBufferQueue.mState.count--;
811 ap->mBufferQueue.mState.playIndex++;
819 callback = ap->mBufferQueue.mCallback;
821 callbackPContext = ap->mBufferQueue.mContext;
828 audioPlayer_dispatch_headAtEnd_lockPlay(ap, false /*set state to paused?*/, false);
831 if (IsInterfaceInitialized(&(ap->mObject), MPH_PREFETCHSTATUS)) {
832 audioPlayer_dispatch_prefetchStatus_lockPrefetch(ap, SL_PREFETCHSTATUS_UNDERFLOW,
837 ap->mAudioTrack->stop();
839 interface_unlock_exclusive(&ap->mBufferQueue);
842 (*callback)(&ap->mBufferQueue.mItf, callbackPContext);
848 audioTrack_handleMarker_lockPlay(ap);
852 audioTrack_handleNewPos_lockPlay(ap);
856 audioTrack_handleUnderrun_lockPlay(ap);
941 SLresult android_audioPlayer_setConfig(CAudioPlayer *ap, const SLchar *configKey,
946 if (NULL == ap) {
959 result = audioPlayer_setStreamType(ap, *(SLuint32*)pConfigValue);
972 SLresult android_audioPlayer_getConfig(CAudioPlayer* ap, const SLchar *configKey,
977 if (NULL == ap) {
992 result = audioPlayer_getStreamType(ap, (SLint32*)pConfigValue);
1183 SLresult android_audioPlayer_setPlayRate(CAudioPlayer *ap, SLpermille rate, bool lockAP) {
1186 switch(ap->mAndroidObjType) {
1190 if (lockAP) { object_lock_shared(&ap->mObject); }
1191 uint32_t contentRate = sles_to_android_sampleRate(ap->mSampleRateMilliHz);
1192 if (lockAP) { object_unlock_shared(&ap->mObject); }
1194 if (ap->mAudioTrack != NULL) {
1195 ap->mAudioTrack->setSampleRate(contentRate * (rate/1000.0f));
1201 SL_LOGE("Unexpected object type %d", ap->mAndroidObjType);
1211 SLresult android_audioPlayer_setPlaybackRateBehavior(CAudioPlayer *ap,
1214 switch(ap->mAndroidObjType) {
1222 SL_LOGE("Unexpected object type %d", ap->mAndroidObjType);
1232 SLresult android_audioPlayer_getCapabilitiesOfRate(CAudioPlayer *ap,
1234 switch(ap->mAndroidObjType) {
1248 void android_audioPlayer_setPlayState(CAudioPlayer *ap, bool lockAP) {
1250 if (lockAP) { object_lock_shared(&ap->mObject); }
1251 SLuint32 playState = ap->mPlay.mState;
1252 AndroidObject_state objState = ap->mAndroidObjState;
1253 if (lockAP) { object_unlock_shared(&ap->mObject); }
1255 switch(ap->mAndroidObjType) {
1260 if (NULL != ap->mAudioTrack) {
1261 ap->mAudioTrack->stop();
1266 if (NULL != ap->mAudioTrack) {
1267 ap->mAudioTrack->pause();
1272 if (NULL != ap->mAudioTrack) {
1273 ap->mAudioTrack->start();
1286 if (ap->mSfPlayer != 0) {
1287 ap->mSfPlayer->stop();
1294 sfplayer_prepare(ap, lockAP);
1299 if (ap->mSfPlayer != 0) {
1300 ap->mSfPlayer->pause();
1311 sfplayer_prepare(ap, lockAP);
1315 if (ap->mSfPlayer != 0) {
1316 ap->mSfPlayer->play();
1337 void android_audioPlayer_useEventMask(CAudioPlayer *ap) {
1338 IPlay *pPlayItf = &ap->mPlay;
1340 /*switch(ap->mAndroidObjType) {
1343 if (NULL == ap->mAudioTrack) {
1348 ap->mAudioTrack->setMarkerPosition((uint32_t)((((int64_t)pPlayItf->mMarkerPosition
1349 * sles_to_android_sampleRate(ap->mSampleRateMilliHz)))/1000));
1352 ap->mAudioTrack->setMarkerPosition(0);
1356 ap->mAudioTrack->setPositionUpdatePeriod(
1358 * sles_to_android_sampleRate(ap->mSampleRateMilliHz)))/1000));
1361 ap->mAudioTrack->setPositionUpdatePeriod(0);
1382 CAudioPlayer *ap = (CAudioPlayer *)pPlayItf->mThis;
1383 switch(ap->mAndroidObjType) {
1393 if (ap->mSfPlayer != 0) {
1394 durationUsec = ap->mSfPlayer->getDurationUsec();
1408 CAudioPlayer *ap = (CAudioPlayer *)pPlayItf->mThis;
1409 switch(ap->mAndroidObjType) {
1411 if ((ap->mSampleRateMilliHz == 0) || (NULL == ap->mAudioTrack)) {
1415 ap->mAudioTrack->getPosition(&positionInFrames);
1417 sles_to_android_sampleRate(ap->mSampleRateMilliHz);
1421 if (ap->mSfPlayer != 0) {
1422 *pPosMsec = ap->mSfPlayer->getPositionMsec();
1434 void android_audioPlayer_seek(CAudioPlayer *ap, SLmillisecond posMsec) {
1436 switch(ap->mAndroidObjType) {
1441 if (ap->mSfPlayer != 0) {
1442 ap->mSfPlayer->seek(posMsec);
1453 void android_audioPlayer_loop(CAudioPlayer *ap, SLboolean loopEnable) {
1455 if ((MEDIAPLAYER == ap->mAndroidObjType) && (ap->mSfPlayer != 0)) {
1456 ap->mSfPlayer->loop((bool)loopEnable);
1466 * if ap->mMute is SL_BOOLEAN_FALSE, a call to this function was preceded by a call
1469 static void android_audioPlayer_setMute(CAudioPlayer* ap) {
1471 switch(ap->mAndroidObjType) {
1474 t = ap->mAudioTrack;
1481 t->mute(ap->mMute);
1487 SLresult android_audioPlayer_volumeUpdate(CAudioPlayer* ap) {
1488 android_audioPlayer_updateStereoVolume(ap);
1489 android_audioPlayer_setMute(ap);
1495 void android_audioPlayer_bufferQueue_onRefilled(CAudioPlayer *ap) {
1499 if (NULL != ap->mAudioTrack) {
1500 ap->mAudioTrack->start();
1505 if (IsInterfaceInitialized(&(ap->mObject), MPH_PREFETCHSTATUS)) {
1506 audioPlayer_dispatch_prefetchStatus_lockPrefetch(ap, SL_PREFETCHSTATUS_SUFFICIENTDATA,
1516 SLresult android_audioPlayer_bufferQueue_onClear(CAudioPlayer *ap) {
1519 switch (ap->mAndroidObjType) {
1523 if (NULL != ap->mAudioTrack) {
1524 ap->mAudioTrack->flush();