Make TIZEN 2.0
[apps/home/call.git] / call-engine / voice-call-sound.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
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
7  *
8  * http://www.tizenopensource.org/license
9  *
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.
15  */
16
17
18 #include "voice-call-sound.h"
19 #include "vc-core-util.h"
20 #include "vc-core-engine-types.h"
21 #include "voice-call-core.h"
22 #include "voice-call-bt.h"
23 #include "voice-call-service.h"
24 #include "voice-call-device.h"
25 #include <vconf.h>
26 #include <vconf-keys.h>
27
28 #include <mm_message.h>
29 #include <mm_player.h>
30 #include <media/sound_manager.h>
31 #include <mm_sound_private.h>
32 #include <mm_types.h>
33 #include <mm_error.h>
34
35 #include <mm_session.h>
36 #include <mm_session_private.h>
37
38 #include <devman_haptic.h>
39
40 #define VOICE_CALL_SND_INVALID_SND_HANDLE                       -1      /**<Invalid Sound lib Handle*/
41 #define VOICE_CALL_SND_INVALID_PLAYER_HANDLE            0       /**<Invalid player lib Handle*/
42
43 #define VOICE_CALL_SND_VIBON_TIME_PERIOD                1500    /**< Vibration On Timer Interval */
44 #define VOICE_CALL_SND_VIBOFF_TIME_PERIOD               500             /**< Vibration Off Timer Interval  */
45 #define VOICE_CALL_SND_INCREMENT_TIMER_INTERVAL 2000    /**< Incremental Melody Timer Interval  */
46 #define VOICE_CALL_SND_VIB_THEN_MELODY_TIMER_INTERVAL   6000    /**< 6 sec  (3 * (VOICE_CALL_SND_VIBON_TIME_PERIOD + VOICE_CALL_SND_VIBOFF_TIME_PERIOD)) approximately*/
47 #define VOICE_CALL_SND_2ND_CALL_BEEP_INTERVAL   2500
48
49 #define VOICE_CALL_SND_DEFAULT_RINGTONE_PATH            MEDIADIR"/01_Minimal_tone.mp3"
50 #define VOICE_CALL_SND_SECOND_RINGTONE_PATH                     MEDIADIR"/Call_WaitingTone.wav"
51
52 #define VOICE_CALL_SND_CONNECT_SIGNAL_PATH                      MEDIADIR"/03_Call_connect.wav"
53 #define VOICE_CALL_SND_DISCONNECT_SIGNAL_PATH           MEDIADIR"/04_Call_disconnect.wav"
54 #define VOICE_CALL_SND_MINUTE_MINDER_SIGNAL_PATH                MEDIADIR"/03_Call_connect.wav"
55
56 #define VOICE_CALL_SND_USER_BUSY_SIGNAL_PATH            MEDIADIR"/Call_BusyTone.wav"
57 #define VOICE_CALL_SND_NW_CONGESTION_SIGNAL_PATH        MEDIADIR"/Call_NwCongestionTone.wav"
58 #define VOICE_CALL_SND_ERROR_SIGNAL_PATH                                MEDIADIR"/Call_ErrorTone.wav"
59
60 /**
61  * Enumeration for volume level of 10 levels
62  */
63 typedef enum _voicecall_snd_mm_vol_level9_t {
64         VOICE_CALL_SND_MM_VOLUME_LEVEL_0_9 = 0,                 /**< volume level 1 of 10 */
65         VOICE_CALL_SND_MM_VOLUME_LEVEL_1_9 = 16,                /**< volume level 2 of 10 */
66         VOICE_CALL_SND_MM_VOLUME_LEVEL_2_9 = 28,                /**< volume level 3 of 10 */
67         VOICE_CALL_SND_MM_VOLUME_LEVEL_3_9 = 39,                /**< volume level 4 of 10 */
68         VOICE_CALL_SND_MM_VOLUME_LEVEL_4_9 = 50,                /**< volume level 5 of 10 */
69         VOICE_CALL_SND_MM_VOLUME_LEVEL_5_9 = 62,                /**< volume level 6 of 10 */
70         VOICE_CALL_SND_MM_VOLUME_LEVEL_6_9 = 73,                /**< volume level 7 of 10 */
71         VOICE_CALL_SND_MM_VOLUME_LEVEL_7_9 = 82,                /**< volume level 8 of 10 */
72         VOICE_CALL_SND_MM_VOLUME_LEVEL_8_9 = 91,                /**< volume level 9 of 10 */
73         VOICE_CALL_SND_MM_VOLUME_LEVEL_9_9 = 100,               /**< volume level 10 of 10 */
74 } voicecall_snd_mm_vol_level9_t;
75
76 typedef struct __voicecall_snd_path_info_t {
77         int phone_path;                                 /**< normal call state path */
78         int alert_phone_path;                           /**< alert sound to other party (record alert beep or answering machine guidance) */
79         gboolean bmic_on;
80 } voicecall_snd_path_info_t;
81
82 /* Local Fucntion Declerations */
83 /**
84  * This function prepares to start the melody to be played according to the given parameters
85  *
86  * @return              Returns TRUE on success or FALSE on failure
87  * @param[in]           papp_snd                        Handle to the Sound Manager
88  * @param[in]           bis_increasing          TRUE - Increasing Melody, FALSE -Normal Melody
89  * @param[in]           call_handle             Call Handle of the Incoming Call
90  */
91 static gboolean __voicecall_snd_start_melody(voicecall_snd_mgr_t *papp_snd, gboolean bis_increasing, int call_handle);
92
93  /**
94 * This function create the mm player
95 *
96 * @return       turns TRUE on success or FALSE on failure
97 * @param[in]            papp_snd                Handle to the Soudn Manager
98 * @param[in]            pPlayer         Handle to the mm player
99 * @param[in]            play_type               Play Type of the Sound
100 */
101 static gboolean __voicecall_snd_create_player(voicecall_snd_mgr_t *papp_snd, MMHandleType * pPlayer, voicecall_snd_play_type_t play_type);
102
103  /**
104  * This function starts the vibration
105  *
106  * @return              Returns nothing
107  * @param[in]           papp_snd                        Handle to the Sound Manager
108  */
109 static void __voicecall_snd_start_vibration(voicecall_snd_mgr_t *papp_snd);
110
111 /**
112 * This function stops the vibration
113 *
114 * @return               Returns TRUE on success or FALSE on failure
115 * @param[in]            papp_snd                        Handle to the Sound Manager
116 */
117 static void __voicecall_snd_stop_vibration(voicecall_snd_mgr_t *papp_snd);
118
119  /**
120  * This function serves as the callbback for the MM Player
121  *
122  * @return              Returns TRUE on success or FALSE on failure
123  * @param[in]           message         MM Message from the MM Player
124  * @param[in]           data                    Data send by the MM Player according to the Message
125  * @param[in]           user_data       Local Data by the Caller
126  */
127 static int __voicecall_snd_mmplayer_cb(int message, void *data, void *user_data);
128
129 static void __voicecall_snd_mmplayer_signal_cb(gpointer puser_data);
130
131  /**
132  * This function serves as the callback for the increasing melody periodic timer
133  *
134  * @return              Returns TRUE if sound cane be played or FALSE otherwise
135  * @param[in]           data            Loca Data set by the caller
136  */
137 static gboolean __voicecall_snd_increasing_melody_cb(void *data);
138
139  /**
140 * This function plays the ringtone melody according to the settings
141 *
142 * @return               void
143 * @param[in]            papp_snd                Handle to the Sound Manager
144 * @param[in]            bis_increasing          TRUE - increasing melody, FALSE - normal
145 */
146 static gboolean __voicecall_snd_play_melody(voicecall_snd_mgr_t *papp_snd, gboolean bis_increasing);
147
148 /**
149 * This function sets the mm player volume according to the settings volume level
150 *
151 * @return               void
152 * @param[in]            papp_snd                Handle to the Sound Manager
153 * @param[in]            bis_increasing          TRUE if incremntal melody type, FALSE otherwise
154 */
155 static void __voicecall_snd_set_mm_volume(voicecall_snd_mgr_t *papp_snd, int bis_increasing);
156
157 /**
158  * This function retreives the tapi sound path to be used according to the current status
159  *
160  * @return              void
161  * @param[in]           papp_snd                Handle to Sound Manager
162  * @param[out]  voice_snd_path          Tapi Sound Path
163  */
164 static void __voicecall_snd_get_voice_path(voicecall_snd_mgr_t *papp_snd, int *voice_snd_path);
165
166 /*Function Defintions*/
167 /**
168  * This function initializes the sound functionalties required by the Application
169  *
170  * @return              Returns TRUE on success or FALSE on failure
171  * @param[in]           pcall_core              Handle to voicecall core
172  * @param[out]  papp_snd                        Handle to the Sound Manager
173  */
174 gboolean voicecall_snd_init(void *pcall_core, voicecall_snd_mgr_t **papp_snd)
175 {
176         voicecall_snd_mgr_t *psnd_mgr = NULL;
177
178         CALL_ENG_DEBUG(ENG_DEBUG, "Sound CM Test");
179
180         psnd_mgr = (voicecall_snd_mgr_t *)calloc(1, sizeof(voicecall_snd_mgr_t));
181
182         if (psnd_mgr == NULL) {
183                 CALL_ENG_DEBUG(ENG_ERR, "Memory Allocation Failed");
184                 return FALSE;
185         }
186         CALL_ENG_DEBUG(ENG_DEBUG, "psnd_mgr alloctated memory:[%d]", sizeof(voicecall_snd_mgr_t));
187
188         /*Store  voice call Handle */
189         psnd_mgr->pcall_core = pcall_core;
190         psnd_mgr->current_snd_path = VOICE_CALL_SND_PATH_RECEIVER_EARJACK;
191         psnd_mgr->old_snd_path = VOICE_CALL_SND_PATH_NONE;
192         psnd_mgr->bsound_cm_state = FALSE;
193
194         psnd_mgr->pmm_player = VOICE_CALL_SND_INVALID_PLAYER_HANDLE;
195         psnd_mgr->pmm_signal_player = VOICE_CALL_SND_INVALID_SND_HANDLE;
196
197         psnd_mgr->mmfsoundplay_handle = VOICE_CALL_SND_INVALID_SND_HANDLE;
198         psnd_mgr->mmfalternateplay_handle = VOICE_CALL_SND_INVALID_SND_HANDLE;
199
200         psnd_mgr->psignal_play_end_cb = NULL;
201         psnd_mgr->psignal_play_end_cb_data = NULL;
202
203         /*Return the created Sound Manager */
204         *papp_snd = psnd_mgr;
205         return TRUE;
206
207 }
208
209 void __voicecall_snd_alternate_sound_cb(void *puser_data);
210 void __voicecall_snd_play_alternate_sound(voicecall_snd_mgr_t *papp_snd);
211 gboolean __voicecall_snd_stop_alternate_sound(voicecall_snd_mgr_t *papp_snd);
212
213 gboolean __voicecall_snd_alternate_sound_idle_cb(void *puser_data)
214 {
215         voicecall_snd_mgr_t *papp_snd = (voicecall_snd_mgr_t *)puser_data;
216         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)papp_snd->pcall_core;
217
218         CALL_ENG_DEBUG(ENG_DEBUG, "..");
219
220         if (TRUE == papp_snd->balternate_play) {
221                 if ((FALSE == voicecall_core_is_connected_call_exist(pcall_core->pcall_engine))
222                     && (TRUE == voicecall_core_is_incoming_call_exists(pcall_core->pcall_engine))) {
223                         /* case : during 2nd incoming call, connected call is cleared. so, just 1 incoming call case... */
224                         CALL_ENG_DEBUG(ENG_DEBUG, "2nd incoming -> just single incoming call.");
225                         voicecall_snd_prepare_alert(papp_snd, papp_snd->incoming_call_handle);
226                         sound_manager_call_session_set_mode(papp_snd->psnd_session, SOUND_CALL_SESSION_MODE_RINGTONE);
227                         voicecall_snd_play_alert(papp_snd);
228                 } else {
229                         __voicecall_snd_play_alternate_sound(papp_snd);
230                 }
231         }
232
233         return FALSE;
234 }
235
236 gboolean __voicecall_snd_alternate_play_timeout_cb(gpointer pdata)
237 {
238         voicecall_snd_mgr_t *papp_snd = (voicecall_snd_mgr_t *)pdata;
239
240         CALL_ENG_DEBUG(ENG_DEBUG, "..");
241         if (papp_snd->balternate_play == TRUE) {
242                 __voicecall_snd_play_alternate_sound(papp_snd);
243         }
244
245         return FALSE;
246 }
247
248 void __voicecall_snd_play_alternate_sound(voicecall_snd_mgr_t *papp_snd)
249 {
250         CALL_ENG_DEBUG(ENG_DEBUG, "..");
251         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)papp_snd->pcall_core;
252
253         if (TRUE == voicecall_core_is_incoming_call_exists(pcall_core->pcall_engine)) {
254                 CALL_ENG_DEBUG(ENG_DEBUG, "Incoming call is there!Play Alternate Sound");
255
256                 int mmf_error = -1;
257
258                 char ring_tone[VOICE_CALL_SND_RINGTONE_PATH_LEN];
259                 snprintf(ring_tone, sizeof(ring_tone), "file://%s", VOICE_CALL_SND_SECOND_RINGTONE_PATH);
260
261                 sound_manager_call_session_set_mode(pcall_core->papp_snd->psnd_session, SOUND_CALL_SESSION_MODE_MEDIA);
262
263                 CALL_ENG_DEBUG(ENG_DEBUG, "Call mm_sound_play_sound to play alternate ringtonen");
264                 mmf_error = mm_sound_play_sound(VOICE_CALL_SND_SECOND_RINGTONE_PATH, VOLUME_TYPE_CALL, __voicecall_snd_alternate_sound_cb, papp_snd, &papp_snd->mmfalternateplay_handle);
265
266                 if (MM_ERROR_NONE == mmf_error) {
267                         papp_snd->balternate_play = TRUE;
268                         papp_snd->ringtone_sound_status = VOICE_CALL_SND_STATUS_PLAY;
269                         CALL_ENG_DEBUG(ENG_DEBUG, "Alternate Sound Play Called,papp_snd->balternate_play=%d", papp_snd->balternate_play);
270                 } else {
271                         papp_snd->ringtone_sound_status = VOICE_CALL_SND_STATUS_STOP;
272                         papp_snd->balternate_play = FALSE;
273                         CALL_ENG_DEBUG(ENG_DEBUG, "mmf_error = [0x%x]", mmf_error);
274                 }
275                 CALL_ENG_DEBUG(ENG_DEBUG, "End of Alternate Sound!");
276         }
277 }
278
279 gboolean __voicecall_snd_stop_alternate_sound(voicecall_snd_mgr_t *papp_snd)
280 {
281         CALL_ENG_DEBUG(ENG_DEBUG, " papp_snd->balternate_play = %d", papp_snd->balternate_play);
282         if (TRUE == papp_snd->balternate_play) {
283                 /*Only Stop if it is in Play State */
284                 if (VOICE_CALL_SND_STATUS_PLAY == papp_snd->ringtone_sound_status) {
285                         int error = 0;
286                         error = mm_sound_stop_sound(papp_snd->mmfalternateplay_handle);
287                         papp_snd->mmfalternateplay_handle = -1;
288                         papp_snd->ringtone_sound_status = VOICE_CALL_SND_STATUS_STOP;
289                         CALL_ENG_DEBUG(ENG_ERR, "Alternate Ringtone Stopeed,Error Code: [0x%x]", error);
290                 }
291                 papp_snd->balternate_play = FALSE;
292                 return TRUE;
293         }
294         return FALSE;
295 }
296
297 void __voicecall_snd_alternate_sound_cb(void *puser_data)
298 {
299         voicecall_snd_mgr_t *papp_snd = (voicecall_snd_mgr_t *)puser_data;
300         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)papp_snd->pcall_core;
301
302         CALL_ENG_DEBUG(ENG_DEBUG, "papp_snd->balternate_play= %d", papp_snd->balternate_play);
303
304         papp_snd->ringtone_sound_status = VOICE_CALL_SND_STATUS_STOPPED;
305
306         /*If connected call exists then change the audio path */
307         if ((TRUE == voicecall_core_is_connected_call_exist(pcall_core->pcall_engine)) || (TRUE == voicecall_core_is_outgoing_call_exists(pcall_core->pcall_engine))) {
308                 voicecall_snd_change_path(papp_snd);
309         }
310
311         g_timeout_add(VOICE_CALL_SND_2ND_CALL_BEEP_INTERVAL, __voicecall_snd_alternate_sound_idle_cb, papp_snd);
312
313 }
314
315 void voicecall_snd_prepare_alert(voicecall_snd_mgr_t *papp_snd, int call_handle)
316 {
317         CALL_ENG_DEBUG(ENG_DEBUG, "..");
318
319         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)papp_snd->pcall_core;
320         int err_code = -1;
321
322         papp_snd->incoming_call_handle = call_handle;
323
324         /* Save the original volume level to reset */
325         err_code = mm_sound_volume_get_value(VOLUME_TYPE_RINGTONE, (unsigned int *) &(papp_snd->org_ringtone_value));
326
327         if (MM_ERROR_NONE != err_code) {
328                 CALL_ENG_DEBUG(ENG_ERR, "Get Volume Error: [0x%x]", err_code);
329                 return;
330         }
331
332         if (TRUE == voicecall_core_is_connected_call_exist(pcall_core->pcall_engine)) {
333                 CALL_ENG_DEBUG(ENG_DEBUG, "Alternate Sound Needs to be played");
334                 papp_snd->ringtone_sound_status = VOICE_CALL_AND_STATUS_ALTERNATE_PLAY;
335                 return;
336         }
337
338         /*
339            Always stop the alert before starting another
340            to make sure the previous alert is proerly closed.
341          */
342         voicecall_snd_stop_alert(papp_snd);
343
344         /*Initizlize Variables */
345         papp_snd->pmm_player = VOICE_CALL_SND_INVALID_PLAYER_HANDLE;
346         papp_snd->settings_sound_status = FALSE;
347         papp_snd->settings_vib_status = FALSE;
348
349         err_code = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &papp_snd->settings_sound_status);
350         CALL_ENG_DEBUG(ENG_DEBUG, "cur_sound_status = %d, error_code = %d", papp_snd->settings_sound_status, err_code);
351
352         err_code = vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &papp_snd->settings_vib_status);
353         CALL_ENG_DEBUG(ENG_DEBUG, "cur_vib_status = %d, error_code = %d", papp_snd->settings_vib_status, err_code);
354
355         if (papp_snd->settings_sound_status == FALSE)
356                 papp_snd->bmute_play = TRUE;
357
358         __voicecall_snd_start_melody(papp_snd, FALSE, call_handle);
359 }
360
361 void voicecall_snd_play_alert(voicecall_snd_mgr_t *papp_snd)
362 {
363         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)papp_snd->pcall_core;
364
365         CALL_ENG_DEBUG(ENG_DEBUG, "papp_snd->ringtone_sound_status=%d", papp_snd->ringtone_sound_status);
366
367         if (VOICE_CALL_AND_STATUS_ALTERNATE_PLAY == papp_snd->ringtone_sound_status) {
368                 if (TRUE == voicecall_core_is_connected_call_exist(pcall_core->pcall_engine)) {
369                         CALL_ENG_DEBUG(ENG_DEBUG, "Starting Alternate Sound");
370                         papp_snd->balternate_play_count = 0;
371                         __voicecall_snd_play_alternate_sound(papp_snd);
372                 }
373         }
374
375         if (VOICE_CALL_SND_STATUS_READY != papp_snd->ringtone_sound_status) {
376                 CALL_ENG_DEBUG(ENG_DEBUG, " Invalid ringtone_sound_status: %d", papp_snd->ringtone_sound_status);
377                 return;
378         }
379
380         papp_snd->ringtone_sound_status = VOICE_CALL_SND_STATUS_PROCESSED;
381
382         CALL_ENG_DEBUG(ENG_DEBUG, " [##### papp_snd->settings_sound_status #####] : %d", papp_snd->settings_sound_status);
383         CALL_ENG_DEBUG(ENG_DEBUG, " [##### papp_snd->settings_vib_status #####] : %d", papp_snd->settings_vib_status);
384
385         sound_manager_call_session_set_mode(papp_snd->psnd_session, SOUND_CALL_SESSION_MODE_RINGTONE);
386         __voicecall_snd_play_melody(papp_snd, FALSE);
387
388         if (papp_snd->settings_vib_status) {
389                 __voicecall_snd_start_vibration(papp_snd);
390         }
391 }
392
393 gboolean voicecall_snd_mute_alert(voicecall_snd_mgr_t *papp_snd)
394 {
395         CALL_ENG_DEBUG(ENG_DEBUG, "..");
396         if (papp_snd->pmm_player != VOICE_CALL_SND_INVALID_PLAYER_HANDLE) {
397                 int ret_value = 0;
398
399                 ret_value = mm_player_set_mute(papp_snd->pmm_player, TRUE);
400                 CALL_ENG_DEBUG(ENG_DEBUG, "MM Set Mute Error code: [0x%x]", ret_value);
401         }
402
403         if (TRUE == papp_snd->bvibration) {
404                 CALL_ENG_DEBUG(ENG_DEBUG, "Vibration is playing, stopping vibration");
405                 __voicecall_snd_stop_vibration(papp_snd);
406         }
407
408         /*Make Vibration than melody flag to FALSE, so melody will not be played when it is muted */
409         papp_snd->bvibration_then_melody = FALSE;
410
411         /*Make Increasing Melody flag to FALSE, so melody volume will not be increased when it is muted */
412         papp_snd->bincreasingmelody = FALSE;
413
414         return FALSE;
415 }
416
417 /**
418  * This function stops the sound alert
419  *
420  * @return              void
421  * @param[in]           papp_snd                        Handle to Sound Manager
422  */
423 void voicecall_snd_stop_alert(voicecall_snd_mgr_t *papp_snd)
424 {
425         CALL_ENG_DEBUG(ENG_DEBUG, "..");
426
427         __voicecall_snd_stop_vibration(papp_snd);
428
429         if (TRUE == __voicecall_snd_stop_alternate_sound(papp_snd)) {
430                 CALL_ENG_DEBUG(ENG_DEBUG, "Alternate sound stopped");
431                 return;
432         }
433
434         CALL_ENG_DEBUG(ENG_DEBUG, "pmm_player = %d", papp_snd->pmm_player);
435         if (papp_snd->pmm_player != VOICE_CALL_SND_INVALID_PLAYER_HANDLE) {
436                 int ret_value = 0;
437                 MMPlayerStateType mmplayer_state = MM_PLAYER_STATE_NONE;
438
439                 /*Sound Stop requested by the Application */
440                 papp_snd->ringtone_sound_status = VOICE_CALL_SND_STATUS_STOP;
441
442                 mm_player_get_state(papp_snd->pmm_player, &mmplayer_state);
443
444                 CALL_ENG_DEBUG(ENG_DEBUG, "Callling mmplayer_stop, current mm state = %d, Player = %d", mmplayer_state, papp_snd->pmm_player);
445                 if (MM_PLAYER_STATE_PLAYING == mmplayer_state || MM_PLAYER_STATE_PAUSED == mmplayer_state) {
446                         ret_value = mm_player_stop(papp_snd->pmm_player);
447                         if (MM_ERROR_NONE != ret_value) {
448                                 CALL_ENG_DEBUG(ENG_ERR, "mmplayer_stop failed: [0x%x]", ret_value);
449                         }
450                 }
451
452                 CALL_ENG_DEBUG(ENG_DEBUG, "Callling mmplayer_unrealize, Player = %d", papp_snd->pmm_player);
453                 ret_value = mm_player_unrealize(papp_snd->pmm_player);
454                 if (MM_ERROR_NONE != ret_value) {
455                         CALL_ENG_DEBUG(ENG_ERR, "mmplayer_unrealize failed: [0x%x]", ret_value);
456                 }
457
458                 CALL_ENG_DEBUG(ENG_DEBUG, "Callling mmplayer_destroy, Player = %d", papp_snd->pmm_player);
459                 ret_value = mm_player_destroy(papp_snd->pmm_player);
460                 if (MM_ERROR_NONE != ret_value) {
461                         CALL_ENG_DEBUG(ENG_ERR, "mmplayer_destroy failed: [0x%x]", ret_value);
462                 }
463                 papp_snd->pmm_player = VOICE_CALL_SND_INVALID_PLAYER_HANDLE;
464
465                 papp_snd->ringtone_sound_status = VOICE_CALL_SND_STATUS_STOPPED;
466
467                 ret_value = mm_sound_volume_set_value(VOLUME_TYPE_RINGTONE, papp_snd->org_ringtone_value);
468
469                 if (MM_ERROR_NONE != ret_value) {
470                         CALL_ENG_DEBUG(ENG_ERR, "Set Volume Error: [0x%x]", ret_value);
471                 }
472         }
473
474         /* Stop All periodic Timers */
475         papp_snd->bvibration_then_melody = FALSE;
476         papp_snd->bincreasingmelody = FALSE;
477
478         /* Make the Current Sound Playing Call HAndle Invalid */
479         papp_snd->current_playing_call_handle = -1;
480
481         papp_snd->bmute_play = FALSE;
482
483 }
484
485 gboolean voicecall_snd_set_play_end_callback(voicecall_snd_mgr_t *papp_snd, voicecall_snd_callback psignal_play_end_cb, gpointer psignal_play_end_cb_data)
486 {
487         CALL_ENG_DEBUG(ENG_DEBUG, "signal_type = %d", papp_snd->signal_type);
488
489         if (VOICE_CALL_SND_STATUS_NONE == papp_snd->signal_sound_status) {
490                 CALL_ENG_DEBUG(ENG_DEBUG, "No Signal Being Played");
491                 return FALSE;
492         }
493
494         papp_snd->psignal_play_end_cb = psignal_play_end_cb;
495         papp_snd->psignal_play_end_cb_data = psignal_play_end_cb_data;
496
497         return TRUE;
498 }
499
500 /**
501  * This function plays call sound
502  *
503  * @return              Returns TRUE on success or FALSE on failure
504  * @param[in]           papp_snd                        Handle to Sound Manager
505  */
506 gboolean voicecall_snd_is_signal_playing(voicecall_snd_mgr_t *papp_snd)
507 {
508         CALL_ENG_DEBUG(ENG_DEBUG, "Signal Sound Status : [%d]", papp_snd->signal_sound_status);
509         if ((papp_snd->pmm_signal_player != VOICE_CALL_SND_INVALID_SND_HANDLE) && (VOICE_CALL_SND_STATUS_PLAY == papp_snd->signal_sound_status)) {
510                 CALL_ENG_DEBUG(ENG_DEBUG, "Signal is playing");
511                 return TRUE;
512         }
513
514         CALL_ENG_DEBUG(ENG_DEBUG, "Signal is not playing");
515         return FALSE;
516 }
517
518 gboolean voicecall_snd_play_signal(voicecall_snd_mgr_t *papp_snd, voicecall_snd_callback psignal_play_end_cb, gpointer psignal_play_end_cb_data)
519 {
520         int ret_value = 0;
521
522         CALL_ENG_DEBUG(ENG_DEBUG, "signal_type = %d", papp_snd->signal_type);
523
524         if (VOICE_CALL_SIGNAL_NONE == papp_snd->signal_type) {
525                 CALL_ENG_DEBUG(ENG_DEBUG, "No Signal Type Assinged");
526                 return FALSE;
527         }
528
529         /*
530            Always stop the signal before playing another one
531            This is to make sure that previous signal sound is stopeed completely
532          */
533         voicecall_snd_stop_signal(papp_snd);
534
535         /*Set status, the signal play is being prepared */
536         papp_snd->signal_sound_status = VOICE_CALL_SND_STATUS_READY;
537         CALL_ENG_DEBUG(ENG_DEBUG, "papp_snd->signal_sound_status = %d", papp_snd->signal_sound_status);
538
539         papp_snd->psignal_play_end_cb = psignal_play_end_cb;
540         papp_snd->psignal_play_end_cb_data = psignal_play_end_cb_data;
541
542         if (TRUE == voicecall_snd_is_effect_playing(papp_snd)) {
543                 CALL_ENG_DEBUG(ENG_ERR, "Stopping effect tone to play signal");
544                 voicecall_snd_stop_effect_tone(papp_snd);
545         }
546
547         CALL_ENG_DEBUG(ENG_ERR, "Changing path to play signal");
548         sound_manager_call_session_set_mode(papp_snd->psnd_session, SOUND_CALL_SESSION_MODE_MEDIA);
549         CALL_ENG_DEBUG(ENG_ERR, "Changing path to play signal Over");
550
551         CALL_ENG_DEBUG(ENG_DEBUG, "signal_tone = %s", papp_snd->signal_tone);
552         ret_value = mm_sound_play_sound(papp_snd->signal_tone, VOLUME_TYPE_CALL, __voicecall_snd_mmplayer_signal_cb, papp_snd, &papp_snd->pmm_signal_player);
553         if (MM_ERROR_NONE != ret_value) {
554                 papp_snd->signal_sound_status = VOICE_CALL_SND_STATUS_NONE;
555                 CALL_ENG_DEBUG(ENG_ERR, "mm_sound_play_sound failed,Error: [0x%x]", ret_value);
556         } else {
557                 CALL_ENG_DEBUG(ENG_DEBUG, "papp_snd->pmm_signal_player[%d]", papp_snd->pmm_signal_player);
558                 papp_snd->signal_sound_status = VOICE_CALL_SND_STATUS_PLAY;
559         }
560         CALL_ENG_DEBUG(ENG_DEBUG, "Signal Play Started, Sound Status is: %d", papp_snd->signal_sound_status);
561
562         return TRUE;
563 }
564
565 /**
566  * This function stops the sound alert
567  *
568  * @return              void
569  * @param[in]           papp_snd                        Handle to Sound Manager
570  */
571 void voicecall_snd_stop_signal(voicecall_snd_mgr_t *papp_snd)
572 {
573         int ret_value = 0;
574
575         CALL_ENG_DEBUG(ENG_DEBUG, "Sound Status: %d, papp_snd->pmm_signal_player(%d)", papp_snd->signal_sound_status, papp_snd->pmm_signal_player);
576         if (papp_snd->pmm_signal_player != VOICE_CALL_SND_INVALID_SND_HANDLE) {
577                 if (VOICE_CALL_SND_STATUS_PLAY == papp_snd->signal_sound_status) {
578                         papp_snd->signal_sound_status = VOICE_CALL_SND_STATUS_STOPPED;
579
580                         CALL_ENG_DEBUG(ENG_DEBUG, "Stopping Signal Sound");
581                         ret_value = mm_sound_stop_sound(papp_snd->pmm_signal_player);
582                         if (MM_ERROR_NONE != ret_value) {
583                                 CALL_ENG_DEBUG(ENG_ERR, "mm_sound_stop_sound failed: [0x%x]", ret_value);
584                         }
585                 } else {
586                         CALL_ENG_DEBUG(ENG_DEBUG, "Sound Play Over / Already Stopped");
587                 }
588                 papp_snd->pmm_signal_player = VOICE_CALL_SND_INVALID_SND_HANDLE;
589         }
590         if (papp_snd->psignal_play_end_cb != NULL) {
591                 papp_snd->psignal_play_end_cb(papp_snd->psignal_play_end_cb_data);
592                 papp_snd->psignal_play_end_cb = NULL;
593                 papp_snd->psignal_play_end_cb_data = NULL;
594         }
595
596         CALL_ENG_DEBUG(ENG_DEBUG, "Application Sound Status:%d", papp_snd->signal_sound_status);
597 }
598
599 /**
600  * This function sets the end signal of the given end cause type
601  *
602  * @return              void
603  * @param[in]           papp_snd                Handle to Sound Manager
604  * @param[in]           end_cause_type          Type of the end cause
605  */
606 void voicecall_snd_set_signal_type(voicecall_snd_mgr_t *papp_snd, voicecall_snd_signal_type_t signal_type)
607 {
608         char signal_tone[VOICE_CALL_SND_RINGTONE_PATH_LEN];
609
610         CALL_ENG_DEBUG(ENG_DEBUG, "Signal Type: %d", signal_type);
611
612         memset(signal_tone, 0, sizeof(signal_tone));
613
614         papp_snd->signal_type = signal_type;
615         switch (papp_snd->signal_type) {
616         case VOICE_CALL_SIGNAL_USER_BUSY_TONE:
617                 {
618                         _vc_core_util_strcpy(signal_tone, VOICE_CALL_SND_RINGTONE_PATH_LEN, VOICE_CALL_SND_USER_BUSY_SIGNAL_PATH);
619                 }
620                 break;
621         case VOICE_CALL_SIGNAL_WRONG_NUMBER_TONE:
622                 {
623                         _vc_core_util_strcpy(signal_tone, VOICE_CALL_SND_RINGTONE_PATH_LEN, VOICE_CALL_SND_ERROR_SIGNAL_PATH);
624                 }
625                 break;
626         case VOICE_CALL_SIGNAL_CALL_FAIL_TONE:
627         case VOICE_CALL_SIGNAL_NW_CONGESTION_TONE:
628                 {
629                         _vc_core_util_strcpy(signal_tone, VOICE_CALL_SND_RINGTONE_PATH_LEN, VOICE_CALL_SND_NW_CONGESTION_SIGNAL_PATH);
630                 }
631                 break;
632         default:
633                 CALL_ENG_DEBUG(ENG_ERR, "Invalid Signal Type");
634                 break;
635         }
636
637         _vc_core_util_strcpy(papp_snd->signal_tone, sizeof(papp_snd->signal_tone), signal_tone);
638
639 }
640
641 static void __voicecall_snd_get_voice_path(voicecall_snd_mgr_t *papp_snd, int *voice_snd_path)
642 {
643         voicecall_audio_path_t tmp_audio_path;
644
645         CALL_ENG_DEBUG(ENG_DEBUG, "current path = %d", voicecall_snd_get_path_status(papp_snd));
646
647         switch (voicecall_snd_get_path_status(papp_snd)) {
648         case VOICE_CALL_SND_PATH_BT:
649                 {
650                         tmp_audio_path = VC_AUDIO_PATH_BLUETOOTH;
651                 }
652                 break;
653         case VOICE_CALL_SND_PATH_SPEAKER:
654                 {
655                         tmp_audio_path = VC_AUDIO_PATH_SPK_PHONE;
656                 }
657                 break;
658         case VOICE_CALL_SND_PATH_RECEIVER_EARJACK:
659         default:
660                 {
661                         if (_voicecall_dvc_get_earjack_connected() == TRUE)
662                                 tmp_audio_path = VC_AUDIO_PATH_HEADSET;
663                         else
664                                 tmp_audio_path = VC_AUDIO_PATH_HANDSET;
665                 }
666         }
667         *voice_snd_path = tmp_audio_path;
668
669         CALL_ENG_DEBUG(ENG_DEBUG, "voice_snd_path = %d", *voice_snd_path);
670
671 }
672
673 void voicecall_snd_change_mm_path(voicecall_snd_mgr_t *papp_snd)
674 {
675         sound_route_e route = 0;
676
677         CALL_ENG_DEBUG(ENG_DEBUG, "papp_snd->current_path_type = %d", papp_snd->current_path_type);
678
679         switch (voicecall_snd_get_path_status(papp_snd)) {
680         case VOICE_CALL_SND_PATH_BT:
681                 CALL_ENG_DEBUG(ENG_DEBUG, "route path : SOUND_ROUTE_INOUT_BLUETOOTH");
682                 route = SOUND_ROUTE_INOUT_BLUETOOTH;
683                 break;
684
685         case VOICE_CALL_SND_PATH_SPEAKER:
686                 CALL_ENG_DEBUG(ENG_DEBUG, "route path : SOUND_ROUTE_IN_MIC_OUT_SPEAKER");
687                 route = SOUND_ROUTE_IN_MIC_OUT_SPEAKER;
688                 break;
689
690         case VOICE_CALL_SND_PATH_RECEIVER_EARJACK:
691         default:
692                 {
693                         if (_voicecall_dvc_get_earjack_connected() == TRUE) {
694                                 if (sound_manager_is_route_available (MM_SOUND_ROUTE_INOUT_HEADSET)) {
695                                         CALL_ENG_DEBUG(ENG_DEBUG, "route path : MM_SOUND_ROUTE_INOUT_HEADSET");
696                                         route = MM_SOUND_ROUTE_INOUT_HEADSET;
697                                 } else if (sound_manager_is_route_available (SOUND_ROUTE_IN_MIC_OUT_HEADPHONE)) {
698                                         route = SOUND_ROUTE_IN_MIC_OUT_HEADPHONE;
699                                         CALL_ENG_DEBUG(ENG_DEBUG, "route path : SOUND_ROUTE_IN_MIC_OUT_HEADPHONE");
700                                 } else {
701                                         route = SOUND_ROUTE_IN_MIC_OUT_RECEIVER;
702                                 }
703                         } else {
704                                 CALL_ENG_DEBUG(ENG_DEBUG, "route path : SOUND_ROUTE_IN_MIC_OUT_RECEIVER");
705                                 route = SOUND_ROUTE_IN_MIC_OUT_RECEIVER;
706                         }
707                 }
708                 break;
709         }
710         CALL_ENG_DEBUG(ENG_ERR, "route = 0x04X", route);
711
712         if (papp_snd->bsound_cm_state == TRUE) {
713                 CALL_ENG_DEBUG(ENG_ERR, "sound_manager_set_active_route [0x%X]", route);
714                 sound_manager_set_active_route(route);
715
716                 CALL_ENG_KPI("mm_sound_set_path done");
717                 papp_snd->current_path_type = VOICE_CALL_MM_VOICE;
718         } else {
719                 CALL_ENG_DEBUG(ENG_ERR, "** we can't change mm path. check it. ****");
720         }
721 }
722
723 /**
724  * This function changes the sound path according to the current status
725  *
726  * @return              void
727  * @param[in]           papp_snd                        Handle to Sound Manager
728  */
729 void voicecall_snd_change_path(voicecall_snd_mgr_t *papp_snd)
730 {
731         CALL_ENG_DEBUG(ENG_DEBUG, "..");
732         CALL_ENG_KPI("voicecall_snd_change_path start");
733         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)papp_snd->pcall_core;
734
735         if (voicecall_snd_get_path_status(papp_snd) == VOICE_CALL_SND_PATH_BT) {
736                 int bt_sco_status = 0;
737
738                 bt_sco_status = _vc_bt_get_bt_sco_status();
739                 if (FALSE == bt_sco_status) {
740                         gboolean bevent_wait = FALSE;
741
742                         CALL_ENG_DEBUG(ENG_ERR, "BT Sco is OFF, request BT for path change");
743                         bevent_wait = voicecall_core_get_status(pcall_core, CALL_VC_CORE_FLAG_BT_EVENT_WAITING);
744                         if (FALSE == bevent_wait) {
745                                 /*Request BT for change path to headset */
746                                 _vc_bt_request_switch_headset_path(pcall_core, TRUE);
747                         } else {
748                                 CALL_ENG_DEBUG(ENG_ERR, "bevent_wait = %d, waiting for BT Event", bevent_wait);
749                         }
750                 } else {
751                         CALL_ENG_DEBUG(ENG_DEBUG, "BT SCO is open, Change the path to sync with BT Path");
752                         voicecall_snd_change_path_real(papp_snd);
753                 }
754         } else {
755                 CALL_ENG_DEBUG(ENG_DEBUG, "new PATH is not BT.");
756                 gboolean bevent_wait = FALSE;
757
758                 bevent_wait = voicecall_core_get_status(pcall_core, CALL_VC_CORE_FLAG_BT_EVENT_WAITING);
759                 if (FALSE == bevent_wait) {
760                         /*Request BT for change path to headset */
761                         voicecall_snd_change_path_real(papp_snd);
762                 } else {
763                         CALL_ENG_DEBUG(ENG_ERR, "bevent_wait = %d, waiting for BT Event", bevent_wait);
764                 }
765         }
766         CALL_ENG_KPI("voicecall_snd_change_path done");
767 }
768
769 void voicecall_snd_change_path_real(voicecall_snd_mgr_t *papp_snd)
770 {
771         sound_call_session_mode_e current_session_mode;
772         CALL_ENG_DEBUG(ENG_DEBUG, "..");
773
774         /* Change the mm sound path */
775         sound_manager_call_session_get_mode(papp_snd->psnd_session, &current_session_mode);
776
777         CALL_ENG_DEBUG(ENG_ERR, "current session mode = %d..", current_session_mode);
778
779         if (current_session_mode != SOUND_CALL_SESSION_MODE_VOICE) {
780                 sound_manager_call_session_set_mode(papp_snd->psnd_session, SOUND_CALL_SESSION_MODE_VOICE);
781         } else {
782                 voicecall_snd_change_mm_path(papp_snd);
783         }
784         voicecall_snd_change_modem_path(papp_snd);
785 }
786
787 void voicecall_snd_change_modem_path(voicecall_snd_mgr_t *papp_snd)
788 {
789         CALL_ENG_DEBUG(ENG_DEBUG, "..");
790         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)papp_snd->pcall_core;
791
792         int audio_path = VC_AUDIO_PATH_HANDSET;
793
794         /* Change the tapi sound path */
795         __voicecall_snd_get_voice_path(papp_snd, &audio_path);
796
797         if (FALSE == voicecall_core_change_audio_path(pcall_core->pcall_engine, audio_path, papp_snd->bextra_volume_status)) {
798                 CALL_ENG_DEBUG(ENG_ERR, "TAPI Audio Change Path ERROR");
799         }
800 }
801
802 /**
803  * This function sets the status of the given call audio type
804  *
805  * @return              void
806  * @param[in]           papp_snd                Handle to Sound Manager
807  * @param[in]           snd_audio_type          Type of the Device to be changed
808  * @param[in]           status                          Status, TRUE - Enable, FALSE -Disable
809  */
810 void voicecall_snd_set_status(voicecall_snd_mgr_t *papp_snd, voicecall_snd_audio_type_t snd_audio_type, gboolean status)
811 {
812         CALL_ENG_DEBUG(ENG_DEBUG, "snd_audio_type:[%d], status:[%d]", snd_audio_type, status);
813
814         /*if BT headset is connected , switch off loud speaker - it will be reflectd in the next sound path change */
815         if (((VOICE_CALL_AUDIO_HEADSET == snd_audio_type) || (VOICE_CALL_AUDIO_RECEIVER_EARJACK == snd_audio_type)) && (TRUE == status)) {
816                 CALL_ENG_DEBUG(ENG_DEBUG, "loud speaker status is to be FALSE");
817                 papp_snd->bcall_audio_status[VOICE_CALL_AUDIO_SPEAKER] = FALSE;
818         }
819         papp_snd->bcall_audio_status[snd_audio_type] = status;
820 }
821
822 /**
823  * This function returns the current status of the given call audio type
824  *
825  * @return              Returns TRUE if given call audio type is enables or FALSE otherwise
826  * @param[in]           papp_snd                Handle to Sound Manager
827  * @param[in]           snd_audio_type  Type of the Device to be changed
828  */
829 gboolean voicecall_snd_get_status(voicecall_snd_mgr_t *papp_snd, voicecall_snd_audio_type_t snd_audio_type)
830 {
831         CALL_ENG_DEBUG(ENG_DEBUG, "Status[%d] = %d", snd_audio_type, papp_snd->bcall_audio_status[snd_audio_type]);
832         return papp_snd->bcall_audio_status[snd_audio_type];
833 }
834
835 /**
836  * This function sets the status of the given call audio type
837  *
838  * @return              void
839  * @param[in]           papp_snd                Handle to Sound Manager
840  * @param[in]           snd_audio_type          Type of the Device to be changed
841  * @param[in]           status                          Status, TRUE - Enable, FALSE -Disable
842  */
843 void voicecall_snd_set_path_status(voicecall_snd_mgr_t *papp_snd, voicecall_snd_path_t path)
844 {
845         CALL_ENG_DEBUG(ENG_DEBUG, "current path:[%d], new path:[%d]", papp_snd->current_snd_path, path);
846
847         papp_snd->old_snd_path = papp_snd->current_snd_path;
848         papp_snd->current_snd_path = path;
849 }
850
851 voicecall_snd_path_t voicecall_snd_get_path_status(voicecall_snd_mgr_t *papp_snd)
852 {
853         CALL_ENG_DEBUG(ENG_DEBUG, "old path:[%d], current path:[%d]", papp_snd->old_snd_path, papp_snd->current_snd_path);
854
855         return papp_snd->current_snd_path;
856 }
857
858 /**
859 * This function sets the volume level for the given volume alert type
860 *
861 * @return               void
862 * @param[in]    papp_snd                Handle to Sound Manager
863 * @param[in]    vol_alert_type  volume alert type #voicecall_snd_volume_alert_type_t
864 * @param[in]    volume_level    volume level to be set
865 */
866 void voicecall_snd_set_volume(voicecall_snd_mgr_t *papp_snd, voicecall_snd_volume_alert_type_t vol_alert_type, int volume_level)
867 {
868         CALL_ENG_DEBUG(ENG_DEBUG, "volume_level = %d", volume_level);
869         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)papp_snd->pcall_core;
870
871         switch (vol_alert_type) {
872         case VOICE_CALL_VOL_TYPE_RINGTONE:
873                 {
874                         int ret_value = 0;
875                         int volume;
876
877                         if (VOICE_CALL_SND_INVALID_PLAYER_HANDLE == papp_snd->pmm_player) {
878                                 CALL_ENG_DEBUG(ENG_ERR, "Invalid MM Player Handle");
879                                 return;
880                         }
881
882                         /* Make Increasing Melody flag to FALSE, so melody volume will not be increased when volume it adjusted by user during increasing melody */
883                         papp_snd->bincreasingmelody = FALSE;
884
885                         volume = volume_level;
886
887                         ret_value = mm_sound_volume_set_value(VOLUME_TYPE_RINGTONE, volume);
888                         if (MM_ERROR_NONE != ret_value) {
889                                 CALL_ENG_DEBUG(ENG_ERR, "mmplayer_set_volume failed Error: [0x%x]", ret_value);
890                         }
891                 }
892                 break;
893         case VOICE_CALL_VOL_TYPE_VOICE:
894                 {
895                         int incall_vol_level = 0;
896                         int audio_path = 0;
897
898                         if (VOICE_CALL_VOL_LEVEL_1 >= volume_level) {
899                                 incall_vol_level = VOICE_CALL_VOL_LEVEL_1;
900                         } else if (VOICE_CALL_VOL_LEVEL_6 < volume_level) {
901                                 incall_vol_level = VOICE_CALL_VOL_LEVEL_6;
902                         } else {
903                                 incall_vol_level = volume_level;
904                         }
905
906                         __voicecall_snd_get_voice_path(papp_snd, &audio_path);
907
908                         _vc_core_util_set_call_volume(volume_level);
909
910                         /* MODEM want to get volume level as 0~5, not a 1~6. So pass -1 value */
911                         if (FALSE == voicecall_core_set_audio_volume(pcall_core->pcall_engine, audio_path, (incall_vol_level-1))) {
912                                 CALL_ENG_DEBUG(ENG_DEBUG, "voicecall_doc_set_audio_volume failed");
913                         }
914                 }
915                 break;
916         case VOICE_CALL_VOL_TYPE_HEADSET:
917                 {
918                         int bt_vol_level = 0;
919                         if (TRUE == voicecall_core_get_status(pcall_core, CALL_VC_CORE_FLAG_VOL_CHNGD_BYBT)) {
920                                 CALL_ENG_DEBUG(ENG_DEBUG, "BT Requested Volume flag is enabled, not sending response");
921                                 voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_VOL_CHNGD_BYBT, FALSE);
922                         } else {
923                                 bt_vol_level = volume_level;
924                                 CALL_ENG_DEBUG(ENG_DEBUG, "bt_vol_level = %d", bt_vol_level);
925
926                                 _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_SPK_GAIN, bt_vol_level, NULL);
927                         }
928
929                 }
930                 break;
931         default:
932                 CALL_ENG_DEBUG(ENG_DEBUG, "No Actions Defined for the volume alert type: %d", vol_alert_type);
933
934         }
935 }
936
937 /**
938  * This function retreives the volume according to the given volume alert type
939  *
940  * @return              current volume level
941  * @param[in]           papp_snd                Handle to Sound Manager
942  * @param[in]           vol_alert_type          volume alert type #voicecall_snd_volume_alert_type_t
943  */
944 int voicecall_snd_get_volume(voicecall_snd_mgr_t *papp_snd, voicecall_snd_volume_alert_type_t vol_alert_type)
945 {
946         CALL_ENG_DEBUG(ENG_DEBUG, "");
947         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)papp_snd->pcall_core;
948
949         switch (vol_alert_type) {
950         case VOICE_CALL_VOL_TYPE_RINGTONE:
951                 {
952                         int ret_val = 0;
953                         unsigned int volume = 0;
954
955                         ret_val = mm_sound_volume_get_value(VOLUME_TYPE_RINGTONE, &volume);
956                         if (MM_ERROR_NONE != ret_val) {
957                                 CALL_ENG_DEBUG(ENG_DEBUG, "ret_val = [0x%x]", ret_val);
958                                 return VC_INVALID_VOLUME;
959                         }
960                         CALL_ENG_DEBUG(ENG_DEBUG, "MM Volume Level : %d", volume);
961
962                         return volume;
963
964                 }
965                 break;
966         case VOICE_CALL_VOL_TYPE_VOICE:
967                 {
968                         return _vc_core_util_get_call_volume();
969                 }
970                 break;
971         case VOICE_CALL_VOL_TYPE_HEADSET:
972                 {
973                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_HEADSET_VOL, 0, NULL);
974                         return VC_INVALID_VOLUME;       /*Return Invalid Volume level as default */
975                 }
976                 break;
977         default:
978                 return VC_INVALID_VOLUME;       /*Return Invalid Volume level as default */
979         }
980
981         return VC_INVALID_VOLUME;
982 }
983
984 gboolean voicecall_snd_get_alternate_play(voicecall_snd_mgr_t *papp_snd)
985 {
986         return papp_snd->balternate_play;
987 }
988
989 static gboolean __voicecall_snd_start_melody(voicecall_snd_mgr_t *papp_snd, gboolean bis_increasing, int call_handle)
990 {
991         char *setting_file_path = NULL;
992         char ringtone_path[VOICE_CALL_SND_RINGTONE_PATH_LEN] = { 0, };
993
994         CALL_ENG_DEBUG(ENG_DEBUG, "call_handle = %d", call_handle);
995
996         CALL_ENG_DEBUG(ENG_DEBUG, "Contact ring_tone_path = [%s]", papp_snd->ring_tone);
997
998         if (strlen(papp_snd->ring_tone) <= 0) {
999                 setting_file_path = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR);
1000 #ifdef DRM_USED
1001                 if ((setting_file_path == NULL) || (strlen(setting_file_path) <= 0) ||
1002                         (FALSE == g_file_test(setting_file_path, G_FILE_TEST_EXISTS)) ||
1003                         (FALSE == voicecall_util_is_valid_drm_file(setting_file_path, DRM_PERMISSION_PLAY)))
1004 #else
1005                 if ((setting_file_path == NULL) || (strlen(setting_file_path) <= 0) ||
1006                 (FALSE == g_file_test(setting_file_path, G_FILE_TEST_EXISTS)))
1007 #endif
1008                 {
1009                         CALL_ENG_DEBUG(ENG_ERR, "setting ring tone path is invalid : [%s]", setting_file_path);
1010                         /*snprintf(ringtone_path, sizeof(ringtone_path), "file://%s", VOICE_CALL_SND_DEFAULT_RINGTONE_PATH);*/
1011                         return FALSE;
1012                 } else {
1013                         snprintf(ringtone_path, sizeof(ringtone_path), "file://%s", setting_file_path);
1014
1015                 }
1016                 CALL_ENG_DEBUG(ENG_DEBUG, "Ringtone From Settings : %s", ringtone_path);
1017                 _vc_core_util_strcpy(papp_snd->ring_tone, sizeof(papp_snd->ring_tone), ringtone_path);
1018         }
1019
1020         /* Create MM Player */
1021         papp_snd->pmm_player = VOICE_CALL_SND_INVALID_PLAYER_HANDLE;
1022         __voicecall_snd_create_player(papp_snd, &papp_snd->pmm_player, VOICE_CALL_PLAY_TYPE_RINGTONE);
1023
1024         /*Set Volume */
1025         __voicecall_snd_set_mm_volume(papp_snd, bis_increasing);
1026
1027         papp_snd->ringtone_sound_status = VOICE_CALL_SND_STATUS_READY;
1028
1029         return TRUE;
1030 }
1031
1032 static gboolean __voicecall_snd_create_player(voicecall_snd_mgr_t *papp_snd, MMHandleType * pPlayer, voicecall_snd_play_type_t play_type)
1033 {
1034         int ret_value = 0;
1035         MMMessageCallback callback = NULL;
1036         char *mmf_error = NULL;
1037
1038         CALL_ENG_DEBUG(ENG_DEBUG, "Start..");
1039
1040         if (*pPlayer != VOICE_CALL_SND_INVALID_SND_HANDLE) {
1041                 CALL_ENG_DEBUG(ENG_DEBUG, "Player = %d", *pPlayer);
1042                 mm_player_destroy(*pPlayer);
1043                 *pPlayer = VOICE_CALL_SND_INVALID_SND_HANDLE;
1044         }
1045
1046         ret_value = mm_player_create(pPlayer);
1047         if (MM_ERROR_NONE != ret_value || *pPlayer == VOICE_CALL_SND_INVALID_SND_HANDLE) {
1048                 CALL_ENG_DEBUG(ENG_ERR, "mmplayer_create failed , Error:[0x%x]", ret_value);
1049                 return FALSE;
1050         }
1051         CALL_ENG_DEBUG(ENG_DEBUG, "*pPlayer: %d", *pPlayer);
1052
1053         switch (play_type) {
1054                 /*Set the MM Player Attributes according to the Display Priority Type */
1055         case VOICE_CALL_PLAY_TYPE_RINGTONE:
1056                 {
1057                         mm_player_set_attribute(*pPlayer, &mmf_error,
1058                                                 "sound_volume_type", MM_SOUND_VOLUME_TYPE_RINGTONE,
1059                                                 "profile_uri", papp_snd->ring_tone, VOICE_CALL_SND_RINGTONE_PATH_LEN,
1060                                                 "profile_play_count", -1, "sound_route", MM_AUDIOROUTE_USE_EXTERNAL_SETTING, "sound_spk_out_only", TRUE, "sound_stop_when_unplugged", FALSE, NULL);
1061                         callback = __voicecall_snd_mmplayer_cb;
1062
1063                 }
1064                 break;
1065         default:
1066                 break;
1067         }
1068
1069         mm_player_set_message_callback(*pPlayer, callback, papp_snd);
1070
1071         ret_value = mm_player_realize(*pPlayer);
1072         if (MM_ERROR_NONE != ret_value) {
1073                 CALL_ENG_DEBUG(ENG_ERR, "mmplayer_realize failed , Error:[0x%x]", ret_value);
1074                 return FALSE;
1075         }
1076
1077         CALL_ENG_DEBUG(ENG_DEBUG, "Finish..");
1078         return TRUE;
1079 }
1080
1081 static void __voicecall_snd_set_mm_volume(voicecall_snd_mgr_t *papp_snd, int bis_increasing)
1082 {
1083 #ifdef _VOL_LEVEL_FROM_SETTINGS_
1084         int ret_value = 0;
1085         int set_volume_level = VOICE_CALL_VOL_LEVEL_1;
1086         int volume_val;
1087
1088         CALL_ENG_DEBUG(ENG_DEBUG, "..");
1089
1090         /*Get the settings current ringtone volume level and set to media player */
1091         if (FALSE == vconf_get_int(VCONFKEY_SETAPPL_CALL_RINGTONE_SOUND_VOLUME_INT, &set_volume_level)) {
1092                 CALL_ENG_DEBUG(ENG_ERR, "settings read failed Error: %d", ret_value);
1093         }
1094         CALL_ENG_DEBUG(ENG_DEBUG, "Settings Volume Level = %d", set_volume_level);
1095
1096         if (set_volume_level > 0) {
1097                 if (TRUE == bis_increasing) {
1098                         papp_snd->increment_melody_value = set_volume_level = 1;
1099                 }
1100         } else {
1101                 CALL_ENG_DEBUG(ENG_DEBUG, "Increasing melody not set to VOICE_CALL_VOL_LEVEL_1");
1102         }
1103
1104         volume_val = set_volume_level;
1105         ret_value = mm_sound_volume_set_value(VOLUME_TYPE_RINGTONE, volume_val);
1106         if (MM_ERROR_NONE != ret_value) {
1107                 CALL_ENG_DEBUG(ENG_ERR, "Set Volume Error: [0x%x]", ret_value);
1108         } else {
1109                 CALL_ENG_DEBUG(ENG_DEBUG, "Final Volume Set to [%d]", volume_val);
1110         }
1111 #endif
1112 }
1113
1114 static gboolean __voicecall_snd_play_melody(voicecall_snd_mgr_t *papp_snd, gboolean bis_increasing)
1115 {
1116         CALL_ENG_DEBUG(ENG_DEBUG, "..");
1117
1118         if (strlen(papp_snd->ring_tone) > 0) {
1119                 int mm_error = MM_ERROR_NONE;
1120
1121                 mm_error = mm_player_start(papp_snd->pmm_player);
1122                 if (MM_ERROR_NONE != mm_error) {
1123                         CALL_ENG_DEBUG(ENG_ERR, "mm_player_start failed,Error: [0x%x]", mm_error);
1124                 } else {
1125                         if (TRUE == bis_increasing) {
1126                                 papp_snd->bincreasingmelody = TRUE;
1127                                 g_timeout_add(VOICE_CALL_SND_INCREMENT_TIMER_INTERVAL, __voicecall_snd_increasing_melody_cb, (gpointer) papp_snd);
1128                         }
1129
1130                         CALL_ENG_DEBUG(ENG_DEBUG, "ringtone_sound_status : %d", papp_snd->ringtone_sound_status);
1131
1132                         papp_snd->ringtone_sound_status = VOICE_CALL_SND_STATUS_PLAY;
1133                         return TRUE;
1134                 }
1135         } else {
1136                 CALL_ENG_DEBUG(ENG_ERR, "Ringtone is empty(Problem)");
1137         }
1138
1139         return FALSE;
1140 }
1141
1142 static int __voicecall_snd_mmplayer_cb(int message, void *data, void *user_data)
1143 {
1144         voicecall_snd_mgr_t *papp_snd = (voicecall_snd_mgr_t *)user_data;
1145         if (VOICE_CALL_SND_STATUS_PLAY != papp_snd->ringtone_sound_status) {
1146                 CALL_ENG_DEBUG(ENG_DEBUG, "Sound Play stopped by application, callback not handled");
1147                 return FALSE;
1148         }
1149
1150         switch (message) {
1151         case MM_MESSAGE_END_OF_STREAM:
1152                 {
1153                         CALL_ENG_DEBUG(ENG_DEBUG, "Ringtone loop count is supported by MMF , need not restart the ringtone");
1154                 }
1155                 break;
1156         default:
1157                 return FALSE;
1158                 break;
1159         }
1160         return TRUE;
1161 }
1162
1163 gboolean __voicecall_snd_mmplayer_signal_end_callback_idle_cb(gpointer pdata)
1164 {
1165         voicecall_snd_mgr_t *papp_snd = (voicecall_snd_mgr_t *)pdata;
1166
1167         CALL_ENG_DEBUG(ENG_DEBUG, "");
1168
1169         /*Callback needs to be called, only when the tone is played completely and it is ended
1170            if the signal is explictly stopped, don't call the user callback */
1171         if (papp_snd->psignal_play_end_cb != NULL) {
1172                 CALL_ENG_DEBUG(ENG_DEBUG, "Calling user callback");
1173                 papp_snd->psignal_play_end_cb(papp_snd->psignal_play_end_cb_data);
1174                 papp_snd->psignal_play_end_cb = NULL;
1175                 papp_snd->psignal_play_end_cb_data = NULL;
1176         }
1177
1178         return FALSE;
1179 }
1180
1181 static void __voicecall_snd_mmplayer_signal_cb(gpointer puser_data)
1182 {
1183         voicecall_snd_mgr_t *papp_snd = (voicecall_snd_mgr_t *)puser_data;
1184
1185         CALL_ENG_DEBUG(ENG_DEBUG, "Sound Play Over");
1186
1187         if (papp_snd->signal_sound_status != VOICE_CALL_SND_STATUS_PLAY) {
1188                 CALL_ENG_DEBUG(ENG_DEBUG, "Sound Play already stopped by application");
1189                 return;
1190         }
1191
1192         papp_snd->signal_sound_status = VOICE_CALL_SND_STATUS_STOPPED;
1193
1194         __voicecall_snd_mmplayer_signal_end_callback_idle_cb(papp_snd);
1195 }
1196
1197 static gboolean __voicecall_snd_increasing_melody_cb(void *data)
1198 {
1199         voicecall_snd_mgr_t *papp_snd = (voicecall_snd_mgr_t *)data;
1200         int ret_value = 0;
1201         int set_volume_level = VOICE_CALL_VOL_LEVEL_1;
1202
1203         if (FALSE == papp_snd->bincreasingmelody) {
1204                 CALL_ENG_DEBUG(ENG_DEBUG, "Already Deactivated");
1205                 return FALSE;
1206         }
1207
1208         if ((set_volume_level != 0) && (papp_snd->increment_melody_value <= set_volume_level)) {
1209                 int volume_val;
1210
1211                 papp_snd->increment_melody_value++;
1212
1213                 volume_val = papp_snd->increment_melody_value;
1214                 ret_value = mm_sound_volume_set_value(VOLUME_TYPE_RINGTONE, volume_val);
1215
1216                 if (MM_ERROR_NONE != ret_value) {
1217                         CALL_ENG_DEBUG(ENG_ERR, "Set Volume Error: [0x%x]", ret_value);
1218                 }
1219
1220                 CALL_ENG_DEBUG(ENG_DEBUG, "Increasing Melody Continuing, Current Increased Melody : %d", papp_snd->increment_melody_value);
1221                 if (papp_snd->increment_melody_value >= set_volume_level) {
1222                         CALL_ENG_DEBUG(ENG_DEBUG, "Increasing Melody Ended");
1223                         return FALSE;
1224                 }
1225
1226                 return TRUE;
1227         }
1228
1229         CALL_ENG_DEBUG(ENG_DEBUG, "Increasing Melody Ended");
1230         return FALSE;
1231 }
1232
1233 static void __voicecall_snd_start_vibration(voicecall_snd_mgr_t *papp_snd)
1234 {
1235         /*First Stop the previous Vibration and then start it again */
1236
1237         CALL_ENG_DEBUG(ENG_DEBUG, "..");
1238         int vib_type = -1;
1239         int vib_level = -1;
1240         int haptic_vib_type = -1;
1241
1242         papp_snd->bvibration = FALSE;
1243
1244         papp_snd->vibration_handle = device_haptic_open(DEV_IDX_0, 0);
1245
1246         CALL_ENG_DEBUG(ENG_DEBUG, "srart vibration device_handle=%d", papp_snd->vibration_handle);
1247
1248         if (papp_snd->vibration_handle < 0) {
1249                 CALL_ENG_DEBUG(ENG_DEBUG, "device_haptic_open error");
1250                 return;
1251         }
1252
1253         if (vconf_get_int(VCONFKEY_SETAPPL_CALL_VIBRATION_PATTERN_INT, &vib_type)) {
1254                 CALL_ENG_DEBUG(ENG_ERR, "VCONFKEY_SETAPPL_CALL_VIBRATION_PATTERN_INT vconf_get_bool failed.");
1255         }
1256         if (vconf_get_int(VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT, &vib_level)) {
1257                 CALL_ENG_DEBUG(ENG_ERR, "VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT vconf_get_bool failed.");
1258         }
1259
1260         if (vib_level > 5)
1261                 vib_level = 5;
1262
1263         switch (vib_type) {
1264         case SETTING_CALL_ALERT_VIB_TYPE1:
1265                 haptic_vib_type = EFFCTVIBE_INCOMING_CALL01;
1266                 break;
1267         case SETTING_CALL_ALERT_VIB_TYPE2:
1268                 haptic_vib_type = EFFCTVIBE_INCOMING_CALL02;
1269                 break;
1270         case SETTING_CALL_ALERT_VIB_TYPE3:
1271                 haptic_vib_type = EFFCTVIBE_INCOMING_CALL03;
1272                 break;
1273         default:
1274                 haptic_vib_type = EFFCTVIBE_INCOMING_CALL01;
1275                 break;
1276         }
1277         if (device_haptic_play_pattern(papp_snd->vibration_handle, haptic_vib_type, 255, vib_level)) {
1278                 CALL_ENG_DEBUG(ENG_DEBUG, "device_haptic_play_pattern error");
1279                 return;
1280         }
1281         if (device_haptic_play_monotone(papp_snd->vibration_handle, 60000)) {
1282                 CALL_ENG_DEBUG(ENG_DEBUG, "device_haptic_play_monotone error");
1283                 return;
1284         }
1285
1286         papp_snd->bvibration = TRUE;
1287
1288 }
1289
1290 static void __voicecall_snd_stop_vibration(voicecall_snd_mgr_t *papp_snd)
1291 {
1292         CALL_ENG_DEBUG(ENG_DEBUG, "..");
1293
1294         if (TRUE == papp_snd->bvibration) {
1295                 CALL_ENG_DEBUG(ENG_DEBUG, "Stopping Vibration , handle=%d", papp_snd->vibration_handle);
1296
1297                 if (device_haptic_stop_play(papp_snd->vibration_handle)) {
1298                         CALL_ENG_DEBUG(ENG_DEBUG, "device_haptic_play_stop error");
1299                         return;
1300                 }
1301
1302                 if (device_haptic_close(papp_snd->vibration_handle)) {
1303                         CALL_ENG_DEBUG(ENG_DEBUG, "device_haptic_close error");
1304                         return;
1305                 }
1306
1307                 papp_snd->vibration_handle = -1;
1308
1309                 papp_snd->bvibration = FALSE;
1310         } else {
1311                 CALL_ENG_DEBUG(ENG_DEBUG, "bvibration is not enabled.");
1312         }
1313
1314 }
1315
1316 /*
1317 * This function is callback of mm_sound_route_add_callback
1318 * @return       void
1319 * @param[in]    data    call user data
1320 *               policy  system audio route policy which has applied.
1321 */
1322 void voicecall_snd_route_change_cb(void *data, system_audio_route_t policy)
1323 {
1324         int error_code = 0;
1325         CALL_ENG_DEBUG(ENG_ERR, "System audio route policy has changed");
1326         if (policy != SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP) {
1327                 error_code = mm_sound_route_set_system_policy(SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP);
1328                 if (error_code) {
1329                         CALL_ENG_DEBUG(ENG_ERR, "mm_sound_route_set_system_policy failed. error_code:[0x%x]", error_code);
1330                 }
1331         }
1332 }
1333
1334 /**
1335 * This function unregisters the application with the sound conflict manager
1336 *
1337 * @return                       void
1338 * @param[in]            papp_snd                Handle to Sound Manager
1339 */
1340 void voicecall_snd_register_cm(voicecall_snd_mgr_t *papp_snd)
1341 {
1342         int error_code = 0;
1343
1344         CALL_ENG_DEBUG(ENG_DEBUG, "current bsound_cm_state:[%d].", papp_snd->bsound_cm_state);
1345
1346         if (FALSE == papp_snd->bsound_cm_state) {
1347                 error_code = sound_manager_call_session_create(SOUND_SESSION_TYPE_CALL, &papp_snd->psnd_session);
1348                 if (error_code) {
1349                         CALL_ENG_DEBUG(ENG_ERR, "sound_manager_call_session_create failed. error_code:[0x%x]", error_code);
1350                         return;
1351                 }
1352                 papp_snd->bsound_cm_state = TRUE;
1353         }
1354         return;
1355 }
1356
1357 /**
1358 * This function unregisters the application from the sound conflict manager
1359 *
1360 * @return                       void
1361 * @param[in]            papp_snd                Handle to Sound Manager
1362 */
1363 void voicecall_snd_unregister_cm(voicecall_snd_mgr_t *papp_snd)
1364 {
1365         int error_code = 0;
1366
1367         CALL_ENG_DEBUG(ENG_DEBUG, "current bsound_cm_state:[%d].", papp_snd->bsound_cm_state);
1368
1369         if (TRUE == papp_snd->bsound_cm_state) {
1370                 /*Reset the Path when the app is closed - safety code */
1371                 CALL_ENG_DEBUG(ENG_DEBUG, "Sound Path reset to Default");
1372
1373                 papp_snd->bsound_cm_state = FALSE;
1374
1375                 error_code = sound_manager_call_session_destroy(papp_snd->psnd_session);
1376                 if (error_code) {
1377                         CALL_ENG_DEBUG(ENG_ERR, "sound_manager_call_session_destroy failed. error_code:[0x%x]", error_code);
1378                 }
1379         }
1380         /*Set to Defaults */
1381         voicecall_snd_set_to_defaults(papp_snd);
1382         return;
1383 }
1384
1385 gboolean __voicecall_snd_effect_idle_cb(gpointer puser_data)
1386 {
1387         voicecall_snd_mgr_t *papp_snd = (voicecall_snd_mgr_t *)puser_data;
1388         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)papp_snd->pcall_core;
1389
1390         papp_snd->effect_tone_status = VOICE_CALL_SND_STATUS_NONE;
1391         CALL_ENG_DEBUG(ENG_DEBUG, "papp_snd->effect_tone_status = %d", papp_snd->effect_tone_status);
1392
1393         /*If connected call exists then change the audio path */
1394         if ((TRUE == voicecall_core_is_connected_call_exist(pcall_core->pcall_engine)) || (TRUE == voicecall_core_is_outgoing_call_exists(pcall_core->pcall_engine))) {
1395                 CALL_ENG_DEBUG(ENG_DEBUG, "Connected call exists, changing path at the end of effect tone");
1396
1397                 CALL_ENG_DEBUG(ENG_ERR, "papp_snd->signal_sound_status = %d", papp_snd->signal_sound_status);
1398                 /*Check the signal play status, if signal is being prepared / played, don't change the path */
1399                 if (VOICE_CALL_SND_STATUS_NONE == papp_snd->signal_sound_status) {
1400                         voicecall_snd_change_path(papp_snd);
1401                 } else {
1402                         CALL_ENG_DEBUG(ENG_ERR, "Signal is playing, skipping path change, it will be done at the end of signal");
1403                 }
1404         } else {
1405                 CALL_ENG_DEBUG(ENG_DEBUG, "non connected call");
1406         }
1407         CALL_ENG_DEBUG(ENG_DEBUG, "Over");
1408         return FALSE;
1409 }
1410
1411 static void __voicecall_snd_effect_cb(gpointer puser_data)
1412 {
1413         voicecall_snd_mgr_t *papp_snd = (voicecall_snd_mgr_t *)puser_data;
1414
1415         CALL_ENG_DEBUG(ENG_DEBUG, "effect_tone_status = %d, Calling Idle", papp_snd->effect_tone_status);
1416         papp_snd->effect_tone_status = VOICE_CALL_SND_STATUS_STOPPED;
1417
1418         __voicecall_snd_effect_idle_cb(papp_snd);
1419         CALL_ENG_DEBUG(ENG_DEBUG, "End : papp_snd->effect_tone_status = %d", papp_snd->effect_tone_status);
1420 }
1421
1422 gboolean voicecall_snd_play_effect_tone(voicecall_snd_mgr_t *papp_snd, int effect_type)
1423 {
1424         int error_code = -1;
1425         gboolean bzuhause = FALSE;
1426         gboolean bstatus = FALSE;
1427         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)papp_snd->pcall_core;
1428
1429         CALL_ENG_DEBUG(ENG_DEBUG, "effect type:[%d]", effect_type);
1430
1431         switch (effect_type) {
1432         case VOICE_CALL_SND_EFFECT_CALL_CONNECT:
1433                 {
1434                         CALL_ENG_KPI("voicecall_core_get_zuhause start");
1435                         voicecall_core_get_zuhause(pcall_core->pcall_engine, &bzuhause);
1436                         CALL_ENG_KPI("voicecall_core_get_zuhause done");
1437
1438                         if (bzuhause == TRUE) {
1439                                 CALL_ENG_DEBUG(ENG_DEBUG, "It's zuhause area! don't play connect tone!");
1440                                 return FALSE;
1441                         }
1442
1443                         CALL_ENG_KPI("get VCONFKEY_CISSAPPL_CALL_CONNECT_TONE_BOOL start");
1444                         if (vconf_get_bool(VCONFKEY_CISSAPPL_CALL_CONNECT_TONE_BOOL, &bstatus)) {
1445                                 CALL_ENG_DEBUG(ENG_ERR, "vconf_get_bool failed.");
1446                         }
1447                         CALL_ENG_KPI("get VCONFKEY_CISSAPPL_CALL_CONNECT_TONE_BOOL done");
1448
1449                         if (!bstatus) {
1450                                 CALL_ENG_DEBUG(ENG_DEBUG, "Connect Tone Settings not enabled");
1451                                 return FALSE;
1452                         }
1453
1454                         /*First Reset the audio Path to PDA */
1455                         sound_manager_call_session_set_mode(papp_snd->psnd_session, SOUND_CALL_SESSION_MODE_MEDIA);
1456
1457                         error_code = mm_sound_play_sound(VOICE_CALL_SND_CONNECT_SIGNAL_PATH, VOLUME_TYPE_CALL, __voicecall_snd_effect_cb, papp_snd, &papp_snd->mmfsoundplay_handle);
1458                 }
1459                 break;
1460         case VOICE_CALL_SND_EFFECT_CALL_DISCONNECT:
1461                 {
1462
1463                         if (vconf_get_bool(VCONFKEY_CISSAPPL_CALL_END_TONE_BOOL, &bstatus)) {
1464                                 CALL_ENG_DEBUG(ENG_ERR, "vconf_get_bool failed.");
1465                         }
1466
1467                         if (!bstatus) {
1468                                 CALL_ENG_DEBUG(ENG_DEBUG, "Disconnect Tone Settings not enabled");
1469                                 return FALSE;
1470                         }
1471
1472                         sound_manager_call_session_set_mode(papp_snd->psnd_session, SOUND_CALL_SESSION_MODE_MEDIA);
1473
1474                         error_code = mm_sound_play_sound(VOICE_CALL_SND_DISCONNECT_SIGNAL_PATH, VOLUME_TYPE_CALL, __voicecall_snd_effect_cb, papp_snd, &papp_snd->mmfsoundplay_handle);
1475
1476                 }
1477                 break;
1478
1479         case VOICE_CALL_SND_EFFECT_CALL_MINUTE_MINDER:
1480                 {
1481                         sound_manager_call_session_set_mode(papp_snd->psnd_session, SOUND_CALL_SESSION_MODE_MEDIA);
1482                         error_code = mm_sound_play_sound(VOICE_CALL_SND_MINUTE_MINDER_SIGNAL_PATH, VOLUME_TYPE_CALL, __voicecall_snd_effect_cb, papp_snd, &papp_snd->mmfsoundplay_handle);
1483                 }
1484                 break;
1485
1486         default:
1487                 CALL_ENG_DEBUG(ENG_DEBUG, "Invalid Effect Type: %d", effect_type);
1488
1489         }
1490
1491         if (MM_ERROR_NONE == error_code) {
1492                 papp_snd->effect_tone_status = VOICE_CALL_SND_STATUS_PLAY;
1493         }
1494
1495         CALL_ENG_DEBUG(ENG_DEBUG, "error code = [0x%x]", error_code);
1496         return (MM_ERROR_NONE == error_code) ? TRUE : FALSE;
1497 }
1498
1499 gboolean voicecall_snd_is_effect_playing(voicecall_snd_mgr_t *papp_snd)
1500 {
1501         CALL_ENG_DEBUG(ENG_ERR, "Effect tone status: %d", papp_snd->effect_tone_status);
1502         if (VOICE_CALL_SND_STATUS_PLAY == papp_snd->effect_tone_status) {
1503                 return TRUE;
1504         }
1505
1506         return FALSE;
1507 }
1508
1509 void voicecall_snd_stop_effect_tone(voicecall_snd_mgr_t *papp_snd)
1510 {
1511         CALL_ENG_DEBUG(ENG_ERR, "Effect tone status: %d", papp_snd->effect_tone_status);
1512
1513         if (VOICE_CALL_SND_STATUS_PLAY == papp_snd->effect_tone_status) {
1514                 if (MM_ERROR_NONE != mm_sound_stop_sound(papp_snd->mmfsoundplay_handle)) {
1515                         CALL_ENG_DEBUG(ENG_ERR, "MM Stop Sound Failed");
1516                 }
1517
1518                 papp_snd->effect_tone_status = VOICE_CALL_SND_STATUS_NONE;
1519                 papp_snd->mmfsoundplay_handle = VOICE_CALL_SND_INVALID_SND_HANDLE;
1520         }
1521         CALL_ENG_DEBUG(ENG_ERR, "Effect tone status: %d", papp_snd->effect_tone_status);
1522 }
1523
1524 void voicecall_snd_set_to_defaults(voicecall_snd_mgr_t *papp_snd)
1525 {
1526         call_vc_core_state_t *pcall_core = NULL;
1527
1528         CALL_ENG_DEBUG(ENG_DEBUG, "papp_snd = %p", papp_snd);
1529
1530         /*Backup core handle */
1531         pcall_core = (call_vc_core_state_t *)papp_snd->pcall_core;
1532
1533         /*Reset Sound Magr Data */
1534         memset(papp_snd, 0, sizeof(voicecall_snd_mgr_t));
1535
1536         /*Re Assign core handle */
1537         papp_snd->pcall_core = pcall_core;
1538
1539         /*Set to Defaults */
1540         papp_snd->pmm_player = VOICE_CALL_SND_INVALID_PLAYER_HANDLE;
1541         papp_snd->pmm_signal_player = VOICE_CALL_SND_INVALID_SND_HANDLE;
1542
1543         papp_snd->mmfsoundplay_handle = VOICE_CALL_SND_INVALID_SND_HANDLE;
1544         papp_snd->mmfalternateplay_handle = VOICE_CALL_SND_INVALID_SND_HANDLE;
1545
1546 }