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, bool *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 bool 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 bool 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, is_running, stream_id, stream_num, is_connected, cb_data->user_data);
176 _notify_signal_handled(event, event_id, cb_data->subs_id, g_variant_new("(ib)", device_id, 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, 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, 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, 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 params = g_variant_new("(ii)", a, b);
297 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_TEST, params, &result)) != MM_ERROR_NONE) {
298 debug_error("dbus test call failed");
302 debug_error("Construct Param for method call failed");
303 return MM_ERROR_SOUND_INTERNAL;
307 g_variant_get(result, "(i)", &reply);
308 debug_log("reply : %d", reply);
311 debug_error("reply null");
316 g_variant_unref(result);
322 int mm_sound_proxy_is_stream_on_device(int stream_id, int device_id, bool *is_on)
324 int ret = MM_ERROR_NONE;
325 GVariant *params, *result;
331 debug_error("Invalid Parameter, is_on null");
332 return MM_ERROR_INVALID_ARGUMENT;
335 if ((params = g_variant_new("(ii)", stream_id, device_id)) == NULL) {
336 debug_error("Construct Param for query is stream on device failed");
337 return MM_ERROR_SOUND_INTERNAL;
340 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_IS_STREAM_ON_DEVICE, params, &result)) != MM_ERROR_NONE) {
341 debug_error("is stream on device failed");
346 g_variant_get(result, "(b)", &_is_on);
347 debug_log("is_on : %d", _is_on);
348 *is_on = (bool)_is_on;
350 debug_error("reply null");
351 ret = MM_ERROR_SOUND_INTERNAL;
356 g_variant_unref(params);
358 g_variant_unref(result);
365 #define _VCONF_KEY_SOUND_SPEAKER_SELECTION "file/private/sound/feature/SpeakerSelection"
366 #define _AUDIO_TV_OUTPUT_BT_HEADSET 5
368 static mm_sound_device_t* _get_tv_bt_device(void)
370 int speaker_value = 0;
371 mm_sound_device_t* device_item = NULL;
373 if (vconf_get_int(_VCONF_KEY_SOUND_SPEAKER_SELECTION, &speaker_value) == VCONF_ERROR) {
374 debug_error("vconf_get_int(%s) failed..", _VCONF_KEY_SOUND_SPEAKER_SELECTION);
378 debug_warning("speaker selection value = %d", speaker_value);
379 if (speaker_value != _AUDIO_TV_OUTPUT_BT_HEADSET)
382 device_item = g_malloc0(sizeof(mm_sound_device_t));
386 MMSOUND_STRNCPY(device_item->name, "BluetoothMedia", MAX_DEVICE_NAME_NUM);
387 MMSOUND_STRNCPY(device_item->type, "bt-a2dp", MAX_DEVICE_TYPE_STR_LEN);
388 device_item->id = 99;
389 device_item->io_direction = DEVICE_IO_DIRECTION_OUT;
390 device_item->state = DEVICE_STATE_ACTIVATED;
391 device_item->vendor_id = -1;
392 device_item->product_id = -1;
393 device_item->stream_num = -1;
397 #endif /* TIZEN_TV */
399 int mm_sound_proxy_get_current_connected_device_list(int device_flags, GList** device_list)
401 int ret = MM_ERROR_NONE;
402 GVariant *result = NULL, *child = NULL;
403 GVariant *params = NULL;
405 mm_sound_device_t* device_item;
406 const gchar *device_name_tmp = NULL, *device_type_tmp = NULL;
411 debug_error("Invalid Parameter, device_list null");
412 ret = MM_ERROR_INVALID_ARGUMENT;
416 params = g_variant_new("(i)", device_flags);
419 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_GET_CONNECTED_DEVICE_LIST, params, &result)) != MM_ERROR_NONE) {
420 debug_error("Get current connected device list failed");
424 debug_error("Construct Param for get current connected device failed");
425 return MM_ERROR_SOUND_INTERNAL;
428 child = g_variant_get_child_value(result, 0);
429 g_variant_iter_init(&iter, child);
431 device_item = g_malloc0(sizeof(mm_sound_device_t));
432 if (device_item && g_variant_iter_loop(&iter, "(i&sii&siib)",
433 &device_item->id, &device_type_tmp, &device_item->io_direction, &device_item->state,
434 &device_name_tmp, &device_item->vendor_id, &device_item->product_id, &device_item->is_running)) {
435 MMSOUND_STRNCPY(device_item->name, device_name_tmp, MAX_DEVICE_NAME_NUM);
436 MMSOUND_STRNCPY(device_item->type, device_type_tmp, MAX_DEVICE_TYPE_STR_LEN);
437 *device_list = g_list_append(*device_list, device_item);
438 debug_log("Added device id(%d) type(%17s) direction(%d) state(%d) name(%s) vendor-id(%04x) product-id(%04x) is_running(%d)",
439 device_item->id, device_item->type, device_item->io_direction, device_item->state,
440 device_item->name, device_item->vendor_id, device_item->product_id, device_item->is_running);
441 device_item->stream_num = -1;
451 device_item = _get_tv_bt_device();
453 *device_list = g_list_append(*device_list, device_item);
454 debug_msg("Added TV bt device id(%d) type(%17s) direction(%d) state(%d) name(%s) vendor-id(%04x) product-id(%04x)",
455 device_item->id, device_item->type, device_item->io_direction, device_item->state,
456 device_item->name, device_item->vendor_id, device_item->product_id);
458 #endif /* TIZEN_TV */
462 g_variant_unref(result);
468 int mm_sound_proxy_get_device_by_id(int device_id, mm_sound_device_t **device)
470 int ret = MM_ERROR_NONE;
471 GVariant *params = NULL, *result = NULL;
472 mm_sound_device_t* device_item = NULL;
473 const gchar *device_name_tmp = NULL, *device_type_tmp = NULL;
477 if (!device || device_id < 1) {
478 debug_error("Invalid Parameter, device null or improper device id");
479 return MM_ERROR_INVALID_ARGUMENT;
482 if ((params = g_variant_new("(i)", device_id)) == NULL) {
483 debug_error("Construct Param for get device by id failed");
484 return MM_ERROR_SOUND_INTERNAL;
487 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_GET_DEVICE_BY_ID, params, &result)) != MM_ERROR_NONE) {
488 debug_error("get device by id failed");
489 ret = MM_ERROR_SOUND_NO_DATA;
494 if ((device_item = g_malloc0(sizeof(mm_sound_device_t))) == NULL) {
495 debug_error("Alloc device handle failed");
496 ret = MM_ERROR_SOUND_INTERNAL;
500 g_variant_get(result, "(i&sii&sii)",
501 &device_item->id, &device_type_tmp, &device_item->io_direction,
502 &device_item->state, &device_name_tmp,
503 &device_item->vendor_id, &device_item->product_id);
504 MMSOUND_STRNCPY(device_item->name, device_name_tmp, MAX_DEVICE_NAME_NUM);
505 MMSOUND_STRNCPY(device_item->type, device_type_tmp, MAX_DEVICE_TYPE_STR_LEN);
506 debug_log("Get device id(%d) type(%17s) direction(%d) state(%d) name(%s) vendor-id(%04x) product-id(%04x)",
507 device_item->id, device_item->type, device_item->io_direction,
508 device_item->state, device_item->name,
509 device_item->vendor_id, device_item->product_id);
510 device_item->stream_num = -1;
511 *device = device_item;
513 debug_error("reply null");
514 ret = MM_ERROR_SOUND_INTERNAL;
519 g_variant_unref(result);
525 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)
527 int ret = MM_ERROR_NONE;
528 struct callback_data *cb_data;
532 CB_DATA_NEW(cb_data, func, userdata, freefunc);
534 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) {
535 debug_error("add device connected callback failed");
539 if ((ret = _notify_subscription(AUDIO_EVENT_DEVICE_CONNECTED, cb_data->subs_id, TRUE)) != MM_ERROR_NONE) {
540 debug_error("failed to notify subscription of device connected event");
544 *subs_id = cb_data->subs_id;
551 int mm_sound_proxy_remove_device_connected_callback(unsigned subs_id)
553 int ret = MM_ERROR_NONE;
556 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
557 debug_error("remove device connected callback failed");
561 if ((ret = _notify_subscription(AUDIO_EVENT_DEVICE_CONNECTED, subs_id, FALSE)) != MM_ERROR_NONE)
562 debug_error("failed to notify unsubscription of device connected event");
569 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)
571 int ret = MM_ERROR_NONE;
572 struct callback_data *cb_data;
576 CB_DATA_NEW(cb_data, func, userdata, freefunc);
578 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)
579 debug_error("Add device info changed callback failed");
581 *subs_id = cb_data->subs_id;
587 int mm_sound_proxy_remove_device_info_changed_callback(unsigned subs_id)
589 int ret = MM_ERROR_NONE;
592 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
593 debug_error("remove device info changed callback failed");
599 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)
601 int ret = MM_ERROR_NONE;
602 struct callback_data *cb_data;
606 CB_DATA_NEW(cb_data, func, userdata, freefunc);
608 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)
609 debug_error("Add device state changed callback failed");
611 *subs_id = cb_data->subs_id;
617 int mm_sound_proxy_remove_device_state_changed_callback(unsigned subs_id)
619 int ret = MM_ERROR_NONE;
622 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
623 debug_error("remove device state changed callback failed");
629 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)
631 int ret = MM_ERROR_NONE;
632 struct callback_data *cb_data;
636 CB_DATA_NEW(cb_data, func, userdata, freefunc);
638 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)
639 debug_error("Add device running changed callback failed");
641 *subs_id = cb_data->subs_id;
647 int mm_sound_proxy_remove_device_running_changed_callback(unsigned subs_id)
649 int ret = MM_ERROR_NONE;
652 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
653 debug_error("remove device running changed callback failed");
659 int mm_sound_proxy_set_volume_by_type(const char *volume_type, const unsigned volume_level)
661 int ret = MM_ERROR_NONE;
662 char *reply = NULL, *direction = "out";
663 GVariant *params = NULL, *result = NULL;
667 params = g_variant_new("(ssu)", direction, volume_type, volume_level);
669 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_SET_VOLUME_LEVEL, params, &result)) != MM_ERROR_NONE) {
670 debug_error("dbus set volume by type failed");
674 debug_error("Construct Param for method call failed");
675 return MM_ERROR_SOUND_INTERNAL;
679 g_variant_get(result, "(&s)", &reply);
680 debug_log("reply : %s", reply);
681 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
682 ret = MM_ERROR_SOUND_INTERNAL;
684 debug_error("reply null");
689 g_variant_unref(result);
695 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)
697 int ret = MM_ERROR_NONE;
698 struct callback_data *cb_data;
702 CB_DATA_NEW(cb_data, func, userdata, freefunc);
704 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)
705 debug_error("Add Volume changed callback failed");
707 *subs_id = cb_data->subs_id;
715 int mm_sound_proxy_remove_volume_changed_callback(unsigned subs_id)
717 int ret = MM_ERROR_NONE;
720 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
721 debug_error("Remove Volume changed callback failed");
727 int mm_sound_proxy_set_filter_by_type(const char *stream_type, const char *filter_name, const char *filter_parameters, const char *filter_group)
729 int ret = MM_ERROR_NONE;
731 GVariant *params = NULL, *result = NULL;
735 params = g_variant_new("(ssss)", filter_name, filter_parameters, filter_group, stream_type);
737 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_SET_FILTER, params, &result)) != MM_ERROR_NONE) {
738 debug_error("dbus set filter by type failed");
742 debug_error("construct param for method call failed");
743 return MM_ERROR_SOUND_INTERNAL;
747 g_variant_get(result, "(&s)", &reply);
748 debug_log("reply : %s", reply);
749 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
750 ret = MM_ERROR_SOUND_INTERNAL;
752 debug_error("reply null");
757 g_variant_unref(result);
763 int mm_sound_proxy_unset_filter_by_type(const char *stream_type)
765 int ret = MM_ERROR_NONE;
767 GVariant *params = NULL, *result = NULL;
771 params = g_variant_new("(s)", stream_type);
773 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_UNSET_FILTER, params, &result)) != MM_ERROR_NONE) {
774 debug_error("dbus unset filter by type failed");
778 debug_error("construct param for method call failed");
779 return MM_ERROR_SOUND_INTERNAL;
783 g_variant_get(result, "(&s)", &reply);
784 debug_log("reply : %s", reply);
785 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
786 ret = MM_ERROR_SOUND_INTERNAL;
788 debug_error("reply null");
793 g_variant_unref(result);
799 int mm_sound_proxy_control_filter_by_type(const char *stream_type, const char *filter_name, const char *filter_controls)
801 int ret = MM_ERROR_NONE;
803 GVariant *params = NULL, *result = NULL;
807 params = g_variant_new("(sss)", filter_name, filter_controls, stream_type);
809 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_CONTROL_FILTER, params, &result)) != MM_ERROR_NONE) {
810 debug_error("dbus control filter by type failed");
814 debug_error("construct param for method call failed");
815 return MM_ERROR_SOUND_INTERNAL;
819 g_variant_get(result, "(&s)", &reply);
820 debug_log("reply : %s", reply);
821 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
822 ret = MM_ERROR_SOUND_INTERNAL;
824 debug_error("reply null");
829 g_variant_unref(result);
835 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)
837 int ret = MM_ERROR_NONE;
839 GVariant *params = NULL, *result = NULL;
844 debug_error("Param for play is null");
845 return MM_ERROR_INVALID_ARGUMENT;
848 params = g_variant_new("(iiiisi)", tone, repeat, volume, client_pid, stream_type, stream_index);
850 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_DTMF_WITH_STREAM_INFO, params, &result)) != MM_ERROR_NONE) {
851 debug_error("dbus play tone failed");
855 debug_error("Construct Param for method call failed");
859 g_variant_get(result, "(i)", &handle);
860 debug_log("handle : %d", handle);
861 *codechandle = handle;
863 debug_error("reply null");
868 g_variant_unref(result);
874 int mm_sound_proxy_play_sound_with_stream_info(const char* filename, int repeat, int volume,
875 int client_pid, int *codechandle, char *stream_type, int stream_index)
877 int ret = MM_ERROR_NONE;
879 GVariant *params = NULL, *result = NULL;
881 if (!filename || !codechandle) {
882 debug_error("Param for play is null");
883 return MM_ERROR_INVALID_ARGUMENT;
888 params = g_variant_new("(siiisi)", filename, repeat, volume, client_pid, stream_type, stream_index);
890 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) {
891 debug_error("dbus play file failed");
895 debug_error("Construct Param for method call failed");
899 g_variant_get(result, "(i)", &handle);
900 debug_log("handle : %d", handle);
901 *codechandle = handle;
903 debug_error("reply null");
908 g_variant_unref(result);
916 int mm_sound_proxy_stop_sound(int handle)
918 int ret = MM_ERROR_NONE;
919 GVariant *result = NULL;
923 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) {
924 debug_error("dbus stop file playing failed");
930 g_variant_unref(result);
936 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)
938 int ret = MM_ERROR_NONE;
939 struct callback_data *cb_data;
943 CB_DATA_NEW(cb_data, func, userdata, freefunc);
945 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)
946 debug_error("add play sound end callback failed");
948 *subs_id = cb_data->subs_id;
955 int mm_sound_proxy_remove_play_sound_end_callback(unsigned subs_id)
957 int ret = MM_ERROR_NONE;
960 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
961 debug_error("Remove Play File End callback failed");
967 int mm_sound_proxy_register_focus(int index, const char *stream_type, int *id)
969 int ret = MM_ERROR_NONE;
970 int pid = g_focus_sound_handle[index].focus_pid;
976 ret = mm_sound_focus_socket_register(pid, stream_type, &client_fd, id);
978 debug_error("failed to mm_sound_focus_socket_register(), ret[0x%x]", ret);
980 g_focus_sound_handle[index].client_fd = client_fd;
981 g_focus_sound_handle[index].handle = *id;
989 int mm_sound_proxy_unregister_focus(int index)
991 int ret = MM_ERROR_NONE;
992 int pid = g_focus_sound_handle[index].focus_pid;
993 int client_fd = g_focus_sound_handle[index].client_fd;
994 int id = g_focus_sound_handle[index].handle;
998 ret = mm_sound_focus_socket_unregister(pid, client_fd, id);
1000 debug_error("failed to mm_sound_focus_socket_unregister(), client_fd[%d], id[%d], ret[0x%x]", client_fd, id, ret);
1007 int mm_sound_proxy_set_focus_reacquisition(int index, bool reacquisition)
1009 int ret = MM_ERROR_NONE;
1010 int pid = g_focus_sound_handle[index].focus_pid;
1011 int client_fd = g_focus_sound_handle[index].client_fd;
1012 int id = g_focus_sound_handle[index].handle;
1016 ret = mm_sound_focus_socket_set_reacquisition(pid, client_fd, id, reacquisition);
1018 debug_error("failed to mm_sound_focus_socket_set_reacquisition(), ret[0x%x]", ret);
1024 int mm_sound_proxy_get_acquired_focus_stream_type(int focus_type, char **stream_type, int *option, char **ext_info)
1026 int ret = MM_ERROR_NONE;
1030 ret = mm_sound_focus_socket_get_acquired_focus_stream_type(focus_type, stream_type, option, ext_info);
1032 debug_error("failed to mm_sound_focus_socket_get_acquired_focus_stream_type(), ret[0x%x]", ret);
1038 int mm_sound_proxy_acquire_focus(int index, mm_sound_focus_type_e type, int option, const char *ext_info)
1040 int ret = MM_ERROR_NONE;
1041 bool is_in_focus_cb_thread = false;
1042 int pid = g_focus_sound_handle[index].focus_pid;
1043 int client_fd = g_focus_sound_handle[index].client_fd;
1044 int id = g_focus_sound_handle[index].handle;
1048 mm_sound_client_is_focus_cb_thread(g_thread_self(), &is_in_focus_cb_thread);
1049 if (!is_in_focus_cb_thread) {
1050 if ((ret = mm_sound_focus_socket_acquire(pid, client_fd, id,
1051 type, option, ext_info ? ext_info : "", true)))
1052 debug_error("failed to mm_sound_focus_socket_acquire(), ret[0x%x]", ret);
1054 GVariant *params = NULL, *result = NULL;
1056 params = g_variant_new("(iiiis)", pid, id, type, option, ext_info ? ext_info : "");
1058 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_ACQUIRE_FOCUS, params, &result)) != MM_ERROR_NONE)
1059 debug_error("dbus acquire focus failed");
1061 debug_error("Construct Param for method call failed");
1064 if (ret != MM_ERROR_NONE)
1065 g_variant_get(result, "(i)", &ret);
1067 g_variant_unref(result);
1074 int mm_sound_proxy_release_focus(int index, mm_sound_focus_type_e type, int option, const char *ext_info)
1076 int ret = MM_ERROR_NONE;
1077 bool is_in_focus_cb_thread = false;
1078 int pid = g_focus_sound_handle[index].focus_pid;
1079 int client_fd = g_focus_sound_handle[index].client_fd;
1080 int id = g_focus_sound_handle[index].handle;
1084 mm_sound_client_is_focus_cb_thread(g_thread_self(), &is_in_focus_cb_thread);
1085 if (!is_in_focus_cb_thread) {
1086 if ((ret = mm_sound_focus_socket_release(pid, client_fd, id, type, option, ext_info ? ext_info : "", true)))
1087 debug_error("failed to mm_sound_focus_socket_release(), ret[0x%x]", ret);
1089 GVariant *params = NULL, *result = NULL;
1091 params = g_variant_new("(iiiis)", pid, id, type, option, ext_info ? ext_info : "");
1093 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_RELEASE_FOCUS, params, &result)) != MM_ERROR_NONE)
1094 debug_error("dbus release focus failed");
1096 debug_error("Construct Param for method call failed");
1099 if (ret != MM_ERROR_NONE)
1100 g_variant_get(result, "(i)", &ret);
1102 g_variant_unref(result);
1109 int mm_sound_proxy_update_stream_focus_status(int focus_id, unsigned int status)
1111 int ret = MM_ERROR_NONE;
1113 GVariant *params = NULL, *result = NULL;
1117 params = g_variant_new("(iu)", focus_id, status);
1119 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_UPDATE_STREAM_FOCUS_STATUS, params, &result)) != MM_ERROR_NONE) {
1120 debug_error("dbus set volume by type failed");
1122 g_variant_get(result, "(&s)", &reply);
1123 debug_log("reply : %s", reply);
1124 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
1125 ret = MM_ERROR_SOUND_INTERNAL;
1129 debug_error("Construct Param for method call failed");
1130 return MM_ERROR_SOUND_INTERNAL;
1134 g_variant_unref(result);
1140 int mm_sound_proxy_deliver_focus(int src_index, int dst_index, mm_sound_focus_type_e focus_type)
1142 int ret = MM_ERROR_NONE;
1143 int pid = g_focus_sound_handle[src_index].focus_pid;
1144 int src_client_fd = g_focus_sound_handle[src_index].client_fd;
1145 int src_server_fd = g_focus_sound_handle[src_index].handle;
1146 int dst_client_fd = g_focus_sound_handle[dst_index].client_fd;
1147 int dst_server_fd = g_focus_sound_handle[dst_index].handle;
1151 ret = mm_sound_focus_socket_deliver(pid, src_client_fd, src_server_fd, dst_client_fd, dst_server_fd, focus_type);
1153 debug_error("failed to mm_sound_focus_socket_deliver(), ret[0x%x]", ret);
1159 int mm_sound_proxy_add_focus_watch_callback(int index, mm_sound_focus_type_e type)
1161 int ret = MM_ERROR_NONE;
1162 int pid = g_focus_sound_handle[index].focus_pid;
1168 ret = mm_sound_focus_socket_add_watch_cb(pid, type, &client_fd, &id);
1170 debug_error("failed to mm_sound_focus_socket_add_watch_cb(), ret[0x%x]", ret);
1172 g_focus_sound_handle[index].handle = id;
1173 g_focus_sound_handle[index].client_fd = client_fd;
1181 int mm_sound_proxy_remove_focus_watch_callback(int index)
1183 int ret = MM_ERROR_NONE;
1184 int pid = g_focus_sound_handle[index].focus_pid;
1185 int client_fd = g_focus_sound_handle[index].client_fd;
1186 int id = g_focus_sound_handle[index].handle;
1190 ret = mm_sound_focus_socket_remove_watch_cb(pid, client_fd, id);
1192 debug_error("failed to mm_sound_focus_socket_remove_watch_cb(), ret[0x%x]", ret);
1199 int mm_sound_proxy_initialize(void)
1201 int ret = MM_ERROR_NONE;
1209 int mm_sound_proxy_finalize(void)
1211 int ret = MM_ERROR_NONE;