2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file PhnSettingsMoreOptionsForm.cpp
19 * @brief Sound manager class
21 #include "PhnSoundManager.h"
23 using namespace Tizen::Base;
24 using namespace Tizen::Graphics;
25 using namespace Tizen::Io;
26 using namespace Tizen::Media;
27 using namespace Tizen::Social;
28 using namespace Tizen::System;
29 using namespace Tizen::Base::Collection;
31 static const wchar_t* RINGTONE_PATH = L"/opt/usr/apps/zktdpemtmw/shared/data/ringtone_sdk.mp3";
33 SoundManager::SoundManager(void)
34 : __pSoundCallSession(null)
38 __isSoundStatusOn = false;
39 __isVibrateStatusOn = false;
42 SoundManager::~SoundManager(void)
44 if(__pSoundCallSession != null)
46 sound_manager_call_session_destroy(__pSoundCallSession);
48 if (__pVibrator != null)
52 if (__pPlayer != null)
59 SoundManager::StopSession(void)
62 if(__pSoundCallSession != null)
64 AppLogDebug("sound_manager_call_session_destroy");
65 sound_manager_call_session_destroy(__pSoundCallSession);
66 __pSoundCallSession = null;
73 SoundManager::StartSession(void)
76 if (__pSoundCallSession != null)
78 sound_manager_call_session_set_mode(__pSoundCallSession,(sound_call_session_mode_e)SOUND_CALL_SESSION_MODE_VOICE);
79 sound_manager_set_active_route((sound_route_e)SOUND_ROUTE_IN_MIC_OUT_RECEIVER);
80 sound_manager_set_volume((sound_type_e)SOUND_TYPE_CALL,5);
83 int res = sound_manager_call_session_create((sound_call_session_type_e)SOUND_SESSION_TYPE_CALL, &__pSoundCallSession);
84 if (res != SOUND_MANAGER_ERROR_NONE)
86 AppLogDebug("Sound manager creation failed");
89 res = sound_manager_call_session_set_mode(__pSoundCallSession,(sound_call_session_mode_e)SOUND_CALL_SESSION_MODE_VOICE);
90 sound_manager_set_active_route((sound_route_e)SOUND_ROUTE_IN_MIC_OUT_RECEIVER);
91 //todo start listening for volume key and set the volume
92 sound_manager_set_volume((sound_type_e)SOUND_TYPE_CALL,5);
97 SoundManager::SetSpeakerStatus(bool setSpeaker)
101 bool isEarJackPresent = IsEarJackConnected();
102 sound_route_e soundRoute;
103 if (setSpeaker == true)
105 soundRoute = SOUND_ROUTE_IN_MIC_OUT_SPEAKER;
109 if (isEarJackPresent == true)
111 soundRoute = SOUND_ROUTE_IN_MIC_OUT_HEADPHONE;
115 soundRoute = SOUND_ROUTE_IN_MIC_OUT_RECEIVER;
118 res = sound_manager_set_active_route(soundRoute);
119 if (res == SOUND_MANAGER_ERROR_NONE)
131 SoundManager::SetSoundMode(SoundMode soundMode)
133 if (__pSoundCallSession == null)
137 sound_call_session_mode_e sessionMode;
140 case SOUND_MODE_RINGTONE:
142 sessionMode = SOUND_CALL_SESSION_MODE_RINGTONE;
145 case SOUND_MODE_MEDIA:
147 sessionMode = SOUND_CALL_SESSION_MODE_MEDIA;
150 case SOUND_MODE_VOICE:
152 sessionMode = SOUND_CALL_SESSION_MODE_VOICE;
157 sessionMode = SOUND_CALL_SESSION_MODE_RINGTONE;
161 int res = sound_manager_call_session_set_mode(__pSoundCallSession,sessionMode);
162 if (res != SOUND_MANAGER_ERROR_NONE)
170 SoundManager::StartAlert(String& contactRingTone)
172 AppLogDebug("Enter");
173 if(__pSoundCallSession != null)
175 AppLogDebug("No Alert already in call");
182 result r = E_FAILURE;
183 if(__pVibrator == null)
185 __pVibrator = new (std::nothrow) Vibrator();
186 r = __pVibrator->Construct();
188 if(__pPlayer == null)
190 __pPlayer = new (std::nothrow) Player();
191 r = __pPlayer->Construct(*this);
194 vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &retVal);
195 __isSoundStatusOn = retVal;
196 vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &retVal);
197 __isVibrateStatusOn = retVal;
198 //todo: do only if call alert mode is set
199 if (__isSoundStatusOn == true)
202 //Check if contact has any custom ringtone, else play defautl ringtone.
203 if(contactRingTone.IsEmpty() == true)
205 char* pRingTonePtr = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR);
206 ringTonePath.Append(pRingTonePtr);
210 ringTonePath.Append(contactRingTone);
213 //Check if file is present
215 result res = file.Construct(ringTonePath, "r");
216 if(res != E_SUCCESS )
218 ringTonePath.Clear();
219 ringTonePath.Append(RINGTONE_PATH);
221 r = __pPlayer->OpenFile(ringTonePath,false);
222 r = __pPlayer->SetLooping(true);
223 r = __pPlayer->SetVolume(80);
224 r = SetSoundMode(SOUND_MODE_VOICE);
225 r = __pPlayer->Play();
227 if (__isVibrateStatusOn == true)
229 //todo: Get the level from settings
230 r = __pVibrator->Start(3000,1000,1000);
237 SoundManager::StopAlert(void)
239 AppLogDebug("Enter");
240 if (__isSoundStatusOn == true)
243 AppLogDebug("Stopping ring tone");
246 SetSoundMode(SOUND_MODE_VOICE);
247 __isSoundStatusOn = false;
250 if (__isVibrateStatusOn == true)
253 __isVibrateStatusOn = false;
259 SoundManager::OnPlayerOpened(result r)
264 SoundManager::OnPlayerEndOfClip(void)
269 SoundManager::OnPlayerSeekCompleted(result r)
274 SoundManager::OnPlayerBuffering(int percent)
279 SoundManager::OnPlayerErrorOccurred(Tizen::Media::PlayerErrorReason r)
284 SoundManager::OnPlayerInterrupted(void)
289 SoundManager::OnPlayerReleased(void)
294 SoundManager::IsEarJackConnected(void)
296 int earJackStatus = -1;
297 if (vconf_get_int(VCONFKEY_SYSMAN_EARJACK, &earJackStatus) == 0)
299 if (earJackStatus == VCONFKEY_SYSMAN_EARJACK_REMOVED)