From 2d52646db9df5ca979f7d2d64e7abbb07a5f5c89 Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Wed, 10 May 2017 15:24:42 +0900 Subject: [PATCH] stream-manager: Enhance error handling in handle_set_stream_route_devices() [Version] 5.0.148 [Issue Type] Enhancement Change-Id: I6508166f096188a6c30fe2410afba546c9c999e7 Signed-off-by: Sangchul Lee --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/stream-manager.c | 275 +++++++++++++++++++------------- 2 files changed, 169 insertions(+), 108 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 84f923d..08e10e3 100644 --- a/packaging/pulseaudio-modules-tizen.spec +++ b/packaging/pulseaudio-modules-tizen.spec @@ -1,6 +1,6 @@ Name: pulseaudio-modules-tizen Summary: Pulseaudio modules for Tizen -Version: 5.0.147 +Version: 5.0.148 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/stream-manager.c b/src/stream-manager.c index cb52d51..eb5a4b5 100644 --- a/src/stream-manager.c +++ b/src/stream-manager.c @@ -291,12 +291,20 @@ static pa_dbus_method_handler method_handlers[METHOD_HANDLER_MAX] = { }; const char *dbus_str_none = "none"; -const char* stream_manager_dbus_ret_str[] = {"STREAM_MANAGER_RETURN_OK", "STREAM_MANAGER_RETURN_ERROR", "STREAM_MANAGER_RETURN_ERROR_NO_STREAM"}; -enum { - RET_MSG_INDEX_OK, - RET_MSG_INDEX_ERROR, - RET_MSG_INDEX_ERROR_NO_STREAM, -}; +const char* stream_manager_dbus_ret_str[] = {"STREAM_MANAGER_RETURN_OK", + "STREAM_MANAGER_RETURN_ERROR_INTERNAL", + "STREAM_MANAGER_RETURN_ERROR_NO_STREAM", + "STREAM_MANAGER_RETURN_ERROR_INVALID_ARGUMENT", + "STREAM_MANAGER_RETURN_ERROR_DEVICE_NOT_FOUND", + "STREAM_MANAGER_RETURN_ERROR_POLICY"}; +typedef enum { + RET_MSG_OK, + RET_MSG_ERROR_INTERNAL, + RET_MSG_ERROR_NO_STREAM, + RET_MSG_ERROR_INVALID_ARGUMENT, + RET_MSG_ERROR_DEVICE_NOT_FOUND, + RET_MSG_ERROR_POLICY, +} ret_msg_t; #ifdef USE_DBUS_PROTOCOL @@ -557,7 +565,7 @@ typedef struct _stream_route_option { #define CONVERT_TO_DEVICE_DIRECTION(stream_type) \ ((stream_type == STREAM_SINK_INPUT) ? DM_DEVICE_DIRECTION_OUT : DM_DEVICE_DIRECTION_IN) -static void do_notify(pa_stream_manager *m, notify_command_type_t command, stream_type_t type, bool is_new_data, void *user_data); +static ret_msg_t do_notify(pa_stream_manager *m, notify_command_type_t command, stream_type_t type, bool is_new_data, void *user_data); static process_stream_result_t process_stream(pa_stream_manager *m, void *stream, stream_type_t type, process_command_type_t command, bool is_new_data); static bool stream_is_call_family(pa_object *stream) { @@ -1135,12 +1143,13 @@ static bool check_stream_exist_by_pid(pa_stream_manager *m, uint32_t pid, const return false; } -static void update_devices_and_trigger_routing(pa_stream_manager *m, stream_parent *sp, stream_type_t type) { +static ret_msg_t update_devices_and_trigger_routing(pa_stream_manager *m, stream_parent *sp, stream_type_t type) { void *stream = NULL; pa_idxset *idx_streams = NULL; uint32_t idx = 0; void *cur_highest_priority_stream = NULL; stream_route_type_t route_type = STREAM_ROUTE_TYPE_DEFAULT; + ret_msg_t ret = RET_MSG_OK; pa_assert(m); pa_assert(sp); @@ -1157,17 +1166,17 @@ static void update_devices_and_trigger_routing(pa_stream_manager *m, stream_pare if (sp->route_type == STREAM_ROUTE_TYPE_DEFAULT) { PA_IDXSET_FOREACH(stream, idx_streams, idx) { /* find route type of stream */ - if (!get_route_type(stream, type, false, &route_type)) { - if (route_type == STREAM_ROUTE_TYPE_MANUAL || - route_type == STREAM_ROUTE_TYPE_MANUAL_EXT) { - sp->route_type = route_type; - pa_log_info(" -- the route type is [%d]", route_type); - } else { - pa_log_error(" -- the route type is not valid[%d]", route_type); - return; - } - } else - return; + if (get_route_type(stream, type, false, &route_type)) + return RET_MSG_ERROR_INTERNAL; + + if (route_type == STREAM_ROUTE_TYPE_MANUAL || + route_type == STREAM_ROUTE_TYPE_MANUAL_EXT) { + sp->route_type = route_type; + pa_log_info(" -- the route type is [%d]", route_type); + } else { + pa_log_error(" -- the route type is not valid[%d]", route_type); + return RET_MSG_ERROR_POLICY; + } } } @@ -1176,20 +1185,52 @@ static void update_devices_and_trigger_routing(pa_stream_manager *m, stream_pare PA_IDXSET_FOREACH(stream, idx_streams, idx) { pa_log_debug(" -- stream->index[%u] belongs to this stream parent[%p], do notify for the select proper source", GET_STREAM_INDEX(stream, type), sp); - do_notify(m, NOTIFY_COMMAND_SELECT_PROPER_SINK_OR_SOURCE_FOR_INIT, type, false, stream); + ret = do_notify(m, NOTIFY_COMMAND_SELECT_PROPER_SINK_OR_SOURCE_FOR_INIT, type, false, stream); } } else { /* trigger only when it occupies routing path */ if (cur_highest_priority_stream && pa_idxset_get_by_data(idx_streams, cur_highest_priority_stream, NULL)) { pa_log_debug(" -- cur_highest_priority_stream->index[%u] belongs to this stream_parent[%p], do notify for the route change", GET_STREAM_INDEX(cur_highest_priority_stream, type), sp); - do_notify(m, NOTIFY_COMMAND_CHANGE_ROUTE_START, type, false, cur_highest_priority_stream); - if (stream_is_call_family(PA_OBJECT(cur_highest_priority_stream)) && m->on_call) { + ret = do_notify(m, NOTIFY_COMMAND_CHANGE_ROUTE_START, type, false, cur_highest_priority_stream); + if (!ret && stream_is_call_family(PA_OBJECT(cur_highest_priority_stream)) && m->on_call) { pa_log_info("set active device for new call route device"); change_active_route_for_call(PA_OBJECT(cur_highest_priority_stream), false, m); } } } + + return ret; +} + +static bool check_all_requested_devices_connected(pa_stream_manager *m, uint32_t *device_list, uint32_t length) { + pa_idxset *dm_device_list; + uint32_t found_count = 0; + uint32_t i = 0; + + pa_assert(m); + pa_assert(device_list); + + dm_device_list = pa_device_manager_get_device_list(m->dm); + + for (i = 0; i < length; i++) { + pa_tz_device *dm_device; + uint32_t dm_device_id; + uint32_t idx = 0; + + PA_IDXSET_FOREACH(dm_device, dm_device_list, idx) { + dm_device_id = pa_tz_device_get_id(dm_device); + if (device_list[i] == dm_device_id) { + pa_log_debug("device[%u] is connected", dm_device_id); + found_count++; + if (length == found_count) + return true; + break; + } + } + } + + return false; } static void handle_set_stream_route_devices(DBusConnection *conn, DBusMessage *msg, void *userdata) { @@ -1204,6 +1245,7 @@ static void handle_set_stream_route_devices(DBusConnection *conn, DBusMessage *m stream_parent *sp = NULL; DBusMessage *reply = NULL; pa_stream_manager *m = (pa_stream_manager*)userdata; + ret_msg_t ret = RET_MSG_OK; pa_assert(conn); pa_assert(msg); @@ -1220,52 +1262,63 @@ static void handle_set_stream_route_devices(DBusConnection *conn, DBusMessage *m pa_assert_se((reply = dbus_message_new_method_return(msg))); sp = pa_hashmap_get(m->stream_parents, (const void*)id); - if (sp) { - if (!in_device_list && !out_device_list) { - pa_log_error("invalid arguments"); - goto fail; - } - if (!sp->idx_route_in_devices || !sp->idx_route_out_devices) { - pa_log_error("failed to update, idx_route_in_devices[%p], idx_route_out_devices[%p]", - sp->idx_route_in_devices, sp->idx_route_out_devices); - goto fail; - } + if (!sp) { + pa_log_error("could not find matching client for this parent_id[%u]", id); + ret = RET_MSG_ERROR_INTERNAL; + goto finish; + } + if (!in_device_list && !out_device_list) { + pa_log_error("invalid arguments"); + ret = RET_MSG_ERROR_INVALID_ARGUMENT; + goto finish; + } + if (!sp->idx_route_in_devices || !sp->idx_route_out_devices) { + pa_log_error("failed to update, idx_route_in_devices[%p], idx_route_out_devices[%p]", + sp->idx_route_in_devices, sp->idx_route_out_devices); + ret = RET_MSG_ERROR_INTERNAL; + goto finish; + } - PA_IDXSET_FOREACH(device_id, sp->idx_route_in_devices, idx) { - pa_idxset_remove_by_data(sp->idx_route_in_devices, device_id, NULL); - pa_xfree(device_id); - } - if (in_device_list && list_len_in) { - for (i = 0; i < list_len_in; i++) { - pa_idxset_put(sp->idx_route_in_devices, pa_xmemdup(&in_device_list[i], sizeof(uint32_t)), NULL); - pa_log_debug(" -- [in] device id:%u", in_device_list[i]); - } - } - update_devices_and_trigger_routing(m, sp, STREAM_SOURCE_OUTPUT); + /* check if all the requested devices are connected now */ + if (in_device_list && !check_all_requested_devices_connected(m, in_device_list, list_len_in)) { + pa_log_error("could not find requested in-devices"); + ret = RET_MSG_ERROR_DEVICE_NOT_FOUND; + goto finish; + } + if (out_device_list && !check_all_requested_devices_connected(m, out_device_list, list_len_out)) { + pa_log_error("could not find requested out-devices"); + ret = RET_MSG_ERROR_DEVICE_NOT_FOUND; + goto finish; + } - PA_IDXSET_FOREACH(device_id, sp->idx_route_out_devices, idx) { - pa_idxset_remove_by_data(sp->idx_route_out_devices, device_id, NULL); - pa_xfree(device_id); - } - if (out_device_list && list_len_out) { - for (i = 0; i < list_len_out; i++) { - pa_idxset_put(sp->idx_route_out_devices, pa_xmemdup(&out_device_list[i], sizeof(uint32_t)), NULL); - pa_log_debug(" -- [out] device id:%u", out_device_list[i]); - } + PA_IDXSET_FOREACH(device_id, sp->idx_route_in_devices, idx) { + pa_idxset_remove_by_data(sp->idx_route_in_devices, device_id, NULL); + pa_xfree(device_id); + } + if (in_device_list && list_len_in) { + for (i = 0; i < list_len_in; i++) { + pa_idxset_put(sp->idx_route_in_devices, pa_xmemdup(&in_device_list[i], sizeof(uint32_t)), NULL); + pa_log_debug(" -- [in] device id:%u", in_device_list[i]); } - update_devices_and_trigger_routing(m, sp, STREAM_SINK_INPUT); + } + if ((ret = update_devices_and_trigger_routing(m, sp, STREAM_SOURCE_OUTPUT))) + goto finish; - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_OK], DBUS_TYPE_INVALID)); - } else { - pa_log_error("could not find matching client for this parent_id[%u]", id); - goto fail; + PA_IDXSET_FOREACH(device_id, sp->idx_route_out_devices, idx) { + pa_idxset_remove_by_data(sp->idx_route_out_devices, device_id, NULL); + pa_xfree(device_id); } + if (out_device_list && list_len_out) { + for (i = 0; i < list_len_out; i++) { + pa_idxset_put(sp->idx_route_out_devices, pa_xmemdup(&out_device_list[i], sizeof(uint32_t)), NULL); + pa_log_debug(" -- [out] device id:%u", out_device_list[i]); + } + } + if ((ret = update_devices_and_trigger_routing(m, sp, STREAM_SINK_INPUT))) + goto finish; - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); - return; -fail: - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], DBUS_TYPE_INVALID)); +finish: + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret], DBUS_TYPE_INVALID)); pa_assert_se(dbus_connection_send(conn, reply, NULL)); dbus_message_unref(reply); } @@ -1318,17 +1371,17 @@ static void handle_set_stream_route_option(DBusConnection *conn, DBusMessage *ms } if (!updated) { pa_log_error("invalid state"); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR_NO_STREAM], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_NO_STREAM], DBUS_TYPE_INVALID)); } else - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_OK], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_OK], DBUS_TYPE_INVALID)); } else { pa_log_error("invalid arguments"); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INVALID_ARGUMENT], DBUS_TYPE_INVALID)); } } else { pa_log_error("could not find matching client for this parent_id[%u]", id); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INTERNAL], DBUS_TYPE_INVALID)); } pa_assert_se(dbus_connection_send(conn, reply, NULL)); @@ -1362,15 +1415,15 @@ static void handle_set_volume_level(DBusConnection *conn, DBusMessage *msg, void else if (pa_streq(direction, "out")) stream_type = STREAM_SINK_INPUT; else { - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INTERNAL], DBUS_TYPE_INVALID)); ret = -1; goto finish; } if ((ret = set_volume_level_by_type(m, stream_type, type, level))) - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INTERNAL], DBUS_TYPE_INVALID)); else - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_OK], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_OK], DBUS_TYPE_INVALID)); finish: pa_assert_se(dbus_connection_send(conn, reply, NULL)); @@ -1406,16 +1459,16 @@ static void handle_get_volume_level(DBusConnection *conn, DBusMessage *msg, void stream_type = STREAM_SINK_INPUT; else { pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, 0, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INTERNAL], DBUS_TYPE_INVALID)); goto finish; } if (get_volume_level_by_type(m, GET_VOLUME_CURRENT_LEVEL, stream_type, type, &level)) { pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, 0, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INTERNAL], DBUS_TYPE_INVALID)); } else { pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, &level, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_OK], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_OK], DBUS_TYPE_INVALID)); } finish: @@ -1449,16 +1502,16 @@ static void handle_get_volume_max_level(DBusConnection *conn, DBusMessage *msg, stream_type = STREAM_SINK_INPUT; else { pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, 0, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INTERNAL], DBUS_TYPE_INVALID)); goto finish; } if (get_volume_level_by_type(m, GET_VOLUME_MAX_LEVEL, stream_type, type, &level)) { pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, 0, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INTERNAL], DBUS_TYPE_INVALID)); } else { pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, &level, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_OK], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_OK], DBUS_TYPE_INVALID)); } finish: pa_assert_se(dbus_connection_send(conn, reply, NULL)); @@ -1491,14 +1544,14 @@ static void handle_set_volume_mute(DBusConnection *conn, DBusMessage *msg, void else if (pa_streq(direction, "out")) stream_type = STREAM_SINK_INPUT; else { - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INTERNAL], DBUS_TYPE_INVALID)); goto finish; } if (set_volume_mute_by_type(m, stream_type, type, (bool)do_mute)) - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INTERNAL], DBUS_TYPE_INVALID)); else - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_OK], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_OK], DBUS_TYPE_INVALID)); finish: pa_assert_se(dbus_connection_send(conn, reply, NULL)); @@ -1531,16 +1584,16 @@ static void handle_get_volume_mute(DBusConnection *conn, DBusMessage *msg, void stream_type = STREAM_SINK_INPUT; else { pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, 0, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INTERNAL], DBUS_TYPE_INVALID)); goto fail; } if (get_volume_mute_by_type(m, stream_type, type, (bool*)&is_muted)) { pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, 0, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INTERNAL], DBUS_TYPE_INVALID)); } else { pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, &is_muted, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_OK], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_OK], DBUS_TYPE_INVALID)); } fail: @@ -1577,7 +1630,7 @@ static void handle_get_current_volume_type(DBusConnection *conn, DBusMessage *ms streams = m->core->sink_inputs; } else { pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &dbus_str_none, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INTERNAL], DBUS_TYPE_INVALID)); goto fail; } @@ -1609,10 +1662,10 @@ static void handle_get_current_volume_type(DBusConnection *conn, DBusMessage *ms if (type) { pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &type, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_OK], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_OK], DBUS_TYPE_INVALID)); } else { pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &dbus_str_none, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR_NO_STREAM], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_NO_STREAM], DBUS_TYPE_INVALID)); } fail: @@ -1672,13 +1725,13 @@ static void handle_get_current_media_routing_path(DBusConnection *conn, DBusMess fail: pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &dbus_str_none, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INTERNAL], DBUS_TYPE_INVALID)); pa_assert_se(dbus_connection_send(conn, reply, NULL)); dbus_message_unref(reply); return; success: pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &device_type, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_OK], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_OK], DBUS_TYPE_INVALID)); pa_assert_se(dbus_connection_send(conn, reply, NULL)); dbus_message_unref(reply); } @@ -1734,10 +1787,10 @@ static void handle_update_focus_status(DBusConnection *conn, DBusMessage *msg, v } else { pa_log_error("could not find matching client for this parent_id[%u]", id); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INTERNAL], DBUS_TYPE_INVALID)); goto fail; } - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_OK], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_OK], DBUS_TYPE_INVALID)); fail: pa_assert_se(dbus_connection_send(conn, reply, NULL)); dbus_message_unref(reply); @@ -1776,13 +1829,13 @@ static void handle_update_focus_status_by_focus_id(DBusConnection *conn, DBusMes acquired_focus_status ? STREAM_FOCUS_STATE_ACQUIRED : STREAM_FOCUS_STATE_RELEASED); process_stream(m, i, STREAM_SINK_INPUT, PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_FOCUS_CHANGED, false); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_OK], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_OK], DBUS_TYPE_INVALID)); goto success; } } } pa_log_error("could not find matching stream for this focus_id[%i]", id); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INTERNAL], DBUS_TYPE_INVALID)); success: pa_assert_se(dbus_connection_send(conn, reply, NULL)); dbus_message_unref(reply); @@ -1807,11 +1860,11 @@ static void handle_update_restriction(DBusConnection *conn, DBusMessage *msg, vo pa_assert_se((reply = dbus_message_new_method_return(msg))); if (handle_restrictions(m, name, value) < 0) { - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INTERNAL], DBUS_TYPE_INVALID)); goto fail; } - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_OK], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_OK], DBUS_TYPE_INVALID)); fail: pa_assert_se(dbus_connection_send(conn, reply, NULL)); dbus_message_unref(reply); @@ -1839,12 +1892,12 @@ static void handle_set_filter(DBusConnection *conn, DBusMessage *msg, void *user /* Set filter sink according to stream type */ if (update_filter(m, filter_name, filter_parameters, filter_group, stream_type) < 0) { - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INTERNAL], DBUS_TYPE_INVALID)); goto fail; } - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_OK], + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_OK], DBUS_TYPE_INVALID)); fail: @@ -1870,12 +1923,12 @@ static void handle_unset_filter(DBusConnection *conn, DBusMessage *msg, void *us /* Unset filter sink according to stream type */ if (update_filter(m, NULL, NULL, NULL, stream_type) < 0) { - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INTERNAL], DBUS_TYPE_INVALID)); goto fail; } - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_OK], + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_OK], DBUS_TYPE_INVALID)); fail: @@ -1904,12 +1957,12 @@ static void handle_control_filter(DBusConnection *conn, DBusMessage *msg, void * /* Control parameters to filter sink */ if (control_filter(m, filter_name, filter_controls, stream_type, conn) < 0) { - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INTERNAL], DBUS_TYPE_INVALID)); goto fail; } - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_OK], + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_OK], DBUS_TYPE_INVALID)); fail: pa_assert_se(dbus_connection_send(conn, reply, NULL)); @@ -1942,18 +1995,18 @@ static void handle_check_stream_exist_by_pid(DBusConnection *conn, DBusMessage * else if (pa_streq(direction, "out")) stream_type = STREAM_SINK_INPUT; else { - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INVALID_ARGUMENT], DBUS_TYPE_INVALID)); goto fail; } if (!check_stream_exist_by_pid(m, pid, type, stream_type)) { - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR_NO_STREAM], + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_NO_STREAM], DBUS_TYPE_INVALID)); goto fail; } - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_OK], + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_OK], DBUS_TYPE_INVALID)); fail: pa_assert_se(dbus_connection_send(conn, reply, NULL)); @@ -3013,7 +3066,7 @@ static void fill_device_info_to_hook_data(pa_stream_manager *m, void *hook_data, } } -static void do_notify(pa_stream_manager *m, notify_command_type_t command, stream_type_t type, bool is_new_data, void *user_data) { +static ret_msg_t do_notify(pa_stream_manager *m, notify_command_type_t command, stream_type_t type, bool is_new_data, void *user_data) { pa_stream_manager_hook_data_for_select hook_call_select_data; pa_stream_manager_hook_data_for_route hook_call_route_data; hal_stream_connection_info stream_conn_info; @@ -3021,6 +3074,7 @@ static void do_notify(pa_stream_manager *m, notify_command_type_t command, strea const char *role = NULL; void *s = NULL; const char *modifier_gain = NULL; + ret_msg_t ret = RET_MSG_OK; pa_assert(m); pa_log_debug("do_notify(%s): type(%d), is_new_data(%d), user_data(%p)", notify_command_type_str[command], type, is_new_data, user_data); @@ -3073,7 +3127,8 @@ static void do_notify(pa_stream_manager *m, notify_command_type_t command, strea hook_call_select_data.proper_source = &(((pa_source_output*)s)->source); } CONVERT_TO_DEVICE_ROLE(hook_call_select_data.stream_role, hook_call_select_data.device_role); - pa_hook_fire(pa_communicator_hook(m->comm.comm, PA_COMMUNICATOR_HOOK_SELECT_INIT_SINK_OR_SOURCE), &hook_call_select_data); + if (pa_hook_fire(pa_communicator_hook(m->comm.comm, PA_COMMUNICATOR_HOOK_SELECT_INIT_SINK_OR_SOURCE), &hook_call_select_data)) + ret = RET_MSG_ERROR_INTERNAL; BREAK_WITH_FREE: pa_xfree(filtered_avail_devices); } @@ -3109,7 +3164,8 @@ BREAK_WITH_FREE: hook_call_route_data.stream = NULL; } } - pa_hook_fire(pa_communicator_hook(m->comm.comm, PA_COMMUNICATOR_HOOK_CHANGE_ROUTE), &hook_call_route_data); + if (pa_hook_fire(pa_communicator_hook(m->comm.comm, PA_COMMUNICATOR_HOOK_CHANGE_ROUTE), &hook_call_route_data)) + ret = RET_MSG_ERROR_INTERNAL; } break; } @@ -3132,7 +3188,8 @@ BREAK_WITH_FREE: hook_call_route_data.stream = NULL; hook_call_route_data.stream_type = type; } - pa_hook_fire(pa_communicator_hook(m->comm.comm, PA_COMMUNICATOR_HOOK_CHANGE_ROUTE), &hook_call_route_data); + if (pa_hook_fire(pa_communicator_hook(m->comm.comm, PA_COMMUNICATOR_HOOK_CHANGE_ROUTE), &hook_call_route_data)) + ret = RET_MSG_ERROR_INTERNAL; break; } case NOTIFY_COMMAND_UPDATE_ROUTE_OPTION: { @@ -3145,7 +3202,8 @@ BREAK_WITH_FREE: (m->cur_highest_priority.role_so); route_option.name = ((stream_route_option*)user_data)->name; route_option.value = ((stream_route_option*)user_data)->value; - pa_hal_interface_update_route_option(m->hal, &route_option); + if (pa_hal_interface_update_route_option(m->hal, &route_option)) + ret = RET_MSG_ERROR_INTERNAL; } break; } @@ -3159,11 +3217,14 @@ BREAK_WITH_FREE: stream_conn_info.direction = (type == STREAM_SINK_INPUT) ? DIRECTION_OUT : DIRECTION_IN; stream_conn_info.idx = GET_STREAM_INDEX(s, type); stream_conn_info.is_connected = (command == NOTIFY_COMMAND_INFORM_STREAM_CONNECTED) ? true : false; - pa_hal_interface_notify_stream_connection_changed(m->hal, &stream_conn_info); + if (pa_hal_interface_notify_stream_connection_changed(m->hal, &stream_conn_info)) + ret = RET_MSG_ERROR_INTERNAL; } break; } } + + return ret; } static void update_mirroring_streams(pa_stream_manager *m, pa_source_output *o, bool put) { -- 2.7.4