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"
39 #define MASTER_VOLUME_MAX 100
40 #define MASTER_VOLUME_MIN 0
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"
48 static const char* _get_volume_str(volume_type_t type)
50 static const char *volume_type_str[VOLUME_TYPE_MAX] = {
51 "SYSTEM", "NOTIFICATION", "ALARM", "RINGTONE", "MEDIA", "CALL", "VOIP", "VOICE", "FIXED"
54 return (type < VOLUME_TYPE_MAX) ? volume_type_str[type] : "Unknown";
57 static const char* _get_volume_str_internal(volume_type_internal_t type)
59 static const char *volume_type_str[] = {
63 return (type < (VOLUME_TYPE_BIXBY + 1)) ? volume_type_str[type] : "Unknown";
67 int mm_sound_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* user_data, unsigned int *subs_id)
69 int ret = MM_ERROR_NONE;
71 if (func == NULL || subs_id == NULL) {
72 debug_error("argument is not valid");
73 return MM_ERROR_INVALID_ARGUMENT;
76 ret = mm_sound_client_add_volume_changed_callback(func, user_data, subs_id);
78 debug_error("Can not add volume changed callback, ret = %x", ret);
85 int mm_sound_remove_volume_changed_callback(unsigned int subs_id)
87 int ret = MM_ERROR_NONE;
89 ret = mm_sound_client_remove_volume_changed_callback(subs_id);
91 debug_error("Can not remove volume changed callback, ret = %x", ret);
98 int mm_sound_volume_set_value(volume_type_t type, const unsigned int value)
100 int ret = MM_ERROR_NONE;
102 /* request daemon to set volume */
103 ret = mm_sound_client_set_volume_by_type(type, value);
105 debug_error("can not set volume, type(%s), value(%d), ret=0x%x", _get_volume_str(type), value, ret);
107 debug_msg("set (%s) volume to (%d)", _get_volume_str(type), value);
113 int mm_sound_volume_get_value(volume_type_t type, unsigned int *value)
115 int ret = MM_ERROR_NONE;
117 ret = mm_sound_client_get_volume_by_type(type, value);
119 debug_error("can not get volume, type(%s), ret=0x%x", _get_volume_str(type), ret);
121 debug_msg("(%s) volume : %d", _get_volume_str(type), *value);
127 int mm_sound_add_volume_changed_callback_internal(mm_sound_volume_changed_cb_internal func, void* user_data, unsigned int *subs_id)
129 int ret = MM_ERROR_NONE;
131 if (func == NULL || subs_id == NULL) {
132 debug_error("argument is not valid");
133 return MM_ERROR_INVALID_ARGUMENT;
136 ret = mm_sound_client_add_volume_changed_callback_internal(func, user_data, subs_id);
138 debug_error("Can not add internal volume changed callback, ret = %x", ret);
144 int mm_sound_remove_volume_changed_callback_internal(unsigned int subs_id)
146 int ret = MM_ERROR_NONE;
148 ret = mm_sound_client_remove_volume_changed_callback(subs_id);
150 debug_error("Can not remove internal volume changed callback, ret = %x", ret);
156 int mm_sound_volume_set_value_internal(volume_type_internal_t type, const unsigned int value)
158 int ret = MM_ERROR_NONE;
160 /* request daemon to set volume */
161 ret = mm_sound_client_set_volume_by_internal_type(type, value);
163 debug_error("can not set internal volume, type(%s), value(%d), ret=0x%x", _get_volume_str_internal(type), value, ret);
165 debug_msg("set (%s) volume to (%d)", _get_volume_str_internal(type), value);
171 int mm_sound_volume_get_value_internal(volume_type_internal_t type, unsigned int *value)
173 int ret = MM_ERROR_NONE;
175 ret = mm_sound_client_get_volume_by_internal_type(type, value);
177 debug_error("can not get internal volume, type(%s), ret=0x%x", _get_volume_str_internal(type), ret);
179 debug_msg("(%s) volume : %d", _get_volume_str_internal(type), *value);
185 int mm_sound_set_mute(volume_type_t type, bool mute)
187 int ret = MM_ERROR_NONE;
189 ret = mm_sound_client_set_mute_by_type(type, mute);
191 debug_error("can not set mute, type(%s), mute(%d), ret=0x%x", _get_volume_str(type), mute, ret);
193 debug_msg("set (%s) mute to (%d)", _get_volume_str(type), mute);
199 int mm_sound_get_mute(volume_type_t type, bool *muted)
201 int ret = MM_ERROR_NONE;
203 /* Check input param */
205 debug_error("invalid argument");
206 return MM_ERROR_INVALID_ARGUMENT;
208 if (type > VOLUME_TYPE_VOICE) {
209 debug_error("invalid volume type value %d", type);
210 return MM_ERROR_INVALID_ARGUMENT;
213 ret = mm_sound_client_get_mute_by_type(type, muted);
215 debug_error("can not get mute, type(%s), ret=0x%x", _get_volume_str(type), ret);
217 debug_msg("(%s) mute state : %d", _get_volume_str(type), *muted);
223 int mm_sound_set_filter(const char *stream_type, const char *filter_name, const char *filter_parameters, const char *filter_group)
225 /* Check input param */
226 if (!stream_type || !filter_name) {
227 debug_error("invalid argument");
228 return MM_ERROR_INVALID_ARGUMENT;
230 if (!filter_parameters)
231 filter_parameters = "";
233 filter_group = "default";
235 debug_msg("stream_type(%s), filter_name(%s), filter_parameters(%s), filter_group(%s)", stream_type, filter_name, filter_parameters, filter_group);
237 return mm_sound_client_set_filter_by_type(stream_type, filter_name, filter_parameters, filter_group);
241 int mm_sound_unset_filter(const char *stream_type)
243 /* Check input param */
245 debug_error("invalid argument");
246 return MM_ERROR_INVALID_ARGUMENT;
249 debug_msg("stream_type(%s)", stream_type);
251 return mm_sound_client_unset_filter_by_type(stream_type);
255 int mm_sound_control_filter(const char *stream_type, const char *filter_name, const char *filter_controls)
257 /* Check input param */
258 if (!stream_type || !filter_name || !filter_controls) {
259 debug_error("invalid argument");
260 return MM_ERROR_INVALID_ARGUMENT;
263 debug_msg("stream_type(%s), filter_name(%s), filter_controls(%s)", stream_type, filter_name, filter_controls);
265 return mm_sound_client_control_filter_by_type(stream_type, filter_name, filter_controls);
268 ///////////////////////////////////
269 //// MMSOUND ROUTING APIs
270 ///////////////////////////////////
273 int mm_sound_add_ducking_state_changed_callback(mm_sound_ducking_state_changed_cb func, void *user_data, unsigned int *subs_id)
275 int ret = MM_ERROR_NONE;
277 if (func == NULL || subs_id == NULL) {
278 debug_error("argument is not valid");
279 return MM_ERROR_INVALID_ARGUMENT;
282 ret = mm_sound_client_add_ducking_state_changed_callback(func, user_data, subs_id);
284 debug_error("Can not add ducking state changed callback, ret = %x", ret);
291 int mm_sound_remove_ducking_state_changed_callback(unsigned int subs_id)
293 int ret = MM_ERROR_NONE;
295 ret = mm_sound_client_remove_ducking_state_changed_callback(subs_id);
297 debug_error("Can not remove ducking state changed callback, ret = %x", ret);
305 void mm_sound_dotnet_cleanup(int signo)
310 __attribute__ ((constructor))
311 static void _mm_sound_initialize(void)
313 mm_sound_client_initialize();
317 __attribute__ ((destructor))
318 static void _mm_sound_finalize(void)
320 mm_sound_client_finalize();