diff options
Diffstat (limited to 'src/core/mp-player-mgr.c')
-rwxr-xr-x | src/core/mp-player-mgr.c | 591 |
1 files changed, 591 insertions, 0 deletions
diff --git a/src/core/mp-player-mgr.c b/src/core/mp-player-mgr.c new file mode 100755 index 0000000..a7f153c --- /dev/null +++ b/src/core/mp-player-mgr.c @@ -0,0 +1,591 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.tizenopensource.org/license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + + +#include <glib.h> +#include <mm_error.h> +#include "music.h" +#include "mp-player-mgr.h" +#include "mp-player-control.h" +#include "mp-play.h" +#include "mp-player-drm.h" +#include <mm_session.h> +#include <mm_message.h> +#include "mp-player-debug.h" +#include "mp-widget.h" +#include "mp-play-view.h" +#include "mp-streaming-mgr.h" + +#define MAX_PATH_LEN MAX_NAM_LEN + +static MMHandleType _player = 0; + +bool +mp_player_mgr_is_active(void) +{ + return _player ? TRUE : FALSE; +} + +bool +mp_player_mgr_set_msg_callback(MMMessageCallback cb, gpointer user_data) +{ + if (!mp_player_mgr_is_active()) + return FALSE; + + if (mm_player_set_message_callback(_player, cb, user_data) != MM_ERROR_NONE) + { + ERROR_TRACE("Error when mp_player_mgr_set_msg_callback\n"); + return FALSE; + } + return TRUE; +} + +MMPlayerStateType +mp_player_mgr_get_state(void) +{ + int ret = -1; + MMPlayerStateType state_now = MM_PLAYER_STATE_NULL; + + if (!_player) + return state_now; + + ret = mm_player_get_state(_player, &state_now); + return state_now; +} + + +bool +mp_player_mgr_create(void *data, const gchar * path) +{ + struct appdata *ad = (struct appdata *)data; + int path_len = strlen(path); + + char *g_err_name = NULL; + int ret = MM_ERROR_NONE; + + DEBUG_TRACE("mp_player_mgr_create with [%s]\n", path); + + if(!ad->player_msg_pipe) + ad->player_msg_pipe = ecore_pipe_add(mp_player_mgr_pipe_cb, ad); + + if (path_len > 0 && path_len < MAX_PATH_LEN) + { + + if (mp_player_mgr_is_active()) + { + return FALSE; + } + if (mm_player_create(&_player) != MM_ERROR_NONE) + { + ERROR_TRACE("Error when mp_player_mgr_create\n"); + return FALSE; + } + + ret = mm_player_set_attribute(_player, &g_err_name, + "sound_volume_type", MM_SOUND_VOLUME_TYPE_MEDIA, + "profile_uri", path, strlen(path), NULL); + if (ret != MM_ERROR_NONE) + { + ERROR_TRACE(">>>>>>>>>>>>>g_err_name : %s\n", g_err_name); + SAFE_FREE(g_err_name); + return FALSE; + } + + if (mp_streaming_mgr_check_streaming(ad, path)) { + if (!mp_streaming_mgr_set_attribute(ad, _player)) { + mp_error("streaming set attribute fail"); + return FALSE; + } + } + } + else + { + + return FALSE; + } + return TRUE; +} + + +bool +mp_player_mgr_destroy(void *data) +{ + struct appdata *ad = data; + + if(ad->player_msg_pipe) + { + ecore_pipe_del(ad->player_msg_pipe); + ad->player_msg_pipe = NULL; + } + + if (!mp_player_mgr_is_active()) + return FALSE; + + if (mm_player_destroy(_player) != MM_ERROR_NONE) + { + ERROR_TRACE("Error when mp_player_mgr_destroy\n"); + return FALSE; + } + + _player = 0; + ad->player_state = PLAY_STATE_INIT; + if (!ad->freeze_indicator_icon) + vconf_set_int(VCONFKEY_MUSIC_STATE, VCONFKEY_MUSIC_OFF); + else + ad->freeze_indicator_icon = FALSE; + + return TRUE; +} + +bool +mp_player_mgr_realize(void *data) +{ + if (!mp_player_mgr_is_active()) + return FALSE; + + if (mm_player_realize(_player) != MM_ERROR_NONE) + { + ERROR_TRACE("Error when mp_player_mgr_realize\n"); + _player = 0; + return FALSE; + } + return TRUE; +} + +bool +mp_player_mgr_unrealize(void *data) +{ + if (!mp_player_mgr_is_active()) + return FALSE; + + if (mm_player_unrealize(_player) != MM_ERROR_NONE) + { + ERROR_TRACE("Error when mp_player_mgr_unrealize\n"); + return FALSE; + } + return TRUE; +} + +bool +mp_player_mgr_play(void *data) +{ + startfunc; + struct appdata *ad = data; + int err = -1; + + if (!mp_player_mgr_is_active()) + return FALSE; + + err = mm_player_start(_player); + if (err != MM_ERROR_NONE) + { + if (err == MM_ERROR_POLICY_BLOCKED) + { + mp_widget_text_popup(ad, GET_STR("IDS_MUSIC_POP_UNABLE_TO_PLAY_DURING_CALL")); + } + else + { + mp_widget_text_popup(ad, GET_STR("IDS_MUSIC_POP_UNABLE_TO_PLAY_ERROR_OCCURRED")); + } + + ERROR_TRACE("Error when mp_player_mgr_play. err[%x]\n", err); + return FALSE; + } + return TRUE; +} + + +bool +mp_player_mgr_stop(void *data) +{ + startfunc; + struct appdata *ad = data; + + if (!mp_player_mgr_is_active()) + return FALSE; + + if (mm_player_stop(_player) != MM_ERROR_NONE) + { + ERROR_TRACE("Error when mp_player_mgr_stop\n"); + return FALSE; + } + + mp_play_stop(ad); + return TRUE; +} + +bool +mp_player_mgr_resume(void *data) +{ + startfunc; + struct appdata *ad = data; + int err = -1; + + if (!mp_player_mgr_is_active()) + return FALSE; + + err = mm_player_resume(_player); + if (err != MM_ERROR_NONE) + { + ERROR_TRACE("Error when mp_player_mgr_resume. err[%x]\n", err); + if (err == MM_ERROR_POLICY_BLOCKED) + { + mp_widget_text_popup(ad, GET_STR("IDS_MUSIC_POP_UNABLE_TO_PLAY_DURING_CALL")); + } + else + { + mp_widget_text_popup(ad, GET_STR("IDS_MUSIC_POP_UNABLE_TO_PLAY_ERROR_OCCURRED")); + } + return FALSE; + } + + mp_play_view_update_progressbar(data); + mp_play_view_progress_timer_thaw(data); + + return TRUE; +} + +bool +mp_player_mgr_pause(void *data) +{ + startfunc; + int err = -1; + + if (!mp_player_mgr_is_active()) + return FALSE; + + err = mm_player_pause(_player); + if (err != MM_ERROR_NONE) + { + ERROR_TRACE("Error when mp_player_mgr_pause. err[%x]\n", err); + return FALSE; + } + return TRUE; +} + +bool +mp_player_mgr_set_position(guint pos) +{ + startfunc; + if (!mp_player_mgr_is_active()) + return FALSE; + + if (mm_player_set_position(_player, MM_PLAYER_POS_FORMAT_TIME, (int)pos) != MM_ERROR_NONE) + { + ERROR_TRACE("Error when mp_player_mgr_set_position\n"); + return FALSE; + } + + return TRUE; +} + +int +mp_player_mgr_get_position(void) +{ + int pos = 0; + + if (!mp_player_mgr_is_active()) + return 0; + + if (mm_player_get_position(_player, MM_PLAYER_POS_FORMAT_TIME, &pos) != MM_ERROR_NONE) + { + ERROR_TRACE("Error when mp_player_mgr_get_position\n"); + return 0; + } + + return pos; +} + +int +mp_player_mgr_get_duration(void) +{ + if (!mp_player_mgr_is_active()) + return -1; + + int ret = MM_ERROR_NONE; + char *g_err_name = NULL; + int duration = -1; + + ret = mm_player_get_attribute(_player, &g_err_name, "content_duration", &duration, NULL); + if (ret != MM_ERROR_NONE) + { + ERROR_TRACE(">>>>>>>>>>>>>g_err_name : %s\n", g_err_name); + SAFE_FREE(g_err_name); + return FALSE; + } + else + { + return duration; + } + return duration; +} + +static Eina_Bool +mp_playing_paused_by_bluetooth(void *data) +{ + struct appdata *ad = data; + MP_CHECK_FALSE(ad); + + int earjack = 0; + + if (vconf_get_int(VCONFKEY_SYSMAN_EARJACK, &earjack)) + { + WARN_TRACE("Earjack state get Fail..."); + + if (earjack == 0) + { + mp_play_pause(ad); + } + } + + mp_widget_text_popup(ad, GET_STR("IDS_MUSIC_POP_BLUETOOTH_DISCONNECTED")); + ad->bt_pause_idler = NULL; + return 0; +} + +static Eina_Bool +mp_playing_error(void *data) +{ + struct appdata *ad = data; + MP_CHECK_FALSE(ad); + + mp_play_destory(ad); + ad->playing_err_idler = NULL; + return EINA_FALSE; +} + +typedef struct{ + int msg_type; + MMMessageParamType msg_param; +}mp_pipe_msg; + +void +mp_player_mgr_pipe_cb(void *data, void *buffer, unsigned int nbyte) +{ + struct appdata *ad = data; + MP_CHECK(ad); + MP_CHECK(buffer); + mp_pipe_msg *pipe_msg = buffer; + MMMessageParamType *param = &(pipe_msg->msg_param); + int msg_type = pipe_msg->msg_type; + + DEBUG_TRACE("msg_type: %d,", msg_type); + + switch (msg_type) + { + case MM_MESSAGE_BEGIN_OF_STREAM: + DEBUG_TRACE("receive MM_MESSAGE_BEGIN_OF_STREAM\n"); + mp_play_start(ad); + break; + + case MM_MESSAGE_ERROR: + DEBUG_TRACE("receive MM_MESSAGE_ERROR \n"); + DEBUG_TRACE("Error Code=%x\n", param->code); + MP_CHECK(param); + switch (param->code) + { + case MM_ERROR_PLAYER_BT_CONNECTION: + DEBUG_TRACE("receive MM_ERROR_PLAYER_BT_CONNECTION\n"); + break; + case MM_ERROR_PLAYER_INTERNAL: + DEBUG_TRACE("receive MM_ERROR_PLAYER_INTERNAL\n"); + mp_widget_text_popup(ad, GET_STR("IDS_MUSIC_POP_UNABLE_TO_PLAY_ERROR_OCCURRED")); + break; + case MM_ERROR_PLAYER_CODEC_NOT_FOUND: + DEBUG_TRACE("receive MM_ERROR_PLAYER_CODEC_NOT_FOUND\n"); + mp_widget_text_popup(ad, GET_STR("IDS_MUSIC_POP_UNABLE_TO_PLAY_UNSUPPORTED_FILETYPE")); + break; + default: + if (!mp_streaming_mgr_message_callback(msg_type, param, ad)) + mp_widget_text_popup(ad, GET_STR("IDS_MUSIC_POP_UNABLE_TO_PLAY_UNSUPPORTED_FILETYPE")); + break; + } + if(!ad->playing_err_idler) + ad->playing_err_idler = ecore_idler_add(mp_playing_error, ad); + break; + + case MM_MESSAGE_WARNING: + DEBUG_TRACE("receive MM_MESSAGE_WARNING\n"); + break; + + case MM_MESSAGE_END_OF_STREAM: + DEBUG_TRACE("receive MM_MESSAGE_END_OF_STREAM\n"); + mp_play_control_end_of_stream(ad); + break; + + case MM_MESSAGE_STATE_CHANGED: + MP_CHECK(param); + switch (param->state.current) + { + case MM_PLAYER_STATE_NONE: + DEBUG_TRACE("==> [MediaPlayerApp] Player is [NONE]\n"); + break; + case MM_PLAYER_STATE_READY: + DEBUG_TRACE("==> [MediaPlayerApp] Player is [READY]\n"); + ad->player_state = PLAY_STATE_READY; + mp_play_ready(ad); + break; + case MM_PLAYER_STATE_PLAYING: + DEBUG_TRACE("==> [MediaPlayerApp] Player is [PLAYING]\n"); + if (ad->player_state == PLAY_STATE_PAUSED) + mp_play_resume(ad); + + ad->player_state = PLAY_STATE_PLAYING; + + if (ad->is_focus_out) { + mp_debug("prohibit playing in bg"); + mp_play_control_play_cb(ad, NULL, SIGNAL_PAUSE, NULL); + } + + break; + case MM_PLAYER_STATE_PAUSED: + DEBUG_TRACE("==> [MediaPlayerApp] Player is [PAUSED]\n"); + mp_play_pause(ad); + ad->player_state = PLAY_STATE_PAUSED; + break; + case MM_PLAYER_STATE_NULL: + DEBUG_TRACE("==> [MediaPlayerApp] Player is [NULL]\n"); + break; + } + + break; + + case MM_MESSAGE_STATE_INTERRUPTED: + DEBUG_TRACE("receive MM_MESSAGE_STATE_CHANGED_BY_ASM\n"); + MP_CHECK(param); + switch (param->code) + { + case MM_MSG_CODE_INTERRUPTED_BY_OTHER_APP: + DEBUG_TRACE("receive MM_MSG_CODE_INTERRUPTED_BY_OTHER_APP"); + break; + case MM_MSG_CODE_INTERRUPTED_BY_CALL_START: + DEBUG_TRACE("receive MM_MSG_CODE_INTERRUPTED_BY_CALL_START"); + break; + case MM_MSG_CODE_INTERRUPTED_BY_CALL_END: + DEBUG_TRACE("receive MM_MSG_CODE_INTERRUPTED_BY_CALL_END"); + break; + case MM_MSG_CODE_INTERRUPTED_BY_EARJACK_UNPLUG: + DEBUG_TRACE("receive MM_MSG_CODE_INTERRUPTED_BY_EARJACK_UNPLUG"); + break; + case MM_MSG_CODE_INTERRUPTED_BY_RESOURCE_CONFLICT: + DEBUG_TRACE("receive MM_MSG_CODE_INTERRUPTED_BY_RESOURCE_CONFLICT"); + break; + case MM_MSG_CODE_INTERRUPTED_BY_ALARM_START: + DEBUG_TRACE("receive MM_MSG_CODE_INTERRUPTED_BY_ALARM_START"); + break; + case MM_MSG_CODE_INTERRUPTED_BY_ALARM_END: + DEBUG_TRACE("receive MM_MSG_CODE_INTERRUPTED_BY_ALARM_END"); + break; + } + mp_play_pause(ad); + + break; + + case MM_MESSAGE_BLUETOOTH_OFF: + DEBUG_TRACE("receive MM_MESSAGE_BLUETOOTH_OFF\n"); + if(!ad->bt_pause_idler) + ad->bt_pause_idler = ecore_idler_add(mp_playing_paused_by_bluetooth, ad); + break; + + case MM_MESSAGE_READY_TO_RESUME: + DEBUG_TRACE("receive MM_MESSAGE_READY_TO_RESUME"); + + if (ad->player_state == PLAY_STATE_PAUSED) + mp_player_mgr_resume(ad); + else + ERROR_TRACE("Check player state"); + break; + + default: + if (!mp_streaming_mgr_message_callback(msg_type, param, ad)) { + DEBUG_TRACE("receive unknown msg [0x%x]", msg_type); + } + } + return; +} + +int +player_msg_cb(int msg_type, void *msg_param, void *user_param) +{ + startfunc; + struct appdata *ad = user_param; + MP_CHECK_VAL(ad, 0); + + MP_CHECK_VAL(mp_player_mgr_is_active(), 1); + + mp_pipe_msg *pipe_msg = calloc(sizeof(mp_pipe_msg), 1); + if(msg_param) + memcpy(&(pipe_msg->msg_param), msg_param, sizeof(MMMessageParamType)); + pipe_msg->msg_type = msg_type; + + ecore_pipe_write(ad->player_msg_pipe, pipe_msg, sizeof(mp_pipe_msg)); + + IF_FREE(pipe_msg); + return 1; +} + +int +mp_player_mgr_vol_type_set(void) +{ + return mm_sound_volume_primary_type_set(VOLUME_TYPE_MEDIA); +} + +int +mp_player_mgr_vol_type_unset(void) +{ + return mm_sound_volume_primary_type_clear(); +} + +bool +mp_player_mgr_session_init(void) +{ + int ret = MM_ERROR_NONE; + + ret = mm_session_init(MM_SESSION_TYPE_SHARE); + + if (ret != MM_ERROR_NONE) + return FALSE; + + return TRUE; +} + +bool +mp_player_mgr_session_finish(void) +{ + int ret = MM_ERROR_NONE; + + ret = mm_session_finish(); + + if (ret != MM_ERROR_NONE) + return FALSE; + + return TRUE; + +} + +void +mp_player_mgr_set_mute(bool bMuteEnable) +{ + + if (!mp_player_mgr_is_active()) + return; + + if (mm_player_set_mute(_player, (int)bMuteEnable) != MM_ERROR_NONE) + { + ERROR_TRACE("[ERR] mm_player_set_mute"); + } +} |