11 #include "include/mm_sound_proxy.h"
12 #include "include/mm_sound_common.h"
13 #include "include/mm_sound_dbus.h"
14 #include "include/mm_sound_intf.h"
15 #include "include/mm_sound_focus_socket.h"
16 #include "include/mm_sound_focus_private.h"
18 extern focus_sound_info_t g_focus_sound_handle[FOCUS_HANDLE_MAX];
20 struct callback_data {
23 mm_sound_proxy_userdata_free free_func;
27 #define CB_DATA_NEW(_cb_data, _func, _userdata, _freefunc) \
29 _cb_data = (struct callback_data*) g_malloc0(sizeof(struct callback_data)); \
30 _cb_data->user_cb = _func; \
31 _cb_data->user_data = _userdata; \
32 _cb_data->free_func = _freefunc; \
33 _cb_data->subs_id = 0; \
36 /* subscribe is true when add callback,
37 * false when remove callback */
38 static int _notify_subscription(audio_event_t event, uint32_t subs_id, gboolean subscribe)
40 int ret = MM_ERROR_NONE;
41 GVariant *params = NULL;
42 const char *event_name = NULL;
46 if ((ret = mm_sound_dbus_get_event_name(event, &event_name) != MM_ERROR_NONE)) {
47 debug_error("Failed to get event name");
48 return MM_ERROR_SOUND_INTERNAL;
51 if (!(params = g_variant_new("(sub)", event_name, subs_id, subscribe))) {
52 debug_error("Construct Param failed");
53 return MM_ERROR_SOUND_INTERNAL;
56 if ((ret = mm_sound_dbus_emit_signal(AUDIO_PROVIDER_AUDIO_CLIENT, AUDIO_EVENT_CLIENT_SUBSCRIBED, params)))
57 debug_error("dbus send signal for client subscribed failed");
63 static int _notify_signal_handled(audio_event_t event, uint32_t event_id, uint32_t subs_id, GVariant *signal_params)
65 int ret = MM_ERROR_NONE;
66 GVariant *params = NULL;
67 const char *event_name = NULL;
71 if ((ret = mm_sound_dbus_get_event_name(event, &event_name) != MM_ERROR_NONE)) {
72 debug_error("Failed to get event name");
73 return MM_ERROR_SOUND_INTERNAL;
76 if (!(params = g_variant_new("(usuv)", event_id, event_name, subs_id, signal_params))) {
77 debug_error("Construct Param failed");
78 return MM_ERROR_SOUND_INTERNAL;
81 if ((ret = mm_sound_dbus_emit_signal(AUDIO_PROVIDER_AUDIO_CLIENT, AUDIO_EVENT_CLIENT_HANDLED, params)))
82 debug_error("dbus send signal for client handled failed");
88 static int parse_device_variant(GVariant *v, int *device_id, const char **device_type, int *direction, int *state,
89 const char **device_name, int *vendor_id, int *product_id, gboolean *is_running, int *stream_id, int *stream_num)
93 GVariantIter iter, array_iter;
95 int ret = MM_ERROR_NONE;
98 debug_error("Variant NULL");
102 v_type = g_variant_get_type_string(v);
103 if (g_variant_type_equal(v_type, "(isiisiibai)") == FALSE) {
104 debug_error("device variant type not matching '%s'", v_type);
105 return MM_ERROR_NONE;
108 g_variant_iter_init(&iter, v);
109 g_variant_iter_next(&iter, "i", device_id);
110 g_variant_iter_next(&iter, "&s", device_type);
111 g_variant_iter_next(&iter, "i", direction);
112 g_variant_iter_next(&iter, "i", state);
113 g_variant_iter_next(&iter, "&s", device_name);
114 g_variant_iter_next(&iter, "i", vendor_id);
115 g_variant_iter_next(&iter, "i", product_id);
116 g_variant_iter_next(&iter, "b", is_running);
118 array_v = g_variant_iter_next_value(&iter);
119 *stream_num = g_variant_iter_init(&array_iter, array_v);
120 if (*stream_num > MAX_STREAM_ON_DEVICE) {
121 debug_error("too many streams on device %d", *stream_num);
122 ret = MM_ERROR_SOUND_INTERNAL;
126 while (g_variant_iter_loop(&array_iter, "i", &stream_id[i++])) ;
128 g_variant_unref(array_v);
133 /* This callback unmarshall general-formed paramters to subject specific parameters,
134 * and call proper callback */
135 static void dbus_callback(audio_event_t event, GVariant *params, void *userdata)
137 struct callback_data *cb_data = (struct callback_data*) userdata;
139 const char *name = NULL, *device_type = NULL;
140 int device_id, direction, state;
144 int stream_id[MAX_STREAM_ON_DEVICE];
146 int vendor_id, product_id;
147 gboolean is_running = FALSE;
149 v_type = g_variant_get_type_string(params);
151 if (event == AUDIO_EVENT_VOLUME_CHANGED) {
152 char *volume_type_str = NULL, *direction = NULL;
153 unsigned volume_level;
155 g_variant_get(params, "(&s&su)", &direction, &volume_type_str, &volume_level);
156 ((mm_sound_volume_changed_wrapper_cb)(cb_data->user_cb))(direction, volume_type_str, volume_level, cb_data->user_data);
157 } else if (event == AUDIO_EVENT_DEVICE_CONNECTED) {
158 gboolean is_connected = FALSE;
160 if (g_variant_type_equal(v_type, "(u(isiisiibai)b)") == FALSE) {
161 debug_error("Device connection changed signature not matching : %s", v_type);
164 g_variant_iter_init(&iter, params);
165 g_variant_iter_next(&iter, "u", &event_id);
166 device_v = g_variant_iter_next_value(&iter);
167 if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
168 &name, &vendor_id, &product_id, &is_running, stream_id, &stream_num) < 0) {
169 debug_error("Failed to parse device variant");
172 g_variant_iter_next(&iter, "b", &is_connected);
174 ((mm_sound_device_connected_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
175 state, name, vendor_id, product_id, (bool)is_running, stream_id, stream_num, (bool)is_connected, cb_data->user_data);
176 _notify_signal_handled(event, event_id, cb_data->subs_id, g_variant_new("(ib)", device_id, (bool)is_connected));
177 } else if (event == AUDIO_EVENT_DEVICE_INFO_CHANGED) {
178 int changed_device_info_type = 0;
180 if (g_variant_type_equal(v_type, "(u(isiisiibai)i)") == FALSE) {
181 debug_error("Device information changed signature not matching : %s", v_type);
185 g_variant_iter_init(&iter, params);
186 g_variant_iter_next(&iter, "u", &event_id);
187 device_v = g_variant_iter_next_value(&iter);
188 if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
189 &name, &vendor_id, &product_id, &is_running, stream_id, &stream_num) < 0) {
190 debug_error("Failed to parse device variant");
193 g_variant_iter_next(&iter, "i", &changed_device_info_type);
195 ((mm_sound_device_info_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
196 state, name, vendor_id, product_id, (bool)is_running, stream_id, stream_num, changed_device_info_type, cb_data->user_data);
197 } else if (event == AUDIO_EVENT_DEVICE_STATE_CHANGED) {
199 if (g_variant_type_equal(v_type, "(u(isiisiibai))") == FALSE) {
200 debug_error("Device state changed signature not matching : %s", v_type);
204 g_variant_iter_init(&iter, params);
205 g_variant_iter_next(&iter, "u", &event_id);
206 device_v = g_variant_iter_next_value(&iter);
207 if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
208 &name, &vendor_id, &product_id, &is_running, stream_id, &stream_num) < 0) {
209 debug_error("Failed to parse device variant");
213 ((mm_sound_device_state_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
214 state, name, vendor_id, product_id, (bool)is_running, stream_id, stream_num, cb_data->user_data);
215 } else if (event == AUDIO_EVENT_DEVICE_RUNNING_CHANGED) {
217 if (g_variant_type_equal(v_type, "(u(isiisiibai))") == FALSE) {
218 debug_error("Device state changed signature not matching : %s", v_type);
222 g_variant_iter_init(&iter, params);
223 g_variant_iter_next(&iter, "u", &event_id);
224 device_v = g_variant_iter_next_value(&iter);
225 if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
226 &name, &vendor_id, &product_id, &is_running, stream_id, &stream_num) < 0) {
227 debug_error("Failed to parse device variant");
231 ((mm_sound_device_running_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
232 state, name, vendor_id, product_id, (bool)is_running, stream_id, stream_num, cb_data->user_data);
233 } else if (event == AUDIO_EVENT_FOCUS_CHANGED) {
234 } else if (event == AUDIO_EVENT_FOCUS_WATCH) {
235 } else if (event == AUDIO_EVENT_TEST) {
237 g_variant_get(params, "(i)", &test_var);
238 ((mm_sound_test_cb)(cb_data->user_cb))(test_var, cb_data->user_data);
239 } else if (event == AUDIO_EVENT_PLAY_FILE_END) {
240 int ended_handle = 0;
241 g_variant_get(params, "(i)", &ended_handle);
242 ((mm_sound_stop_callback_wrapper_func)(cb_data->user_cb))(ended_handle, cb_data->user_data);
246 static void simple_callback_data_free_func(void *data)
248 struct callback_data *cb_data = (struct callback_data*) data;
251 if (cb_data->free_func)
252 cb_data->free_func(cb_data->user_data);
257 int mm_sound_proxy_add_test_callback(mm_sound_test_cb func, void *userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id)
259 int ret = MM_ERROR_NONE;
260 struct callback_data *cb_data;
264 CB_DATA_NEW(cb_data, func, userdata, freefunc);
266 if ((ret = mm_sound_dbus_signal_subscribe_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_EVENT_TEST, dbus_callback, cb_data, simple_callback_data_free_func, &cb_data->subs_id)) != MM_ERROR_NONE)
267 debug_error("add test callback failed");
269 *subs_id = cb_data->subs_id;
275 int mm_sound_proxy_remove_test_callback(unsigned subs_id)
277 int ret = MM_ERROR_NONE;
280 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
281 debug_error("remove test callback failed");
287 int mm_sound_proxy_test(int a, int b, int *get)
289 int ret = MM_ERROR_NONE;
291 GVariant *params = NULL, *result = NULL;
295 if ((params = g_variant_new("(ii)", a, b)) == NULL) {
296 debug_error("Construct Param for method call failed");
297 return MM_ERROR_SOUND_INTERNAL;
300 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_TEST, params, &result)) != MM_ERROR_NONE) {
301 debug_error("dbus test call failed");
302 g_variant_unref(result);
307 g_variant_get(result, "(i)", &reply);
308 debug_log("reply : %d", reply);
310 g_variant_unref(result);
312 debug_error("reply null");
313 ret = MM_ERROR_SOUND_INTERNAL;
320 int mm_sound_proxy_is_stream_on_device(int stream_id, int device_id, bool *is_on)
322 int ret = MM_ERROR_NONE;
323 GVariant *params = NULL, *result = NULL;
329 debug_error("Invalid Parameter, is_on null");
330 return MM_ERROR_INVALID_ARGUMENT;
333 if ((params = g_variant_new("(ii)", stream_id, device_id)) == NULL) {
334 debug_error("Construct Param for query is stream on device failed");
335 return MM_ERROR_SOUND_INTERNAL;
338 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_IS_STREAM_ON_DEVICE, params, &result)) != MM_ERROR_NONE) {
339 debug_error("is stream on device failed");
344 g_variant_get(result, "(b)", &_is_on);
345 debug_log("is_on : %d", _is_on);
346 *is_on = (bool)_is_on;
348 debug_error("reply null");
349 ret = MM_ERROR_SOUND_INTERNAL;
353 g_variant_unref(result);
360 #define _VCONF_KEY_SOUND_SPEAKER_SELECTION "file/private/sound/feature/SpeakerSelection"
361 #define _AUDIO_TV_OUTPUT_BT_HEADSET 5
363 static mm_sound_device_t* _get_tv_bt_device(void)
365 int speaker_value = 0;
366 mm_sound_device_t* device_item = NULL;
368 if (vconf_get_int(_VCONF_KEY_SOUND_SPEAKER_SELECTION, &speaker_value) == VCONF_ERROR) {
369 debug_error("vconf_get_int(%s) failed..", _VCONF_KEY_SOUND_SPEAKER_SELECTION);
373 debug_warning("speaker selection value = %d", speaker_value);
374 if (speaker_value != _AUDIO_TV_OUTPUT_BT_HEADSET)
377 device_item = g_malloc0(sizeof(mm_sound_device_t));
381 MMSOUND_STRNCPY(device_item->name, "BluetoothMedia", MAX_DEVICE_NAME_NUM);
382 MMSOUND_STRNCPY(device_item->type, "bt-a2dp", MAX_DEVICE_TYPE_STR_LEN);
383 device_item->id = 99;
384 device_item->io_direction = DEVICE_IO_DIRECTION_OUT;
385 device_item->state = DEVICE_STATE_ACTIVATED;
386 device_item->vendor_id = -1;
387 device_item->product_id = -1;
388 device_item->stream_num = -1;
392 #endif /* TIZEN_TV */
394 int mm_sound_proxy_get_current_connected_device_list(int device_flags, GList** device_list)
396 int ret = MM_ERROR_NONE;
397 GVariant *result = NULL, *child = NULL;
398 GVariant *params = NULL;
400 mm_sound_device_t* device_item;
401 const gchar *device_name_tmp = NULL, *device_type_tmp = NULL;
406 debug_error("Invalid Parameter, device_list null");
407 ret = MM_ERROR_INVALID_ARGUMENT;
411 params = g_variant_new("(i)", device_flags);
414 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_GET_CONNECTED_DEVICE_LIST, params, &result)) != MM_ERROR_NONE) {
415 debug_error("Get current connected device list failed");
419 debug_error("Construct Param for get current connected device failed");
420 return MM_ERROR_SOUND_INTERNAL;
423 child = g_variant_get_child_value(result, 0);
424 g_variant_iter_init(&iter, child);
426 device_item = g_malloc0(sizeof(mm_sound_device_t));
427 if (device_item && g_variant_iter_loop(&iter, "(i&sii&siib)",
428 &device_item->id, &device_type_tmp, &device_item->io_direction, &device_item->state,
429 &device_name_tmp, &device_item->vendor_id, &device_item->product_id, &device_item->is_running)) {
430 MMSOUND_STRNCPY(device_item->name, device_name_tmp, MAX_DEVICE_NAME_NUM);
431 MMSOUND_STRNCPY(device_item->type, device_type_tmp, MAX_DEVICE_TYPE_STR_LEN);
432 *device_list = g_list_append(*device_list, device_item);
433 debug_log("Added device id(%d) type(%17s) direction(%d) state(%d) name(%s) vendor-id(%04x) product-id(%04x) is_running(%d)",
434 device_item->id, device_item->type, device_item->io_direction, device_item->state,
435 device_item->name, device_item->vendor_id, device_item->product_id, device_item->is_running);
436 device_item->stream_num = -1;
445 device_item = _get_tv_bt_device();
447 *device_list = g_list_append(*device_list, device_item);
448 debug_msg("Added TV bt device id(%d) type(%17s) direction(%d) state(%d) name(%s) vendor-id(%04x) product-id(%04x)",
449 device_item->id, device_item->type, device_item->io_direction, device_item->state,
450 device_item->name, device_item->vendor_id, device_item->product_id);
452 #endif /* TIZEN_TV */
455 g_variant_unref(result);
461 int mm_sound_proxy_get_device_by_id(int device_id, mm_sound_device_t **device)
463 int ret = MM_ERROR_NONE;
464 GVariant *params = NULL, *result = NULL;
465 mm_sound_device_t* device_item = NULL;
466 const gchar *device_name_tmp = NULL, *device_type_tmp = NULL;
470 if (!device || device_id < 1) {
471 debug_error("Invalid Parameter, device null or improper device id");
472 return MM_ERROR_INVALID_ARGUMENT;
475 if ((params = g_variant_new("(i)", device_id)) == NULL) {
476 debug_error("Construct Param for get device by id failed");
477 return MM_ERROR_SOUND_INTERNAL;
480 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_GET_DEVICE_BY_ID, params, &result)) != MM_ERROR_NONE) {
481 debug_error("get device by id failed");
482 ret = MM_ERROR_SOUND_NO_DATA;
487 if ((device_item = g_malloc0(sizeof(mm_sound_device_t))) == NULL) {
488 debug_error("Alloc device handle failed");
489 ret = MM_ERROR_SOUND_INTERNAL;
493 g_variant_get(result, "(i&sii&sii)",
494 &device_item->id, &device_type_tmp, &device_item->io_direction,
495 &device_item->state, &device_name_tmp,
496 &device_item->vendor_id, &device_item->product_id);
497 MMSOUND_STRNCPY(device_item->name, device_name_tmp, MAX_DEVICE_NAME_NUM);
498 MMSOUND_STRNCPY(device_item->type, device_type_tmp, MAX_DEVICE_TYPE_STR_LEN);
499 debug_log("Get device id(%d) type(%17s) direction(%d) state(%d) name(%s) vendor-id(%04x) product-id(%04x)",
500 device_item->id, device_item->type, device_item->io_direction,
501 device_item->state, device_item->name,
502 device_item->vendor_id, device_item->product_id);
503 device_item->stream_num = -1;
504 *device = device_item;
506 debug_error("reply null");
507 ret = MM_ERROR_SOUND_INTERNAL;
511 g_variant_unref(result);
517 int mm_sound_proxy_add_device_connected_callback(mm_sound_device_connected_wrapper_cb func, void *userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id)
519 int ret = MM_ERROR_NONE;
520 struct callback_data *cb_data;
524 CB_DATA_NEW(cb_data, func, userdata, freefunc);
526 if ((ret = mm_sound_dbus_signal_subscribe_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_EVENT_DEVICE_CONNECTED, dbus_callback, cb_data, simple_callback_data_free_func, &cb_data->subs_id)) != MM_ERROR_NONE) {
527 debug_error("add device connected callback failed");
531 if ((ret = _notify_subscription(AUDIO_EVENT_DEVICE_CONNECTED, cb_data->subs_id, TRUE)) != MM_ERROR_NONE) {
532 debug_error("failed to notify subscription of device connected event");
536 *subs_id = cb_data->subs_id;
543 int mm_sound_proxy_remove_device_connected_callback(unsigned subs_id)
545 int ret = MM_ERROR_NONE;
548 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
549 debug_error("remove device connected callback failed");
553 if ((ret = _notify_subscription(AUDIO_EVENT_DEVICE_CONNECTED, subs_id, FALSE)) != MM_ERROR_NONE)
554 debug_error("failed to notify unsubscription of device connected event");
561 int mm_sound_proxy_add_device_info_changed_callback(mm_sound_device_info_changed_wrapper_cb func, void* userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id)
563 int ret = MM_ERROR_NONE;
564 struct callback_data *cb_data;
568 CB_DATA_NEW(cb_data, func, userdata, freefunc);
570 if ((ret = mm_sound_dbus_signal_subscribe_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_EVENT_DEVICE_INFO_CHANGED, dbus_callback, cb_data, simple_callback_data_free_func, &cb_data->subs_id)) != MM_ERROR_NONE)
571 debug_error("Add device info changed callback failed");
573 *subs_id = cb_data->subs_id;
579 int mm_sound_proxy_remove_device_info_changed_callback(unsigned subs_id)
581 int ret = MM_ERROR_NONE;
584 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
585 debug_error("remove device info changed callback failed");
591 int mm_sound_proxy_add_device_state_changed_callback(mm_sound_device_state_changed_wrapper_cb func, void* userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id)
593 int ret = MM_ERROR_NONE;
594 struct callback_data *cb_data;
598 CB_DATA_NEW(cb_data, func, userdata, freefunc);
600 if ((ret = mm_sound_dbus_signal_subscribe_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_EVENT_DEVICE_STATE_CHANGED, dbus_callback, cb_data, simple_callback_data_free_func, &cb_data->subs_id)) != MM_ERROR_NONE)
601 debug_error("Add device state changed callback failed");
603 *subs_id = cb_data->subs_id;
609 int mm_sound_proxy_remove_device_state_changed_callback(unsigned subs_id)
611 int ret = MM_ERROR_NONE;
614 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
615 debug_error("remove device state changed callback failed");
621 int mm_sound_proxy_add_device_running_changed_callback(mm_sound_device_running_changed_wrapper_cb func, void* userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id)
623 int ret = MM_ERROR_NONE;
624 struct callback_data *cb_data;
628 CB_DATA_NEW(cb_data, func, userdata, freefunc);
630 if ((ret = mm_sound_dbus_signal_subscribe_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_EVENT_DEVICE_RUNNING_CHANGED, dbus_callback, cb_data, simple_callback_data_free_func, &cb_data->subs_id)) != MM_ERROR_NONE)
631 debug_error("Add device running changed callback failed");
633 *subs_id = cb_data->subs_id;
639 int mm_sound_proxy_remove_device_running_changed_callback(unsigned subs_id)
641 int ret = MM_ERROR_NONE;
644 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
645 debug_error("remove device running changed callback failed");
651 int mm_sound_proxy_set_volume_by_type(const char *volume_type, const unsigned volume_level)
653 int ret = MM_ERROR_NONE;
654 char *reply = NULL, *direction = "out";
655 GVariant *params = NULL, *result = NULL;
659 if ((params = g_variant_new("(ssu)", direction, volume_type, volume_level)) == NULL) {
660 debug_error("Construct Param for method call failed");
661 return MM_ERROR_SOUND_INTERNAL;
664 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_SET_VOLUME_LEVEL, params, &result)) != MM_ERROR_NONE) {
665 debug_error("dbus set volume by type failed");
666 g_variant_unref(result);
671 g_variant_get(result, "(&s)", &reply);
672 debug_log("reply : %s", reply);
673 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
674 ret = MM_ERROR_SOUND_INTERNAL;
675 g_variant_unref(result);
677 debug_error("reply null");
678 ret = MM_ERROR_SOUND_INTERNAL;
685 int mm_sound_proxy_add_volume_changed_callback(mm_sound_volume_changed_wrapper_cb func, void* userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id)
687 int ret = MM_ERROR_NONE;
688 struct callback_data *cb_data;
692 CB_DATA_NEW(cb_data, func, userdata, freefunc);
694 if ((ret = mm_sound_dbus_signal_subscribe_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_EVENT_VOLUME_CHANGED, dbus_callback, cb_data, simple_callback_data_free_func, &cb_data->subs_id)) != MM_ERROR_NONE)
695 debug_error("Add Volume changed callback failed");
697 *subs_id = cb_data->subs_id;
704 int mm_sound_proxy_remove_volume_changed_callback(unsigned subs_id)
706 int ret = MM_ERROR_NONE;
709 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
710 debug_error("Remove Volume changed callback failed");
716 int mm_sound_proxy_set_filter_by_type(const char *stream_type, const char *filter_name, const char *filter_parameters, const char *filter_group)
718 int ret = MM_ERROR_NONE;
720 GVariant *params = NULL, *result = NULL;
724 if ((params = g_variant_new("(ssss)", filter_name, filter_parameters, filter_group, stream_type)) == NULL) {
725 debug_error("construct param for method call failed");
726 return MM_ERROR_SOUND_INTERNAL;
729 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_SET_FILTER, params, &result)) != MM_ERROR_NONE)
730 debug_error("dbus set filter by type failed");
732 /* stream-manager always returns a string as return value */
734 g_variant_get(result, "(&s)", &reply);
735 debug_log("reply : %s", reply);
736 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
737 ret = MM_ERROR_SOUND_INTERNAL;
738 g_variant_unref(result);
740 debug_error("reply null");
741 if (ret == MM_ERROR_NONE)
742 ret = MM_ERROR_SOUND_INTERNAL;
749 int mm_sound_proxy_unset_filter_by_type(const char *stream_type)
751 int ret = MM_ERROR_NONE;
753 GVariant *params = NULL, *result = NULL;
757 if ((params = g_variant_new("(s)", stream_type)) == NULL) {
758 debug_error("construct param for method call failed");
759 return MM_ERROR_SOUND_INTERNAL;
762 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_UNSET_FILTER, params, &result)) != MM_ERROR_NONE)
763 debug_error("dbus unset filter by type failed");
765 /* stream-manager always returns a string as return value */
767 g_variant_get(result, "(&s)", &reply);
768 debug_log("reply : %s", reply);
769 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
770 ret = MM_ERROR_SOUND_INTERNAL;
771 g_variant_unref(result);
773 debug_error("reply null");
774 if (ret == MM_ERROR_NONE)
775 ret = MM_ERROR_SOUND_INTERNAL;
782 int mm_sound_proxy_control_filter_by_type(const char *stream_type, const char *filter_name, const char *filter_controls)
784 int ret = MM_ERROR_NONE;
786 GVariant *params = NULL, *result = NULL;
790 if ((params = g_variant_new("(sss)", filter_name, filter_controls, stream_type)) == NULL) {
791 debug_error("construct param for method call failed");
792 return MM_ERROR_SOUND_INTERNAL;
795 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_CONTROL_FILTER, params, &result)) != MM_ERROR_NONE)
796 debug_error("dbus control filter by type failed");
798 /* stream-manager always returns a string as return value */
800 g_variant_get(result, "(&s)", &reply);
801 debug_log("reply : %s", reply);
802 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
803 ret = MM_ERROR_SOUND_INTERNAL;
804 g_variant_unref(result);
806 debug_error("reply null");
807 if (ret == MM_ERROR_NONE)
808 ret = MM_ERROR_SOUND_INTERNAL;
811 g_variant_unref(result);
817 int mm_sound_proxy_play_tone_with_stream_info(int client_pid, int tone, char *stream_type, int stream_index, int volume, int repeat, int *codechandle)
819 int ret = MM_ERROR_NONE;
821 GVariant *params = NULL, *result = NULL;
826 debug_error("Param for play is null");
827 return MM_ERROR_INVALID_ARGUMENT;
830 if ((params = g_variant_new("(iiiisi)", tone, repeat, volume, client_pid, stream_type, stream_index)) == NULL) {
831 debug_error("Construct Param for method call failed");
832 return MM_ERROR_SOUND_INTERNAL;
835 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_DTMF_WITH_STREAM_INFO, params, &result)) != MM_ERROR_NONE) {
836 debug_error("dbus play tone failed");
837 g_variant_unref(result);
842 g_variant_get(result, "(i)", &handle);
843 debug_log("handle : %d", handle);
844 *codechandle = handle;
845 g_variant_unref(result);
847 debug_error("reply null");
848 ret = MM_ERROR_SOUND_INTERNAL;
855 int mm_sound_proxy_play_sound_with_stream_info(const char* filename, int repeat, int volume,
856 int client_pid, int *codechandle, char *stream_type, int stream_index)
858 int ret = MM_ERROR_NONE;
860 GVariant *params = NULL, *result = NULL;
862 if (!filename || !codechandle) {
863 debug_error("Param for play is null");
864 return MM_ERROR_INVALID_ARGUMENT;
869 if ((params = g_variant_new("(siiisi)", filename, repeat, volume, client_pid, stream_type, stream_index)) == NULL) {
870 debug_error("Construct Param for method call failed");
871 return MM_ERROR_SOUND_INTERNAL;
874 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_FILE_START_WITH_STREAM_INFO, params, &result)) != MM_ERROR_NONE) {
875 debug_error("dbus play file failed");
876 g_variant_unref(result);
881 g_variant_get(result, "(i)", &handle);
882 debug_log("handle : %d", handle);
883 *codechandle = handle;
884 g_variant_unref(result);
886 debug_error("reply null");
887 ret = MM_ERROR_SOUND_INTERNAL;
894 int mm_sound_proxy_stop_sound(int handle)
896 int ret = MM_ERROR_NONE;
897 GVariant *result = NULL;
901 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_FILE_STOP, g_variant_new("(i)", handle), &result)) != MM_ERROR_NONE)
902 debug_error("dbus stop file playing failed");
904 g_variant_unref(result);
910 int mm_sound_proxy_add_play_sound_end_callback(mm_sound_stop_callback_wrapper_func func, void* userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id)
912 int ret = MM_ERROR_NONE;
913 struct callback_data *cb_data;
917 CB_DATA_NEW(cb_data, func, userdata, freefunc);
919 if ((ret = mm_sound_dbus_signal_subscribe_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_EVENT_PLAY_FILE_END, dbus_callback, cb_data, simple_callback_data_free_func, &cb_data->subs_id)) != MM_ERROR_NONE)
920 debug_error("add play sound end callback failed");
922 *subs_id = cb_data->subs_id;
929 int mm_sound_proxy_remove_play_sound_end_callback(unsigned subs_id)
931 int ret = MM_ERROR_NONE;
934 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
935 debug_error("Remove Play File End callback failed");
941 int mm_sound_proxy_register_focus(int index, const char *stream_type, int *id)
943 int ret = MM_ERROR_NONE;
944 int pid = g_focus_sound_handle[index].focus_pid;
950 ret = mm_sound_focus_socket_register(pid, stream_type, &client_fd, id);
952 debug_error("failed to mm_sound_focus_socket_register(), ret[0x%x]", ret);
954 g_focus_sound_handle[index].client_fd = client_fd;
955 g_focus_sound_handle[index].handle = *id;
963 int mm_sound_proxy_unregister_focus(int index)
965 int ret = MM_ERROR_NONE;
966 int pid = g_focus_sound_handle[index].focus_pid;
967 int client_fd = g_focus_sound_handle[index].client_fd;
968 int id = g_focus_sound_handle[index].handle;
972 ret = mm_sound_focus_socket_unregister(pid, client_fd, id);
974 debug_error("failed to mm_sound_focus_socket_unregister(), client_fd[%d], id[%d], ret[0x%x]", client_fd, id, ret);
981 int mm_sound_proxy_set_focus_reacquisition(int index, bool reacquisition)
983 int ret = MM_ERROR_NONE;
984 int pid = g_focus_sound_handle[index].focus_pid;
985 int client_fd = g_focus_sound_handle[index].client_fd;
986 int id = g_focus_sound_handle[index].handle;
990 ret = mm_sound_focus_socket_set_reacquisition(pid, client_fd, id, reacquisition);
992 debug_error("failed to mm_sound_focus_socket_set_reacquisition(), ret[0x%x]", ret);
998 int mm_sound_proxy_get_acquired_focus_stream_type(int focus_type, char **stream_type, int *option, char **ext_info)
1000 int ret = MM_ERROR_NONE;
1004 ret = mm_sound_focus_socket_get_acquired_focus_stream_type(focus_type, stream_type, option, ext_info);
1006 debug_error("failed to mm_sound_focus_socket_get_acquired_focus_stream_type(), ret[0x%x]", ret);
1012 int mm_sound_proxy_acquire_focus(int index, mm_sound_focus_type_e type, int option, const char *ext_info)
1014 int ret = MM_ERROR_NONE;
1015 bool is_in_focus_cb_thread = false;
1016 int pid = g_focus_sound_handle[index].focus_pid;
1017 int client_fd = g_focus_sound_handle[index].client_fd;
1018 int id = g_focus_sound_handle[index].handle;
1022 mm_sound_client_is_focus_cb_thread(g_thread_self(), &is_in_focus_cb_thread);
1023 if (!is_in_focus_cb_thread) {
1024 if ((ret = mm_sound_focus_socket_acquire(pid, client_fd, id,
1025 type, option, ext_info ? ext_info : "", true)))
1026 debug_error("failed to mm_sound_focus_socket_acquire(), ret[0x%x]", ret);
1028 GVariant *params = NULL, *result = NULL;
1030 if ((params = g_variant_new("(iiiis)", pid, id, type, option, ext_info ? ext_info : "")) == NULL) {
1031 debug_error("Construct Param for method call failed");
1032 return MM_ERROR_SOUND_INTERNAL;
1035 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_ACQUIRE_FOCUS, params, &result)) != MM_ERROR_NONE)
1036 debug_error("dbus acquire focus failed");
1038 g_variant_unref(result);
1046 int mm_sound_proxy_release_focus(int index, mm_sound_focus_type_e type, int option, const char *ext_info)
1048 int ret = MM_ERROR_NONE;
1049 bool is_in_focus_cb_thread = false;
1050 int pid = g_focus_sound_handle[index].focus_pid;
1051 int client_fd = g_focus_sound_handle[index].client_fd;
1052 int id = g_focus_sound_handle[index].handle;
1056 mm_sound_client_is_focus_cb_thread(g_thread_self(), &is_in_focus_cb_thread);
1057 if (!is_in_focus_cb_thread) {
1058 if ((ret = mm_sound_focus_socket_release(pid, client_fd, id, type, option, ext_info ? ext_info : "", true)))
1059 debug_error("failed to mm_sound_focus_socket_release(), ret[0x%x]", ret);
1061 GVariant *params = NULL, *result = NULL;
1063 if ((params = g_variant_new("(iiiis)", pid, id, type, option, ext_info ? ext_info : "")) == NULL) {
1064 debug_error("Construct Param for method call failed");
1065 return MM_ERROR_SOUND_INTERNAL;
1068 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_RELEASE_FOCUS, params, &result)) != MM_ERROR_NONE)
1069 debug_error("dbus release focus failed");
1071 g_variant_unref(result);
1079 int mm_sound_proxy_update_stream_focus_status(int focus_id, unsigned int status)
1081 int ret = MM_ERROR_NONE;
1083 GVariant *params = NULL, *result = NULL;
1087 if ((params = g_variant_new("(iu)", focus_id, status)) == NULL) {
1088 debug_error("Construct Param for method call failed");
1089 return MM_ERROR_SOUND_INTERNAL;
1092 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_UPDATE_STREAM_FOCUS_STATUS, params, &result)) != MM_ERROR_NONE)
1093 debug_error("dbus set volume by type failed");
1095 /* stream-manager always returns a string as return value */
1097 g_variant_get(result, "(&s)", &reply);
1098 debug_log("reply : %s", reply);
1099 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
1100 ret = MM_ERROR_SOUND_INTERNAL;
1101 g_variant_unref(result);
1103 debug_error("reply null");
1104 ret = MM_ERROR_SOUND_INTERNAL;
1112 int mm_sound_proxy_deliver_focus(int src_index, int dst_index, mm_sound_focus_type_e focus_type)
1114 int ret = MM_ERROR_NONE;
1115 int pid = g_focus_sound_handle[src_index].focus_pid;
1116 int src_client_fd = g_focus_sound_handle[src_index].client_fd;
1117 int src_server_fd = g_focus_sound_handle[src_index].handle;
1118 int dst_client_fd = g_focus_sound_handle[dst_index].client_fd;
1119 int dst_server_fd = g_focus_sound_handle[dst_index].handle;
1123 ret = mm_sound_focus_socket_deliver(pid, src_client_fd, src_server_fd, dst_client_fd, dst_server_fd, focus_type);
1125 debug_error("failed to mm_sound_focus_socket_deliver(), ret[0x%x]", ret);
1131 int mm_sound_proxy_add_focus_watch_callback(int index, mm_sound_focus_type_e type)
1133 int ret = MM_ERROR_NONE;
1134 int pid = g_focus_sound_handle[index].focus_pid;
1140 ret = mm_sound_focus_socket_add_watch_cb(pid, type, &client_fd, &id);
1142 debug_error("failed to mm_sound_focus_socket_add_watch_cb(), ret[0x%x]", ret);
1144 g_focus_sound_handle[index].handle = id;
1145 g_focus_sound_handle[index].client_fd = client_fd;
1153 int mm_sound_proxy_remove_focus_watch_callback(int index)
1155 int ret = MM_ERROR_NONE;
1156 int pid = g_focus_sound_handle[index].focus_pid;
1157 int client_fd = g_focus_sound_handle[index].client_fd;
1158 int id = g_focus_sound_handle[index].handle;
1162 ret = mm_sound_focus_socket_remove_watch_cb(pid, client_fd, id);
1164 debug_error("failed to mm_sound_focus_socket_remove_watch_cb(), ret[0x%x]", ret);
1171 int mm_sound_proxy_initialize(void)
1173 int ret = MM_ERROR_NONE;
1181 int mm_sound_proxy_finalize(void)
1183 int ret = MM_ERROR_NONE;