#include "CAudioIODef.h"
#include <sched.h>
+#include <chrono>
using namespace std;
using namespace tizen_media_audio;
+static constexpr auto cond_wait_ms = 200ms;
+
/**
* class CAudioOutput
*/
#ifdef _AUDIO_IO_DEBUG_TIMING_
AUDIO_IO_LOGD("Sync Write Mode! - signal! - pClient:[%p], length:[%zu]", pClient, length);
#endif
- internalSignal();
+ {
+ std::lock_guard<std::mutex> cond_guard(mCondMutex);
+ }
+ mCond.notify_one();
return;
}
}
CAudioIO::finalize();
-
__setInit(false);
}
CPulseStreamSpec spec(streamSpec, mAudioInfo);
- internalLock();
- mpPulseAudioClient = new CPulseAudioClient(CPulseAudioClient::EStreamDirection::STREAM_DIRECTION_PLAYBACK, spec, this);
+ std::unique_lock<std::mutex> mutex(mMutex);
+ mpPulseAudioClient = new CPulseAudioClient(CPulseAudioClient::EStreamDirection::STREAM_DIRECTION_PLAYBACK,
+ spec, this);
mpPulseAudioClient->initialize();
#ifndef DISABLE_MOBILE_BACK_COMP
/* Uncork stream which is created with CORKED flag */
mpPulseAudioClient->cork(false);
#endif
- internalUnlock();
+ mutex.unlock();
CAudioIO::prepare();
} catch (const CAudioError& e) {
//LCOV_EXCL_START
SAFE_FINALIZE(mpPulseAudioClient);
SAFE_DELETE(mpPulseAudioClient);
- internalUnlock();
throw;
//LCOV_EXCL_STOP
} catch (const std::bad_alloc&) {
-//LCOV_EXCL_START
- internalUnlock();
THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed to allocate CPulseAudioClient object");
-//LCOV_EXCL_STOP
}
}
CAudioIO::unprepare();
- try {
- internalLock();
- if (mpPulseAudioClient && mpPulseAudioClient->isInThread())
- THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_OPERATION, "Can't unprepare inside pulseaudio thread");
- SAFE_FINALIZE(mpPulseAudioClient);
- SAFE_DELETE(mpPulseAudioClient);
- internalUnlock();
- } catch (const CAudioError& e) {
-//LCOV_EXCL_START
- internalUnlock();
- throw;
-//LCOV_EXCL_STOP
- }
+ std::unique_lock<std::mutex> mutex(mMutex);
+ if (mpPulseAudioClient && mpPulseAudioClient->isInThread())
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_OPERATION, "Can't unprepare inside pulseaudio thread");
+ SAFE_FINALIZE(mpPulseAudioClient);
+ SAFE_DELETE(mpPulseAudioClient);
+ mutex.unlock();
CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_IDLE);
}
if (mStreamCallback.onStream)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_OPERATION, "async type don't support drain");
- try {
- if (mpPulseAudioClient->isInThread()) {
- mpPulseAudioClient->drain();
- } else {
- internalLock();
- mpPulseAudioClient->drain();
- internalUnlock();
- }
- } catch (const CAudioError& e) {
- if (!mpPulseAudioClient->isInThread())
- internalUnlock();
- throw;
- }
+ std::unique_lock<std::mutex> defer_mutex(mMutex, std::defer_lock);
+ if (!mpPulseAudioClient->isInThread())
+ defer_mutex.lock();
+
+ mpPulseAudioClient->drain();
}
void CAudioOutput::flush() {
try {
/* For synchronization */
- internalLock();
+ std::unique_lock<std::mutex> mutex(mMutex);
// If another thread did call unprepare, do not write
if (!mpPulseAudioClient)
// Sets synchronous flag
__mIsUsedSyncWrite = true;
-
size_t lengthIter = length;
while (lengthIter > 0) {
#ifdef _AUDIO_IO_DEBUG_TIMING_
AUDIO_IO_LOGD("writableSize is [%zu].. wait", l);
#endif
- internalWait();
+ std::unique_lock<std::mutex> cond_mutex(mCondMutex);
+ mCond.wait_for(cond_mutex, cond_wait_ms);
}
if (l > lengthIter)
} // End of while (length > 0)
__mIsUsedSyncWrite = false;
- internalUnlock();
+ mutex.unlock();
sched_yield();
} catch (const CAudioError& e) {
__mIsUsedSyncWrite = false;
- internalUnlock();
throw;
}