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 String reminderTonePath;
226 int unknownRejectStatus = -1;
227 vconf_get_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, &unknownRejectStatus);
228 bool ReminderToneSetStatus = unknownRejectStatus;
229 result res = E_FAILURE;
230 reminderTonePath.Append(MINUTEREMINDERTONE_PATH);
232 if(ReminderToneSetStatus == true)
235 if(__pReminderPlayer == null)
238 if(reminderTonePath.IsEmpty() == false)
240 __pReminderPlayer = new (std::nothrow) Player();
241 res = __pReminderPlayer->Construct(*this);
244 AppLogDebug("__pReminderPlayer Construct failed with %d",res);
245 delete __pReminderPlayer;
246 __pReminderPlayer = null;
249 res = __pReminderPlayer->OpenFile(reminderTonePath,false);
252 AppLogDebug("__pReminderPlayer OpenFile failed with %d",res);
253 delete __pReminderPlayer;
254 __pReminderPlayer = null;
257 res = __pReminderPlayer->SetLooping(false);
260 AppLogDebug("__pReminderPlayer SetLooping failed with %d",res);
261 delete __pReminderPlayer;
262 __pReminderPlayer = null;
265 res = __pReminderPlayer->SetVolume(80);
268 AppLogDebug("__pReminderPlayer SetVolume failed with %d",res);
269 delete __pReminderPlayer;
270 __pReminderPlayer = null;
276 if(__pReminderPlayer != null)
278 SetSoundMode(SOUND_MODE_MEDIA);
279 res = __pReminderPlayer->Play();
282 AppLogDebug("__pReminderPlayer Play failed with %d",res);
285 SetSoundMode(SOUND_MODE_VOICE);
288 /*else if(ReminderToneSetStatus == false)
298 SoundManager::SetDisconnectTone(void)
301 AppLogDebug("Enter");
302 int unknownRejectStatus = -1;
303 String disconnectTonePath=L"";
304 vconf_get_bool(VCONFKEY_CISSAPPL_CALL_END_TONE_BOOL, &unknownRejectStatus);
305 bool disconnectToneSetStatus = unknownRejectStatus;
306 result res = E_FAILURE;
308 if(disconnectToneSetStatus == true)
310 AppLogDebug("disconnectToneSetStatus == true");
311 disconnectTonePath.Append(CALLDISCONNECTTONE_PATH);
312 if(disconnectTonePath.IsEmpty() == false)
314 if(__pDisconnectPlayer == null)
316 AppLogDebug("__pConnectPlayer == null");
317 __pDisconnectPlayer = new (std::nothrow) Player();
318 res = __pDisconnectPlayer->Construct(*this);
321 AppLogDebug("__pDisconnectPlayer Construct failed with %d",res);
322 delete __pDisconnectPlayer;
323 __pDisconnectPlayer = null;
326 res = __pDisconnectPlayer->OpenFile(disconnectTonePath,false);
329 AppLogDebug("__pDisconnectPlayer OpenFile failed with %d",res);
330 delete __pDisconnectPlayer;
331 __pDisconnectPlayer = null;
334 res = __pDisconnectPlayer->SetLooping(false);
337 AppLogDebug("__pDisconnectPlayer SetLooping failed with %d",res);
338 delete __pDisconnectPlayer;
339 __pDisconnectPlayer = null;
342 res = __pDisconnectPlayer->SetVolume(80);
345 AppLogDebug("__pDisconnectPlayer SetLooping SetVolume with %d",res);
346 delete __pDisconnectPlayer;
347 __pDisconnectPlayer = null;
354 if(__pDisconnectPlayer != null)
356 AppLogDebug("__pDisconnectPlayer OpenFile %ls",disconnectTonePath.GetPointer());
357 SetSoundMode(SOUND_MODE_MEDIA);
358 AppLogDebug("__pDisconnectPlayer SetVolume");
359 if(__pDisconnectPlayer->GetState() == PLAYER_STATE_PLAYING)
361 __pDisconnectPlayer->Stop();
363 res = __pDisconnectPlayer->Play();
366 AppLogDebug("__pDisconnectPlayer Play with %d",res);
381 SoundManager::SetMinuteReminderTone(void)
383 __timer.StartAsRepeatable(60000);
388 SoundManager::SetConnectTone(void)
391 String connectTonePath;
392 int unknownRejectStatus = -1;
393 vconf_get_bool(VCONFKEY_CISSAPPL_CALL_CONNECT_TONE_BOOL, &unknownRejectStatus);
394 bool connectToneSetStatus = unknownRejectStatus;
395 result res = E_FAILURE;
397 connectTonePath.Append(CALLCONNECTTONE_PATH);
399 if(connectToneSetStatus == true)
402 if(__pConnectPlayer == null)
404 if (connectTonePath.IsEmpty() == false)
406 __pConnectPlayer = new (std::nothrow) Player();
407 res = __pConnectPlayer->Construct(*this);
410 AppLogDebug("__pConnectPlayer Construct failed with %d",res);
411 delete __pConnectPlayer;
412 __pConnectPlayer = null;
415 res = __pConnectPlayer->OpenFile(connectTonePath,false);
418 AppLogDebug("__pConnectPlayer OpenFile failed with %d",res);
419 delete __pConnectPlayer;
420 __pConnectPlayer = null;
423 res = __pConnectPlayer->SetLooping(false);
426 AppLogDebug("__pConnectPlayer SetLooping failed with %d",res);
427 delete __pConnectPlayer;
428 __pConnectPlayer = null;
431 res = __pConnectPlayer->SetVolume(80);
434 AppLogDebug("__pConnectPlayer SetVolume failed with %d",res);
435 delete __pConnectPlayer;
436 __pConnectPlayer = null;
442 if(__pConnectPlayer != null)
444 res = SetSoundMode(SOUND_MODE_MEDIA);
445 AppLogDebug("__pConnectPlayer Playing connect tone");
446 res = __pConnectPlayer->Play();
449 AppLogDebug("__pConnectPlayer Play failed with %d",res);
460 SoundManager::SetWaitTone(void)
462 CallAlertStatus status= CALL_ALERT_SOUND;
463 int alertStatus = -1;
464 result res = E_FAILURE;
465 int retVal = vconf_get_int(VCONFKEY_CISSAPPL_ALERT_ON_CALL_INT, &alertStatus);
468 status = (CallAlertStatus) alertStatus;
470 AppLogDebug("No Alert already in call");
471 if(status == CALL_ALERT_SOUND)
473 AppLogDebug("Playing alert tone");
474 String waitingTonePath;
475 waitingTonePath.Append(CALLWAITINGTONE_PATH);
476 if(__pWaitingTonePlayer == null)
478 if (waitingTonePath.IsEmpty() == false)
480 __pWaitingTonePlayer = new (std::nothrow) Player();
481 res = __pWaitingTonePlayer->Construct(*this);
484 AppLogDebug("__pWaitingTonePlayer Construct failed with %d",res);
485 delete __pWaitingTonePlayer;
486 __pWaitingTonePlayer = null;
489 res = __pWaitingTonePlayer->OpenFile(waitingTonePath,false);
492 AppLogDebug("__pWaitingTonePlayer OpenFile failed with %d",res);
493 delete __pWaitingTonePlayer;
494 __pWaitingTonePlayer = null;
498 res = __pWaitingTonePlayer->SetLooping(true);
501 AppLogDebug("__pWaitingTonePlayer SetLooping failed with %d",res);
502 delete __pWaitingTonePlayer;
503 __pWaitingTonePlayer = null;
507 res = __pWaitingTonePlayer->SetVolume(80);
510 AppLogDebug("__pWaitingTonePlayer SetVolume failed with %d",res);
511 delete __pWaitingTonePlayer;
512 __pWaitingTonePlayer = null;
519 if( __pWaitingTonePlayer != null )
521 SetSoundMode(SOUND_MODE_MEDIA);
522 res = __pWaitingTonePlayer->Play();
525 AppLogDebug("__pWaitingTonePlayer Play failed with %d",res);
534 SoundManager::StartAlert(String& contactRingTone)
536 result res = E_FAILURE;
537 IntensityDurationVibrationPattern vibration;
538 vibration.duration = 3000;
539 vibration.intensity = -1;
540 AppLogDebug("Enter");
541 if(__pSoundCallSession != null)
550 if(__pVibrator == null)
552 __pVibrator = new (std::nothrow) Vibrator();
553 res = __pVibrator->Construct();
556 AppLogDebug("__pVibrator Construct failed with %d",res);
560 if(__pPlayer == null)
562 __pPlayer = new (std::nothrow) Player();
563 res = __pPlayer->Construct(*this);
566 AppLogDebug("__pPlayer Construct failed with %d",res);
573 vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &retVal);
574 __isSoundStatusOn = retVal;
575 vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &retVal);
576 __isVibrateStatusOn = retVal;
577 //todo: do only if call alert mode is set
578 if (__isSoundStatusOn == true)
581 //Check if contact has any custom ringtone, else play defautl ringtone.
582 if(contactRingTone.IsEmpty() == true)
584 char* pRingTonePtr = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR);
585 AppLog("Ringtone Path : %s",pRingTonePtr);
586 ringTonePath.Append(pRingTonePtr);
590 AppLog("Ringtone Path : %ls",contactRingTone.GetPointer());
591 ringTonePath.Append(contactRingTone);
594 //Check if file is present
596 res = file.Construct(ringTonePath, "r");
597 if(res != E_SUCCESS )
599 ringTonePath.Clear();
600 ringTonePath.Append(RINGTONE_PATH);
603 res = __pPlayer->OpenFile(ringTonePath,false);
606 AppLogDebug("__pPlayer Construct failed with %d",res);
609 res = __pPlayer->SetLooping(true);
612 AppLogDebug("__pPlayer Construct failed with %d",res);
615 res = __pPlayer->SetVolume(80);
618 AppLogDebug("__pPlayer Construct failed with %d",res);
621 res = SetSoundMode(SOUND_MODE_RINGTONE);
622 res = __pPlayer->Play();
625 AppLogDebug("__pPlayer Construct failed with %d",res);
629 if (__isVibrateStatusOn == true)
631 //todo: Get the level from settings
632 __pVibrator->Start(&vibration, 1, 1000);
639 SoundManager::StopAlert(void)
641 result res = E_FAILURE;
642 AppLogDebug("Enter");
643 if (__isSoundStatusOn == true)
646 if(__pPlayer != null)
648 AppLogDebug("Stopping ring tone");
649 if(__pPlayer->GetState() == PLAYER_STATE_PLAYING)
651 res = __pPlayer->Stop();
655 AppLogDebug("__pPlayer Stop failed with %d",res);
658 res = __pPlayer->Close();
661 AppLogDebug("__pPlayer Close failed with %d",res);
664 SetSoundMode(SOUND_MODE_VOICE);
665 __isSoundStatusOn = false;
669 if (__isVibrateStatusOn == true)
672 __isVibrateStatusOn = false;
674 if(__pWaitingTonePlayer != null)
676 if(__pWaitingTonePlayer->GetState() == PLAYER_STATE_PLAYING)
678 __pWaitingTonePlayer->Stop();
686 SoundManager::OnPlayerOpened(result r)
691 SoundManager::OnPlayerEndOfClip(void)
696 SoundManager::OnPlayerSeekCompleted(result r)
701 SoundManager::OnPlayerBuffering(int percent)
706 SoundManager::OnPlayerErrorOccurred(Tizen::Media::PlayerErrorReason r)
711 SoundManager::OnPlayerInterrupted(void)
716 SoundManager::OnPlayerReleased(void)
721 SoundManager::IsEarJackConnected(void)
723 int earJackStatus = -1;
724 if (vconf_get_int(VCONFKEY_SYSMAN_EARJACK, &earJackStatus) == 0)
726 if (earJackStatus == VCONFKEY_SYSMAN_EARJACK_REMOVED)