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_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 >= 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_set_filter(const char *stream_type, const char *filter_name, const char *filter_parameters, const char *filter_group)
175 /* Check input param */
176 if (!stream_type || !filter_name) {
177 debug_error("invalid argument");
178 return MM_ERROR_INVALID_ARGUMENT;
180 if (!filter_parameters)
181 filter_parameters = "";
183 filter_group = "default";
185 debug_msg("stream_type(%s), filter_name(%s), filter_parameters(%s), filter_group(%s)", stream_type, filter_name, filter_parameters, filter_group);
187 return mm_sound_client_set_filter_by_type(stream_type, filter_name, filter_parameters, filter_group);
191 int mm_sound_unset_filter(const char *stream_type)
193 /* Check input param */
195 debug_error("invalid argument");
196 return MM_ERROR_INVALID_ARGUMENT;
199 debug_msg("stream_type(%s)", stream_type);
201 return mm_sound_client_unset_filter_by_type(stream_type);
205 int mm_sound_control_filter(const char *stream_type, const char *filter_name, const char *filter_controls)
207 /* Check input param */
208 if (!stream_type || !filter_name || !filter_controls) {
209 debug_error("invalid argument");
210 return MM_ERROR_INVALID_ARGUMENT;
213 debug_msg("stream_type(%s), filter_name(%s), filter_controls(%s)", stream_type, filter_name, filter_controls);
215 return mm_sound_client_control_filter_by_type(stream_type, filter_name, filter_controls);
218 ///////////////////////////////////
219 //// MMSOUND PLAY APIs
220 ///////////////////////////////////
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)
224 MMSoundPlayParam param = { 0, };
227 param.filename = filename;
228 param.volume = 0; //volume value dose not effect anymore
229 param.callback = callback;
237 err = mm_sound_client_play_sound_with_stream_info(¶m, handle, stream_type, stream_id);
239 debug_error("Failed to play sound");
243 debug_warning("success : handle=[%p]", handle);
245 return MM_ERROR_NONE;
251 int mm_sound_stop_sound(int handle)
255 debug_warning("enter : handle=[%d]", handle);
257 err = mm_sound_client_stop_sound(handle);
259 debug_error("Fail to stop sound");
262 debug_warning("success : handle=[%d]", handle);
264 return MM_ERROR_NONE;
267 ///////////////////////////////////
268 //// MMSOUND TONE APIs
269 ///////////////////////////////////
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)
274 int err = MM_ERROR_NONE;
276 err = mm_sound_client_play_tone_with_stream_info(tone, stream_type, stream_id, volume, duration, handle);
278 debug_error("Failed to play sound");
286 ///////////////////////////////////
287 //// MMSOUND ROUTING APIs
288 ///////////////////////////////////
291 int mm_sound_test(int a, int b, int* getv)
293 int ret = MM_ERROR_NONE;
295 debug_log("mm_sound_test enter");
297 debug_error("argu null");
298 return MM_ERROR_INVALID_ARGUMENT;
300 ret = mm_sound_client_test(a, b, getv);
302 debug_error("Can not mm sound test, ret = %x", ret);
304 debug_log("mm_sound_test leave");
310 int mm_sound_add_test_callback(mm_sound_test_cb func, void *user_data, unsigned int *subs_id)
312 int ret = MM_ERROR_NONE;
315 if (!func || !subs_id) {
316 debug_error("argument is not valid");
317 return MM_ERROR_INVALID_ARGUMENT;
320 ret = mm_sound_client_add_test_callback(func, user_data, subs_id);
322 debug_error("Can not add test callback, ret = %x", ret);
330 int mm_sound_remove_test_callback(unsigned int subs_id)
332 int ret = MM_ERROR_NONE;
335 ret = mm_sound_client_remove_test_callback(subs_id);
337 debug_error("Can not remove test callback, ret = %x", ret);
346 void mm_sound_dotnet_cleanup(int signo)
351 __attribute__ ((constructor))
352 static void _mm_sound_initialize(void)
354 mm_sound_client_initialize();
358 __attribute__ ((destructor))
359 static void _mm_sound_finalize(void)
361 mm_sound_client_finalize();