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;
204 if(ReminderToneSetStatus == true)
207 if(__pPlayer == null)
209 __pPlayer = new (std::nothrow) Player();
210 __pPlayer->Construct(*this);
213 reminderTonePath.Append(MINUTEREMINDERTONE_PATH);
214 if(reminderTonePath.IsEmpty() == false)
217 __pPlayer->OpenFile(reminderTonePath,false);
218 __pPlayer->SetLooping(false);
219 __pPlayer->SetVolume(80);
220 SetSoundMode(SOUND_MODE_MEDIA);
222 SetSoundMode(SOUND_MODE_VOICE);
225 /*else if(ReminderToneSetStatus == false)
235 SoundManager::SetDisconnectTone(void)
238 AppLogDebug("Enter");
239 int unknownRejectStatus = -1;
240 String disconnectTonePath=L"";
241 vconf_get_bool(VCONFKEY_CISSAPPL_CALL_END_TONE_BOOL, &unknownRejectStatus);
242 bool disconnectToneSetStatus = unknownRejectStatus;
244 if(disconnectToneSetStatus == true)
246 AppLogDebug("disconnectToneSetStatus == true");
247 disconnectTonePath.Append(CALLDISCONNECTTONE_PATH);
248 if(__pPlayer == null)
250 AppLogDebug("__pPlayer == null");
252 __pPlayer = new (std::nothrow) Player();
253 __pPlayer->Construct(*this);
254 AppLogDebug("__pPlayer Construct");
256 if(disconnectTonePath.IsEmpty() == false)
258 AppLogDebug("__pPlayer OpenFile %ls",disconnectTonePath.GetPointer());
259 __pPlayer->OpenFile(disconnectTonePath,false);
260 AppLogDebug("__pPlayer OpenFile");
261 __pPlayer->SetLooping(false);
262 AppLogDebug("__pPlayer SetLooping");
263 __pPlayer->SetVolume(80);
264 AppLogDebug("__pPlayer SetVolume");
265 SetSoundMode(SOUND_MODE_MEDIA);
266 AppLogDebug("__pPlayer SetVolume");
275 SoundManager::SetMinuteReminderTone()
278 int unknownRejectStatus = -1;
279 vconf_get_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, &unknownRejectStatus);
280 bool reminderToneSetStatus = unknownRejectStatus;
282 if(reminderToneSetStatus == true)
284 __timer.StartAsRepeatable(60000);
291 SoundManager::SetConnectTone()
294 result r = E_FAILURE;
295 String connectTonePath;
296 int unknownRejectStatus = -1;
297 vconf_get_bool(VCONFKEY_CISSAPPL_CALL_CONNECT_TONE_BOOL, &unknownRejectStatus);
298 bool connectToneSetStatus = unknownRejectStatus;
300 connectTonePath.Append(CALLCONNECTTONE_PATH);
302 if(connectToneSetStatus == true)
305 if(__pPlayer == null)
307 __pPlayer = new (std::nothrow) Player();
308 r = __pPlayer->Construct(*this);
310 if (connectTonePath.IsEmpty() == false)
313 r = __pPlayer->OpenFile(connectTonePath,false);
314 r = __pPlayer->SetLooping(false);
315 r = __pPlayer->SetVolume(80);
316 r = SetSoundMode(SOUND_MODE_MEDIA);
317 r = __pPlayer->Play();
323 SoundManager::StartAlert(String& contactRingTone)
325 AppLogDebug("Enter");
326 if(__pSoundCallSession != null)
328 CallAlertStatus status= CALL_ALERT_SOUND;
329 int alertStatus = -1;
330 int retVal = vconf_get_int(VCONFKEY_CISSAPPL_ALERT_ON_CALL_INT, &alertStatus);
333 status = (CallAlertStatus) alertStatus;
335 AppLogDebug("No Alert already in call");
336 if(status == CALL_ALERT_SOUND)
338 AppLogDebug("Playing alert tone");
339 String waitingTonePath;
340 waitingTonePath.Append(CALLWAITINGTONE_PATH);
341 if(__pPlayer == null)
343 __pPlayer = new (std::nothrow) Player();
344 __pPlayer->Construct(*this);
346 if (waitingTonePath.IsEmpty() == false)
349 __pPlayer->OpenFile(waitingTonePath,false);
350 __pPlayer->SetLooping(true);
351 __pPlayer->SetVolume(80);
352 SetSoundMode(SOUND_MODE_MEDIA);
362 result r = E_FAILURE;
363 if(__pVibrator == null)
365 __pVibrator = new (std::nothrow) Vibrator();
366 r = __pVibrator->Construct();
368 if(__pPlayer == null)
370 __pPlayer = new (std::nothrow) Player();
371 r = __pPlayer->Construct(*this);
374 vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &retVal);
375 __isSoundStatusOn = retVal;
376 vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &retVal);
377 __isVibrateStatusOn = retVal;
378 //todo: do only if call alert mode is set
379 if (__isSoundStatusOn == true)
382 //Check if contact has any custom ringtone, else play defautl ringtone.
383 if(contactRingTone.IsEmpty() == true)
385 char* pRingTonePtr = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR);
386 AppLog("Ringtone Path : %s",pRingTonePtr);
387 ringTonePath.Append(pRingTonePtr);
391 AppLog("Ringtone Path : %ls",contactRingTone.GetPointer());
392 ringTonePath.Append(contactRingTone);
395 //Check if file is present
397 result res = file.Construct(ringTonePath, "r");
398 if(res != E_SUCCESS )
400 ringTonePath.Clear();
401 ringTonePath.Append(RINGTONE_PATH);
404 r = __pPlayer->OpenFile(ringTonePath,false);
405 r = __pPlayer->SetLooping(true);
406 r = __pPlayer->SetVolume(80);
407 r = SetSoundMode(SOUND_MODE_RINGTONE);
408 r = __pPlayer->Play();
410 if (__isVibrateStatusOn == true)
412 //todo: Get the level from settings
413 r = __pVibrator->Start(3000,1000,1000);
420 SoundManager::StopAlert(void)
422 AppLogDebug("Enter");
423 if (__isSoundStatusOn == true)
426 AppLogDebug("Stopping ring tone");
429 SetSoundMode(SOUND_MODE_VOICE);
430 __isSoundStatusOn = false;
433 if (__isVibrateStatusOn == true)
436 __isVibrateStatusOn = false;
442 SoundManager::OnPlayerOpened(result r)
447 SoundManager::OnPlayerEndOfClip(void)
452 SoundManager::OnPlayerSeekCompleted(result r)
457 SoundManager::OnPlayerBuffering(int percent)
462 SoundManager::OnPlayerErrorOccurred(Tizen::Media::PlayerErrorReason r)
467 SoundManager::OnPlayerInterrupted(void)
472 SoundManager::OnPlayerReleased(void)
477 SoundManager::IsEarJackConnected(void)
479 int earJackStatus = -1;
480 if (vconf_get_int(VCONFKEY_SYSMAN_EARJACK, &earJackStatus) == 0)
482 if (earJackStatus == VCONFKEY_SYSMAN_EARJACK_REMOVED)