Remove unused symbols
[platform/core/multimedia/libmm-sound.git] / mm_sound.c
1 /*
2  * libmm-sound
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Seungbae Shin <seungbae.shin@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  */
21
22 #include <stdlib.h>
23 #include <memory.h>
24 #include <unistd.h>
25 #include <pthread.h>
26
27 #include <errno.h>
28
29 #include <vconf.h>
30 #include <mm_types.h>
31 #include <mm_error.h>
32 #include <mm_debug.h>
33 #include "include/mm_sound_private.h"
34 #include "include/mm_sound_utils.h"
35 #include "include/mm_sound_client.h"
36 #include "include/mm_sound_pa_client.h"
37 #include "include/mm_sound_common.h"
38
39
40 #define VOLUME_MAX_MULTIMEDIA   16
41 #define VOLUME_MAX_BASIC                8
42 #define VOLUME_MAX_SINGLE               1
43
44
45 #define MASTER_VOLUME_MAX 100
46 #define MASTER_VOLUME_MIN 0
47
48 #include <gio/gio.h>
49
50 #define MM_SOUND_DBUS_BUS_NAME_PREPIX  "org.tizen.MMSound"
51 #define MM_SOUND_DBUS_OBJECT_PATH  "/org/tizen/MMSound"
52 #define MM_SOUND_DBUS_INTERFACE    "org.tizen.mmsound"
53
54 static const char* _get_volume_str(volume_type_t type)
55 {
56         static const char *volume_type_str[VOLUME_TYPE_MAX] = {
57                 "SYSTEM", "NOTIFICATION", "ALARM", "RINGTONE", "MEDIA", "CALL", "VOIP", "VOICE", "FIXED"
58         };
59
60         return (type < VOLUME_TYPE_MAX) ? volume_type_str[type] : "Unknown";
61 }
62
63 static int _validate_volume(volume_type_t type, int value)
64 {
65         if (value < 0)
66                 return -1;
67
68         switch (type) {
69         case VOLUME_TYPE_CALL:
70         case VOLUME_TYPE_VOIP:
71                 if (value >= VOLUME_MAX_BASIC) {
72                         return -1;
73                 }
74                 break;
75         case VOLUME_TYPE_SYSTEM:
76         case VOLUME_TYPE_MEDIA:
77         case VOLUME_TYPE_ALARM:
78         case VOLUME_TYPE_NOTIFICATION:
79         case VOLUME_TYPE_RINGTONE:
80         case VOLUME_TYPE_VOICE:
81                 if (value >= VOLUME_MAX_MULTIMEDIA) {
82                         return -1;
83                 }
84                 break;
85         default:
86                 return -1;
87                 break;
88         }
89         return 0;
90 }
91
92 EXPORT_API
93 int mm_sound_volume_remove_callback(volume_type_t type)
94 {
95         /* FIXME : Will be removed */
96         return MM_ERROR_NOT_SUPPORT_API;
97 }
98
99 EXPORT_API
100 int mm_sound_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* user_data, unsigned int *subs_id)
101 {
102         int ret = MM_ERROR_NONE;
103
104         if (func == NULL || subs_id == NULL) {
105                 debug_error("argument is not valid");
106                 return MM_ERROR_INVALID_ARGUMENT;
107         }
108
109         ret = mm_sound_client_add_volume_changed_callback(func, user_data, subs_id);
110         if (ret < 0) {
111                 debug_error("Can not add volume changed callback, ret = %x", ret);
112         }
113
114         return ret;
115 }
116
117 EXPORT_API
118 int mm_sound_remove_volume_changed_callback(unsigned int subs_id)
119 {
120         int ret = MM_ERROR_NONE;
121
122         ret = mm_sound_client_remove_volume_changed_callback(subs_id);
123         if (ret < 0) {
124                 debug_error("Can not remove volume changed callback, ret = %x", ret);
125         }
126
127         return ret;
128 }
129
130 EXPORT_API
131 int mm_sound_volume_set_value(volume_type_t volume_type, const unsigned int volume_level)
132 {
133         int ret = MM_ERROR_NONE;
134
135         debug_msg("type = (%d)%s, value = %d", volume_type, _get_volume_str(volume_type), volume_level);
136
137         /* Check input param */
138         if (0 > _validate_volume(volume_type, (int)volume_level)) {
139                 debug_error("invalid volume type %d, value %u", volume_type, volume_level);
140                 return MM_ERROR_INVALID_ARGUMENT;
141         }
142
143         /* request daemon to set volume */
144         ret = mm_sound_client_set_volume_by_type(volume_type, volume_level);
145         if (MM_ERROR_NONE != ret)
146                 debug_error("Can not set volume, ret=0x%x", ret);
147
148         return ret;
149 }
150
151 EXPORT_API
152 int mm_sound_volume_get_value(volume_type_t type, unsigned int *value)
153 {
154         int ret = MM_ERROR_NONE;
155
156         /* Check input param */
157         if (value == NULL) {
158                 debug_error("invalid argument");
159                 return MM_ERROR_INVALID_ARGUMENT;
160         }
161         if (type >= VOLUME_TYPE_MAX) {
162                 debug_error("invalid volume type value %d", type);
163                 return MM_ERROR_INVALID_ARGUMENT;
164         }
165
166         ret = mm_sound_util_volume_get_value_by_type(type, value);
167
168         debug_msg("returned %s = %d", _get_volume_str(type), *value);
169         return ret;
170 }
171
172 EXPORT_API
173 int mm_sound_set_filter(const char *stream_type, const char *filter_name, const char *filter_parameters, const char *filter_group)
174 {
175         /* Check input param */
176         if (!stream_type || !filter_name) {
177                 debug_error("invalid argument");
178                 return MM_ERROR_INVALID_ARGUMENT;
179         }
180         if (!filter_parameters)
181                 filter_parameters = "";
182         if (!filter_group)
183                 filter_group = "default";
184
185         debug_msg("stream_type(%s), filter_name(%s), filter_parameters(%s), filter_group(%s)", stream_type, filter_name, filter_parameters, filter_group);
186
187         return mm_sound_client_set_filter_by_type(stream_type, filter_name, filter_parameters, filter_group);
188 }
189
190 EXPORT_API
191 int mm_sound_unset_filter(const char *stream_type)
192 {
193         /* Check input param */
194         if (!stream_type) {
195                 debug_error("invalid argument");
196                 return MM_ERROR_INVALID_ARGUMENT;
197         }
198
199         debug_msg("stream_type(%s)", stream_type);
200
201         return mm_sound_client_unset_filter_by_type(stream_type);
202 }
203
204 EXPORT_API
205 int mm_sound_control_filter(const char *stream_type, const char *filter_name, const char *filter_controls)
206 {
207         /* Check input param */
208         if (!stream_type || !filter_name || !filter_controls) {
209                 debug_error("invalid argument");
210                 return MM_ERROR_INVALID_ARGUMENT;
211         }
212
213         debug_msg("stream_type(%s), filter_name(%s), filter_controls(%s)", stream_type, filter_name, filter_controls);
214
215         return mm_sound_client_control_filter_by_type(stream_type, filter_name, filter_controls);
216 }
217
218 ///////////////////////////////////
219 ////     MMSOUND PLAY APIs
220 ///////////////////////////////////
221 EXPORT_API
222 int mm_sound_play_sound_with_stream_info(const char *filename, char *stream_type, int stream_id, unsigned int loop, mm_sound_stop_callback_func callback, void *data, int *handle)
223 {
224         MMSoundPlayParam param = { 0, };
225         int err;
226
227         param.filename = filename;
228         param.volume = 0; //volume value dose not effect anymore
229         param.callback = callback;
230         param.data = data;
231
232         if (loop == 0)
233                 param.loop = -1;
234         else
235                 param.loop = loop;
236
237         err = mm_sound_client_play_sound_with_stream_info(&param, handle, stream_type, stream_id);
238         if (err < 0) {
239                 debug_error("Failed to play sound");
240                 return err;
241         }
242
243         debug_warning("success : handle=[%p]", handle);
244
245         return MM_ERROR_NONE;
246
247 }
248
249
250 EXPORT_API
251 int mm_sound_stop_sound(int handle)
252 {
253         int err;
254
255         debug_warning("enter : handle=[%d]", handle);
256         /* Stop sound */
257         err = mm_sound_client_stop_sound(handle);
258         if (err < 0) {
259                 debug_error("Fail to stop sound");
260                 return err;
261         }
262         debug_warning("success : handle=[%d]", handle);
263
264         return MM_ERROR_NONE;
265 }
266
267 ///////////////////////////////////
268 ////     MMSOUND TONE APIs
269 ///////////////////////////////////
270 EXPORT_API
271 int mm_sound_play_tone_with_stream_info(MMSoundTone_t tone, char *stream_type, int stream_id, const double volume, const int duration, int *handle)
272 {
273
274         int err = MM_ERROR_NONE;
275
276         err = mm_sound_client_play_tone_with_stream_info(tone, stream_type, stream_id, volume, duration, handle);
277         if (err < 0) {
278                 debug_error("Failed to play sound");
279                 return err;
280         }
281
282         return err;
283
284 }
285
286 ///////////////////////////////////
287 ////     MMSOUND ROUTING APIs
288 ///////////////////////////////////
289
290 EXPORT_API
291 int mm_sound_test(int a, int b, int* getv)
292 {
293         int ret = MM_ERROR_NONE;
294
295         debug_log("mm_sound_test enter");
296         if (!getv) {
297                 debug_error("argu null");
298                 return MM_ERROR_INVALID_ARGUMENT;
299         }
300         ret = mm_sound_client_test(a, b, getv);
301         if (ret < 0) {
302                 debug_error("Can not mm sound test, ret = %x", ret);
303         }
304         debug_log("mm_sound_test leave");
305
306         return ret;
307 }
308
309 EXPORT_API
310 int mm_sound_add_test_callback(mm_sound_test_cb func, void *user_data, unsigned int *subs_id)
311 {
312         int ret = MM_ERROR_NONE;
313
314         debug_log("enter");
315         if (!func || !subs_id) {
316                 debug_error("argument is not valid");
317                 return MM_ERROR_INVALID_ARGUMENT;
318         }
319
320         ret = mm_sound_client_add_test_callback(func, user_data, subs_id);
321         if (ret < 0) {
322                 debug_error("Can not add test callback, ret = %x", ret);
323         }
324         debug_log("leave");
325
326         return ret;
327 }
328
329 EXPORT_API
330 int mm_sound_remove_test_callback(unsigned int subs_id)
331 {
332         int ret = MM_ERROR_NONE;
333
334         debug_log("enter");
335         ret = mm_sound_client_remove_test_callback(subs_id);
336         if (ret < 0) {
337                 debug_error("Can not remove test callback, ret = %x", ret);
338         }
339         debug_log("leave");
340
341         return ret;
342 }
343
344 #ifdef TIZEN_TV
345 EXPORT_API
346 void mm_sound_dotnet_cleanup(int signo)
347 {
348 }
349 #endif
350
351 __attribute__ ((constructor))
352 static void _mm_sound_initialize(void)
353 {
354         mm_sound_client_initialize();
355         /* Will be Fixed */
356 }
357
358 __attribute__ ((destructor))
359 static void _mm_sound_finalize(void)
360 {
361         mm_sound_client_finalize();
362 }
363
364