#include <mm_error.h>
#include <mm_attrs.h>
#include <mm_attrs_private.h>
-#include <mm_sound.h>
-#include <mm_sound_focus.h>
#include "mm_player_priv.h"
#include "mm_player_ini.h"
__mmplayer_set_state(mm_player_t* player, int state)
{
MMMessageParamType msg = {0, };
- int sound_result = MM_ERROR_NONE;
gboolean post_bos = FALSE;
- gboolean interrupted_by_focus = FALSE;
MMPLAYER_RETURN_VAL_IF_FAIL(player, FALSE);
/* print state */
MMPLAYER_PRINT_STATE(player);
- /* do some FSM stuffs before posting new state to application */
- interrupted_by_focus = player->sound_focus.by_asm_cb;
-
switch (MMPLAYER_CURRENT_STATE(player)) {
case MM_PLAYER_STATE_NULL:
case MM_PLAYER_STATE_READY:
- {
- if (player->cmd == MMPLAYER_COMMAND_STOP) {
- sound_result = _mmplayer_sound_release_focus(&player->sound_focus);
- if (sound_result != MM_ERROR_NONE) {
- LOGE("failed to release sound focus\n");
- return MM_ERROR_POLICY_INTERNAL;
- }
- }
- }
break;
case MM_PLAYER_STATE_PAUSED:
if (!player->audio_cb_probe_id && player->set_mode.pcm_extraction && !player->audio_stream_render_cb_ex)
__mmplayer_configure_audio_callback(player);
/* FIXIT : handle return value */
-
- if (!MMPLAYER_IS_STREAMING(player) || (player->streamer && !player->streamer->is_buffering)) {
- sound_result = _mmplayer_sound_release_focus(&player->sound_focus);
- if (sound_result != MM_ERROR_NONE) {
- LOGE("failed to release sound focus\n");
- return MM_ERROR_POLICY_INTERNAL;
- }
- }
}
break;
if ((player->cmd == MMPLAYER_COMMAND_START) || (player->cmd == MMPLAYER_COMMAND_RESUME)) {
if (!player->sent_bos)
__mmplayer_handle_missed_plugin(player);
- sound_result = _mmplayer_sound_acquire_focus(&player->sound_focus);
- if (sound_result != MM_ERROR_NONE) {
- // FIXME : need to check history
- if (player->pipeline->videobin) {
- MMMessageParamType msg = {0, };
-
- LOGE("failed to go ahead because of video conflict\n");
-
- msg.union_type = MM_MSG_UNION_CODE;
- msg.code = MM_PLAYER_FOCUS_CHANGED_BY_RESOURCE_CONFLICT;
- MMPLAYER_POST_MSG(player, MM_MESSAGE_STATE_INTERRUPTED, &msg);
-
- _mmplayer_unrealize((MMHandleType)player);
- } else {
- LOGE("failed to play by sound focus error : 0x%X\n", sound_result);
- _mmplayer_pause((MMHandleType)player);
- }
-
- return MM_ERROR_POLICY_INTERNAL;
- }
}
if (player->resumed_by_rewind && player->playback_rate < 0.0) {
LOGD("player reach the target state (%s)", MMPLAYER_STATE_GET_NAME(MMPLAYER_TARGET_STATE(player)));
- /* state changed by focus or resource callback */
- if (interrupted_by_focus || player->interrupted_by_resource) {
- if (interrupted_by_focus)
- msg.state.code = player->sound_focus.focus_changed_msg;
- else if (player->interrupted_by_resource)
- msg.state.code = MM_PLAYER_FOCUS_CHANGED_BY_RESOURCE_CONFLICT;
+ /* state changed by resource callback */
+ if (player->interrupted_by_resource) {
+ msg.state.code = MM_PLAYER_FOCUS_CHANGED_BY_RESOURCE_CONFLICT;
MMPLAYER_POST_MSG(player, MM_MESSAGE_STATE_INTERRUPTED, &msg);
} else { /* state changed by usecase */
MMPLAYER_POST_MSG(player, MM_MESSAGE_STATE_CHANGED, &msg);
if (!stream_type) {
LOGE("stream_type is null.\n");
} else {
- if (player->sound_focus.focus_id)
- snprintf(stream_props, sizeof(stream_props)-1, "props,media.role=%s, media.parent_id=%d, media.focus_id=%d, mused.client_pid=%d",
- stream_type, stream_id, player->sound_focus.focus_id, player->sound_focus.pid);
+ if (player->sound.focus_id)
+ snprintf(stream_props, sizeof(stream_props)-1, "props,media.role=%s, media.parent_id=%d, media.focus_id=%d",
+ stream_type, stream_id, player->sound.focus_id);
else
- snprintf(stream_props, sizeof(stream_props)-1, "props,media.role=%s, media.parent_id=%d, mused.client_pid=%d",
- stream_type, stream_id, player->sound_focus.pid);
+ snprintf(stream_props, sizeof(stream_props)-1, "props,media.role=%s, media.parent_id=%d",
+ stream_type, stream_id);
props = gst_structure_from_string(stream_props, NULL);
g_object_set(player->pipeline->audiobin[MMPLAYER_A_SINK].gst, "stream-properties", props, NULL);
- LOGI("stream_type[%s], stream_id[%d], focus_id[%d], client_pid[%d], result[%s].\n",
- stream_type, stream_id, player->sound_focus.focus_id, player->sound_focus.pid, stream_props);
+ LOGI("stream_type[%s], stream_id[%d], focus_id[%d], result[%s].\n",
+ stream_type, stream_id, player->sound.focus_id, stream_props);
gst_structure_free(props);
}
break;
};
-#if 0 //need to check
- if (player->sound_focus.user_route_policy != 0)
- route_path = player->sound_focus.user_route_policy;
-
- g_object_set(player->pipeline->audiobin[MMPLAYER_A_SINK].gst,
- "latency", latency_mode,
- NULL);
-
- LOGD("audiosink property status...volume type:%d, user-route=%d, latency=%d \n",
- volume_type, route_path, latency_mode);
- MMPLAYER_FLEAVE();
-
-#endif
-
g_object_set(player->pipeline->audiobin[MMPLAYER_A_SINK].gst,
"latency", latency,
NULL);
mm_attrs_get_int_by_name(attrs, "sound_fadedown", &fadedown);
/* enable fadedown */
- if (fadedown || player->sound_focus.by_asm_cb)
+ if (fadedown)
__mmplayer_do_sound_fadedown(player, MM_PLAYER_FADEOUT_TIME_DEFAULT);
/* Just set state to PAUESED and the rewind. it's usual player behavior. */
ret = __mmplayer_gst_set_state(player, player->pipeline->mainbin[MMPLAYER_M_PIPE].gst, GST_STATE_PAUSED, async, timeout);
/* disable fadeout */
- if (fadedown || player->sound_focus.by_asm_cb)
+ if (fadedown)
__mmplayer_undo_sound_fadedown(player);
/* return if set_state has failed */
if (player->duration > 0 && pos_msec > player->duration)
pos_msec = player->duration;
- if (player->sound_focus.keep_last_pos) {
- LOGD("return last pos as stop by asm, %"GST_TIME_FORMAT, GST_TIME_ARGS(player->last_position));
- pos_msec = player->last_position;
- } else {
- player->last_position = pos_msec;
- }
+ player->last_position = pos_msec;
}
switch (format) {
return ret;
}
-gboolean _asm_postmsg(gpointer *data)
-{
- mm_player_t* player = (mm_player_t*)data;
- MMMessageParamType msg = {0, };
-
- MMPLAYER_FENTER();
- MMPLAYER_RETURN_VAL_IF_FAIL(player, FALSE);
- LOGW("get notified");
-
- if ((player->cmd == MMPLAYER_COMMAND_DESTROY) ||
- (player->cmd == MMPLAYER_COMMAND_UNREALIZE)) {
- LOGW("dispatched");
- return FALSE;
- }
-
-
- msg.union_type = MM_MSG_UNION_CODE;
- msg.code = player->sound_focus.focus_changed_msg;
-
- MMPLAYER_POST_MSG(player, MM_MESSAGE_READY_TO_RESUME, &msg);
- player->resume_event_id = 0;
-
- LOGW("dispatched");
- return FALSE;
-}
-
-gboolean _asm_lazy_pause(gpointer *data)
-{
- mm_player_t* player = (mm_player_t*)data;
- int ret = MM_ERROR_NONE;
-
- MMPLAYER_FENTER();
-
- MMPLAYER_RETURN_VAL_IF_FAIL(player, FALSE);
-
- if (MMPLAYER_CURRENT_STATE(player) == MM_PLAYER_STATE_PLAYING) {
- LOGD("Ready to proceed lazy pause\n");
- ret = _mmplayer_pause((MMHandleType)player);
- if (MM_ERROR_NONE != ret)
- LOGE("MMPlayer pause failed in ASM callback lazy pause\n");
- } else
- LOGD("Invalid state to proceed lazy pause\n");
-
- /* unset mute */
- if (player->pipeline && player->pipeline->audiobin)
- g_object_set(G_OBJECT(player->pipeline->audiobin[MMPLAYER_A_SINK].gst), "mute", 0, NULL);
-
- player->sound_focus.by_asm_cb = FALSE; //should be reset here
-
- MMPLAYER_FLEAVE();
-
- return FALSE;
-}
-
gboolean
__mmplayer_can_do_interrupt(mm_player_t *player)
{
goto FAILED;
}
- if ((player->sound_focus.exit_cb) || (player->set_mode.pcm_extraction)) {
- LOGW("leave from asm cb right now, %d, %d", player->sound_focus.exit_cb, player->set_mode.pcm_extraction);
+ if (player->set_mode.pcm_extraction) {
+ LOGW("leave right now, %d", player->set_mode.pcm_extraction);
goto FAILED;
}
return FALSE;
}
-/* if you want to enable USE_ASM, please check the history get the ASM cb code. */
-static int
-__mmplayer_convert_sound_focus_state(gboolean acquire, const char *reason_for_change, MMPlayerFocusChangedMsg *msg)
-{
- int ret = MM_ERROR_NONE;
- MMPlayerFocusChangedMsg focus_msg = MM_PLAYER_FOCUS_CHANGED_BY_UNKNOWN;
-
- if (strstr(reason_for_change, "alarm")) {
- focus_msg = MM_PLAYER_FOCUS_CHANGED_BY_ALARM;
-
- } else if (strstr(reason_for_change, "notification")) {
- focus_msg = MM_PLAYER_FOCUS_CHANGED_BY_NOTIFICATION;
-
- } else if (strstr(reason_for_change, "emergency")) {
- focus_msg = MM_PLAYER_FOCUS_CHANGED_BY_EMERGENCY;
-
- } else if (strstr(reason_for_change, "call-voice") ||
- strstr(reason_for_change, "call-video") ||
- strstr(reason_for_change, "voip") ||
- strstr(reason_for_change, "ringtone-voip") ||
- strstr(reason_for_change, "ringtone-call")) {
- focus_msg = MM_PLAYER_FOCUS_CHANGED_BY_CALL;
-
- } else if (strstr(reason_for_change, "media") ||
- strstr(reason_for_change, "radio") ||
- strstr(reason_for_change, "loopback") ||
- strstr(reason_for_change, "system") ||
- strstr(reason_for_change, "voice-information") ||
- strstr(reason_for_change, "voice-recognition")) {
- focus_msg = MM_PLAYER_FOCUS_CHANGED_BY_MEDIA;
-
- } else {
- ret = MM_ERROR_INVALID_ARGUMENT;
- LOGW("not supported reason(%s), err(0x%08x)", reason_for_change, ret);
- goto DONE;
- }
-
- if (acquire && (focus_msg != MM_PLAYER_FOCUS_CHANGED_BY_MEDIA))
- /* can acqurie */
- focus_msg = MM_PLAYER_FOCUS_CHANGED_COMPLETED;
-
- LOGD("converted from reason(%s) to msg(%d)", reason_for_change, focus_msg);
- *msg = focus_msg;
-
-DONE:
- return ret;
-}
-
-/* FIXME: will be updated with new funct */
-void __mmplayer_sound_focus_watch_callback(int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e focus_state,
- const char *reason_for_change, const char *additional_info, void *user_data)
-{
- mm_player_t* player = (mm_player_t*) user_data;
- int result = MM_ERROR_NONE;
- MMPlayerFocusChangedMsg msg = MM_PLAYER_FOCUS_CHANGED_BY_UNKNOWN;
-
- LOGW("[handle: %p] focus watch notified", player);
-
- if (!__mmplayer_can_do_interrupt(player)) {
- LOGW("no need to interrupt, so leave");
- goto EXIT_WITHOUT_UNLOCK;
- }
-
- if (player->sound_focus.session_flags & MM_SESSION_OPTION_UNINTERRUPTIBLE) {
- LOGW("flags is UNINTERRUPTIBLE. do nothing.");
- goto EXIT;
- }
-
- LOGW("watch: state: %d, focus_type : %d, reason_for_change : %s",
- focus_state, focus_type, (reason_for_change ? reason_for_change : "N/A"));
-
- player->sound_focus.cb_pending = TRUE;
- player->sound_focus.by_asm_cb = TRUE;
-
- if (focus_state == FOCUS_IS_ACQUIRED) {
- LOGW("watch: FOCUS_IS_ACQUIRED");
- player->sound_focus.acquired = TRUE;
-
- if (MM_ERROR_NONE == __mmplayer_convert_sound_focus_state(FALSE, reason_for_change, &msg))
- player->sound_focus.focus_changed_msg = (int)msg;
-
- if (player->sound_focus.focus_changed_msg == MM_PLAYER_FOCUS_CHANGED_BY_CALL ||
- player->sound_focus.focus_changed_msg == MM_PLAYER_FOCUS_CHANGED_BY_ALARM ||
- player->sound_focus.focus_changed_msg == MM_PLAYER_FOCUS_CHANGED_BY_MEDIA) {
- if (!MMPLAYER_IS_RTSP_STREAMING(player)) {
- // hold 0.7 second to excute "fadedown mute" effect
- LOGW("do fade down->pause->undo fade down");
-
- __mmplayer_do_sound_fadedown(player, MM_PLAYER_FADEOUT_TIME_DEFAULT);
-
- result = _mmplayer_pause((MMHandleType)player);
- if (result != MM_ERROR_NONE) {
- LOGW("fail to set Pause state by asm");
- goto EXIT;
- }
-
- __mmplayer_undo_sound_fadedown(player);
- } else {
- /* rtsp should connect again in specific network becasue tcp session can't be kept any more */
- _mmplayer_unrealize((MMHandleType)player);
- }
- } else {
- LOGW("pause immediately");
- result = _mmplayer_pause((MMHandleType)player);
- if (result != MM_ERROR_NONE) {
- LOGW("fail to set Pause state by asm");
- goto EXIT;
- }
- }
- } else if (focus_state == FOCUS_IS_RELEASED) {
- LOGW("FOCUS_IS_RELEASED: Got msg from asm to resume");
- player->sound_focus.acquired = FALSE;
- player->sound_focus.antishock = TRUE;
- player->sound_focus.by_asm_cb = FALSE;
-
- if (MM_ERROR_NONE == __mmplayer_convert_sound_focus_state(TRUE, reason_for_change, &msg))
- player->sound_focus.focus_changed_msg = (int)msg;
-
- //ASM server is single thread daemon. So use g_idle_add() to post resume msg
- player->resume_event_id = g_idle_add((GSourceFunc)_asm_postmsg, (gpointer)player);
- goto DONE;
- } else
- LOGW("unknown focus state %d", focus_state);
-
-DONE:
- player->sound_focus.by_asm_cb = FALSE;
- player->sound_focus.cb_pending = FALSE;
-
-EXIT:
- MMPLAYER_CMD_UNLOCK(player);
- LOGW("dispatched");
- return;
-
-EXIT_WITHOUT_UNLOCK:
- LOGW("dispatched");
- return;
-}
-
-void
-__mmplayer_sound_focus_callback(int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e focus_state,
- const char *reason_for_change, int option, const char *additional_info, void *user_data)
-{
- mm_player_t* player = (mm_player_t*) user_data;
- int result = MM_ERROR_NONE;
- MMPlayerFocusChangedMsg msg = MM_PLAYER_FOCUS_CHANGED_BY_UNKNOWN;
-
- LOGW("get focus notified");
-
- if (!__mmplayer_can_do_interrupt(player)) {
- LOGW("no need to interrupt, so leave");
- goto EXIT_WITHOUT_UNLOCK;
- }
-
- if (player->sound_focus.session_flags & MM_SESSION_OPTION_UNINTERRUPTIBLE) {
- LOGW("flags is UNINTERRUPTIBLE. do nothing.");
- goto EXIT;
- }
-
- LOGW("state: %d, focus_type : %d, reason_for_change : %s",
- focus_state, focus_type, (reason_for_change ? reason_for_change : "N/A"));
-
- player->sound_focus.cb_pending = TRUE;
- player->sound_focus.by_asm_cb = TRUE;
-// player->sound_focus.event_src = event_src;
-
- if (focus_state == FOCUS_IS_RELEASED) {
- LOGW("FOCUS_IS_RELEASED");
- player->sound_focus.acquired = FALSE;
-
- if (MM_ERROR_NONE == __mmplayer_convert_sound_focus_state(FALSE, reason_for_change, &msg))
- player->sound_focus.focus_changed_msg = (int)msg;
-
- if (player->sound_focus.focus_changed_msg == MM_PLAYER_FOCUS_CHANGED_BY_CALL ||
- player->sound_focus.focus_changed_msg == MM_PLAYER_FOCUS_CHANGED_BY_ALARM ||
- player->sound_focus.focus_changed_msg == MM_PLAYER_FOCUS_CHANGED_BY_MEDIA) {
- if (!MMPLAYER_IS_RTSP_STREAMING(player)) {
- //hold 0.7 second to excute "fadedown mute" effect
- LOGW("do fade down->pause->undo fade down");
-
- __mmplayer_do_sound_fadedown(player, MM_PLAYER_FADEOUT_TIME_DEFAULT);
-
- result = _mmplayer_pause((MMHandleType)player);
- if (result != MM_ERROR_NONE) {
- LOGW("fail to set Pause state by asm");
- goto EXIT;
- }
- __mmplayer_undo_sound_fadedown(player);
- } else {
- /* rtsp should connect again in specific network becasue tcp session can't be kept any more */
- _mmplayer_unrealize((MMHandleType)player);
- }
- } else {
- LOGW("pause immediately");
- result = _mmplayer_pause((MMHandleType)player);
- if (result != MM_ERROR_NONE) {
- LOGW("fail to set Pause state by asm");
- goto EXIT;
- }
- }
-
- if (player->sound_focus.focus_changed_msg == MM_PLAYER_FOCUS_CHANGED_BY_MEDIA &&
- player->sound_focus.session_type == MM_SESSION_TYPE_MEDIA &&
- !(player->sound_focus.session_flags & MM_SESSION_OPTION_RESUME_BY_SYSTEM_OR_MEDIA_PAUSED)) {
- result = mm_sound_set_focus_reacquisition_for_session(player->sound_focus.focus_id, false);
- if (result != MM_ERROR_NONE)
- LOGW("fail to set focus reacquisition to FALSE, skip going on..");
- }
- } else if (focus_state == FOCUS_IS_ACQUIRED) {
- LOGW("FOCUS_IS_ACQUIRED: Got msg from asm to resume");
- player->sound_focus.antishock = TRUE;
- player->sound_focus.by_asm_cb = FALSE;
-
- if (MM_ERROR_NONE == __mmplayer_convert_sound_focus_state(TRUE, reason_for_change, &msg))
- player->sound_focus.focus_changed_msg = (int)msg;
-
- //ASM server is single thread daemon. So use g_idle_add() to post resume msg
- player->resume_event_id = g_idle_add((GSourceFunc)_asm_postmsg, (gpointer)player);
- goto DONE;
- } else
- LOGW("unknown focus state %d", focus_state);
-
-DONE:
- player->sound_focus.by_asm_cb = FALSE;
- player->sound_focus.cb_pending = FALSE;
-
-EXIT:
- if (mm_sound_update_focus_status(id, 0))
- LOGE("failed to update focus status\n");
- MMPLAYER_CMD_UNLOCK(player);
- LOGW("dispatched");
- return;
-
-EXIT_WITHOUT_UNLOCK:
- LOGW("dispatched");
- return;
-}
-
-
int
_mmplayer_create_player(MMHandleType handle)
{
g_mutex_init(&player->subtitle_info_mutex);
g_cond_init(&player->subtitle_info_cond);
- /* create sound focus lock */
- g_mutex_init(&player->sound_focus.focus_lock);
-
player->streaming_type = STREAMING_SERVICE_NONE;
/* give default value of audio effect setting */
_mmplayer_release_video_capture(player);
- /* flush any pending asm_cb */
- if (player->sound_focus.cb_pending) {
- /* set a flag for make sure asm_cb to be returned immediately */
- LOGW("asm cb has pending state");
- player->sound_focus.exit_cb = TRUE;
-
- /* make sure to release any pending asm_cb which locked by cmd_lock */
- MMPLAYER_CMD_UNLOCK(player);
- sched_yield();
- MMPLAYER_CMD_LOCK(player);
- }
-
- /* withdraw asm */
- if (MM_ERROR_NONE != _mmplayer_sound_unregister(&player->sound_focus))
- LOGE("failed to deregister asm server\n");
-
/* de-initialize resource manager */
if (MM_RESOURCE_MANAGER_ERROR_NONE != mm_resource_manager_destroy(
player->resource_manager))
LOGE("failed to deinitialize resource manager\n");
- if (player->resume_event_id) {
- g_source_remove(player->resume_event_id);
- player->resume_event_id = 0;
- }
-
- if (player->resumable_cancel_id) {
- g_source_remove(player->resumable_cancel_id);
- player->resumable_cancel_id = 0;
- }
-
/* release pipeline */
if (MM_ERROR_NONE != __mmplayer_gst_destroy_pipeline(player)) {
LOGE("failed to destory pipeline\n");
/* release media stream callback lock */
g_mutex_clear(&player->media_stream_cb_lock);
- /* release sound focus lock */
- g_mutex_clear(&player->sound_focus.focus_lock);
-
MMPLAYER_FLEAVE();
return MM_ERROR_NONE;
}
int
-_mmplayer_sound_register_with_pid(MMHandleType hplayer, int pid)
-{
- mm_player_t* player = (mm_player_t*)hplayer;
- MMHandleType attrs = 0;
- int ret = MM_ERROR_NONE;
-
- attrs = MMPLAYER_GET_ATTRS(player);
- if (!attrs) {
- LOGE("fail to get attributes.\n");
- return MM_ERROR_PLAYER_INTERNAL;
- }
-
- player->sound_focus.pid = pid;
-
- /* register to asm */
- if (MM_ERROR_NONE != _mmplayer_sound_register(&player->sound_focus,
- (mm_sound_focus_changed_cb)__mmplayer_sound_focus_callback,
- (mm_sound_focus_changed_watch_cb)__mmplayer_sound_focus_watch_callback,
- (void*)player)) {
- /* NOTE : we are dealing it as an error since we cannot expect it's behavior */
- LOGE("failed to register asm server\n");
- return MM_ERROR_POLICY_INTERNAL;
- }
- return ret;
-}
-
-int
-_mmplayer_get_client_pid(MMHandleType hplayer, int* pid)
-{
- mm_player_t* player = (mm_player_t*) hplayer;
-
- MMPLAYER_FENTER();
-
- MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
-
- *pid = player->sound_focus.pid;
-
- LOGD("registered pid[%d] %p", *pid, player);
-
- MMPLAYER_FLEAVE();
-
- return MM_ERROR_NONE;
-}
-
-int
_mmplayer_realize(MMHandleType hplayer)
{
mm_player_t* player = (mm_player_t*)hplayer;
/* set asm stop if success */
if (MM_ERROR_NONE == ret) {
- ret = _mmplayer_sound_release_focus(&player->sound_focus);
- if (ret != MM_ERROR_NONE)
- LOGE("failed to release sound focus, ret(0x%x)\n", ret);
-
if (!player->interrupted_by_resource) {
if (player->video_decoder_resource != NULL) {
ret = mm_resource_manager_mark_for_release(player->resource_manager,
/* check current state */
MMPLAYER_CHECK_STATE(player, MMPLAYER_COMMAND_START);
- ret = _mmplayer_sound_acquire_focus(&player->sound_focus);
- if (ret != MM_ERROR_NONE) {
- LOGE("failed to acquire sound focus.\n");
- return ret;
- }
-
/* NOTE : we should check and create pipeline again if not created as we destroy
* whole pipeline when stopping in streamming playback
*/
/* check current state */
MMPLAYER_CHECK_STATE(player, MMPLAYER_COMMAND_RESUME);
- ret = _mmplayer_sound_acquire_focus(&player->sound_focus);
- if (ret != MM_ERROR_NONE) {
- LOGE("failed to acquire sound focus.\n");
- return ret;
- }
-
ret = __gst_resume(player, async);
if (ret != MM_ERROR_NONE)
player->max_audio_channels = 0;
player->video_share_api_delta = 0;
player->video_share_clock_delta = 0;
- player->sound_focus.keep_last_pos = FALSE;
player->is_subtitle_force_drop = FALSE;
player->play_subtitle = FALSE;
player->adjust_subtitle_pos = 0;
+++ /dev/null
-/*
- * libmm-player
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, YeJin Cho <cho.yejin@samsung.com>,
- * Seungbae Shin <seungbae.shin@samsung.com>, YoungHwan An <younghwan_.an@samsung.com>
- *
- * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * 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 <sys/types.h>
-#include <unistd.h>
-#include <dlog.h>
-#include <mm_error.h>
-#include "mm_player_utils.h"
-#include "mm_player_priv.h"
-#include "mm_player_sound_focus.h"
-
-#define MMPLAYER_CHECK_SOUND_FOCUS_INSTANCE(x_player_sound_focus) \
-do { \
- if (!x_player_sound_focus) { \
- LOGD("no sound focus instance");\
- return MM_ERROR_SOUND_NOT_INITIALIZED; \
- } \
-} while (0);
-
-void __mmplayer_sound_signal_callback(mm_sound_signal_name_t signal, int value, void *user_data)
-{
- MMPlayerSoundFocus *sound_focus = (MMPlayerSoundFocus*)user_data;
- MMPLAYER_RETURN_IF_FAIL(sound_focus);
-
- LOGD("sound signal callback %d / %d", signal, value);
-
- if (signal == MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS && value == 1)
- _mmplayer_sound_unregister(sound_focus);
-}
-
-static void
-__mmplayer_sound_device_connected_cb_func(MMSoundDevice_t device_h, bool is_connected, void *user_data)
-{
- mm_player_t* player = (mm_player_t*) user_data;
- MMPLAYER_RETURN_IF_FAIL(player);
-
- mm_sound_device_type_e device_type;
- int ret;
-
- LOGW("device_connected_cb is called, device_h[0x%x], is_connected[%d]\n", device_h, is_connected);
-
- /* get device type with device_h*/
- ret = mm_sound_get_device_type(device_h, &device_type);
-
- if (!is_connected && MMPLAYER_CURRENT_STATE(player) == MM_PLAYER_STATE_PLAYING
- && (player->sound_focus.focus_id > 0 || player->sound_focus.watch_id > 0)) {
- switch (device_type) {
- case MM_SOUND_DEVICE_TYPE_AUDIOJACK:
- case MM_SOUND_DEVICE_TYPE_BLUETOOTH:
- case MM_SOUND_DEVICE_TYPE_HDMI:
- case MM_SOUND_DEVICE_TYPE_USB_AUDIO:
- {
- int result = MM_ERROR_NONE;
- LOGW("pause immediately");
-
- player->sound_focus.by_asm_cb = TRUE;
- player->sound_focus.focus_changed_msg = MM_PLAYER_FOCUS_CHANGED_BY_EARJACK_UNPLUG;
-
- result = _mmplayer_pause((MMHandleType)player);
- if (result != MM_ERROR_NONE) {
- LOGE("focus_id [%d], watch_id [%d], connected_id [%d], change_state result[%d]",
- player->sound_focus.focus_id, player->sound_focus.watch_id,
- player->sound_focus.connected_id, ret);
- }
- player->sound_focus.by_asm_cb = FALSE;
- }
- break;
-
- default:
- LOGD("do nothing");
- }
- }
-}
-
-const gchar *
-__mmplayer_sound_get_stream_type(gint type)
-{
- switch (type) {
- case MM_SESSION_TYPE_CALL:
- case MM_SESSION_TYPE_VIDEOCALL:
- case MM_SESSION_TYPE_VOIP:
- return "ringtone-voip";
- case MM_SESSION_TYPE_MEDIA:
- return "media";
- case MM_SESSION_TYPE_NOTIFY:
- return "notification";
- case MM_SESSION_TYPE_ALARM:
- return "alarm";
- case MM_SESSION_TYPE_EMERGENCY:
- return "emergency";
- default:
- LOGW("unexpected case!\n");
- return "media";
- }
-}
-
-static bool
-__mmplayer_check_need_block(const char *focus_acquired_by)
-{
- if (!focus_acquired_by)
- return false;
-
- if (!strcmp(focus_acquired_by, "alarm") ||
- !strcmp(focus_acquired_by, "ringtone-voip") ||
- !strcmp(focus_acquired_by, "ringtone-call") ||
- !strcmp(focus_acquired_by, "voip") ||
- !strcmp(focus_acquired_by, "call-voice") ||
- !strcmp(focus_acquired_by, "call-video")) {
- LOGW("Blocked by session policy, focus_acquired_by[%s]", focus_acquired_by);
- return true;
- }
-
- return false;
-}
-
-int
-_mmplayer_sound_acquire_focus(MMPlayerSoundFocus* sound_focus)
-{
- int ret = MM_ERROR_NONE;
-
- MMPLAYER_FENTER();
- MMPLAYER_CHECK_SOUND_FOCUS_INSTANCE(sound_focus);
-
- if (sound_focus->acquired) {
- LOGW("focus is already acquired. can't acquire again.");
- return MM_ERROR_NONE;
- }
-
- if (_mmplayer_is_using_internal_sound_focus(sound_focus)) {
- if (sound_focus->session_type == MM_SESSION_TYPE_MEDIA)
- /* option: 1 for no-resume */
- ret = mm_sound_acquire_focus_with_option(sound_focus->focus_id, FOCUS_FOR_BOTH, 1, "mm-player acquire focus");
- else
- ret = mm_sound_acquire_focus(sound_focus->focus_id, FOCUS_FOR_BOTH, "mm-player acquire focus");
-
- if (ret != MM_ERROR_NONE) {
- LOGE("failed to acquire sound focus [0x%X]", ret);
- return ret;
- }
-
- sound_focus->acquired = TRUE;
-
- ret = mm_sound_update_focus_status(sound_focus->focus_id, 1);
- if (ret != MM_ERROR_NONE)
- LOGE("failed to update focus status [0x%X]", ret);
- } else {
- if (sound_focus->watch_id > 0) {
- char *stream_type = NULL;
- char *ext_info = NULL;
- int option = 0;
-
- ret = mm_sound_get_stream_type_of_acquired_focus(FOCUS_FOR_BOTH, &stream_type, &option, &ext_info);
- if (ret == MM_ERROR_NONE) {
- LOGD("Focus is acquired by stream_type[%s], option[%d], ext_info[%s]", stream_type, option, ext_info);
- if (__mmplayer_check_need_block((const char*)stream_type)) {
- LOGE("Blocked by an acquired focus[%s]", stream_type);
- ret = MM_ERROR_POLICY_INTERNAL;
- }
- } else {
- LOGW("failed to get stream type of acquired focus [0x%X]", ret);
- if (ret == MM_ERROR_SOUND_NO_DATA) /* there is no acquired focus, it is normal case */
- ret = MM_ERROR_NONE;
- }
-
- if (stream_type) free(stream_type);
- if (ext_info) free(ext_info);
- }
- }
-
- MMPLAYER_FLEAVE();
- return ret;
-}
-
-int
-_mmplayer_sound_release_focus(MMPlayerSoundFocus* sound_focus)
-{
- int ret = MM_ERROR_NONE;
-
- MMPLAYER_FENTER();
- MMPLAYER_CHECK_SOUND_FOCUS_INSTANCE(sound_focus);
-
- if (!sound_focus->acquired) {
- LOGW("focus is not acquired. no need to release.");
- return MM_ERROR_NONE;
- }
-
- if (_mmplayer_is_using_internal_sound_focus(sound_focus)) {
- if (sound_focus->session_type == MM_SESSION_TYPE_MEDIA)
- /* option: 1 for no-resume */
- ret = mm_sound_release_focus_with_option(sound_focus->focus_id, FOCUS_FOR_BOTH, 1, "mm-player release focus");
- else
- ret = mm_sound_release_focus(sound_focus->focus_id, FOCUS_FOR_BOTH, "mm-player release focus");
-
- if (ret != MM_ERROR_NONE) {
- LOGE("failed to release sound focus\n");
- return ret;
- }
-
- sound_focus->acquired = FALSE;
-
- ret = mm_sound_update_focus_status(sound_focus->focus_id, 0);
- if (ret != MM_ERROR_NONE)
- LOGE("failed to update focus status\n");
- }
-
- MMPLAYER_FLEAVE();
- return MM_ERROR_NONE;
-}
-
-gint
-_mmplayer_sound_register(MMPlayerSoundFocus* sound_focus,
- mm_sound_focus_changed_cb focus_cb, mm_sound_focus_changed_watch_cb watch_cb, void* param)
-{
- gint pid = -1;
- gint ret = MM_ERROR_NONE;
- const gchar *stream_type = NULL;
- mm_player_t* player = MM_PLAYER_CAST(param);
-
- MMPLAYER_FENTER();
- MMPLAYER_CHECK_SOUND_FOCUS_INSTANCE(sound_focus);
- MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_INVALID_ARGUMENT);
-
- /* check if it's running on the media_server */
- if (sound_focus->pid > 0)
- pid = sound_focus->pid;
- else
- return MM_ERROR_INVALID_ARGUMENT;
-
- LOGD("sound register focus pid[%d]", pid);
- /* read session information */
- ret = _mm_session_util_read_information(pid, &sound_focus->session_type, &sound_focus->session_flags);
- LOGW("Read Session Type -> ret:0x%X \n", ret);
-
- if (ret == MM_ERROR_INVALID_HANDLE) {
- /* case 1. if there is no session */
- LOGW("subscribe_id=%d\n", sound_focus->subscribe_id);
-
- if (sound_focus->subscribe_id == 0) {
- ret = mm_sound_subscribe_signal_for_daemon(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, pid, &sound_focus->subscribe_id,
- (mm_sound_signal_callback)__mmplayer_sound_signal_callback, (void*)sound_focus);
- if (ret != MM_ERROR_NONE) {
- LOGE("mm_sound_subscribe_signal is failed\n");
- return MM_ERROR_POLICY_BLOCKED;
- }
-
- LOGD("register focus watch callback for the value is 0, sub_cb id %d\n", sound_focus->subscribe_id);
- /* register watch callback */
- ret = mm_sound_set_focus_watch_callback_for_session(pid ,
- FOCUS_FOR_BOTH, watch_cb, (void*)param, &sound_focus->watch_id);
- if (ret != MM_ERROR_NONE) {
- LOGE("mm_sound_set_focus_watch_callback is failed\n");
- return MM_ERROR_POLICY_BLOCKED;
- }
- /* register device connected callback */
- ret = mm_sound_add_device_connected_callback(MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG,
- (mm_sound_device_connected_cb)__mmplayer_sound_device_connected_cb_func, (void*)param, &sound_focus->connected_id);
- if (ret != MM_ERROR_NONE) {
- LOGE("mm_sound_add_device_connected_callback is failed\n");
- return MM_ERROR_POLICY_BLOCKED;
- }
- LOGD("register device connected callback for the value is 0, sub_cb id %d\n", sound_focus->connected_id);
- }
- ret = MM_ERROR_NONE;
- } else if (ret == MM_ERROR_NONE) {
- /* case 2. if sessoin exists */
- /* in this case, this process is using stream info created by using sound-manager,
- * we're going to skip working on backward compatibility of session. */
- if (sound_focus->session_type == MM_SESSION_TYPE_REPLACED_BY_STREAM) {
- LOGW("this process is using stream info. skip it..");
- } else {
- /* interpret session information */
- stream_type = __mmplayer_sound_get_stream_type(sound_focus->session_type);
- LOGD("fid [%d] wid [%d] type[%s], flags[0x%02X]\n",
- sound_focus->focus_id, sound_focus->watch_id, stream_type, sound_focus->session_flags);
-
- if (sound_focus->focus_id == 0) {
- /* get unique id */
- ret = mm_sound_focus_get_id(&sound_focus->focus_id);
- if (ret != MM_ERROR_NONE) {
- LOGE("failed to get unique focus id\n");
- return MM_ERROR_POLICY_BLOCKED;
- }
-
- /* register sound focus callback */
- ret = mm_sound_register_focus_for_session(sound_focus->focus_id, pid,
- stream_type, focus_cb, (void*)param);
- if (ret != MM_ERROR_NONE) {
- LOGE("mm_sound_register_focus is failed\n");
- return MM_ERROR_POLICY_BLOCKED;
- }
- }
-
- if ((sound_focus->watch_id == 0) &&
- (strstr(stream_type, "media")) &&
- !(sound_focus->session_flags & MM_SESSION_OPTION_PAUSE_OTHERS) &&
- !(sound_focus->session_flags & MM_SESSION_OPTION_UNINTERRUPTIBLE)) {
- LOGD("register focus watch callback\n");
- /* register watch callback */
- ret = mm_sound_set_focus_watch_callback_for_session(pid,
- FOCUS_FOR_BOTH, watch_cb, (void*)param, &sound_focus->watch_id);
- if (ret != MM_ERROR_NONE) {
- LOGE("mm_sound_set_focus_watch_callback is failed\n");
- return MM_ERROR_POLICY_BLOCKED;
- }
- }
-
- if ((strstr(stream_type, "media")) && (sound_focus->connected_id == 0)) {
- /* register device connected callback */
- ret = mm_sound_add_device_connected_callback(MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG,
- (mm_sound_device_connected_cb)__mmplayer_sound_device_connected_cb_func, (void*)param, &sound_focus->connected_id);
- if (ret != MM_ERROR_NONE) {
- LOGE("mm_sound_add_device_connected_callback is failed\n");
- return MM_ERROR_POLICY_BLOCKED;
- }
- LOGD("register device connected callback for the value is 0, sub_cb id %d\n", sound_focus->connected_id);
- }
-
- ret = mm_player_set_attribute(player, NULL, "sound_stream_type", stream_type, strlen(stream_type), (char *)NULL);
- if (ret != MM_ERROR_NONE) {
- LOGE("mm_player_set_attribute for sound_stream_type is failed\n");
- return ret;
- }
- }
- ret = MM_ERROR_NONE;
- } else {
- LOGE("_mm_session_util_read_information is failed");
- ret = MM_ERROR_POLICY_BLOCKED;
- }
-
- MMPLAYER_FLEAVE();
- return ret;
-}
-
-gint
-_mmplayer_sound_unregister(MMPlayerSoundFocus* sound_focus)
-{
- int ret = MM_ERROR_NONE;
-
- MMPLAYER_FENTER();
-
- MMPLAYER_CHECK_SOUND_FOCUS_INSTANCE(sound_focus);
- MMPLAYER_SOUND_FOCUS_LOCK(sound_focus);
-
- LOGD("unregister sound focus callback\n");
-
- if (sound_focus->focus_id > 0) {
- ret = mm_sound_unregister_focus(sound_focus->focus_id);
- if (ret != MM_ERROR_NONE)
- LOGE("failed to mm_sound_unregister_focus() %d", sound_focus->focus_id);
- sound_focus->focus_id = 0;
- }
-
- if (sound_focus->watch_id > 0) {
- ret = mm_sound_unset_focus_watch_callback(sound_focus->watch_id);
- if (ret != MM_ERROR_NONE)
- LOGE("failed to mm_sound_unset_focus_watch_callback() %d", sound_focus->watch_id);
- sound_focus->watch_id = 0;
- }
-
- if (sound_focus->subscribe_id > 0) {
- mm_sound_unsubscribe_signal(sound_focus->subscribe_id);
- sound_focus->subscribe_id = 0;
- }
- if (sound_focus->connected_id > 0) {
- ret = mm_sound_remove_device_connected_callback(sound_focus->connected_id);
- if (ret != MM_ERROR_NONE)
- LOGE("failed to mm_sound_remove_device_connected_callback() %d", sound_focus->connected_id);
- sound_focus->connected_id = 0;
- }
-
- MMPLAYER_SOUND_FOCUS_UNLOCK(sound_focus);
- MMPLAYER_FLEAVE();
-
- return MM_ERROR_NONE;
-}
-
-bool _mmplayer_is_using_internal_sound_focus(MMPlayerSoundFocus* sound_focus)
-{
- MMPLAYER_RETURN_VAL_IF_FAIL(sound_focus, false);
-
- /* Perhaps, already got release signal or application may use stream focus directly */
- if (sound_focus->focus_id == 0)
- return false;
-
- if ((sound_focus->session_type == MM_SESSION_TYPE_MEDIA && sound_focus->session_flags & MM_SESSION_OPTION_PAUSE_OTHERS) ||
- (sound_focus->session_type == MM_SESSION_TYPE_NOTIFY) ||
- (sound_focus->session_type == MM_SESSION_TYPE_ALARM) ||
- (sound_focus->session_type == MM_SESSION_TYPE_EMERGENCY))
- return true;
- else
- return false;
-}