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 static ASM_sound_events_t __mmplayer_asm_get_event_type(gint type);
30 _mmplayer_asm_register(MMPlayerASM* sm, ASM_sound_cb_t callback, void* param)
32 /* read mm-session type */
33 gint sessionType = MM_SESSION_TYPE_SHARE;
34 gint errorcode = MM_ERROR_NONE;
36 gint event_type = ASM_EVENT_NONE;
43 debug_error("invalid session handle\n");
44 return MM_ERROR_PLAYER_NOT_INITIALIZED;
47 /* check if it's running on the media_server */
51 debug_log("mm-player is running on different process. Just faking pid to [%d]. :-p\n", pid);
55 debug_log("no pid has assigned. using default(current) context\n");
58 /* read session type */
59 errorcode = _mm_session_util_read_type(pid, &sessionType);
62 debug_warning("Read MMSession Type failed. use default \"share\" type\n");
63 sessionType = MM_SESSION_TYPE_SHARE;
66 errorcode = mm_session_init(sessionType);
69 debug_critical("mm_session_init() failed\n");
74 /* check if it's CALL */
75 if ( sessionType == MM_SESSION_TYPE_CALL )
77 debug_log("session type is CALL\n");
78 sm->event = ASM_EVENT_CALL;
81 else if ( sessionType == MM_SESSION_TYPE_VIDEOCALL )
83 debug_log("session type is VIDEOCALL\n");
84 sm->event = ASM_EVENT_VIDEOCALL;
88 /* interpret session type */
89 event_type = __mmplayer_asm_get_event_type(sessionType);
93 /* register audio-session-manager callback */
94 if( ! ASM_register_sound(pid, &asm_handle, event_type, ASM_STATE_NONE, callback, (void*)param, ASM_RESOURCE_NONE, &errorcode))
96 debug_critical("ASM_register_sound() failed\n");
100 /* now succeed to register our callback. take result */
101 sm->handle = asm_handle;
102 sm->state = ASM_STATE_NONE;
103 sm->event = event_type;
105 return MM_ERROR_NONE;
109 _mmplayer_asm_deregister(MMPlayerASM* sm)
111 gint event_type = ASM_EVENT_NONE;
117 debug_error("invalid session handle\n");
118 return MM_ERROR_PLAYER_NOT_INITIALIZED;
121 /* check if it's running on the media_server */
125 debug_log("mm-player is running on different process. Just faking pid to [%d]. :-p\n", pid);
129 debug_log("no pid has assigned. using default(current) context\n");
132 /* check if it's CALL */
133 if(sm->event == ASM_EVENT_CALL || sm->event == ASM_EVENT_VIDEOCALL)
135 debug_log("session type is VOICE or VIDEO CALL (%d)\n", sm->event);
136 return MM_ERROR_NONE;
138 event_type = sm->event;
140 if( ! ASM_unregister_sound( sm->handle, event_type, &errorcode) )
142 debug_error("Unregister sound failed 0x%X\n", errorcode);
143 return MM_ERROR_POLICY_INTERNAL;
146 return MM_ERROR_NONE;
149 gint _mmplayer_asm_set_state(MMHandleType hplayer, ASM_sound_states_t state)
151 gint event_type = ASM_EVENT_NONE;
153 ASM_resource_t resource = ASM_RESOURCE_NONE;
154 mm_player_t *player = (mm_player_t *)hplayer;
155 MMPlayerASM* sm = &player->sm;
159 debug_error("invalid session handle\n");
160 return MM_ERROR_PLAYER_NOT_INITIALIZED;
163 /* check if it's running on the media_server */
167 debug_log("mm-player is running on different process. Just faking pid to [%d]. :-p\n", pid);
171 debug_log("no pid has assigned. using default(current) context\n");
174 /* check if it's CALL */
175 if(sm->event == ASM_EVENT_CALL || sm->event == ASM_EVENT_VIDEOCALL)
177 debug_log("session type is VOICE or VIDEO CALL (%d)\n", sm->event);
178 return MM_ERROR_NONE;
182 if ( ! sm->by_asm_cb )//|| sm->state == ASM_STATE_PLAYING )
185 event_type = sm->event;
187 /* check if there is video */
188 /* NOTE: resource can be set as NONE when it's not occupied or unknown resource is used. */
189 if(ASM_STATE_PLAYING == state || ASM_STATE_PAUSE == state)
191 if(player->pipeline && player->pipeline->videobin)
192 resource = ASM_RESOURCE_VIDEO_OVERLAY | ASM_RESOURCE_HW_DECODER;
195 if( ! ASM_set_sound_state( sm->handle, event_type, state, resource, &ret) )
197 debug_error("Set state to [%d] failed 0x%X\n", state, ret);
198 return MM_ERROR_POLICY_BLOCKED;
209 return MM_ERROR_NONE;
212 static ASM_sound_events_t
213 __mmplayer_asm_get_event_type(gint type)
215 gint event_type = ASM_EVENT_NONE;
217 /* interpret session type */
220 case MM_SESSION_TYPE_SHARE:
221 event_type = ASM_EVENT_SHARE_MMPLAYER;
224 case MM_SESSION_TYPE_EXCLUSIVE:
225 event_type = ASM_EVENT_EXCLUSIVE_MMPLAYER;
228 case MM_SESSION_TYPE_NOTIFY:
229 event_type = ASM_EVENT_NOTIFY;
232 case MM_SESSION_TYPE_ALARM:
233 event_type = ASM_EVENT_ALARM;
236 case MM_SESSION_TYPE_EMERGENCY:
237 event_type = ASM_EVENT_EMERGENCY;
241 debug_critical("unexpected case!\n");
242 event_type = ASM_EVENT_SHARE_MMPLAYER;