2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (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)
44 , __pConnectPlayer(null)
45 , __pDisconnectPlayer(null)
46 , __pReminderPlayer(null)
47 , __pWaitingTonePlayer(null)
49 __timer.Construct(*this);
50 __isSoundStatusOn = false;
51 __isVibrateStatusOn = false;
54 SoundManager::~SoundManager(void)
56 if(__pSoundCallSession != null)
58 sound_manager_call_session_destroy(__pSoundCallSession);
60 if (__pVibrator != null)
65 if (__pPlayer != null)
70 if(__pConnectPlayer != null)
72 delete __pConnectPlayer;
73 __pConnectPlayer = null;
75 if(__pDisconnectPlayer != null)
77 delete __pDisconnectPlayer;
78 __pDisconnectPlayer = null;
80 if(__pReminderPlayer != null)
82 delete __pReminderPlayer;
83 __pReminderPlayer = null;
85 if(__pWaitingTonePlayer != null)
87 delete __pWaitingTonePlayer;
88 __pWaitingTonePlayer = null;
94 SoundManager::SetlastEndedConferenceCall()
96 __lastEndedConferenceCall = true;
100 SoundManager::GetLastConferenceCall()
102 return __lastEndedConferenceCall;
106 SoundManager::GetTimer()
112 SoundManager::StopSession(void)
114 AppLogDebug("Enter");
115 if(__pSoundCallSession != null)
117 AppLogDebug("sound_manager_call_session_destroy");
118 sound_manager_call_session_destroy(__pSoundCallSession);
119 __pSoundCallSession = null;
126 SoundManager::StartSession(void)
128 AppLogDebug("Enter");
129 if (__pSoundCallSession != null)
131 sound_manager_call_session_set_mode(__pSoundCallSession,(sound_call_session_mode_e)SOUND_CALL_SESSION_MODE_VOICE);
132 sound_manager_set_active_route((sound_route_e)SOUND_ROUTE_IN_MIC_OUT_RECEIVER);
133 sound_manager_set_volume((sound_type_e)SOUND_TYPE_CALL,5);
136 int res = sound_manager_call_session_create((sound_call_session_type_e)SOUND_SESSION_TYPE_CALL, &__pSoundCallSession);
137 if (res != SOUND_MANAGER_ERROR_NONE)
139 AppLogDebug("Sound manager creation failed");
142 res = sound_manager_call_session_set_mode(__pSoundCallSession,(sound_call_session_mode_e)SOUND_CALL_SESSION_MODE_VOICE);
143 sound_manager_set_active_route((sound_route_e)SOUND_ROUTE_IN_MIC_OUT_RECEIVER);
144 //todo start listening for volume key and set the volume
145 sound_manager_set_volume((sound_type_e)SOUND_TYPE_CALL,5);
150 SoundManager::SetSpeakerStatus(bool setSpeaker)
152 result r = E_FAILURE;
154 bool isEarJackPresent = IsEarJackConnected();
155 sound_route_e soundRoute;
156 if (setSpeaker == true)
158 soundRoute = SOUND_ROUTE_IN_MIC_OUT_SPEAKER;
162 if (isEarJackPresent == true)
164 soundRoute = SOUND_ROUTE_IN_MIC_OUT_HEADPHONE;
168 soundRoute = SOUND_ROUTE_IN_MIC_OUT_RECEIVER;
171 res = sound_manager_set_active_route(soundRoute);
172 if (res == SOUND_MANAGER_ERROR_NONE)
184 SoundManager::SetSoundMode(SoundMode soundMode)
186 if (__pSoundCallSession == null)
190 sound_call_session_mode_e sessionMode;
193 case SOUND_MODE_RINGTONE:
195 sessionMode = SOUND_CALL_SESSION_MODE_RINGTONE;
198 case SOUND_MODE_MEDIA:
200 sessionMode = SOUND_CALL_SESSION_MODE_MEDIA;
203 case SOUND_MODE_VOICE:
205 sessionMode = SOUND_CALL_SESSION_MODE_VOICE;
210 sessionMode = SOUND_CALL_SESSION_MODE_RINGTONE;
214 int res = sound_manager_call_session_set_mode(__pSoundCallSession,sessionMode);
215 if (res != SOUND_MANAGER_ERROR_NONE)
223 SoundManager::OnTimerExpired(Timer& timer)
225 AppLogDebug("Enter");
226 String reminderTonePath;
227 int unknownRejectStatus = -1;
228 vconf_get_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, &unknownRejectStatus);
229 bool ReminderToneSetStatus = unknownRejectStatus;
230 result res = E_FAILURE;
231 reminderTonePath.Append(MINUTEREMINDERTONE_PATH);
233 if(ReminderToneSetStatus == true)
236 if(__pReminderPlayer == null)
239 if(reminderTonePath.IsEmpty() == false)
241 __pReminderPlayer = new (std::nothrow) Player();
242 res = __pReminderPlayer->Construct(*this);
245 AppLogDebug("__pReminderPlayer Construct failed with %d",res);
246 delete __pReminderPlayer;
247 __pReminderPlayer = null;
250 res = __pReminderPlayer->OpenFile(reminderTonePath,false);
253 AppLogDebug("__pReminderPlayer OpenFile failed with %d",res);
254 delete __pReminderPlayer;
255 __pReminderPlayer = null;
258 res = __pReminderPlayer->SetLooping(false);
261 AppLogDebug("__pReminderPlayer SetLooping failed with %d",res);
262 delete __pReminderPlayer;
263 __pReminderPlayer = null;
266 res = __pReminderPlayer->SetVolume(80);
269 AppLogDebug("__pReminderPlayer SetVolume failed with %d",res);
270 delete __pReminderPlayer;
271 __pReminderPlayer = null;
277 if(__pReminderPlayer != null)
279 SetSoundMode(SOUND_MODE_MEDIA);
280 res = __pReminderPlayer->Play();
283 AppLogDebug("__pReminderPlayer Play failed with %d",res);
286 SetSoundMode(SOUND_MODE_VOICE);
289 /*else if(ReminderToneSetStatus == false)
299 SoundManager::SetDisconnectTone(void)
302 AppLogDebug("Enter");
303 int unknownRejectStatus = -1;
304 String disconnectTonePath=L"";
305 vconf_get_bool(VCONFKEY_CISSAPPL_CALL_END_TONE_BOOL, &unknownRejectStatus);
306 bool disconnectToneSetStatus = unknownRejectStatus;
307 result res = E_FAILURE;
309 if(disconnectToneSetStatus == true)
311 AppLogDebug("disconnectToneSetStatus == true");
312 disconnectTonePath.Append(CALLDISCONNECTTONE_PATH);
313 if(disconnectTonePath.IsEmpty() == false)
315 if(__pDisconnectPlayer == null)
317 AppLogDebug("__pConnectPlayer == null");
318 __pDisconnectPlayer = new (std::nothrow) Player();
319 res = __pDisconnectPlayer->Construct(*this);
322 AppLogDebug("__pDisconnectPlayer Construct failed with %d",res);
323 delete __pDisconnectPlayer;
324 __pDisconnectPlayer = null;
327 res = __pDisconnectPlayer->OpenFile(disconnectTonePath,false);
330 AppLogDebug("__pDisconnectPlayer OpenFile failed with %d",res);
331 delete __pDisconnectPlayer;
332 __pDisconnectPlayer = null;
335 res = __pDisconnectPlayer->SetLooping(false);
338 AppLogDebug("__pDisconnectPlayer SetLooping failed with %d",res);
339 delete __pDisconnectPlayer;
340 __pDisconnectPlayer = null;
343 res = __pDisconnectPlayer->SetVolume(80);
346 AppLogDebug("__pDisconnectPlayer SetLooping SetVolume with %d",res);
347 delete __pDisconnectPlayer;
348 __pDisconnectPlayer = null;
355 if(__pDisconnectPlayer != null)
357 AppLogDebug("__pDisconnectPlayer OpenFile %ls",disconnectTonePath.GetPointer());
358 SetSoundMode(SOUND_MODE_MEDIA);
359 AppLogDebug("__pDisconnectPlayer SetVolume");
360 if(__pDisconnectPlayer->GetState() == PLAYER_STATE_PLAYING)
362 __pDisconnectPlayer->Stop();
364 res = __pDisconnectPlayer->Play();
367 AppLogDebug("__pDisconnectPlayer Play with %d",res);
382 SoundManager::SetMinuteReminderTone(void)
384 __timer.StartAsRepeatable(60000);
389 SoundManager::SetConnectTone(void)
392 String connectTonePath;
393 int unknownRejectStatus = -1;
394 vconf_get_bool(VCONFKEY_CISSAPPL_CALL_CONNECT_TONE_BOOL, &unknownRejectStatus);
395 bool connectToneSetStatus = unknownRejectStatus;
396 result res = E_FAILURE;
398 connectTonePath.Append(CALLCONNECTTONE_PATH);
400 if(connectToneSetStatus == true)
403 if(__pConnectPlayer == null)
405 if (connectTonePath.IsEmpty() == false)
407 __pConnectPlayer = new (std::nothrow) Player();
408 res = __pConnectPlayer->Construct(*this);
411 AppLogDebug("__pConnectPlayer Construct failed with %d",res);
412 delete __pConnectPlayer;
413 __pConnectPlayer = null;
416 res = __pConnectPlayer->OpenFile(connectTonePath,false);
419 AppLogDebug("__pConnectPlayer OpenFile failed with %d",res);
420 delete __pConnectPlayer;
421 __pConnectPlayer = null;
424 res = __pConnectPlayer->SetLooping(false);
427 AppLogDebug("__pConnectPlayer SetLooping failed with %d",res);
428 delete __pConnectPlayer;
429 __pConnectPlayer = null;
432 res = __pConnectPlayer->SetVolume(80);
435 AppLogDebug("__pConnectPlayer SetVolume failed with %d",res);
436 delete __pConnectPlayer;
437 __pConnectPlayer = null;
443 if(__pConnectPlayer != null)
445 res = SetSoundMode(SOUND_MODE_MEDIA);
446 AppLogDebug("__pConnectPlayer Playing connect tone");
447 res = __pConnectPlayer->Play();
450 AppLogDebug("__pConnectPlayer Play failed with %d",res);
461 SoundManager::SetWaitTone(void)
463 CallAlertStatus status= CALL_ALERT_SOUND;
464 int alertStatus = -1;
465 result res = E_FAILURE;
466 int retVal = vconf_get_int(VCONFKEY_CISSAPPL_ALERT_ON_CALL_INT, &alertStatus);
469 status = (CallAlertStatus) alertStatus;
471 AppLogDebug("No Alert already in call");
472 if(status == CALL_ALERT_SOUND)
474 AppLogDebug("Playing alert tone");
475 String waitingTonePath;
476 waitingTonePath.Append(CALLWAITINGTONE_PATH);
477 if(__pWaitingTonePlayer == null)
479 if (waitingTonePath.IsEmpty() == false)
481 __pWaitingTonePlayer = new (std::nothrow) Player();
482 res = __pWaitingTonePlayer->Construct(*this);
485 AppLogDebug("__pWaitingTonePlayer Construct failed with %d",res);
486 delete __pWaitingTonePlayer;
487 __pWaitingTonePlayer = null;
490 res = __pWaitingTonePlayer->OpenFile(waitingTonePath,false);
493 AppLogDebug("__pWaitingTonePlayer OpenFile failed with %d",res);
494 delete __pWaitingTonePlayer;
495 __pWaitingTonePlayer = null;
499 res = __pWaitingTonePlayer->SetLooping(true);
502 AppLogDebug("__pWaitingTonePlayer SetLooping failed with %d",res);
503 delete __pWaitingTonePlayer;
504 __pWaitingTonePlayer = null;
508 res = __pWaitingTonePlayer->SetVolume(80);
511 AppLogDebug("__pWaitingTonePlayer SetVolume failed with %d",res);
512 delete __pWaitingTonePlayer;
513 __pWaitingTonePlayer = null;
520 if( __pWaitingTonePlayer != null )
522 SetSoundMode(SOUND_MODE_MEDIA);
523 res = __pWaitingTonePlayer->Play();
526 AppLogDebug("__pWaitingTonePlayer Play failed with %d",res);
535 SoundManager::StartAlert(String& contactRingTone)
537 result res = E_FAILURE;
538 IntensityDurationVibrationPattern vibration;
539 vibration.duration = 3000;
540 vibration.intensity = -1;
541 AppLogDebug("Enter");
542 if(__pSoundCallSession != null)
551 if(__pVibrator == null)
553 __pVibrator = new (std::nothrow) Vibrator();
554 res = __pVibrator->Construct();
557 AppLogDebug("__pVibrator Construct failed with %d",res);
561 if(__pPlayer == null)
563 __pPlayer = new (std::nothrow) Player();
564 res = __pPlayer->Construct(*this);
567 AppLogDebug("__pPlayer Construct failed with %d",res);
574 vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &retVal);
575 __isSoundStatusOn = retVal;
576 vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &retVal);
577 __isVibrateStatusOn = retVal;
578 //todo: do only if call alert mode is set
579 if (__isSoundStatusOn == true)
582 //Check if contact has any custom ringtone, else play defautl ringtone.
583 if(contactRingTone.IsEmpty() == true)
585 char* pRingTonePtr = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR);
586 AppLog("Ringtone Path : %s",pRingTonePtr);
587 ringTonePath.Append(pRingTonePtr);
591 AppLog("Ringtone Path : %ls",contactRingTone.GetPointer());
592 ringTonePath.Append(contactRingTone);
595 //Check if file is present
597 res = file.Construct(ringTonePath, "r");
598 if(res != E_SUCCESS )
600 ringTonePath.Clear();
601 ringTonePath.Append(RINGTONE_PATH);
604 res = __pPlayer->OpenFile(ringTonePath,false);
607 AppLogDebug("__pPlayer Construct failed with %d",res);
610 res = __pPlayer->SetLooping(true);
613 AppLogDebug("__pPlayer Construct failed with %d",res);
616 res = __pPlayer->SetVolume(80);
619 AppLogDebug("__pPlayer Construct failed with %d",res);
622 res = SetSoundMode(SOUND_MODE_RINGTONE);
623 res = __pPlayer->Play();
626 AppLogDebug("__pPlayer Construct failed with %d",res);
630 if (__isVibrateStatusOn == true)
632 //todo: Get the level from settings
633 __pVibrator->Start(&vibration, 1, 1000);
640 SoundManager::StopAlert(void)
642 result res = E_FAILURE;
643 AppLogDebug("Enter");
644 if (__isSoundStatusOn == true)
647 if(__pPlayer != null)
649 AppLogDebug("Stopping ring tone");
650 if(__pPlayer->GetState() == PLAYER_STATE_PLAYING)
652 res = __pPlayer->Stop();
656 AppLogDebug("__pPlayer Stop failed with %d",res);
659 res = __pPlayer->Close();
662 AppLogDebug("__pPlayer Close failed with %d",res);
665 SetSoundMode(SOUND_MODE_VOICE);
666 __isSoundStatusOn = false;
670 if (__isVibrateStatusOn == true)
673 __isVibrateStatusOn = false;
675 if(__pWaitingTonePlayer != null)
677 if(__pWaitingTonePlayer->GetState() == PLAYER_STATE_PLAYING)
679 __pWaitingTonePlayer->Stop();
687 SoundManager::OnPlayerOpened(result r)
692 SoundManager::OnPlayerEndOfClip(void)
697 SoundManager::OnPlayerSeekCompleted(result r)
702 SoundManager::OnPlayerBuffering(int percent)
707 SoundManager::OnPlayerErrorOccurred(Tizen::Media::PlayerErrorReason r)
712 SoundManager::OnPlayerInterrupted(void)
717 SoundManager::OnPlayerReleased(void)
722 SoundManager::IsEarJackConnected(void)
724 int earJackStatus = -1;
725 if (vconf_get_int(VCONFKEY_SYSMAN_EARJACK, &earJackStatus) == 0)
727 if (earJackStatus == VCONFKEY_SYSMAN_EARJACK_REMOVED)