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 int unknownRejectStatus = -1;
239 String disconnectTonePath;
240 vconf_get_bool(VCONFKEY_CISSAPPL_CALL_END_TONE_BOOL, &unknownRejectStatus);
241 bool disconnectToneSetStatus = unknownRejectStatus;
243 if(disconnectToneSetStatus == true)
245 disconnectTonePath.Append(CALLDISCONNECTTONE_PATH);
246 if(__pPlayer == null)
248 __pPlayer = new (std::nothrow) Player();
249 __pPlayer->Construct(*this);
251 if(disconnectTonePath.IsEmpty() == false)
254 __pPlayer->OpenFile(disconnectTonePath,false);
255 __pPlayer->SetLooping(false);
256 __pPlayer->SetVolume(80);
257 SetSoundMode(SOUND_MODE_MEDIA);
265 SoundManager::SetMinuteReminderTone()
268 int unknownRejectStatus = -1;
269 vconf_get_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, &unknownRejectStatus);
270 bool reminderToneSetStatus = unknownRejectStatus;
272 if(reminderToneSetStatus == true)
274 __timer.StartAsRepeatable(60000);
281 SoundManager::SetConnectTone()
284 result r = E_FAILURE;
285 String connectTonePath;
286 int unknownRejectStatus = -1;
287 vconf_get_bool(VCONFKEY_CISSAPPL_CALL_CONNECT_TONE_BOOL, &unknownRejectStatus);
288 bool connectToneSetStatus = unknownRejectStatus;
290 connectTonePath.Append(CALLCONNECTTONE_PATH);
292 if(connectToneSetStatus == true)
295 if(__pPlayer == null)
297 __pPlayer = new (std::nothrow) Player();
298 r = __pPlayer->Construct(*this);
300 if (connectTonePath.IsEmpty() == false)
303 r = __pPlayer->OpenFile(connectTonePath,false);
304 r = __pPlayer->SetLooping(false);
305 r = __pPlayer->SetVolume(80);
306 r = SetSoundMode(SOUND_MODE_MEDIA);
307 r = __pPlayer->Play();
313 SoundManager::StartAlert(String& contactRingTone)
315 AppLogDebug("Enter");
316 if(__pSoundCallSession != null)
318 AppLogDebug("No Alert already in call");
319 String waitingTonePath;
320 waitingTonePath.Append(CALLWAITINGTONE_PATH);
321 if(__pPlayer == null)
323 __pPlayer = new (std::nothrow) Player();
324 __pPlayer->Construct(*this);
326 if (waitingTonePath.IsEmpty() == false)
329 __pPlayer->OpenFile(waitingTonePath,false);
330 __pPlayer->SetLooping(true);
331 __pPlayer->SetVolume(80);
332 SetSoundMode(SOUND_MODE_MEDIA);
341 result r = E_FAILURE;
342 if(__pVibrator == null)
344 __pVibrator = new (std::nothrow) Vibrator();
345 r = __pVibrator->Construct();
347 if(__pPlayer == null)
349 __pPlayer = new (std::nothrow) Player();
350 r = __pPlayer->Construct(*this);
353 vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &retVal);
354 __isSoundStatusOn = retVal;
355 vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &retVal);
356 __isVibrateStatusOn = retVal;
357 //todo: do only if call alert mode is set
358 if (__isSoundStatusOn == true)
361 //Check if contact has any custom ringtone, else play defautl ringtone.
362 if(contactRingTone.IsEmpty() == true)
364 char* pRingTonePtr = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR);
365 AppLog("Ringtone Path : %s",pRingTonePtr);
366 ringTonePath.Append(pRingTonePtr);
370 AppLog("Ringtone Path : %ls",contactRingTone.GetPointer());
371 ringTonePath.Append(contactRingTone);
374 //Check if file is present
376 result res = file.Construct(ringTonePath, "r");
377 if(res != E_SUCCESS )
379 ringTonePath.Clear();
380 ringTonePath.Append(RINGTONE_PATH);
383 r = __pPlayer->OpenFile(ringTonePath,false);
384 r = __pPlayer->SetLooping(true);
385 r = __pPlayer->SetVolume(80);
386 r = SetSoundMode(SOUND_MODE_RINGTONE);
387 r = __pPlayer->Play();
389 if (__isVibrateStatusOn == true)
391 //todo: Get the level from settings
392 r = __pVibrator->Start(3000,1000,1000);
399 SoundManager::StopAlert(void)
401 AppLogDebug("Enter");
402 if (__isSoundStatusOn == true)
405 AppLogDebug("Stopping ring tone");
408 SetSoundMode(SOUND_MODE_VOICE);
409 __isSoundStatusOn = false;
412 if (__isVibrateStatusOn == true)
415 __isVibrateStatusOn = false;
421 SoundManager::OnPlayerOpened(result r)
426 SoundManager::OnPlayerEndOfClip(void)
431 SoundManager::OnPlayerSeekCompleted(result r)
436 SoundManager::OnPlayerBuffering(int percent)
441 SoundManager::OnPlayerErrorOccurred(Tizen::Media::PlayerErrorReason r)
446 SoundManager::OnPlayerInterrupted(void)
451 SoundManager::OnPlayerReleased(void)
456 SoundManager::IsEarJackConnected(void)
458 int earJackStatus = -1;
459 if (vconf_get_int(VCONFKEY_SYSMAN_EARJACK, &earJackStatus) == 0)
461 if (earJackStatus == VCONFKEY_SYSMAN_EARJACK_REMOVED)