X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=mm_sound_proxy.c;h=552614a43e93d0441f0ee31ec84df1f80a497f62;hb=b5fb9c9e321a75736f19c4e8aca472031c2ca1ca;hp=81f6e88837d3c336f4b2fd7cadba61bfd5bdfb13;hpb=cf01a5538ee6081bd326d15f933cdfa4e7cf4546;p=platform%2Fcore%2Fmultimedia%2Flibmm-sound.git diff --git a/mm_sound_proxy.c b/mm_sound_proxy.c index 81f6e88..552614a 100644 --- a/mm_sound_proxy.c +++ b/mm_sound_proxy.c @@ -79,12 +79,63 @@ static int _notify_signal_handled(audio_event_t event, uint32_t event_id, uint32 return ret; } +static int parse_device_variant(GVariant *v, int *device_id, const char **device_type, int *direction, int *state, + const char **device_name, int *stream_id, int *stream_num) +{ + const char *v_type; + GVariant *array_v; + GVariantIter iter, array_iter; + int i = 0; + int ret = MM_ERROR_NONE; + + if (v == NULL) { + debug_error("Variant NULL"); + return MM_ERROR_NONE; + } + + v_type = g_variant_get_type_string(v); + if (g_variant_type_equal(v_type, "(isiisai)") == FALSE) { + debug_error("device variant type not matching '%s'", v_type); + return MM_ERROR_NONE; + } + + g_variant_iter_init(&iter, v); + g_variant_iter_next(&iter, "i", device_id); + g_variant_iter_next(&iter, "&s", device_type); + g_variant_iter_next(&iter, "i", direction); + g_variant_iter_next(&iter, "i", state); + g_variant_iter_next(&iter, "&s", device_name); + + array_v = g_variant_iter_next_value(&iter); + *stream_num = g_variant_iter_init(&array_iter, array_v); + if (*stream_num > MAX_STREAM_ON_DEVICE) { + debug_error("too many streams on device %d", *stream_num); + ret = MM_ERROR_SOUND_INTERNAL; + goto finish; + } + + while (g_variant_iter_loop(&array_iter, "i", &stream_id[i++])) ; +finish: + g_variant_unref(array_v); + + return ret; +} + /* This callback unmarshall general-formed paramters to subject specific parameters, * and call proper callback */ static void dbus_callback(audio_event_t event, GVariant *params, void *userdata) { struct callback_data *cb_data = (struct callback_data*) userdata; uint32_t event_id; + const char *name = NULL, *device_type = NULL; + int device_id, direction, state; + const gchar *v_type; + GVariantIter iter; + GVariant *device_v; + int stream_id[MAX_STREAM_ON_DEVICE]; + int stream_num; + + v_type = g_variant_get_type_string(params); if (event == AUDIO_EVENT_VOLUME_CHANGED) { char *volume_type_str = NULL, *direction = NULL; @@ -93,22 +144,63 @@ static void dbus_callback(audio_event_t event, GVariant *params, void *userdata) g_variant_get(params, "(&s&su)", &direction, &volume_type_str, &volume_level); ((mm_sound_volume_changed_wrapper_cb)(cb_data->user_cb))(direction, volume_type_str, volume_level, cb_data->user_data); } else if (event == AUDIO_EVENT_DEVICE_CONNECTED) { - const char *name = NULL, *device_type = NULL; gboolean is_connected = FALSE; - int device_id, io_direction, state; - g_variant_get(params, "(u(i&sii&s)b)", &event_id, &device_id, &device_type, &io_direction, - &state, &name, &is_connected); - ((mm_sound_device_connected_wrapper_cb)(cb_data->user_cb))(device_id, device_type, io_direction, state, name, is_connected, cb_data->user_data); + if (g_variant_type_equal(v_type, "(u(isiisai)b)") == FALSE) { + debug_error("Device connection changed signature not matching : %s", v_type); + return ; + } + g_variant_iter_init(&iter, params); + g_variant_iter_next(&iter, "u", &event_id); + device_v = g_variant_iter_next_value(&iter); + if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state, + &name, stream_id, &stream_num) < 0) { + debug_error("Failed to parse device variant"); + return ; + } + g_variant_iter_next(&iter, "b", &is_connected); + + ((mm_sound_device_connected_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction, + state, name, stream_id, stream_num, is_connected, cb_data->user_data); _notify_signal_handled(event, event_id, cb_data->subs_id, g_variant_new("(ib)", device_id, is_connected)); } else if (event == AUDIO_EVENT_DEVICE_INFO_CHANGED) { - const char *name = NULL, *device_type = NULL; int changed_device_info_type = 0; - int device_id, io_direction, state; - g_variant_get(params, "(u(i&sii&s)i)", &event_id, &device_id, &device_type, &io_direction, - &state, &name, &changed_device_info_type); - ((mm_sound_device_info_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, io_direction, state, name, changed_device_info_type, cb_data->user_data); + if (g_variant_type_equal(v_type, "(u(isiisai)i)") == FALSE) { + debug_error("Device information changed signature not matching : %s", v_type); + return ; + } + + g_variant_iter_init(&iter, params); + g_variant_iter_next(&iter, "u", &event_id); + device_v = g_variant_iter_next_value(&iter); + if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state, + &name, stream_id, &stream_num) < 0) { + debug_error("Failed to parse device variant"); + return ; + } + g_variant_iter_next(&iter, "i", &changed_device_info_type); + + ((mm_sound_device_info_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction, + state, name, stream_id, stream_num, changed_device_info_type, cb_data->user_data); + } else if (event == AUDIO_EVENT_DEVICE_STATE_CHANGED) { + + if (g_variant_type_equal(v_type, "(u(isiisai))") == FALSE) { + debug_error("Device state changed signature not matching : %s", v_type); + return ; + } + + g_variant_iter_init(&iter, params); + g_variant_iter_next(&iter, "u", &event_id); + device_v = g_variant_iter_next_value(&iter); + if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state, + &name, stream_id, &stream_num) < 0) { + debug_error("Failed to parse device variant"); + return ; + } + + ((mm_sound_device_state_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction, + state, name, stream_id, stream_num, cb_data->user_data); } else if (event == AUDIO_EVENT_FOCUS_CHANGED) { } else if (event == AUDIO_EVENT_FOCUS_WATCH) { } else if (event == AUDIO_EVENT_TEST) { @@ -199,6 +291,48 @@ cleanup: return ret; } +int mm_sound_proxy_is_stream_on_device(int stream_id, int device_id, bool *is_on) +{ + int ret = MM_ERROR_NONE; + GVariant *params, *result; + gboolean _is_on; + + debug_fenter(); + + if (!is_on) { + debug_error("Invalid Parameter, is_on null"); + return MM_ERROR_INVALID_ARGUMENT; + } + + if ((params = g_variant_new("(ii)", stream_id, device_id)) == NULL) { + debug_error("Construct Param for query is stream on device failed"); + return MM_ERROR_SOUND_INTERNAL; + } + + if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_IS_STREAM_ON_DEVICE, params, &result)) != MM_ERROR_NONE) { + debug_error("is stream on device failed"); + goto cleanup; + } + + if (result) { + g_variant_get(result, "(b)", &_is_on); + debug_log("is_on : %d", _is_on); + *is_on = (bool)_is_on; + } else { + debug_error("reply null"); + ret = MM_ERROR_SOUND_INTERNAL; + } + +cleanup: + if (params) + g_variant_unref(params); + if (result) + g_variant_unref(result); + + debug_fleave(); + return ret; +} + int mm_sound_proxy_get_current_connected_device_list(int device_flags, GList** device_list) { int ret = MM_ERROR_NONE; @@ -232,11 +366,16 @@ int mm_sound_proxy_get_current_connected_device_list(int device_flags, GList** d g_variant_iter_init(&iter, child); while (1) { device_item = g_malloc0(sizeof(mm_sound_device_t)); - if (device_item && g_variant_iter_loop(&iter, "(i&sii&s)", &device_item->id, &device_type_tmp, &device_item->io_direction, &device_item->state, &device_name_tmp)) { + if (device_item && g_variant_iter_loop(&iter, "(i&sii&s)", + &device_item->id, &device_type_tmp, &device_item->io_direction, &device_item->state, + &device_name_tmp)) { MMSOUND_STRNCPY(device_item->name, device_name_tmp, MAX_DEVICE_NAME_NUM); MMSOUND_STRNCPY(device_item->type, device_type_tmp, MAX_DEVICE_TYPE_STR_LEN); *device_list = g_list_append(*device_list, device_item); - debug_log("Added device id(%d) type(%17s) direction(%d) state(%d) name(%s)", device_item->id, device_item->type,device_item->io_direction, device_item->state, device_item->name); + debug_log("Added device id(%d) type(%17s) direction(%d) state(%d) name(%s)", + device_item->id, device_item->type,device_item->io_direction, device_item->state, + device_item->name); + device_item->stream_num = -1; } else { if (device_item) g_free(device_item); @@ -327,6 +466,37 @@ int mm_sound_proxy_remove_device_info_changed_callback(unsigned subs_id) return ret; } +int mm_sound_proxy_add_device_state_changed_callback(int device_flags, mm_sound_device_state_changed_wrapper_cb func, void* userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id) +{ + int ret = MM_ERROR_NONE; + struct callback_data *cb_data; + + debug_fenter(); + + CB_DATA_NEW(cb_data, func, userdata, freefunc); + + 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) + debug_error("Add device state changed callback failed"); + else + *subs_id = cb_data->subs_id; + + debug_fleave(); + return ret; +} + +int mm_sound_proxy_remove_device_state_changed_callback(unsigned subs_id) +{ + int ret = MM_ERROR_NONE; + debug_fenter(); + + if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) { + debug_error("remove device state changed callback failed"); + } + + debug_fleave(); + return ret; +} + int mm_sound_proxy_set_volume_by_type(const char *volume_type, const unsigned volume_level) { int ret = MM_ERROR_NONE; @@ -412,8 +582,8 @@ int mm_sound_proxy_play_tone(int tone, int repeat, int volume, int volume_config debug_fenter(); - params = g_variant_new("(iiiiiiibsi)", tone, repeat, volume, - volume_config, session_type, session_options, client_pid , _enable_session, stream_type, stream_index); + params = g_variant_new("(iiiiiiibsi)", tone, repeat, volume, volume_config, session_type, + session_options, client_pid , _enable_session, stream_type, stream_index); if (params) { if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_DTMF, params, &result)) != MM_ERROR_NONE) { debug_error("dbus play tone failed"); @@ -437,8 +607,6 @@ cleanup: debug_fleave(); return ret; - - } 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) @@ -478,13 +646,11 @@ cleanup: debug_fleave(); return ret; - - } int mm_sound_proxy_play_sound(const char* filename, int tone, int repeat, int volume, int volume_config, - int priority, int session_type, int session_options, int client_pid, int handle_route, - bool enable_session, int *codechandle, char *stream_type, int stream_index) + int session_type, int session_options, int client_pid, bool enable_session, int *codechandle, + char *stream_type, int stream_index) { int ret = MM_ERROR_NONE; int handle = 0; @@ -498,8 +664,8 @@ int mm_sound_proxy_play_sound(const char* filename, int tone, int repeat, int vo debug_fenter(); - params = g_variant_new("(siiiiiiiiibsi)", filename, tone, repeat, volume, - volume_config, priority, session_type, session_options, client_pid, handle_route, _enable_session, stream_type, stream_index); + params = g_variant_new("(siiiiiiibsi)", filename, tone, repeat, volume, + volume_config, session_type, session_options, client_pid, _enable_session, stream_type, stream_index); if (params) { if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_FILE_START, params, &result)) != MM_ERROR_NONE) { debug_error("dbus play file failed"); @@ -526,7 +692,7 @@ cleanup: } int mm_sound_proxy_play_sound_with_stream_info(const char* filename, int repeat, int volume, - int priority, int client_pid, int handle_route, int *codechandle, char *stream_type, int stream_index) + int client_pid, int *codechandle, char *stream_type, int stream_index) { int ret = MM_ERROR_NONE; int handle = 0; @@ -539,8 +705,7 @@ int mm_sound_proxy_play_sound_with_stream_info(const char* filename, int repeat, debug_fenter(); - params = g_variant_new("(siiiiisi)", filename, repeat, volume, - priority, client_pid, handle_route, stream_type, stream_index); + params = g_variant_new("(siiisi)", filename, repeat, volume, client_pid, stream_type, stream_index); if (params) { 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) { debug_error("dbus play file failed"); @@ -568,7 +733,6 @@ cleanup: } - int mm_sound_proxy_stop_sound(int handle) { int ret = MM_ERROR_NONE; @@ -768,7 +932,7 @@ int mm_sound_proxy_set_foucs_reacquisition(int instance, int id, bool reacquisit return ret; } -int mm_sound_proxy_get_acquired_focus_stream_type(int focus_type, char **stream_type, char **additional_info) +int mm_sound_proxy_get_acquired_focus_stream_type(int focus_type, char **stream_type, int *option, char **ext_info) { int ret = MM_ERROR_NONE; GVariant *params = NULL, *result = NULL; @@ -782,7 +946,7 @@ int mm_sound_proxy_get_acquired_focus_stream_type(int focus_type, char **stream_ if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_GET_ACQUIRED_FOCUS_STREAM_TYPE, params, &result)) == MM_ERROR_NONE) { if (result) { - g_variant_get(result, "(ss)", stream_type, additional_info); + g_variant_get(result, "(sis)", stream_type, option, ext_info); g_variant_unref(result); } } else { @@ -793,14 +957,14 @@ int mm_sound_proxy_get_acquired_focus_stream_type(int focus_type, char **stream_ return ret; } -int mm_sound_proxy_acquire_focus(int instance, int id, mm_sound_focus_type_e type, const char *option, bool is_for_session) +int mm_sound_proxy_acquire_focus(int instance, int id, mm_sound_focus_type_e type, int option, const char *ext_info, bool is_for_session) { int ret = MM_ERROR_NONE; GVariant *params = NULL, *result = NULL; debug_fenter(); - params = g_variant_new("(iiisb)", instance, id, type, option ? option : "", is_for_session); + params = g_variant_new("(iiiisb)", instance, id, type, option, ext_info ? ext_info : "", is_for_session); if (params) { if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_ACQUIRE_FOCUS, params, &result)) != MM_ERROR_NONE) { debug_error("dbus acquire focus failed"); @@ -818,14 +982,14 @@ int mm_sound_proxy_acquire_focus(int instance, int id, mm_sound_focus_type_e typ return ret; } -int mm_sound_proxy_release_focus(int instance, int id, mm_sound_focus_type_e type, const char *option, bool is_for_session) +int mm_sound_proxy_release_focus(int instance, int id, mm_sound_focus_type_e type, int option, const char *ext_info, bool is_for_session) { int ret = MM_ERROR_NONE; GVariant *params = NULL, *result = NULL; debug_fenter(); - params = g_variant_new("(iiisb)", instance, id, type, option ? option : "", is_for_session); + params = g_variant_new("(iiiisb)", instance, id, type, option, ext_info ? ext_info : "", is_for_session); if (params) { if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_RELEASE_FOCUS, params, &result)) != MM_ERROR_NONE) { debug_error("dbus release focus failed");