-void CAudioIO::onInterrupt(CAudioSessionHandler* pHandler, int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info) {
- assert(pHandler);
-
- int session_option = pHandler->getOptions();
-
- if (id == -1) {
- ///////////////////////////////////////
- // Triggered by 'focus watch callback'
- ///////////////////////////////////////
-
- if (session_option & (MM_SESSION_OPTION_PAUSE_OTHERS | MM_SESSION_OPTION_UNINTERRUPTIBLE)) {
- AUDIO_IO_LOGD("Session option is pausing others or uninterruptible, skip...");
- return;
- }
-
- if (state == FOCUS_IS_RELEASED) {
- // Focus handle(id) of the other application was released, do resume if possible
- internalLock();
- if (mpPulseAudioClient) {
- mpPulseAudioClient->cork(false);
- onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING);
- }
- internalUnlock();
-
- // Focus watch callback doesn't have focus handle, but it need to convert & report to application for convenience
- state = FOCUS_IS_ACQUIRED;
- } else if (state == FOCUS_IS_ACQUIRED) {
- // Focus handle(id) of the other application was acquired, do pause if possible
- internalLock();
- if (mpPulseAudioClient) {
- /* FIXME: Skip this codes due to the blocking of drain() function
- if (mpPulseAudioClient->getStreamDirection() == CPulseAudioClient::EStreamDirection::STREAM_DIRECTION_PLAYBACK) {
- if (mpPulseAudioClient->drain() == false) {
- AUDIO_IO_LOGE("Failed CPulseAudioClient::drain()");
- }
- }
- */
- mpPulseAudioClient->cork(true);
- onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_PAUSED);
- }
- internalUnlock();
-
- // Focus watch callback doesn't have focus handle, but it need to convert & report to application for convenience
- state = FOCUS_IS_RELEASED;
- }
- } else {
- ///////////////////////////////////////
- // Triggered by 'focus callback'
- ///////////////////////////////////////
-
- if (pHandler->getId() != id) {
- AUDIO_IO_LOGW("Id is different, why? [mId : %d]", pHandler->getId());
- }
-
- if (session_option & MM_SESSION_OPTION_UNINTERRUPTIBLE) {
- AUDIO_IO_LOGD("Session option is uninterruptible, skip...");
- return;
- }
-
- if (state == FOCUS_IS_RELEASED) {
- // Focus handle(id) was released, do pause here
- internalLock();
- if (mpPulseAudioClient) {
- /* FIXME: Skip this codes due to the blocking of drain() function
- if (mpPulseAudioClient->getStreamDirection() == CPulseAudioClient::EStreamDirection::STREAM_DIRECTION_PLAYBACK) {
- if (mpPulseAudioClient->drain() == false) {
- AUDIO_IO_LOGE("Failed CPulseAudioClient::drain()");
- }
- }
- */
- mpPulseAudioClient->cork(true);
- onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_PAUSED);
- }
- internalUnlock();
- } else if (state == FOCUS_IS_ACQUIRED) {
- // Focus handle(id) was acquired again,
- // check reason_for_change ("call-voice","call-video","voip","alarm","notification", ...)
- // do resume here and call interrupt completed callback to application.
- internalLock();
- if (mpPulseAudioClient) {
- mpPulseAudioClient->cork(false);
- onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING);
- }
- internalUnlock();
- }
- }
-
- if (mInterruptCallback.onInterrupt != NULL) {
- IAudioSessionEventListener::EInterruptCode e = IAudioSessionEventListener::EInterruptCode::INTERRUPT_COMPLETED;
- e = IAudioSessionEventListener::convertInterruptedCode(state, reason_for_change);
- mInterruptCallback.onInterrupt(e, mInterruptCallback.mUserData);
- }
-}
-
-void CAudioIO::onSignal(CAudioSessionHandler* pHandler, mm_sound_signal_name_t signal, int value) {
- assert(pHandler);
-
- if (signal == MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS) {
- if (value == 1 && pHandler->getSubscribeId() > 0) {
- // Unregister focus watch callback & disable session handler
- pHandler->disableSessionHandler();
- AUDIO_IO_LOGD("Session handler disabled by signal");
- } else if (value == 0) {
- // Currently do nothing...
- }
- }
-}
-
-void CAudioIO::prepare() throw(CAudioError) {
- if (__mIsInit == false) {
- THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
- }
-
- try {
- AUDIO_IO_LOGD("------> prepare done");
- /* Do nothing */
- } catch (CAudioError e) {
- throw e;
- }
-}
-
-void CAudioIO::unprepare() throw(CAudioError) {
- if (__mIsInit == false) {
- THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
- }
-
- try {
- AUDIO_IO_LOGD("unprepare ----->");
- /* Do nothing */
- } catch (CAudioError e) {
- throw e;
- }