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.
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"
40 #define VOLUME_MAX_MULTIMEDIA 16
41 #define VOLUME_MAX_BASIC 8
42 #define VOLUME_MAX_SINGLE 1
45 #define MASTER_VOLUME_MAX 100
46 #define MASTER_VOLUME_MIN 0
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"
54 static const char* _get_volume_str(volume_type_t type)
56 static const char *volume_type_str[VOLUME_TYPE_MAX] = {
57 "SYSTEM", "NOTIFICATION", "ALARM", "RINGTONE", "MEDIA", "CALL", "VOIP", "VOICE", "FIXED"
60 return (type >= VOLUME_TYPE_SYSTEM && type < VOLUME_TYPE_MAX) ? volume_type_str[type] : "Unknown";
63 static int _validate_volume(volume_type_t type, int value)
69 case VOLUME_TYPE_CALL:
70 case VOLUME_TYPE_VOIP:
71 if (value >= VOLUME_MAX_BASIC) {
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) {
93 int mm_sound_volume_remove_callback(volume_type_t type)
95 /* FIXME : Will be removed */
96 return MM_ERROR_NOT_SUPPORT_API;
100 int mm_sound_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* user_data, unsigned int *subs_id)
102 int ret = MM_ERROR_NONE;
104 if (func == NULL || subs_id == NULL) {
105 debug_error("argument is not valid");
106 return MM_ERROR_INVALID_ARGUMENT;
109 ret = mm_sound_client_add_volume_changed_callback(func, user_data, subs_id);
111 debug_error("Can not add volume changed callback, ret = %x", ret);
118 int mm_sound_remove_volume_changed_callback(unsigned int subs_id)
120 int ret = MM_ERROR_NONE;
122 ret = mm_sound_client_remove_volume_changed_callback(subs_id);
124 debug_error("Can not remove volume changed callback, ret = %x", ret);
131 int mm_sound_volume_set_value(volume_type_t volume_type, const unsigned int volume_level)
133 int ret = MM_ERROR_NONE;
135 debug_msg("type = (%d)%s, value = %d", volume_type, _get_volume_str(volume_type), volume_level);
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;
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);
152 int mm_sound_volume_get_value(volume_type_t type, unsigned int *value)
154 int ret = MM_ERROR_NONE;
156 /* Check input param */
158 debug_error("invalid argument");
159 return MM_ERROR_INVALID_ARGUMENT;
161 if (type < 0 || type >= VOLUME_TYPE_MAX) {
162 debug_error("invalid volume type value %d", type);
163 return MM_ERROR_INVALID_ARGUMENT;
166 ret = mm_sound_util_volume_get_value_by_type(type, value);
168 debug_msg("returned %s = %d", _get_volume_str(type), *value);
173 int mm_sound_volume_primary_type_set(volume_type_t type)
175 int ret = MM_ERROR_NONE;
177 /* Check input param */
178 if (type < VOLUME_TYPE_UNKNOWN || type >= VOLUME_TYPE_MAX) {
179 debug_error("invalid argument");
180 return MM_ERROR_INVALID_ARGUMENT;
183 if (vconf_set_int(VCONFKEY_SOUND_PRIMARY_VOLUME_TYPE, type)) {
184 debug_error("could not set vconf for RIMARY_VOLUME_TYPE");
185 ret = MM_ERROR_SOUND_INTERNAL;
187 debug_msg("set primary volume type forcibly %d(%s)", type, _get_volume_str(type));
194 int mm_sound_volume_primary_type_get(volume_type_t *type)
196 int ret = MM_ERROR_NONE;
197 int voltype = VOLUME_TYPE_RINGTONE;
199 /* Check input param */
201 debug_error("invalid argument");
202 return MM_ERROR_INVALID_ARGUMENT;
205 /* check force set */
206 if (vconf_get_int(VCONFKEY_SOUND_PRIMARY_VOLUME_TYPE, &voltype)) {
207 debug_error("could not get vconf for PRIMARY_VOLUME_TYPE");
208 ret = MM_ERROR_SOUND_INTERNAL;
210 debug_msg("get primary volume type %d(%s)", voltype, _get_volume_str(voltype));
218 int mm_sound_set_filter(const char *stream_type, const char *filter_name, const char *filter_parameters, const char *filter_group)
220 /* Check input param */
221 if (!stream_type || !filter_name) {
222 debug_error("invalid argument");
223 return MM_ERROR_INVALID_ARGUMENT;
225 if (!filter_parameters)
226 filter_parameters = "";
228 filter_group = "default";
230 debug_msg("stream_type(%s), filter_name(%s), filter_parameters(%s), filter_group(%s)", stream_type, filter_name, filter_parameters, filter_group);
232 return mm_sound_client_set_filter_by_type(stream_type, filter_name, filter_parameters, filter_group);
236 int mm_sound_unset_filter(const char *stream_type)
238 /* Check input param */
240 debug_error("invalid argument");
241 return MM_ERROR_INVALID_ARGUMENT;
244 debug_msg("stream_type(%s)", stream_type);
246 return mm_sound_client_unset_filter_by_type(stream_type);
250 int mm_sound_control_filter(const char *stream_type, const char *filter_name, const char *filter_controls)
252 /* Check input param */
253 if (!stream_type || !filter_name || !filter_controls) {
254 debug_error("invalid argument");
255 return MM_ERROR_INVALID_ARGUMENT;
258 debug_msg("stream_type(%s), filter_name(%s), filter_controls(%s)", stream_type, filter_name, filter_controls);
260 return mm_sound_client_control_filter_by_type(stream_type, filter_name, filter_controls);
263 ///////////////////////////////////
264 //// MMSOUND PLAY APIs
265 ///////////////////////////////////
267 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)
269 MMSoundPlayParam param = { 0, };
272 param.filename = filename;
273 param.volume = 0; //volume value dose not effect anymore
274 param.callback = callback;
282 err = mm_sound_client_play_sound_with_stream_info(¶m, handle, stream_type, stream_id);
284 debug_error("Failed to play sound");
288 debug_warning("success : handle=[%p]", handle);
290 return MM_ERROR_NONE;
296 int mm_sound_stop_sound(int handle)
300 debug_warning("enter : handle=[%d]", handle);
302 err = mm_sound_client_stop_sound(handle);
304 debug_error("Fail to stop sound");
307 debug_warning("success : handle=[%d]", handle);
309 return MM_ERROR_NONE;
312 ///////////////////////////////////
313 //// MMSOUND TONE APIs
314 ///////////////////////////////////
316 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)
319 int err = MM_ERROR_NONE;
321 err = mm_sound_client_play_tone_with_stream_info(tone, stream_type, stream_id, volume, duration, handle);
323 debug_error("Failed to play sound");
331 ///////////////////////////////////
332 //// MMSOUND ROUTING APIs
333 ///////////////////////////////////
336 int mm_sound_test(int a, int b, int* getv)
338 int ret = MM_ERROR_NONE;
340 debug_log("mm_sound_test enter");
342 debug_error("argu null");
343 return MM_ERROR_INVALID_ARGUMENT;
345 ret = mm_sound_client_test(a, b, getv);
347 debug_error("Can not mm sound test, ret = %x", ret);
349 debug_log("mm_sound_test leave");
355 int mm_sound_add_test_callback(mm_sound_test_cb func, void *user_data, unsigned int *subs_id)
357 int ret = MM_ERROR_NONE;
360 if (!func || !subs_id) {
361 debug_error("argument is not valid");
362 return MM_ERROR_INVALID_ARGUMENT;
365 ret = mm_sound_client_add_test_callback(func, user_data, subs_id);
367 debug_error("Can not add test callback, ret = %x", ret);
375 int mm_sound_remove_test_callback(unsigned int subs_id)
377 int ret = MM_ERROR_NONE;
380 ret = mm_sound_client_remove_test_callback(subs_id);
382 debug_error("Can not remove test callback, ret = %x", ret);
391 void mm_sound_dotnet_cleanup(int signo)
396 __attribute__ ((constructor))
397 static void _mm_sound_initialize(void)
399 mm_sound_client_initialize();
403 __attribute__ ((destructor))
404 static void _mm_sound_finalize(void)
406 mm_sound_client_finalize();