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>, YoungHwan An <younghwan_.an@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
24 #include "mm_player_priv.h"
25 #include "mm_player_asm.h"
27 #define MMPLAYER_CHECK_SESSION_SKIP(x_player_asm) \
30 if (x_player_asm->skip_session == TRUE) \
32 debug_log("skip session"); \
33 return MM_ERROR_NONE; \
37 #define MMPLAYER_CHECK_SESSION_INSTANCE(x_player_asm) \
42 debug_log("no session instance");\
43 return MM_ERROR_SOUND_NOT_INITIALIZED; \
47 static ASM_sound_events_t __mmplayer_asm_get_event_type(gint type);
50 _mmplayer_asm_register(MMPlayerASM* sm, ASM_sound_cb_t callback, void* param)
52 /* read mm-session type */
53 gint sessionType = MM_SESSION_TYPE_SHARE;
54 gint errorcode = MM_ERROR_NONE;
56 gint event_type = ASM_EVENT_NONE;
60 MMPLAYER_CHECK_SESSION_INSTANCE(sm);
61 MMPLAYER_CHECK_SESSION_SKIP(sm);
63 /* check if it's running on the media_server */
67 debug_log("mm-player is running on different process. Just faking pid to [%d]. :-p\n", pid);
71 debug_log("no pid has assigned. using default(current) context\n");
74 /* read session type */
75 errorcode = _mm_session_util_read_type(pid, &sessionType);
78 debug_warning("Read MMSession Type failed. use default \"share\" type\n");
79 sessionType = MM_SESSION_TYPE_SHARE;
82 errorcode = mm_session_init(sessionType);
85 debug_critical("mm_session_init() failed\n");
90 /* check if it's CALL */
91 if ( sessionType == MM_SESSION_TYPE_CALL )
93 debug_log("session type is CALL\n");
94 sm->event = ASM_EVENT_CALL;
97 else if ( sessionType == MM_SESSION_TYPE_VIDEOCALL )
99 debug_log("session type is VIDEOCALL\n");
100 sm->event = ASM_EVENT_VIDEOCALL;
101 return MM_ERROR_NONE;
104 /* interpret session type */
105 event_type = __mmplayer_asm_get_event_type(sessionType);
107 /* register audio-session-manager callback */
108 if( ! ASM_register_sound(pid, &asm_handle, event_type, ASM_STATE_NONE, callback, (void*)param, ASM_RESOURCE_NONE, &errorcode))
110 debug_critical("ASM_register_sound() failed\n");
114 /* now succeed to register our callback. take result */
115 sm->handle = asm_handle;
116 sm->state = ASM_STATE_NONE;
117 sm->event = event_type;
119 return MM_ERROR_NONE;
123 _mmplayer_asm_unregister(MMPlayerASM* sm)
125 gint event_type = ASM_EVENT_NONE;
129 MMPLAYER_CHECK_SESSION_INSTANCE(sm);
130 MMPLAYER_CHECK_SESSION_SKIP(sm);
132 /* check if it's running on the media_server */
136 debug_log("mm-player is running on different process. Just faking pid to [%d]. :-p\n", pid);
140 debug_log("no pid has assigned. using default(current) context\n");
143 /* check if it's CALL */
144 if(sm->event == ASM_EVENT_CALL || sm->event == ASM_EVENT_VIDEOCALL)
146 debug_log("session type is VOICE or VIDEO CALL (%d)\n", sm->event);
147 return MM_ERROR_NONE;
149 event_type = sm->event;
151 if( ! ASM_unregister_sound( sm->handle, event_type, &errorcode) )
153 debug_error("Unregister sound failed 0x%X\n", errorcode);
154 return MM_ERROR_POLICY_INTERNAL;
157 return MM_ERROR_NONE;
160 gint _mmplayer_asm_set_state(MMHandleType hplayer, ASM_sound_states_t state)
162 gint event_type = ASM_EVENT_NONE;
164 ASM_resource_t resource = ASM_RESOURCE_NONE;
165 mm_player_t *player = (mm_player_t *)hplayer;
166 MMPlayerASM* sm = &player->sm;
168 MMPLAYER_CHECK_SESSION_INSTANCE(sm);
169 MMPLAYER_CHECK_SESSION_SKIP(sm);
171 /* check if it's running on the media_server */
175 debug_log("mm-player is running on different process. Just faking pid to [%d]. :-p\n", pid);
179 debug_log("no pid has assigned. using default(current) context\n");
182 /* check if it's CALL */
183 if(sm->event == ASM_EVENT_CALL || sm->event == ASM_EVENT_VIDEOCALL)
185 debug_log("session type is VOICE or VIDEO CALL (%d)\n", sm->event);
186 return MM_ERROR_NONE;
190 if ( ! sm->by_asm_cb )//|| sm->state == ASM_STATE_PLAYING )
193 event_type = sm->event;
195 /* check if there is video */
196 /* NOTE: resource can be set as NONE when it's not occupied or unknown resource is used. */
197 if(ASM_STATE_PLAYING == state || ASM_STATE_PAUSE == state)
199 if(player->pipeline && player->pipeline->videobin)
200 resource = ASM_RESOURCE_VIDEO_OVERLAY | ASM_RESOURCE_HW_DECODER;
203 if( ! ASM_set_sound_state( sm->handle, event_type, state, resource, &ret) )
205 debug_error("Set state to [%d] failed 0x%X\n", state, ret);
206 return MM_ERROR_POLICY_BLOCKED;
217 return MM_ERROR_NONE;
220 static ASM_sound_events_t
221 __mmplayer_asm_get_event_type(gint type)
223 gint event_type = ASM_EVENT_NONE;
225 /* interpret session type */
228 case MM_SESSION_TYPE_SHARE:
229 event_type = ASM_EVENT_SHARE_MMPLAYER;
232 case MM_SESSION_TYPE_EXCLUSIVE:
233 event_type = ASM_EVENT_EXCLUSIVE_MMPLAYER;
236 case MM_SESSION_TYPE_NOTIFY:
237 event_type = ASM_EVENT_NOTIFY;
240 case MM_SESSION_TYPE_ALARM:
241 event_type = ASM_EVENT_ALARM;
244 case MM_SESSION_TYPE_EMERGENCY:
245 event_type = ASM_EVENT_EMERGENCY;
249 debug_critical("unexpected case!\n");
250 event_type = ASM_EVENT_SHARE_MMPLAYER;
258 _mmplayer_asm_ignore_session(MMHandleType hplayer)
260 mm_player_t *player = (mm_player_t *)hplayer;
264 return_val_if_fail (player, MM_ERROR_PLAYER_NOT_INITIALIZED);
267 if (player->state != MM_PLAYER_STATE_NULL)
269 debug_log("invalid state to make session mix");
270 return MM_ERROR_PLAYER_INVALID_STATE;
273 if (player->sm.skip_session == FALSE && player->sm.handle)
277 if (!ASM_unregister_sound(player->sm.handle, player->sm.event, &error_code))
279 debug_error("Unregister sound failed 0x%X", error_code);
280 return MM_ERROR_POLICY_INTERNAL;
282 player->sm.skip_session = TRUE;
283 player->sm.handle = 0;
285 debug_log("session skip enabled");
290 return MM_ERROR_NONE;