4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: JongHyuk Choi <jhchoi.choi@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_radio_asm.h"
26 static ASM_sound_events_t __mmradio_asm_get_event_type(int type);
28 int mmradio_asm_register(MMRadioASM* sm, ASM_sound_cb_t callback, void* param)
30 /* read mm-session type */
31 int sessionType = MM_SESSION_TYPE_SHARE;
32 int errorcode = MM_ERROR_NONE;
34 int event_type = ASM_EVENT_NONE;
41 debug_error("invalid session handle\n");
42 return MM_ERROR_RADIO_NOT_INITIALIZED;
45 /* read session type */
46 // errorcode = __MMSessionUtilReadType(&sessionType);
47 errorcode = _mm_session_util_read_type(-1, &sessionType);
50 debug_warning("Read MMSession Type failed. use default \"exclusive\" type\n");
51 sessionType = MM_SESSION_TYPE_EXCLUSIVE;
54 errorcode = mm_session_init(sessionType);
57 debug_critical("mm_session_init() failed\n");
62 /* check if it's CALL */
63 if ( sessionType == MM_SESSION_TYPE_CALL || sessionType == MM_SESSION_TYPE_VIDEOCALL)
65 debug_log("session type is VOICE or VIDEO CALL (%d)\n", sessionType);
69 /* interpret session type */
70 event_type = __mmradio_asm_get_event_type(sessionType);
72 /* check if it's running on the media_server */
76 debug_log("mm-radio is running on different process. Just faking pid to [%d]. :-p\n", pid);
80 debug_log("no pid has assigned. using default(current) context\n");
83 /* register audio-session-manager callback */
84 if( ! ASM_register_sound(pid, &asm_handle, event_type, ASM_STATE_NONE, callback, (void*)param, ASM_RESOURCE_NONE, &errorcode))
86 debug_critical("ASM_register_sound() failed\n");
90 /* now succeded to register our callback. take result */
91 sm->handle = asm_handle;
92 sm->state = ASM_STATE_NONE;
97 int mmradio_asm_deregister(MMRadioASM* sm)
99 int sessionType = MM_SESSION_TYPE_SHARE;
100 int event_type = ASM_EVENT_NONE;
105 debug_error("invalid session handle\n");
106 return MM_ERROR_RADIO_NOT_INITIALIZED;
109 /* read session type */
110 // errorcode = __MMSessionUtilReadType(&sessionType);
111 errorcode = _mm_session_util_read_type(-1, &sessionType);
114 debug_error("MMSessionReadType Fail %s\n",__func__);
115 return MM_ERROR_POLICY_INTERNAL;
118 /* check if it's CALL */
119 if ( sessionType == MM_SESSION_TYPE_CALL || sessionType == MM_SESSION_TYPE_VIDEOCALL)
121 debug_log("session type is VOICE or VIDEO CALL (%d)\n", sessionType);
122 return MM_ERROR_NONE;
125 /* interpret session type */
126 event_type = __mmradio_asm_get_event_type(sessionType);
128 if( ! ASM_unregister_sound( sm->handle, event_type, &errorcode) )
130 debug_error("Unregister sound failed 0x%X\n", errorcode);
131 return MM_ERROR_POLICY_INTERNAL;
134 return MM_ERROR_NONE;
137 int mmradio_asm_set_state(MMRadioASM* sm, ASM_sound_states_t state, ASM_resource_t resource)
139 int sessionType = MM_SESSION_TYPE_SHARE;
140 int event_type = ASM_EVENT_NONE;
145 debug_error("invalid session handle\n");
146 return MM_ERROR_RADIO_NOT_INITIALIZED;
149 /* read session type */
150 // errorcode = __MMSessionUtilReadType(&sessionType);
151 errorcode = _mm_session_util_read_type(-1, &sessionType);
154 debug_error("MMSessionReadType Fail\n");
155 return MM_ERROR_POLICY_INTERNAL;
158 /* check if it's CALL */
159 if ( sessionType == MM_SESSION_TYPE_CALL || sessionType == MM_SESSION_TYPE_VIDEOCALL )
161 debug_log("session type is VOICE or VIDEO CALL (%d)\n", sessionType);
162 return MM_ERROR_NONE;
165 if ( sm->by_asm_cb == MMRADIO_ASM_CB_NONE ) //|| sm->state == ASM_STATE_PLAYING )
169 event_type = __mmradio_asm_get_event_type(sessionType);
171 if( ! ASM_set_sound_state( sm->handle, event_type, state, resource, &ret) )
173 debug_error("set ASM state to [%d] failed 0x%X\n", state, ret);
174 return MM_ERROR_POLICY_BLOCKED;
179 else // by asm callback
181 sm->by_asm_cb = MMRADIO_ASM_CB_NONE;
185 return MM_ERROR_NONE;
189 ASM_sound_events_t __mmradio_asm_get_event_type(int type)
191 int event_type = ASM_EVENT_NONE;
193 /* interpret session type */
196 case MM_SESSION_TYPE_SHARE:
197 event_type = ASM_EVENT_SHARE_FMRADIO;
200 case MM_SESSION_TYPE_EXCLUSIVE:
201 event_type = ASM_EVENT_EXCLUSIVE_FMRADIO;
204 case MM_SESSION_TYPE_ALARM:
205 event_type = ASM_EVENT_ALARM;
208 case MM_SESSION_TYPE_NOTIFY:
209 case MM_SESSION_TYPE_CALL:
210 case MM_SESSION_TYPE_VIDEOCALL:
212 debug_critical("unexpected case! (%d)\n", type);