2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #define LOG_TAG "TIZEN_N_SOUND_MANGER"
20 #include <sound_manager.h>
22 #include <mm_sound_private.h>
28 #include <mm_session.h>
30 #define MAX_VOLUME_TYPE 5
34 sound_manager_volume_changed_cb user_cb;
35 }_changed_volume_info_s;
39 sound_manager_route_policy_changed_cb user_cb;
40 }_changed_policy_info_s;
45 sound_session_notify_cb user_cb;
46 }_session_notify_info_s;
48 static _changed_volume_info_s g_volume_changed_cb_table;
49 static _changed_policy_info_s g_policy_changed_cb_table;
50 static _session_notify_info_s g_session_notify_cb_table = {0, NULL, NULL };
52 static void __volume_changed_cb(void *user_data)
54 sound_type_e type = (sound_type_e)user_data;
57 sound_manager_get_volume( type, &new_volume);
58 if( g_volume_changed_cb_table.user_cb )
59 (g_volume_changed_cb_table.user_cb)(type, new_volume, g_volume_changed_cb_table.user_data);
62 static void __policy_changed_cb(void *user_data, system_audio_route_t policy){
63 if( g_policy_changed_cb_table.user_cb)
64 g_policy_changed_cb_table.user_cb(policy, g_policy_changed_cb_table.user_data);
67 static void __session_notify_cb(session_msg_t msg, void *user_data){
68 if( g_session_notify_cb_table.user_cb ){
69 g_session_notify_cb_table.user_cb(msg, g_session_notify_cb_table.user_data);
74 static int __convert_sound_manager_error_code(const char *func, int code){
75 int ret = SOUND_MANAGER_ERROR_NONE;
76 char *errorstr = NULL;
80 case SOUND_MANAGER_ERROR_INVALID_PARAMETER:
81 ret = SOUND_MANAGER_ERROR_INVALID_PARAMETER;
82 errorstr = "INVALID_PARAMETER";
85 ret = SOUND_MANAGER_ERROR_NONE;
86 errorstr = "ERROR_NONE";
88 case MM_ERROR_INVALID_ARGUMENT:
89 case MM_ERROR_SOUND_INVALID_POINTER:
90 ret = SOUND_MANAGER_ERROR_INVALID_PARAMETER;
91 errorstr = "INVALID_PARAMETER";
93 case MM_ERROR_SOUND_INTERNAL:
94 ret = SOUND_MANAGER_ERROR_INVALID_OPERATION;
95 errorstr = "INVALID_OPERATION" ;
97 case MM_ERROR_SOUND_VOLUME_NO_INSTANCE:
98 case MM_ERROR_SOUND_VOLUME_CAPTURE_ONLY:
99 ret = SOUND_MANAGER_ERROR_NO_PLAYING_SOUND;
100 errorstr = "NO_PLAYING_SOUND" ;
103 LOGE( "[%s] %s(0x%08x) : core frameworks error code(0x%08x)",func, errorstr, ret, code);
110 int sound_manager_get_max_volume(sound_type_e type, int *max)
114 return __convert_sound_manager_error_code(__func__, SOUND_MANAGER_ERROR_INVALID_PARAMETER);
116 if( type > MAX_VOLUME_TYPE || type < 0 )
117 return __convert_sound_manager_error_code(__func__, SOUND_MANAGER_ERROR_INVALID_PARAMETER);
118 int ret = mm_sound_volume_get_step(type, &volume);
121 *max = volume -1; // actual volume step can be max step - 1
123 return __convert_sound_manager_error_code(__func__, ret);
126 int sound_manager_set_volume(sound_type_e type, int volume)
128 if( type > MAX_VOLUME_TYPE || type < 0 )
129 return __convert_sound_manager_error_code(__func__, SOUND_MANAGER_ERROR_INVALID_PARAMETER);
131 return __convert_sound_manager_error_code(__func__, SOUND_MANAGER_ERROR_INVALID_PARAMETER);
133 int ret = mm_sound_volume_set_value(type, volume);
135 return __convert_sound_manager_error_code(__func__, ret);
138 int sound_manager_get_volume(sound_type_e type, int *volume)
140 unsigned int uvolume;
141 if( type > MAX_VOLUME_TYPE || type < 0 )
142 return __convert_sound_manager_error_code(__func__, SOUND_MANAGER_ERROR_INVALID_PARAMETER);
144 return __convert_sound_manager_error_code(__func__, SOUND_MANAGER_ERROR_INVALID_PARAMETER);
145 int ret = mm_sound_volume_get_value(type, &uvolume);
150 return __convert_sound_manager_error_code(__func__, ret);
153 int sound_manager_set_route_policy (sound_route_policy_e route)
155 if( route < 0 || route > SOUND_ROUTE_HANDSET_ONLY)
156 return __convert_sound_manager_error_code(__func__, SOUND_MANAGER_ERROR_INVALID_PARAMETER);
159 ret = mm_sound_route_set_system_policy(route);
161 return __convert_sound_manager_error_code(__func__, ret);
164 int sound_manager_get_route_policy (sound_route_policy_e *route)
167 return __convert_sound_manager_error_code(__func__, SOUND_MANAGER_ERROR_INVALID_PARAMETER);
169 ret= mm_sound_route_get_system_policy((system_audio_route_t *)route);
171 return __convert_sound_manager_error_code(__func__, ret);
174 int sound_manager_get_current_sound_type(sound_type_e *type)
177 return __convert_sound_manager_error_code(__func__, SOUND_MANAGER_ERROR_INVALID_PARAMETER);
179 ret = mm_sound_volume_get_current_playing_type((volume_type_t *)type);
181 return __convert_sound_manager_error_code(__func__, ret);
184 int sound_manager_get_current_sound_device(sound_device_e *device)
187 return __convert_sound_manager_error_code(__func__, SOUND_MANAGER_ERROR_INVALID_PARAMETER);
189 ret = mm_sound_route_get_playing_device((system_audio_route_device_t*)device);
190 return __convert_sound_manager_error_code(__func__, ret);
193 int sound_manager_set_volume_changed_cb(sound_manager_volume_changed_cb callback, void* user_data)
195 if( callback == NULL )
196 return __convert_sound_manager_error_code(__func__, SOUND_MANAGER_ERROR_INVALID_PARAMETER);
198 g_volume_changed_cb_table.user_cb = callback;
199 g_volume_changed_cb_table.user_data = user_data;
200 for(i = 0 ; i <= MAX_VOLUME_TYPE ; i++)
202 mm_sound_volume_add_callback( i , __volume_changed_cb ,(void*) i);
207 void sound_manager_unset_volume_changed_cb(void)
210 for(i = 0 ; i <= MAX_VOLUME_TYPE ; i++)
212 mm_sound_volume_remove_callback( i );
214 g_volume_changed_cb_table.user_cb = NULL;
215 g_volume_changed_cb_table.user_data = NULL;
218 int sound_manager_set_route_policy_changed_cb(sound_manager_route_policy_changed_cb callback, void* user_data)
220 if( callback == NULL)
221 return __convert_sound_manager_error_code(__func__, SOUND_MANAGER_ERROR_INVALID_PARAMETER);
222 g_policy_changed_cb_table.user_cb = callback;
223 g_policy_changed_cb_table.user_data = user_data;
224 mm_sound_route_add_change_callback(__policy_changed_cb, user_data);
228 void sound_manager_unset_route_policy_changed_cb(void)
230 mm_sound_route_remove_change_callback();
231 g_policy_changed_cb_table.user_cb = NULL;
232 g_policy_changed_cb_table.user_data = NULL;
235 int sound_manager_get_a2dp_status(bool *connected , char** bt_name){
238 ret = mm_sound_route_get_a2dp_status(&connect , bt_name );
240 *connected = connect;
241 return __convert_sound_manager_error_code(__func__, ret);
246 int sound_manager_set_session_type(sound_session_type_e type){
248 if( type < 0 || type > SOUND_SESSION_TYPE_EXCLUSIVE )
249 return __convert_sound_manager_error_code(__func__, SOUND_MANAGER_ERROR_INVALID_PARAMETER);
251 if( g_session_notify_cb_table.is_registered ){
253 g_session_notify_cb_table.is_registered = 0;
256 ret = mm_session_init_ex( type , __session_notify_cb, NULL);
258 g_session_notify_cb_table.is_registered = 1;
260 return __convert_sound_manager_error_code(__func__, ret);
263 int sound_manager_set_session_notify_cb(sound_session_notify_cb callback , void *user_data){
265 if( callback == NULL)
266 return __convert_sound_manager_error_code(__func__, SOUND_MANAGER_ERROR_INVALID_PARAMETER);
269 if( g_session_notify_cb_table.is_registered ==0 ){
270 ret = mm_session_init_ex( SOUND_SESSION_TYPE_SHARE /*default*/ , __session_notify_cb, NULL);
272 return __convert_sound_manager_error_code(__func__, ret);
273 g_session_notify_cb_table.is_registered = 1;
276 g_session_notify_cb_table.user_cb = callback ;
277 g_session_notify_cb_table.user_data = user_data;
278 return SOUND_MANAGER_ERROR_NONE;
281 void sound_manager_unset_session_notify_cb(void){
282 g_session_notify_cb_table.user_cb = NULL;
283 g_session_notify_cb_table.user_data = NULL;
287 int sound_manager_set_volume_key_type(volume_key_type_e type){
288 if( type < VOLUME_KEY_TYPE_NONE || type > VOLUME_KEY_TYPE_CALL )
289 return __convert_sound_manager_error_code(__func__, SOUND_MANAGER_ERROR_INVALID_PARAMETER);
291 if( type == VOLUME_KEY_TYPE_NONE )
292 ret = mm_sound_volume_primary_type_clear();
294 ret = mm_sound_volume_primary_type_set(type);
296 return __convert_sound_manager_error_code(__func__, ret);