16ce016b343bd12a1e07653c731eb813023b05fb
[platform/core/messaging/msg-service.git] / manager / src / msg-manager-sound.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved
3  *
4  * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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 FILES
19 ==================================================================================================*/
20
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <glib.h>
24 #include <sys/stat.h>
25 #include <unistd.h>
26
27 #include <player.h>
28 #include <recorder.h>
29 #include <sound_manager.h>
30 #include <feedback.h>
31 #include <feedback-internal.h>
32 #include <vconf.h>
33
34 #include <msg-manager-contact.h>
35 #include <msg-manager-debug.h>
36 #include <msg-manager-notification.h>
37 #include <msg-manager-sound.h>
38 #include <msg-manager-util.h>
39
40 /*==================================================================================================
41                                     DEFINES
42 ==================================================================================================*/
43
44 #define DEFAULT_ALERT_FILE              TZ_SYS_RO_APP_PATH "/" MSG_SETTING_APP_ID "shared/res/settings/Alerts/General notification_sdk.wav"
45
46 #define MSG_MGR_SOUND_TIMEOUT 5500
47
48
49 /*==================================================================================================
50                                      VARIABLES
51 ==================================================================================================*/
52 player_h g_PlayerHandle = NULL;
53 sound_stream_info_h g_stream_info = NULL;
54 char *defaultRingtonePath = NULL;
55 bool bFeedbackInit = false;
56 bool bPlaying = false;
57
58 pthread_mutex_t muMmPlay = PTHREAD_MUTEX_INITIALIZER;
59 pthread_mutex_t muStream = PTHREAD_MUTEX_INITIALIZER;
60
61 /*==================================================================================================
62                                                                                 FUNCTION DEFINE
63 ===================================================================================================*/
64 int MsgMgrGetFileSize(const char *pFileName);
65
66 int MsgMgrStreamStart(MSG_MGR_SOUND_TYPE_T soundType);
67 void MsgMgrStreamStop();
68 void MsgMgrGetPlayStatus(bool bOnCall, bool bSound, bool bVibration, bool bMsgSound, bool bMsgVibration, bool *bPlaySound, bool *bPlayVibration);
69
70 void MsgMgrSoundPlayMelody(char *pMsgToneFilePath);
71 void MsgMgrSoundPlayVibration();
72
73 /*==================================================================================================
74                                                                         FUNCTION IMPLEMENTATION
75 ==================================================================================================*/
76 int MsgMgrGetFileSize(const char *pFileName)
77 {
78         struct stat file_stat;
79
80         if (lstat(pFileName, &file_stat)) {
81                 MSG_MGR_FATAL("file[%s] error lstat: %s", pFileName, g_strerror(errno));
82                 return -1;
83         }
84
85         return (int)file_stat.st_size;
86 }
87
88
89 static void MsgMgrSoundPlayeErrorCallback(int error_code, void *user_data)
90 {
91         MSG_MGR_DEBUG("MsgMgrSoundPlayeErrorCallback called [%d]", error_code);
92         MsgMgrStreamStop();
93         MsgMgrSoundPlayStart(NULL, MSG_MGR_SOUND_PLAY_DEFAULT);
94 }
95
96 static void MsgMgrSoundPlayeCompletedCallback(void *user_data)
97 {
98         MSG_MGR_DEBUG("MsgMgrSoundPlayeCompletedCallback called");
99         MsgMgrSoundPlayStop();
100 }
101
102 static void MsgMgrSoundPlayeInterruptedCallback(player_interrupted_code_e code, void *user_data)
103 {
104         MSG_MGR_DEBUG("MsgMgrSoundPlayeInterruptedCallback called [%d]", code);
105         MsgMgrSoundPlayStop();
106 }
107
108 static void MsgStreamFocusCallback(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state,
109                                    sound_stream_focus_change_reason_e reason_for_change, int sound_behavior, const char *additional_info, void *user_data)
110 {
111         MSG_MGR_DEBUG("MsgStreamFocusCallback called, reason_for_change [%d], additional_info [%s]", reason_for_change, additional_info);
112
113         if ((focus_mask == SOUND_STREAM_FOCUS_FOR_PLAYBACK) && (focus_state == SOUND_STREAM_FOCUS_STATE_RELEASED)) {
114                 MSG_MGR_DEBUG("sound stream focus released");
115                 MsgMgrSoundPlayStop();
116         }
117 }
118
119
120 void initMsgMgrSoundPlayer()
121 {
122         bPlaying = false;
123         bFeedbackInit = false;
124
125         defaultRingtonePath = vconf_get_str(VCONFKEY_SETAPPL_NOTI_RINGTONE_DEFAULT_PATH_STR);
126
127         if (defaultRingtonePath == NULL || MsgMgrGetFileSize(defaultRingtonePath) < 1) {
128                         defaultRingtonePath = (char *)DEFAULT_ALERT_FILE;
129         }
130
131         MSG_MGR_DEBUG("defaultRingtonePath [%s]", defaultRingtonePath);
132 }
133
134
135 void MsgMgrGetRingtonePath(char *userRingtonePath, char **msg_tone_file_path_p)
136 {
137         int tmpVal = 0;
138         if (vconf_get_int(MSG_SETTING_RINGTONE_TYPE, &tmpVal) != 0) {
139                 MSG_MGR_INFO("vcong_get_int() is failed");
140         }
141         int ringtoneType = tmpVal;
142
143         MSG_MGR_DEBUG("Ringtone type = [%d]", ringtoneType);
144
145         if (ringtoneType == MSG_RINGTONE_TYPE_SILENT) {
146                 *msg_tone_file_path_p = NULL;
147                 return;
148         }
149
150         char *tmpFilePath = NULL;
151         *msg_tone_file_path_p = new char[MSG_FILEPATH_LEN_MAX+1];
152
153         char *msg_tone_file_path = *msg_tone_file_path_p;
154
155         bool bUserRingtone = userRingtonePath && userRingtonePath[0] != '\0';
156         if (bUserRingtone) {
157                 tmpFilePath = userRingtonePath;
158         } else {
159                 if (ringtoneType == MSG_RINGTONE_TYPE_DEFAULT) {
160                         tmpFilePath = vconf_get_str(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR);
161                 } else {
162                         tmpFilePath = vconf_get_str(MSG_SETTING_RINGTONE_PATH);
163                 }
164         }
165
166         memset(msg_tone_file_path, 0x00, sizeof(char)*(MSG_FILEPATH_LEN_MAX+1));
167 #if 0 /* MSG_DRM_SUPPORT */
168         if ((tmpFilePath == NULL || MsgMgrGetFileSize(tmpFilePath) < 1) || /* wrong ringtone file path */
169                         (MsgDrmIsDrmFile(tmpFilePath) && !MsgDrmCheckRingtone(tmpFilePath))) { /* check DRM */
170 #endif
171         if ((tmpFilePath == NULL || MsgMgrGetFileSize(tmpFilePath) < 1)) { /* wrong ringtone file path */
172                 if (tmpFilePath && (strcmp(tmpFilePath, "silent") == 0)) {
173                         MSG_MGR_DEBUG("Set ringtone to NONE(Silent)");
174                         msg_tone_file_path = NULL;
175                 } else {
176                         MSG_MGR_DEBUG("Set ringtone to defaultRingtonePath.");
177                         if (defaultRingtonePath && defaultRingtonePath[0] != '\0') {
178                                 MSG_MGR_DEBUG("defaultRingtonePath [%s]", defaultRingtonePath);
179                                 snprintf(msg_tone_file_path, MSG_FILEPATH_LEN_MAX, "%s", defaultRingtonePath);
180                         } else {
181                                 MSG_MGR_DEBUG("defaultRingtonePath is null");
182                                 msg_tone_file_path = NULL;
183                         }
184                 }
185         } else {
186                 MSG_MGR_DEBUG("Set ringtone to tmpFilePath.");
187                 snprintf(msg_tone_file_path, MSG_FILEPATH_LEN_MAX, "%s", tmpFilePath);
188         }
189
190         if (tmpFilePath && !bUserRingtone) {
191                 free(tmpFilePath);
192                 tmpFilePath = NULL;
193         }
194 }
195
196 void MsgMgrGetPlayStatus(bool bVoiceMail, bool *bPlaySound, bool *bPlayVibration, bool *bOnCall)
197 {
198         MSG_MGR_BEGIN();
199
200         if (!bPlaySound || !bPlayVibration) {
201                 MSG_MGR_DEBUG("IN parameter is NULL.");
202                 return;
203         }
204
205         *bPlaySound = false;
206         *bPlayVibration = false;
207
208         /* Global setting */
209         int bSoundOn = 0; /* sound setting on notification panel */
210         int bVibrationOn = 0; /* vibration setting on notification panel */
211
212         if (vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &bSoundOn) != 0)
213                 MSG_MGR_INFO("vconf_get_bool() is failed");
214
215         if (vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &bVibrationOn) != 0)
216                 MSG_MGR_INFO("vconf_get_bool() is failed");
217
218         /* Alert setting */
219 #if 0   /* not used value */
220         int bNotiVibrationOn = 0; /* alert vibration */
221         if (vconf_get_bool(VCONFKEY_SETAPPL_VIBRATE_WHEN_NOTIFICATION_BOOL, &bNotiVibrationOn) != 0)
222                 MSG_MGR_INFO("vconf_get_bool() is failed");
223 #endif
224
225         int bMsgSettingNoti = 1; /* Alert for message notification */
226         int bMsgSettingVibration = 0; /* vibration for message notification */
227
228         int ringtoneType = MSG_RINGTONE_TYPE_DEFAULT; /*sound type for message notification */
229         bool bMsgSettingSound = true;
230
231         if (vconf_get_bool(MSG_SETTING_VIBRATION, &bMsgSettingVibration) != 0)
232                 MSG_MGR_INFO("vconf_get_bool() is failed");
233
234         if (vconf_get_bool(MSG_SETTING_NOTIFICATION, &bMsgSettingNoti) != 0)
235                 MSG_MGR_INFO("vconf_get_bool() is failed");
236
237         int tmpVal = 0;
238         if (vconf_get_int(MSG_SETTING_RINGTONE_TYPE, &tmpVal) != 0) {
239                 MSG_MGR_INFO("vconf_get_int() is failed");
240         }
241         ringtoneType = tmpVal;
242         if (ringtoneType == MSG_RINGTONE_TYPE_SILENT)
243                 bMsgSettingSound = false;
244
245         MSG_MGR_SEC_DEBUG("Sound status : Sound mode[%d], Manner mode[%d]", bSoundOn, bVibrationOn);
246         MSG_MGR_SEC_DEBUG("Msg Setting : Noti Alert[%d], vibration[%d], sound[%d], ringtoneType[%d]", bMsgSettingNoti, bMsgSettingVibration, bMsgSettingSound, ringtoneType);
247
248         cm_call_status_e callStatus = CM_CALL_STATUS_IDLE;
249 /*      int alertOnCall = 0; */
250
251         callStatus = MsgMgrGetCallStatus();
252         MSG_MGR_DEBUG("Call Status [%d]", callStatus);
253
254         /* Check call status */
255         if (callStatus > CM_CALL_STATUS_IDLE && callStatus < CM_CALL_STATUS_MAX) {
256                 /* 1. On Call */
257                 *bOnCall = true; /* set call status; */
258         } else {
259                 /* 2. Call is not active */
260                 MSG_MGR_DEBUG("Call is not active.");
261                 recorder_device_state_e recorderState = RECORDER_DEVICE_STATE_IDLE;
262                 int ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &recorderState);
263                 if (ret != 0)
264                         MSG_MGR_INFO("recorder_get_device_state() is failed [%d]", ret);
265
266                 if (bVoiceMail) {       /* 2-1. Voice message */
267                         if (bMsgSettingNoti) {
268                                 MsgMgrGetPlayStatus(false, bSoundOn, bVibrationOn, bMsgSettingSound, bMsgSettingVibration, bPlaySound, bPlayVibration);
269
270                         } else {
271                                 MSG_MGR_DEBUG("It doesn't play sound/vibration - voice message.");
272                         }
273                 } else {        /* 2-1. Normal message */
274                         if (bMsgSettingNoti) {
275                                 if (recorderState != RECORDER_DEVICE_STATE_RECORDING) {
276                                         MsgMgrGetPlayStatus(false, bSoundOn, bVibrationOn, bMsgSettingSound, bMsgSettingVibration, bPlaySound, bPlayVibration);
277                                 } else {
278                                         MSG_MGR_DEBUG("It doesn't play sound/vibration.");
279                                 }
280                         } else {
281                                 MSG_MGR_DEBUG("It doesn't play sound/vibration.");
282                         }
283                 }
284         }
285
286         MSG_MGR_END();
287 }
288
289
290 void MsgMgrGetPlayStatus(bool bOnCall, bool bSound, bool bVibration, bool bMsgSound, bool bMsgVibration, bool *bPlaySound, bool *bPlayVibration)
291 {
292         MSG_MGR_BEGIN();
293
294         /* samsung basic concept : feedback should follow profile setting.
295          * And if notification setting exist in msg app, then apply it prior to profile when profile either sound or vibration.
296          * But, Play sound when profile is vibration during call, if device does not support haptic */
297         if (bSound || bVibration) {
298                 bool bHantic_device = false;
299 #ifdef FEATURE_HAPTIC_ENABLE
300                 bHantic_device = true;
301 #endif
302                 if (bHantic_device || (bOnCall == false)) {
303                         if (bSound) {
304                                 if (bMsgSound) {
305                                         MSG_MGR_DEBUG("Play sound.");
306                                         *bPlaySound = true;
307                                 }
308
309                                 if (bMsgVibration) {
310                                         MSG_MGR_DEBUG("Play vibration.");
311                                         *bPlayVibration = true;
312                                 }
313                         } else {
314                                 if (bMsgVibration) {
315                                         MSG_MGR_DEBUG("Play vibration.");
316                                         *bPlayVibration = true;
317                                 }
318                         }
319                 } else { /* during call */
320                         if (bMsgSound || bMsgVibration) {
321                                 MSG_MGR_DEBUG("Play sound.");
322                                 *bPlaySound = true;
323                         }
324                 }
325         }
326
327         MSG_MGR_END();
328 }
329
330
331 void MsgMgrSoundPlayStart(const MSG_MGR_ADDRESS_INFO_S *pAddrInfo, MSG_MGR_SOUND_TYPE_T soundType)
332 {
333         MSG_MGR_BEGIN();
334
335         MSG_MGR_DEBUG("soundType [%d]", soundType);
336
337         /* check recorder state */
338         recorder_device_state_e recorderState = RECORDER_DEVICE_STATE_IDLE;
339         int ret = recorder_get_device_state(RECORDER_TYPE_VIDEO, &recorderState);
340         if (ret != 0)
341                 MSG_MGR_INFO("recorder_get_device_state() is failed [%d]", ret);
342
343         MSG_MGR_SEC_DEBUG("Recorder state [%d]", recorderState);
344
345         if (recorderState == RECORDER_DEVICE_STATE_RECORDING) {
346                 MSG_MGR_END();
347                 return;
348         }
349
350         MSG_MGR_CONTACT_INFO_S contactInfo = {0, };
351         if (pAddrInfo) {
352                 if (MsgMgrGetContactInfo(pAddrInfo, &contactInfo) != 0) {
353                         MSG_MGR_DEBUG("MsgGetContactInfo() fail.");
354                 }
355         }
356
357         /* get ringtone file path */
358         char *msg_tone_file_path = NULL;
359
360         if (soundType == MSG_MGR_SOUND_PLAY_EMERGENCY) {
361                 msg_tone_file_path = new char[MSG_FILEPATH_LEN_MAX+1];
362                 memset(msg_tone_file_path, 0x00, sizeof(char)*(MSG_FILEPATH_LEN_MAX+1));
363         } else if (soundType == MSG_MGR_SOUND_PLAY_DEFAULT) {
364                 msg_tone_file_path = new char[MSG_FILEPATH_LEN_MAX+1];
365                 memset(msg_tone_file_path, 0x00, sizeof(char)*(MSG_FILEPATH_LEN_MAX+1));
366                 snprintf(msg_tone_file_path, MSG_FILEPATH_LEN_MAX, "%s", DEFAULT_ALERT_FILE);
367         } else {
368                 MsgMgrGetRingtonePath(contactInfo.alerttonePath, &msg_tone_file_path);
369         }
370         MSG_MGR_SEC_DEBUG("soundType [%d], Sound File [%s]", soundType, msg_tone_file_path);
371
372         /* get sound play status */
373         bool bPlaySound = false;
374         bool bPlayVibration = false;
375         bool bVoiceMsg = (soundType == MSG_MGR_SOUND_PLAY_VOICEMAIL)?true:false;
376         bool bOnCall = false;
377
378         MsgMgrGetPlayStatus(bVoiceMsg, &bPlaySound, &bPlayVibration, &bOnCall);
379
380         MSG_MGR_SEC_DEBUG("sound=[%d], vibration=[%d], voice_msg?[%d], on_call?[%d]",
381                         bPlaySound, bPlayVibration, bVoiceMsg, bOnCall);
382
383         /* play sound */
384         if (bPlaySound) {
385                 int err = MsgMgrStreamStart(soundType);
386
387                 if (err != SOUND_MANAGER_ERROR_NONE)
388                         MSG_MGR_DEBUG("MsgMgrStreamStart() Failed : %d", err);
389                 else
390                         MsgMgrSoundPlayMelody(msg_tone_file_path);
391         }
392
393         if (bPlayVibration)
394                 MsgMgrSoundPlayVibration();
395
396         if (msg_tone_file_path)
397                 delete [] msg_tone_file_path;
398
399         MSG_MGR_END();
400 }
401
402
403 void MsgMgrSoundPlayStop()
404 {
405         MSG_MGR_BEGIN();
406
407         int err = 0;
408         pthread_mutex_lock(&muMmPlay);
409
410         if (bPlaying == true && g_PlayerHandle != NULL) {
411                 MSG_MGR_DEBUG("stopping the player.");
412                 /* Stop playing media contents */
413                 err = player_stop(g_PlayerHandle);
414
415                 if (err != PLAYER_ERROR_NONE)
416                         MSG_MGR_DEBUG("stopping the player handle failed");
417         }
418
419         if (g_PlayerHandle != NULL) {
420                 MSG_MGR_DEBUG("destroy the player.");
421
422                 player_unset_error_cb(g_PlayerHandle);
423                 player_unset_completed_cb(g_PlayerHandle);
424                 player_unset_interrupted_cb(g_PlayerHandle);
425                 player_unprepare(g_PlayerHandle);
426                 player_destroy(g_PlayerHandle);
427         }
428
429         g_PlayerHandle = NULL;
430         bPlaying = false;
431
432         pthread_mutex_unlock(&muMmPlay);
433
434         MsgMgrStreamStop();
435
436         MSG_MGR_END();
437 }
438
439
440 int MsgMgrStreamStart(MSG_MGR_SOUND_TYPE_T soundType)
441 {
442         MSG_MGR_BEGIN();
443         int err = 0;
444
445         pthread_mutex_lock(&muStream);
446
447         if (g_stream_info != NULL) {
448                 err = sound_manager_destroy_stream_information(g_stream_info);
449                 if (err != SOUND_MANAGER_ERROR_NONE)
450                         MSG_MGR_DEBUG("sound_manager_destroy_stream_information() Failed : %d", err);
451
452                 g_stream_info = NULL;
453         }
454
455         if (soundType == MSG_MGR_SOUND_PLAY_EMERGENCY)
456                 err = sound_manager_create_stream_information(SOUND_STREAM_TYPE_EMERGENCY, MsgStreamFocusCallback, NULL, &g_stream_info);
457         else
458                 err = sound_manager_create_stream_information(SOUND_STREAM_TYPE_NOTIFICATION, MsgStreamFocusCallback, NULL, &g_stream_info);
459
460         if (err != SOUND_MANAGER_ERROR_NONE) {
461                 MSG_MGR_DEBUG("sound_manager_create_stream_information() Failed : %d", err);
462                 pthread_mutex_unlock(&muStream);
463                 return err;
464         }
465
466         err = sound_manager_acquire_focus(g_stream_info, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, NULL);
467         pthread_mutex_unlock(&muStream);
468
469         MSG_MGR_END();
470         return err;
471 }
472
473
474 void MsgMgrStreamStop()
475 {
476         MSG_MGR_BEGIN();
477         pthread_mutex_lock(&muStream);
478
479         if (g_stream_info != NULL) {
480                 int err = sound_manager_release_focus(g_stream_info, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, NULL);
481                 if (err != SOUND_MANAGER_ERROR_NONE)
482                         MSG_MGR_DEBUG("sound_manager_release_focus() Failed : %d", err);
483
484                 err = sound_manager_destroy_stream_information(g_stream_info);
485                 if (err != SOUND_MANAGER_ERROR_NONE)
486                         MSG_MGR_DEBUG("sound_manager_destroy_stream_information() Failed : %d", err);
487
488                 g_stream_info = NULL;
489         }
490         pthread_mutex_unlock(&muStream);
491
492         MSG_MGR_END();
493 }
494
495
496 void MsgMgrSoundPlayMelody(char *pMsgToneFilePath)
497 {
498         int err = PLAYER_ERROR_NONE;
499
500         if (!pMsgToneFilePath) {
501                 MSG_MGR_DEBUG("Ringtone path is NULL");
502                 return;
503         }
504
505         pthread_mutex_lock(&muMmPlay);
506
507         if (g_stream_info == NULL) {
508                 MSG_MGR_DEBUG("g_stream_info is NULL");
509                 pthread_mutex_unlock(&muMmPlay);
510                 return;
511         }
512
513         if (g_PlayerHandle) {
514                 player_unset_error_cb(g_PlayerHandle);
515                 player_unset_completed_cb(g_PlayerHandle);
516                 player_unset_interrupted_cb(g_PlayerHandle);
517                 player_unprepare(g_PlayerHandle);
518                 player_destroy(g_PlayerHandle);
519         }
520
521         err = player_create(&g_PlayerHandle);
522
523         pthread_mutex_unlock(&muMmPlay);
524
525         if (err != PLAYER_ERROR_NONE) {
526                 MSG_MGR_DEBUG("creating the player handle failed");
527                 return;
528         }
529
530         /* Setting the call back function msg_callback */
531         player_set_error_cb(g_PlayerHandle, MsgMgrSoundPlayeErrorCallback, NULL);
532         player_set_completed_cb(g_PlayerHandle, MsgMgrSoundPlayeCompletedCallback, NULL);
533         player_set_interrupted_cb(g_PlayerHandle, MsgMgrSoundPlayeInterruptedCallback, NULL);
534
535         player_set_audio_policy_info(g_PlayerHandle, g_stream_info);
536
537         do {
538                 err = player_set_uri(g_PlayerHandle, (const char *)pMsgToneFilePath);
539                 if (err != PLAYER_ERROR_NONE)
540                         MSG_MGR_DEBUG("player_set_uri() error : [%d]", err);
541
542                 err = player_prepare(g_PlayerHandle);
543                 if (err != PLAYER_ERROR_NONE) {
544                         MSG_MGR_DEBUG("player_prepare() error : [%d]", err);
545                         if (pMsgToneFilePath != defaultRingtonePath) {
546                                 pMsgToneFilePath = defaultRingtonePath;
547                         } else {
548                                 return;
549                         }
550                 }
551         } while (err != PLAYER_ERROR_NONE);
552
553
554         pthread_mutex_lock(&muMmPlay);
555         MSG_MGR_DEBUG("player_start with [%s]", pMsgToneFilePath);
556         err = player_start(g_PlayerHandle);
557
558         if (err != PLAYER_ERROR_NONE) {
559                 MSG_MGR_DEBUG("player_start, FAIL [%x]", err);
560         } else {
561                 /* Add Timer to stop playing after 5 sec. */
562                 /*
563                 int g_contact_timer = -1;
564                 g_contact_timer = g_timeout_add(MSG_MGR_SOUND_TIMEOUT, (GSourceFunc)MsgSoundMelodyTimeout, NULL);
565                 */
566
567                 bPlaying = true;
568         }
569         pthread_mutex_unlock(&muMmPlay);
570 }
571
572
573 void MsgMgrSoundPlayVibration()
574 {
575         MSG_MGR_BEGIN();
576
577         int ret = 0;
578
579         if (!bFeedbackInit) {
580                 int ret = feedback_initialize();
581
582                 if (ret != FEEDBACK_ERROR_NONE) {
583                         MSG_MGR_DEBUG("Fail to feedback_initialize : [%d]", ret);
584                         bFeedbackInit = false;
585                         return;
586                 } else {
587                         MSG_MGR_DEBUG("Success to feedback_initialize.");
588                         bFeedbackInit = true;
589                 }
590         }
591
592 #if 1
593         ret = feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_MESSAGE);
594         if (ret != FEEDBACK_ERROR_NONE)
595                 MSG_MGR_DEBUG("Fail to feedback_play_type");
596 #else
597         if (vibrationPath && strlen(vibrationPath)) {
598                 MSG_MGR_DEBUG("vibrationPath: [%s]", vibrationPath);
599                 ret = feedback_set_resource_path(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_MESSAGE, vibrationPath);
600                 if (ret != FEEDBACK_ERROR_NONE)
601                         MSG_MGR_DEBUG("Fail to feedback_set_resource_path");
602                 ret = feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_MESSAGE);
603
604                 if (ret != FEEDBACK_ERROR_NONE)
605                         MSG_MGR_DEBUG("Fail to feedback_play_type");
606         } else {
607                 ret = feedback_set_resource_path(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_MESSAGE, NULL);
608                 if (ret != FEEDBACK_ERROR_NONE)
609                         MSG_MGR_DEBUG("Fail to feedback_set_resource_path");
610
611                 ret = feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_MESSAGE);
612                 if (ret != FEEDBACK_ERROR_NONE)
613                         MSG_MGR_DEBUG("Fail to feedback_play_type");
614         }
615 #endif
616         MSG_MGR_END();
617 }