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 struct callback_data {
21 mm_sound_proxy_userdata_free free_func;
25 #define CB_DATA_NEW(_cb_data, _func, _userdata, _freefunc) \
27 _cb_data = (struct callback_data*) g_try_malloc0(sizeof(struct callback_data)); \
29 debug_error("failed to allocate callback_data"); \
30 return MM_ERROR_OUT_OF_MEMORY; \
32 _cb_data->user_cb = _func; \
33 _cb_data->user_data = _userdata; \
34 _cb_data->free_func = _freefunc; \
35 _cb_data->subs_id = 0; \
38 /* subscribe is true when add callback,
39 * false when remove callback */
40 static int _notify_subscription(audio_event_t event, uint32_t subs_id, gboolean subscribe)
42 int ret = MM_ERROR_NONE;
43 GVariant *params = NULL;
44 const char *event_name = NULL;
48 if ((ret = mm_sound_dbus_get_event_name(event, &event_name)) != MM_ERROR_NONE) {
49 debug_error("Failed to get event name");
50 return MM_ERROR_SOUND_INTERNAL;
53 if (!(params = g_variant_new("(sub)", event_name, subs_id, subscribe))) {
54 debug_error("Construct Param failed");
55 return MM_ERROR_SOUND_INTERNAL;
58 if ((ret = mm_sound_dbus_emit_signal(AUDIO_PROVIDER_AUDIO_CLIENT, AUDIO_EVENT_CLIENT_SUBSCRIBED, params)))
59 debug_error("dbus send signal for client subscribed failed");
65 static int _notify_signal_handled(audio_event_t event, uint32_t event_id, uint32_t subs_id, GVariant *signal_params)
67 int ret = MM_ERROR_NONE;
68 GVariant *params = NULL;
69 const char *event_name = NULL;
73 if ((ret = mm_sound_dbus_get_event_name(event, &event_name)) != MM_ERROR_NONE) {
74 debug_error("Failed to get event name");
75 return MM_ERROR_SOUND_INTERNAL;
78 if (!(params = g_variant_new("(usuv)", event_id, event_name, subs_id, signal_params))) {
79 debug_error("Construct Param failed");
80 return MM_ERROR_SOUND_INTERNAL;
83 if ((ret = mm_sound_dbus_emit_signal(AUDIO_PROVIDER_AUDIO_CLIENT, AUDIO_EVENT_CLIENT_HANDLED, params)))
84 debug_error("dbus send signal for client handled failed");
90 static int parse_device_variant(GVariant *v, int *device_id, const char **device_type, int *direction, int *state,
91 const char **device_name, int *vendor_id, int *product_id, gboolean *is_running, int *stream_id, int *stream_num)
95 GVariantIter iter, array_iter;
97 int ret = MM_ERROR_NONE;
100 debug_error("Variant NULL");
101 return MM_ERROR_NONE;
104 v_type = g_variant_get_type_string(v);
105 if (g_variant_type_equal(v_type, "(isiisiibai)") == FALSE) {
106 debug_error("device variant type not matching '%s'", v_type);
107 return MM_ERROR_NONE;
110 g_variant_iter_init(&iter, v);
111 g_variant_iter_next(&iter, "i", device_id);
112 g_variant_iter_next(&iter, "&s", device_type);
113 g_variant_iter_next(&iter, "i", direction);
114 g_variant_iter_next(&iter, "i", state);
115 g_variant_iter_next(&iter, "&s", device_name);
116 g_variant_iter_next(&iter, "i", vendor_id);
117 g_variant_iter_next(&iter, "i", product_id);
118 g_variant_iter_next(&iter, "b", is_running);
120 array_v = g_variant_iter_next_value(&iter);
122 debug_error("Error iterate on next value");
123 return MM_ERROR_SOUND_INTERNAL;
126 *stream_num = g_variant_iter_init(&array_iter, array_v);
127 if (*stream_num > MAX_STREAM_ON_DEVICE) {
128 debug_error("too many streams on device %d", *stream_num);
129 ret = MM_ERROR_SOUND_INTERNAL;
133 while (g_variant_iter_loop(&array_iter, "i", &stream_id[i++])) {}
136 g_variant_unref(array_v);
141 /* This callback unmarshall general-formed parameters to subject specific parameters,
142 * and call proper callback */
143 static void dbus_callback(audio_event_t event, GVariant *params, void *userdata)
145 struct callback_data *cb_data = (struct callback_data*) userdata;
147 const char *name = NULL, *device_type = NULL;
148 int device_id, direction, state;
152 int stream_id[MAX_STREAM_ON_DEVICE];
154 int vendor_id, product_id;
155 gboolean is_running = FALSE;
157 v_type = g_variant_get_type_string(params);
159 if (event == AUDIO_EVENT_VOLUME_CHANGED) {
160 char *volume_type_str = NULL, *direction = NULL;
161 unsigned volume_level;
163 g_variant_get(params, "(&s&su)", &direction, &volume_type_str, &volume_level);
164 ((mm_sound_volume_changed_wrapper_cb)(cb_data->user_cb))(direction, volume_type_str, volume_level, cb_data->user_data);
165 } else if (event == AUDIO_EVENT_DEVICE_CONNECTED) {
166 gboolean is_connected = FALSE;
168 if (g_variant_type_equal(v_type, "(u(isiisiibai)b)") == FALSE) {
169 debug_error("Device connection changed signature not matching : %s", v_type);
172 g_variant_iter_init(&iter, params);
173 g_variant_iter_next(&iter, "u", &event_id);
174 device_v = g_variant_iter_next_value(&iter);
175 if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
176 &name, &vendor_id, &product_id, &is_running, stream_id, &stream_num) < 0) {
177 debug_error("Failed to parse device variant");
180 g_variant_iter_next(&iter, "b", &is_connected);
182 ((mm_sound_device_connected_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
183 state, name, vendor_id, product_id, (bool)is_running, stream_id, stream_num, (bool)is_connected, cb_data->user_data);
184 _notify_signal_handled(event, event_id, cb_data->subs_id, g_variant_new("(ib)", device_id, (bool)is_connected));
185 } else if (event == AUDIO_EVENT_DEVICE_INFO_CHANGED) {
186 int changed_device_info_type = 0;
188 if (g_variant_type_equal(v_type, "(u(isiisiibai)i)") == FALSE) {
189 debug_error("Device information changed signature not matching : %s", v_type);
193 g_variant_iter_init(&iter, params);
194 g_variant_iter_next(&iter, "u", &event_id);
195 device_v = g_variant_iter_next_value(&iter);
196 if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
197 &name, &vendor_id, &product_id, &is_running, stream_id, &stream_num) < 0) {
198 debug_error("Failed to parse device variant");
201 g_variant_iter_next(&iter, "i", &changed_device_info_type);
203 ((mm_sound_device_info_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
204 state, name, vendor_id, product_id, (bool)is_running, stream_id, stream_num, changed_device_info_type, cb_data->user_data);
205 } else if (event == AUDIO_EVENT_DEVICE_STATE_CHANGED) {
207 if (g_variant_type_equal(v_type, "(u(isiisiibai))") == FALSE) {
208 debug_error("Device state changed signature not matching : %s", v_type);
212 g_variant_iter_init(&iter, params);
213 g_variant_iter_next(&iter, "u", &event_id);
214 device_v = g_variant_iter_next_value(&iter);
215 if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
216 &name, &vendor_id, &product_id, &is_running, stream_id, &stream_num) < 0) {
217 debug_error("Failed to parse device variant");
221 ((mm_sound_device_state_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
222 state, name, vendor_id, product_id, (bool)is_running, stream_id, stream_num, cb_data->user_data);
223 } else if (event == AUDIO_EVENT_DEVICE_RUNNING_CHANGED) {
225 if (g_variant_type_equal(v_type, "(u(isiisiibai))") == FALSE) {
226 debug_error("Device state changed signature not matching : %s", v_type);
230 g_variant_iter_init(&iter, params);
231 g_variant_iter_next(&iter, "u", &event_id);
232 device_v = g_variant_iter_next_value(&iter);
233 if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
234 &name, &vendor_id, &product_id, &is_running, stream_id, &stream_num) < 0) {
235 debug_error("Failed to parse device variant");
239 ((mm_sound_device_running_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
240 state, name, vendor_id, product_id, (bool)is_running, stream_id, stream_num, cb_data->user_data);
241 } else if (event == AUDIO_EVENT_FOCUS_CHANGED) {
242 } else if (event == AUDIO_EVENT_FOCUS_WATCH) {
243 } else if (event == AUDIO_EVENT_TEST) {
245 g_variant_get(params, "(i)", &test_var);
246 ((mm_sound_test_cb)(cb_data->user_cb))(test_var, cb_data->user_data);
247 } else if (event == AUDIO_EVENT_DUCKING_STATE_CHANGED) {
251 g_variant_get(params, "(ii)", &idx, &is_ducked);
253 ((mm_sound_ducking_state_changed_wrapper_cb)(cb_data->user_cb))(idx, is_ducked, cb_data->user_data);
257 static void simple_callback_data_free_func(void *data)
259 struct callback_data *cb_data = (struct callback_data*) data;
262 if (cb_data->free_func)
263 cb_data->free_func(cb_data->user_data);
268 int mm_sound_proxy_is_stream_on_device(int stream_id, int device_id, bool *is_on)
270 int ret = MM_ERROR_NONE;
271 GVariant *params = NULL, *result = NULL;
277 debug_error("Invalid Parameter, is_on null");
278 return MM_ERROR_INVALID_ARGUMENT;
281 if ((params = g_variant_new("(ii)", stream_id, device_id)) == NULL) {
282 debug_error("Construct Param for query is stream on device failed");
283 return MM_ERROR_SOUND_INTERNAL;
286 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_IS_STREAM_ON_DEVICE, params, &result)) != MM_ERROR_NONE) {
287 debug_error("is stream on device failed");
292 g_variant_get(result, "(b)", &_is_on);
293 debug_log("is_on : %d", _is_on);
294 *is_on = (bool)_is_on;
296 debug_error("reply null");
297 ret = MM_ERROR_SOUND_INTERNAL;
302 g_variant_unref(result);
309 #define _VCONF_KEY_SOUND_SPEAKER_SELECTION "file/private/sound/feature/SpeakerSelection"
310 #define _AUDIO_TV_OUTPUT_BT_HEADSET 5
312 static mm_sound_device_t* _get_tv_bt_device(int device_flags)
314 int speaker_value = 0;
315 mm_sound_device_t* device_item = NULL;
317 /* check precondition mask first here */
318 if (device_flags != DEVICE_ALL_FLAG) {
319 if (!(device_flags & DEVICE_IO_DIRECTION_OUT_FLAG)) {
320 debug_warning("no out flag given, skip checking bt a2dp");
323 if (device_flags & DEVICE_TYPE_INTERNAL_FLAG) {
324 debug_warning("internal flag given, skip checking bt a2dp");
329 if (vconf_get_int(_VCONF_KEY_SOUND_SPEAKER_SELECTION, &speaker_value) == VCONF_ERROR) {
330 debug_error("vconf_get_int(%s) failed..", _VCONF_KEY_SOUND_SPEAKER_SELECTION);
334 debug_warning("speaker selection value = %d", speaker_value);
335 if (speaker_value != _AUDIO_TV_OUTPUT_BT_HEADSET)
338 device_item = g_new0(mm_sound_device_t, 1);
340 MMSOUND_STRNCPY(device_item->name, "BluetoothMedia", MAX_DEVICE_NAME_NUM);
341 MMSOUND_STRNCPY(device_item->type, "bt-a2dp", MAX_DEVICE_TYPE_STR_LEN);
342 device_item->id = 99;
343 device_item->io_direction = DEVICE_IO_DIRECTION_OUT;
344 device_item->state = DEVICE_STATE_ACTIVATED;
345 device_item->vendor_id = -1;
346 device_item->product_id = -1;
347 device_item->stream_num = -1;
351 #endif /* TIZEN_TV */
353 int mm_sound_proxy_get_current_connected_device_list(int device_flags, GList** device_list)
355 int ret = MM_ERROR_NONE;
356 GVariant *result = NULL, *child = NULL;
357 GVariant *params = NULL;
359 mm_sound_device_t* device_item;
360 const gchar *device_name_tmp = NULL, *device_type_tmp = NULL;
365 debug_error("Invalid Parameter, device_list null");
366 ret = MM_ERROR_INVALID_ARGUMENT;
370 params = g_variant_new("(i)", device_flags);
373 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_GET_CONNECTED_DEVICE_LIST, params, &result)) != MM_ERROR_NONE) {
374 debug_error("Get current connected device list failed");
378 debug_error("Construct Param for get current connected device failed");
379 return MM_ERROR_SOUND_INTERNAL;
382 child = g_variant_get_child_value(result, 0);
384 debug_error("Error getting child value from result");
387 g_variant_iter_init(&iter, child);
389 device_item = g_malloc0(sizeof(mm_sound_device_t));
390 if (device_item && g_variant_iter_loop(&iter, "(i&sii&siib)",
391 &device_item->id, &device_type_tmp, &device_item->io_direction, &device_item->state,
392 &device_name_tmp, &device_item->vendor_id, &device_item->product_id, &device_item->is_running)) {
393 MMSOUND_STRNCPY(device_item->name, device_name_tmp, MAX_DEVICE_NAME_NUM);
394 MMSOUND_STRNCPY(device_item->type, device_type_tmp, MAX_DEVICE_TYPE_STR_LEN);
395 *device_list = g_list_append(*device_list, device_item);
396 debug_log("Added device id(%d) type(%17s) direction(%d) state(%d) name(%s) vendor-id(%04x) product-id(%04x) is_running(%d)",
397 device_item->id, device_item->type, device_item->io_direction, device_item->state,
398 device_item->name, device_item->vendor_id, device_item->product_id, device_item->is_running);
399 device_item->stream_num = -1;
405 g_variant_unref(child);
408 device_item = _get_tv_bt_device(device_flags);
410 *device_list = g_list_append(*device_list, device_item);
411 debug_msg("Added TV bt device id(%d) type(%17s) direction(%d) state(%d) name(%s) vendor-id(%04x) product-id(%04x)",
412 device_item->id, device_item->type, device_item->io_direction, device_item->state,
413 device_item->name, device_item->vendor_id, device_item->product_id);
415 #endif /* TIZEN_TV */
419 g_variant_unref(result);
425 int mm_sound_proxy_get_device_by_id(int device_id, mm_sound_device_t **device)
427 int ret = MM_ERROR_NONE;
428 GVariant *params = NULL, *result = NULL;
429 mm_sound_device_t* device_item = NULL;
430 const gchar *device_name_tmp = NULL, *device_type_tmp = NULL;
434 if (!device || device_id < 1) {
435 debug_error("Invalid Parameter, device null or improper device id");
436 return MM_ERROR_INVALID_ARGUMENT;
439 if ((params = g_variant_new("(i)", device_id)) == NULL) {
440 debug_error("Construct Param for get device by id failed");
441 return MM_ERROR_SOUND_INTERNAL;
444 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_GET_DEVICE_BY_ID, params, &result)) != MM_ERROR_NONE) {
445 debug_error("get device by id failed");
446 ret = MM_ERROR_SOUND_NO_DATA;
451 if ((device_item = g_malloc0(sizeof(mm_sound_device_t))) == NULL) {
452 debug_error("Alloc device handle failed");
453 ret = MM_ERROR_SOUND_INTERNAL;
457 g_variant_get(result, "(i&sii&sii)",
458 &device_item->id, &device_type_tmp, &device_item->io_direction,
459 &device_item->state, &device_name_tmp,
460 &device_item->vendor_id, &device_item->product_id);
461 MMSOUND_STRNCPY(device_item->name, device_name_tmp, MAX_DEVICE_NAME_NUM);
462 MMSOUND_STRNCPY(device_item->type, device_type_tmp, MAX_DEVICE_TYPE_STR_LEN);
463 debug_log("Get device id(%d) type(%17s) direction(%d) state(%d) name(%s) vendor-id(%04x) product-id(%04x)",
464 device_item->id, device_item->type, device_item->io_direction,
465 device_item->state, device_item->name,
466 device_item->vendor_id, device_item->product_id);
467 device_item->stream_num = -1;
468 *device = device_item;
470 debug_error("reply null");
471 ret = MM_ERROR_SOUND_INTERNAL;
476 g_variant_unref(result);
482 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)
484 int ret = MM_ERROR_NONE;
485 struct callback_data *cb_data;
489 CB_DATA_NEW(cb_data, func, userdata, freefunc);
491 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) {
492 debug_error("add device connected callback failed");
496 if ((ret = _notify_subscription(AUDIO_EVENT_DEVICE_CONNECTED, cb_data->subs_id, TRUE)) != MM_ERROR_NONE) {
497 debug_error("failed to notify subscription of device connected event");
501 *subs_id = cb_data->subs_id;
508 int mm_sound_proxy_remove_device_connected_callback(unsigned subs_id)
510 int ret = MM_ERROR_NONE;
513 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
514 debug_error("remove device connected callback failed");
518 if ((ret = _notify_subscription(AUDIO_EVENT_DEVICE_CONNECTED, subs_id, FALSE)) != MM_ERROR_NONE)
519 debug_error("failed to notify unsubscription of device connected event");
526 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)
528 int ret = MM_ERROR_NONE;
529 struct callback_data *cb_data;
533 CB_DATA_NEW(cb_data, func, userdata, freefunc);
535 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)
536 debug_error("Add device info changed callback failed");
538 *subs_id = cb_data->subs_id;
544 int mm_sound_proxy_remove_device_info_changed_callback(unsigned subs_id)
546 int ret = MM_ERROR_NONE;
549 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
550 debug_error("remove device info changed callback failed");
556 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)
558 int ret = MM_ERROR_NONE;
559 struct callback_data *cb_data;
563 CB_DATA_NEW(cb_data, func, userdata, freefunc);
565 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)
566 debug_error("Add device state changed callback failed");
568 *subs_id = cb_data->subs_id;
574 int mm_sound_proxy_remove_device_state_changed_callback(unsigned subs_id)
576 int ret = MM_ERROR_NONE;
579 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
580 debug_error("remove device state changed callback failed");
586 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)
588 int ret = MM_ERROR_NONE;
589 struct callback_data *cb_data;
593 CB_DATA_NEW(cb_data, func, userdata, freefunc);
595 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)
596 debug_error("Add device running changed callback failed");
598 *subs_id = cb_data->subs_id;
604 int mm_sound_proxy_remove_device_running_changed_callback(unsigned subs_id)
606 int ret = MM_ERROR_NONE;
609 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
610 debug_error("remove device running changed callback failed");
616 int mm_sound_proxy_set_volume_by_type(const char *volume_type, const unsigned volume_level)
618 int ret = MM_ERROR_NONE;
619 const char *reply = NULL, *direction = "out";
620 GVariant *params = NULL, *result = NULL;
624 if ((params = g_variant_new("(ssu)", direction, volume_type, volume_level)) == NULL) {
625 debug_error("Construct Param for method call failed");
626 return MM_ERROR_SOUND_INTERNAL;
629 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_SET_VOLUME_LEVEL, params, &result)) != MM_ERROR_NONE) {
630 debug_error("dbus set volume by type failed");
635 g_variant_get(result, "(&s)", &reply);
636 debug_log("reply : %s", reply);
637 if (!strcmp(reply, "STREAM_MANAGER_RETURN_ERROR_INVALID_ARGUMENT"))
638 ret = MM_ERROR_INVALID_ARGUMENT;
639 else if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
640 ret = MM_ERROR_SOUND_INTERNAL;
642 debug_error("reply null");
643 ret = MM_ERROR_SOUND_INTERNAL;
648 g_variant_unref(result);
654 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)
656 int ret = MM_ERROR_NONE;
657 struct callback_data *cb_data;
661 CB_DATA_NEW(cb_data, func, userdata, freefunc);
663 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)
664 debug_error("Add Volume changed callback failed");
666 *subs_id = cb_data->subs_id;
673 int mm_sound_proxy_remove_volume_changed_callback(unsigned subs_id)
675 int ret = MM_ERROR_NONE;
678 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
679 debug_error("Remove Volume changed callback failed");
685 int mm_sound_proxy_add_ducking_state_changed_callback(mm_sound_ducking_state_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_DUCKING_STATE_CHANGED, dbus_callback, cb_data, simple_callback_data_free_func, &cb_data->subs_id)) != MM_ERROR_NONE)
695 debug_error("Add Ducking State changed callback failed");
697 *subs_id = cb_data->subs_id;
704 int mm_sound_proxy_remove_ducking_state_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 Ducking State changed callback failed");
716 int mm_sound_proxy_set_mute_by_type(const char *volume_type, bool mute)
718 int ret = MM_ERROR_NONE;
719 const char *reply = NULL, *direction = "out";
720 GVariant *params = NULL, *result = NULL;
724 if ((params = g_variant_new("(ssu)", direction, volume_type, (unsigned int)mute)) == 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_MUTE, params, &result)) != MM_ERROR_NONE) {
730 debug_error("dbus set mute by type failed");
735 g_variant_get(result, "(&s)", &reply);
736 debug_log("reply : %s", reply);
737 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
738 ret = MM_ERROR_SOUND_INTERNAL;
740 debug_error("reply null");
741 ret = MM_ERROR_SOUND_INTERNAL;
746 g_variant_unref(result);
752 int mm_sound_proxy_set_filter_by_type(const char *stream_type, const char *filter_name, const char *filter_parameters, const char *filter_group) {
753 int ret = MM_ERROR_NONE;
754 const char *reply = NULL;
755 GVariant *params = NULL, *result = NULL;
759 if ((params = g_variant_new("(ssss)", filter_name, filter_parameters, filter_group, stream_type)) == NULL) {
760 debug_error("construct param for method call failed");
761 return MM_ERROR_SOUND_INTERNAL;
764 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_SET_FILTER, params, &result)) != MM_ERROR_NONE) {
765 debug_error("dbus set filter by type failed");
769 /* stream-manager always returns a string as return value */
771 g_variant_get(result, "(&s)", &reply);
772 debug_log("reply : %s", reply);
773 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
774 ret = MM_ERROR_SOUND_INTERNAL;
776 debug_error("reply null");
777 ret = MM_ERROR_SOUND_INTERNAL;
782 g_variant_unref(result);
788 int mm_sound_proxy_unset_filter_by_type(const char *stream_type)
790 int ret = MM_ERROR_NONE;
791 const char *reply = NULL;
792 GVariant *params = NULL, *result = NULL;
796 if ((params = g_variant_new("(s)", stream_type)) == NULL) {
797 debug_error("construct param for method call failed");
798 return MM_ERROR_SOUND_INTERNAL;
801 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_UNSET_FILTER, params, &result)) != MM_ERROR_NONE) {
802 debug_error("dbus unset filter by type failed");
806 /* stream-manager always returns a string as return value */
808 g_variant_get(result, "(&s)", &reply);
809 debug_log("reply : %s", reply);
810 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
811 ret = MM_ERROR_SOUND_INTERNAL;
813 debug_error("reply null");
814 ret = MM_ERROR_SOUND_INTERNAL;
819 g_variant_unref(result);
825 int mm_sound_proxy_control_filter_by_type(const char *stream_type, const char *filter_name, const char *filter_controls)
827 int ret = MM_ERROR_NONE;
828 const char *reply = NULL;
829 GVariant *params = NULL, *result = NULL;
833 if ((params = g_variant_new("(sss)", filter_name, filter_controls, stream_type)) == NULL) {
834 debug_error("construct param for method call failed");
835 return MM_ERROR_SOUND_INTERNAL;
838 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_CONTROL_FILTER, params, &result)) != MM_ERROR_NONE) {
839 debug_error("dbus control filter by type failed");
842 /* stream-manager always returns a string as return value */
844 g_variant_get(result, "(&s)", &reply);
845 debug_log("reply : %s", reply);
846 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
847 ret = MM_ERROR_SOUND_INTERNAL;
849 debug_error("reply null");
850 ret = MM_ERROR_SOUND_INTERNAL;
855 g_variant_unref(result);
861 int mm_sound_proxy_register_focus(int index, const char *stream_type, int *id)
863 int ret = MM_ERROR_NONE;
864 int pid = g_focus_sound_handle[index].focus_pid;
870 ret = mm_sound_focus_socket_register(pid, stream_type, &client_fd, id);
872 debug_error("failed to mm_sound_focus_socket_register(), ret[0x%x]", ret);
874 g_focus_sound_handle[index].client_fd = client_fd;
875 g_focus_sound_handle[index].handle = *id;
883 int mm_sound_proxy_unregister_focus(int index)
885 int ret = MM_ERROR_NONE;
886 int pid = g_focus_sound_handle[index].focus_pid;
887 int client_fd = g_focus_sound_handle[index].client_fd;
888 int id = g_focus_sound_handle[index].handle;
892 ret = mm_sound_focus_socket_unregister(pid, client_fd, id);
894 debug_error("failed to mm_sound_focus_socket_unregister(), client_fd[%d], id[%d], ret[0x%x]", client_fd, id, ret);
901 int mm_sound_proxy_set_focus_reacquisition(int index, bool reacquisition)
903 int ret = MM_ERROR_NONE;
904 int pid = g_focus_sound_handle[index].focus_pid;
905 int client_fd = g_focus_sound_handle[index].client_fd;
906 int id = g_focus_sound_handle[index].handle;
910 ret = mm_sound_focus_socket_set_reacquisition(pid, client_fd, id, reacquisition);
912 debug_error("failed to mm_sound_focus_socket_set_reacquisition(), ret[0x%x]", ret);
918 int mm_sound_proxy_get_acquired_focus_stream_type(int focus_type, char **stream_type, int *option, char **ext_info)
920 int ret = MM_ERROR_NONE;
924 ret = mm_sound_focus_socket_get_acquired_focus_stream_type(focus_type, stream_type, option, ext_info);
926 debug_error("failed to mm_sound_focus_socket_get_acquired_focus_stream_type(), ret[0x%x]", ret);
932 int mm_sound_proxy_acquire_focus(int index, mm_sound_focus_type_e type, int option, const char *ext_info)
934 int ret = MM_ERROR_NONE;
935 bool is_in_focus_cb_thread = false;
936 int pid = g_focus_sound_handle[index].focus_pid;
937 int client_fd = g_focus_sound_handle[index].client_fd;
938 int id = g_focus_sound_handle[index].handle;
942 mm_sound_client_is_focus_cb_thread(g_thread_self(), &is_in_focus_cb_thread, NULL);
943 if (!is_in_focus_cb_thread) {
944 if ((ret = mm_sound_focus_socket_acquire(pid, client_fd, id,
945 type, option, ext_info ? ext_info : "", true)))
946 debug_error("failed to mm_sound_focus_socket_acquire(), ret[0x%x]", ret);
948 GVariant *params = NULL, *result = NULL;
950 if ((params = g_variant_new("(iiiis)", pid, id, type, option, ext_info ? ext_info : "")) == NULL) {
951 debug_error("Construct Param for method call failed");
952 return MM_ERROR_SOUND_INTERNAL;
955 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_ACQUIRE_FOCUS, params, &result)) != MM_ERROR_NONE)
956 debug_error("dbus acquire focus failed");
959 g_variant_unref(result);
967 int mm_sound_proxy_release_focus(int index, mm_sound_focus_type_e type, int option, const char *ext_info)
969 int ret = MM_ERROR_NONE;
970 bool is_in_focus_cb_thread = false;
971 int pid = g_focus_sound_handle[index].focus_pid;
972 int client_fd = g_focus_sound_handle[index].client_fd;
973 int id = g_focus_sound_handle[index].handle;
977 mm_sound_client_is_focus_cb_thread(g_thread_self(), &is_in_focus_cb_thread, NULL);
978 if (!is_in_focus_cb_thread) {
979 if ((ret = mm_sound_focus_socket_release(pid, client_fd, id, type, option, ext_info ? ext_info : "", true)))
980 debug_error("failed to mm_sound_focus_socket_release(), ret[0x%x]", ret);
982 GVariant *params = NULL, *result = NULL;
984 if ((params = g_variant_new("(iiiis)", pid, id, type, option, ext_info ? ext_info : "")) == NULL) {
985 debug_error("Construct Param for method call failed");
986 return MM_ERROR_SOUND_INTERNAL;
989 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_RELEASE_FOCUS, params, &result)) != MM_ERROR_NONE)
990 debug_error("dbus release focus failed");
993 g_variant_unref(result);
1000 int mm_sound_proxy_update_stream_focus_status(int focus_id, unsigned int status)
1002 int ret = MM_ERROR_NONE;
1003 const char *reply = NULL;
1004 GVariant *params = NULL, *result = NULL;
1008 if ((params = g_variant_new("(iu)", focus_id, status)) == NULL) {
1009 debug_error("Construct Param for method call failed");
1010 return MM_ERROR_SOUND_INTERNAL;
1013 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_UPDATE_STREAM_FOCUS_STATUS, params, &result)) != MM_ERROR_NONE) {
1014 debug_error("dbus set volume by type failed");
1018 /* stream-manager always returns a string as return value */
1020 g_variant_get(result, "(&s)", &reply);
1021 debug_log("reply : %s", reply);
1022 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
1023 ret = MM_ERROR_SOUND_INTERNAL;
1025 debug_error("reply null");
1026 ret = MM_ERROR_SOUND_INTERNAL;
1031 g_variant_unref(result);
1037 int mm_sound_proxy_deliver_focus(int src_index, int dst_index, mm_sound_focus_type_e focus_type)
1039 int ret = MM_ERROR_NONE;
1040 int pid = g_focus_sound_handle[src_index].focus_pid;
1041 int src_client_fd = g_focus_sound_handle[src_index].client_fd;
1042 int src_server_fd = g_focus_sound_handle[src_index].handle;
1043 int dst_client_fd = g_focus_sound_handle[dst_index].client_fd;
1044 int dst_server_fd = g_focus_sound_handle[dst_index].handle;
1048 ret = mm_sound_focus_socket_deliver(pid, src_client_fd, src_server_fd, dst_client_fd, dst_server_fd, focus_type);
1050 debug_error("failed to mm_sound_focus_socket_deliver(), ret[0x%x]", ret);
1056 int mm_sound_proxy_add_focus_watch_callback(int index, mm_sound_focus_type_e type)
1058 int ret = MM_ERROR_NONE;
1059 int pid = g_focus_sound_handle[index].focus_pid;
1065 ret = mm_sound_focus_socket_add_watch_cb(pid, type, &client_fd, &id);
1067 debug_error("failed to mm_sound_focus_socket_add_watch_cb(), ret[0x%x]", ret);
1069 g_focus_sound_handle[index].handle = id;
1070 g_focus_sound_handle[index].client_fd = client_fd;
1078 int mm_sound_proxy_remove_focus_watch_callback(int index)
1080 int ret = MM_ERROR_NONE;
1081 int pid = g_focus_sound_handle[index].focus_pid;
1082 int client_fd = g_focus_sound_handle[index].client_fd;
1083 int id = g_focus_sound_handle[index].handle;
1087 ret = mm_sound_focus_socket_remove_watch_cb(pid, client_fd, id);
1089 debug_error("failed to mm_sound_focus_socket_remove_watch_cb(), ret[0x%x]", ret);
1096 int mm_sound_proxy_initialize(void)
1098 int ret = MM_ERROR_NONE;
1106 int mm_sound_proxy_finalize(void)
1108 int ret = MM_ERROR_NONE;