From: Seungbae Shin Date: Fri, 23 Feb 2018 10:13:45 +0000 (+0900) Subject: Remove 3.0 deprecated API implementation X-Git-Tag: accepted/tizen/unified/20180227.062934^0 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fapi%2Faudio-io.git;a=commitdiff_plain;h=41701aae153a4e3a00de9e23fec203538abe3576 Remove 3.0 deprecated API implementation [Version] 0.5.4 [Issue Type] Deprecation Change-Id: I8acb7365e55e0d76afe8fdca9e559e0b90f5743f --- diff --git a/CMakeLists.txt b/CMakeLists.txt index b9999e9..00bbf88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) -SET(dependents "dlog mm-sound capi-base-common capi-media-sound-manager mm-common mm-session libpulse dpm capi-system-info") +SET(dependents "dlog mm-sound capi-base-common capi-media-sound-manager mm-common libpulse dpm capi-system-info") SET(pc_dependents "capi-base-common capi-media-sound-manager") INCLUDE(FindPkgConfig) diff --git a/include/CAudioIO.h b/include/CAudioIO.h index 7254d60..939236f 100644 --- a/include/CAudioIO.h +++ b/include/CAudioIO.h @@ -17,6 +17,7 @@ #ifndef __TIZEN_MEDIA_AUDIO_IO_CAUDIO_IO_H__ #define __TIZEN_MEDIA_AUDIO_IO_CAUDIO_IO_H__ +#include #ifdef __cplusplus @@ -29,8 +30,7 @@ namespace tizen_media_audio { * You can't take this object directly. */ class IPulseStreamListener; - class IAudioSessionEventListener; - class CAudioIO : public IPulseStreamListener, public IAudioSessionEventListener { + class CAudioIO : public IPulseStreamListener { public: struct SStreamCallback { void* mUserData; @@ -48,14 +48,6 @@ namespace tizen_media_audio { { /* Empty Body */ } }; - struct SInterruptCallback { - void* mUserData; - void (*onInterrupt)(IAudioSessionEventListener::EInterruptCode code, void* user_data); - - SInterruptCallback() : mUserData(NULL), onInterrupt(NULL) - { /* Empty Body */ } - }; - /* Constructor & Destructor */ CAudioIO(); CAudioIO(CAudioInfo& audioInfo); @@ -80,9 +72,6 @@ namespace tizen_media_audio { virtual void onStream(CPulseAudioClient* pClient, size_t length); virtual void onStateChanged(CAudioInfo::EAudioIOState state, bool byPolicy); virtual void onStateChanged(CAudioInfo::EAudioIOState state); - virtual void onInterrupt(CAudioSessionHandler* pHandler, int id, mm_sound_focus_type_e focus_type, - mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info); - virtual void onSignal(CAudioSessionHandler* pHandler, mm_sound_signal_name_t signal, int value); /* Methods */ CAudioInfo& getAudioInfo(); @@ -93,16 +82,8 @@ namespace tizen_media_audio { virtual void setStateChangedCallback(SStateChangedCallback callback); SStateChangedCallback getStateChangedCallback(); - void setInterruptCallback(SInterruptCallback callback); - SInterruptCallback getInterruptCallback(); - - void ignoreSession(); - void setStreamInfo(sound_stream_info_h stream_info); - void setInternalStreamInfo(); /* this is for session backward compatibility and will be removed later */ - static int sendInterrupt(void* user_data); - CAudioInfo::EAudioIOState getState(); protected: @@ -113,38 +94,25 @@ namespace tizen_media_audio { void internalLock(); void internalUnlock(); - void internalSessionLock(); - void internalSessionUnlock(); void internalWait(); void internalSignal(); - bool isForceIgnore(); - bool isSessionEnabled(); - - CAudioSessionHandler* mpAudioSessionHandler; CPulseAudioClient* mpPulseAudioClient; CAudioInfo mAudioInfo; SStreamCallback mStreamCallback; SStateChangedCallback mStateChangedCallback; - SInterruptCallback mInterruptCallback; - IAudioSessionEventListener::EInterruptCode mInterruptCode; CAudioInfo::EAudioDirection mDirection; CAudioInfo::EAudioIOState mState; CAudioInfo::EAudioIOState mStatePrev; bool mByPolicy; - bool mIsInterrupted; private: pthread_mutex_t __mMutex; - pthread_mutex_t __mSessionMutex; pthread_mutex_t __mCondMutex; pthread_cond_t __mCond; bool __mIsInit; - bool __mForceIgnore; - - void abandonInternalFocus(); /* this is for session backward compatibility and will be removed later */ }; diff --git a/include/CAudioIODef.h b/include/CAudioIODef.h index 0f378df..b7ce786 100644 --- a/include/CAudioIODef.h +++ b/include/CAudioIODef.h @@ -26,11 +26,7 @@ #include "CAudioError.h" #include "CAudioInfo.h" -#include "IAudioSessionEventListener.h" -#include "CAudioSessionHandler.h" #include "IPulseStreamListener.h" -#include "CPulseAudioVolume.h" -#include "CPulseAudioPolicy.h" #include "CPulseStreamSpec.h" #include "CPulseAudioClient.h" #include "CAudioIO.h" diff --git a/include/CAudioInput.h b/include/CAudioInput.h index a6619e9..dad3873 100644 --- a/include/CAudioInput.h +++ b/include/CAudioInput.h @@ -40,10 +40,6 @@ namespace tizen_media_audio { /* Overridden Handler */ virtual void onStream(CPulseAudioClient* pClient, size_t length); - virtual void onInterrupt(CAudioSessionHandler* pHandler, int id, - mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, - const char *reason_for_change, const char *additional_info); - virtual void onSignal(CAudioSessionHandler* pHandler, mm_sound_signal_name_t signal, int value); /* Implemented Methods */ virtual void initialize(); diff --git a/include/CAudioOutput.h b/include/CAudioOutput.h index 6705020..1378653 100644 --- a/include/CAudioOutput.h +++ b/include/CAudioOutput.h @@ -42,8 +42,6 @@ namespace tizen_media_audio { /* Overridden Handler */ virtual void onStream(CPulseAudioClient* pClient, size_t length); - virtual void onInterrupt(CAudioSessionHandler* pHandler, int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info); - virtual void onSignal(CAudioSessionHandler* pHandler, mm_sound_signal_name_t signal, int value); /* Implemented Methods */ virtual void initialize(); diff --git a/include/CAudioSessionHandler.h b/include/CAudioSessionHandler.h deleted file mode 100644 index cd971b2..0000000 --- a/include/CAudioSessionHandler.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __TIZEN_MEDIA_AUDIOIO_IO_CAUDIO_SESSION_HANDLER_H__ -#define __TIZEN_MEDIA_AUDIOIO_IO_CAUDIO_SESSION_HANDLER_H__ - - -#ifdef __cplusplus - -#include -#include -#include -#include -#include -#include -#include - -namespace tizen_media_audio { - - - /** - * ASM Thread - */ - class CAudioSessionHandler { - public: - enum class EAudioSessionType : unsigned int { - AUDIO_SESSION_TYPE_CAPTURE, - AUDIO_SESSION_TYPE_PLAYBACK - }; - - /* Constructor & Destructor */ - CAudioSessionHandler(EAudioSessionType sessionType, CAudioInfo& audioInfo, IAudioSessionEventListener* listener); - virtual ~CAudioSessionHandler(); - - /* Methods */ - virtual void initialize(); - virtual void finalize(); - - bool isSkipSession(); - - void registerSound(); - void unregisterSound(); - - void updatePlaying(); - void updateStop(); - void disableSessionHandler(); - - /* Setter & Getter */ - int getId(); - int getOptions(); - EAudioSessionType getAudioSession(); - MMSessionType getMultimediaSession(); - void getInternalVoipStreamInfo(sound_stream_info_h *stream_info); - unsigned int getSubscribeId(); - CAudioInfo getAudioInfo(); - - private: - struct __streamTypeTable { - const char* name; - MMSessionType type; - }; - const struct __streamTypeTable __STREAM_TYPE_TABLE_IN[MM_SESSION_TYPE_NUM] = { - {"media", MM_SESSION_TYPE_MEDIA}, - {"media", MM_SESSION_TYPE_MEDIA_RECORD}, - {"media", MM_SESSION_TYPE_ALARM}, - {"media", MM_SESSION_TYPE_NOTIFY}, - {"media", MM_SESSION_TYPE_EMERGENCY}, - {"media", MM_SESSION_TYPE_CALL}, - {"media", MM_SESSION_TYPE_VIDEOCALL}, - {"voip", MM_SESSION_TYPE_VOIP}, - {"media", MM_SESSION_TYPE_VOICE_RECOGNITION}, - {"media", MM_SESSION_TYPE_RECORD_AUDIO}, - {"media", MM_SESSION_TYPE_RECORD_VIDEO} - }; - const struct __streamTypeTable __STREAM_TYPE_TABLE_OUT[MM_SESSION_TYPE_NUM] = { - {"media", MM_SESSION_TYPE_MEDIA}, - {"media", MM_SESSION_TYPE_MEDIA_RECORD}, - {"alarm", MM_SESSION_TYPE_ALARM}, - {"notification", MM_SESSION_TYPE_NOTIFY}, - {"emergency", MM_SESSION_TYPE_EMERGENCY}, - {"media", MM_SESSION_TYPE_CALL}, - {"media", MM_SESSION_TYPE_VIDEOCALL}, - {"voip", MM_SESSION_TYPE_VOIP}, - {"media", MM_SESSION_TYPE_VOICE_RECOGNITION}, - {"media", MM_SESSION_TYPE_RECORD_AUDIO}, - {"media", MM_SESSION_TYPE_RECORD_VIDEO} - }; - - /* Private Static Methods */ - static int __pcmCaptureCountInc(); - static int __pcmCaptureCountDec(); - static int __pcmCaptureCountGet(); - static int __focusIdCountInc(); - static int __focusIdCountDec(); - static int __focusIdCountGet(); - - static void __sound_pcm_signal_cb(mm_sound_signal_name_t signal, int value, void *user_data); - static void __sound_pcm_focus_cb(int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, const char *reason_for_change, int option, const char *additional_info, void *user_data); - static void __sound_pcm_focus_watch_cb(int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info, void *user_data); - - /* Private Method */ - CAudioError __convertStreamType(EAudioSessionType type1, MMSessionType type2, int *index); - CAudioError __getAsmInformation(MMSessionType *type, int *options); - bool __isFocusRequired(MMSessionType type, int options); - bool __isFocusDisableReacquisitionRequired(MMSessionType type, int options); - void __lockFocusIdMutex(); - void __unlockFocusIdMutex(); - void __lockFocusCBMutex(); - void __unlockFocusCBMutex(); - bool __checkNeedBlock(const char *focus_acquired_by); - - /* Static Member */ - static int __sCaptureRef; - static int __sFocusRef; - - /* Members */ - int __mId; - int __mOptions; - - EAudioSessionType __mAudioSession; - MMSessionType __mMultimediaSession; - - CAudioInfo __mAudioInfo; /* Referenced from CAudioIO */ - - IAudioSessionEventListener* __mpEventListener; - - bool __mIsInit; - unsigned int __mSubscribeId; - - bool __mUseFocus; - int __mAcquiredFocus; /* For audio focus */ - char* __mReasonForChange; /* For audio focus */ - char* __mAdditionalInfo; /* For audio focus */ - - pthread_mutex_t __mFocusIdMutex; - pthread_mutex_t __mFocusCBMutex; - }; - - -} /* namespace tizen_media_audio */ - -#endif -#endif /* __TIZEN_MEDIA_AUDIOIO_IO_CAUDIO_SESSION_HANDLER_H__ */ diff --git a/include/CPulseAudioPolicy.h b/include/CPulseAudioPolicy.h deleted file mode 100644 index 2a38ac9..0000000 --- a/include/CPulseAudioPolicy.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#if 0 -#ifndef __TIZEN_MEDIA_AUDIO_IO_CPULSEAUDIO_POLICY_H__ -#define __TIZEN_MEDIA_AUDIO_IO_CPULSEAUDIO_POLICY_H__ - - -#ifdef __cplusplus - - -namespace tizen_media_audio { - - - /** - * class CPulseAudioPolicy - */ - class CPulseAudioPolicy { - public: - /* Enums */ - enum class EPolicy : unsigned int { - POLICY_DEFAULT, - POLICY_OUT_AUTO, - POLICY_OUT_PHONE, - POLICY_OUT_VOIP, - POLICY_OUT_ALL, - POLICY_IN_VOIP, - POLICY_IN_LOOPBACK, - POLICY_IN_MIRRORING, - POLICY_HIGH_LATENCY, - POLICY_MAX - }; - - /* Constructors */ - CPulseAudioPolicy(); - CPulseAudioPolicy(EPolicy policy); - ~CPulseAudioPolicy(); - - /* getter & setter */ - void setPolicy(EPolicy policy); - EPolicy getPolicy(); - - /* Override */ - bool operator != (const EPolicy policy); - bool operator == (const EPolicy policy); - - private: - /* Members */ - EPolicy __mPolicy; - }; - - -} /* namespace tizen_media_audio */ - -#endif -#endif /* __TIZEN_MEDIA_AUDIO_IO_CPULSEAUDIO_POLICY_H__ */ -#endif diff --git a/include/CPulseAudioVolume.h b/include/CPulseAudioVolume.h deleted file mode 100644 index e2839ac..0000000 --- a/include/CPulseAudioVolume.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#if 0 -#ifndef __TIZEN_MEDIA_AUDIO_IO_CPULSEAUDIO_VOLUME_H__ -#define __TIZEN_MEDIA_AUDIO_IO_CPULSEAUDIO_VOLUME_H__ - - -#ifdef __cplusplus - - -namespace tizen_media_audio { - - - /** - * Audio Volume - */ - class CPulseAudioVolume { - public: - /* Enums */ - enum class EVolume : unsigned int { - VOLUME_SYSTEM, /**< System volume type */ - VOLUME_NOTIFICATION, /**< Notification volume type */ - VOLUME_ALARM, /**< Alarm volume type */ - VOLUME_RINGTONE, /**< Ringtone volume type */ - VOLUME_MEDIA, /**< Media volume type */ - VOLUME_CALL, /**< Call volume type */ - VOLUME_VOIP, /**< VOIP volume type */ - VOLUME_VOICE, /**< VOICE volume type */ - VOLUME_FIXED, /**< Volume type for fixed acoustic level */ - VOLUME_EXT_ANDROID = VOLUME_FIXED, /**< External system volume for Android */ - VOLUME_MAX /**< Volume type count */ - }; - - enum class EVolumeGain : unsigned int { - VOLUME_GAIN_DEFAULT, - VOLUME_GAIN_DIALER, - VOLUME_GAIN_TOUCH, - VOLUME_GAIN_AF, - VOLUME_GAIN_SHUTTER1, - VOLUME_GAIN_SHUTTER2, - VOLUME_GAIN_CAMCORDING, - VOLUME_GAIN_MIDI, - VOLUME_GAIN_BOOTING, - VOLUME_GAIN_VIDEO, - VOLUME_GAIN_TTS, - VOLUME_GAIN_MAX - }; - - /* Constructor & Destructor */ - CPulseAudioVolume(); - CPulseAudioVolume(EVolume volume, EVolumeGain gain); - ~CPulseAudioVolume(); - - /* Methods */ - - /* Setter & Getter */ - void setVolume(EVolume volume); - EVolume getVolume(); - - void setVolumeGain(EVolumeGain volumeGain); - EVolumeGain getVolumeGain(); - - private: - /* Members */ - EVolume __mVolume; - EVolumeGain __mVolumeGain; - }; - - -} /* namespace tizen_media_audio */ - -#endif -#endif /* __TIZEN_MEDIA_AUDIO_IO_CPULSEAUDIO_VOLUME_H__ */ -#endif diff --git a/include/IAudioSessionEventListener.h b/include/IAudioSessionEventListener.h deleted file mode 100644 index 6ae05f6..0000000 --- a/include/IAudioSessionEventListener.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __TIZEN_MEDIA_AUDIO_IO_IAUDIO_SESSION_EVENT_LISTENER_H__ -#define __TIZEN_MEDIA_AUDIO_IO_IAUDIO_SESSION_EVENT_LISTENER_H__ - - -#ifdef __cplusplus - - -#include -#include - - -namespace tizen_media_audio { - - - /** - * Called by ASM Thread - */ - class CAudioSessionHandler; - class IAudioSessionEventListener { - public: - enum class EInterruptCode : unsigned int { - INTERRUPT_COMPLETED = 0, /**< Interrupt completed */ - INTERRUPT_BY_MEDIA, /**< Interrupted by a media application */ - INTERRUPT_BY_CALL, /**< Interrupted by an incoming call */ - INTERRUPT_BY_EARJACK_UNPLUG, /**< Interrupted by unplugging headphones */ - INTERRUPT_BY_RESOURCE_CONFLICT, /**< Interrupted by a resource conflict */ - INTERRUPT_BY_ALARM, /**< Interrupted by an alarm */ - INTERRUPT_BY_EMERGENCY, /**< Interrupted by an emergency */ - INTERRUPT_BY_NOTIFICATION, /**< Interrupted by a notification */ - INTERRUPT_MAX - }; - - static EInterruptCode convertInterruptedCode(int code, const char *reason_for_change); - virtual void onInterrupt(CAudioSessionHandler* pHandler, int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info) = 0; - virtual void onSignal(CAudioSessionHandler* pHandler, mm_sound_signal_name_t signal, int value) = 0; - }; - - -} /* namespace tizen_media_audio */ - -#endif -#endif /* __TIZEN_MEDIA_AUDIO_IO_IAUDIO_SESSION_EVENT_LISTENER_H__ */ diff --git a/packaging/capi-media-audio-io.spec b/packaging/capi-media-audio-io.spec index e37b52f..5e1e73c 100644 --- a/packaging/capi-media-audio-io.spec +++ b/packaging/capi-media-audio-io.spec @@ -1,6 +1,6 @@ Name: capi-media-audio-io Summary: An Audio Input & Audio Output library in Tizen Native API -Version: 0.5.3 +Version: 0.5.4 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/cpp/CAudioIO.cpp b/src/cpp/CAudioIO.cpp index 1d0c36a..e35e8db 100644 --- a/src/cpp/CAudioIO.cpp +++ b/src/cpp/CAudioIO.cpp @@ -20,6 +20,7 @@ #include #include #include "CAudioIODef.h" +#include using namespace std; using namespace tizen_media_audio; @@ -29,38 +30,28 @@ using namespace tizen_media_audio; * class CAudioIO */ CAudioIO::CAudioIO() : - mpAudioSessionHandler(NULL), mpPulseAudioClient(NULL), __mMutex(PTHREAD_MUTEX_INITIALIZER), - __mSessionMutex(PTHREAD_MUTEX_INITIALIZER), __mCondMutex(PTHREAD_MUTEX_INITIALIZER), __mCond(PTHREAD_COND_INITIALIZER), - __mIsInit(false), - __mForceIgnore(false) { - mInterruptCode = IAudioSessionEventListener::EInterruptCode::INTERRUPT_MAX; + __mIsInit(false) { mDirection = CAudioInfo::EAudioDirection::AUDIO_DIRECTION_MAX; mState = CAudioInfo::EAudioIOState::AUDIO_IO_STATE_NONE; mStatePrev = CAudioInfo::EAudioIOState::AUDIO_IO_STATE_NONE; mByPolicy = false; - mIsInterrupted = false; } CAudioIO::CAudioIO(CAudioInfo& audioInfo) : - mpAudioSessionHandler(NULL), mpPulseAudioClient(NULL), __mMutex(PTHREAD_MUTEX_INITIALIZER), - __mSessionMutex(PTHREAD_MUTEX_INITIALIZER), __mCondMutex(PTHREAD_MUTEX_INITIALIZER), __mCond(PTHREAD_COND_INITIALIZER), - __mIsInit(false), - __mForceIgnore(false) { + __mIsInit(false) { mAudioInfo = audioInfo; - mInterruptCode = IAudioSessionEventListener::EInterruptCode::INTERRUPT_MAX; mDirection = CAudioInfo::EAudioDirection::AUDIO_DIRECTION_MAX; mState = CAudioInfo::EAudioIOState::AUDIO_IO_STATE_NONE; mStatePrev = CAudioInfo::EAudioIOState::AUDIO_IO_STATE_NONE; mByPolicy = false; - mIsInterrupted = false; } CAudioIO::~CAudioIO() { @@ -103,31 +94,6 @@ void CAudioIO::internalUnlock() { #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) THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO"); @@ -154,19 +120,6 @@ void CAudioIO::internalSignal() { pthread_mutex_unlock(&__mCondMutex); } -bool CAudioIO::isForceIgnore() { - return __mForceIgnore; -} - -bool CAudioIO::isSessionEnabled() { - if (mpAudioSessionHandler && - mpAudioSessionHandler->isSkipSession() == false && - mpAudioSessionHandler->getId() >= 0) - return true; - - return false; -} - void CAudioIO::initialize() { if (__mIsInit == true) return; @@ -177,10 +130,6 @@ void CAudioIO::initialize() { 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) THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed pthread_cond_init()"); @@ -201,12 +150,6 @@ void CAudioIO::finalize() { error_occured = true; } - ret = pthread_mutex_destroy(&__mSessionMutex); - if (ret != 0) { - 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); @@ -270,133 +213,9 @@ CAudioInfo::EAudioIOState CAudioIO::getState() { return mState; } -int CAudioIO::sendInterrupt(void* user_data) { - CAudioIO *pCaudioIo = (CAudioIO *)user_data; - - if (pCaudioIo && pCaudioIo->mInterruptCallback.onInterrupt) { - AUDIO_IO_LOGD("sending interrupt [%d]", static_cast(pCaudioIo->mInterruptCode)); - pCaudioIo->mInterruptCallback.onInterrupt(pCaudioIo->mInterruptCode, pCaudioIo->mInterruptCallback.mUserData); - } - return 0; -} - -int caudio_gsource_callback(void *user_data) { - CAudioIO::sendInterrupt(user_data); - return 0; -} - -void CAudioIO::onInterrupt(CAudioSessionHandler* pHandler, int id, mm_sound_focus_type_e focus_type, - mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info) { - assert(pHandler); - - int session_option = pHandler->getOptions(); - - if (id == -1) { - /////////////////////////////////////// - // Triggered by 'focus watch callback' - /////////////////////////////////////// - - if (session_option & (MM_SESSION_OPTION_PAUSE_OTHERS | MM_SESSION_OPTION_UNINTERRUPTIBLE)) { - AUDIO_IO_LOGD("Session option is pausing others or uninterruptible, skip..."); - return; - } - - if (state == FOCUS_IS_RELEASED) { - // Focus handle(id) of the other application was released, notify resume - // Focus watch callback doesn't have focus handle, but it need to convert & report to application for convenience - state = FOCUS_IS_ACQUIRED; - } else if (state == FOCUS_IS_ACQUIRED) { - // Focus handle(id) of the other application was acquired, do pause if possible - internalLock(); - if (mpPulseAudioClient) - mpPulseAudioClient->cork(true); - mIsInterrupted = true; - internalUnlock(); - - // Focus watch callback doesn't have focus handle, but it need to convert & report to application for convenience - state = FOCUS_IS_RELEASED; - } - } else { - /////////////////////////////////////// - // Triggered by 'focus callback' - /////////////////////////////////////// - - if (pHandler->getId() != id) - AUDIO_IO_LOGW("Id is different, why? [mId : %d]", pHandler->getId()); - - if (session_option & MM_SESSION_OPTION_UNINTERRUPTIBLE) { - AUDIO_IO_LOGD("Session option is uninterruptible, skip..."); - return; - } - - if (state == FOCUS_IS_RELEASED) { - // Focus handle(id) was released, do pause here - internalLock(); - if (mpPulseAudioClient) - mpPulseAudioClient->cork(true); - - mIsInterrupted = true; - internalUnlock(); - } else if (state == FOCUS_IS_ACQUIRED) { - // Focus handle(id) was acquired again, - // check reason_for_change ("call-voice","call-video","voip","alarm","notification", ...) - // do resume here and call interrupt completed callback to application. - } - } - - if (mInterruptCallback.onInterrupt != NULL) { - IAudioSessionEventListener::EInterruptCode e = IAudioSessionEventListener::EInterruptCode::INTERRUPT_COMPLETED; - e = IAudioSessionEventListener::convertInterruptedCode(state, reason_for_change); - - if (EInterruptCode::INTERRUPT_COMPLETED == e) { - mInterruptCode = e; - g_idle_add(caudio_gsource_callback, this); - } else { - mInterruptCallback.onInterrupt(e, mInterruptCallback.mUserData); - } - } -} - -void CAudioIO::onSignal(CAudioSessionHandler* pHandler, mm_sound_signal_name_t signal, int value) { - assert(pHandler); - - if (signal == MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS) { - if (value == 1 && pHandler->getSubscribeId() > 0) { - // Unregister focus watch callback & disable session handler - pHandler->disableSessionHandler(); - AUDIO_IO_LOGD("Session handler disabled by signal"); - } else if (value == 0) { - // Currently do nothing... - } - } -} - void CAudioIO::prepare() { if (__mIsInit == false) THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO"); - - try { - if (mIsInterrupted) { - internalSessionLock(); - AUDIO_IO_LOGE("This is preparing during interrupted!!!"); - if (isSessionEnabled() && __mForceIgnore == false) { - AUDIO_IO_LOGE("Session updatePlaying!!!"); - mpAudioSessionHandler->updatePlaying(); - } - internalSessionUnlock(); - } - } catch (CAudioError& e) { - internalSessionUnlock(); - throw; - } - - if (mIsInterrupted) { - if (mpPulseAudioClient && mpPulseAudioClient->isCorked()) { - AUDIO_IO_LOGE("Uncork!"); - mpPulseAudioClient->cork(false); - } - mIsInterrupted = false; - } } void CAudioIO::unprepare() { @@ -507,37 +326,6 @@ CAudioIO::SStateChangedCallback CAudioIO::getStateChangedCallback() { return mStateChangedCallback; } -void CAudioIO::setInterruptCallback(SInterruptCallback callback) { - if (__mIsInit == false) - THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO"); - - mInterruptCallback = callback; -} - -CAudioIO::SInterruptCallback CAudioIO::getInterruptCallback() { - if (__mIsInit == false) - THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO"); - - return mInterruptCallback; -} - -void CAudioIO::ignoreSession() { - if (__mIsInit == false) - THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO"); - - 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(); - throw; - } -} - void CAudioIO::setStreamInfo(sound_stream_info_h stream_info) { if (stream_info == NULL) THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_ARGUMENT, "stream_info is NULL"); @@ -549,8 +337,6 @@ void CAudioIO::setStreamInfo(sound_stream_info_h stream_info) { if (mState != CAudioInfo::EAudioIOState::AUDIO_IO_STATE_IDLE) THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_STATE, "it is not permitted while started"); - abandonInternalFocus(); - int errorCode = SOUND_MANAGER_ERROR_NONE; CAudioInfo::EAudioType audioType = CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA; char *type = NULL; @@ -577,46 +363,4 @@ void CAudioIO::setStreamInfo(sound_stream_info_h stream_info) { } catch (CAudioError& e) { throw; } -} - -void CAudioIO::setInternalStreamInfo() { - if (__mIsInit == false) - THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO"); - - 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) { - mpAudioSessionHandler->getInternalVoipStreamInfo(&stream_info); - AUDIO_IO_LOGD("get internal VOIP stream info(%p)", 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() { - try { - internalSessionLock(); - if (isSessionEnabled()) { - mpAudioSessionHandler->unregisterSound(); - mpAudioSessionHandler->finalize(); /* FIXME : SAFE_FINALIZE or SAFE_DELETE? */ - } - __mForceIgnore = true; - internalSessionUnlock(); - } catch (CAudioError& e) { - internalSessionUnlock(); - throw; - } -} +} \ No newline at end of file diff --git a/src/cpp/CAudioInput.cpp b/src/cpp/CAudioInput.cpp index 903ee7d..ecae45c 100644 --- a/src/cpp/CAudioInput.cpp +++ b/src/cpp/CAudioInput.cpp @@ -79,22 +79,6 @@ void CAudioInput::onStream(CPulseAudioClient* pClient, size_t length) { CAudioIO::onStream(pClient, length); } -void CAudioInput::onInterrupt(CAudioSessionHandler* pHandler, int id, mm_sound_focus_type_e focus_type, - mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info) { - assert(pHandler); - 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); -} - void CAudioInput::__setInit(bool flag) { __mIsInit = flag; } @@ -219,21 +203,6 @@ void CAudioInput::initialize() { if (__IsPrivilegeAllowed() == false) THROW_ERROR_MSG(CAudioError::EError::ERROR_PERMISSION_DENIED, "No privilege for record"); - try { - internalSessionLock(); - mpAudioSessionHandler = new CAudioSessionHandler(CAudioSessionHandler::EAudioSessionType::AUDIO_SESSION_TYPE_CAPTURE, mAudioInfo, this); - mpAudioSessionHandler->initialize(); - 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); } @@ -244,11 +213,6 @@ void CAudioInput::finalize() { return; } - internalSessionLock(); - SAFE_FINALIZE(mpAudioSessionHandler); - SAFE_DELETE(mpAudioSessionHandler); - internalSessionUnlock(); - CAudioIO::finalize(); __setInit(false); @@ -272,34 +236,6 @@ void CAudioInput::prepare() { "The audioType is invalid [type:%d]", static_cast(audioType)); try { - 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(); - - try { - internalSessionLock(); - if (isSessionEnabled() && isForceIgnore() == false) - mpAudioSessionHandler->updatePlaying(); - internalSessionUnlock(); - } catch (CAudioError& e) { - internalSessionUnlock(); - throw; - } - - try { /* Init StreamSpec */ AUDIO_IO_LOGD("Set Stream Spec : CPulseStreamSpec::STREAM_LATENCY_INPUT_DEFAULT"); CPulseStreamSpec::EStreamLatency streamSpec = CPulseStreamSpec::EStreamLatency::STREAM_LATENCY_INPUT_DEFAULT; @@ -350,17 +286,7 @@ void CAudioInput::unprepare() { throw; } - try { - internalSessionLock(); - if (isSessionEnabled() && isForceIgnore() == false) - mpAudioSessionHandler->updateStop(); - internalSessionUnlock(); - - CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_IDLE); - } catch (CAudioError& e) { - internalSessionUnlock(); - throw; - } + CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_IDLE); } void CAudioInput::pause() { @@ -450,8 +376,6 @@ size_t CAudioInput::read(void* buffer, size_t length) { try { internalLock(); - 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) diff --git a/src/cpp/CAudioOutput.cpp b/src/cpp/CAudioOutput.cpp index b5c239f..2de88a9 100644 --- a/src/cpp/CAudioOutput.cpp +++ b/src/cpp/CAudioOutput.cpp @@ -71,20 +71,6 @@ void CAudioOutput::onStream(CPulseAudioClient* pClient, size_t length) { CAudioIO::onStream(pClient, length); } -void CAudioOutput::onInterrupt(CAudioSessionHandler* pHandler, int id, mm_sound_focus_type_e focus_type, - mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info) { - assert(pHandler); - 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 CAudioOutput::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); -} - void CAudioOutput::__setInit(bool flag) { __mIsInit = flag; } @@ -108,21 +94,6 @@ void CAudioOutput::initialize() { throw; } - try { - internalSessionLock(); - mpAudioSessionHandler = new CAudioSessionHandler(CAudioSessionHandler::EAudioSessionType::AUDIO_SESSION_TYPE_PLAYBACK, mAudioInfo, this); - mpAudioSessionHandler->initialize(); - 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); } @@ -133,11 +104,6 @@ void CAudioOutput::finalize() { return; } - internalSessionLock(); - SAFE_FINALIZE(mpAudioSessionHandler); - SAFE_DELETE(mpAudioSessionHandler); - internalSessionUnlock(); - CAudioIO::finalize(); __setInit(false); @@ -161,34 +127,6 @@ void CAudioOutput::prepare() { "The audioType is invalid [type:%d]", static_cast(audioType)); try { - 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(); - - try { - internalSessionLock(); - if (isSessionEnabled() && isForceIgnore() == false) - mpAudioSessionHandler->updatePlaying(); - internalSessionUnlock(); - } catch (CAudioError& e) { - internalSessionUnlock(); - throw; - } - - try { /* Init StreamSpec */ CPulseStreamSpec::EStreamLatency streamSpec = CPulseStreamSpec::EStreamLatency::STREAM_LATENCY_OUTPUT_DEFAULT; #ifndef DISABLE_MOBILE_BACK_COMP @@ -233,20 +171,6 @@ void CAudioOutput::unprepare() { return; } - try { - internalSessionLock(); - if (isSessionEnabled() && - !mIsInterrupted && - !isForceIgnore() && - mStreamCallback.onStream == NULL) { - CAudioIO::drain(); - } - internalSessionUnlock(); - } catch (CAudioError& e) { - internalSessionUnlock(); - throw; - } - CAudioIO::unprepare(); try { @@ -261,17 +185,7 @@ void CAudioOutput::unprepare() { throw; } - try { - internalSessionLock(); - if (isSessionEnabled() && isForceIgnore() == false) - mpAudioSessionHandler->updateStop(); - internalSessionUnlock(); - - CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_IDLE); - } catch (CAudioError& e) { - internalSessionUnlock(); - throw; - } + CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_IDLE); } void CAudioOutput::pause() { @@ -362,8 +276,6 @@ size_t CAudioOutput::write(const void* buffer, size_t length) { 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) diff --git a/src/cpp/CAudioSessionHandler.cpp b/src/cpp/CAudioSessionHandler.cpp deleted file mode 100644 index ceaf3ce..0000000 --- a/src/cpp/CAudioSessionHandler.cpp +++ /dev/null @@ -1,657 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include "CAudioIODef.h" - - -using namespace std; -using namespace tizen_media_audio; - - -/** - * class CAudioSessionHandler - */ -int CAudioSessionHandler::__sCaptureRef = 0; - -int CAudioSessionHandler::__pcmCaptureCountInc() { - int actual; - do { - actual = __sCaptureRef; - } while (!__sync_bool_compare_and_swap(&__sCaptureRef, actual, actual + 1)); - AUDIO_IO_LOGD("CaptureRefCount+1 > [%d]", __sCaptureRef); - return __sCaptureRef; -} - -int CAudioSessionHandler::__pcmCaptureCountDec() { - int actual; - do { - actual = __sCaptureRef; - } while (!__sync_bool_compare_and_swap(&__sCaptureRef, actual, actual - 1)); - AUDIO_IO_LOGD("CaptureRefCount-1 > [%d]", __sCaptureRef); - if (__sCaptureRef < 0) { - AUDIO_IO_LOGE("A CaptureRef[%d] is not valid! Something is wrong!", __sCaptureRef); - __sCaptureRef = 0; - } - return __sCaptureRef; -} - -int CAudioSessionHandler::__pcmCaptureCountGet() { - AUDIO_IO_LOGD("CaptureRefCount > [%d]", __sCaptureRef); - return __sCaptureRef; -} - -int CAudioSessionHandler::__sFocusRef = 0; - -int CAudioSessionHandler::__focusIdCountInc() { - int actual; - do { - actual = __sFocusRef; - } while (!__sync_bool_compare_and_swap(&__sFocusRef, actual, actual + 1)); - AUDIO_IO_LOGD("FocusRefCount+1 > [%d]", __sFocusRef); - return __sFocusRef; -} - -int CAudioSessionHandler::__focusIdCountDec() { - int actual; - do { - actual = __sFocusRef; - } while (!__sync_bool_compare_and_swap(&__sFocusRef, actual, actual - 1)); - AUDIO_IO_LOGD("FocusRefCount-1 > [%d]", __sFocusRef); - return __sFocusRef; -} - -int CAudioSessionHandler::__focusIdCountGet() { - /* AUDIO_IO_LOGD("FocusRefCount > [%d]", __sFocusRef); */ - return __sFocusRef; -} - -void CAudioSessionHandler::__lockFocusIdMutex() { - 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) - 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) - 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) - 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 -} - -CAudioSessionHandler::CAudioSessionHandler(EAudioSessionType sessionType, CAudioInfo& audioInfo, IAudioSessionEventListener* listener) : - __mId(-1), - __mOptions(0), - __mAudioSession(sessionType), - __mMultimediaSession(MM_SESSION_TYPE_MEDIA), - __mpEventListener(listener), - __mIsInit(false), - __mSubscribeId(0), - __mUseFocus(false), - __mAcquiredFocus(FOCUS_NONE), - __mReasonForChange(NULL), - __mAdditionalInfo(NULL), - __mFocusIdMutex(PTHREAD_MUTEX_INITIALIZER), - __mFocusCBMutex(PTHREAD_MUTEX_INITIALIZER) { - __mAudioInfo = audioInfo; -} - -CAudioSessionHandler::~CAudioSessionHandler() { -} - -CAudioError CAudioSessionHandler::__convertStreamType(EAudioSessionType type1, MMSessionType type2, int *index) { - unsigned int i; - int idx = -1; - - assert(index != NULL); - - if (type1 == EAudioSessionType::AUDIO_SESSION_TYPE_CAPTURE) { - for (i = 0 ; i < sizeof(__STREAM_TYPE_TABLE_IN) / sizeof(__STREAM_TYPE_TABLE_IN[0]) ; i++) { - if (__STREAM_TYPE_TABLE_IN[i].type == type2) { - idx = i; - break; - } - } - } else { - for (i = 0 ; i < sizeof(__STREAM_TYPE_TABLE_OUT) / sizeof(__STREAM_TYPE_TABLE_OUT[0]) ; i++) { - if (__STREAM_TYPE_TABLE_OUT[i].type == type2) { - idx = i; - break; - } - } - } - - if (idx < 0) { - RET_ERROR_MSG(CAudioError::EError::ERROR_NOT_SUPPORTED, "Does not support session type."); - } - *index = idx; - RET_ERROR(CAudioError::EError::ERROR_NONE); -} - -CAudioError CAudioSessionHandler::__getAsmInformation(MMSessionType *type, int *options) { - assert(type != NULL); - assert(options != NULL); - - MMSessionType currentSession = MM_SESSION_TYPE_MEDIA; - int sessionOptions = 0; - - /* 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) - RET_ERROR_MSG(CAudioError::EError::ERROR_INVALID_HANDLE, "Failed _mm_session_util_read_information(). Invalid handle"); - else - RET_ERROR_MSG(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed _mm_session_util_read_information(). Not exist"); - } - - *type = currentSession; - *options = sessionOptions; - - RET_ERROR(CAudioError::EError::ERROR_NONE); -} - -bool CAudioSessionHandler::__isFocusRequired(MMSessionType type, int options) { - if ((options & MM_SESSION_OPTION_PAUSE_OTHERS) - || ((type != MM_SESSION_TYPE_MEDIA) && (type != MM_SESSION_TYPE_MEDIA_RECORD))) - return true; - else - return false; -} - -bool CAudioSessionHandler::__isFocusDisableReacquisitionRequired(MMSessionType type, int options) { - if ((type == MM_SESSION_TYPE_MEDIA) && - !(options & MM_SESSION_OPTION_RESUME_BY_SYSTEM_OR_MEDIA_PAUSED)) - return true; - - return false; -} - -bool CAudioSessionHandler::__checkNeedBlock(const char *focus_acquired_by) { - assert(focus_acquired_by != NULL); - - if (!strcmp(focus_acquired_by, "alarm") || - !strcmp(focus_acquired_by, "ringtone-voip") || - !strcmp(focus_acquired_by, "ringtone-call") || - !strcmp(focus_acquired_by, "voip") || - !strcmp(focus_acquired_by, "call-voice") || - !strcmp(focus_acquired_by, "call-video")) { - AUDIO_IO_LOGW("Blocked by session policy, focus_acquired_by[%s]", focus_acquired_by); - return true; - } - - return false; -} - -int CAudioSessionHandler::getId() { - return __mId; -} - -int CAudioSessionHandler::getOptions() { - return __mOptions; -} - -CAudioSessionHandler::EAudioSessionType CAudioSessionHandler::getAudioSession() { - return __mAudioSession; -} - -MMSessionType CAudioSessionHandler::getMultimediaSession() { - return __mMultimediaSession; -} - -void CAudioSessionHandler::getInternalVoipStreamInfo(sound_stream_info_h *stream_info) { -#if 0 - int ret; - if ((ret = sound_manager_get_internal_voip_stream_information(stream_info))) { - if (ret == SOUND_MANAGER_ERROR_NO_DATA) - AUDIO_IO_LOGW("there's no internal voip stream info."); - else - AUDIO_IO_LOGE("failed to sound_manager_get_internal_voip_stream_information(), ret(0x%x)", ret); - } -#endif - return; -} - -unsigned int CAudioSessionHandler::getSubscribeId() { - return __mSubscribeId; -} - -CAudioInfo CAudioSessionHandler::getAudioInfo() { - return __mAudioInfo; -} - -void CAudioSessionHandler::__sound_pcm_signal_cb(mm_sound_signal_name_t signal, int value, void *user_data) { - assert(user_data); - - AUDIO_IO_LOGD("[signal:%d], [value:%d], [user_data:%p]", signal, value, user_data); - - CAudioSessionHandler* pHandler = static_cast(user_data); - if (pHandler->__mpEventListener != NULL) - pHandler->__mpEventListener->onSignal(pHandler, signal, value); -} - -void CAudioSessionHandler::initialize() { - AUDIO_IO_LOGD(""); - if (__mIsInit == true) - return; - - MMSessionType currentSession = MM_SESSION_TYPE_MEDIA; - int sessionOptions = 0; // Mix with others by default - - CAudioError err = __getAsmInformation(¤tSession, &sessionOptions); - if (err == CAudioError::EError::ERROR_NONE) { - if (currentSession == MM_SESSION_TYPE_REPLACED_BY_STREAM) { - __mUseFocus = false; - AUDIO_IO_LOGD("Stream info. was created outside, skip audio focus concept internally!"); - } else { - // Session was configured before, use focus callback - __mUseFocus = true; - AUDIO_IO_LOGD("Use audio focus concept internally!"); - } - } else { - if (err == CAudioError::EError::ERROR_INVALID_HANDLE) { - // No session, No stream_info, No focus watch callback before - // 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(this)); - 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); - - sessionOptions = 0; // Mix with others by default - __mUseFocus = true; - AUDIO_IO_LOGD("Use audio focus(watch) concept internally!"); - } else { - __mUseFocus = false; - AUDIO_IO_LOGD("Skip audio focus concept!"); - } - - if (__mAudioSession == EAudioSessionType::AUDIO_SESSION_TYPE_CAPTURE) { - AUDIO_IO_LOGD("Set default \"Media_Record\" type"); - currentSession = MM_SESSION_TYPE_MEDIA_RECORD; - } else { - AUDIO_IO_LOGD("Set default \"Media\" type"); - currentSession = MM_SESSION_TYPE_MEDIA; - } - } - - // Updates session information - __mMultimediaSession = currentSession; - __mOptions = sessionOptions; - - if (this->__mAudioSession == EAudioSessionType::AUDIO_SESSION_TYPE_CAPTURE) - __pcmCaptureCountInc(); - - __mIsInit = true; -} - -void CAudioSessionHandler::finalize() { - AUDIO_IO_LOGD(""); - if (__mIsInit == false) - return; - - if (__mAudioSession == EAudioSessionType::AUDIO_SESSION_TYPE_CAPTURE) - __pcmCaptureCountDec(); - - unregisterSound(); - - if (__mSubscribeId > 0) { - AUDIO_IO_LOGD("Unsubscribed mm_sound signal [id:%d]", __mSubscribeId); - mm_sound_unsubscribe_signal(__mSubscribeId); - __mSubscribeId = 0; - } - - __mpEventListener = NULL; - - __mIsInit = false; -} - -bool CAudioSessionHandler::isSkipSession() { - if (__mMultimediaSession == MM_SESSION_TYPE_REPLACED_BY_STREAM || - __mMultimediaSession == MM_SESSION_TYPE_VOIP || - __mMultimediaSession == MM_SESSION_TYPE_CALL || - __mMultimediaSession == MM_SESSION_TYPE_VIDEOCALL) { - AUDIO_IO_LOGD("__mMultimediaSession is [%d], skip session", __mMultimediaSession); - return true; - } - - return false; -} - -void CAudioSessionHandler::__sound_pcm_focus_cb(int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, - const char *reason_for_change, int option, const char *additional_info, void *user_data) { - assert(user_data); - - AUDIO_IO_LOGD("[id:%d], [focus_type:%d], [state:%d], [reason_for_change:%s], [additional_info:%s], [user_data:%p]", - id, focus_type, state, reason_for_change, additional_info, user_data); - -/* FIXME: disable it temporarily */ -#ifndef DISABLE_SESSION_BACK_COMP - - CAudioSessionHandler* pHandler = static_cast(user_data); - - pHandler->__lockFocusCBMutex(); - - if (state == FOCUS_IS_RELEASED) - pHandler->__mAcquiredFocus &= ~focus_type; - else if (state == FOCUS_IS_ACQUIRED) - pHandler->__mAcquiredFocus |= focus_type; - pHandler->__mReasonForChange = (char *)reason_for_change; - pHandler->__mAdditionalInfo = (char *)additional_info; - - if (pHandler->__mpEventListener != NULL) - pHandler->__mpEventListener->onInterrupt(pHandler, id, focus_type, state, reason_for_change, additional_info); - - pHandler->__unlockFocusCBMutex(); -#endif - return; -} - -void CAudioSessionHandler::__sound_pcm_focus_watch_cb(int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, - const char *reason_for_change, const char *additional_info, void *user_data) { - AUDIO_IO_LOGD("[id:%d], [focus_type:%d], [state:%d], [reason_for_change:%s], [additional_info:%s], [user_data:%p]", - id, focus_type, state, reason_for_change, additional_info, user_data); - - CAudioSessionHandler::__sound_pcm_focus_cb(-1, focus_type, state, reason_for_change, 0, additional_info, user_data); - - return; -} - -void CAudioSessionHandler::registerSound() { - if (__mIsInit == false) - THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioSessionHandler"); - - if (__mUseFocus == true) { - __lockFocusIdMutex(); - if (__mId >= 0) { - __unlockFocusIdMutex(); - THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_POLICY_BLOCKED, "Already registered [id:%d]", __mId); - } - - int errorCode = 0; - - if (__isFocusRequired(__mMultimediaSession, __mOptions)) { - int index = 0; - - CAudioError err = __convertStreamType(__mAudioSession, __mMultimediaSession, &index); - if (err != CAudioError::EError::ERROR_NONE) { - __unlockFocusIdMutex(); - throw err; - } - - errorCode = mm_sound_focus_get_id(&__mId); - if (errorCode != MM_ERROR_NONE) { - __unlockFocusIdMutex(); - THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed mm_sound_focus_get_id() err:0x%x", errorCode); - } - - // Register focus callback - errorCode = mm_sound_register_focus_for_session(__mId, - getpid(), - __mAudioSession == EAudioSessionType::AUDIO_SESSION_TYPE_CAPTURE ? __STREAM_TYPE_TABLE_IN[index].name : __STREAM_TYPE_TABLE_OUT[index].name, - __sound_pcm_focus_cb, - static_cast(this)); - if (errorCode != MM_ERROR_NONE) { - __unlockFocusIdMutex(); - THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed mm_sound_register_focus_for_session() err:0x%x", errorCode); - } - - if (__isFocusDisableReacquisitionRequired(__mMultimediaSession, __mOptions)) { - errorCode = mm_sound_set_focus_reacquisition_for_session(__mId, false); - if (errorCode != MM_ERROR_NONE) { - __unlockFocusIdMutex(); - THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed mm_sound_set_focus_reacquisition() err:0x%x", errorCode); - } - } - - __focusIdCountInc(); - - AUDIO_IO_LOGD("Focus callback registered successfully [id:%d]", __mId); - } else if (!(__mOptions & MM_SESSION_OPTION_UNINTERRUPTIBLE)) { - // Register focus watch callback - errorCode = mm_sound_set_focus_watch_callback_for_session(getpid(), FOCUS_FOR_BOTH, __sound_pcm_focus_watch_cb, static_cast(this), &__mId); - if (errorCode < 0) { - __unlockFocusIdMutex(); - THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed mm_sound_set_focus_watch_callback_for_session() err:0x%x", errorCode); - } - - __focusIdCountInc(); - - AUDIO_IO_LOGD("Focus watch callback registered successfully [id:%d]", __mId); - } - __unlockFocusIdMutex(); - } -} - -void CAudioSessionHandler::unregisterSound() { - if (__mIsInit == false) - THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioSessionHandler"); - - __lockFocusIdMutex(); - if (__mUseFocus == true && __mId >= 0) { - int errorCode = 0; - - if (__isFocusRequired(__mMultimediaSession, __mOptions)) { - // Unregister focus callback - errorCode = mm_sound_unregister_focus(__mId); - if (errorCode != MM_ERROR_NONE) { - __unlockFocusIdMutex(); - THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed mm_sound_unregister_focus() err:0x%x", errorCode); - } - - __focusIdCountDec(); - - AUDIO_IO_LOGD("Focus callback unregistered successfully [id:%d]", __mId); - __mId = -1; - } else if (!(__mOptions & MM_SESSION_OPTION_UNINTERRUPTIBLE)) { - // Unregister focus watch callback. - errorCode = mm_sound_unset_focus_watch_callback(__mId); - if (errorCode < 0) { - __unlockFocusIdMutex(); - THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed mm_sound_unset_focus_watch_callback() err:0x%x", errorCode); - } - - __focusIdCountDec(); - - AUDIO_IO_LOGD("Focus watch callback unregistered successfully [id:%d]", __mId); - __mId = -1; - } - __mAcquiredFocus = FOCUS_NONE; - } - __unlockFocusIdMutex(); -} - -void CAudioSessionHandler::updatePlaying() { - if (__mIsInit == false) - THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioSessionHandler"); - - __lockFocusIdMutex(); - if (!__mUseFocus || __mId < 0) { - __unlockFocusIdMutex(); - return; - } - - if (__mUseFocus && __isFocusRequired(__mMultimediaSession, __mOptions)) { - if (__mId >= 0) { - int ret = MM_ERROR_NONE; - int focus_type = 0; - bool is_focus_cb_thread; - - if ((ret = mm_sound_focus_is_cb_thread(&is_focus_cb_thread))) { - __unlockFocusIdMutex(); - THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INTERNAL_OPERATION, "Failed mm_sound_focus_is_cb_thread() err:0x%x", ret); - } - - if (!is_focus_cb_thread) - __lockFocusCBMutex(); - - if (__mAcquiredFocus == FOCUS_FOR_BOTH) { - AUDIO_IO_LOGW("Focus was already acquired, skip it..."); - if (!is_focus_cb_thread) - __unlockFocusCBMutex(); - __unlockFocusIdMutex(); - return; - } - - focus_type |= (FOCUS_FOR_BOTH & ~__mAcquiredFocus); - if (__mMultimediaSession == MM_SESSION_TYPE_MEDIA) - ret = mm_sound_acquire_focus_with_option(__mId, (mm_sound_focus_type_e)focus_type, 1, "audio-io acquire focus"); /* option: 1 for no-resume */ - else - ret = mm_sound_acquire_focus(__mId, (mm_sound_focus_type_e)focus_type, "audio-io acquire focus"); - if (ret != MM_ERROR_NONE) { - if (!is_focus_cb_thread) - __unlockFocusCBMutex(); - __unlockFocusIdMutex(); - THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_POLICY_BLOCKED, "Failed mm_sound_acquire_focus() err:0x%x", ret); - } - __mAcquiredFocus = FOCUS_FOR_BOTH; - AUDIO_IO_LOGD("Focus acquired successfully [id:%d]", __mId); - - if (!is_focus_cb_thread) - __unlockFocusCBMutex(); - } - } else { - int ret = MM_ERROR_NONE; - char *stream_type = NULL; - char *ext_info = NULL; - int option = 0; - - if ((ret = mm_sound_get_stream_type_of_acquired_focus(FOCUS_FOR_BOTH, &stream_type, &option, &ext_info))) { - __unlockFocusIdMutex(); - return; - } - - AUDIO_IO_LOGD("Focus is acquired by stream_type[%s], option[%d], ext_info[%s]", stream_type, option, ext_info); - - if (__checkNeedBlock((const char*)stream_type)) { - free(stream_type); - free(ext_info); - __unlockFocusIdMutex(); - THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_POLICY_BLOCKED, "Blocked by an acquired focus"); - } - free(stream_type); - free(ext_info); - } - __unlockFocusIdMutex(); -} - -void CAudioSessionHandler::updateStop() { - if (__mIsInit == false) - THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioSessionHandler"); - - if (__mUseFocus && __isFocusRequired(__mMultimediaSession, __mOptions)) { - __lockFocusIdMutex(); - if (__mId >= 0) { - int ret = MM_ERROR_NONE; - bool is_focus_cb_thread; - - if ((ret = mm_sound_focus_is_cb_thread(&is_focus_cb_thread))) { - __unlockFocusIdMutex(); - THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INTERNAL_OPERATION, "Failed mm_sound_focus_is_cb_thread() err:0x%x", ret); - } - - if (!is_focus_cb_thread) - __lockFocusCBMutex(); - - if (__mAcquiredFocus == FOCUS_NONE) { - AUDIO_IO_LOGW("Focus was already released, skip it..."); - if (!is_focus_cb_thread) - __unlockFocusCBMutex(); - __unlockFocusIdMutex(); - return; - } - - if (__mMultimediaSession == MM_SESSION_TYPE_MEDIA) - ret = mm_sound_release_focus_with_option(__mId, (mm_sound_focus_type_e)__mAcquiredFocus, 1, "audio-io release focus"); /* option: 1 for no-resume */ - else - ret = mm_sound_release_focus(__mId, (mm_sound_focus_type_e)__mAcquiredFocus, "audio-io release focus"); - if (ret != MM_ERROR_NONE) { - if (!is_focus_cb_thread) - __unlockFocusCBMutex(); - __unlockFocusIdMutex(); - THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed mm_sound_release_focus() err:0x%x", ret); - } - __mAcquiredFocus = FOCUS_NONE; - AUDIO_IO_LOGD("Focus released successfully [id:%d]", __mId); - - if (!is_focus_cb_thread) - __unlockFocusCBMutex(); - } - __unlockFocusIdMutex(); - } -} - -void CAudioSessionHandler::disableSessionHandler() { - CAudioSessionHandler::updateStop(); - CAudioSessionHandler::unregisterSound(); - - CAudioSessionHandler::__mUseFocus = false; -} - -/** - * class IAudioSessionEventListener - */ -IAudioSessionEventListener::EInterruptCode IAudioSessionEventListener::convertInterruptedCode(int code, const char *reason_for_change) { - EInterruptCode e = EInterruptCode::INTERRUPT_BY_MEDIA; - - switch (code) { - case FOCUS_IS_ACQUIRED: - e = EInterruptCode::INTERRUPT_COMPLETED; - break; - - case FOCUS_IS_RELEASED: - if (!strcmp(reason_for_change, "media")) e = EInterruptCode::INTERRUPT_BY_MEDIA; - if (!strcmp(reason_for_change, "radio")) e = EInterruptCode::INTERRUPT_BY_MEDIA; - if (!strcmp(reason_for_change, "loopback")) e = EInterruptCode::INTERRUPT_BY_MEDIA; - if (!strcmp(reason_for_change, "system")) e = EInterruptCode::INTERRUPT_BY_MEDIA; - if (!strcmp(reason_for_change, "alarm")) e = EInterruptCode::INTERRUPT_BY_ALARM; - if (!strcmp(reason_for_change, "notification")) e = EInterruptCode::INTERRUPT_BY_NOTIFICATION; - if (!strcmp(reason_for_change, "emergency")) e = EInterruptCode::INTERRUPT_BY_EMERGENCY; - if (!strcmp(reason_for_change, "voice-information")) e = EInterruptCode::INTERRUPT_BY_MEDIA; - if (!strcmp(reason_for_change, "voice-recognition")) e = EInterruptCode::INTERRUPT_BY_MEDIA; - if (!strcmp(reason_for_change, "voice-recognition-service")) e = EInterruptCode::INTERRUPT_BY_MEDIA; - if (!strcmp(reason_for_change, "ringtone-voip")) e = EInterruptCode::INTERRUPT_BY_CALL; - if (!strcmp(reason_for_change, "ringtone-call")) e = EInterruptCode::INTERRUPT_BY_CALL; - if (!strcmp(reason_for_change, "voip")) e = EInterruptCode::INTERRUPT_BY_CALL; - if (!strcmp(reason_for_change, "call-voice")) e = EInterruptCode::INTERRUPT_BY_CALL; - if (!strcmp(reason_for_change, "call-video")) e = EInterruptCode::INTERRUPT_BY_CALL; - break; - } - - return e; -} diff --git a/src/cpp/CPulseAudioPolicy.cpp b/src/cpp/CPulseAudioPolicy.cpp deleted file mode 100644 index 1477b81..0000000 --- a/src/cpp/CPulseAudioPolicy.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#if 0 -#include "CAudioIODef.h" - - -using namespace std; -using namespace tizen_media_audio; - - -/** - * class CPulseAudioPolicy - */ -CPulseAudioPolicy::CPulseAudioPolicy() : - __mPolicy(EPolicy::POLICY_DEFAULT) { -} - -CPulseAudioPolicy::CPulseAudioPolicy(EPolicy policy) : - __mPolicy(policy) { -} - -CPulseAudioPolicy::~CPulseAudioPolicy() { -} - -void CPulseAudioPolicy::setPolicy(EPolicy policy) { - if (policy < EPolicy::POLICY_DEFAULT || policy >= EPolicy::POLICY_MAX) { - THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_ARGUMENT, "The argument is out of range"); - } - - __mPolicy = policy; -} - -CPulseAudioPolicy::EPolicy CPulseAudioPolicy::getPolicy() { - return __mPolicy; -} - -bool CPulseAudioPolicy::operator != (const EPolicy policy) { - return (__mPolicy != policy); -} - -bool CPulseAudioPolicy::operator == (const EPolicy policy) { - return (__mPolicy == policy); -} -#endif diff --git a/src/cpp/CPulseAudioVolume.cpp b/src/cpp/CPulseAudioVolume.cpp deleted file mode 100644 index 66a3330..0000000 --- a/src/cpp/CPulseAudioVolume.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#if 0 -#include "CAudioIODef.h" - - -using namespace std; -using namespace tizen_media_audio; - - -/** - * class CPulseAudioVolume - */ -CPulseAudioVolume::CPulseAudioVolume() : __mVolume(EVolume::VOLUME_MEDIA), __mVolumeGain(EVolumeGain::VOLUME_GAIN_DEFAULT) { -} - -CPulseAudioVolume::CPulseAudioVolume(EVolume volume, EVolumeGain gain) : - __mVolume(volume), - __mVolumeGain(gain) { -} - -CPulseAudioVolume::~CPulseAudioVolume() { -} - -void CPulseAudioVolume::setVolume(EVolume volume) { - __mVolume = volume; -} - -CPulseAudioVolume::EVolume CPulseAudioVolume::getVolume() { - return __mVolume; -} - -void CPulseAudioVolume::setVolumeGain(EVolumeGain volumeGain) { - __mVolumeGain = volumeGain; -} - -CPulseAudioVolume::EVolumeGain CPulseAudioVolume::getVolumeGain() { - return __mVolumeGain; -} -#endif diff --git a/src/cpp/cpp_audio_io.cpp b/src/cpp/cpp_audio_io.cpp index b3d12b7..309e73d 100644 --- a/src/cpp/cpp_audio_io.cpp +++ b/src/cpp/cpp_audio_io.cpp @@ -18,7 +18,6 @@ #include #include "cpp_audio_io.h" -#include #include "audio_io.h" #include "CAudioIODef.h" @@ -29,21 +28,6 @@ using namespace std; using namespace tizen_media_audio; - -/** - * Defines Structures - * type : struct - * Name : audio_io_interrupted_cb_s - * Declaration : Keeps user callback pointer and user data for delivering an interrupt event - */ -typedef struct audio_io_interrupted_cb_s { - void* user_data; - audio_io_interrupted_cb onInterrupt; - - audio_io_interrupted_cb_s() : user_data(NULL), onInterrupt(NULL) - {/* Empty Body */} -} audio_io_interrupted_cb_s; - /** * Defines Structures * type : struct @@ -83,7 +67,6 @@ typedef struct audio_io_state_changed_cb_s { */ 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; @@ -328,17 +311,6 @@ static CAudioInfo __generate_audio_input_info(int sampleRate, audio_channel_e ch return CAudioInfo(sampleRate, dstChannel, dstSampleType, dstAudioType, -1); } -static CAudioInfo __generate_audio_input_loopback_info(int sampleRate, audio_channel_e channel, audio_sample_type_e sample_type) { - CAudioInfo::EChannel dstChannel; - CAudioInfo::ESampleType dstSampleType; - 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); - - return CAudioInfo(sampleRate, dstChannel, dstSampleType, dstAudioType, -1); -} - 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::ESampleType dstSampleType; @@ -351,29 +323,6 @@ static CAudioInfo __generate_audio_output_info(int sampleRate, audio_channel_e c return CAudioInfo(sampleRate, dstChannel, dstSampleType, dstAudioType, -1); } -static audio_io_interrupted_code_e __convert_interrupted_code(IAudioSessionEventListener::EInterruptCode code) { - switch (code) { - case IAudioSessionEventListener::EInterruptCode::INTERRUPT_COMPLETED: - return AUDIO_IO_INTERRUPTED_COMPLETED; - case IAudioSessionEventListener::EInterruptCode::INTERRUPT_BY_CALL: - return AUDIO_IO_INTERRUPTED_BY_CALL; - case IAudioSessionEventListener::EInterruptCode::INTERRUPT_BY_EARJACK_UNPLUG: - return AUDIO_IO_INTERRUPTED_BY_EARJACK_UNPLUG; - case IAudioSessionEventListener::EInterruptCode::INTERRUPT_BY_RESOURCE_CONFLICT: - return AUDIO_IO_INTERRUPTED_BY_RESOURCE_CONFLICT; - case IAudioSessionEventListener::EInterruptCode::INTERRUPT_BY_ALARM: - return AUDIO_IO_INTERRUPTED_BY_ALARM; - case IAudioSessionEventListener::EInterruptCode::INTERRUPT_BY_EMERGENCY: - return AUDIO_IO_INTERRUPTED_BY_EMERGENCY; - case IAudioSessionEventListener::EInterruptCode::INTERRUPT_BY_NOTIFICATION: - return AUDIO_IO_INTERRUPTED_BY_NOTIFICATION; - case IAudioSessionEventListener::EInterruptCode::INTERRUPT_BY_MEDIA: - case IAudioSessionEventListener::EInterruptCode::INTERRUPT_MAX: - default: - return AUDIO_IO_INTERRUPTED_BY_MEDIA; - } -} - static void __handle_safe_free(audio_io_s* handle, void *obj, bool is_output) { VALID_POINTER_START(handle) SAFE_FINALIZE(handle->audioIoHandle); @@ -436,32 +385,7 @@ int cpp_audio_in_create(int sample_rate, audio_channel_e channel, audio_sample_t } 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) - THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, - "Parameters are NULL input:%p", input); - - __check_audio_param(sample_rate, channel, type); - 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; - } catch (CAudioError& e) { - AUDIO_IO_LOGE("%s", e.getErrorMsg()); - __handle_safe_free(handle, (void *)input, false); - return __convert_CAudioError(e); - } catch (const std::bad_alloc&) { - CAudioError e = CAudioError::EError::ERROR_OUT_OF_MEMORY; - AUDIO_IO_LOGE("Failed to allocate handle"); - __handle_safe_free(handle, (void *)input, false); - return __convert_CAudioError(e); - } - - return AUDIO_IO_ERROR_NONE; + return AUDIO_IO_ERROR_NOT_SUPPORTED; } int cpp_audio_in_destroy(audio_in_h input) { @@ -749,96 +673,16 @@ int cpp_audio_in_get_sample_type(audio_in_h input, audio_sample_type_e *type) { return AUDIO_IO_ERROR_NONE; } -static void __interrupt_cb_internal(IAudioSessionEventListener::EInterruptCode _code, void* user_data) { - audio_io_s* handle = static_cast(user_data); - audio_io_interrupted_code_e code = __convert_interrupted_code(_code); - - assert(handle); - - 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(input); - - try { - 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; - - CAudioIO::SInterruptCallback cb = handle->audioIoHandle->getInterruptCallback(); - cb.mUserData = static_cast(handle); - cb.onInterrupt = __interrupt_cb_internal; - - handle->audioIoHandle->setInterruptCallback(cb); - } catch (CAudioError& e) { - AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); - } - - AUDIO_IO_LOGD("[%p] done", handle); - - return AUDIO_IO_ERROR_NONE; + return AUDIO_IO_ERROR_NOT_SUPPORTED; } int cpp_audio_in_unset_interrupted_cb(audio_in_h input) { - audio_io_s* handle = static_cast(input); - - try { - 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; - - CAudioIO::SInterruptCallback cb = handle->audioIoHandle->getInterruptCallback(); - cb.mUserData = NULL; - cb.onInterrupt = NULL; - - handle->audioIoHandle->setInterruptCallback(cb); - } catch (CAudioError& e) { - AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); - } - - AUDIO_IO_LOGD("[%p] done", handle); - - return AUDIO_IO_ERROR_NONE; + return AUDIO_IO_ERROR_NOT_SUPPORTED; } int cpp_audio_in_ignore_session(audio_in_h input) { - audio_io_s* handle = static_cast(input); - - try { - if (handle == NULL) - THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, - "Parameters are NULL input:%p", input); - 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) { - AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); - } - - AUDIO_IO_LOGD("[%p] done", handle); - - return AUDIO_IO_ERROR_NONE; + return AUDIO_IO_ERROR_NOT_SUPPORTED; } static void __stream_cb_internal(size_t nbytes, void *user_data) { @@ -1024,35 +868,7 @@ int cpp_audio_in_unset_state_changed_cb(audio_in_h input) { * Audio Out */ 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) - THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, - "Parameters are NULL output:%p", output); - - __check_audio_param(sample_rate, channel, type, sound_type); - - 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()); - __handle_safe_free(handle, (void *)output, true); - return __convert_CAudioError(e); - } catch (const std::bad_alloc&) { - CAudioError e = CAudioError::EError::ERROR_OUT_OF_MEMORY; - AUDIO_IO_LOGE("Failed to allocate handle"); - __handle_safe_free(handle, (void *)output, true); - return __convert_CAudioError(e); - } - - return AUDIO_IO_ERROR_NONE; + return AUDIO_IO_ERROR_NOT_SUPPORTED; } int cpp_audio_out_create_new(int sample_rate, audio_channel_e channel, audio_sample_type_e type, audio_out_h *output) { @@ -1394,83 +1210,15 @@ int cpp_audio_out_get_sound_type(audio_out_h output, sound_type_e *type) { } int cpp_audio_out_set_interrupted_cb(audio_out_h output, audio_io_interrupted_cb callback, void *user_data) { - audio_io_s* handle = static_cast(output); - - try { - 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(handle); - cb.onInterrupt = __interrupt_cb_internal; - - handle->audioIoHandle->setInterruptCallback(cb); - } catch (CAudioError& e) { - AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); - } - - AUDIO_IO_LOGD("[%p] done", handle); - - return AUDIO_IO_ERROR_NONE; + return AUDIO_IO_ERROR_NOT_SUPPORTED; } int cpp_audio_out_unset_interrupted_cb(audio_out_h output) { - audio_io_s* handle = static_cast(output); - - try { - 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; - - CAudioIO::SInterruptCallback cb = handle->audioIoHandle->getInterruptCallback(); - cb.mUserData = NULL; - cb.onInterrupt = NULL; - - handle->audioIoHandle->setInterruptCallback(cb); - } catch (CAudioError& e) { - AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); - } - - AUDIO_IO_LOGD("[%p] done", handle); - - return AUDIO_IO_ERROR_NONE; + return AUDIO_IO_ERROR_NOT_SUPPORTED; } int cpp_audio_out_ignore_session(audio_out_h output) { - audio_io_s* handle = static_cast(output); - - try { - if (handle == NULL) - THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, - "Parameters are NULL output:%p", output); - 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) { - AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); - } - - AUDIO_IO_LOGD("[%p] done", handle); - - return AUDIO_IO_ERROR_NONE; + return AUDIO_IO_ERROR_NOT_SUPPORTED; } int cpp_audio_out_set_stream_cb(audio_out_h output, audio_out_stream_cb callback, void* user_data) { diff --git a/test/audio_io_test.c b/test/audio_io_test.c index 3b5d98f..61ea8eb 100644 --- a/test/audio_io_test.c +++ b/test/audio_io_test.c @@ -225,12 +225,6 @@ int audio_io_loopback_in_test() } if ((ret = audio_in_create(16000, AUDIO_CHANNEL_MONO, AUDIO_SAMPLE_TYPE_S16_LE, &input)) == AUDIO_IO_ERROR_NONE) { - ret = audio_in_ignore_session(input); - if (ret != 0) { - printf("ERROR, set session mix\n"); - goto exit; - } - ret = audio_in_prepare(input); if (ret != 0) { printf("ERROR, prepare\n"); @@ -278,7 +272,7 @@ int audio_io_loopback_test() } ret = audio_out_create_new(16000, AUDIO_CHANNEL_MONO, AUDIO_SAMPLE_TYPE_S16_LE, &output); if (ret != AUDIO_IO_ERROR_NONE) { - printf("audio_out_create failed. \n"); + printf("audio_out_create_new failed. \n"); goto exit; } @@ -508,16 +502,16 @@ int audio_io_async_test(int mode) } if (write_mode) { - printf("before audio_out_create\n"); + printf("before audio_out_create_new\n"); getchar(); - printf("audio_out_create\n"); + printf("audio_out_create_new\n"); ret = audio_out_create_new(44100, AUDIO_CHANNEL_STEREO, AUDIO_SAMPLE_TYPE_S16_LE, &output); if (ret != AUDIO_IO_ERROR_NONE) { - printf("audio_out_create failed. \n"); + printf("audio_out_create_new failed. \n"); goto EXIT; } - printf("audio_out_create success!!! [%p]\n", output); + printf("audio_out_create_new success!!! [%p]\n", output); ret = audio_out_set_stream_cb(output, _audio_io_stream_write_cb, NULL); if (ret != AUDIO_IO_ERROR_NONE) {