void internalLock();
void internalUnlock();
+ void internalSessionLock();
+ void internalSessionUnlock();
void internalWait();
void internalSignal();
bool isForceIgnore();
+ bool isSessionEnabled();
CAudioSessionHandler* mpAudioSessionHandler;
CPulseAudioClient* mpPulseAudioClient;
private:
pthread_mutex_t __mMutex;
+ pthread_mutex_t __mSessionMutex;
pthread_mutex_t __mCondMutex;
pthread_cond_t __mCond;
bool __mIsInit;
#endif
#define LOG_TAG "TIZEN_N_AUDIO_IO"
-#define AUDIO_IO_LOGD(_fmt_, arg...) { \
+#define AUDIO_IO_LOGD(_fmt_, arg...) do { \
LOGI(_fmt_, ##arg); \
-}
+} while (0)
-#define AUDIO_IO_LOGW(_fmt_, arg...) { \
+#define AUDIO_IO_LOGW(_fmt_, arg...) do { \
LOGW(_fmt_, ##arg); \
-}
+} while (0)
-#define AUDIO_IO_LOGE(_fmt_, arg...) { \
+#define AUDIO_IO_LOGE(_fmt_, arg...) do { \
LOGE(_fmt_, ##arg); \
-}
+} while (0)
#define _AUDIO_IO_SHELL_COLOR_
#ifdef _AUDIO_IO_SHELL_COLOR_
#endif
-#define RET_ERROR(_x_) {return CAudioError((_x_), __FILE__, __func__, __LINE__);};
-#define RET_ERROR_MSG(_x_, _msg_) {return CAudioError((_x_), (_msg_), __FILE__, __func__, __LINE__);};
+#define RET_ERROR(_x_) do {return CAudioError((_x_), __FILE__, __func__, __LINE__);} while(0)
+#define RET_ERROR_MSG(_x_, _msg_) do {return CAudioError((_x_), (_msg_), __FILE__, __func__, __LINE__);} while(0)
-#define RET_ERROR_MSG_FORMAT(_x_, _format_, ...) { \
+#define RET_ERROR_MSG_FORMAT(_x_, _format_, ...) do { \
char _msg_[CAudioError::MSG_LENGTH] = {0, }; \
snprintf(_msg_, CAudioError::MSG_LENGTH, _format_, ##__VA_ARGS__); \
return CAudioError((_x_), (_msg_), __FILE__, __func__, __LINE__); \
-};
+} while (0)
-#define THROW_ERROR(_x_) {throw CAudioError((_x_), __FILE__, __func__, __LINE__);};
-#define THROW_ERROR_MSG(_x_, _msg_) {throw CAudioError((_x_), (_msg_), __FILE__, __func__, __LINE__);};
+#define THROW_ERROR(_x_) do {throw CAudioError((_x_), __FILE__, __func__, __LINE__);} while (0)
+#define THROW_ERROR_MSG(_x_, _msg_) do {throw CAudioError((_x_), (_msg_), __FILE__, __func__, __LINE__);} while (0)
-#define THROW_ERROR_MSG_FORMAT(_x_, _format_, ...) { \
+#define THROW_ERROR_MSG_FORMAT(_x_, _format_, ...) do { \
char _msg_[CAudioError::MSG_LENGTH] = {0, }; \
snprintf(_msg_, CAudioError::MSG_LENGTH, _format_, ##__VA_ARGS__); \
throw CAudioError((_x_), (_msg_), __FILE__, __func__, __LINE__); \
-};
+} while (0)
#define VALID_POINTER_START(_x_) { \
if ((_x_) != NULL) {
#define VALID_POINTER_END } \
}
-#define SAFE_DELETE(_x_) {if ((_x_)) {delete (_x_); (_x_) = NULL;}};
-#define SAFE_FINALIZE(_x_) {if ((_x_)) {(_x_)->finalize();}};
-#define SAFE_REMOVE(_x_) {if ((_x_)) {(_x_)->finalize(); delete (_x_); (_x_) = NULL;}};
+#define SAFE_DELETE(_x_) do {if ((_x_)) {delete (_x_); (_x_) = NULL;}} while (0)
+#define SAFE_FINALIZE(_x_) do {if ((_x_)) {(_x_)->finalize();}} while (0)
+#define SAFE_REMOVE(_x_) do {if ((_x_)) {(_x_)->finalize(); delete (_x_); (_x_) = NULL;}} while (0)
#define DEFAULT_PERIOD_SIZE 50
#endif
-#endif /* __TIZEN_MEDIA_CPP_OBJECTS_IO_H__ */
+#endif /* __TIZEN_MEDIA_AUDIO_IO_CAUDIO_DEF_H__ */
Name: capi-media-audio-io
Summary: An Audio Input & Audio Output library in Tizen Native API
-Version: 0.5.1
+Version: 0.5.2
Release: 0
Group: Multimedia/API
License: Apache-2.0
mpAudioSessionHandler(NULL),
mpPulseAudioClient(NULL),
__mMutex(PTHREAD_MUTEX_INITIALIZER),
+ __mSessionMutex(PTHREAD_MUTEX_INITIALIZER),
__mCondMutex(PTHREAD_MUTEX_INITIALIZER),
__mCond(PTHREAD_COND_INITIALIZER),
__mIsInit(false),
mpAudioSessionHandler(NULL),
mpPulseAudioClient(NULL),
__mMutex(PTHREAD_MUTEX_INITIALIZER),
+ __mSessionMutex(PTHREAD_MUTEX_INITIALIZER),
__mCondMutex(PTHREAD_MUTEX_INITIALIZER),
__mCond(PTHREAD_COND_INITIALIZER),
__mIsInit(false),
}
bool CAudioIO::IsReady() {
- return ((mState == CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING || mState == CAudioInfo::EAudioIOState::AUDIO_IO_STATE_PAUSED)? true : false);
+ return ((mState == CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING ||
+ mState == CAudioInfo::EAudioIOState::AUDIO_IO_STATE_PAUSED)? true : false);
}
void CAudioIO::internalLock() {
- if (__mIsInit == false) {
+ if (__mIsInit == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
- }
- if (pthread_mutex_lock(&__mMutex) != 0) {
+ if (pthread_mutex_lock(&__mMutex) != 0)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INTERNAL_OPERATION, "Failed pthread_mutex_lock()");
- }
#ifdef _AUDIO_IO_DEBUG_TIMING_
AUDIO_IO_LOGD(COLOR_RED "%p LOCKED" COLOR_END, &__mMutex);
}
void CAudioIO::internalUnlock() {
- if (__mIsInit == false) {
+ if (__mIsInit == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
- }
- if (pthread_mutex_unlock(&__mMutex) != 0) {
+ if (pthread_mutex_unlock(&__mMutex) != 0)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INTERNAL_OPERATION, "Failed pthread_mutex_lock()");
- }
+
#ifdef _AUDIO_IO_DEBUG_TIMING_
AUDIO_IO_LOGD(COLOR_GREEN "%p UNLOCKED" COLOR_END, &__mMutex);
#endif
}
+void CAudioIO::internalSessionLock() {
+ if (__mIsInit == false)
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
+
+ if (pthread_mutex_lock(&__mSessionMutex) != 0)
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_INTERNAL_OPERATION, "Failed session pthread_mutex_lock()");
+
+#ifdef _AUDIO_IO_DEBUG_TIMING_
+ AUDIO_IO_LOGD(COLOR_RED "%p LOCKED" COLOR_END, &__mSessionMutex);
+#endif
+}
+
+void CAudioIO::internalSessionUnlock() {
+ if (__mIsInit == false)
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
+
+ if (pthread_mutex_unlock(&__mSessionMutex) != 0)
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_INTERNAL_OPERATION, "Failed session pthread_mutex_unlock()");
+
+#ifdef _AUDIO_IO_DEBUG_TIMING_
+ AUDIO_IO_LOGD(COLOR_GREEN "%p UNLOCKED" COLOR_END, &__mSessionMutex);
+#endif
+}
+
+
void CAudioIO::internalWait() {
- if (__mIsInit == false) {
+ if (__mIsInit == false)
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);
}
void CAudioIO::internalSignal() {
- if (__mIsInit == false) {
+ if (__mIsInit == false)
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);
return __mForceIgnore;
}
+bool CAudioIO::isSessionEnabled() {
+ if (mpAudioSessionHandler &&
+ mpAudioSessionHandler->isSkipSession() == false &&
+ mpAudioSessionHandler->getId() >= 0)
+ return true;
+
+ return false;
+}
+
void CAudioIO::initialize() {
- if (__mIsInit == true) {
+ if (__mIsInit == true)
return;
- }
AUDIO_IO_LOGD("initialize");
int ret = pthread_mutex_init(&__mMutex, NULL);
- if (ret != 0) {
+ if (ret != 0)
THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed pthread_mutex_init()");
- }
+
+ ret = pthread_mutex_init(&__mSessionMutex, NULL);
+ if (ret != 0)
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed session pthread_mutex_init()");
ret = pthread_cond_init(&__mCond, NULL);
- if (ret != 0) {
+ if (ret != 0)
THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed pthread_cond_init()");
- }
__mIsInit = true;
}
void CAudioIO::finalize() {
- if (__mIsInit == false) {
+ if (__mIsInit == false)
return;
- }
AUDIO_IO_LOGD("finalize");
AUDIO_IO_LOGE("Failed pthread_mutex_destroy(%p) errno:%d", &__mMutex, ret);
error_occured = true;
}
- ret = pthread_mutex_destroy(&__mCondMutex);
+
+ ret = pthread_mutex_destroy(&__mSessionMutex);
if (ret != 0) {
- AUDIO_IO_LOGE("Failed pthread_mutex_destroy(%p) errno:%d", &__mCondMutex, ret);
+ AUDIO_IO_LOGE("Failed session pthread_mutex_destroy(%p) errno:%d", &__mSessionMutex, ret);
error_occured = true;
}
+ ret = pthread_mutex_destroy(&__mCondMutex);
+ if (ret != 0) {
+ AUDIO_IO_LOGE("Failed cond pthread_mutex_destroy(%p) errno:%d", &__mCondMutex, ret);
+ error_occured = true;
+ }
ret = pthread_cond_destroy(&__mCond);
if (ret != 0) {
AUDIO_IO_LOGD("mStreamCallback.onStream(%p), pClient(%p), length(%zu)", mStreamCallback.onStream, pClient, length);
#endif
- if (mStreamCallback.onStream != NULL) {
+ if (mStreamCallback.onStream != NULL)
mStreamCallback.onStream(length, mStreamCallback.mUserData);
- }
}
void CAudioIO::onStateChanged(CAudioInfo::EAudioIOState state, bool byPolicy) {
assert(state >= CAudioInfo::EAudioIOState::AUDIO_IO_STATE_NONE && state < CAudioInfo::EAudioIOState::AUDIO_IO_STATE_MAX);
mStatePrev = mState;
- mState = state;
- mByPolicy = byPolicy;
+ mState = state;
+ mByPolicy = byPolicy;
if (mState == mStatePrev)
return;
static_cast<int>(mState),
mByPolicy);
- if (mStateChangedCallback.onStateChanged != NULL) {
+ if (mStateChangedCallback.onStateChanged != NULL)
mStateChangedCallback.onStateChanged(mState, mStatePrev, mByPolicy, mStateChangedCallback.mUserData);
- }
}
void CAudioIO::onStateChanged(CAudioInfo::EAudioIOState state) {
} else if (state == FOCUS_IS_ACQUIRED) {
// Focus handle(id) of the other application was acquired, do pause if possible
internalLock();
- if (mpPulseAudioClient) {
+ if (mpPulseAudioClient)
mpPulseAudioClient->cork(true);
- }
mIsInterrupted = true;
internalUnlock();
// Triggered by 'focus callback'
///////////////////////////////////////
- if (pHandler->getId() != id) {
+ 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...");
if (state == FOCUS_IS_RELEASED) {
// Focus handle(id) was released, do pause here
internalLock();
- if (mpPulseAudioClient) {
+ if (mpPulseAudioClient)
mpPulseAudioClient->cork(true);
- }
mIsInterrupted = true;
internalUnlock();
}
void CAudioIO::prepare() {
- if (__mIsInit == false) {
+ if (__mIsInit == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
- }
- if (mDirection == CAudioInfo::EAudioDirection::AUDIO_DIRECTION_IN) {
- AUDIO_IO_LOGD("Prepare for Audio in");
- } else if (mDirection == CAudioInfo::EAudioDirection::AUDIO_DIRECTION_OUT) {
- AUDIO_IO_LOGD("Prepare for Audio Out");
- }
+
try {
if (mIsInterrupted) {
+ internalSessionLock();
AUDIO_IO_LOGE("This is preparing during interrupted!!!");
- bool isSkip = mpAudioSessionHandler->isSkipSession();
- if (__mForceIgnore == false && isSkip == false && mpAudioSessionHandler->getId() >= 0) {
+ if (isSessionEnabled() && __mForceIgnore == false) {
AUDIO_IO_LOGE("Session updatePlaying!!!");
mpAudioSessionHandler->updatePlaying();
}
-
- if (mpPulseAudioClient && mpPulseAudioClient->isCorked()) {
- AUDIO_IO_LOGE("Uncork!");
- mpPulseAudioClient->cork(false);
- }
- mIsInterrupted = false;
+ internalSessionUnlock();
}
-
- AUDIO_IO_LOGD("------> prepare done");
- /* Do nothing */
} catch (CAudioError& e) {
+ internalSessionUnlock();
throw;
}
+
+ if (mIsInterrupted) {
+ if (mpPulseAudioClient && mpPulseAudioClient->isCorked()) {
+ AUDIO_IO_LOGE("Uncork!");
+ mpPulseAudioClient->cork(false);
+ }
+ mIsInterrupted = false;
+ }
}
void CAudioIO::unprepare() {
- if (__mIsInit == false) {
+ 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;
- }
}
void CAudioIO::pause() {
- if (__mIsInit == false || IsReady() == false) {
+ if (__mIsInit == false || IsReady() == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize or prepare CAudioIO");
- }
try {
internalLock();
}
void CAudioIO::resume() {
- if (__mIsInit == false || IsReady() == false) {
+ if (__mIsInit == false || IsReady() == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize or prepare CAudioIO");
- }
try {
internalLock();
}
void CAudioIO::drain() {
- if (__mIsInit == false || IsReady() == false) {
+ if (__mIsInit == false || IsReady() == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize or prepare CAudioIO");
- }
try {
if (mpPulseAudioClient->isInThread()) {
internalUnlock();
}
} catch (CAudioError& e) {
- if (!mpPulseAudioClient->isInThread()) {
+ if (!mpPulseAudioClient->isInThread())
internalUnlock();
- }
throw;
}
}
void CAudioIO::flush() {
- if (__mIsInit == false || IsReady() == false) {
+ if (__mIsInit == false || IsReady() == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize or prepare CAudioIO");
- }
try {
if (mpPulseAudioClient->isInThread()) {
internalUnlock();
}
} catch (CAudioError& e) {
- if (!mpPulseAudioClient->isInThread()) {
+ if (!mpPulseAudioClient->isInThread())
internalUnlock();
- }
throw;
}
}
CAudioInfo& CAudioIO::getAudioInfo() {
- if (__mIsInit == false) {
+ if (__mIsInit == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
- }
return mAudioInfo;
}
void CAudioIO::setStreamCallback(SStreamCallback callback) {
- if (__mIsInit == false) {
+ if (__mIsInit == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
- }
mStreamCallback = callback;
}
CAudioIO::SStreamCallback CAudioIO::getStreamCallback() {
- if (__mIsInit == false) {
+ if (__mIsInit == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
- }
return mStreamCallback;
}
void CAudioIO::setStateChangedCallback(SStateChangedCallback callback) {
- if (__mIsInit == false) {
+ if (__mIsInit == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
- }
mStateChangedCallback = callback;
}
CAudioIO::SStateChangedCallback CAudioIO::getStateChangedCallback() {
- if (__mIsInit == false) {
+ if (__mIsInit == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
- }
return mStateChangedCallback;
}
void CAudioIO::setInterruptCallback(SInterruptCallback callback) {
- if (__mIsInit == false) {
+ if (__mIsInit == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
- }
mInterruptCallback = callback;
}
CAudioIO::SInterruptCallback CAudioIO::getInterruptCallback() {
- if (__mIsInit == false) {
+ if (__mIsInit == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
- }
return mInterruptCallback;
}
try {
internalLock();
-
if (mpPulseAudioClient != NULL && mState == CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_OPERATION, "An Operation is not permitted while started");
abandonInternalFocus();
-
internalUnlock();
} catch (CAudioError& e) {
internalUnlock();
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);
-
if (!avail)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE, "Input stream is not supported");
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);
-
if (mDirection == CAudioInfo::EAudioDirection::AUDIO_DIRECTION_IN)
getAudioInfo().convertInputStreamType2AudioType(type, &audioType);
else
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);
-
getAudioInfo().setAudioIndex(index);
- AUDIO_IO_LOGD("stream info(%p) is set", stream_info);
} catch (CAudioError& e) {
throw;
}
if (__mIsInit == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
- try {
- if (mState != CAudioInfo::EAudioIOState::AUDIO_IO_STATE_IDLE)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_STATE, "it is not permitted while started");
+ if (mState != CAudioInfo::EAudioIOState::AUDIO_IO_STATE_IDLE)
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_STATE, "it is not permitted while started");
+ sound_stream_info_h stream_info = NULL;
+
+ try {
+ internalSessionLock();
if (mpAudioSessionHandler &&
mpAudioSessionHandler->getMultimediaSession() == MM_SESSION_TYPE_VOIP) {
- sound_stream_info_h stream_info = NULL;
mpAudioSessionHandler->getInternalVoipStreamInfo(&stream_info);
AUDIO_IO_LOGD("get internal VOIP stream info(%p)", stream_info);
- setStreamInfo(stream_info);
}
+ internalSessionUnlock();
} catch (CAudioError& e) {
+ internalSessionUnlock();
throw;
}
+
+ /* NOTE: to avoid double-lock, this should be outside of try-catch. */
+ if (stream_info)
+ setStreamInfo(stream_info);
}
void CAudioIO::abandonInternalFocus() {
- bool isSkip = mpAudioSessionHandler->isSkipSession();
- int id = mpAudioSessionHandler->getId();
-
try {
- if (isSkip == false && id >= 0)
+ internalSessionLock();
+ if (isSessionEnabled()) {
mpAudioSessionHandler->unregisterSound();
-
- mpAudioSessionHandler->finalize();
+ mpAudioSessionHandler->finalize(); /* FIXME : SAFE_FINALIZE or SAFE_DELETE? */
+ }
__mForceIgnore = true;
+ internalSessionUnlock();
} catch (CAudioError& e) {
+ internalSessionUnlock();
throw;
}
}
}
void CAudioInfo::convertAudioType2StreamType(CAudioInfo::EAudioType audioType, char **streamType) {
- if (audioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA || audioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX) {
+ if (audioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA || audioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE,
"The audioType is not supported [audioType:%u]", to_integral(audioType));
- }
+
*streamType = (char *)__STREAM_TYPE_TABLE[(unsigned int)audioType];
return;
}
assert(pHandler);
AUDIO_IO_LOGD("[pHandler:%p], [focus_type:%d], [state:%d], [reason_for_change:%s], [additional_info:%s]",
pHandler, focus_type, state, reason_for_change, additional_info);
+
CAudioIO::onInterrupt(pHandler, id, focus_type, state, reason_for_change, additional_info);
}
void CAudioInput::onSignal(CAudioSessionHandler* pHandler, mm_sound_signal_name_t signal, int value) {
assert(pHandler);
AUDIO_IO_LOGD("[pHandler:%p], [signal:%d], [value:%d]", pHandler, signal, value);
+
CAudioIO::onSignal(pHandler, signal, value);
}
prData.paMainloop = pa_threaded_mainloop_new();
if (prData.paMainloop == NULL)
THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed pa_threaded_mainloop_new()");
+
c = pa_context_new(pa_threaded_mainloop_get_api(prData.paMainloop), CLIENT_NAME);
if (c == NULL)
THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed pa_context_new()");
}
void CAudioInput::initialize() {
- if (__IsInit() == true) {
+ if (__IsInit() == true)
return;
- }
try {
CAudioIO::initialize();
- if (__IsPrivilegeAllowed() == false) {
- THROW_ERROR_MSG(CAudioError::EError::ERROR_PERMISSION_DENIED, "No privilege for record");
- }
+ } catch (CAudioError& e) {
+ finalize();
+ throw;
+ }
- // Create ASM Handler
- mpAudioSessionHandler = new CAudioSessionHandler(CAudioSessionHandler::EAudioSessionType::AUDIO_SESSION_TYPE_CAPTURE, mAudioInfo, this);
+ if (__IsPrivilegeAllowed() == false)
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_PERMISSION_DENIED, "No privilege for record");
- // Initialize ASM Handler
+ try {
+ internalSessionLock();
+ mpAudioSessionHandler = new CAudioSessionHandler(CAudioSessionHandler::EAudioSessionType::AUDIO_SESSION_TYPE_CAPTURE, mAudioInfo, this);
mpAudioSessionHandler->initialize();
-
- __setInit(true);
- CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_IDLE);
+ internalSessionUnlock();
} catch (CAudioError& e) {
+ internalSessionUnlock();
finalize();
throw;
} catch (const std::bad_alloc&) {
+ internalSessionUnlock();
finalize();
THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed to allocate CAudioSessionHandler object");
}
+
+ __setInit(true);
+ CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_IDLE);
}
void CAudioInput::finalize() {
return;
}
+ internalSessionLock();
SAFE_FINALIZE(mpAudioSessionHandler);
SAFE_DELETE(mpAudioSessionHandler);
+ internalSessionUnlock();
CAudioIO::finalize();
}
void CAudioInput::prepare() {
- if (__IsInit() == false) {
+ if (__IsInit() == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CAudioInput");
- }
if (__IsReady() == true) {
AUDIO_IO_LOGD("Already prepared CAudioInput");
/* Check invalid AudioType */
CAudioInfo::EAudioType audioType = mAudioInfo.getAudioType();
- if (audioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA || audioType >= CAudioInfo::EAudioType::AUDIO_OUT_TYPE_MEDIA) {
+ if (audioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA ||
+ audioType >= CAudioInfo::EAudioType::AUDIO_OUT_TYPE_MEDIA)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"The audioType is invalid [type:%d]", static_cast<int>(audioType));
- }
try {
- if (mpAudioSessionHandler->getId() < 0) {
- if (isForceIgnore() == false && mpAudioSessionHandler->isSkipSession() == false) {
- /* Register ASM Listener */
+ internalSessionLock();
+ if (mpAudioSessionHandler &&
+ mpAudioSessionHandler->getId() < 0) { // Did not registerSound()
+ if (isForceIgnore() == false &&
+ mpAudioSessionHandler->isSkipSession() == false) {
AUDIO_IO_LOGD("Register ASM Listener");
mpAudioSessionHandler->registerSound();
}
}
+ internalSessionUnlock();
+ } catch (CAudioError& e) {
+ internalSessionUnlock();
+ throw;
+ }
- CAudioIO::setInternalStreamInfo();
+ CAudioIO::setInternalStreamInfo();
- if (isForceIgnore() == false && mpAudioSessionHandler->isSkipSession() == false)
+ try {
+ internalSessionLock();
+ if (isSessionEnabled() && isForceIgnore() == false)
mpAudioSessionHandler->updatePlaying();
+ internalSessionUnlock();
} catch (CAudioError& e) {
+ internalSessionUnlock();
throw;
}
CPulseStreamSpec spec(streamSpec, mAudioInfo);
internalLock();
-
- /* Create PulseAudio Handler */
mpPulseAudioClient = new CPulseAudioClient(CPulseAudioClient::EStreamDirection::STREAM_DIRECTION_RECORD, spec, this);
-
- /* Initialize PulseAudio Handler */
mpPulseAudioClient->initialize();
#ifndef DISABLE_MOBILE_BACK_COMP
/* Uncork stream which is created with CORKED flag */
mpPulseAudioClient->cork(false);
#endif
-
internalUnlock();
CAudioIO::prepare();
}
void CAudioInput::unprepare() {
- if (__IsInit() == false) {
+ if (__IsInit() == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize CAudioInput");
- }
if (__IsReady() == false) {
AUDIO_IO_LOGD("Already unprepared");
return;
}
- try {
- CAudioIO::unprepare();
+ CAudioIO::unprepare();
+ try {
internalLock();
-
SAFE_FINALIZE(mpPulseAudioClient);
SAFE_DELETE(mpPulseAudioClient);
-
internalUnlock();
} catch (CAudioError& e) {
internalUnlock();
}
try {
- if (mpAudioSessionHandler->getId() >= 0) {
- if (isForceIgnore() == false && mpAudioSessionHandler->isSkipSession() == false)
- mpAudioSessionHandler->updateStop();
- }
+ internalSessionLock();
+ if (isSessionEnabled() && isForceIgnore() == false)
+ mpAudioSessionHandler->updateStop();
+ internalSessionUnlock();
CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_IDLE);
} catch (CAudioError& e) {
- internalUnlock();
+ internalSessionUnlock();
throw;
}
}
void CAudioInput::pause() {
- if (__IsInit() == false || __IsReady() == false) {
+ if (__IsInit() == false || __IsReady() == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioInput");
- }
- if (CAudioIO::getState() != CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING) {
+ if (CAudioIO::getState() != CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_STATE,
"Can't pause if not in Running state");
- }
- if (mpPulseAudioClient->isInThread() == true) {
+ if (mpPulseAudioClient->isInThread() == true)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_OPERATION, "Can't pause in thread");
- }
-
- try {
- CAudioIO::pause();
- CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_PAUSED);
- } catch (CAudioError& e) {
- throw;
- }
+ CAudioIO::pause();
+ CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_PAUSED);
}
void CAudioInput::resume() {
- if (__IsInit() == false || __IsReady() == false) {
+ if (__IsInit() == false || __IsReady() == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioInput");
- }
- if (CAudioIO::getState() != CAudioInfo::EAudioIOState::AUDIO_IO_STATE_PAUSED) {
+ if (CAudioIO::getState() != CAudioInfo::EAudioIOState::AUDIO_IO_STATE_PAUSED)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_STATE,
"Can't resume if not in Paused state");
- }
- if (mpPulseAudioClient->isInThread() == true) {
+ if (mpPulseAudioClient->isInThread() == true)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_OPERATION, "Can't resume in thread");
- }
-
- try {
- CAudioIO::resume();
- CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING);
- } catch (CAudioError& e) {
- throw;
- }
+ CAudioIO::resume();
+ CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING);
}
void CAudioInput::drain() {
}
void CAudioInput::flush() {
- if (__IsInit() == false || __IsReady() == false) {
+ if (__IsInit() == false || __IsReady() == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioInput");
- }
- try {
- CAudioIO::flush();
- } catch (CAudioError& e) {
- throw;
- }
+ CAudioIO::flush();
}
int CAudioInput::getBufferSize() {
- if (__IsInit() == false) {
+ if (__IsInit() == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CAudioInput");
- }
/* FIXME : return calculated size here to satisfy backward compatibility */
return (mAudioInfo.getSampleRate() * DEFAULT_PERIOD_SIZE) / 1000 * mAudioInfo.getSampleSize();
}
void CAudioInput::setStreamCallback(SStreamCallback callback) {
- if (__IsInit() == false) {
+ if (__IsInit() == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CAudioInput");
- }
- if (callback.onStream == NULL) {
- AUDIO_IO_LOGD("__mIsUsedSyncRead = true");
+ if (callback.onStream == NULL)
__mIsUsedSyncRead = true;
- } else {
- AUDIO_IO_LOGD("__mIsUsedSyncRead = false");
+ else
__mIsUsedSyncRead = false;
- }
+ AUDIO_IO_LOGD("__mIsUsedSyncRead = %d", __mIsUsedSyncRead);
CAudioIO::setStreamCallback(callback);
}
size_t CAudioInput::read(void* buffer, size_t length) {
- if (__IsInit() == false || __IsReady() == false) {
+ if (__IsInit() == false || __IsReady() == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioInput");
- }
- if (buffer == NULL) {
+
+ if (buffer == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL buffer:%p", buffer);
- }
- if (CAudioIO::getState() != CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING) {
+
+ if (CAudioIO::getState() != CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_OPERATION,
"Can't read if not in Running state");
- }
+
/* Checks synchronous flag */
- if (__mIsUsedSyncRead == false) {
+ if (__mIsUsedSyncRead == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_OPERATION,
"Invalid operation of read() if receive stream callback");
- }
int ret = 0;
try {
internalLock();
- if (mIsInterrupted) {
+ if (mIsInterrupted)
THROW_ERROR_MSG(CAudioError::EError::ERROR_POLICY_BLOCKED, "audio-io is interrupted");
- }
// If another thread did call unprepare, do not read
if (mpPulseAudioClient == NULL)
// Block until read done
ret = mpPulseAudioClient->read(buffer, length);
-
internalUnlock();
+
sched_yield();
} catch (CAudioError& e) {
internalUnlock();
}
int CAudioInput::peek(const void** buffer, size_t* length) {
- if (__IsInit() == false || __IsReady() == false) {
+ if (__IsInit() == false || __IsReady() == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioInput");
- }
- if (buffer == NULL || length == NULL) {
+ if (buffer == NULL || length == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL buffer:%p, length:%p", buffer, length);
- }
/* Checks synchronous flag */
- if (__mIsUsedSyncRead == true) {
+ if (__mIsUsedSyncRead == true)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_OPERATION,
"Invalid operation of peek() if does not receive a stream callback");
- }
-
- int ret = 0;
- try {
- ret = mpPulseAudioClient->peek(buffer, length);
- } catch (CAudioError& e) {
- throw;
- }
-
- return ret;
+ return mpPulseAudioClient->peek(buffer, length);
}
int CAudioInput::drop() {
- if (__IsInit() == false || __IsReady() == false) {
+ if (__IsInit() == false || __IsReady() == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioInput");
- }
/* Checks synchronous flag */
- if (__mIsUsedSyncRead == true) {
+ if (__mIsUsedSyncRead == true)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_OPERATION,
"Invalid operation of drop() if does not receive a stream callback");
- }
- int ret = 0;
-
- try {
- ret = mpPulseAudioClient->drop();
- } catch (CAudioError& e) {
- throw;
- }
-
- return ret;
+ return mpPulseAudioClient->drop();
}
}
void CAudioOutput::initialize() {
- if (__IsInit() == true) {
+ if (__IsInit() == true)
return;
- }
try {
CAudioIO::initialize();
+ } catch (CAudioError& e) {
+ finalize();
+ throw;
+ }
- // Create ASM Handler
+ try {
+ internalSessionLock();
mpAudioSessionHandler = new CAudioSessionHandler(CAudioSessionHandler::EAudioSessionType::AUDIO_SESSION_TYPE_PLAYBACK, mAudioInfo, this);
-
- // Initialize ASM Handler
mpAudioSessionHandler->initialize();
-
- __setInit(true);
- CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_IDLE);
+ internalSessionUnlock();
} catch (CAudioError& e) {
+ internalSessionUnlock();
finalize();
throw;
} catch (const std::bad_alloc&) {
+ internalSessionUnlock();
finalize();
THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed to allocate CAudioSessionHandler object");
}
+
+ __setInit(true);
+ CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_IDLE);
}
void CAudioOutput::finalize() {
return;
}
+ internalSessionLock();
SAFE_FINALIZE(mpAudioSessionHandler);
SAFE_DELETE(mpAudioSessionHandler);
+ internalSessionUnlock();
CAudioIO::finalize();
}
void CAudioOutput::prepare() {
- if (__IsInit() == false) {
+ if (__IsInit() == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CAudioOutput");
- }
if (__IsReady() == true) {
AUDIO_IO_LOGD("Already prepared CAudioOutput");
/* Check invalid AudioType */
CAudioInfo::EAudioType audioType = mAudioInfo.getAudioType();
- if (audioType < CAudioInfo::EAudioType::AUDIO_OUT_TYPE_MEDIA || audioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX) {
+ 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 */
+ internalSessionLock();
+ if (mpAudioSessionHandler &&
+ mpAudioSessionHandler->getId() < 0) { // Did not registerSound()
+ if (isForceIgnore() == false &&
+ mpAudioSessionHandler->isSkipSession() == false) {
AUDIO_IO_LOGD("Register ASM Listener");
mpAudioSessionHandler->registerSound();
}
}
+ internalSessionUnlock();
+ } catch (CAudioError& e) {
+ internalSessionUnlock();
+ throw;
+ }
- CAudioIO::setInternalStreamInfo();
+ CAudioIO::setInternalStreamInfo();
- if (isForceIgnore() == false && mpAudioSessionHandler->isSkipSession() == false)
+ try {
+ internalSessionLock();
+ if (isSessionEnabled() && isForceIgnore() == false)
mpAudioSessionHandler->updatePlaying();
+ internalSessionUnlock();
} catch (CAudioError& e) {
+ internalSessionUnlock();
throw;
}
CPulseStreamSpec spec(streamSpec, mAudioInfo);
internalLock();
-
- /* Create PulseAudio Handler */
mpPulseAudioClient = new CPulseAudioClient(CPulseAudioClient::EStreamDirection::STREAM_DIRECTION_PLAYBACK, spec, this);
-
- /* Initialize PulseAudio Handler */
mpPulseAudioClient->initialize();
#ifndef DISABLE_MOBILE_BACK_COMP
/* Uncork stream which is created with CORKED flag */
}
void CAudioOutput::unprepare() {
- if (__IsInit() == false) {
+ if (__IsInit() == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize CAudioOutput");
- }
if (__IsReady() == false) {
AUDIO_IO_LOGD("Already unprepared");
}
try {
- if (mpAudioSessionHandler->getId() >= 0 && !mIsInterrupted) {
- if (isForceIgnore() == false && mpAudioSessionHandler->isSkipSession() == false) {
- if (mStreamCallback.onStream == NULL)
- CAudioIO::drain();
- }
+ internalSessionLock();
+ if (isSessionEnabled() &&
+ !mIsInterrupted &&
+ !isForceIgnore() &&
+ mStreamCallback.onStream == NULL) {
+ CAudioIO::drain();
}
- CAudioIO::unprepare();
+ internalSessionUnlock();
+ } catch (CAudioError& e) {
+ internalSessionUnlock();
+ throw;
+ }
- internalLock();
+ CAudioIO::unprepare();
+ try {
+ internalLock();
SAFE_FINALIZE(mpPulseAudioClient);
SAFE_DELETE(mpPulseAudioClient);
-
internalUnlock();
-
} catch (CAudioError& e) {
internalUnlock();
throw;
}
try {
- if (mpAudioSessionHandler->getId() >= 0) {
- if (isForceIgnore() == false && mpAudioSessionHandler->isSkipSession() == false)
- mpAudioSessionHandler->updateStop();
- }
+ internalSessionLock();
+ if (isSessionEnabled() && isForceIgnore() == false)
+ mpAudioSessionHandler->updateStop();
+ internalSessionUnlock();
+
CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_IDLE);
} catch (CAudioError& e) {
- internalUnlock();
+ internalSessionUnlock();
throw;
}
}
void CAudioOutput::pause() {
- if (__IsInit() == false || __IsReady() == false) {
+ if (__IsInit() == false || __IsReady() == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioOutput");
- }
- if (CAudioIO::getState() != CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING) {
+ if (CAudioIO::getState() != CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_STATE,
"Can't pause if not in Running state");
- }
- if (mpPulseAudioClient->isInThread() == true) {
+ if (mpPulseAudioClient->isInThread() == true)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_OPERATION, "Can't pause in thread");
- }
- try {
- CAudioIO::pause();
-
- CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_PAUSED);
- } catch (CAudioError& e) {
- throw;
- }
+ CAudioIO::pause();
+ CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_PAUSED);
}
void CAudioOutput::resume() {
- if (__IsInit() == false || __IsReady() == false) {
+ if (__IsInit() == false || __IsReady() == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioOutput");
- }
- if (CAudioIO::getState() != CAudioInfo::EAudioIOState::AUDIO_IO_STATE_PAUSED) {
+ if (CAudioIO::getState() != CAudioInfo::EAudioIOState::AUDIO_IO_STATE_PAUSED)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_STATE,
"Can't resume if not in Paused state");
- }
- if (mpPulseAudioClient->isInThread() == true) {
+ if (mpPulseAudioClient->isInThread() == true)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_OPERATION, "Can't resume in thread");
- }
-
- try {
- CAudioIO::resume();
- CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING);
- } catch (CAudioError& e) {
- throw;
- }
+ CAudioIO::resume();
+ CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING);
}
void CAudioOutput::drain() {
- if (__IsInit() == false || __IsReady() == false) {
+ 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;
- }
+ CAudioIO::drain();
}
void CAudioOutput::flush() {
- if (__IsInit() == false || __IsReady() == false) {
+ 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;
- }
+ CAudioIO::flush();
}
int CAudioOutput::getBufferSize() {
- if (__IsInit() == false) {
+ if (__IsInit() == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioOutput");
- }
/* FIXME : return calculated size here to satisfy backward compatibility */
return (mAudioInfo.getSampleRate() * DEFAULT_PERIOD_SIZE) / 1000 * mAudioInfo.getSampleSize();
}
size_t CAudioOutput::write(const void* buffer, size_t length) {
- if (__IsInit() == false || __IsReady() == false) {
+ if (__IsInit() == false || __IsReady() == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioOutput");
- }
- if (buffer == NULL) {
+ if (buffer == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are invalid - buffer:%p, length:%zu", buffer, length);
- }
- if (CAudioIO::getState() != CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING) {
+
+ if (CAudioIO::getState() != CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_OPERATION,
"Can't write if not in Running state");
- }
/* When write() is called in PulseAudio callback, bypass a pcm data to CPulseAudioClient (For Asynchronous) */
if (mpPulseAudioClient && mpPulseAudioClient->isInThread() == true) {
int ret = mpPulseAudioClient->write(buffer, length);
- if (ret < 0) {
+ if (ret < 0)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INTERNAL_OPERATION,
"The written result is invalid ret:%d", ret);
- }
-
#ifdef _AUDIO_IO_DEBUG_TIMING_
AUDIO_IO_LOGD("CPulseAudioClient->write(buffer:%p, length:%d)", buffer, length);
#endif
-
return length;
}
try {
/* For synchronization */
internalLock();
- if (mIsInterrupted) {
+ 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)
internalWait();
}
- if (l > lengthIter) {
+ if (l > lengthIter)
l = lengthIter;
- }
#ifdef _AUDIO_IO_DEBUG_TIMING_
AUDIO_IO_LOGD("CPulseAudioClient->write(buffer:%p, length:%d)", buffer, l);
#endif
int ret = mpPulseAudioClient->write(buffer, l);
- if (ret < 0) {
+ if (ret < 0)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INTERNAL_OPERATION,
"The written result is invalid ret:%d", ret);
- }
buffer = static_cast<const uint8_t*>(buffer) + l;
lengthIter -= l;
__mIsUsedSyncWrite = false;
internalUnlock();
+
sched_yield();
} catch (CAudioError& e) {
__mIsUsedSyncWrite = false;
}
void CAudioSessionHandler::__lockFocusIdMutex() {
- if (pthread_mutex_lock(&__mFocusIdMutex) != 0) {
+ if (pthread_mutex_lock(&__mFocusIdMutex) != 0)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INTERNAL_OPERATION, "Failed pthread_mutex_lock() - FocusId Mutex");
- }
#ifdef _AUDIO_IO_DEBUG_TIMING_
AUDIO_IO_LOGD(COLOR_RED "LOCK - FocusId Mutex" COLOR_END);
#endif
}
void CAudioSessionHandler::__unlockFocusIdMutex() {
- if (pthread_mutex_unlock(&__mFocusIdMutex) != 0) {
+ if (pthread_mutex_unlock(&__mFocusIdMutex) != 0)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INTERNAL_OPERATION, "Failed pthread_mutex_unlock() - FocusId Mutex");
- }
#ifdef _AUDIO_IO_DEBUG_TIMING_
AUDIO_IO_LOGD(COLOR_GREEN "UNLOCK - FocusId Mutex" COLOR_END);
#endif
}
void CAudioSessionHandler::__lockFocusCBMutex() {
- if (pthread_mutex_lock(&__mFocusCBMutex) != 0) {
+ if (pthread_mutex_lock(&__mFocusCBMutex) != 0)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INTERNAL_OPERATION, "Failed pthread_mutex_lock() - FocusCB Mutex");
- }
#ifdef _AUDIO_IO_DEBUG_TIMING_
AUDIO_IO_LOGD(COLOR_RED "LOCK - FocusCB Mutex" COLOR_END);
#endif
}
void CAudioSessionHandler::__unlockFocusCBMutex() {
- if (pthread_mutex_unlock(&__mFocusCBMutex) != 0) {
+ if (pthread_mutex_unlock(&__mFocusCBMutex) != 0)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INTERNAL_OPERATION, "Failed pthread_mutex_unlock() - FocusCB Mutex");
- }
#ifdef _AUDIO_IO_DEBUG_TIMING_
AUDIO_IO_LOGD(COLOR_GREEN "UNLOCK - FocusCB Mutex" COLOR_END);
#endif
/* Read session information */
int ret = 0;
if ((ret = _mm_session_util_read_information(-1, (int*)¤tSession, &sessionOptions)) < 0) {
- if (ret == (int) MM_ERROR_INVALID_HANDLE) {
+ if (ret == (int) MM_ERROR_INVALID_HANDLE)
RET_ERROR_MSG(CAudioError::EError::ERROR_INVALID_HANDLE, "Failed _mm_session_util_read_information(). Invalid handle");
- } else {
+ else
RET_ERROR_MSG(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed _mm_session_util_read_information(). Not exist");
- }
}
*type = currentSession;
#if 0
int ret;
if ((ret = sound_manager_get_internal_voip_stream_information(stream_info))) {
- if (ret == SOUND_MANAGER_ERROR_NO_DATA) {
+ if (ret == SOUND_MANAGER_ERROR_NO_DATA)
AUDIO_IO_LOGW("there's no internal voip stream info.");
- } else {
+ else
AUDIO_IO_LOGE("failed to sound_manager_get_internal_voip_stream_information(), ret(0x%x)", ret);
- }
}
#endif
return;
void CAudioSessionHandler::initialize() {
AUDIO_IO_LOGD("");
- if (__mIsInit == true) {
+ if (__mIsInit == true)
return;
- }
MMSessionType currentSession = MM_SESSION_TYPE_MEDIA;
int sessionOptions = 0; // Mix with others by default
// Use focus watch callback with signal subscribe
int errorCode = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &__mSubscribeId, __sound_pcm_signal_cb, static_cast<void*>(this));
- if (errorCode != MM_ERROR_NONE || __mSubscribeId == 0) {
+ if (errorCode != MM_ERROR_NONE || __mSubscribeId == 0)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed mm_sound_subscribe_signal() err:0x%x, __mSubscribeId:%u",
errorCode, __mSubscribeId);
- }
AUDIO_IO_LOGD("Subscribed mm_sound signal [id:%d]", __mSubscribeId);
__mMultimediaSession = currentSession;
__mOptions = sessionOptions;
- if (this->__mAudioSession == EAudioSessionType::AUDIO_SESSION_TYPE_CAPTURE) {
+ if (this->__mAudioSession == EAudioSessionType::AUDIO_SESSION_TYPE_CAPTURE)
__pcmCaptureCountInc();
- }
__mIsInit = true;
}
void CAudioSessionHandler::finalize() {
AUDIO_IO_LOGD("");
- if (__mIsInit == false) {
+ if (__mIsInit == false)
return;
- }
- if (__mAudioSession == EAudioSessionType::AUDIO_SESSION_TYPE_CAPTURE) {
+ if (__mAudioSession == EAudioSessionType::AUDIO_SESSION_TYPE_CAPTURE)
__pcmCaptureCountDec();
- }
unregisterSound();
}
void CAudioSessionHandler::registerSound() {
- if (__mIsInit == false) {
+ if (__mIsInit == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioSessionHandler");
- }
if (__mUseFocus == true) {
__lockFocusIdMutex();
}
void CAudioSessionHandler::unregisterSound() {
- if (__mIsInit == false) {
+ if (__mIsInit == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioSessionHandler");
- }
__lockFocusIdMutex();
if (__mUseFocus == true && __mId >= 0) {
}
void CAudioSessionHandler::updatePlaying() {
- if (__mIsInit == false) {
+ if (__mIsInit == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioSessionHandler");
- }
+
__lockFocusIdMutex();
if (!__mUseFocus || __mId < 0) {
__unlockFocusIdMutex();
}
void CAudioSessionHandler::updateStop() {
- if (__mIsInit == false) {
+ if (__mIsInit == false)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioSessionHandler");
- }
if (__mUseFocus && __isFocusRequired(__mMultimediaSession, __mOptions)) {
__lockFocusIdMutex();
* The CAudioIO is a abstract class object about Input and Output
*/
typedef struct audio_io_s {
- CAudioIO* audioIoHandle;
- audio_io_interrupted_cb_s interrupt_callback;
- audio_io_stream_cb_s stream_callback;
- audio_io_state_changed_cb_s state_changed_callback;
+ CAudioIO* audioIoHandle;
+ audio_io_interrupted_cb_s interrupt_callback;
+ audio_io_stream_cb_s stream_callback;
+ audio_io_state_changed_cb_s state_changed_callback;
audio_io_s() : audioIoHandle(NULL)
{/* Empty Body */}
* Internal functions
*/
static audio_io_error_e __convert_CAudioError(CAudioError& error) {
- audio_io_error_e ret = AUDIO_IO_ERROR_NONE;
+ audio_io_error_e ret = AUDIO_IO_ERROR_NONE;
CAudioError::EError err = error.getError();
switch (err) {
}
static void __check_audio_param(int sample_rate, audio_channel_e channel, audio_sample_type_e type) {
- if (sample_rate < 0) {
+ if (sample_rate < 0)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "Invalid sample rate :%d", sample_rate);
- }
- if (channel != AUDIO_CHANNEL_MONO && channel != AUDIO_CHANNEL_STEREO) {
+ if (channel != AUDIO_CHANNEL_MONO && channel != AUDIO_CHANNEL_STEREO)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "Invalid channel :%d", channel);
- }
- if (type != AUDIO_SAMPLE_TYPE_U8 && type != AUDIO_SAMPLE_TYPE_S16_LE) {
+ if (type != AUDIO_SAMPLE_TYPE_U8 && type != AUDIO_SAMPLE_TYPE_S16_LE)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "Invalid sample type :%d", type);
- }
}
static void __check_audio_param(int sample_rate, audio_channel_e channel, audio_sample_type_e type, sound_type_e sound_type) {
__check_audio_param(sample_rate, channel, type);
- if (sound_type < SOUND_TYPE_SYSTEM || sound_type > SOUND_TYPE_VOICE) {
+ if (sound_type < SOUND_TYPE_SYSTEM || sound_type > SOUND_TYPE_VOICE)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "Invalid sound type : %d", sound_type);
- }
}
static CAudioInfo __generate_audio_input_info(int sampleRate, audio_channel_e channel, audio_sample_type_e sample_type) {
- CAudioInfo::EChannel dstChannel;
+ CAudioInfo::EChannel dstChannel;
CAudioInfo::ESampleType dstSampleType;
- CAudioInfo::EAudioType dstAudioType = CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA;
+ CAudioInfo::EAudioType dstAudioType = CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA;
__convert_channel_2_audio_info_channel(channel, dstChannel);
__convert_sample_type_2_audio_info_sample_type(sample_type, dstSampleType);
}
static CAudioInfo __generate_audio_input_loopback_info(int sampleRate, audio_channel_e channel, audio_sample_type_e sample_type) {
- CAudioInfo::EChannel dstChannel;
+ CAudioInfo::EChannel dstChannel;
CAudioInfo::ESampleType dstSampleType;
- CAudioInfo::EAudioType dstAudioType = CAudioInfo::EAudioType::AUDIO_IN_TYPE_LOOPBACK;
+ CAudioInfo::EAudioType dstAudioType = CAudioInfo::EAudioType::AUDIO_IN_TYPE_LOOPBACK;
__convert_channel_2_audio_info_channel(channel, dstChannel);
__convert_sample_type_2_audio_info_sample_type(sample_type, dstSampleType);
}
static CAudioInfo __generate_audio_output_info(int sampleRate, audio_channel_e channel, audio_sample_type_e sample_type, sound_type_e sound_type) {
- CAudioInfo::EChannel dstChannel;
+ CAudioInfo::EChannel dstChannel;
CAudioInfo::ESampleType dstSampleType;
- CAudioInfo::EAudioType dstAudioType;
+ CAudioInfo::EAudioType dstAudioType;
__convert_channel_2_audio_info_channel(channel, dstChannel);
__convert_sample_type_2_audio_info_sample_type(sample_type, dstSampleType);
__check_audio_param(sample_rate, channel, type);
+ AUDIO_IO_LOGD("samplerate:[%d] channel:[0x%x] sample_type:[0x%x]", sample_rate, channel, type);
+
/* If MIC is not supported, return NOT_SUPPORTED error */
ret = system_info_get_platform_bool(FEATURE_MICROPHONE, &mic_enable);
AUDIO_IO_LOGD("system_info_platform [%s]=[%d], ret[%d]", FEATURE_MICROPHONE, mic_enable, ret);
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_SUPPORTED, "System doesn't support microphone!");
}
- handle = new audio_io_s;
-
CAudioInfo audioInfo = __generate_audio_input_info(sample_rate, channel, type);
+ handle = new audio_io_s;
handle->audioIoHandle = new CAudioInput(audioInfo);
-
handle->audioIoHandle->initialize();
+ AUDIO_IO_LOGD("[%p] created", handle);
*input = handle;
} catch (CAudioError& e) {
AUDIO_IO_LOGE("%s", e.getErrorMsg());
int cpp_audio_in_create_loopback(int sample_rate, audio_channel_e channel, audio_sample_type_e type , audio_in_h* input) {
audio_io_s* handle = NULL;
try {
- if (input == NULL) {
+ if (input == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
- }
__check_audio_param(sample_rate, channel, type);
-
- handle = new audio_io_s;
-
CAudioInfo audioInfo = __generate_audio_input_loopback_info(sample_rate, channel, type);
+ handle = new audio_io_s;
handle->audioIoHandle = new CAudioInput(audioInfo);
-
handle->audioIoHandle->initialize();
*input = handle;
audio_io_s* handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
/* Internal unprepare for backward compatibility */
handle->audioIoHandle->unprepare();
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("destroyed");
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL || stream_info == NULL) {
+ if (handle == NULL || stream_info == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p, stream_info:%p", input, stream_info);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p], stream_info:[%p]", handle, stream_info);
handle->audioIoHandle->setStreamInfo(stream_info);
} catch (CAudioError& e) {
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] done", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
handle->audioIoHandle->prepare();
} catch (CAudioError& e) {
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] prepared", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
handle->audioIoHandle->unprepare();
} catch (CAudioError& e) {
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] unprepared", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
handle->audioIoHandle->pause();
} catch (CAudioError& e) {
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] paused", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
handle->audioIoHandle->resume();
} catch (CAudioError& e) {
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] resumed", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
handle->audioIoHandle->drain();
} catch (CAudioError& e) {
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] drained", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
handle->audioIoHandle->flush();
} catch (CAudioError& e) {
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] flushed", handle);
+
return AUDIO_IO_ERROR_NONE;
}
int ret = 0;
try {
- if (handle == NULL || buffer == NULL) {
+ if (handle == NULL || buffer == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p, buffer:%p", input, buffer);
- }
assert(handle->audioIoHandle);
CAudioInput* inputHandle = static_cast<CAudioInput*>(handle->audioIoHandle);
audio_io_s* handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL || size == NULL) {
+ if (handle == NULL || size == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p, size:%p", input, size);
- }
assert(handle->audioIoHandle);
CAudioIO* inputHandle = static_cast<CAudioInput*>(handle->audioIoHandle);
audio_io_s* handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL || sample_rate == NULL) {
+ if (handle == NULL || sample_rate == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p, sample_rate:%p", input, sample_rate);
- }
assert(handle->audioIoHandle);
*sample_rate = handle->audioIoHandle->getAudioInfo().getSampleRate();
audio_io_s* handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL || channel == NULL) {
+ if (handle == NULL || channel == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p, channel:%p", input, channel);
- }
assert(handle->audioIoHandle);
const CAudioInfo::EChannel srcChannel = handle->audioIoHandle->getAudioInfo().getChannel();
audio_io_s* handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL || type == NULL) {
+ if (handle == NULL || type == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p, type:%p", input, type);
- }
assert(handle->audioIoHandle);
const CAudioInfo::ESampleType srcSampleType = handle->audioIoHandle->getAudioInfo().getSampleType();
assert(handle);
- if (handle->interrupt_callback.onInterrupt) {
+ AUDIO_IO_LOGD("Calling interrupted callback for handle:[%p] code:[%d]", handle, code);
+
+ if (handle->interrupt_callback.onInterrupt)
handle->interrupt_callback.onInterrupt(code, handle->interrupt_callback.user_data);
- }
}
int cpp_audio_in_set_interrupted_cb(audio_in_h input, audio_io_interrupted_cb callback, void *user_data) {
audio_io_s* handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL || callback == NULL) {
+ if (handle == NULL || callback == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p, callback:%p", input, callback);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p], callback:[%p], user_data:[%p]", handle, callback, user_data);
handle->interrupt_callback.onInterrupt = callback;
handle->interrupt_callback.user_data = user_data;
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] done", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
handle->interrupt_callback.onInterrupt = NULL;
handle->interrupt_callback.user_data = NULL;
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] done", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
- }
-
- if (handle->stream_callback.onStream) {
+ if (handle->stream_callback.onStream)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_OPERATION,
"Not support ignore session in async mode");
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
handle->audioIoHandle->ignoreSession();
} catch (CAudioError& e) {
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] done", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* audioIo = static_cast<audio_io_s*>(user_data);
assert(audioIo);
- if (audioIo->stream_callback.onStream) {
+ if (audioIo->stream_callback.onStream)
audioIo->stream_callback.onStream(audioIo, nbytes, audioIo->stream_callback.user_data);
- }
}
static void __state_changed_cb_internal(CAudioInfo::EAudioIOState state,
audio_io_s* audioIo = static_cast<audio_io_s*>(user_data);
assert(audioIo);
- if (audioIo->state_changed_callback.onStateChanged) {
+ if (audioIo->state_changed_callback.onStateChanged)
audioIo->state_changed_callback.onStateChanged(audioIo, __convert_state_type(state_prev),
__convert_state_type(state), by_policy,
audioIo->state_changed_callback.user_data);
- }
}
int cpp_audio_in_set_stream_cb(audio_in_h input, audio_in_stream_cb callback, void* user_data) {
audio_io_s* handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL || callback == NULL) {
+ if (handle == NULL || callback == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p, callback:%p", input, callback);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p], callback:[%p], user_data:[%p]", handle, callback, user_data);
handle->stream_callback.onStream = callback;
handle->stream_callback.user_data = user_data;
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] done", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
handle->stream_callback.onStream = NULL;
handle->stream_callback.user_data = NULL;
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] done", handle);
+
return AUDIO_IO_ERROR_NONE;
}
size_t _length = 0;
try {
- if (handle == NULL || buffer == NULL) {
+ if (handle == NULL || buffer == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p, buffer:%p", input, buffer);
- }
CAudioInput* inputHandle = static_cast<CAudioInput*>(handle->audioIoHandle);
- if (inputHandle == NULL) {
+ if (inputHandle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_HANDLE, "Handle is NULL");
- }
inputHandle->peek(buffer, &_length);
} catch (CAudioError& e) {
audio_io_s* handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
- }
CAudioInput* inputHandle = static_cast<CAudioInput*>(handle->audioIoHandle);
- if (inputHandle == NULL) {
+ if (inputHandle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_HANDLE, "Handle is NULL");
- }
inputHandle->drop();
} catch (CAudioError& e) {
audio_io_s* handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL || callback == NULL) {
+ if (handle == NULL || callback == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p, callback:%p", input, callback);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p], callback:[%p], user_data:[%p]", handle, callback, user_data);
handle->state_changed_callback.onStateChanged = callback;
handle->state_changed_callback.user_data = user_data;
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] done", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p", input);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
handle->state_changed_callback.onStateChanged = NULL;
handle->state_changed_callback.user_data = NULL;
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] done", handle);
+
return AUDIO_IO_ERROR_NONE;
}
int cpp_audio_out_create(int sample_rate, audio_channel_e channel, audio_sample_type_e type, sound_type_e sound_type, audio_out_h *output) {
audio_io_s* handle = NULL;
try {
- if (output == NULL) {
+ if (output == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p", output);
- }
__check_audio_param(sample_rate, channel, type, sound_type);
- handle = new audio_io_s;
-
+ AUDIO_IO_LOGD("samplerate:[%d] channel:[0x%x] sample_type:[0x%x] sound_type:[%d]", sample_rate, channel, type, sound_type);
CAudioInfo audioInfo = __generate_audio_output_info(sample_rate, channel, type, sound_type);
+ handle = new audio_io_s;
handle->audioIoHandle = new CAudioOutput(audioInfo);
-
handle->audioIoHandle->initialize();
+ AUDIO_IO_LOGD("[%p] created", handle);
*output = handle;
} catch (CAudioError& e) {
AUDIO_IO_LOGE("%s", e.getErrorMsg());
int cpp_audio_out_create_new(int sample_rate, audio_channel_e channel, audio_sample_type_e type, audio_out_h *output) {
audio_io_s* handle = NULL;
try {
- if (output == NULL) {
+ if (output == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p", output);
- }
__check_audio_param(sample_rate, channel, type, SOUND_TYPE_SYSTEM /*default check */);
- handle = new audio_io_s;
-
+ AUDIO_IO_LOGD("samplerate:[%d] channel:[0x%x] sample_type:[0x%x]", sample_rate, channel, type);
CAudioInfo audioInfo = __generate_audio_output_info(sample_rate, channel, type, SOUND_TYPE_MEDIA);
+ handle = new audio_io_s;
handle->audioIoHandle = new CAudioOutput(audioInfo);
-
handle->audioIoHandle->initialize();
+ AUDIO_IO_LOGD("[%p] created", handle);
*output = handle;
} catch (CAudioError& e) {
AUDIO_IO_LOGE("%s", e.getErrorMsg());
audio_io_s* handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameter is NULL output:%p", output);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
/* Internal unprepare for backward compatibility */
handle->audioIoHandle->unprepare();
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("destroyed");
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL || stream_info == NULL) {
+ if (handle == NULL || stream_info == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p, stream_info:%p", output, stream_info);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p], stream_info:[%p]", handle, stream_info);
handle->audioIoHandle->setStreamInfo(stream_info);
} catch (CAudioError& e) {
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] done", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameter is NULL output:%p", output);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
handle->audioIoHandle->prepare();
} catch (CAudioError& e) {
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] prepared", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameter is NULL output:%p", output);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
handle->audioIoHandle->unprepare();
} catch (CAudioError& e) {
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] unprepared", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameter is NULL output:%p", output);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
handle->audioIoHandle->pause();
} catch (CAudioError& e) {
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] paused", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameter is NULL output:%p", output);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
handle->audioIoHandle->resume();
} catch (CAudioError& e) {
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] resumed", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameter is NULL output:%p", output);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
handle->audioIoHandle->drain();
} catch (CAudioError& e) {
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] drained", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameter is NULL output:%p", output);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
handle->audioIoHandle->flush();
} catch (CAudioError& e) {
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] flushed", handle);
+
return AUDIO_IO_ERROR_NONE;
}
int ret = 0;
try {
- if (handle == NULL || buffer == NULL) {
+ if (handle == NULL || buffer == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameter is NULL output:%p, buffer:%p", output, buffer);
- }
assert(handle->audioIoHandle);
CAudioOutput* outputHandle = static_cast<CAudioOutput*>(handle->audioIoHandle);
- if (outputHandle == NULL) {
+ if (outputHandle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_HANDLE, "Handle is NULL");
- }
size_t written = outputHandle->write(buffer, static_cast<size_t>(length));
ret = static_cast<int>(written);
audio_io_s* handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL || size == NULL) {
+ if (handle == NULL || size == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p, size:%p", output, size);
- }
assert(handle->audioIoHandle);
CAudioOutput* outputHandle = static_cast<CAudioOutput*>(handle->audioIoHandle);
- if (outputHandle == NULL) {
+ if (outputHandle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_HANDLE, "Handle is NULL");
- }
+
*size = outputHandle->getBufferSize();
} catch (CAudioError& e) {
AUDIO_IO_LOGE("%s", e.getErrorMsg());
audio_io_s* handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL || sample_rate == NULL) {
+ if (handle == NULL || sample_rate == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p, sample_rate:%p", output, sample_rate);
- }
assert(handle->audioIoHandle);
*sample_rate = handle->audioIoHandle->getAudioInfo().getSampleRate();
audio_io_s* handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL || channel == NULL) {
+ if (handle == NULL || channel == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p, channel:%p", output, channel);
- }
assert(handle->audioIoHandle);
const CAudioInfo::EChannel srcChannel = handle->audioIoHandle->getAudioInfo().getChannel();
audio_io_s* handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL || type == NULL) {
+ if (handle == NULL || type == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p, type:%p", output, type);
- }
assert(handle->audioIoHandle);
const CAudioInfo::ESampleType srcSampleType = handle->audioIoHandle->getAudioInfo().getSampleType();
- audio_sample_type_e dstSampleType = AUDIO_SAMPLE_TYPE_U8;
+ audio_sample_type_e dstSampleType = AUDIO_SAMPLE_TYPE_U8;
__convert_audio_info_sample_type_2_sample_type(srcSampleType, dstSampleType);
*type = dstSampleType;
audio_io_s* handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL || type == NULL) {
+ if (handle == NULL || type == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p, type:%p", output, type);
- }
assert(handle->audioIoHandle);
const CAudioInfo::EAudioType srcAudioType = handle->audioIoHandle->getAudioInfo().getAudioType();
- sound_type_e dstSoundType = SOUND_TYPE_MEDIA;
+ sound_type_e dstSoundType = SOUND_TYPE_MEDIA;
__convert_audio_info_audio_type_2_sound_type(srcAudioType, dstSoundType);
*type = dstSoundType;
audio_io_s* handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL || callback == NULL) {
+ if (handle == NULL || callback == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p, callback:%p", output, callback);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p], callback:[%p], user_data:[%p]", handle, callback, user_data);
handle->interrupt_callback.onInterrupt = callback;
handle->interrupt_callback.user_data = user_data;
CAudioIO::SInterruptCallback cb = handle->audioIoHandle->getInterruptCallback();
- cb.mUserData = static_cast<void*>(handle);
+ cb.mUserData = static_cast<void*>(handle);
cb.onInterrupt = __interrupt_cb_internal;
handle->audioIoHandle->setInterruptCallback(cb);
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] done", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p", output);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
handle->interrupt_callback.onInterrupt = NULL;
handle->interrupt_callback.user_data = NULL;
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] done", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p", output);
- }
-
- if (handle->stream_callback.onStream) {
+ if (handle->stream_callback.onStream)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_OPERATION,
"Not support ignore session in async mode");
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
handle->audioIoHandle->ignoreSession();
} catch (CAudioError& e) {
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] done", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL || callback == NULL) {
+ if (handle == NULL || callback == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p, callback:%p", output, callback);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p], callback:[%p], user_data:[%p]", handle, callback, user_data);
handle->stream_callback.onStream = callback;
handle->stream_callback.user_data = user_data;
CAudioIO::SStreamCallback cb = handle->audioIoHandle->getStreamCallback();
cb.mUserData = static_cast<void*>(handle);
- cb.onStream = __stream_cb_internal;
+ cb.onStream = __stream_cb_internal;
handle->audioIoHandle->setStreamCallback(cb);
} catch (CAudioError& e) {
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] done", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p", output);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
handle->stream_callback.onStream = NULL;
handle->stream_callback.user_data = NULL;
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] done", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL || callback == NULL) {
+ if (handle == NULL || callback == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p, callback:%p", output, callback);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p], callback:[%p], user_data:[%p]", handle, callback, user_data);
handle->state_changed_callback.onStateChanged = callback;
handle->state_changed_callback.user_data = user_data;
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] done", handle);
+
return AUDIO_IO_ERROR_NONE;
}
audio_io_s* handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL) {
+ if (handle == NULL)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p", output);
- }
assert(handle->audioIoHandle);
+ AUDIO_IO_LOGD("[%p]", handle);
handle->state_changed_callback.onStateChanged = NULL;
handle->state_changed_callback.user_data = NULL;
return __convert_CAudioError(e);
}
+ AUDIO_IO_LOGD("[%p] done", handle);
+
return AUDIO_IO_ERROR_NONE;
}