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"
17 struct callback_data {
20 mm_sound_proxy_userdata_free free_func;
24 #define CB_DATA_NEW(_cb_data, _func, _userdata, _freefunc) \
26 _cb_data = (struct callback_data*) g_malloc0(sizeof(struct callback_data)); \
27 _cb_data->user_cb = _func; \
28 _cb_data->user_data = _userdata; \
29 _cb_data->free_func = _freefunc; \
30 _cb_data->subs_id = 0; \
33 /* subscribe is true when add callback,
34 * false when remove callback */
35 static int _notify_subscription(audio_event_t event, uint32_t subs_id, gboolean subscribe)
37 int ret = MM_ERROR_NONE;
38 GVariant *params = NULL;
39 const char *event_name = NULL;
43 if ((ret = mm_sound_dbus_get_event_name(event, &event_name) != MM_ERROR_NONE)) {
44 debug_error("Failed to get event name");
45 return MM_ERROR_SOUND_INTERNAL;
48 if (!(params = g_variant_new("(sub)", event_name, subs_id, subscribe))) {
49 debug_error("Construct Param failed");
50 return MM_ERROR_SOUND_INTERNAL;
53 if ((ret = mm_sound_dbus_emit_signal(AUDIO_PROVIDER_AUDIO_CLIENT, AUDIO_EVENT_CLIENT_SUBSCRIBED, params)))
54 debug_error("dbus send signal for client subscribed failed");
60 static int _notify_signal_handled(audio_event_t event, uint32_t event_id, uint32_t subs_id, GVariant *signal_params)
62 int ret = MM_ERROR_NONE;
63 GVariant *params = NULL;
64 const char *event_name = NULL;
68 if ((ret = mm_sound_dbus_get_event_name(event, &event_name) != MM_ERROR_NONE)) {
69 debug_error("Failed to get event name");
70 return MM_ERROR_SOUND_INTERNAL;
73 if (!(params = g_variant_new("(usuv)", event_id, event_name, subs_id, signal_params))) {
74 debug_error("Construct Param failed");
75 return MM_ERROR_SOUND_INTERNAL;
78 if ((ret = mm_sound_dbus_emit_signal(AUDIO_PROVIDER_AUDIO_CLIENT, AUDIO_EVENT_CLIENT_HANDLED, params)))
79 debug_error("dbus send signal for client handled failed");
85 static int parse_device_variant(GVariant *v, int *device_id, const char **device_type, int *direction, int *state,
86 const char **device_name, int *vendor_id, int *product_id, bool *is_running, int *stream_id, int *stream_num)
90 GVariantIter iter, array_iter;
92 int ret = MM_ERROR_NONE;
95 debug_error("Variant NULL");
99 v_type = g_variant_get_type_string(v);
100 if (g_variant_type_equal(v_type, "(isiisiibai)") == FALSE) {
101 debug_error("device variant type not matching '%s'", v_type);
102 return MM_ERROR_NONE;
105 g_variant_iter_init(&iter, v);
106 g_variant_iter_next(&iter, "i", device_id);
107 g_variant_iter_next(&iter, "&s", device_type);
108 g_variant_iter_next(&iter, "i", direction);
109 g_variant_iter_next(&iter, "i", state);
110 g_variant_iter_next(&iter, "&s", device_name);
111 g_variant_iter_next(&iter, "i", vendor_id);
112 g_variant_iter_next(&iter, "i", product_id);
113 g_variant_iter_next(&iter, "b", is_running);
115 array_v = g_variant_iter_next_value(&iter);
116 *stream_num = g_variant_iter_init(&array_iter, array_v);
117 if (*stream_num > MAX_STREAM_ON_DEVICE) {
118 debug_error("too many streams on device %d", *stream_num);
119 ret = MM_ERROR_SOUND_INTERNAL;
123 while (g_variant_iter_loop(&array_iter, "i", &stream_id[i++])) ;
125 g_variant_unref(array_v);
130 /* This callback unmarshall general-formed paramters to subject specific parameters,
131 * and call proper callback */
132 static void dbus_callback(audio_event_t event, GVariant *params, void *userdata)
134 struct callback_data *cb_data = (struct callback_data*) userdata;
136 const char *name = NULL, *device_type = NULL;
137 int device_id, direction, state;
141 int stream_id[MAX_STREAM_ON_DEVICE];
143 int vendor_id, product_id;
144 bool is_running = FALSE;
146 v_type = g_variant_get_type_string(params);
148 if (event == AUDIO_EVENT_VOLUME_CHANGED) {
149 char *volume_type_str = NULL, *direction = NULL;
150 unsigned volume_level;
152 g_variant_get(params, "(&s&su)", &direction, &volume_type_str, &volume_level);
153 ((mm_sound_volume_changed_wrapper_cb)(cb_data->user_cb))(direction, volume_type_str, volume_level, cb_data->user_data);
154 } else if (event == AUDIO_EVENT_DEVICE_CONNECTED) {
155 bool is_connected = false;
157 if (g_variant_type_equal(v_type, "(u(isiisiibai)b)") == FALSE) {
158 debug_error("Device connection changed signature not matching : %s", v_type);
161 g_variant_iter_init(&iter, params);
162 g_variant_iter_next(&iter, "u", &event_id);
163 device_v = g_variant_iter_next_value(&iter);
164 if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
165 &name, &vendor_id, &product_id, &is_running, stream_id, &stream_num) < 0) {
166 debug_error("Failed to parse device variant");
169 g_variant_iter_next(&iter, "b", &is_connected);
171 ((mm_sound_device_connected_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
172 state, name, vendor_id, product_id, is_running, stream_id, stream_num, is_connected, cb_data->user_data);
173 _notify_signal_handled(event, event_id, cb_data->subs_id, g_variant_new("(ib)", device_id, is_connected));
174 } else if (event == AUDIO_EVENT_DEVICE_INFO_CHANGED) {
175 int changed_device_info_type = 0;
177 if (g_variant_type_equal(v_type, "(u(isiisiibai)i)") == FALSE) {
178 debug_error("Device information changed signature not matching : %s", v_type);
182 g_variant_iter_init(&iter, params);
183 g_variant_iter_next(&iter, "u", &event_id);
184 device_v = g_variant_iter_next_value(&iter);
185 if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
186 &name, &vendor_id, &product_id, &is_running, stream_id, &stream_num) < 0) {
187 debug_error("Failed to parse device variant");
190 g_variant_iter_next(&iter, "i", &changed_device_info_type);
192 ((mm_sound_device_info_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
193 state, name, vendor_id, product_id, is_running, stream_id, stream_num, changed_device_info_type, cb_data->user_data);
194 } else if (event == AUDIO_EVENT_DEVICE_STATE_CHANGED) {
196 if (g_variant_type_equal(v_type, "(u(isiisiibai))") == FALSE) {
197 debug_error("Device state changed signature not matching : %s", v_type);
201 g_variant_iter_init(&iter, params);
202 g_variant_iter_next(&iter, "u", &event_id);
203 device_v = g_variant_iter_next_value(&iter);
204 if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
205 &name, &vendor_id, &product_id, &is_running, stream_id, &stream_num) < 0) {
206 debug_error("Failed to parse device variant");
210 ((mm_sound_device_state_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
211 state, name, vendor_id, product_id, is_running, stream_id, stream_num, cb_data->user_data);
212 } else if (event == AUDIO_EVENT_DEVICE_RUNNING_CHANGED) {
214 if (g_variant_type_equal(v_type, "(u(isiisiibai))") == FALSE) {
215 debug_error("Device state changed signature not matching : %s", v_type);
219 g_variant_iter_init(&iter, params);
220 g_variant_iter_next(&iter, "u", &event_id);
221 device_v = g_variant_iter_next_value(&iter);
222 if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
223 &name, &vendor_id, &product_id, &is_running, stream_id, &stream_num) < 0) {
224 debug_error("Failed to parse device variant");
228 ((mm_sound_device_running_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
229 state, name, vendor_id, product_id, is_running, stream_id, stream_num, cb_data->user_data);
230 } else if (event == AUDIO_EVENT_FOCUS_CHANGED) {
231 } else if (event == AUDIO_EVENT_FOCUS_WATCH) {
232 } else if (event == AUDIO_EVENT_TEST) {
234 g_variant_get(params, "(i)", &test_var);
235 ((mm_sound_test_cb)(cb_data->user_cb))(test_var, cb_data->user_data);
236 } else if (event == AUDIO_EVENT_PLAY_FILE_END) {
237 int ended_handle = 0;
238 g_variant_get(params, "(i)", &ended_handle);
239 ((mm_sound_stop_callback_wrapper_func)(cb_data->user_cb))(ended_handle, cb_data->user_data);
243 static void simple_callback_data_free_func(void *data)
245 struct callback_data *cb_data = (struct callback_data*) data;
248 if (cb_data->free_func)
249 cb_data->free_func(cb_data->user_data);
254 int mm_sound_proxy_add_test_callback(mm_sound_test_cb func, void *userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id)
256 int ret = MM_ERROR_NONE;
257 struct callback_data *cb_data;
261 CB_DATA_NEW(cb_data, func, userdata, freefunc);
263 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)
264 debug_error("add test callback failed");
266 *subs_id = cb_data->subs_id;
272 int mm_sound_proxy_remove_test_callback(unsigned subs_id)
274 int ret = MM_ERROR_NONE;
277 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
278 debug_error("remove test callback failed");
284 int mm_sound_proxy_test(int a, int b, int *get)
286 int ret = MM_ERROR_NONE;
288 GVariant *params = NULL, *result = NULL;
292 params = g_variant_new("(ii)", a, b);
294 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_TEST, params, &result)) != MM_ERROR_NONE) {
295 debug_error("dbus test call failed");
299 debug_error("Construct Param for method call failed");
300 return MM_ERROR_SOUND_INTERNAL;
304 g_variant_get(result, "(i)", &reply);
305 debug_log("reply : %d", reply);
308 debug_error("reply null");
313 g_variant_unref(result);
319 int mm_sound_proxy_is_stream_on_device(int stream_id, int device_id, bool *is_on)
321 int ret = MM_ERROR_NONE;
322 GVariant *params, *result;
328 debug_error("Invalid Parameter, is_on null");
329 return MM_ERROR_INVALID_ARGUMENT;
332 if ((params = g_variant_new("(ii)", stream_id, device_id)) == NULL) {
333 debug_error("Construct Param for query is stream on device failed");
334 return MM_ERROR_SOUND_INTERNAL;
337 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_IS_STREAM_ON_DEVICE, params, &result)) != MM_ERROR_NONE) {
338 debug_error("is stream on device failed");
343 g_variant_get(result, "(b)", &_is_on);
344 debug_log("is_on : %d", _is_on);
345 *is_on = (bool)_is_on;
347 debug_error("reply null");
348 ret = MM_ERROR_SOUND_INTERNAL;
353 g_variant_unref(params);
355 g_variant_unref(result);
362 #define _VCONF_KEY_SOUND_SPEAKER_SELECTION "file/private/sound/feature/SpeakerSelection"
363 #define _AUDIO_TV_OUTPUT_BT_HEADSET 5
365 static mm_sound_device_t* _get_tv_bt_device(void)
367 int speaker_value = 0;
368 mm_sound_device_t* device_item = NULL;
370 if (vconf_get_int(_VCONF_KEY_SOUND_SPEAKER_SELECTION, &speaker_value) == VCONF_ERROR) {
371 debug_error("vconf_get_int(%s) failed..", _VCONF_KEY_SOUND_SPEAKER_SELECTION);
375 debug_warning("speaker selection value = %d", speaker_value);
376 if (speaker_value != _AUDIO_TV_OUTPUT_BT_HEADSET)
379 device_item = g_malloc0(sizeof(mm_sound_device_t));
383 MMSOUND_STRNCPY(device_item->name, "BluetoothMedia", MAX_DEVICE_NAME_NUM);
384 MMSOUND_STRNCPY(device_item->type, "bt-a2dp", MAX_DEVICE_TYPE_STR_LEN);
385 device_item->id = 99;
386 device_item->io_direction = DEVICE_IO_DIRECTION_OUT;
387 device_item->state = DEVICE_STATE_ACTIVATED;
388 device_item->vendor_id = -1;
389 device_item->product_id = -1;
390 device_item->stream_num = -1;
394 #endif /* TIZEN_TV */
396 int mm_sound_proxy_get_current_connected_device_list(int device_flags, GList** device_list)
398 int ret = MM_ERROR_NONE;
399 GVariant *result = NULL, *child = NULL;
400 GVariant *params = NULL;
402 mm_sound_device_t* device_item;
403 const gchar *device_name_tmp = NULL, *device_type_tmp = NULL;
408 debug_error("Invalid Parameter, device_list null");
409 ret = MM_ERROR_INVALID_ARGUMENT;
413 params = g_variant_new("(i)", device_flags);
416 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_GET_CONNECTED_DEVICE_LIST, params, &result)) != MM_ERROR_NONE) {
417 debug_error("Get current connected device list failed");
421 debug_error("Construct Param for get current connected device failed");
422 return MM_ERROR_SOUND_INTERNAL;
425 child = g_variant_get_child_value(result, 0);
426 g_variant_iter_init(&iter, child);
428 device_item = g_malloc0(sizeof(mm_sound_device_t));
429 if (device_item && g_variant_iter_loop(&iter, "(i&sii&siib)",
430 &device_item->id, &device_type_tmp, &device_item->io_direction, &device_item->state,
431 &device_name_tmp, &device_item->vendor_id, &device_item->product_id, &device_item->is_running)) {
432 MMSOUND_STRNCPY(device_item->name, device_name_tmp, MAX_DEVICE_NAME_NUM);
433 MMSOUND_STRNCPY(device_item->type, device_type_tmp, MAX_DEVICE_TYPE_STR_LEN);
434 *device_list = g_list_append(*device_list, device_item);
435 debug_log("Added device id(%d) type(%17s) direction(%d) state(%d) name(%s) vendor-id(%04x) product-id(%04x) is_running(%d)",
436 device_item->id, device_item->type, device_item->io_direction, device_item->state,
437 device_item->name, device_item->vendor_id, device_item->product_id, device_item->is_running);
438 device_item->stream_num = -1;
448 device_item = _get_tv_bt_device();
450 *device_list = g_list_append(*device_list, device_item);
451 debug_msg("Added TV bt device id(%d) type(%17s) direction(%d) state(%d) name(%s) vendor-id(%04x) product-id(%04x)",
452 device_item->id, device_item->type, device_item->io_direction, device_item->state,
453 device_item->name, device_item->vendor_id, device_item->product_id);
455 #endif /* TIZEN_TV */
459 g_variant_unref(result);
465 int mm_sound_proxy_get_device_by_id(int device_id, mm_sound_device_t **device)
467 int ret = MM_ERROR_NONE;
468 GVariant *params = NULL, *result = NULL;
469 mm_sound_device_t* device_item = NULL;
470 const gchar *device_name_tmp = NULL, *device_type_tmp = NULL;
474 if (!device || device_id < 1) {
475 debug_error("Invalid Parameter, device null or improper device id");
476 return MM_ERROR_INVALID_ARGUMENT;
479 if ((params = g_variant_new("(i)", device_id)) == NULL) {
480 debug_error("Construct Param for get device by id failed");
481 return MM_ERROR_SOUND_INTERNAL;
484 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_GET_DEVICE_BY_ID, params, &result)) != MM_ERROR_NONE) {
485 debug_error("get device by id failed");
486 ret = MM_ERROR_SOUND_NO_DATA;
491 if ((device_item = g_malloc0(sizeof(mm_sound_device_t))) == NULL) {
492 debug_error("Alloc device handle failed");
493 ret = MM_ERROR_SOUND_INTERNAL;
497 g_variant_get(result, "(i&sii&sii)",
498 &device_item->id, &device_type_tmp, &device_item->io_direction,
499 &device_item->state, &device_name_tmp,
500 &device_item->vendor_id, &device_item->product_id);
501 MMSOUND_STRNCPY(device_item->name, device_name_tmp, MAX_DEVICE_NAME_NUM);
502 MMSOUND_STRNCPY(device_item->type, device_type_tmp, MAX_DEVICE_TYPE_STR_LEN);
503 debug_log("Get device id(%d) type(%17s) direction(%d) state(%d) name(%s) vendor-id(%04x) product-id(%04x)",
504 device_item->id, device_item->type, device_item->io_direction,
505 device_item->state, device_item->name,
506 device_item->vendor_id, device_item->product_id);
507 device_item->stream_num = -1;
508 *device = device_item;
510 debug_error("reply null");
511 ret = MM_ERROR_SOUND_INTERNAL;
516 g_variant_unref(result);
522 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)
524 int ret = MM_ERROR_NONE;
525 struct callback_data *cb_data;
529 CB_DATA_NEW(cb_data, func, userdata, freefunc);
531 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) {
532 debug_error("add device connected callback failed");
536 if ((ret = _notify_subscription(AUDIO_EVENT_DEVICE_CONNECTED, cb_data->subs_id, TRUE)) != MM_ERROR_NONE) {
537 debug_error("failed to notify subscription of device connected event");
541 *subs_id = cb_data->subs_id;
548 int mm_sound_proxy_remove_device_connected_callback(unsigned subs_id)
550 int ret = MM_ERROR_NONE;
553 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
554 debug_error("remove device connected callback failed");
558 if ((ret = _notify_subscription(AUDIO_EVENT_DEVICE_CONNECTED, subs_id, FALSE)) != MM_ERROR_NONE)
559 debug_error("failed to notify unsubscription of device connected event");
566 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)
568 int ret = MM_ERROR_NONE;
569 struct callback_data *cb_data;
573 CB_DATA_NEW(cb_data, func, userdata, freefunc);
575 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)
576 debug_error("Add device info changed callback failed");
578 *subs_id = cb_data->subs_id;
584 int mm_sound_proxy_remove_device_info_changed_callback(unsigned subs_id)
586 int ret = MM_ERROR_NONE;
589 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
590 debug_error("remove device info changed callback failed");
596 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)
598 int ret = MM_ERROR_NONE;
599 struct callback_data *cb_data;
603 CB_DATA_NEW(cb_data, func, userdata, freefunc);
605 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)
606 debug_error("Add device state changed callback failed");
608 *subs_id = cb_data->subs_id;
614 int mm_sound_proxy_remove_device_state_changed_callback(unsigned subs_id)
616 int ret = MM_ERROR_NONE;
619 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
620 debug_error("remove device state changed callback failed");
626 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)
628 int ret = MM_ERROR_NONE;
629 struct callback_data *cb_data;
633 CB_DATA_NEW(cb_data, func, userdata, freefunc);
635 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)
636 debug_error("Add device running changed callback failed");
638 *subs_id = cb_data->subs_id;
644 int mm_sound_proxy_remove_device_running_changed_callback(unsigned subs_id)
646 int ret = MM_ERROR_NONE;
649 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
650 debug_error("remove device running changed callback failed");
656 int mm_sound_proxy_set_volume_by_type(const char *volume_type, const unsigned volume_level)
658 int ret = MM_ERROR_NONE;
659 char *reply = NULL, *direction = "out";
660 GVariant *params = NULL, *result = NULL;
664 params = g_variant_new("(ssu)", direction, volume_type, volume_level);
666 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_SET_VOLUME_LEVEL, params, &result)) != MM_ERROR_NONE) {
667 debug_error("dbus set volume by type failed");
671 debug_error("Construct Param for method call failed");
672 return MM_ERROR_SOUND_INTERNAL;
676 g_variant_get(result, "(&s)", &reply);
677 debug_log("reply : %s", reply);
678 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
679 ret = MM_ERROR_SOUND_INTERNAL;
681 debug_error("reply null");
686 g_variant_unref(result);
692 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)
694 int ret = MM_ERROR_NONE;
695 struct callback_data *cb_data;
699 CB_DATA_NEW(cb_data, func, userdata, freefunc);
701 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)
702 debug_error("Add Volume changed callback failed");
704 *subs_id = cb_data->subs_id;
712 int mm_sound_proxy_remove_volume_changed_callback(unsigned subs_id)
714 int ret = MM_ERROR_NONE;
717 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
718 debug_error("Remove Volume changed callback failed");
724 int mm_sound_proxy_set_filter_by_type(const char *stream_type, const char *filter_name, const char *filter_parameters, const char *filter_group)
726 int ret = MM_ERROR_NONE;
728 GVariant *params = NULL, *result = NULL;
732 params = g_variant_new("(ssss)", filter_name, filter_parameters, filter_group, stream_type);
734 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_SET_FILTER, params, &result)) != MM_ERROR_NONE) {
735 debug_error("dbus set filter by type failed");
739 debug_error("construct param for method call failed");
740 return MM_ERROR_SOUND_INTERNAL;
744 g_variant_get(result, "(&s)", &reply);
745 debug_log("reply : %s", reply);
746 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
747 ret = MM_ERROR_SOUND_INTERNAL;
749 debug_error("reply null");
754 g_variant_unref(result);
760 int mm_sound_proxy_unset_filter_by_type(const char *stream_type)
762 int ret = MM_ERROR_NONE;
764 GVariant *params = NULL, *result = NULL;
768 params = g_variant_new("(s)", stream_type);
770 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_UNSET_FILTER, params, &result)) != MM_ERROR_NONE) {
771 debug_error("dbus unset filter by type failed");
775 debug_error("construct param for method call failed");
776 return MM_ERROR_SOUND_INTERNAL;
780 g_variant_get(result, "(&s)", &reply);
781 debug_log("reply : %s", reply);
782 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
783 ret = MM_ERROR_SOUND_INTERNAL;
785 debug_error("reply null");
790 g_variant_unref(result);
796 int mm_sound_proxy_control_filter_by_type(const char *stream_type, const char *filter_name, const char *filter_controls)
798 int ret = MM_ERROR_NONE;
800 GVariant *params = NULL, *result = NULL;
804 params = g_variant_new("(sss)", filter_name, filter_controls, stream_type);
806 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_CONTROL_FILTER, params, &result)) != MM_ERROR_NONE) {
807 debug_error("dbus control filter by type failed");
811 debug_error("construct param for method call failed");
812 return MM_ERROR_SOUND_INTERNAL;
816 g_variant_get(result, "(&s)", &reply);
817 debug_log("reply : %s", reply);
818 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
819 ret = MM_ERROR_SOUND_INTERNAL;
821 debug_error("reply null");
826 g_variant_unref(result);
832 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)
834 int ret = MM_ERROR_NONE;
836 GVariant *params = NULL, *result = NULL;
841 debug_error("Param for play is null");
842 return MM_ERROR_INVALID_ARGUMENT;
845 params = g_variant_new("(iiiisi)", tone, repeat, volume, client_pid, stream_type, stream_index);
847 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_DTMF_WITH_STREAM_INFO, params, &result)) != MM_ERROR_NONE) {
848 debug_error("dbus play tone failed");
852 debug_error("Construct Param for method call failed");
856 g_variant_get(result, "(i)", &handle);
857 debug_log("handle : %d", handle);
858 *codechandle = handle;
860 debug_error("reply null");
865 g_variant_unref(result);
871 int mm_sound_proxy_play_sound_with_stream_info(const char* filename, int repeat, int volume,
872 int client_pid, int *codechandle, char *stream_type, int stream_index)
874 int ret = MM_ERROR_NONE;
876 GVariant *params = NULL, *result = NULL;
878 if (!filename || !codechandle) {
879 debug_error("Param for play is null");
880 return MM_ERROR_INVALID_ARGUMENT;
885 params = g_variant_new("(siiisi)", filename, repeat, volume, client_pid, stream_type, stream_index);
887 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) {
888 debug_error("dbus play file failed");
892 debug_error("Construct Param for method call failed");
896 g_variant_get(result, "(i)", &handle);
897 debug_log("handle : %d", handle);
898 *codechandle = handle;
900 debug_error("reply null");
905 g_variant_unref(result);
913 int mm_sound_proxy_stop_sound(int handle)
915 int ret = MM_ERROR_NONE;
916 GVariant *result = NULL;
920 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) {
921 debug_error("dbus stop file playing failed");
927 g_variant_unref(result);
933 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)
935 int ret = MM_ERROR_NONE;
936 struct callback_data *cb_data;
940 CB_DATA_NEW(cb_data, func, userdata, freefunc);
942 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)
943 debug_error("add play sound end callback failed");
945 *subs_id = cb_data->subs_id;
952 int mm_sound_proxy_remove_play_sound_end_callback(unsigned subs_id)
954 int ret = MM_ERROR_NONE;
957 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
958 debug_error("Remove Play File End callback failed");
964 int mm_sound_proxy_emergent_exit(int exit_pid)
966 int ret = MM_ERROR_NONE;
967 GVariant *params = NULL;
973 params = g_variant_new("(i)", exit_pid);
975 if ((ret = mm_sound_dbus_emit_signal(AUDIO_PROVIDER_AUDIO_CLIENT, AUDIO_EVENT_EMERGENT_EXIT, params)) != MM_ERROR_NONE) {
977 debug_error("dbus emergent exit failed");
983 debug_error("Construct Param for emergent exit signal failed");
985 ret = MM_ERROR_SOUND_INTERNAL;
996 /*------------------------------------------ FOCUS --------------------------------------------------*/
999 int mm_sound_proxy_get_unique_id(int *id)
1001 int ret = MM_ERROR_NONE;
1003 GVariant *result = NULL;
1007 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_GET_UNIQUE_ID, NULL, &result)) != MM_ERROR_NONE)
1008 debug_error("dbus get unique id failed");
1011 g_variant_get(result, "(i)", &res);
1013 debug_msg("got unique id(%d)", *id);
1014 g_variant_unref(result);
1022 int mm_sound_proxy_register_focus(int id, int instance, const char *stream_type, mm_sound_focus_changed_cb callback, void* userdata)
1024 int ret = MM_ERROR_NONE;
1025 GVariant *params = NULL, *result = NULL;
1029 params = g_variant_new("(iis)", instance, id, stream_type);
1031 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_REGISTER_FOCUS, params, &result)) != MM_ERROR_NONE)
1032 debug_error("dbus register focus failed");
1034 debug_error("Construct Param for method call failed");
1037 if (ret != MM_ERROR_NONE)
1038 g_variant_get(result, "(i)", &ret);
1040 g_variant_unref(result);
1048 int mm_sound_proxy_unregister_focus(int instance, int id)
1050 int ret = MM_ERROR_NONE;
1051 GVariant *params = NULL, *result = NULL;
1055 params = g_variant_new("(ii)", instance, id);
1057 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_UNREGISTER_FOCUS, params, &result)) != MM_ERROR_NONE)
1058 debug_error("dbus unregister focus failed");
1060 debug_error("Construct Param for method call failed");
1063 if (ret != MM_ERROR_NONE)
1064 g_variant_get(result, "(i)", &ret);
1066 g_variant_unref(result);
1073 int mm_sound_proxy_set_focus_reacquisition(int instance, int id, bool reacquisition)
1075 int ret = MM_ERROR_NONE;
1076 GVariant *params = NULL, *result = NULL;
1080 params = g_variant_new("(iib)", instance, id, reacquisition);
1082 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_SET_FOCUS_REACQUISITION, params, &result)) != MM_ERROR_NONE)
1083 debug_error("dbus set focus reacquisition failed");
1085 debug_error("Construct Param for method call failed");
1088 if (ret != MM_ERROR_NONE)
1089 g_variant_get(result, "(i)", &ret);
1091 g_variant_unref(result);
1097 int mm_sound_proxy_get_acquired_focus_stream_type(int focus_type, char **stream_type, int *option, char **ext_info)
1099 int ret = MM_ERROR_NONE;
1100 GVariant *params = NULL, *result = NULL;
1104 if (!(params = g_variant_new("(i)", focus_type))) {
1105 debug_error("Construct Param for method call failed");
1106 return MM_ERROR_SOUND_INTERNAL;
1109 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_GET_ACQUIRED_FOCUS_STREAM_TYPE, params, &result)) == MM_ERROR_NONE) {
1111 g_variant_get(result, "(sis)", stream_type, option, ext_info);
1112 g_variant_unref(result);
1115 debug_error("dbus get stream type of acquired focus failed");
1122 int mm_sound_proxy_acquire_focus(int instance, int id, mm_sound_focus_type_e type, int option, const char *ext_info)
1124 int ret = MM_ERROR_NONE;
1125 bool is_in_focus_cb_thread = false;
1129 mm_sound_client_is_focus_cb_thread(g_thread_self(), &is_in_focus_cb_thread);
1130 if (is_in_focus_cb_thread) {
1131 if ((ret = mm_sound_focus_socket_acquire(instance, id, type, option, ext_info ? ext_info : "", true)))
1132 debug_error("failed to mm_sound_focus_socket_acquire(), ret[0x%x]", ret);
1134 GVariant *params = NULL, *result = NULL;
1136 params = g_variant_new("(iiiis)", instance, id, type, option, ext_info ? ext_info : "");
1138 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_ACQUIRE_FOCUS, params, &result)) != MM_ERROR_NONE)
1139 debug_error("dbus acquire focus failed");
1141 debug_error("Construct Param for method call failed");
1144 if (ret != MM_ERROR_NONE)
1145 g_variant_get(result, "(i)", &ret);
1147 g_variant_unref(result);
1154 int mm_sound_proxy_release_focus(int instance, int id, mm_sound_focus_type_e type, int option, const char *ext_info)
1156 int ret = MM_ERROR_NONE;
1157 bool is_in_focus_cb_thread = false;
1161 mm_sound_client_is_focus_cb_thread(g_thread_self(), &is_in_focus_cb_thread);
1162 if (is_in_focus_cb_thread) {
1163 if ((ret = mm_sound_focus_socket_release(instance, id, type, option, ext_info ? ext_info : "", true)))
1164 debug_error("failed to mm_sound_focus_socket_release(), ret[0x%x]", ret);
1166 GVariant *params = NULL, *result = NULL;
1168 params = g_variant_new("(iiiis)", instance, id, type, option, ext_info ? ext_info : "");
1170 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_RELEASE_FOCUS, params, &result)) != MM_ERROR_NONE)
1171 debug_error("dbus release focus failed");
1173 debug_error("Construct Param for method call failed");
1176 if (ret != MM_ERROR_NONE)
1177 g_variant_get(result, "(i)", &ret);
1179 g_variant_unref(result);
1186 int mm_sound_proxy_update_stream_focus_status(int focus_id, unsigned int status)
1188 int ret = MM_ERROR_NONE;
1190 GVariant *params = NULL, *result = NULL;
1194 params = g_variant_new("(iu)", focus_id, status);
1196 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_UPDATE_STREAM_FOCUS_STATUS, params, &result)) != MM_ERROR_NONE) {
1197 debug_error("dbus set volume by type failed");
1199 g_variant_get(result, "(&s)", &reply);
1200 debug_log("reply : %s", reply);
1201 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
1202 ret = MM_ERROR_SOUND_INTERNAL;
1206 debug_error("Construct Param for method call failed");
1207 return MM_ERROR_SOUND_INTERNAL;
1211 g_variant_unref(result);
1217 int mm_sound_proxy_deliver_focus(int pid, int src_id, int dst_id, mm_sound_focus_type_e focus_type)
1219 int ret = MM_ERROR_NONE;
1221 GVariant *params = NULL, *result = NULL;
1225 params = g_variant_new("(iiii)", pid, src_id, dst_id, focus_type);
1227 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_DELIVER_FOCUS, params, &result)) != MM_ERROR_NONE) {
1228 debug_error("dbus deliver focus failed");
1230 g_variant_get(result, "(&s)", &reply);
1231 debug_log("reply : %s", reply);
1232 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
1233 ret = MM_ERROR_SOUND_INTERNAL;
1237 debug_error("Construct Param for method call failed");
1238 return MM_ERROR_SOUND_INTERNAL;
1242 g_variant_unref(result);
1248 int mm_sound_proxy_set_focus_watch_callback(int instance, int handle, mm_sound_focus_type_e type, mm_sound_focus_changed_watch_cb callback, void* userdata)
1250 int ret = MM_ERROR_NONE;
1251 GVariant *params = NULL, *result = NULL;
1255 params = g_variant_new("(iii)", instance, handle, type);
1257 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_WATCH_FOCUS, params, &result)) != MM_ERROR_NONE)
1258 debug_error("dbus set watch focus failed");
1260 debug_error("Construct Param for method call failed");
1263 if (ret != MM_ERROR_NONE)
1264 g_variant_get(result, "(i)", &ret);
1266 g_variant_unref(result);
1273 int mm_sound_proxy_unset_focus_watch_callback(int focus_tid, int handle)
1275 int ret = MM_ERROR_NONE;
1276 GVariant *params = NULL, *result = NULL;
1280 params = g_variant_new("(ii)", focus_tid, handle);
1282 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_UNWATCH_FOCUS, params, &result)) != MM_ERROR_NONE)
1283 debug_error("dbus unset watch focus failed");
1285 debug_error("Construct Param for method call failed");
1287 if (ret != MM_ERROR_NONE)
1288 g_variant_get(result, "(i)", &ret);
1290 g_variant_unref(result);
1297 #endif /* USE_FOCUS */
1298 /*------------------------------------------ FOCUS --------------------------------------------------*/
1300 int mm_sound_proxy_initialize(void)
1302 int ret = MM_ERROR_NONE;
1310 int mm_sound_proxy_finalize(void)
1312 int ret = MM_ERROR_NONE;