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 CallSettingsMoreOptionsForm.cpp
19 * @brief Sound manager class
21 #include "CallSoundManager.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;
30 using namespace Tizen::Base::Runtime;
32 static const wchar_t* RINGTONE_PATH = L"/opt/usr/apps/zktdpemtmw/shared/data/ringtone_sdk.mp3";
34 SoundManager::SoundManager(void)
35 : __pSoundCallSession(null)
38 , __lastEndedConferenceCall(false)
40 __timer.Construct(*this);
41 __isSoundStatusOn = false;
42 __isVibrateStatusOn = false;
45 SoundManager::~SoundManager(void)
47 if(__pSoundCallSession != null)
49 sound_manager_call_session_destroy(__pSoundCallSession);
51 if (__pVibrator != null)
55 if (__pPlayer != null)
63 SoundManager::SetlastEndedConferenceCall()
65 __lastEndedConferenceCall = true;
69 SoundManager::GetLastConferenceCall()
71 return __lastEndedConferenceCall;
75 SoundManager::GetTimer()
81 SoundManager::StopSession(void)
84 if(__pSoundCallSession != null)
86 AppLogDebug("sound_manager_call_session_destroy");
87 sound_manager_call_session_destroy(__pSoundCallSession);
88 __pSoundCallSession = null;
95 SoundManager::StartSession(void)
98 if (__pSoundCallSession != null)
100 sound_manager_call_session_set_mode(__pSoundCallSession,(sound_call_session_mode_e)SOUND_CALL_SESSION_MODE_VOICE);
101 sound_manager_set_active_route((sound_route_e)SOUND_ROUTE_IN_MIC_OUT_RECEIVER);
102 sound_manager_set_volume((sound_type_e)SOUND_TYPE_CALL,5);
105 int res = sound_manager_call_session_create((sound_call_session_type_e)SOUND_SESSION_TYPE_CALL, &__pSoundCallSession);
106 if (res != SOUND_MANAGER_ERROR_NONE)
108 AppLogDebug("Sound manager creation failed");
111 res = sound_manager_call_session_set_mode(__pSoundCallSession,(sound_call_session_mode_e)SOUND_CALL_SESSION_MODE_VOICE);
112 sound_manager_set_active_route((sound_route_e)SOUND_ROUTE_IN_MIC_OUT_RECEIVER);
113 //todo start listening for volume key and set the volume
114 sound_manager_set_volume((sound_type_e)SOUND_TYPE_CALL,5);
119 SoundManager::SetSpeakerStatus(bool setSpeaker)
121 result r = E_FAILURE;
123 bool isEarJackPresent = IsEarJackConnected();
124 sound_route_e soundRoute;
125 if (setSpeaker == true)
127 soundRoute = SOUND_ROUTE_IN_MIC_OUT_SPEAKER;
131 if (isEarJackPresent == true)
133 soundRoute = SOUND_ROUTE_IN_MIC_OUT_HEADPHONE;
137 soundRoute = SOUND_ROUTE_IN_MIC_OUT_RECEIVER;
140 res = sound_manager_set_active_route(soundRoute);
141 if (res == SOUND_MANAGER_ERROR_NONE)
153 SoundManager::SetSoundMode(SoundMode soundMode)
155 if (__pSoundCallSession == null)
159 sound_call_session_mode_e sessionMode;
162 case SOUND_MODE_RINGTONE:
164 sessionMode = SOUND_CALL_SESSION_MODE_RINGTONE;
167 case SOUND_MODE_MEDIA:
169 sessionMode = SOUND_CALL_SESSION_MODE_MEDIA;
172 case SOUND_MODE_VOICE:
174 sessionMode = SOUND_CALL_SESSION_MODE_VOICE;
179 sessionMode = SOUND_CALL_SESSION_MODE_RINGTONE;
183 int res = sound_manager_call_session_set_mode(__pSoundCallSession,sessionMode);
184 if (res != SOUND_MANAGER_ERROR_NONE)
192 SoundManager::OnTimerExpired(Timer& timer)
194 String reminderTonePath;
195 int unknownRejectStatus = -1;
196 vconf_get_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, &unknownRejectStatus);
197 bool ReminderToneSetStatus = unknownRejectStatus;
199 if(ReminderToneSetStatus == true)
202 if(__pPlayer == null)
204 __pPlayer = new (std::nothrow) Player();
205 __pPlayer->Construct(*this);
208 reminderTonePath.Append(RINGTONE_PATH);
209 __pPlayer->OpenFile(reminderTonePath,false);
210 __pPlayer->SetLooping(false);
211 __pPlayer->SetVolume(80);
212 SetSoundMode(SOUND_MODE_MEDIA);
214 SetSoundMode(SOUND_MODE_VOICE);
216 /*else if(ReminderToneSetStatus == false)
226 SoundManager::SetDisconnectTone(void)
229 int unknownRejectStatus = -1;
230 String disconnectTonePath;
231 vconf_get_bool(VCONFKEY_CISSAPPL_CALL_END_TONE_BOOL, &unknownRejectStatus);
232 bool disconnectToneSetStatus = unknownRejectStatus;
234 if(disconnectToneSetStatus == true)
236 disconnectTonePath.Append(RINGTONE_PATH);
238 if(__pPlayer == null)
240 __pPlayer = new (std::nothrow) Player();
241 __pPlayer->Construct(*this);
244 if(disconnectTonePath.IsEmpty() == false)
246 __pPlayer->OpenFile(disconnectTonePath,false);
247 __pPlayer->SetLooping(false);
248 __pPlayer->SetVolume(80);
249 SetSoundMode(SOUND_MODE_MEDIA);
258 SoundManager::SetMinuteReminderTone()
261 int unknownRejectStatus = -1;
262 vconf_get_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, &unknownRejectStatus);
263 bool reminderToneSetStatus = unknownRejectStatus;
265 if(reminderToneSetStatus == true)
267 __timer.StartAsRepeatable(20000);
274 SoundManager::SetConnectTone()
277 result r = E_FAILURE;
278 String connectTonePath;
279 int unknownRejectStatus = -1;
280 vconf_get_bool(VCONFKEY_CISSAPPL_CALL_CONNECT_TONE_BOOL, &unknownRejectStatus);
281 bool connectToneSetStatus = unknownRejectStatus;
283 connectTonePath.Append(RINGTONE_PATH);
285 if(connectToneSetStatus == true)
287 if(__pPlayer == null)
289 __pPlayer = new (std::nothrow) Player();
290 r = __pPlayer->Construct(*this);
293 if(connectTonePath.IsEmpty() == false)
295 r = __pPlayer->OpenFile(connectTonePath,false);
296 r = __pPlayer->SetLooping(false);
297 r = __pPlayer->SetVolume(80);
298 r = SetSoundMode(SOUND_MODE_MEDIA);
299 r = __pPlayer->Play();
305 SoundManager::StartAlert(String& contactRingTone)
307 AppLogDebug("Enter");
308 if(__pSoundCallSession != null)
310 AppLogDebug("No Alert already in call");
317 result r = E_FAILURE;
318 if(__pVibrator == null)
320 __pVibrator = new (std::nothrow) Vibrator();
321 r = __pVibrator->Construct();
323 if(__pPlayer == null)
325 __pPlayer = new (std::nothrow) Player();
326 r = __pPlayer->Construct(*this);
329 vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &retVal);
330 __isSoundStatusOn = retVal;
331 vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &retVal);
332 __isVibrateStatusOn = retVal;
333 //todo: do only if call alert mode is set
334 if (__isSoundStatusOn == true)
337 //Check if contact has any custom ringtone, else play defautl ringtone.
338 if(contactRingTone.IsEmpty() == true)
340 char* pRingTonePtr = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR);
341 AppLog("Ringtone Path : %s",pRingTonePtr);
342 ringTonePath.Append(pRingTonePtr);
346 AppLog("Ringtone Path : %ls",contactRingTone.GetPointer());
347 ringTonePath.Append(contactRingTone);
350 //Check if file is present
352 result res = file.Construct(ringTonePath, "r");
353 if(res != E_SUCCESS )
355 ringTonePath.Clear();
356 ringTonePath.Append(RINGTONE_PATH);
358 r = __pPlayer->OpenFile(ringTonePath,false);
359 r = __pPlayer->SetLooping(true);
360 r = __pPlayer->SetVolume(80);
361 r = SetSoundMode(SOUND_MODE_RINGTONE);
362 r = __pPlayer->Play();
364 if (__isVibrateStatusOn == true)
366 //todo: Get the level from settings
367 r = __pVibrator->Start(3000,1000,1000);
374 SoundManager::StopAlert(void)
376 AppLogDebug("Enter");
377 if (__isSoundStatusOn == true)
380 AppLogDebug("Stopping ring tone");
383 SetSoundMode(SOUND_MODE_VOICE);
384 __isSoundStatusOn = false;
387 if (__isVibrateStatusOn == true)
390 __isVibrateStatusOn = false;
396 SoundManager::OnPlayerOpened(result r)
401 SoundManager::OnPlayerEndOfClip(void)
406 SoundManager::OnPlayerSeekCompleted(result r)
411 SoundManager::OnPlayerBuffering(int percent)
416 SoundManager::OnPlayerErrorOccurred(Tizen::Media::PlayerErrorReason r)
421 SoundManager::OnPlayerInterrupted(void)
426 SoundManager::OnPlayerReleased(void)
431 SoundManager::IsEarJackConnected(void)
433 int earJackStatus = -1;
434 if (vconf_get_int(VCONFKEY_SYSMAN_EARJACK, &earJackStatus) == 0)
436 if (earJackStatus == VCONFKEY_SYSMAN_EARJACK_REMOVED)