mm_sound: Remove deprecated symbol - mm_sound_volume_remove_callback()
[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 #define MASTER_VOLUME_MAX 100
40 #define MASTER_VOLUME_MIN 0
41
42 #include <gio/gio.h>
43
44 #define MM_SOUND_DBUS_BUS_NAME_PREPIX  "org.tizen.MMSound"
45 #define MM_SOUND_DBUS_OBJECT_PATH  "/org/tizen/MMSound"
46 #define MM_SOUND_DBUS_INTERFACE    "org.tizen.mmsound"
47
48 static const char* _get_volume_str(volume_type_t type)
49 {
50         static const char *volume_type_str[VOLUME_TYPE_MAX] = {
51                 "SYSTEM", "NOTIFICATION", "ALARM", "RINGTONE", "MEDIA", "CALL", "VOIP", "VOICE", "FIXED"
52         };
53
54         return (type < VOLUME_TYPE_MAX) ? volume_type_str[type] : "Unknown";
55 }
56
57 EXPORT_API
58 int mm_sound_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* user_data, unsigned int *subs_id)
59 {
60         int ret = MM_ERROR_NONE;
61
62         if (func == NULL || subs_id == NULL) {
63                 debug_error("argument is not valid");
64                 return MM_ERROR_INVALID_ARGUMENT;
65         }
66
67         ret = mm_sound_client_add_volume_changed_callback(func, user_data, subs_id);
68         if (ret < 0) {
69                 debug_error("Can not add volume changed callback, ret = %x", ret);
70         }
71
72         return ret;
73 }
74
75 EXPORT_API
76 int mm_sound_remove_volume_changed_callback(unsigned int subs_id)
77 {
78         int ret = MM_ERROR_NONE;
79
80         ret = mm_sound_client_remove_volume_changed_callback(subs_id);
81         if (ret < 0) {
82                 debug_error("Can not remove volume changed callback, ret = %x", ret);
83         }
84
85         return ret;
86 }
87
88 EXPORT_API
89 int mm_sound_volume_set_value(volume_type_t type, const unsigned int value)
90 {
91         int ret = MM_ERROR_NONE;
92
93         /* request daemon to set volume */
94         ret = mm_sound_client_set_volume_by_type(type, value);
95         if (ret)
96                 debug_error("can not set volume, type(%s), value(%d), ret=0x%x", _get_volume_str(type), value, ret);
97         else
98                 debug_msg("set (%s) volume to (%d)",  _get_volume_str(type), value);
99
100         return ret;
101 }
102
103 EXPORT_API
104 int mm_sound_volume_get_value(volume_type_t type, unsigned int *value)
105 {
106         int ret = MM_ERROR_NONE;
107
108         ret = mm_sound_client_get_volume_by_type(type, value);
109         if (ret)
110                 debug_error("can not get volume, type(%s), ret=0x%x", _get_volume_str(type), ret);
111         else
112                 debug_msg("(%s) volume : %d",  _get_volume_str(type), *value);
113
114         return ret;
115 }
116
117 EXPORT_API
118 int mm_sound_set_mute(volume_type_t type, bool mute)
119 {
120         int ret = MM_ERROR_NONE;
121
122         ret = mm_sound_client_set_mute_by_type(type, mute);
123         if (ret)
124                 debug_error("can not set mute, type(%s), mute(%d), ret=0x%x", _get_volume_str(type), mute, ret);
125         else
126                 debug_msg("set (%s) mute to (%d)",  _get_volume_str(type), mute);
127
128         return ret;
129 }
130
131 EXPORT_API
132 int mm_sound_get_mute(volume_type_t type, bool  *muted)
133 {
134         int ret = MM_ERROR_NONE;
135
136         /* Check input param */
137         if (!muted) {
138                 debug_error("invalid argument");
139                 return MM_ERROR_INVALID_ARGUMENT;
140         }
141         if (type > VOLUME_TYPE_VOICE) {
142                 debug_error("invalid volume type value %d", type);
143                 return MM_ERROR_INVALID_ARGUMENT;
144         }
145
146         ret = mm_sound_client_get_mute_by_type(type, muted);
147         if (ret)
148                 debug_error("can not get mute, type(%s), ret=0x%x", _get_volume_str(type), ret);
149         else
150                 debug_msg("(%s) mute state : %d",  _get_volume_str(type), *muted);
151
152         return ret;
153 }
154
155 EXPORT_API
156 int mm_sound_set_filter(const char *stream_type, const char *filter_name, const char *filter_parameters, const char *filter_group)
157 {
158         /* Check input param */
159         if (!stream_type || !filter_name) {
160                 debug_error("invalid argument");
161                 return MM_ERROR_INVALID_ARGUMENT;
162         }
163         if (!filter_parameters)
164                 filter_parameters = "";
165         if (!filter_group)
166                 filter_group = "default";
167
168         debug_msg("stream_type(%s), filter_name(%s), filter_parameters(%s), filter_group(%s)", stream_type, filter_name, filter_parameters, filter_group);
169
170         return mm_sound_client_set_filter_by_type(stream_type, filter_name, filter_parameters, filter_group);
171 }
172
173 EXPORT_API
174 int mm_sound_unset_filter(const char *stream_type)
175 {
176         /* Check input param */
177         if (!stream_type) {
178                 debug_error("invalid argument");
179                 return MM_ERROR_INVALID_ARGUMENT;
180         }
181
182         debug_msg("stream_type(%s)", stream_type);
183
184         return mm_sound_client_unset_filter_by_type(stream_type);
185 }
186
187 EXPORT_API
188 int mm_sound_control_filter(const char *stream_type, const char *filter_name, const char *filter_controls)
189 {
190         /* Check input param */
191         if (!stream_type || !filter_name || !filter_controls) {
192                 debug_error("invalid argument");
193                 return MM_ERROR_INVALID_ARGUMENT;
194         }
195
196         debug_msg("stream_type(%s), filter_name(%s), filter_controls(%s)", stream_type, filter_name, filter_controls);
197
198         return mm_sound_client_control_filter_by_type(stream_type, filter_name, filter_controls);
199 }
200
201 ///////////////////////////////////
202 ////     MMSOUND PLAY APIs
203 ///////////////////////////////////
204 EXPORT_API
205 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)
206 {
207         MMSoundPlayParam param = { 0, };
208         int err;
209
210         param.filename = filename;
211         param.volume = 0; //volume value dose not effect anymore
212         param.callback = callback;
213         param.data = data;
214
215         if (loop == 0)
216                 param.loop = -1;
217         else
218                 param.loop = loop;
219
220         err = mm_sound_client_play_sound_with_stream_info(&param, handle, stream_type, stream_id);
221         if (err < 0) {
222                 debug_error("Failed to play sound");
223                 return err;
224         }
225
226         debug_warning("success : handle=[%p]", handle);
227
228         return MM_ERROR_NONE;
229
230 }
231
232
233 EXPORT_API
234 int mm_sound_stop_sound(int handle)
235 {
236         int err;
237
238         debug_warning("enter : handle=[%d]", handle);
239         /* Stop sound */
240         err = mm_sound_client_stop_sound(handle);
241         if (err < 0) {
242                 debug_error("Fail to stop sound");
243                 return err;
244         }
245         debug_warning("success : handle=[%d]", handle);
246
247         return MM_ERROR_NONE;
248 }
249
250 ///////////////////////////////////
251 ////     MMSOUND TONE APIs
252 ///////////////////////////////////
253 EXPORT_API
254 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)
255 {
256
257         int err = MM_ERROR_NONE;
258
259         err = mm_sound_client_play_tone_with_stream_info(tone, stream_type, stream_id, volume, duration, handle);
260         if (err < 0) {
261                 debug_error("Failed to play sound");
262                 return err;
263         }
264
265         return err;
266
267 }
268
269 ///////////////////////////////////
270 ////     MMSOUND ROUTING APIs
271 ///////////////////////////////////
272
273 EXPORT_API
274 int mm_sound_test(int a, int b, int* getv)
275 {
276         int ret = MM_ERROR_NONE;
277
278         debug_log("mm_sound_test enter");
279         if (!getv) {
280                 debug_error("argu null");
281                 return MM_ERROR_INVALID_ARGUMENT;
282         }
283         ret = mm_sound_client_test(a, b, getv);
284         if (ret < 0) {
285                 debug_error("Can not mm sound test, ret = %x", ret);
286         }
287         debug_log("mm_sound_test leave");
288
289         return ret;
290 }
291
292 EXPORT_API
293 int mm_sound_add_test_callback(mm_sound_test_cb func, void *user_data, unsigned int *subs_id)
294 {
295         int ret = MM_ERROR_NONE;
296
297         debug_log("enter");
298         if (!func || !subs_id) {
299                 debug_error("argument is not valid");
300                 return MM_ERROR_INVALID_ARGUMENT;
301         }
302
303         ret = mm_sound_client_add_test_callback(func, user_data, subs_id);
304         if (ret < 0) {
305                 debug_error("Can not add test callback, ret = %x", ret);
306         }
307         debug_log("leave");
308
309         return ret;
310 }
311
312 EXPORT_API
313 int mm_sound_remove_test_callback(unsigned int subs_id)
314 {
315         int ret = MM_ERROR_NONE;
316
317         debug_log("enter");
318         ret = mm_sound_client_remove_test_callback(subs_id);
319         if (ret < 0) {
320                 debug_error("Can not remove test callback, ret = %x", ret);
321         }
322         debug_log("leave");
323
324         return ret;
325 }
326
327 EXPORT_API
328 int mm_sound_add_ducking_state_changed_callback(mm_sound_ducking_state_changed_cb func, void *user_data, unsigned int *subs_id)
329 {
330         int ret = MM_ERROR_NONE;
331
332         if (func == NULL || subs_id == NULL) {
333                 debug_error("argument is not valid");
334                 return MM_ERROR_INVALID_ARGUMENT;
335         }
336
337         ret = mm_sound_client_add_ducking_state_changed_callback(func, user_data, subs_id);
338         if (ret < 0) {
339                 debug_error("Can not add ducking state changed callback, ret = %x", ret);
340         }
341
342         return ret;
343 }
344
345 EXPORT_API
346 int mm_sound_remove_ducking_state_changed_callback(unsigned int subs_id)
347 {
348         int ret = MM_ERROR_NONE;
349
350         ret = mm_sound_client_remove_ducking_state_changed_callback(subs_id);
351         if (ret < 0) {
352                 debug_error("Can not remove ducking state changed callback, ret = %x", ret);
353         }
354
355         return ret;
356 }
357
358 #ifdef TIZEN_TV
359 EXPORT_API
360 void mm_sound_dotnet_cleanup(int signo)
361 {
362 }
363 #endif
364
365 __attribute__ ((constructor))
366 static void _mm_sound_initialize(void)
367 {
368         mm_sound_client_initialize();
369         /* Will be Fixed */
370 }
371
372 __attribute__ ((destructor))
373 static void _mm_sound_finalize(void)
374 {
375         mm_sound_client_finalize();
376 }
377
378