4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Seungbae Shin <seungbae.shin@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.
22 #include <sys/types.h>
31 #include <vconf-keys.h>
35 #include "../include/mm_sound_private.h"
36 #include "../include/mm_sound.h"
37 #include "../include/mm_sound_common.h"
38 #include "../include/mm_sound_utils.h"
40 static mm_sound_route g_valid_route[] = {
41 MM_SOUND_ROUTE_OUT_SPEAKER, MM_SOUND_ROUTE_OUT_RECEIVER, MM_SOUND_ROUTE_OUT_WIRED_ACCESSORY, MM_SOUND_ROUTE_OUT_BLUETOOTH_SCO, MM_SOUND_ROUTE_OUT_BLUETOOTH_A2DP,
42 MM_SOUND_ROUTE_OUT_DOCK, MM_SOUND_ROUTE_OUT_HDMI, MM_SOUND_ROUTE_OUT_MIRRORING, MM_SOUND_ROUTE_OUT_USB_AUDIO, MM_SOUND_ROUTE_OUT_MULTIMEDIA_DOCK,
43 MM_SOUND_ROUTE_IN_MIC, MM_SOUND_ROUTE_IN_WIRED_ACCESSORY, MM_SOUND_ROUTE_IN_MIC_OUT_RECEIVER,
44 MM_SOUND_ROUTE_IN_MIC_OUT_SPEAKER, MM_SOUND_ROUTE_IN_MIC_OUT_HEADPHONE,
45 MM_SOUND_ROUTE_INOUT_HEADSET, MM_SOUND_ROUTE_INOUT_BLUETOOTH
48 #define MM_SOUND_DEFAULT_VOLUME_SYSTEM 9
49 #define MM_SOUND_DEFAULT_VOLUME_NOTIFICATION 11
50 #define MM_SOUND_DEFAULT_VOLUME_ALARAM 7
51 #define MM_SOUND_DEFAULT_VOLUME_RINGTONE 11
52 #define MM_SOUND_DEFAULT_VOLUME_MEDIA 7
53 #define MM_SOUND_DEFAULT_VOLUME_CALL 4
54 #define MM_SOUND_DEFAULT_VOLUME_VOIP 4
55 #define MM_SOUND_DEFAULT_VOLUME_VOICE 7
56 #define MM_SOUND_DEFAULT_VOLUME_ANDROID 0
58 static char *g_volume_vconf[VOLUME_TYPE_MAX] = {
59 VCONF_KEY_VOLUME_TYPE_SYSTEM, /* VOLUME_TYPE_SYSTEM */
60 VCONF_KEY_VOLUME_TYPE_NOTIFICATION, /* VOLUME_TYPE_NOTIFICATION */
61 VCONF_KEY_VOLUME_TYPE_ALARM, /* VOLUME_TYPE_ALARM */
62 VCONF_KEY_VOLUME_TYPE_RINGTONE, /* VOLUME_TYPE_RINGTONE */
63 VCONF_KEY_VOLUME_TYPE_MEDIA, /* VOLUME_TYPE_MEDIA */
64 VCONF_KEY_VOLUME_TYPE_CALL, /* VOLUME_TYPE_CALL */
65 VCONF_KEY_VOLUME_TYPE_VOIP, /* VOLUME_TYPE_VOIP */
66 VCONF_KEY_VOLUME_TYPE_VOICE, /* VOLUME_TYPE_VOICE */
67 VCONF_KEY_VOLUME_TYPE_ANDROID /* VOLUME_TYPE_FIXED */
69 static char *g_volume_str[VOLUME_TYPE_MAX] = {
82 int _mm_sound_get_valid_route_list(mm_sound_route **route_list)
84 *route_list = g_valid_route;
86 return (int)(sizeof(g_valid_route) / sizeof(mm_sound_route));
90 bool _mm_sound_is_route_valid(mm_sound_route route)
92 mm_sound_route *route_list = 0;
94 int route_list_count = 0;
96 route_list_count = _mm_sound_get_valid_route_list(&route_list);
97 for (route_index = 0; route_index < route_list_count; route_index++) {
98 if (route_list[route_index] == route)
106 void _mm_sound_get_devices_from_route(mm_sound_route route, mm_sound_device_in *device_in, mm_sound_device_out *device_out)
108 if (device_in && device_out) {
109 *device_in = route & 0x00FF;
110 *device_out = route & 0xFFF00;
115 bool _mm_sound_check_hibernation (const char *path)
119 debug_error ("Path is null\n");
123 fd = open (path, O_RDONLY | O_CREAT, 0644);
125 debug_log ("Open [%s] success!!\n", path);
127 debug_error ("Can't create [%s] with errno [%d]\n", path, errno);
136 int _mm_sound_volume_add_callback(volume_type_t type, void *func, void* user_data)
138 if (vconf_notify_key_changed(g_volume_vconf[type], func, user_data)) {
139 debug_error ("vconf_notify_key_changed failed..\n");
140 return MM_ERROR_SOUND_INTERNAL;
143 return MM_ERROR_NONE;
147 int _mm_sound_volume_remove_callback(volume_type_t type, void *func)
149 if (vconf_ignore_key_changed(g_volume_vconf[type], func)) {
150 debug_error ("vconf_ignore_key_changed failed..\n");
151 return MM_ERROR_SOUND_INTERNAL;
154 return MM_ERROR_NONE;
158 int _mm_sound_muteall_add_callback(void *func)
160 if (vconf_notify_key_changed(VCONF_KEY_MUTE_ALL, func, NULL)) {
161 debug_error ("vconf_notify_key_changed failed..\n");
162 return MM_ERROR_SOUND_INTERNAL;
165 return MM_ERROR_NONE;
169 int _mm_sound_muteall_remove_callback(void *func)
171 if (vconf_ignore_key_changed(VCONF_KEY_MUTE_ALL, func)) {
172 debug_error ("vconf_ignore_key_changed failed..\n");
173 return MM_ERROR_SOUND_INTERNAL;
176 return MM_ERROR_NONE;
180 int _mm_sound_volume_get_value_by_type(volume_type_t type, unsigned int *value)
182 int ret = MM_ERROR_NONE;
185 /* Get volume value from VCONF */
186 if (vconf_get_int(g_volume_vconf[type], &vconf_value)) {
187 debug_error ("vconf_get_int(%s) failed..\n", g_volume_vconf[type]);
188 return MM_ERROR_SOUND_INTERNAL;
191 *value = vconf_value;
192 if (ret == MM_ERROR_NONE)
193 debug_log("volume_get_value %s %d", g_volume_str[type], *value);
199 int _mm_sound_volume_set_value_by_type(volume_type_t type, unsigned int value)
201 int ret = MM_ERROR_NONE;
205 debug_log("volume_set_value %s %d", g_volume_str[type], value);
207 /* Set volume value to VCONF */
208 if ((ret = vconf_set_int(g_volume_vconf[type], vconf_value)) != 0) {
209 debug_error ("vconf_set_int(%s) failed..ret[%d]\n", g_volume_vconf[type], ret);
210 if (ret == -EPERM || ret == -EACCES)
211 return MM_ERROR_SOUND_PERMISSION_DENIED;
213 return MM_ERROR_SOUND_INTERNAL;
219 int _mm_sound_volume_set_balance(float balance)
221 /* Set balance value to VCONF */
222 if (vconf_set_dbl(VCONF_KEY_VOLUME_BALANCE, balance)) {
223 debug_error ("vconf_set_dbl(%s) failed..\n", VCONF_KEY_VOLUME_BALANCE);
224 return MM_ERROR_SOUND_INTERNAL;
227 return MM_ERROR_NONE;
231 int _mm_sound_volume_get_balance(float *balance)
233 double balance_value = 0;
235 /* Get balance value from VCONF */
236 if (vconf_get_dbl(VCONF_KEY_VOLUME_BALANCE, &balance_value)) {
237 debug_error ("vconf_get_int(%s) failed..\n", VCONF_KEY_VOLUME_BALANCE);
238 return MM_ERROR_SOUND_INTERNAL;
241 *balance = balance_value;
242 debug_log("balance get value [%s]=[%f]", VCONF_KEY_VOLUME_BALANCE, *balance);
244 return MM_ERROR_NONE;
248 int _mm_sound_set_muteall(int muteall)
250 /* Set muteall value to VCONF */
251 if (vconf_set_int(VCONF_KEY_MUTE_ALL, muteall)) {
252 debug_error ("vconf_set_int(%s) failed..\n", VCONF_KEY_MUTE_ALL);
253 return MM_ERROR_SOUND_INTERNAL;
256 return MM_ERROR_NONE;
260 int _mm_sound_get_muteall(int *muteall)
262 int muteall_value = 0;
264 /* Get muteall value from VCONF */
265 if (vconf_get_int(VCONF_KEY_MUTE_ALL, &muteall_value)) {
266 debug_error ("vconf_get_int(%s) failed..\n", VCONF_KEY_MUTE_ALL);
267 return MM_ERROR_SOUND_INTERNAL;
270 *muteall = muteall_value;
271 debug_log("muteall get value [%s]=[%d]", VCONF_KEY_MUTE_ALL, *muteall);
273 return MM_ERROR_NONE;
277 int __mm_sound_set_stereo_to_mono(int ismono)
279 /* Set ismono value to VCONF */
280 if (vconf_set_int(VCONF_KEY_MONO_AUDIO, ismono)) {
281 debug_error ("vconf_set_int(%s) failed..\n", VCONF_KEY_MONO_AUDIO);
282 return MM_ERROR_SOUND_INTERNAL;
285 return MM_ERROR_NONE;
289 int __mm_sound_get_stereo_to_mono(int *ismono)
291 int ismono_value = 0;
293 /* Get ismono value from VCONF */
294 if (vconf_get_int(VCONF_KEY_MONO_AUDIO, &ismono_value)) {
295 debug_error ("vconf_get_int(%s) failed..\n", VCONF_KEY_MONO_AUDIO);
296 return MM_ERROR_SOUND_INTERNAL;
299 *ismono = ismono_value;
300 debug_log("ismono get value [%s]=[%d]", VCONF_KEY_MONO_AUDIO, *ismono);
302 return MM_ERROR_NONE;
306 int _mm_sound_get_earjack_type (int *type)
308 int earjack_status = 0;
311 debug_error ("invalid parameter!!!");
312 return MM_ERROR_INVALID_ARGUMENT;
315 /* Get actual vconf value */
316 vconf_get_int(VCONFKEY_SYSMAN_EARJACK, &earjack_status);
317 debug_msg ("[%s] get status=[%d]\n", VCONFKEY_SYSMAN_EARJACK, earjack_status);
319 *type = (earjack_status >= 0)? earjack_status : VCONFKEY_SYSMAN_EARJACK_REMOVED;
321 return MM_ERROR_NONE;
325 int _mm_sound_get_dock_type (int *type)
330 debug_error ("invalid parameter!!!");
331 return MM_ERROR_INVALID_ARGUMENT;
334 /* Get actual vconf value */
335 vconf_get_int(VCONFKEY_SYSMAN_CRADLE_STATUS, &dock_status);
336 debug_msg ("[%s] get dock status=[%d]\n", VCONFKEY_SYSMAN_CRADLE_STATUS, dock_status);
340 return MM_ERROR_NONE;
344 bool _mm_sound_is_recording (void)
346 int capture_status = 0;
354 bool _mm_sound_is_mute_policy (void)
356 int setting_sound_status = true;
358 /* If sound is mute mode, force ringtone/notification path to headset */
359 vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &setting_sound_status);
360 debug_log ("[%s] setting_sound_status=%d\n", VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, setting_sound_status);
362 return !setting_sound_status;