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";
33 static const wchar_t* CALLCONNECTTONE_PATH = L"/opt/usr/apps/zktdpemtmw/shared/data/Call_Connect.ogg";
34 static const wchar_t* CALLDISCONNECTTONE_PATH = L"/opt/usr/apps/zktdpemtmw/shared/data/Call_Disconnect.ogg";
35 static const wchar_t* MINUTEREMINDERTONE_PATH = L"/opt/usr/apps/zktdpemtmw/shared/data/Call_RecordStart.wav";
36 static const wchar_t* CALLWAITINGTONE_PATH = L"/opt/usr/apps/zktdpemtmw/shared/data/Call_WaitingTone.wav";
39 SoundManager::SoundManager(void)
40 : __pSoundCallSession(null)
43 , __lastEndedConferenceCall(false)
45 __timer.Construct(*this);
46 __isSoundStatusOn = false;
47 __isVibrateStatusOn = false;
50 SoundManager::~SoundManager(void)
52 if(__pSoundCallSession != null)
54 sound_manager_call_session_destroy(__pSoundCallSession);
56 if (__pVibrator != null)
60 if (__pPlayer != null)
68 SoundManager::SetlastEndedConferenceCall()
70 __lastEndedConferenceCall = true;
74 SoundManager::GetLastConferenceCall()
76 return __lastEndedConferenceCall;
80 SoundManager::GetTimer()
86 SoundManager::StopSession(void)
89 if(__pSoundCallSession != null)
91 AppLogDebug("sound_manager_call_session_destroy");
92 sound_manager_call_session_destroy(__pSoundCallSession);
93 __pSoundCallSession = null;
100 SoundManager::StartSession(void)
102 AppLogDebug("Enter");
103 if (__pSoundCallSession != null)
105 sound_manager_call_session_set_mode(__pSoundCallSession,(sound_call_session_mode_e)SOUND_CALL_SESSION_MODE_VOICE);
106 sound_manager_set_active_route((sound_route_e)SOUND_ROUTE_IN_MIC_OUT_RECEIVER);
107 sound_manager_set_volume((sound_type_e)SOUND_TYPE_CALL,5);
110 int res = sound_manager_call_session_create((sound_call_session_type_e)SOUND_SESSION_TYPE_CALL, &__pSoundCallSession);
111 if (res != SOUND_MANAGER_ERROR_NONE)
113 AppLogDebug("Sound manager creation failed");
116 res = sound_manager_call_session_set_mode(__pSoundCallSession,(sound_call_session_mode_e)SOUND_CALL_SESSION_MODE_VOICE);
117 sound_manager_set_active_route((sound_route_e)SOUND_ROUTE_IN_MIC_OUT_RECEIVER);
118 //todo start listening for volume key and set the volume
119 sound_manager_set_volume((sound_type_e)SOUND_TYPE_CALL,5);
124 SoundManager::SetSpeakerStatus(bool setSpeaker)
126 result r = E_FAILURE;
128 bool isEarJackPresent = IsEarJackConnected();
129 sound_route_e soundRoute;
130 if (setSpeaker == true)
132 soundRoute = SOUND_ROUTE_IN_MIC_OUT_SPEAKER;
136 if (isEarJackPresent == true)
138 soundRoute = SOUND_ROUTE_IN_MIC_OUT_HEADPHONE;
142 soundRoute = SOUND_ROUTE_IN_MIC_OUT_RECEIVER;
145 res = sound_manager_set_active_route(soundRoute);
146 if (res == SOUND_MANAGER_ERROR_NONE)
158 SoundManager::SetSoundMode(SoundMode soundMode)
160 if (__pSoundCallSession == null)
164 sound_call_session_mode_e sessionMode;
167 case SOUND_MODE_RINGTONE:
169 sessionMode = SOUND_CALL_SESSION_MODE_RINGTONE;
172 case SOUND_MODE_MEDIA:
174 sessionMode = SOUND_CALL_SESSION_MODE_MEDIA;
177 case SOUND_MODE_VOICE:
179 sessionMode = SOUND_CALL_SESSION_MODE_VOICE;
184 sessionMode = SOUND_CALL_SESSION_MODE_RINGTONE;
188 int res = sound_manager_call_session_set_mode(__pSoundCallSession,sessionMode);
189 if (res != SOUND_MANAGER_ERROR_NONE)
197 SoundManager::OnTimerExpired(Timer& timer)
199 String reminderTonePath;
200 int unknownRejectStatus = -1;
201 vconf_get_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, &unknownRejectStatus);
202 bool ReminderToneSetStatus = unknownRejectStatus;
203 result res = E_FAILURE;
205 if(ReminderToneSetStatus == true)
208 if(__pPlayer == null)
210 __pPlayer = new (std::nothrow) Player();
211 res = __pPlayer->Construct(*this);
214 AppLogDebug("__pPlayer Construct failed with %d",res);
219 reminderTonePath.Append(MINUTEREMINDERTONE_PATH);
220 if(reminderTonePath.IsEmpty() == false)
224 res = __pPlayer->OpenFile(reminderTonePath,false);
227 AppLogDebug("__pPlayer OpenFile failed with %d",res);
230 res = __pPlayer->SetLooping(false);
233 AppLogDebug("__pPlayer SetLooping failed with %d",res);
236 res = __pPlayer->SetVolume(80);
239 AppLogDebug("__pPlayer SetVolume failed with %d",res);
242 SetSoundMode(SOUND_MODE_MEDIA);
243 res = __pPlayer->Play();
246 AppLogDebug("__pPlayer Play failed with %d",res);
249 SetSoundMode(SOUND_MODE_VOICE);
252 /*else if(ReminderToneSetStatus == false)
262 SoundManager::SetDisconnectTone(void)
265 AppLogDebug("Enter");
266 int unknownRejectStatus = -1;
267 String disconnectTonePath=L"";
268 vconf_get_bool(VCONFKEY_CISSAPPL_CALL_END_TONE_BOOL, &unknownRejectStatus);
269 bool disconnectToneSetStatus = unknownRejectStatus;
270 result res = E_FAILURE;
272 if(disconnectToneSetStatus == true)
274 AppLogDebug("disconnectToneSetStatus == true");
275 disconnectTonePath.Append(CALLDISCONNECTTONE_PATH);
276 if(__pPlayer == null)
278 AppLogDebug("__pPlayer == null");
279 __pPlayer = new (std::nothrow) Player();
280 res = __pPlayer->Construct(*this);
283 AppLogDebug("__pPlayer Construct failed with %d",res);
288 if(disconnectTonePath.IsEmpty() == false)
292 AppLogDebug("__pPlayer OpenFile %ls",disconnectTonePath.GetPointer());
293 res = __pPlayer->OpenFile(disconnectTonePath,false);
296 AppLogDebug("__pPlayer OpenFile failed with %d",res);
299 res = __pPlayer->SetLooping(false);
302 AppLogDebug("__pPlayer SetLooping failed with %d",res);
305 res = __pPlayer->SetVolume(80);
308 AppLogDebug("__pPlayer SetLooping SetVolume with %d",res);
311 SetSoundMode(SOUND_MODE_MEDIA);
312 AppLogDebug("__pPlayer SetVolume");
313 res = __pPlayer->Play();
316 AppLogDebug("__pPlayer Play with %d",res);
326 SoundManager::SetMinuteReminderTone()
329 int unknownRejectStatus = -1;
330 vconf_get_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, &unknownRejectStatus);
331 bool reminderToneSetStatus = unknownRejectStatus;
333 if(reminderToneSetStatus == true)
335 __timer.StartAsRepeatable(60000);
342 SoundManager::SetConnectTone()
345 String connectTonePath;
346 int unknownRejectStatus = -1;
347 vconf_get_bool(VCONFKEY_CISSAPPL_CALL_CONNECT_TONE_BOOL, &unknownRejectStatus);
348 bool connectToneSetStatus = unknownRejectStatus;
349 result res = E_FAILURE;
351 connectTonePath.Append(CALLCONNECTTONE_PATH);
353 if(connectToneSetStatus == true)
356 if(__pPlayer == null)
358 __pPlayer = new (std::nothrow) Player();
359 res = __pPlayer->Construct(*this);
362 AppLogDebug("__pPlayer Construct failed with %d",res);
366 if (connectTonePath.IsEmpty() == false)
371 res = __pPlayer->OpenFile(connectTonePath,false);
374 AppLogDebug("__pPlayer OpenFile failed with %d",res);
377 res = __pPlayer->SetLooping(false);
380 AppLogDebug("__pPlayer SetLooping failed with %d",res);
383 res = __pPlayer->SetVolume(80);
386 AppLogDebug("__pPlayer SetVolume failed with %d",res);
389 res = SetSoundMode(SOUND_MODE_MEDIA);
390 AppLogDebug("__pPlayer Playing connect tone");
391 res = __pPlayer->Play();
394 AppLogDebug("__pPlayer Play failed with %d",res);
402 SoundManager::StartAlert(String& contactRingTone)
404 result res = E_FAILURE;
405 AppLogDebug("Enter");
406 if(__pSoundCallSession != null)
408 CallAlertStatus status= CALL_ALERT_SOUND;
409 int alertStatus = -1;
410 int retVal = vconf_get_int(VCONFKEY_CISSAPPL_ALERT_ON_CALL_INT, &alertStatus);
413 status = (CallAlertStatus) alertStatus;
415 AppLogDebug("No Alert already in call");
416 if(status == CALL_ALERT_SOUND)
418 AppLogDebug("Playing alert tone");
419 String waitingTonePath;
420 waitingTonePath.Append(CALLWAITINGTONE_PATH);
421 if(__pPlayer == null)
423 __pPlayer = new (std::nothrow) Player();
424 res = __pPlayer->Construct(*this);
427 AppLogDebug("__pPlayer Construct failed with %d",res);
431 if (waitingTonePath.IsEmpty() == false)
435 res = __pPlayer->OpenFile(waitingTonePath,false);
438 AppLogDebug("__pPlayer OpenFile failed with %d",res);
441 res = __pPlayer->SetLooping(true);
444 AppLogDebug("__pPlayer SetLooping failed with %d",res);
447 res = __pPlayer->SetVolume(80);
450 AppLogDebug("__pPlayer SetVolume failed with %d",res);
453 SetSoundMode(SOUND_MODE_MEDIA);
454 res = __pPlayer->Play();
457 AppLogDebug("__pPlayer Play failed with %d",res);
468 if(__pVibrator == null)
470 __pVibrator = new (std::nothrow) Vibrator();
471 res = __pVibrator->Construct();
474 AppLogDebug("__pVibrator Construct failed with %d",res);
478 if(__pPlayer == null)
480 __pPlayer = new (std::nothrow) Player();
481 res = __pPlayer->Construct(*this);
484 AppLogDebug("__pPlayer Construct failed with %d",res);
489 vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &retVal);
490 __isSoundStatusOn = retVal;
491 vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &retVal);
492 __isVibrateStatusOn = retVal;
493 //todo: do only if call alert mode is set
494 if (__isSoundStatusOn == true)
497 //Check if contact has any custom ringtone, else play defautl ringtone.
498 if(contactRingTone.IsEmpty() == true)
500 char* pRingTonePtr = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR);
501 AppLog("Ringtone Path : %s",pRingTonePtr);
502 ringTonePath.Append(pRingTonePtr);
506 AppLog("Ringtone Path : %ls",contactRingTone.GetPointer());
507 ringTonePath.Append(contactRingTone);
510 //Check if file is present
512 res = file.Construct(ringTonePath, "r");
513 if(res != E_SUCCESS )
515 ringTonePath.Clear();
516 ringTonePath.Append(RINGTONE_PATH);
519 res = __pPlayer->OpenFile(ringTonePath,false);
522 AppLogDebug("__pPlayer Construct failed with %d",res);
525 res = __pPlayer->SetLooping(true);
528 AppLogDebug("__pPlayer Construct failed with %d",res);
531 res = __pPlayer->SetVolume(80);
534 AppLogDebug("__pPlayer Construct failed with %d",res);
537 res = SetSoundMode(SOUND_MODE_RINGTONE);
538 res = __pPlayer->Play();
541 AppLogDebug("__pPlayer Construct failed with %d",res);
545 if (__isVibrateStatusOn == true)
547 //todo: Get the level from settings
548 res = __pVibrator->Start(3000,1000,1000);
555 SoundManager::StopAlert(void)
557 result res = E_FAILURE;
558 AppLogDebug("Enter");
559 if (__isSoundStatusOn == true)
562 AppLogDebug("Stopping ring tone");
563 res = __pPlayer->Stop();
566 AppLogDebug("__pPlayer Stop failed with %d",res);
569 res = __pPlayer->Close();
572 AppLogDebug("__pPlayer Close failed with %d",res);
575 SetSoundMode(SOUND_MODE_VOICE);
576 __isSoundStatusOn = false;
579 if (__isVibrateStatusOn == true)
582 __isVibrateStatusOn = false;
588 SoundManager::OnPlayerOpened(result r)
593 SoundManager::OnPlayerEndOfClip(void)
598 SoundManager::OnPlayerSeekCompleted(result r)
603 SoundManager::OnPlayerBuffering(int percent)
608 SoundManager::OnPlayerErrorOccurred(Tizen::Media::PlayerErrorReason r)
613 SoundManager::OnPlayerInterrupted(void)
618 SoundManager::OnPlayerReleased(void)
623 SoundManager::IsEarJackConnected(void)
625 int earJackStatus = -1;
626 if (vconf_get_int(VCONFKEY_SYSMAN_EARJACK, &earJackStatus) == 0)
628 if (earJackStatus == VCONFKEY_SYSMAN_EARJACK_REMOVED)