4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, YeJin Cho <cho.yejin@samsung.com>,
7 * Seungbae Shin <seungbae.shin@samsung.com>, YoungHwan An <younghwan_.an@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
25 #include "mm_player_utils.h"
26 #include "mm_player_priv.h"
27 #include "mm_player_asm.h"
29 #include <vconf-internal-sound-keys.h>
31 #define MMPLAYER_CHECK_SESSION_SKIP(x_player_asm) \
34 if (x_player_asm->skip_session == TRUE) \
36 debug_log("skip session"); \
37 return MM_ERROR_NONE; \
41 #define MMPLAYER_CHECK_SESSION_INSTANCE(x_player_asm) \
46 debug_log("no session instance");\
47 return MM_ERROR_SOUND_NOT_INITIALIZED; \
51 static ASM_sound_events_t __mmplayer_asm_get_event_type(gint type);
54 __mmplayer_asm_get_state_name ( int state )
60 case ASM_STATE_PLAYING:
66 case ASM_STATE_WAITING:
73 #define MMPLAYER_ASM_STATE_GET_NAME(state) __mmplayer_asm_get_state_name(state)
76 _mmplayer_asm_register(MMPlayerASM* sm, ASM_sound_cb_t callback, void* param)
80 gint session_type = MM_SESSION_TYPE_MEDIA;
81 gint session_options = 0;
82 gint errorcode = MM_ERROR_NONE;
84 gint event_type = ASM_EVENT_NONE;
89 MMPLAYER_CHECK_SESSION_INSTANCE(sm);
90 MMPLAYER_CHECK_SESSION_SKIP(sm);
92 /* check if it's running on the media_server */
96 debug_log("mm-player is running on different process. Just faking pid to [%d]. :-p\n", pid);
99 /* read session information */
100 errorcode = _mm_session_util_read_information(pid, &session_type, &session_options);
103 debug_warning("Read Session Type failed. use default \"media\" type\n");
104 session_type = MM_SESSION_TYPE_MEDIA;
107 /* interpret session information */
108 event_type = __mmplayer_asm_get_event_type(session_type);
110 /* check if it's one of CALL series */
111 if ( event_type == ASM_EVENT_CALL ||
112 event_type == ASM_EVENT_VIDEOCALL ||
113 event_type == ASM_EVENT_VOIP)
115 debug_warning("session type is one of CALL series(%d), skip registering ASM\n", session_type);
116 sm->event = event_type;
117 sm->skip_session = TRUE;
118 return MM_ERROR_NONE;
121 /* register audio-session-manager handle and callback */
122 if( ! ASM_register_sound(pid, &asm_handle, event_type, ASM_STATE_NONE, callback, (void*)param, ASM_RESOURCE_NONE, &errorcode))
124 debug_error("ASM_register_sound() failed, error(%x)\n", errorcode);
127 /* set session options */
130 if( ! ASM_set_session_option(asm_handle, session_options, &errorcode))
132 debug_error("ASM_set_session_options() failed, error(%x)\n", errorcode);
137 /* now succeed to register our callback. take result */
138 sm->handle = asm_handle;
139 sm->state = ASM_STATE_NONE;
140 sm->event = event_type;
144 return MM_ERROR_NONE;
148 _mmplayer_asm_unregister(MMPlayerASM* sm)
150 gint event_type = ASM_EVENT_NONE;
156 MMPLAYER_CHECK_SESSION_INSTANCE(sm);
157 MMPLAYER_CHECK_SESSION_SKIP(sm);
159 /* check if it's running on the media_server */
163 debug_log("mm-player is running on different process. Just faking pid to [%d]. :-p\n", pid);
166 event_type = sm->event;
170 if( ! ASM_unregister_sound( sm->handle, event_type, &errorcode) )
172 debug_error("Unregister sound failed 0x%X\n", errorcode);
173 return MM_ERROR_POLICY_INTERNAL;
176 debug_warning("asm unregistered");
180 return MM_ERROR_NONE;
183 gint _mmplayer_asm_set_state(MMHandleType hplayer, ASM_sound_states_t state, gboolean enable_safety_vol)
185 return MM_ERROR_NONE;
187 gint event_type = ASM_EVENT_NONE;
189 // int vconf_safety_vol_val = 0;
190 ASM_resource_t resource = ASM_RESOURCE_NONE;
191 mm_player_t *player = (mm_player_t *)hplayer;
192 MMPlayerASM* sm = &player->sm;
196 if (player->set_mode.safety_volume)
198 /* get safety volume */
199 if (vconf_get_int(VCONFKEY_SOUND_ENABLE_SAFETY_VOL, &vconf_safety_vol_val))
201 debug_error ("failed to get safety volume");
204 if (enable_safety_vol)
206 vconf_safety_vol_val = vconf_safety_vol_val | VCONFKEY_SOUND_SAFETY_VOL_FW_MMPLAYER;
210 vconf_safety_vol_val = vconf_safety_vol_val & ~VCONFKEY_SOUND_SAFETY_VOL_FW_MMPLAYER;
213 /* set safety volume */
214 if (vconf_set_int(VCONFKEY_SOUND_ENABLE_SAFETY_VOL, vconf_safety_vol_val))
216 debug_error ("failed to set safety volume");
218 debug_log("safety vol : %d(0:false, 1:true), current result of vconf val : 0x%x", enable_safety_vol, vconf_safety_vol_val);
221 MMPLAYER_CHECK_SESSION_INSTANCE(sm);
222 MMPLAYER_CHECK_SESSION_SKIP(sm);
224 /* check if it's running on the media_server */
228 debug_log("mm-player is running on different process. Just faking pid to [%d]. :-p\n", pid);
231 /* in case of stop, it should be stop first and post interrupt message to application */
232 if ( !sm->by_asm_cb || state == ASM_STATE_STOP)//|| sm->state == ASM_STATE_PLAYING )
235 event_type = sm->event;
236 resource = sm->resource;
238 /* check if there is video */
239 /* NOTE: resource can be set as NONE when it's not occupied or unknown resource is used. */
240 if(ASM_STATE_PLAYING == state || ASM_STATE_PAUSE == state || ASM_STATE_WAITING == state)
242 int surface_type = 0;
243 mm_attrs_get_int_by_name (player->attrs, "display_surface_type", &surface_type);
244 debug_log("surface type = %d", surface_type);
246 if (player->pipeline && player->pipeline->videobin)
248 if(surface_type == MM_DISPLAY_SURFACE_X)
250 resource = ASM_RESOURCE_VIDEO_OVERLAY | ASM_RESOURCE_HW_DECODER;
252 else if (surface_type == MM_DISPLAY_SURFACE_EVAS)
254 resource = ASM_RESOURCE_HW_DECODER;
258 if( __mmplayer_is_streaming (player))
259 resource = resource | ASM_RESOURCE_STREAMING;
262 sm->keep_last_pos = FALSE;
265 if( ((sm->state != state) || (sm->resource != resource)) && ! ASM_set_sound_state( sm->handle, event_type, state, resource, &ret) )
267 gint retval = MM_ERROR_POLICY_INTERNAL;
269 debug_error("Set state to [%d] failed 0x%X\n", state, ret);
272 case ERR_ASM_POLICY_CANNOT_PLAY:
273 case ERR_ASM_POLICY_CANNOT_PLAY_BY_CALL:
274 case ERR_ASM_POLICY_CANNOT_PLAY_BY_ALARM:
275 retval = MM_ERROR_POLICY_BLOCKED;
278 retval = MM_ERROR_POLICY_INTERNAL;
287 sm->by_asm_cb = FALSE;
292 /* waiting to be changed because callback can be called */
293 if (ASM_STATE_STOP == state)
295 ASM_sound_states_t session_state;
296 ASM_get_sound_state(sm->handle, event_type, &session_state, NULL);
299 debug_error("ASM state changed to [%s]", MMPLAYER_ASM_STATE_GET_NAME(state));
301 return MM_ERROR_NONE;
304 static ASM_sound_events_t
305 __mmplayer_asm_get_event_type(gint type)
307 gint event_type = ASM_EVENT_NONE;
309 /* interpret session type */
312 case MM_SESSION_TYPE_CALL:
313 event_type = ASM_EVENT_CALL;
316 case MM_SESSION_TYPE_VIDEOCALL:
317 event_type = ASM_EVENT_VIDEOCALL;
320 case MM_SESSION_TYPE_VOIP:
321 event_type = ASM_EVENT_VOIP;
324 case MM_SESSION_TYPE_MEDIA:
325 // case MM_SESSION_TYPE_MEDIA_RECORD:
326 event_type = ASM_EVENT_MEDIA_MMPLAYER;
329 case MM_SESSION_TYPE_NOTIFY:
330 event_type = ASM_EVENT_NOTIFY;
333 case MM_SESSION_TYPE_ALARM:
334 event_type = ASM_EVENT_ALARM;
337 case MM_SESSION_TYPE_EMERGENCY:
338 event_type = ASM_EVENT_EMERGENCY;
341 case MM_SESSION_TYPE_RECORD_VIDEO:
342 case MM_SESSION_TYPE_RECORD_AUDIO:
343 event_type = ASM_EVENT_MEDIA_MMPLAYER;
348 debug_msg("unexpected case!\n");
349 event_type = ASM_EVENT_MEDIA_MMPLAYER;
357 _mmplayer_asm_ignore_session(MMHandleType hplayer)
359 mm_player_t *player = (mm_player_t *)hplayer;
363 return_val_if_fail (player, MM_ERROR_PLAYER_NOT_INITIALIZED);
366 if (player->state != MM_PLAYER_STATE_NULL)
368 debug_log("invalid state to make session mix");
369 return MM_ERROR_PLAYER_INVALID_STATE;
372 if (player->sm.skip_session == FALSE && player->sm.handle)
376 if (!ASM_unregister_sound(player->sm.handle, player->sm.event, &error_code))
378 debug_error("Unregister sound failed 0x%X", error_code);
379 return MM_ERROR_POLICY_INTERNAL;
381 player->sm.skip_session = TRUE;
382 player->sm.handle = 0;
384 debug_log("session skip enabled");
389 return MM_ERROR_NONE;