return CAudioIO::IsReady();
}
-void CAudioOutput::initialize() throw(CAudioError) {
+void CAudioOutput::initialize() {
if (__IsInit() == true) {
return;
}
__setInit(true);
CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_IDLE);
- } catch (CAudioError err) {
+ } catch (CAudioError& e) {
finalize();
- throw err;
- } catch (std::bad_alloc&) {
+ throw;
+ } catch (const std::bad_alloc&) {
finalize();
THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed to allocate CAudioSessionHandler object");
}
__setInit(false);
}
-void CAudioOutput::prepare() throw(CAudioError) {
+void CAudioOutput::prepare() {
if (__IsInit() == false) {
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CAudioOutput");
}
if (__IsReady() == true) {
AUDIO_IO_LOGD("Already prepared CAudioOutput");
+ CAudioIO::prepare();
return;
}
- try {
- internalLock();
-
- // Check to invalid AudioType
- CAudioInfo::EAudioType audioType = mAudioInfo.getAudioType();
- if (audioType < CAudioInfo::EAudioType::AUDIO_OUT_TYPE_MEDIA || audioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX) {
- THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
- "The audioType is invalid [type:%d]", static_cast<int>(audioType));
- }
+ /* Check invalid AudioType */
+ CAudioInfo::EAudioType audioType = mAudioInfo.getAudioType();
+ if (audioType < CAudioInfo::EAudioType::AUDIO_OUT_TYPE_MEDIA || audioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX) {
+ THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
+ "The audioType is invalid [type:%d]", static_cast<int>(audioType));
+ }
+ try {
if (mpAudioSessionHandler->getId() < 0) { // Did not registerSound()
if (isForceIgnore() == false && mpAudioSessionHandler->isSkipSession() == false) {
- // Register ASM Listener
+ /* Register ASM Listener */
AUDIO_IO_LOGD("Register ASM Listener");
mpAudioSessionHandler->registerSound();
}
CAudioIO::setInternalStreamInfo();
- // Init StreamSpec
- AUDIO_IO_LOGD("Set Stream Spec : CPulseStreamSpec::STREAM_LATENCY_OUTPUT_DEFAULT");
+ if (isForceIgnore() == false && mpAudioSessionHandler->isSkipSession() == false)
+ mpAudioSessionHandler->updatePlaying();
+ } catch (CAudioError& e) {
+ throw;
+ }
+
+ try {
+ /* Init StreamSpec */
CPulseStreamSpec::EStreamLatency streamSpec = CPulseStreamSpec::EStreamLatency::STREAM_LATENCY_OUTPUT_DEFAULT;
+#ifndef DISABLE_MOBILE_BACK_COMP
+ if (!mStreamCallback.onStream) {
+ AUDIO_IO_LOGD("Set Stream Spec : CPulseStreamSpec::STREAM_LATENCY_OUTPUT_DEFAULT");
+ streamSpec = CPulseStreamSpec::EStreamLatency::STREAM_LATENCY_OUTPUT_DEFAULT;
+ } else {
+ AUDIO_IO_LOGD("Set Stream Spec : CPulseStreamSpec::STREAM_LATENCY_OUTPUT_DEFAULT_ASYNC");
+ streamSpec = CPulseStreamSpec::EStreamLatency::STREAM_LATENCY_OUTPUT_DEFAULT_ASYNC;
+ }
+#endif
CPulseStreamSpec spec(streamSpec, mAudioInfo);
- // Create PulseAudio Handler
+ internalLock();
+
+ /* Create PulseAudio Handler */
mpPulseAudioClient = new CPulseAudioClient(CPulseAudioClient::EStreamDirection::STREAM_DIRECTION_PLAYBACK, spec, this);
- // Initialize PulseAudio Handler
+ /* Initialize PulseAudio Handler */
mpPulseAudioClient->initialize();
-
- if (isForceIgnore() == false && mpAudioSessionHandler->isSkipSession() == false)
- mpAudioSessionHandler->updatePlaying();
-
+#ifndef DISABLE_MOBILE_BACK_COMP
+ /* Uncork stream which is created with CORKED flag */
+ mpPulseAudioClient->cork(false);
+#endif
internalUnlock();
CAudioIO::prepare();
- } catch (CAudioError e) {
+ } catch (CAudioError& e) {
+ SAFE_FINALIZE(mpPulseAudioClient);
+ SAFE_DELETE(mpPulseAudioClient);
internalUnlock();
- throw e;
- } catch (std::bad_alloc&) {
+ throw;
+ } catch (const std::bad_alloc&) {
internalUnlock();
THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed to allocate CPulseAudioClient object");
}
}
-void CAudioOutput::unprepare() throw(CAudioError) {
+void CAudioOutput::unprepare() {
if (__IsInit() == false) {
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize CAudioOutput");
}
try {
+ if (mpAudioSessionHandler->getId() >= 0 && !mIsInterrupted) {
+ if (isForceIgnore() == false && mpAudioSessionHandler->isSkipSession() == false) {
+ if (mStreamCallback.onStream == NULL)
+ CAudioIO::drain();
+ }
+ }
CAudioIO::unprepare();
internalLock();
internalUnlock();
+ } catch (CAudioError& e) {
+ internalUnlock();
+ throw;
+ }
+
+ try {
if (mpAudioSessionHandler->getId() >= 0) {
if (isForceIgnore() == false && mpAudioSessionHandler->isSkipSession() == false)
mpAudioSessionHandler->updateStop();
-
- if (mpAudioSessionHandler->isSkipSession() == false)
- mpAudioSessionHandler->unregisterSound();
}
-
CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_IDLE);
- } catch (CAudioError e) {
+ } catch (CAudioError& e) {
internalUnlock();
- throw e;
+ throw;
}
}
-void CAudioOutput::pause() throw(CAudioError) {
+void CAudioOutput::pause() {
if (__IsInit() == false || __IsReady() == false) {
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioOutput");
try {
CAudioIO::pause();
- internalLock();
-
- /* Updates ASM to STOP */
- if (isForceIgnore() == false && mpAudioSessionHandler->isSkipSession() == false)
- mpAudioSessionHandler->updateStop();
-
- internalUnlock();
-
CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_PAUSED);
- } catch (CAudioError e) {
- internalUnlock();
- throw e;
+ } catch (CAudioError& e) {
+ throw;
}
}
-void CAudioOutput::resume() throw(CAudioError) {
+void CAudioOutput::resume() {
if (__IsInit() == false || __IsReady() == false) {
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioOutput");
}
try {
- internalLock();
-
- if (isForceIgnore() == false && mpAudioSessionHandler->isSkipSession() == false)
- mpAudioSessionHandler->updatePlaying();
-
- internalUnlock();
-
CAudioIO::resume();
CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING);
- } catch (CAudioError e) {
- internalUnlock();
- throw e;
+ } catch (CAudioError& e) {
+ throw;
}
}
-void CAudioOutput::drain() throw(CAudioError) {
+void CAudioOutput::drain() {
if (__IsInit() == false || __IsReady() == false) {
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioOutput");
}
+ if (mStreamCallback.onStream)
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_OPERATION, "async type don't support drain");
+
try {
CAudioIO::drain();
- } catch (CAudioError e) {
- throw e;
+ } catch (CAudioError& e) {
+ throw;
}
}
-void CAudioOutput::flush() throw(CAudioError) {
+void CAudioOutput::flush() {
if (__IsInit() == false || __IsReady() == false) {
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioOutput");
try {
CAudioIO::flush();
- } catch (CAudioError e) {
- throw e;
+ } catch (CAudioError& e) {
+ throw;
}
}
-int CAudioOutput::getBufferSize() throw(CAudioError) {
+int CAudioOutput::getBufferSize() {
if (__IsInit() == false) {
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioOutput");
return (mAudioInfo.getSampleRate() * DEFAULT_PERIOD_SIZE) / 1000 * mAudioInfo.getSampleSize();
}
-size_t CAudioOutput::write(const void* buffer, size_t length) throw(CAudioError) {
+size_t CAudioOutput::write(const void* buffer, size_t length) {
if (__IsInit() == false || __IsReady() == false) {
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioOutput");
try {
/* For synchronization */
internalLock();
+ if (mIsInterrupted) {
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_POLICY_BLOCKED, "audio io is interrupted");
+ }
// If another thread did call unprepare, do not write
if (mpPulseAudioClient == NULL)
__mIsUsedSyncWrite = false;
internalUnlock();
sched_yield();
- } catch (CAudioError e) {
+ } catch (CAudioError& e) {
__mIsUsedSyncWrite = false;
internalUnlock();
- throw e;
+ throw;
}
return length;