2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License)
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 #include <sound_manager.h>
21 #include <FBaseSysLog.h>
22 #include <FMediaAudioManagerTypes.h>
23 #include "FMedia_AudioManagerConvert.h"
24 #include "FMedia_VoipAudioSessionManagerImpl.h"
26 using namespace Tizen::Base;
27 using namespace Tizen::Base::Runtime;
29 namespace Tizen { namespace Media {
31 _VoipAudioSessionManagerImpl* _VoipAudioSessionManagerImpl::__pVoipAudioSessionManagerImpl = null;
33 _VoipAudioSessionManagerImpl::_VoipAudioSessionManagerImpl()
34 :__soundCallSessionHandle(null)
39 _VoipAudioSessionManagerImpl::~_VoipAudioSessionManagerImpl(void)
41 int ret = SOUND_MANAGER_ERROR_NONE;
43 if (__soundCallSessionHandle != null)
45 ret = sound_manager_call_session_destroy(__soundCallSessionHandle);
46 r = _AudioManagerConvert::CovertSoundManagerError2Result(ret);
47 SysTryLog(NID_MEDIA, r == E_SUCCESS,
48 "[%s] Failed to perform sound_manager_call_session_destroy operation.", GetErrorMessage(r));
49 __soundCallSessionHandle = null;
54 _VoipAudioSessionManagerImpl::InitVoipAudioSessionManagerImpl(void)
56 static _VoipAudioSessionManagerImpl instance;
57 __pVoipAudioSessionManagerImpl = &instance;
60 _VoipAudioSessionManagerImpl*
61 _VoipAudioSessionManagerImpl::GetInstance(void)
64 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
65 if (__pVoipAudioSessionManagerImpl == null)
67 pthread_once(&onceBlock, InitVoipAudioSessionManagerImpl);
69 return __pVoipAudioSessionManagerImpl;
73 _VoipAudioSessionManagerImpl::EnterCallSession(void)
75 int ret = SOUND_MANAGER_ERROR_NONE;
77 SysTryReturn(NID_MEDIA, __soundCallSessionHandle == null , E_INVALID_OPERATION, E_INVALID_OPERATION,
78 "[E_INVALID_OPERATION] A error has been occurred. The value of __soundCallSessionHandle is not null.");
80 ret = sound_manager_call_session_create(SOUND_SESSION_TYPE_VOIP, &__soundCallSessionHandle);
81 r = _AudioManagerConvert::CovertSoundManagerError2Result(ret);
82 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r,
83 "[%s] Failed to perform sound_manager_get_a2dp_status operation with error code : 0x%x", GetErrorMessage(r), ret);
84 SysTryCatch(NID_MEDIA, __soundCallSessionHandle != null, r = E_SYSTEM, E_SYSTEM,
85 "[E_SYSTEM] A system error has been occurred. The value of __soundCallSessionHandle is null.");
89 if (__soundCallSessionHandle)
91 sound_manager_call_session_destroy(__soundCallSessionHandle);
92 __soundCallSessionHandle = null;
98 _VoipAudioSessionManagerImpl::ExitCallSession(void)
100 SysTryReturn(NID_MEDIA, __soundCallSessionHandle != null , E_INVALID_OPERATION, E_INVALID_OPERATION,
101 "[E_INVALID_OPERATION] A error has been occurred. The value of __soundCallSessionHandle is null.");
102 int ret = SOUND_MANAGER_ERROR_NONE;
103 result r = E_SUCCESS;
104 ret = sound_manager_call_session_destroy(__soundCallSessionHandle);
105 r = _AudioManagerConvert::CovertSoundManagerError2Result(ret);
106 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r,"[%s] Failed to perform sound_manager_call_session_destroy operation.", GetErrorMessage(r));
107 __soundCallSessionHandle = null;
112 _VoipAudioSessionManagerImpl::SetCallSessionMode(VoipAudioSessionMode mode)
114 result r = E_SUCCESS;
115 int ret = SOUND_MANAGER_ERROR_NONE;
116 SysAssertf(__soundCallSessionHandle != null, "Not yet constructed! Construct() should be called before use");
117 SysTryReturn(NID_MEDIA, mode != VOIP_AUDIO_SESSION_MODE_NONE , E_INVALID_ARG, E_INVALID_ARG,
118 " [E_INVALID_ARG] Invalid argument is used. The mode is not correct : %d", mode);
119 ret = sound_manager_call_session_set_mode(__soundCallSessionHandle, _AudioManagerConvert::ConvertVoipMode2CallMode(mode));
120 r = _AudioManagerConvert::CovertSoundManagerError2Result(ret);
121 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r,
122 "[%s] Failed to perform sound_manager_call_session_set_mode operation.", GetErrorMessage(r));
127 _VoipAudioSessionManagerImpl::GetCallSessionMode(void)
129 int ret = SOUND_MANAGER_ERROR_NONE;
130 result r = E_SUCCESS;
131 SysAssertf(__soundCallSessionHandle != null, "Not yet constructed! Construct() should be called before use");
132 sound_call_session_mode_e soundCallSessionMode = SOUND_CALL_SESSION_MODE_VOICE;
133 ret = sound_manager_call_session_get_mode(__soundCallSessionHandle, &soundCallSessionMode);
134 r = _AudioManagerConvert::CovertSoundManagerError2Result(ret);
135 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r,
136 "[%s] Failed to perform sound_manager_call_session_get_mode operation with error code : 0x%x", GetErrorMessage(r), ret);
137 return _AudioManagerConvert::ConvertCallSessionMode2VoipMode(soundCallSessionMode);
139 return VOIP_AUDIO_SESSION_MODE_NONE;