2 * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <Elementary.h>
26 #include <metadata_extractor.h>
29 #include <tzsh_quickpanel_service.h>
34 #include "quickpanel-ui.h"
37 #define NEED_TO_DEBUG_LOCKUP_ISSUE
41 int is_feedback_initialized;
43 sound_stream_info_h stream_info;
44 Ecore_Timer *playing_timer;
47 .playing_timer = NULL,
50 .is_feedback_initialized = 0,
53 static void _quickpanel_player_free(player_h *sound_player);
55 static void _quickpanel_player_del_timeout_timer(void)
57 if (s_info.playing_timer) {
58 ecore_timer_del(s_info.playing_timer);
59 s_info.playing_timer = NULL;
63 static Eina_Bool _quickpanel_player_timeout_cb(void *data)
65 s_info.playing_timer = NULL;
67 retif(data == NULL, ECORE_CALLBACK_CANCEL, "invalid parameter");
68 player_h *sound_player = data;
70 _quickpanel_player_free(sound_player);
71 s_info.playing_timer = NULL;
73 return ECORE_CALLBACK_CANCEL;
76 static void _quickpanel_player_free_job_cb(void *data)
78 player_h sound_player = data;
79 player_state_e state = PLAYER_STATE_NONE;
80 sound_stream_focus_state_e state_for_playback;
82 int ret = PLAYER_ERROR_NONE;
83 retif(sound_player == NULL, , "invalid parameter");
85 #ifdef NEED_TO_DEBUG_LOCKUP_ISSUE
86 SERR("before stopping media");
88 if (player_get_state(sound_player, &state) == PLAYER_ERROR_NONE) {
90 INFO("the state of sound player %d", state);
92 if (state == PLAYER_STATE_PLAYING) {
93 player_stop(sound_player);
94 player_unprepare(sound_player);
96 if (state == PLAYER_STATE_READY) {
97 player_unprepare(sound_player);
100 player_destroy(sound_player);
101 #ifdef NEED_TO_DEBUG_LOCKUP_ISSUE
102 SERR("after stopping media");
105 ret = sound_manager_get_focus_state(s_info.stream_info, &state_for_playback, NULL);
107 if (state_for_playback == SOUND_STREAM_FOCUS_STATE_ACQUIRED) {
108 ret = sound_manager_release_focus(s_info.stream_info, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL);
109 if (ret != SOUND_MANAGER_ERROR_NONE) {
110 ERR("sound_manager_release_focus() get failed : %d", ret);
114 ret = sound_manager_destroy_stream_information(s_info.stream_info);
115 if (ret != SOUND_MANAGER_ERROR_NONE) {
116 ERR("sound_manager_destroy_stream_information() get failed : %d", ret);
119 s_info.stream_info = NULL;
124 static void _quickpanel_player_free(player_h *sound_player)
126 retif(sound_player == NULL, , "invalid parameter");
127 retif(*sound_player == NULL, , "invalid parameter");
129 ecore_job_add(_quickpanel_player_free_job_cb, *sound_player);
130 *sound_player = NULL;
133 static void _quickpanel_player_start_job_cb(void *data)
135 int ret = PLAYER_ERROR_NONE;
136 player_h *sound_player = data;
138 #ifdef NEED_TO_DEBUG_LOCKUP_ISSUE
139 SERR("before playing media");
141 ret = player_start(*sound_player);
142 if (ret != PLAYER_ERROR_NONE) { /* if directly return retor.. */
143 ERR("player_start [%d]", ret);
144 _quickpanel_player_free(sound_player);
147 s_info.playing_timer = ecore_timer_add(QP_PLAY_DURATION_LIMIT,
148 _quickpanel_player_timeout_cb, sound_player);
149 #ifdef NEED_TO_DEBUG_LOCKUP_ISSUE
150 SERR("after playing media");
154 static void _quickpanel_player_completed_cb(void *user_data)
156 retif(user_data == NULL, , "invalid parameter");
157 player_h *sound_player = user_data;
159 DBG("Media player completed");
161 _quickpanel_player_del_timeout_timer();
162 _quickpanel_player_free(sound_player);
165 static void _quickpanel_player_error_cb(int error_code, void *user_data)
167 retif(user_data == NULL, , "invalid parameter");
168 player_h *sound_player = user_data;
170 ERR("Error code [%d]", (int)error_code);
172 _quickpanel_player_del_timeout_timer();
173 _quickpanel_player_free(sound_player);
176 HAPI int quickpanel_media_player_is_drm_error(int error_code)
178 if (error_code == PLAYER_ERROR_DRM_EXPIRED
179 || error_code == PLAYER_ERROR_DRM_NO_LICENSE
180 || error_code == PLAYER_ERROR_DRM_FUTURE_USE
181 || error_code == PLAYER_ERROR_DRM_NOT_PERMITTED) {
189 static void _quickpanel_sound_stream_focus_state_changed_cb(sound_stream_info_h stream_info, sound_stream_focus_change_reason_e reason_for_change, const char *additional_info, void *user_data)
191 DBG("_quickpanel_sound_stream_focus_state_changed_cb called, reason_for_change [%d], additional_info [%s]", reason_for_change, additional_info);
193 retif(user_data == NULL, , "invalid parameter");
194 player_h *sound_player = user_data;
196 _quickpanel_player_del_timeout_timer();
197 _quickpanel_player_free(sound_player);
200 HAPI int quickpanel_media_player_play(sound_type_e sound_type, const char *sound_file)
202 player_h *sound_player = &s_info.player;
203 sound_stream_info_h *stream_info = &s_info.stream_info;
205 int ret = PLAYER_ERROR_NONE;
206 int sndRet = SOUND_MANAGER_ERROR_NONE;
207 player_state_e state = PLAYER_STATE_NONE;
209 #ifdef NEED_TO_DEBUG_LOCKUP_ISSUE
210 SERR("Start player");
212 _quickpanel_player_del_timeout_timer();
214 if (*sound_player != NULL) {
215 _quickpanel_player_free(sound_player);
218 #ifdef NEED_TO_DEBUG_LOCKUP_ISSUE
219 SERR("setting sound session start");
222 if (*stream_info != NULL) {
223 sndRet = sound_manager_destroy_stream_information(*stream_info);
224 if (sndRet != SOUND_MANAGER_ERROR_NONE) {
225 ERR("sound_manager_destroy_stream_information() get failed : %x", ret);
229 if (sound_type == SOUND_TYPE_NOTIFICATION) {
230 sndRet = sound_manager_create_stream_information(SOUND_STREAM_TYPE_NOTIFICATION, _quickpanel_sound_stream_focus_state_changed_cb, (void*)sound_player, stream_info);
231 if (sndRet != SOUND_MANAGER_ERROR_NONE) {
232 ERR("sound_manager_create_stream_information() get failed :%x", sndRet);
233 return PLAYER_ERROR_INVALID_PARAMETER;
236 sndRet = sound_manager_set_focus_reacquisition(*stream_info, false);
237 if (sndRet != SOUND_MANAGER_ERROR_NONE) {
238 ERR("sound_manager_set_focus_reacquisition() set failed : %d", ret);
242 sndRet = sound_manager_acquire_focus(*stream_info, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL);
243 if (sndRet != SOUND_MANAGER_ERROR_NONE) {
244 ERR("sound_manager_acquire_focus() get failed : %d", ret);
249 #ifdef NEED_TO_DEBUG_LOCKUP_ISSUE
250 SERR("setting sound session finished");
253 #ifdef NEED_TO_DEBUG_LOCKUP_ISSUE
254 SERR("player_create start");
256 ret = player_create(sound_player);
257 if (ret != PLAYER_ERROR_NONE) {
258 ERR("creating the player handle failed[%d]", ret);
259 *sound_player = NULL;
262 #ifdef NEED_TO_DEBUG_LOCKUP_ISSUE
263 SERR("player_create finished");
266 player_get_state(*sound_player, &state);
267 if (state > PLAYER_STATE_READY) {
268 _quickpanel_player_free(sound_player);
272 ret = player_set_uri(*sound_player, sound_file);
273 if (ret != PLAYER_ERROR_NONE) {
274 ERR("set attribute---profile_uri[%d]", ret);
275 _quickpanel_player_free(sound_player);
279 if (*stream_info != NULL) {
280 ret = player_set_audio_policy_info(*sound_player, *stream_info);
281 if (ret != PLAYER_ERROR_NONE) {
282 ERR("player_set_audio_policy_info failed : %d", ret);
283 _quickpanel_player_free(sound_player);
288 ret = player_prepare(*sound_player);
289 if (ret != PLAYER_ERROR_NONE) {
290 ERR("realizing the player handle failed[%d]", ret);
291 _quickpanel_player_free(sound_player);
295 player_get_state(*sound_player, &state);
296 if (state != PLAYER_STATE_READY) {
297 ERR("state of player is invalid %d", state);
298 _quickpanel_player_free(sound_player);
302 /* register callback */
303 ret = player_set_completed_cb(*sound_player, _quickpanel_player_completed_cb, sound_player);
304 if (ret != PLAYER_ERROR_NONE) {
305 ERR("player_set_completed_cb() ERR: %x!!!!", ret);
306 _quickpanel_player_free(sound_player);
310 ret = player_set_error_cb(*sound_player, _quickpanel_player_error_cb, sound_player);
311 if (ret != PLAYER_ERROR_NONE) {
312 _quickpanel_player_free(sound_player);
316 ecore_job_add(_quickpanel_player_start_job_cb, sound_player);
317 #ifdef NEED_TO_DEBUG_LOCKUP_ISSUE
318 SERR("playing request");
324 static Eina_Bool _playable_check(const char *file_path)
327 int ret_meta = METADATA_EXTRACTOR_ERROR_NONE;
328 metadata_extractor_h metadata = NULL;
329 Eina_Bool ret = EINA_FALSE;
331 ret_meta = metadata_extractor_create(&metadata);
332 if (ret_meta != METADATA_EXTRACTOR_ERROR_NONE) {
333 ERR("Failed to create metadata extractor:%d", ret_meta);
337 if (metadata == NULL) {
338 ERR("Failed to create metadata extractor:%d", ret_meta);
342 ret_meta = metadata_extractor_set_path(metadata, file_path);
343 if (ret_meta != METADATA_EXTRACTOR_ERROR_NONE) {
344 ERR("Failed to set path to meta extractor:%d", ret_meta);
345 metadata_extractor_destroy(metadata);
348 ret_meta = metadata_extractor_get_metadata(metadata, METADATA_HAS_AUDIO, &value);
349 if (ret_meta != METADATA_EXTRACTOR_ERROR_NONE) {
350 ERR("Failed to get metadata:%d", ret_meta);
351 metadata_extractor_destroy(metadata);
355 if(value && g_strcmp0(value, "0")) {
361 DBG("%s :: playable[%d]", file_path, ret);
362 metadata_extractor_destroy(metadata);
366 HAPI Eina_Bool quickpanel_media_playable_check(const char *file_path)
368 Eina_Bool ret = EINA_FALSE;
370 /* Check file exist or not */
371 ret = ecore_file_exists(file_path);
372 if (ret == EINA_FALSE) {
373 ERR("%s file does not exist", file_path);
377 /* Check file playable or not */
378 ret = _playable_check(file_path);
379 if (ret == EINA_FALSE) {
380 ERR("%s file does not playable", file_path);
388 HAPI void quickpanel_media_player_stop(void)
390 _quickpanel_player_del_timeout_timer();
392 if (s_info.player != NULL) {
393 _quickpanel_player_free(&s_info.player);
396 quickpanel_media_player_id_set(0);
399 HAPI void quickpanel_media_player_id_set(int id)
404 HAPI int quickpanel_media_player_id_get(void)
409 HAPI int quickpanel_media_is_sound_enabled(void)
411 int snd_status = 0, ret = -1;
413 #ifdef VCONFKEY_SETAPPL_ACCESSIBILITY_TURN_OFF_ALL_SOUNDS
414 int snd_disabled_status = 0;
416 ret = vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TURN_OFF_ALL_SOUNDS, &snd_disabled_status);
417 msgif(ret != 0, "failed to get VCONFKEY_SETAPPL_ACCESSIBILITY_TURN_OFF_ALL_SOUNDS");
418 ret = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &snd_status);
419 msgif(ret != 0, "failed to get VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
421 if (snd_disabled_status == 0 && snd_status == 1) {
425 ret = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &snd_status);
426 msgif(ret != 0, "failed to get VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
428 if (snd_status == 1) {
436 HAPI int quickpanel_media_is_vib_enabled(void)
438 int vib_status = 0, ret = -1;
440 ret = vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &vib_status);
445 ERR("failed to get a value of VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL");
451 HAPI void quickpanel_media_play_feedback(void)
453 int snd_enabled = quickpanel_media_is_sound_enabled();
454 int vib_enabled = quickpanel_media_is_vib_enabled();
456 quickpanel_media_init();
458 if (snd_enabled == 1) {
459 feedback_play_type(FEEDBACK_TYPE_SOUND, FEEDBACK_PATTERN_TAP);
460 } else if (vib_enabled == 1) {
461 feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_TAP);
465 HAPI int quickpanel_media_set_mute_toggle(void)
469 if (quickpanel_media_is_sound_enabled() == 1 ||
470 quickpanel_media_is_vib_enabled() == 1) {
471 ret = vconf_set_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, 0);
472 msgif(ret != 0, "failed to set VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
474 ret = vconf_set_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, 0);
475 msgif(ret != 0, "failed to set VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL");
479 ret = vconf_set_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, 1);
480 msgif(ret != 0, "failed to set VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
482 ret = vconf_set_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, 0);
483 msgif(ret != 0, "failed to set VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL");
489 HAPI void quickpanel_media_init(void)
491 if (s_info.is_feedback_initialized == 0) {
492 if (feedback_initialize() == FEEDBACK_ERROR_NONE) {
493 s_info.is_feedback_initialized = 1;
495 ERR("failed to init feedback API");
500 HAPI void quickpanel_media_fini(void)
502 if (s_info.is_feedback_initialized == 1) {
503 if (feedback_deinitialize() == FEEDBACK_ERROR_NONE) {
504 s_info.is_feedback_initialized = 0;
506 ERR("failed to deinit feedback API");