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 = _mm_session_util_read_type(-1, &sessionType);
49 debug_warning("Read MMSession Type failed. use default \"exclusive\" type\n");
50 sessionType = MM_SESSION_TYPE_EXCLUSIVE;
53 errorcode = mm_session_init(sessionType);
56 debug_critical("mm_session_init() failed\n");
61 /* check if it's CALL */
62 if ( sessionType == MM_SESSION_TYPE_CALL || sessionType == MM_SESSION_TYPE_VIDEOCALL)
64 debug_log("session type is VOICE or VIDEO CALL (%d)\n", sessionType);
68 /* interpret session type */
69 event_type = __mmradio_asm_get_event_type(sessionType);
71 /* check if it's running on the media_server */
75 debug_log("mm-radio is running on different process. Just faking pid to [%d]. :-p\n", pid);
79 debug_log("no pid has assigned. using default(current) context\n");
82 /* register audio-session-manager callback */
83 if( ! ASM_register_sound(pid, &asm_handle, event_type, ASM_STATE_NONE, callback, (void*)param, ASM_RESOURCE_NONE, &errorcode))
85 debug_critical("ASM_register_sound() failed\n");
89 /* now succeded to register our callback. take result */
90 sm->handle = asm_handle;
91 sm->state = ASM_STATE_NONE;
96 int mmradio_asm_deregister(MMRadioASM* sm)
98 int sessionType = MM_SESSION_TYPE_SHARE;
99 int event_type = ASM_EVENT_NONE;
104 debug_error("invalid session handle\n");
105 return MM_ERROR_RADIO_NOT_INITIALIZED;
108 /* read session type */
109 errorcode = _mm_session_util_read_type(-1, &sessionType);
112 debug_error("MMSessionReadType Fail %s\n",__func__);
113 return MM_ERROR_POLICY_INTERNAL;
116 /* check if it's CALL */
117 if ( sessionType == MM_SESSION_TYPE_CALL || sessionType == MM_SESSION_TYPE_VIDEOCALL)
119 debug_log("session type is VOICE or VIDEO CALL (%d)\n", sessionType);
120 return MM_ERROR_NONE;
123 /* interpret session type */
124 event_type = __mmradio_asm_get_event_type(sessionType);
126 if( ! ASM_unregister_sound( sm->handle, event_type, &errorcode) )
128 debug_error("Unregister sound failed 0x%X\n", errorcode);
129 return MM_ERROR_POLICY_INTERNAL;
132 return MM_ERROR_NONE;
135 int mmradio_asm_set_state(MMRadioASM* sm, ASM_sound_states_t state, ASM_resource_t resource)
137 int sessionType = MM_SESSION_TYPE_SHARE;
138 int event_type = ASM_EVENT_NONE;
143 debug_error("invalid session handle\n");
144 return MM_ERROR_RADIO_NOT_INITIALIZED;
147 /* read session type */
148 errorcode = _mm_session_util_read_type(-1, &sessionType);
151 debug_error("MMSessionReadType Fail\n");
152 return MM_ERROR_POLICY_INTERNAL;
155 /* check if it's CALL */
156 if ( sessionType == MM_SESSION_TYPE_CALL || sessionType == MM_SESSION_TYPE_VIDEOCALL )
158 debug_log("session type is VOICE or VIDEO CALL (%d)\n", sessionType);
159 return MM_ERROR_NONE;
162 if ( sm->by_asm_cb == MMRADIO_ASM_CB_NONE )
166 event_type = __mmradio_asm_get_event_type(sessionType);
168 if( ! ASM_set_sound_state( sm->handle, event_type, state, resource, &ret) )
170 debug_error("set ASM state to [%d] failed 0x%X\n", state, ret);
171 return MM_ERROR_POLICY_BLOCKED;
176 else // by asm callback
178 sm->by_asm_cb = MMRADIO_ASM_CB_NONE;
182 return MM_ERROR_NONE;
186 ASM_sound_events_t __mmradio_asm_get_event_type(int type)
188 int event_type = ASM_EVENT_NONE;
190 /* interpret session type */
193 case MM_SESSION_TYPE_SHARE:
194 event_type = ASM_EVENT_SHARE_FMRADIO;
197 case MM_SESSION_TYPE_EXCLUSIVE:
198 event_type = ASM_EVENT_EXCLUSIVE_FMRADIO;
201 case MM_SESSION_TYPE_ALARM:
202 event_type = ASM_EVENT_ALARM;
205 case MM_SESSION_TYPE_NOTIFY:
206 case MM_SESSION_TYPE_CALL:
207 case MM_SESSION_TYPE_VIDEOCALL:
209 debug_critical("unexpected case! (%d)\n", type);