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 <avsys-audio.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_WIRED_ACCESSORY, MM_SOUND_ROUTE_OUT_BLUETOOTH,
42 MM_SOUND_ROUTE_OUT_DOCK, MM_SOUND_ROUTE_OUT_HDMI, MM_SOUND_ROUTE_OUT_WFD, MM_SOUND_ROUTE_OUT_USB_AUDIO,
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 5
49 #define MM_SOUND_DEFAULT_VOLUME_NOTIFICATION 7
50 #define MM_SOUND_DEFAULT_VOLUME_ALARAM 6
51 #define MM_SOUND_DEFAULT_VOLUME_RINGTONE 13
52 #define MM_SOUND_DEFAULT_VOLUME_MEDIA 7
53 #define MM_SOUND_DEFAULT_VOLUME_CALL 7
54 #define MM_SOUND_DEFAULT_VOLUME_VOIP 7
55 #define MM_SOUND_DEFAULT_VOLUME_ANDROID 0
56 #define MM_SOUND_DEFAULT_VOLUME_JAVA 11
57 static int g_default_volume[VOLUME_TYPE_MAX] = {
58 MM_SOUND_DEFAULT_VOLUME_SYSTEM,
59 MM_SOUND_DEFAULT_VOLUME_NOTIFICATION,
60 MM_SOUND_DEFAULT_VOLUME_ALARAM,
61 MM_SOUND_DEFAULT_VOLUME_RINGTONE,
62 MM_SOUND_DEFAULT_VOLUME_MEDIA,
63 MM_SOUND_DEFAULT_VOLUME_CALL,
64 MM_SOUND_DEFAULT_VOLUME_VOIP,
65 MM_SOUND_DEFAULT_VOLUME_ANDROID,
66 MM_SOUND_DEFAULT_VOLUME_JAVA,
68 static char *g_volume_vconf[VOLUME_TYPE_MAX] = {
69 VCONF_KEY_VOLUME_TYPE_SYSTEM, /* VOLUME_TYPE_SYSTEM */
70 VCONF_KEY_VOLUME_TYPE_NOTIFICATION, /* VOLUME_TYPE_NOTIFICATION */
71 VCONF_KEY_VOLUME_TYPE_ALARM, /* VOLUME_TYPE_ALARM */
72 VCONF_KEY_VOLUME_TYPE_RINGTONE, /* VOLUME_TYPE_RINGTONE */
73 VCONF_KEY_VOLUME_TYPE_MEDIA, /* VOLUME_TYPE_MEDIA */
74 VCONF_KEY_VOLUME_TYPE_CALL, /* VOLUME_TYPE_CALL */
75 VCONF_KEY_VOLUME_TYPE_VOIP, /* VOLUME_TYPE_VOIP */
76 VCONF_KEY_VOLUME_TYPE_ANDROID, /* VOLUME_TYPE_FIXED */
77 VCONF_KEY_VOLUME_TYPE_JAVA /* VOLUME_TYPE_EXT_JAVA */
79 static char *g_volume_str[VOLUME_TYPE_MAX] = {
92 int _mm_sound_get_valid_route_list(mm_sound_route **route_list)
94 *route_list = g_valid_route;
96 return (int)(sizeof(g_valid_route) / sizeof(mm_sound_route));
100 bool _mm_sound_is_route_valid(mm_sound_route route)
102 mm_sound_route *route_list = 0;
104 int route_list_count = 0;
106 route_list_count = _mm_sound_get_valid_route_list(&route_list);
107 for (route_index = 0; route_index < route_list_count; route_index++) {
108 if (route_list[route_index] == route)
116 void _mm_sound_get_devices_from_route(mm_sound_route route, mm_sound_device_in *device_in, mm_sound_device_out *device_out)
118 if (device_in && device_out) {
119 *device_in = route & 0x00FF;
120 *device_out = route & 0xFFF00;
125 bool _mm_sound_check_hibernation (const char *path)
129 debug_error ("Path is null\n");
133 fd = open (path, O_RDONLY | O_CREAT, 0644);
135 debug_log ("Open [%s] success!!\n", path);
137 debug_error ("Can't create [%s] with errno [%d]\n", path, errno);
146 int _mm_sound_volume_add_callback(volume_type_t type, void *func, void* user_data)
148 if (vconf_notify_key_changed(g_volume_vconf[type], func, user_data)) {
149 debug_error ("vconf_notify_key_changed failed..\n");
150 return MM_ERROR_SOUND_INTERNAL;
153 return MM_ERROR_NONE;
157 int _mm_sound_volume_remove_callback(volume_type_t type, void *func)
159 if (vconf_ignore_key_changed(g_volume_vconf[type], func)) {
160 debug_error ("vconf_ignore_key_changed failed..\n");
161 return MM_ERROR_SOUND_INTERNAL;
164 return MM_ERROR_NONE;
168 int _mm_sound_volume_get_value_by_type(volume_type_t type, unsigned int *value)
172 /* Get volume value from VCONF */
173 if (vconf_get_int(g_volume_vconf[type], &vconf_value)) {
174 debug_error ("vconf_get_int(%s) failed..\n", g_volume_vconf[type]);
175 return MM_ERROR_SOUND_INTERNAL;
178 *value = vconf_value;
179 debug_log("volume_get_value %s %d", g_volume_str[type], *value);
181 return MM_ERROR_NONE;
185 int _mm_sound_volume_set_value_by_type(volume_type_t type, unsigned int value)
190 debug_log("volume_set_value %s %d", g_volume_str[type], value);
192 /* Set volume value to VCONF */
193 if (vconf_set_int(g_volume_vconf[type], vconf_value)) {
194 debug_error ("vconf_set_int(%s) failed..\n", g_volume_vconf[type]);
195 return MM_ERROR_SOUND_INTERNAL;
198 return MM_ERROR_NONE;
202 int _mm_sound_volume_get_values_on_bootup(int *values)
204 int i, vconf_value = 0;
206 for (i = 0; i < VOLUME_TYPE_MAX; i++) {
207 if (!vconf_get_int(g_volume_vconf[i], &vconf_value)) {
208 values[i] = vconf_value;
209 debug_log("volume_get_value %s %d", g_volume_str[i], values[i]);
211 debug_error ("vconf_get_int(%s) failed..\n", g_volume_vconf[i]);
212 values[i] = g_default_volume[i];
213 vconf_value = values[i];
214 if (vconf_set_int(g_volume_vconf[i], vconf_value)) {
215 debug_error ("vconf_set_int(%s) failed..\n", g_volume_vconf[i]);
220 return MM_ERROR_NONE;