*/
-#include <pthread.h>
#include <assert.h>
#include "CAudioIODef.h"
#include <sound_manager_internal.h>
+#include <sys/time.h>
+#include <string.h>
using namespace std;
using namespace tizen_media_audio;
/**
* class CAudioIO
*/
-//LCOV_EXCL_START
-CAudioIO::CAudioIO() :
- mpPulseAudioClient(nullptr),
- __mMutex(PTHREAD_MUTEX_INITIALIZER),
- __mCondMutex(PTHREAD_MUTEX_INITIALIZER),
- __mCond(PTHREAD_COND_INITIALIZER),
- __mIsInit(false) {
- mDirection = CAudioInfo::EAudioDirection::AUDIO_DIRECTION_MAX;
- mState = CAudioInfo::EAudioIOState::AUDIO_IO_STATE_NONE;
- mStatePrev = CAudioInfo::EAudioIOState::AUDIO_IO_STATE_NONE;
- mByPolicy = false;
-}
-//LCOV_EXCL_STOP
CAudioIO::CAudioIO(CAudioInfo& audioInfo) :
- mpPulseAudioClient(nullptr),
- __mMutex(PTHREAD_MUTEX_INITIALIZER),
- __mCondMutex(PTHREAD_MUTEX_INITIALIZER),
- __mCond(PTHREAD_COND_INITIALIZER),
- __mIsInit(false) {
- mAudioInfo = audioInfo;
- mDirection = CAudioInfo::EAudioDirection::AUDIO_DIRECTION_MAX;
- mState = CAudioInfo::EAudioIOState::AUDIO_IO_STATE_NONE;
- mStatePrev = CAudioInfo::EAudioIOState::AUDIO_IO_STATE_NONE;
- mByPolicy = false;
+ mAudioInfo(audioInfo) {
}
void CAudioIO::setInit(bool flag) {
mState == CAudioInfo::EAudioIOState::AUDIO_IO_STATE_PAUSED));
}
-void CAudioIO::internalLock() {
- if (!__mIsInit)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
-
- if (pthread_mutex_lock(&__mMutex) != 0)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_INTERNAL_OPERATION, "Failed pthread_mutex_lock()"); //LCOV_EXCL_LINE
-
-#ifdef _AUDIO_IO_DEBUG_TIMING_
- AUDIO_IO_LOGD(COLOR_RED "%p LOCKED" COLOR_END, &__mMutex);
-#endif
-}
-
-void CAudioIO::internalUnlock() {
- if (!__mIsInit)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
-
- if (pthread_mutex_unlock(&__mMutex) != 0)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_INTERNAL_OPERATION, "Failed pthread_mutex_lock()"); //LCOV_EXCL_LINE
-
-#ifdef _AUDIO_IO_DEBUG_TIMING_
- AUDIO_IO_LOGD(COLOR_GREEN "%p UNLOCKED" COLOR_END, &__mMutex);
-#endif
-}
-
-void CAudioIO::internalWait() {
- if (!__mIsInit)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
-
-#ifdef _AUDIO_IO_DEBUG_TIMING_
- AUDIO_IO_LOGD(COLOR_RED "WAIT" COLOR_END);
-#endif
-
- pthread_mutex_lock(&__mCondMutex);
- pthread_cond_wait(&__mCond, &__mCondMutex);
- pthread_mutex_unlock(&__mCondMutex);
-}
-
-void CAudioIO::internalSignal() {
- if (!__mIsInit)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
-
-#ifdef _AUDIO_IO_DEBUG_TIMING_
- AUDIO_IO_LOGD(COLOR_GREEN "SIGNAL" COLOR_END);
-#endif
-
- pthread_mutex_lock(&__mCondMutex);
- pthread_cond_signal(&__mCond);
- pthread_mutex_unlock(&__mCondMutex);
-}
-
void CAudioIO::initialize() {
if (__mIsInit)
return;
AUDIO_IO_LOGD("initialize");
-
- int ret = pthread_mutex_init(&__mMutex, NULL);
- if (ret != 0)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed pthread_mutex_init()"); //LCOV_EXCL_LINE
-
- ret = pthread_cond_init(&__mCond, NULL);
- if (ret != 0)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed pthread_cond_init()"); //LCOV_EXCL_LINE
-
__mIsInit = true;
}
return;
AUDIO_IO_LOGD("finalize");
-
- bool error_occured = false;
- int ret = pthread_mutex_destroy(&__mMutex);
- if (ret != 0) {
-//LCOV_EXCL_START
- AUDIO_IO_LOGE("Failed pthread_mutex_destroy(%p) errno:%d", &__mMutex, ret);
- error_occured = true;
-//LCOV_EXCL_STOP
- }
-
- ret = pthread_mutex_destroy(&__mCondMutex);
- if (ret != 0) {
-//LCOV_EXCL_START
- AUDIO_IO_LOGE("Failed cond pthread_mutex_destroy(%p) errno:%d", &__mCondMutex, ret);
- error_occured = true;
-//LCOV_EXCL_STOP
- }
-
- ret = pthread_cond_destroy(&__mCond);
- if (ret != 0) {
-//LCOV_EXCL_START
- AUDIO_IO_LOGE("Failed pthread_cond_destroy(%p) errno:%d", &__mCond, ret);
- error_occured = true;
-//LCOV_EXCL_STOP
- }
-
- if (error_occured)
- THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INTERNAL_OPERATION, "Finalize Failed"); //LCOV_EXCL_LINE
-
__mIsInit = false;
}
assert(__mIsInit);
assert(state >= CAudioInfo::EAudioIOState::AUDIO_IO_STATE_NONE && state < CAudioInfo::EAudioIOState::AUDIO_IO_STATE_MAX);
- mStatePrev = mState;
- mState = state;
mByPolicy = byPolicy;
if (mState == mStatePrev)
mStateChangedCallback.onStateChanged(mState, mStatePrev, mByPolicy, mStateChangedCallback.mUserData);
}
+void CAudioIO::setState(CAudioInfo::EAudioIOState state) {
+ mStatePrev = mState;
+ mState = state;
+}
+
void CAudioIO::onStateChanged(CAudioInfo::EAudioIOState state) {
onStateChanged(state, false);
}
void CAudioIO::prepare() {
if (!__mIsInit)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO"); //LCOV_EXCL_LINE
}
void CAudioIO::unprepare() {
if (!__mIsInit)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO"); //LCOV_EXCL_LINE
}
void CAudioIO::pause() {
if (!__mIsInit || !IsReady())
- THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize or prepare CAudioIO");
-
- try {
- internalLock();
- AUDIO_IO_LOGD("pause");
- mpPulseAudioClient->cork(true);
- internalUnlock();
- } catch (CAudioError& e) {
- internalUnlock();
- throw;
- }
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize or prepare CAudioIO"); //LCOV_EXCL_LINE
+
+ AUDIO_IO_LOGD("pause");
+ mpPulseAudioClient->cork(true);
}
void CAudioIO::resume() {
if (!__mIsInit || !IsReady())
- THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize or prepare CAudioIO");
-
- try {
- internalLock();
- AUDIO_IO_LOGD("resume");
- mpPulseAudioClient->cork(false);
- internalUnlock();
- } catch (CAudioError& e) {
- internalUnlock();
- throw;
- }
-}
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize or prepare CAudioIO"); //LCOV_EXCL_LINE
-void CAudioIO::drain() {
- if (!__mIsInit || !IsReady())
- THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize or prepare CAudioIO");
-
- try {
- if (mpPulseAudioClient->isInThread()) {
- mpPulseAudioClient->drain();
- } else {
- internalLock();
- mpPulseAudioClient->drain();
- internalUnlock();
- }
- } catch (CAudioError& e) {
- if (!mpPulseAudioClient->isInThread())
- internalUnlock();
- throw;
- }
+ mpPulseAudioClient->cork(false);
}
void CAudioIO::flush() {
if (!__mIsInit || !IsReady())
- THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize or prepare CAudioIO");
-
- try {
- if (mpPulseAudioClient->isInThread()) {
- mpPulseAudioClient->flush();
- } else {
- internalLock();
- mpPulseAudioClient->flush();
- internalUnlock();
- }
- } catch (CAudioError& e) {
- if (!mpPulseAudioClient->isInThread())
- internalUnlock();
- throw;
- }
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize or prepare CAudioIO"); //LCOV_EXCL_LINE
+
+ mpPulseAudioClient->flush();
}
CAudioInfo& CAudioIO::getAudioInfo() {
if (!__mIsInit)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO"); //LCOV_EXCL_LINE
return mAudioInfo;
}
void CAudioIO::setStreamCallback(SStreamCallback callback) {
if (!__mIsInit)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO"); //LCOV_EXCL_LINE
mStreamCallback = callback;
}
CAudioIO::SStreamCallback CAudioIO::getStreamCallback() {
if (!__mIsInit)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO"); //LCOV_EXCL_LINE
return mStreamCallback;
}
void CAudioIO::setStateChangedCallback(SStateChangedCallback callback) {
if (!__mIsInit)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO"); //LCOV_EXCL_LINE
mStateChangedCallback = callback;
}
CAudioIO::SStateChangedCallback CAudioIO::getStateChangedCallback() {
if (!__mIsInit)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO"); //LCOV_EXCL_LINE
return mStateChangedCallback;
}
void CAudioIO::setStreamInfo(sound_stream_info_h stream_info) {
if (!stream_info)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_ARGUMENT, "stream_info is NULL");
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_ARGUMENT, "stream_info is NULL"); //LCOV_EXCL_LINE
if (!__mIsInit)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO"); //LCOV_EXCL_LINE
if (mState != CAudioInfo::EAudioIOState::AUDIO_IO_STATE_IDLE)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_STATE, "it is not permitted while started");
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_STATE, "it is not permitted while started"); //LCOV_EXCL_LINE
int errorCode = SOUND_MANAGER_ERROR_NONE;
char *type = nullptr;
bool avail = false;
if ((errorCode = sound_manager_is_available_stream_information(stream_info, NATIVE_API_AUDIO_IO, &avail)) != SOUND_MANAGER_ERROR_NONE)
- THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "Parameter stream_info is invalid [ret:%d]", errorCode);
+ THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "Parameter stream_info is invalid [ret:%d]", errorCode); //LCOV_EXCL_LINE
if (!avail)
- THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE, "Input stream is not supported");
+ THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE, "Input stream is not supported"); //LCOV_EXCL_LINE
if ((errorCode = sound_manager_get_type_from_stream_information(stream_info, &type)) != SOUND_MANAGER_ERROR_NONE)
- THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "Parameter stream_info->stream_type is invalid [ret:%d]", errorCode);
+ THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "Parameter stream_info->stream_type is invalid [ret:%d]", errorCode); //LCOV_EXCL_LINE
if (mDirection == CAudioInfo::EAudioDirection::AUDIO_DIRECTION_IN)
getAudioInfo().setAudioTypeByInputStreamType(type);
else
getAudioInfo().setAudioTypeByOutputStreamType(type);
if ((errorCode = sound_manager_get_index_from_stream_information(stream_info, &index)) != SOUND_MANAGER_ERROR_NONE)
- THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "Parameter stream_info->index is invalid [ret:%d]", errorCode);
+ THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "Parameter stream_info->index is invalid [ret:%d]", errorCode); //LCOV_EXCL_LINE
getAudioInfo().setAudioIndex(index);
+
+ if (mDirection == CAudioInfo::EAudioDirection::AUDIO_DIRECTION_IN) {
+ int device_id;
+ int method;
+ sound_effect_method_with_reference_e method_reference;
+
+ if (sound_manager_get_effect_method(stream_info, &method) == SOUND_MANAGER_ERROR_NONE)
+ getAudioInfo().setEffectMethod(method);
+
+ if (sound_manager_get_effect_method_with_reference(stream_info, &method_reference, &device_id) == SOUND_MANAGER_ERROR_NONE)
+ getAudioInfo().setEffectMethodWithReference(method_reference, device_id);
+ }
+}
+
+void CAudioIO::onCorked(CPulseAudioClient* pClient, bool corked) {
+ assert(__mIsInit);
+ assert(pClient);
+
+ AUDIO_IO_LOGD("pClient(%p), corked(%d)", pClient, corked);
}