3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
5 * This file is part of msg-service.
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 * Sangkoo Kim <sangkoo.kim@samsung.com>
9 * Seunghwan Lee <sh.cat.lee@samsung.com>
10 * SoonMin Jung <sm0415.jung@samsung.com>
11 * Jae-Young Lee <jy4710.lee@samsung.com>
12 * KeeBum Kim <keebum.kim@samsung.com>
14 * PROPRIETARY/CONFIDENTIAL
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
34 #include "MsgCppTypes.h"
35 #include "MsgSettingTypes.h"
36 #include "MsgGconfWrapper.h"
37 #include "MsgHelper.h"
39 #include <devman_haptic.h>
43 #include <mm_player.h>
44 #include <mm_session_private.h>
47 extern void worker_done();
49 /*==================================================================================================
51 ==================================================================================================*/
52 static MMHandleType hPlayerHandle = 0;
53 static bool bPlaying = false;
54 static bool bVibrating = false;
55 static int dev_handle;
57 pthread_mutex_t muMmPlay = PTHREAD_MUTEX_INITIALIZER;
58 pthread_cond_t cvMmPlay = PTHREAD_COND_INITIALIZER;
60 /*==================================================================================================
61 FUNCTION IMPLEMENTATION
62 ==================================================================================================*/
63 static gboolean MsgSoundMelodyTimeout(gpointer data)
68 if(!bPlaying && !bVibrating)
77 static gboolean MsgSoundVibTimeout(gpointer data)
83 if (bVibrating == true) {
84 ret = device_haptic_stop_play(dev_handle);
87 MSG_DEBUG("Fail to stop haptic : [%d]", ret);
90 ret = device_haptic_close(dev_handle);
93 MSG_DEBUG("Fail to close haptic : [%d]", ret);
99 if(!bPlaying && !bVibrating)
108 static int MsgSoundPlayCallback(int message, void *param, void *user_param)
112 case MM_MESSAGE_ERROR:
113 MSG_DEBUG("ERROR is happened.");
114 MsgSoundPlayUninit();
116 case MM_MESSAGE_BEGIN_OF_STREAM:
117 MSG_DEBUG("Play is started.");
119 case MM_MESSAGE_END_OF_STREAM:
120 MSG_DEBUG("end of stream");
122 if(!bPlaying && !bVibrating)
126 MSG_DEBUG("message = %d", message);
134 void* MsgPlayThread(void *data)
138 bool bSoundOn = false;
139 bool bVibrationOn = false;
140 int callStatus = 0; /* 0 - off, 1 - sound, 2 - vibration */
143 char *msg_tone_file_path = NULL;
144 AutoPtr<char> buf(&msg_tone_file_path);
146 char *tmpFileFath = NULL;
148 tmpFileFath = MsgSettingGetString(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR);
150 if (tmpFileFath == NULL) {
151 msg_tone_file_path = new char[MAX_SOUND_FILE_LEN];
152 strncpy(msg_tone_file_path, DEFAULT_FILE, MAX_SOUND_FILE_LEN-1);
154 msg_tone_file_path = new char[MAX_SOUND_FILE_LEN];
155 strncpy(msg_tone_file_path, tmpFileFath, MAX_SOUND_FILE_LEN-1);
160 MSG_DEBUG("Sound File [%s]", msg_tone_file_path);
162 MsgSettingGetBool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &bSoundOn);
163 MsgSettingGetBool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &bVibrationOn);
165 int err = MM_ERROR_NONE;
167 err = mm_session_init(MM_SESSION_TYPE_NOTIFY);
169 if(err != MM_ERROR_NONE)
170 MSG_DEBUG("MM Session Init Failed");
172 MSG_DEBUG("MM Session Init Success : %d", err);
176 err = mm_player_create(&hPlayerHandle);
178 if (err != MM_ERROR_NONE) {
179 MSG_DEBUG("creating the player handle failed");
183 /* Setting the call back function msg_callback */
184 mm_player_set_message_callback(hPlayerHandle, MsgSoundPlayCallback, (void *)hPlayerHandle);
186 callStatus = MsgSettingGetInt(VCONFKEY_CALL_STATE);
187 MSG_DEBUG("Call Status = %d", callStatus);
189 if (callStatus > VCONFKEY_CALL_OFF && callStatus < VCONFKEY_CALL_STATE_MAX) {
190 alertOnCall = MsgSettingGetInt(VCONFKEY_CISSAPPL_ALERT_ON_CALL_INT);
191 MSG_DEBUG("Alert On Call = %d", alertOnCall);
193 if (alertOnCall == 0) {
194 MSG_DEBUG("Call is active & Alert on Call - Off");
195 } else if (alertOnCall == 1) {
196 MSG_DEBUG("Call is active & Alert on Call - Sound");
199 MsgSoundPlayMelody(msg_tone_file_path, false);
200 } else if (alertOnCall == 2) {
201 MSG_DEBUG("Call is active & Alert on Call - Vibration");
204 MsgSoundPlayVibration();
207 MSG_DEBUG("Call is not active");
210 MSG_DEBUG("Play vibration.");
211 MsgSoundPlayVibration();
215 MSG_DEBUG("Play sound.");
216 MsgSoundPlayMelody(msg_tone_file_path, false);
220 err = mm_session_finish();
222 if (err != MM_ERROR_NONE)
223 MSG_DEBUG("MM Session Finish Failed");
225 MSG_DEBUG("MM Session Finish Success : %d", err);
227 if(!bPlaying && !bVibrating)
236 MSG_ERROR_T MsgSoundPlayUninit()
240 int err = MM_ERROR_NONE;
242 /* Uninitializing the player module */
243 err = mm_player_unrealize(hPlayerHandle);
245 /* Destroying the player handle */
246 err = mm_player_destroy(hPlayerHandle);
248 pthread_mutex_lock(&muMmPlay);
252 pthread_mutex_unlock(&muMmPlay);
254 pthread_cond_signal(&cvMmPlay);
264 void MsgSoundPlayStart()
268 pthread_mutex_lock(&muMmPlay);
270 if (bPlaying == true) {
271 MSG_DEBUG("Ringtone is Playing...");
272 pthread_mutex_unlock(&muMmPlay);
276 pthread_mutex_unlock(&muMmPlay);
280 if (pthread_create(&tid, NULL, &MsgPlayThread, (void*)NULL) == 0) {
281 MSG_DEBUG("Ring alert thread created = %d", tid);
283 MSG_DEBUG("Creating Thread was failed");
291 void MsgSoundPlayStop()
295 pthread_mutex_lock(&muMmPlay);
297 if (bPlaying == false) {
298 MSG_DEBUG("Ringtone is Not Playing...");
299 pthread_mutex_unlock(&muMmPlay);
303 pthread_mutex_unlock(&muMmPlay);
305 /* Stop playing media contents */
306 MSG_DEBUG("Before mm_player_stop, %p", hPlayerHandle);
308 int err = mm_player_stop(hPlayerHandle);
310 MSG_DEBUG("After mm_player_stop");
312 if (err != MM_ERROR_NONE) {
313 MSG_DEBUG("stopping the player handle failed");
316 MsgSoundPlayUninit();
322 int MsgSoundPlayMelody(char *pMsgToneFilePath, bool bIncreasing)
324 int err = MM_ERROR_NONE;
326 /* Setting fade in,out */
327 err = mm_player_set_attribute(hPlayerHandle, NULL, "sound_priority", 2, NULL);
329 if (err != MM_ERROR_NONE) {
330 MSG_DEBUG("error setting the profile attr");
334 /* Setting the Volume */
335 err = mm_player_set_attribute(hPlayerHandle, NULL, "sound_volume_type", MM_SOUND_VOLUME_TYPE_NOTIFICATION,
336 "profile_uri", pMsgToneFilePath, strlen(pMsgToneFilePath), NULL);
338 if (err != MM_ERROR_NONE) {
339 MSG_DEBUG("error setting the profile attr");
343 err = mm_player_realize(hPlayerHandle);
345 if (err != MM_ERROR_NONE) {
346 MSG_DEBUG("mm_player_realize() error : [%d]", err);
350 /* Add Timer to stop playing after 5 sec. */
351 int g_contact_timer = -1;
352 g_contact_timer = g_timeout_add(5500, (GSourceFunc)MsgSoundMelodyTimeout, NULL);
354 err = mm_player_start(hPlayerHandle);
356 if (err != MM_ERROR_NONE) {
357 MSG_DEBUG("mm_player_start, FAIL [%x]", err);
365 pthread_mutex_lock(&muMmPlay);
369 MSG_DEBUG("Ring Alert Playing");
370 pthread_cond_wait(&cvMmPlay, &muMmPlay);
373 pthread_mutex_unlock(&muMmPlay);
375 MSG_DEBUG("Ring Alert Idle");
381 void MsgSoundPlayVibration()
387 char ivtFilePath[MAX_SOUND_FILE_LEN] = {0,};
389 vibLevel = MsgSettingGetInt(VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT);
394 dev_handle = device_haptic_open(DEV_IDX_0, 0);
396 g_timeout_add(MSG_VIBRATION_INTERVAL , MsgSoundVibTimeout, NULL);
398 /* set timer to stop vibration, then play melody */
399 svi_get_path(SVI_TYPE_VIB, SVI_VIB_NOTIFICATION_MESSAGE, ivtFilePath, sizeof(ivtFilePath));
400 ret = device_haptic_play_file(dev_handle, ivtFilePath, HAPTIC_TEST_ITERATION, vibLevel);
403 MSG_DEBUG("Fail to play haptic : [%d]", ret);
411 int MsgSoundGetUnreadMsgCnt()
416 unreadCnt = MsgSettingGetInt(VCONFKEY_MESSAGE_RECV_SMS_STATE);
419 unreadCnt += MsgSettingGetInt(VCONFKEY_MESSAGE_RECV_MMS_STATE);
421 MSG_DEBUG("unread count : [%d]", unreadCnt);