From 2e2db377b4dfd8293a393ca8a8cb7a0e303f9807 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Mon, 13 Jul 2020 11:13:47 +0900 Subject: [PATCH 01/16] tizenaudio-publish: publish only built-in devices [Version] 13.0.24 [Issue Type] Update Change-Id: I69753da561c813c80c35df7690d4efc1efc48a43 --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/module-tizenaudio-publish.c | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 78eccb1..9324ca1 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: 13.0.23 +Version: 13.0.24 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/module-tizenaudio-publish.c b/src/module-tizenaudio-publish.c index 480b98f..cdead84 100644 --- a/src/module-tizenaudio-publish.c +++ b/src/module-tizenaudio-publish.c @@ -329,14 +329,30 @@ static void service_free(struct service *s) { pa_xfree(s); } +static bool is_builtin_device(pa_proplist *pl) +{ + /* FIXME: Determining the built-in device should be retrieved from device-manager. */ + return pa_safe_streq(pa_proplist_gets(pl, PA_PROP_DEVICE_FORM_FACTOR), "internal"); +} + static bool shall_ignore(pa_object *o) { pa_object_assert_ref(o); - if (pa_sink_isinstance(o)) + if (pa_sink_isinstance(o)) { + if (!is_builtin_device(PA_SINK(o)->proplist)) { + pa_log_error("sink [%s] is not an internal, skip this", PA_SINK(o)->name); + return true; + } return !!(PA_SINK(o)->flags & PA_SINK_NETWORK); + } - if (pa_source_isinstance(o)) + if (pa_source_isinstance(o)) { + if (!is_builtin_device(PA_SOURCE(o)->proplist)) { + pa_log_error("source [%s] is not an internal, skip this", PA_SOURCE(o)->name); + return true; + } return PA_SOURCE(o)->monitor_of || (PA_SOURCE(o)->flags & PA_SOURCE_NETWORK); + } pa_assert_not_reached(); } -- 2.7.4 From c3a2c2f15263d3af53c3904da00631e6da68db89 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Tue, 18 Aug 2020 19:36:53 +0900 Subject: [PATCH 02/16] device-manager: handle tunnel device tunnel device will be registered(unregistered) when the remote access permission is allowed(denied). tunnel device will be a network type device [Version] 13.0.25 [Issue Type] Update Change-Id: I897fcb5a74ee55c60112e5a9d956c909aae736d0 --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/device-manager-priv.h | 2 + src/device-manager.c | 109 ++++++++++++++++++++++++++++++++ src/tizen-device-def.h | 1 + 4 files changed, 113 insertions(+), 1 deletion(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 9324ca1..3d9e02b 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: 13.0.24 +Version: 13.0.25 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/device-manager-priv.h b/src/device-manager-priv.h index faf4b1d..5e17f2c 100644 --- a/src/device-manager-priv.h +++ b/src/device-manager-priv.h @@ -53,6 +53,8 @@ struct _device_manager { pa_hook_slot *comm_hook_device_connection_changed_slot; pa_hook_slot *comm_hook_device_state_changed_slot; pa_hook_slot *comm_hook_device_running_changed_slot; + pa_hook_slot *source_proplist_changed_slot; + pa_hook_slot *sink_proplist_changed_slot; pa_communicator *comm; pa_hal_interface *hal_interface; diff --git a/src/device-manager.c b/src/device-manager.c index 6276308..7fc3435 100644 --- a/src/device-manager.c +++ b/src/device-manager.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -80,6 +81,7 @@ #define DEVICE_API_NULL "null" #define DEVICE_API_ACM "acm" #define DEVICE_API_RAOP "raop" +#define DEVICE_API_TUNNEL "tunnel" #define DEVICE_BUS_USB "usb" #define DEVICE_CLASS_SOUND "sound" #define DEVICE_CLASS_MONITOR "monitor" @@ -397,6 +399,14 @@ static bool pulse_device_is_raop(pa_object *pdevice) { return pa_safe_streq(pa_proplist_gets(prop, PA_PROP_DEVICE_API), DEVICE_API_RAOP); } +static bool pulse_device_is_tunnel(pa_object *pdevice) { + pa_proplist *prop = pulse_device_get_proplist(pdevice); + + if (!prop) + return false; + + return pa_safe_streq(pa_proplist_gets(prop, PA_PROP_DEVICE_API), DEVICE_API_TUNNEL); +} static bool pulse_device_is_tizenaudio(pa_object *pdevice) { if (!pdevice) @@ -1140,6 +1150,8 @@ static const char* pulse_device_get_system_id(pa_object *pdevice) { return pa_proplist_gets(prop, "bluez.path"); else if (pulse_device_is_raop(pdevice)) return pa_proplist_gets(prop, PA_PROP_DEVICE_STRING); + else if (pulse_device_is_tunnel(pdevice)) + return pa_proplist_gets(prop, PA_PROP_DEVICE_DESCRIPTION); else return NULL; } @@ -1469,6 +1481,43 @@ static void handle_raop_pulse_device(pa_object *pdevice, bool is_loaded, pa_devi } } +static void handle_tunnel_pulse_device(pa_object *pdevice, bool is_loaded, pa_device_manager *dm) { + dm_device_direction_t direction; + pa_tz_device *device; + const char *system_id; + + pa_assert(pdevice); + pa_assert(dm); + + pa_log_info("Handle TUNNEL pulse device"); + + direction = pulse_device_get_direction(pdevice); + system_id = pulse_device_get_system_id(pdevice); + + if (is_loaded) { + pa_tz_device_new_data data; + + pa_proplist *prop = pulse_device_get_proplist(pdevice); + const char *name = pa_proplist_gets(prop, PA_PROP_DEVICE_DESCRIPTION); + + pa_tz_device_new_data_init(&data, dm->device_list, dm->comm, dm->dbus_conn); + _fill_new_data_basic(&data, DEVICE_TYPE_NETWORK, direction, false, dm); + pa_tz_device_new_data_set_name(&data, name); + pa_tz_device_new_data_set_system_id(&data, system_id); + if (direction == DM_DEVICE_DIRECTION_OUT) + pa_tz_device_new_data_add_sink(&data, DEVICE_ROLE_TUNNEL, PA_SINK(pdevice)); + else + pa_tz_device_new_data_add_source(&data, DEVICE_ROLE_TUNNEL, PA_SOURCE(pdevice)); + pa_tz_device_new(&data); + pa_tz_device_new_data_done(&data); + } else { + if (!(device = device_list_get_device(dm, DEVICE_TYPE_NETWORK, NULL, system_id))) + pa_log_warn("Can't get REMOTE device for %s", system_id); + else + pa_tz_device_free(device); + } +} + static void handle_acm_pulse_device(pa_object *pdevice, bool is_loaded, pa_device_manager *dm) { pa_tz_device *device; @@ -1602,6 +1651,18 @@ static pa_hook_result_t sink_unlink_hook_callback(pa_core *c, pa_sink *sink, pa_ } else if (pulse_device_is_raop(PA_OBJECT(sink))) { handle_raop_pulse_device(PA_OBJECT(sink), false, dm); return PA_HOOK_OK; + } else if (pulse_device_is_tunnel(PA_OBJECT(sink))) { + if (pa_proplist_has_remote_name(sink->proplist)) { + if (pa_proplist_remote_is_allowed(sink->proplist)) { + pa_log_info("allowed sink is unlinked, update to deny now"); + pa_sink_update_proplist_remote_access_permission(sink, false); + } else { + pa_log_info("denied sink is unlinked, nothing to do"); + } + } else { + pa_log_warn("tunnel but not remote....ignore this"); + } + return PA_HOOK_OK; } else if (pulse_device_is_acm(PA_OBJECT(sink))) { handle_acm_pulse_device(PA_OBJECT(sink), false, dm); return PA_HOOK_OK; @@ -1660,6 +1721,18 @@ static pa_hook_result_t source_unlink_hook_callback(pa_core *c, pa_source *sourc } else if (pulse_device_is_bluez(PA_OBJECT(source))) { handle_bt_pulse_device(PA_OBJECT(source), false, dm); return PA_HOOK_OK; + } else if (pulse_device_is_tunnel(PA_OBJECT(source))) { + if (pa_proplist_has_remote_name(source->proplist)) { + if (pa_proplist_remote_is_allowed(source->proplist)) { + pa_log_info("allowed source is unlinked, update to deny now"); + pa_source_update_proplist_remote_access_permission(source, false); + } else { + pa_log_info("denied source is unlinked, nothing to do"); + } + } else { + pa_log_warn("tunnel but not remote....ignore this"); + } + return PA_HOOK_OK; } else if (pulse_device_is_alsa(PA_OBJECT(source)) || pulse_device_is_tizenaudio(PA_OBJECT(source))) { handle_internal_pulse_device(PA_OBJECT(source), false, dm); return PA_HOOK_OK; @@ -1698,6 +1771,32 @@ static pa_hook_result_t sink_source_state_changed_hook_cb(pa_core *c, pa_object return PA_HOOK_OK; } +static pa_hook_result_t source_proplist_changed(pa_core *core, pa_source *source, pa_device_manager *dm) { + pa_core_assert_ref(core); + pa_source_assert_ref(source); + + if (pulse_device_is_tunnel(PA_OBJECT(source)) && + pa_proplist_has_remote_name(source->proplist)) { + /* FIXME : skip if no changes */ + pulse_device_set_use_internal_codec(PA_OBJECT(source), false); + handle_tunnel_pulse_device(PA_OBJECT(source), pa_proplist_remote_is_allowed(source->proplist), dm); + } + return PA_HOOK_OK; +} + +static pa_hook_result_t sink_proplist_changed(pa_core *core, pa_sink *sink, pa_device_manager *dm) { + pa_core_assert_ref(core); + pa_sink_assert_ref(sink); + + if (pulse_device_is_tunnel(PA_OBJECT(sink)) && + pa_proplist_has_remote_name(sink->proplist)) { + /* FIXME : skip if no changes */ + pulse_device_set_use_internal_codec(PA_OBJECT(sink), false); + handle_tunnel_pulse_device(PA_OBJECT(sink), pa_proplist_remote_is_allowed(sink->proplist), dm); + } + return PA_HOOK_OK; +} + /* Build params for load sink or source, and load it. */ @@ -2776,9 +2875,13 @@ pa_device_manager* pa_device_manager_get(pa_core *c) { dm->sink_put_hook_slot = pa_hook_connect(&dm->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_LATE+10, (pa_hook_cb_t) sink_put_hook_callback, dm); dm->sink_unlink_hook_slot = pa_hook_connect(&dm->core->hooks[PA_CORE_HOOK_SINK_UNLINK], PA_HOOK_EARLY, (pa_hook_cb_t) sink_unlink_hook_callback, dm); dm->sink_state_changed_slot = pa_hook_connect(&dm->core->hooks[PA_CORE_HOOK_SINK_STATE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_source_state_changed_hook_cb, dm); + dm->sink_proplist_changed_slot = pa_hook_connect(&dm->core->hooks[PA_CORE_HOOK_SINK_PROPLIST_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_proplist_changed, dm); + dm->source_put_hook_slot = pa_hook_connect(&dm->core->hooks[PA_CORE_HOOK_SOURCE_PUT], PA_HOOK_LATE+10, (pa_hook_cb_t) source_put_hook_callback, dm); dm->source_unlink_hook_slot = pa_hook_connect(&dm->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK], PA_HOOK_EARLY, (pa_hook_cb_t) source_unlink_hook_callback, dm); dm->source_state_changed_slot = pa_hook_connect(&dm->core->hooks[PA_CORE_HOOK_SOURCE_STATE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_source_state_changed_hook_cb, dm); + dm->source_proplist_changed_slot = pa_hook_connect(&dm->core->hooks[PA_CORE_HOOK_SOURCE_PROPLIST_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) source_proplist_changed, dm); + dm->comm = pa_communicator_get(dm->core); dm->comm_hook_device_connection_changed_slot = pa_hook_connect(pa_communicator_hook(dm->comm, PA_COMMUNICATOR_HOOK_DEVICE_CONNECTION_CHANGED), PA_HOOK_EARLY, (pa_hook_cb_t)device_connection_changed_hook_cb, dm); @@ -2843,18 +2946,24 @@ void pa_device_manager_unref(pa_device_manager *dm) { pa_hook_slot_free(dm->comm_hook_device_state_changed_slot); if (dm->comm_hook_device_running_changed_slot) pa_hook_slot_free(dm->comm_hook_device_running_changed_slot); + if (dm->sink_put_hook_slot) pa_hook_slot_free(dm->sink_put_hook_slot); if (dm->sink_unlink_hook_slot) pa_hook_slot_free(dm->sink_unlink_hook_slot); if (dm->sink_state_changed_slot) pa_hook_slot_free(dm->sink_state_changed_slot); + if (dm->sink_proplist_changed_slot) + pa_hook_slot_free(dm->sink_proplist_changed_slot); + if (dm->source_put_hook_slot) pa_hook_slot_free(dm->source_put_hook_slot); if (dm->source_unlink_hook_slot) pa_hook_slot_free(dm->source_unlink_hook_slot); if (dm->source_state_changed_slot) pa_hook_slot_free(dm->source_state_changed_slot); + if (dm->source_proplist_changed_slot) + pa_hook_slot_free(dm->source_proplist_changed_slot); if (dm->hal_interface) pa_hal_interface_unref(dm->hal_interface); diff --git a/src/tizen-device-def.h b/src/tizen-device-def.h index ed91400..e4232da 100644 --- a/src/tizen-device-def.h +++ b/src/tizen-device-def.h @@ -27,6 +27,7 @@ #define DEVICE_ROLE_HIGH_LATENCY "high-latency" #define DEVICE_ROLE_UHQA "uhqa" #define DEVICE_ROLE_RAOP "raop" +#define DEVICE_ROLE_TUNNEL "tunnel" #define DEVICE_ROLE_ACM "acm" typedef enum dm_device_direction_type { -- 2.7.4 From ee06cef6ad7a087ddb440271f072c065cdee9b20 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Tue, 18 Aug 2020 20:10:32 +0900 Subject: [PATCH 03/16] stream-manager: add restriction for accessing denied remote device includes minor code refactoring [Version] 13.0.26 [Issue Type] Update Change-Id: I1d77ff249192bde15b861c9a9d481e3564b791d6 --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/stream-manager-restriction-priv.h | 6 ++-- src/stream-manager-restriction.c | 62 +++++++++++++++++++++++---------- src/stream-manager.c | 5 ++- 4 files changed, 51 insertions(+), 24 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 3d9e02b..06d9cea 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: 13.0.25 +Version: 13.0.26 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/stream-manager-restriction-priv.h b/src/stream-manager-restriction-priv.h index bc1906d..1e738e3 100644 --- a/src/stream-manager-restriction-priv.h +++ b/src/stream-manager-restriction-priv.h @@ -24,10 +24,8 @@ #include "stream-manager.h" -/* dbus method args */ -#define STREAM_MANAGER_METHOD_ARGS_BLOCK_RECORDING_MEDIA "block_recording_media" - int32_t handle_restrictions(pa_stream_manager *m, const char *name, uint32_t value); -bool check_restrictions(pa_stream_manager *m, void *stream, stream_type_t stream_type); +bool is_restricted(pa_stream_manager *m, void *stream, stream_type_t stream_type); +bool is_remote_restricted(void *stream, stream_type_t type); #endif diff --git a/src/stream-manager-restriction.c b/src/stream-manager-restriction.c index 818b6c5..27a91a6 100644 --- a/src/stream-manager-restriction.c +++ b/src/stream-manager-restriction.c @@ -23,9 +23,14 @@ #include #endif +#include + #include "stream-manager-priv.h" #include "stream-manager-restriction-priv.h" +/* dbus method args */ +#define STREAM_MANAGER_METHOD_ARGS_BLOCK_RECORDING_MEDIA "block_recording_media" + int32_t handle_restrictions(pa_stream_manager *m, const char *name, uint32_t value) { const char *role; void *s; @@ -33,33 +38,54 @@ int32_t handle_restrictions(pa_stream_manager *m, const char *name, uint32_t val pa_assert(m); - if (pa_safe_streq(name, STREAM_MANAGER_METHOD_ARGS_BLOCK_RECORDING_MEDIA) ) { - if (value == 1) { - pa_log_info("block MEDIA recording"); - m->restrictions.block_recording_media = true; - PA_IDXSET_FOREACH(s, m->core->source_outputs, idx) { - role = pa_proplist_gets(GET_STREAM_PROPLIST(s, STREAM_SOURCE_OUTPUT), PA_PROP_MEDIA_ROLE); - if (pa_safe_streq(role, "media")) { - pa_log_info(" -- kill source-output(%p, %u)", s, ((pa_source_output*)s)->index); - pa_source_output_kill((pa_source_output*)s); - } + if (!pa_safe_streq(name, STREAM_MANAGER_METHOD_ARGS_BLOCK_RECORDING_MEDIA)) { + pa_log_error("unknown name : %s", pa_strnull(name)); + return -1; + } + + if (value == 1) { + pa_log_info("block MEDIA recording"); + m->restrictions.block_recording_media = true; + PA_IDXSET_FOREACH(s, m->core->source_outputs, idx) { + role = pa_proplist_gets(GET_STREAM_PROPLIST(s, STREAM_SOURCE_OUTPUT), PA_PROP_MEDIA_ROLE); + if (pa_safe_streq(role, "media")) { + pa_log_info(" -- kill source-output(%p, %u)", s, ((pa_source_output*)s)->index); + pa_source_output_kill((pa_source_output*)s); } - } else if (value == 0) { - pa_log_info("MEDIA recording is now available"); - m->restrictions.block_recording_media = false; - } else { - pa_log_error("unknown value"); - return -1; } + } else if (value == 0) { + pa_log_info("MEDIA recording is now available"); + m->restrictions.block_recording_media = false; } else { - pa_log_error("unknown name"); + pa_log_error("unknown value : %u", value); return -1; } return 0; } -bool check_restrictions(pa_stream_manager *m, void *stream, stream_type_t type) { +bool is_remote_restricted(void *stream, stream_type_t type) { + pa_proplist* p = NULL; + if (type == STREAM_SOURCE_OUTPUT) + p = ((pa_source_output_new_data *)stream)->source->proplist; + else + p = ((pa_sink_input_new_data *)stream)->sink->proplist; + + if (!pa_proplist_has_remote_name(p)) { + pa_log_debug("it is a local stream(%p)", stream); + return false; + } + + if (pa_proplist_remote_is_allowed(p)) { + pa_log_info("stream(%p) is currently allowed", stream); + return false; + } + + pa_log_warn("restricted due to denied remote access of stream(%p)!!!", stream); + return true; +} + +bool is_restricted(pa_stream_manager *m, void *stream, stream_type_t type) { const char *role; pa_assert(m); diff --git a/src/stream-manager.c b/src/stream-manager.c index 981d4c6..f75e8f7 100644 --- a/src/stream-manager.c +++ b/src/stream-manager.c @@ -2480,6 +2480,8 @@ static pa_hook_result_t sink_input_new_cb(pa_core *core, pa_sink_input_new_data pa_log_debug("sink-input-new-data(%p)", new_data); process_stream(m, new_data, STREAM_SINK_INPUT, PROCESS_COMMAND_PREPARE, true); + if (is_remote_restricted(new_data, STREAM_SINK_INPUT)) + return PA_HOOK_CANCEL; process_stream(m, new_data, STREAM_SINK_INPUT, PROCESS_COMMAND_UPDATE_BUFFER_ATTR, true); process_stream(m, new_data, STREAM_SINK_INPUT, PROCESS_COMMAND_UPDATE_VOLUME, true); process_stream(m, new_data, STREAM_SINK_INPUT, PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_STARTED, true); @@ -2635,7 +2637,8 @@ static pa_hook_result_t source_output_new_cb(pa_core *core, pa_source_output_new pa_log_debug("source-output-new-data(%p)", new_data); process_stream(m, new_data, STREAM_SOURCE_OUTPUT, PROCESS_COMMAND_PREPARE, true); - if (check_restrictions(m, new_data, STREAM_SOURCE_OUTPUT)) + if (is_restricted(m, new_data, STREAM_SOURCE_OUTPUT) || + is_remote_restricted(new_data, STREAM_SOURCE_OUTPUT)) return PA_HOOK_CANCEL; process_stream(m, new_data, STREAM_SOURCE_OUTPUT, PROCESS_COMMAND_UPDATE_BUFFER_ATTR, true); process_stream(m, new_data, STREAM_SOURCE_OUTPUT, PROCESS_COMMAND_UPDATE_VOLUME, true); -- 2.7.4 From 3a83081231b354654b47e45b1b004ec7f898c866 Mon Sep 17 00:00:00 2001 From: Jaechul Lee Date: Wed, 19 Aug 2020 11:48:15 +0900 Subject: [PATCH 04/16] stream-manager: add publish/discover/set_permission interfaces method name : SetRemotePermission method argument : [in] string for type [in] unsigned for index [in] boolean for allowed return value : None method name : DiscoverRemoteDevice method argument : [in] boolean for enable return value : None method name : PublishLocalDevice method argument : [in] boolean for enable return value : None [Version] 13.0.27 [Issue Type] New feature Change-Id: I6ab4a388410dcf4d9480bdc1aaaaa7202a199a9f Signed-off-by: Jaechul Lee --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/stream-manager-dbus-priv.h | 29 +++- src/stream-manager-dbus.c | 226 +++++++++++++++++++++++++++++++- src/stream-manager-priv.h | 11 +- src/stream-manager.c | 61 +++++++++ 5 files changed, 325 insertions(+), 4 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 06d9cea..bb99b51 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: 13.0.26 +Version: 13.0.27 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/stream-manager-dbus-priv.h b/src/stream-manager-dbus-priv.h index 166c3a3..940940a 100644 --- a/src/stream-manager-dbus-priv.h +++ b/src/stream-manager-dbus-priv.h @@ -54,10 +54,14 @@ #define STREAM_MANAGER_METHOD_NAME_GET_PID_OF_LATEST_STREAM "GetPidOfLatestStream" #define STREAM_MANAGER_METHOD_NAME_ACTIVATE_DUCKING "ActivateDucking" #define STREAM_MANAGER_METHOD_NAME_GET_DUCKING_STATE "GetDuckingState" +#define STREAM_MANAGER_METHOD_NAME_SET_REMOTE_PERMISSION "SetRemotePermission" +#define STREAM_MANAGER_METHOD_NAME_DISCOVER_REMOTE_DEVICE "DiscoverRemoteDevice" +#define STREAM_MANAGER_METHOD_NAME_PUBLISH_LOCAL_DEVICE "PublishLocalDevice" /* signal */ #define STREAM_MANAGER_SIGNAL_NAME_VOLUME_CHANGED "VolumeChanged" #define STREAM_MANAGER_SIGNAL_NAME_DUCKING_STATE_CHANGED "DuckingStateChanged" #define STREAM_MANAGER_SIGNAL_NAME_COMMAND "Command" +#define STREAM_MANAGER_SIGNAL_NAME_REMOTE_FOUND "RemoteFound" enum method_handler_index { METHOD_HANDLER_GET_STREAM_INFO, @@ -88,6 +92,9 @@ enum method_handler_index { METHOD_HANDLER_GET_PID_OF_LATEST_STREAM, METHOD_HANDLER_ACTIVATE_DUCKING, METHOD_HANDLER_GET_DUCKING_STATE, + METHOD_HANDLER_NAME_SET_REMOTE_PERMISSION, + METHOD_HANDLER_DISCOVER_REMOTE_DEVICE, + METHOD_HANDLER_PUBLISH_LOCAL_DEVICE, METHOD_HANDLER_MAX }; @@ -266,6 +273,17 @@ pa_dbus_interface_info stream_manager_interface_info = { " " \ " " \ " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ " " \ " " \ " " \ @@ -275,6 +293,13 @@ pa_dbus_interface_info stream_manager_interface_info = { " " \ " " \ " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ " " \ " " \ " " \ @@ -286,9 +311,11 @@ pa_dbus_interface_info stream_manager_interface_info = { void send_ducking_state_changed_signal(DBusConnection *conn, const int index, const int is_ducked); void send_command_signal(DBusConnection *conn, const char *name, int value); +void send_remote_found_signal(DBusConnection *conn, int type, bool connected, + unsigned int index, const char *name, const char *description); int32_t init_sm_dbus(pa_stream_manager *m); void deinit_sm_dbus(pa_stream_manager *m); #endif -#endif \ No newline at end of file +#endif diff --git a/src/stream-manager-dbus.c b/src/stream-manager-dbus.c index a6e7506..0367446 100644 --- a/src/stream-manager-dbus.c +++ b/src/stream-manager-dbus.c @@ -25,6 +25,7 @@ #ifdef HAVE_DBUS +#include #include "stream-manager-priv.h" #include "stream-manager-dbus-priv.h" #include "stream-manager-volume-priv.h" @@ -70,6 +71,9 @@ static void handle_check_stream_exist_by_pid(DBusConnection *conn, DBusMessage * static void handle_get_pid_of_latest_stream(DBusConnection *conn, DBusMessage *msg, void *userdata); static void handle_activate_ducking(DBusConnection *conn, DBusMessage *msg, void *userdata); static void handle_get_ducking_state(DBusConnection *conn, DBusMessage *msg, void *userdata); +static void handle_set_remote_permission(DBusConnection *conn, DBusMessage *msg, void *userdata); +static void handle_discover_remote_device(DBusConnection *conn, DBusMessage *msg, void *userdata); +static void handle_publish_local_device(DBusConnection *conn, DBusMessage *msg, void *userdata); static void send_volume_changed_signal(DBusConnection *conn, const char *direction, const char *volume_type, const uint32_t volume_level); static pa_dbus_arg_info get_stream_info_args[] = { { "stream_type", "s", "in" }, @@ -179,6 +183,11 @@ static pa_dbus_arg_info activate_ducking_args[] = { { "index", "u", "in" }, static pa_dbus_arg_info get_ducking_state_args[] = { { "index", "u", "in" }, { "is_ducked", "b", "out" }, { "ret_msg", "s", "out" } }; +static pa_dbus_arg_info set_remote_permission_args[] = { { "type", "s", "in" }, + { "index", "u", "in" }, + { "allowed", "b", "in" } }; +static pa_dbus_arg_info discover_remote_device_args[] = { { "enable", "b", "in" } }; +static pa_dbus_arg_info publish_local_device_args[] = { { "enable", "b", "in" } }; static const char* signature_args_for_in[] = { "s", /* METHOD_HANDLER_GET_STREAM_INFO */ @@ -208,7 +217,10 @@ static const char* signature_args_for_in[] = { "uss", /* METHOD_HANDLER_CHECK_STREAM_EXIST_BY_PID */ "sas", /* METHOD_HANDLER_GET_PID_OF_LATEST_STREAM */ "ubsud", /* METHOD_HANDLER_ACTIVATE_DUCKING */ - "u" /* METHOD_HANDLER_GET_DUCKING_STATE */ + "u", /* METHOD_HANDLER_GET_DUCKING_STATE */ + "sub", /* METHOD_HANDLER_SET_REMOTE_PERMISSION */ + "b", /* METHOD_HANDLER_DISCOVER_REMOTE_DEVICE */ + "b" /* METHOD_HANDLER_PUBLISH_LOCAL_DEVICE */ }; static pa_dbus_method_handler method_handlers[METHOD_HANDLER_MAX] = { @@ -352,6 +364,21 @@ static pa_dbus_method_handler method_handlers[METHOD_HANDLER_MAX] = { .arguments = get_ducking_state_args, .n_arguments = sizeof(get_ducking_state_args) / sizeof(pa_dbus_arg_info), .receive_cb = handle_get_ducking_state }, + [METHOD_HANDLER_NAME_SET_REMOTE_PERMISSION] = { + .method_name = STREAM_MANAGER_METHOD_NAME_SET_REMOTE_PERMISSION, + .arguments = set_remote_permission_args, + .n_arguments = sizeof(set_remote_permission_args) / sizeof(pa_dbus_arg_info), + .receive_cb = handle_set_remote_permission }, + [METHOD_HANDLER_DISCOVER_REMOTE_DEVICE] = { + .method_name = STREAM_MANAGER_METHOD_NAME_DISCOVER_REMOTE_DEVICE, + .arguments = discover_remote_device_args, + .n_arguments = sizeof(discover_remote_device_args) / sizeof(pa_dbus_arg_info), + .receive_cb = handle_discover_remote_device }, + [METHOD_HANDLER_PUBLISH_LOCAL_DEVICE] = { + .method_name = STREAM_MANAGER_METHOD_NAME_PUBLISH_LOCAL_DEVICE, + .arguments = publish_local_device_args, + .n_arguments = sizeof(publish_local_device_args) / sizeof(pa_dbus_arg_info), + .receive_cb = handle_publish_local_device }, }; static DBusHandlerResult handle_introspect(DBusConnection *conn, DBusMessage *msg, void *userdata) { @@ -2322,6 +2349,175 @@ static void handle_get_ducking_state(DBusConnection *conn, DBusMessage *msg, voi dbus_message_unref(reply); } +static void handle_set_remote_permission(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager*)userdata; + dbus_uint32_t index; + dbus_bool_t allowed; + pa_proplist *p = NULL; + char *type = NULL; + + pa_assert(conn); + pa_assert(msg); + pa_assert(m); + + pa_assert_se(dbus_message_get_args(msg, NULL, + DBUS_TYPE_STRING, &type, + DBUS_TYPE_UINT32, &index, + DBUS_TYPE_BOOLEAN, &allowed, + DBUS_TYPE_INVALID)); + + if (!type) { + pa_log_error("invalid arguments"); + goto out; + } + + pa_log_info("type(%s), index(%d), allowed(%d)", type, index, allowed); + + p = pa_proplist_new(); + if (!p) { + pa_log_error("failed to create proplist"); + goto out; + } + + if (pa_proplist_set_remote_access_permission(p, allowed)) { + pa_log_error("set remote access permission error"); + goto out; + } + + if (pa_streq(type, "sink-input")) { + pa_sink_input *i; + + i = pa_idxset_get_by_index(m->core->sink_inputs, index); + if (!i) { + pa_log_error("not found sink-input"); + goto out; + } + + if (pa_proplist_remote_is_allowed(i->proplist) != allowed){ + pa_sink_input_update_proplist(i, PA_UPDATE_REPLACE, p); + pa_sink_input_send_event(i, PA_STREAM_EVENT_UPDATE_MEDIA_REMOTE_ACCESS, p); + } + + } else if (pa_streq(type, "source-output")) { + pa_source_output *o; + + o = pa_idxset_get_by_index(m->core->source_outputs, index); + if (!o) { + pa_log_error("not found source-output"); + goto out; + } + + if (pa_proplist_remote_is_allowed(o->proplist) != allowed){ + pa_source_output_update_proplist(o, PA_UPDATE_REPLACE, p); + pa_source_output_send_event(o, PA_STREAM_EVENT_UPDATE_MEDIA_REMOTE_ACCESS, p); + } + + } else { + pa_log_warn("unknown type"); + } + +out: + if (p) + pa_proplist_free(p); + + pa_dbus_send_empty_reply(conn, msg); +} + +static void handle_discover_remote_device(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager*)userdata; + pa_module *module; + dbus_bool_t enable; + + pa_assert(conn); + pa_assert(msg); + pa_assert(m); + + pa_assert_se(dbus_message_get_args(msg, NULL, + DBUS_TYPE_BOOLEAN, &enable, + DBUS_TYPE_INVALID)); + + pa_log_info("discover module enable(%d)", enable); + + if (enable) { + if (m->m_discover) { + pa_log_error("already loaded"); + goto error; + } + + if (pa_module_load(&module, m->core, "module-tizenaudio-discover", NULL)) { + pa_log_error("failed to load module"); + goto error; + } + m->m_discover = module->index; + } else { + if (m->m_discover) { + pa_module_unload_request_by_index(m->core, m->m_discover, true); + m->m_discover = 0; + } + } + + pa_dbus_send_empty_reply(conn, msg); + + return; + +error: + pa_dbus_send_error(conn, msg, DBUS_ERROR_FAILED, "%s", + "org.tizen.multimedia.audio.Internal"); +} + +static void handle_publish_local_device(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager*)userdata; + pa_module *module; + dbus_bool_t enable; + + pa_assert(conn); + pa_assert(msg); + pa_assert(m); + + pa_assert_se(dbus_message_get_args(msg, NULL, + DBUS_TYPE_BOOLEAN, &enable, + DBUS_TYPE_INVALID)); + + pa_log_info("publish module enable(%d)", enable); + + if (enable) { + if (m->m_protocol_tcp || m->m_publish) { + pa_log_error("already loaded"); + goto error; + } + + if (pa_module_load(&module, m->core, "module-native-protocol-tcp", "auth-anonymous=1")) { + pa_log_error("failed to load module"); + goto error; + } + m->m_protocol_tcp = module->index; + + if (pa_module_load(&module, m->core, "module-tizenaudio-publish", NULL)) { + pa_module_unload_request_by_index(m->core, m->m_protocol_tcp, true); + pa_log_error("failed to load module"); + goto error; + } + m->m_publish = module->index; + } else { + if (m->m_protocol_tcp) { + pa_module_unload_request_by_index(m->core, m->m_protocol_tcp, true); + m->m_protocol_tcp = 0; + } + if (m->m_publish) { + pa_module_unload_request_by_index(m->core, m->m_publish, true); + m->m_publish = 0; + } + } + + pa_dbus_send_empty_reply(conn, msg); + + return; + +error: + pa_dbus_send_error(conn, msg, DBUS_ERROR_FAILED, "%s", + "org.tizen.multimedia.audio.Internal"); +} + static DBusHandlerResult handle_methods(DBusConnection *conn, DBusMessage *msg, void *userdata) { int idx = 0; pa_stream_manager *m = (pa_stream_manager*)userdata; @@ -2435,6 +2631,34 @@ void send_command_signal(DBusConnection *conn, const char *name, int value) { dbus_message_unref(signal_msg); } +void send_remote_found_signal(DBusConnection *conn, int type, bool connected, unsigned int index, + const char *name, const char *description) { + DBusMessage *signal_msg; + DBusMessageIter msg_iter; + dbus_bool_t c = (dbus_bool_t)connected; + + pa_assert(conn); + + if (!name || !description) { + pa_log_error("Unknown device"); + return; + } + + pa_log_info("type[%d], index[%d], connected[%d], name[%s] description[%s]", type, index, connected, name, description); + + pa_assert_se((signal_msg = dbus_message_new_signal(STREAM_MANAGER_OBJECT_PATH, STREAM_MANAGER_INTERFACE, STREAM_MANAGER_SIGNAL_NAME_REMOTE_FOUND))); + dbus_message_iter_init_append(signal_msg, &msg_iter); + + dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_INT32, &type); + dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_UINT32, &index); + dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_BOOLEAN, &c); + dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_STRING, &name); + dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_STRING, &description); + + pa_assert_se(dbus_connection_send(conn, signal_msg, NULL)); + dbus_message_unref(signal_msg); +} + int32_t init_sm_dbus(pa_stream_manager *m) { pa_assert(m); diff --git a/src/stream-manager-priv.h b/src/stream-manager-priv.h index f78a063..aeb0ac9 100644 --- a/src/stream-manager-priv.h +++ b/src/stream-manager-priv.h @@ -266,7 +266,16 @@ struct _stream_manager { *source_output_unlink_slot, *source_output_state_changed_slot, *source_output_move_start_slot, - *source_output_move_finish_slot; + *source_output_move_finish_slot, + + *remote_sink_input_put_slot, + *remote_sink_input_unlink_slot, + *remote_source_output_unlink_slot, + *remote_source_output_put_slot; + + uint32_t m_discover; + uint32_t m_protocol_tcp; + uint32_t m_publish; #ifdef HAVE_DBUS #ifdef USE_DBUS_PROTOCOL diff --git a/src/stream-manager.c b/src/stream-manager.c index f75e8f7..8073580 100644 --- a/src/stream-manager.c +++ b/src/stream-manager.c @@ -2731,6 +2731,53 @@ static pa_hook_result_t source_output_move_finish_cb(pa_core *core, pa_source_ou return PA_HOOK_OK; } +static void notify_remote_connection(pa_core *core, pa_object *obj, pa_stream_manager *m, bool connected) { + pa_proplist *p; + pa_sink_input *i; + pa_source_output *o; + unsigned int index; + + if (pa_source_output_isinstance(obj)) { + o = PA_SOURCE_OUTPUT(obj); + p = o->proplist; + index = o->index; + } else { + i = PA_SINK_INPUT(obj); + p = i->proplist; + index = i->index; + } + + if (!p) { + pa_log_error("unknown remote client"); + return; + } + + if (pa_proplist_has_remote_name(p)) { + send_remote_found_signal(pa_dbus_connection_get(m->dbus_conn), + pa_source_output_isinstance(obj) ? 1 : 0, connected, index, + pa_proplist_gets(p, PA_PROP_MEDIA_REMOTE_NAME), + pa_proplist_gets(p, "native-protocol.peer")); + } +} + +static pa_hook_result_t remote_client_put_cb(pa_core *core, pa_object *o, pa_stream_manager *m) { + pa_core_assert_ref(core); + pa_object_assert_ref(o); + + notify_remote_connection(core, o, m, true); + + return PA_HOOK_OK; +} + +static pa_hook_result_t remote_client_unlink_cb(pa_core *core, pa_object *o, pa_stream_manager *m) { + pa_core_assert_ref(core); + pa_object_assert_ref(o); + + notify_remote_connection(core, o, m, false); + + return PA_HOOK_OK; +} + static void find_next_device_for_auto_route(pa_stream_manager *m, stream_route_type_t route_type, const char *stream_role, stream_type_t stream_type, const char *cur_device_type, const char *preferred_device_role, pa_tz_device **next_device) { stream_info *si = NULL; @@ -3734,6 +3781,11 @@ pa_stream_manager* pa_stream_manager_get(pa_core *c) { m->source_output_move_start_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_START], PA_HOOK_EARLY, (pa_hook_cb_t) source_output_move_start_cb, m); m->source_output_move_finish_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_FINISH], PA_HOOK_EARLY, (pa_hook_cb_t) source_output_move_finish_cb, m); + m->remote_sink_input_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_PUT], PA_HOOK_EARLY, (pa_hook_cb_t) remote_client_put_cb, m); + m->remote_sink_input_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_UNLINK], PA_HOOK_EARLY, (pa_hook_cb_t) remote_client_unlink_cb, m); + m->remote_source_output_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PUT], PA_HOOK_NORMAL, (pa_hook_cb_t) remote_client_put_cb, m); + m->remote_source_output_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_UNLINK], PA_HOOK_NORMAL, (pa_hook_cb_t) remote_client_unlink_cb, m); + m->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_CLIENT | PA_SUBSCRIPTION_MASK_SAMPLE_CACHE, (pa_subscription_cb_t)subscribe_cb, m); m->comm.comm = pa_communicator_get(c); @@ -3787,8 +3839,12 @@ static void free_hook_slots(pa_stream_manager *m) { pa_hook_slot_free(m->sink_input_new_slot); if (m->sink_input_put_slot) pa_hook_slot_free(m->sink_input_put_slot); + if (m->remote_sink_input_put_slot) + pa_hook_slot_free(m->remote_sink_input_put_slot); if (m->sink_input_unlink_slot) pa_hook_slot_free(m->sink_input_unlink_slot); + if (m->remote_sink_input_unlink_slot) + pa_hook_slot_free(m->remote_sink_input_unlink_slot); if (m->sink_input_state_changed_slot) pa_hook_slot_free(m->sink_input_state_changed_slot); if (m->sink_input_move_start_slot) @@ -3797,12 +3853,17 @@ static void free_hook_slots(pa_stream_manager *m) { pa_hook_slot_free(m->sink_input_move_finish_slot); if (m->sink_input_ramp_finish_slot) pa_hook_slot_free(m->sink_input_ramp_finish_slot); + if (m->source_output_new_slot) pa_hook_slot_free(m->source_output_new_slot); if (m->source_output_put_slot) pa_hook_slot_free(m->source_output_put_slot); + if (m->remote_source_output_put_slot) + pa_hook_slot_free(m->remote_source_output_put_slot); if (m->source_output_unlink_slot) pa_hook_slot_free(m->source_output_unlink_slot); + if (m->remote_source_output_unlink_slot) + pa_hook_slot_free(m->remote_source_output_unlink_slot); if (m->source_output_state_changed_slot) pa_hook_slot_free(m->source_output_state_changed_slot); if (m->source_output_move_start_slot) -- 2.7.4 From 4473003cc7c2986bacd2f951cc1ac3dab1ab6a15 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Thu, 20 Aug 2020 15:17:38 +0900 Subject: [PATCH 05/16] stream-manager-dbus: launch mdnsd when remote publish/discover [Version] 13.0.28 [Issue Type] Update Change-Id: I0a63ba5c5636e249f640337b25bfd698c18311d9 --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/stream-manager-dbus.c | 42 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index bb99b51..441a781 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: 13.0.27 +Version: 13.0.28 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/stream-manager-dbus.c b/src/stream-manager-dbus.c index 0367446..c365345 100644 --- a/src/stream-manager-dbus.c +++ b/src/stream-manager-dbus.c @@ -2349,6 +2349,38 @@ static void handle_get_ducking_state(DBusConnection *conn, DBusMessage *msg, voi dbus_message_unref(reply); } +static int dbus_launch_mdnsd(pa_stream_manager *m, DBusConnection *conn) { + DBusMessage *msg, *reply; + DBusError err; + const char *name = NULL; + + pa_log_info("launching mdnsd"); + + if (!(msg = dbus_message_new_method_call("net.netconfig", + "/net/netconfig/network", + "net.netconfig.network", + "LaunchMdns"))) { + pa_log_error("dbus method call failed"); + return -1; + } + + name = dbus_bus_get_unique_name(conn); + pa_assert_se(dbus_message_append_args(msg, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)); + + dbus_error_init(&err); + if (!(reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err))) { + pa_log_error("Failed to method call : %s", err.message); + dbus_error_free(&err); + return -1; + } + + dbus_message_unref(reply); + + pa_log_info("success"); + + return 0; +} + static void handle_set_remote_permission(DBusConnection *conn, DBusMessage *msg, void *userdata) { pa_stream_manager *m = (pa_stream_manager*)userdata; dbus_uint32_t index; @@ -2444,6 +2476,11 @@ static void handle_discover_remote_device(DBusConnection *conn, DBusMessage *msg goto error; } + if (dbus_launch_mdnsd(m, conn) == -1) { + pa_log_error("failed to launch mdnsd!!!"); + goto error; + } + if (pa_module_load(&module, m->core, "module-tizenaudio-discover", NULL)) { pa_log_error("failed to load module"); goto error; @@ -2486,6 +2523,11 @@ static void handle_publish_local_device(DBusConnection *conn, DBusMessage *msg, goto error; } + if (dbus_launch_mdnsd(m, conn) == -1) { + pa_log_error("failed to launch mdnsd!!!"); + goto error; + } + if (pa_module_load(&module, m->core, "module-native-protocol-tcp", "auth-anonymous=1")) { pa_log_error("failed to load module"); goto error; -- 2.7.4 From 26c98e7e2a8d03c153ac20af68d31812a406831e Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Thu, 20 Aug 2020 19:07:32 +0900 Subject: [PATCH 06/16] fixup! tizenaudio-discover: ignore local services skip discovered from localhost(127.0.0.1) [Version] 13.0.29 [Issue Type] Update Change-Id: I5faa7ae58b5ebfa8dae5a8c68ba64ff2309096f4 --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/module-tizenaudio-discover.c | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 441a781..04850b6 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: 13.0.28 +Version: 13.0.29 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/module-tizenaudio-discover.c b/src/module-tizenaudio-discover.c index 798f006..e507e39 100644 --- a/src/module-tizenaudio-discover.c +++ b/src/module-tizenaudio-discover.c @@ -356,12 +356,14 @@ finish: } static bool is_local_service(const char *ip_addr) { - char *ipv4_addr = NULL; + static const char *localhost = "127.0.0.1"; + char *current_ip_addr = NULL; bool is_local = false; - ipv4_addr = vconf_get_str(VCONFKEY_NETWORK_IP); - is_local = pa_safe_streq(ipv4_addr, ip_addr); - pa_xfree(ipv4_addr); + current_ip_addr = vconf_get_str(VCONFKEY_NETWORK_IP); + is_local = (pa_safe_streq(ip_addr, current_ip_addr) || + pa_safe_streq(ip_addr, localhost)); + pa_xfree(current_ip_addr); return is_local; } -- 2.7.4 From d04fc67580a49ff132699a1dd85fff0a0a3a2384 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Fri, 21 Aug 2020 16:31:03 +0900 Subject: [PATCH 07/16] fixup! tizenaudio-publish: publish only built-in devices adjust log level for ignoring publish [Version] 13.0.30 [Issue Type] Update Change-Id: I0476c340de9b4bffc13bf9734bd837fd5f169f92 --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/module-tizenaudio-publish.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 04850b6..bc64475 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: 13.0.29 +Version: 13.0.30 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/module-tizenaudio-publish.c b/src/module-tizenaudio-publish.c index cdead84..0fb0602 100644 --- a/src/module-tizenaudio-publish.c +++ b/src/module-tizenaudio-publish.c @@ -340,7 +340,7 @@ static bool shall_ignore(pa_object *o) { if (pa_sink_isinstance(o)) { if (!is_builtin_device(PA_SINK(o)->proplist)) { - pa_log_error("sink [%s] is not an internal, skip this", PA_SINK(o)->name); + pa_log_info("ignore : sink [%s] is not an internal", PA_SINK(o)->name); return true; } return !!(PA_SINK(o)->flags & PA_SINK_NETWORK); @@ -348,7 +348,7 @@ static bool shall_ignore(pa_object *o) { if (pa_source_isinstance(o)) { if (!is_builtin_device(PA_SOURCE(o)->proplist)) { - pa_log_error("source [%s] is not an internal, skip this", PA_SOURCE(o)->name); + pa_log_info("ignore : source [%s] is not an internal", PA_SOURCE(o)->name); return true; } return PA_SOURCE(o)->monitor_of || (PA_SOURCE(o)->flags & PA_SOURCE_NETWORK); -- 2.7.4 From 480ec0b9bfc56f35a4462d58a674a22063e17537 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Thu, 27 Aug 2020 19:28:52 +0900 Subject: [PATCH 08/16] Fix Coverity defects - Unchecked return value (CHECKED_RETURN) - String not null terminated (STRING_NULL) [Version] 13.0.31 [Issue Type] Vulnerability Change-Id: I0e4b8c824c0d6dd9efe71d34d3576aa81453aa83 --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/acm.c | 6 +++--- src/module-sound-player.c | 6 +++--- src/subscribe-observer.c | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index bc64475..2264698 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: 13.0.30 +Version: 13.0.31 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/acm.c b/src/acm.c index a0d07a7..7f697c2 100644 --- a/src/acm.c +++ b/src/acm.c @@ -558,13 +558,13 @@ static void msg_thread_func(void *userdata) { } if ((recv_len = recv(u->msg_fd, recv_msg , IPC_MAX_MSG_LEN, 0)) > 0) { - if (!strcmp(recv_msg, MSG_DRAIN_COMPLETE)) { + if (!strncmp(recv_msg, MSG_DRAIN_COMPLETE, IPC_MAX_MSG_LEN)) { pa_log_debug("got drain complete signal [%s]", recv_msg); pa_cond_signal(u->msg_cond, false); - } else if (!strcmp(recv_msg, MSG_SEND_PAUSE)) { + } else if (!strncmp(recv_msg, MSG_SEND_PAUSE, IPC_MAX_MSG_LEN)) { pa_log_debug("got pause signal [%s]", recv_msg); u->need_pause = true; - } else if (!strcmp(recv_msg, MSG_SEND_RESUME) && u->need_pause) { + } else if (!strncmp(recv_msg, MSG_SEND_RESUME, IPC_MAX_MSG_LEN) && u->need_pause) { pa_log_debug("got resume signal [%s]", recv_msg); u->need_pause = false; pa_cond_signal(u->msg_cond, false); diff --git a/src/module-sound-player.c b/src/module-sound-player.c index 0322544..5e60af2 100644 --- a/src/module-sound-player.c +++ b/src/module-sound-player.c @@ -733,11 +733,11 @@ static void io_event_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io pa_log_info("name(%s), role(%s), volume_gain_type(%s), method(%s)", data.filename, data.role, data.volume_gain_type, data.method); - if (pa_streq(data.method, SOUND_PLAYER_METHOD_NAME_SIMPLE_PLAY)) + if (pa_strneq(data.method, SOUND_PLAYER_METHOD_NAME_SIMPLE_PLAY, METHOD_LEN)) _simple_play(u, data.filename, data.role, data.volume_gain_type); - else if (pa_streq(data.method, SOUND_PLAYER_METHOD_NAME_SIMPLE_STOP)) + else if (pa_strneq(data.method, SOUND_PLAYER_METHOD_NAME_SIMPLE_STOP, METHOD_LEN)) _simple_stop(u, data.filename); - else if (pa_streq(data.method, SOUND_PLAYER_METHOD_NAME_SIMPLE_STOP_ALL)) + else if (pa_strneq(data.method, SOUND_PLAYER_METHOD_NAME_SIMPLE_STOP_ALL, METHOD_LEN)) _simple_stop_all(u); else pa_log_error("Invalid method!!!"); diff --git a/src/subscribe-observer.c b/src/subscribe-observer.c index c565a36..a8ec66a 100644 --- a/src/subscribe-observer.c +++ b/src/subscribe-observer.c @@ -188,9 +188,9 @@ static int get_sender_pid(DBusConnection *c, DBusMessage *got_msg, uint32_t *_se return -1; } - dbus_message_append_args(msg, + pa_assert_se(dbus_message_append_args(msg, DBUS_TYPE_STRING, &sender, - DBUS_TYPE_INVALID); + DBUS_TYPE_INVALID)); dbus_error_init(&err); if (!(reply = dbus_connection_send_with_reply_and_block(c, msg, -1, &err))) { -- 2.7.4 From 49d1e63cff1bfbaa64d6b31efdd29c79e0231489 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Fri, 28 Aug 2020 17:54:19 +0900 Subject: [PATCH 09/16] Fix SVACE defect(DEREF_OF_NULL.RET.STAT) [Version] 13.0.32 [Issue Type] Vulnerability Change-Id: Ideb267ce415c92c51702558cfdba9cb8cb0bc179 --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/stream-manager.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 2264698..a622af5 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: 13.0.31 +Version: 13.0.32 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/stream-manager.c b/src/stream-manager.c index 8073580..e8f107d 100644 --- a/src/stream-manager.c +++ b/src/stream-manager.c @@ -2739,10 +2739,12 @@ static void notify_remote_connection(pa_core *core, pa_object *obj, pa_stream_ma if (pa_source_output_isinstance(obj)) { o = PA_SOURCE_OUTPUT(obj); + pa_assert(o); p = o->proplist; index = o->index; } else { i = PA_SINK_INPUT(obj); + pa_assert(i); p = i->proplist; index = i->index; } -- 2.7.4 From 5b1bfefac4bceed567a2d6c642f861e47aeca872 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Wed, 2 Sep 2020 17:35:14 +0900 Subject: [PATCH 10/16] Fix build warnings [Version] 13.0.33 [Issue Type] Build Change-Id: Idf96facb42ef0260e96ac1d1af4e9ec131c999a7 --- Makefile.am | 22 ++++++------ packaging/pulseaudio-modules-tizen.spec | 2 +- src/module-tizenaudio-discover.c | 48 ++++++++++++------------- src/module-tizenaudio-publish.c | 64 ++++++++++++++++----------------- src/stream-manager.c | 2 +- 5 files changed, 69 insertions(+), 69 deletions(-) diff --git a/Makefile.am b/Makefile.am index 90d1260..e529cae 100644 --- a/Makefile.am +++ b/Makefile.am @@ -65,22 +65,22 @@ libcommunicator_la_CFLAGS = $(AM_CFLAGS) $(PACORE_CFLAGS) $(PA_CFLAGS) module_tizenaudio_sink_la_SOURCES = src/module-tizenaudio-sink.c module_tizenaudio_sink_la_LDFLAGS = $(MODULE_LDFLAGS) module_tizenaudio_sink_la_LIBADD = $(MODULE_LIBADD) libhal-interface.la -module_tizenaudio_sink_la_CFLAGS = $(MODULE_CFLAGS) +module_tizenaudio_sink_la_CFLAGS = $(MODULE_CFLAGS) -DPA_MODULE_NAME=module_tizenaudio_sink module_tizenaudio_source_la_SOURCES = src/module-tizenaudio-source.c module_tizenaudio_source_la_LDFLAGS = $(MODULE_LDFLAGS) module_tizenaudio_source_la_LIBADD = $(MODULE_LIBADD) libhal-interface.la -module_tizenaudio_source_la_CFLAGS = $(MODULE_CFLAGS) +module_tizenaudio_source_la_CFLAGS = $(MODULE_CFLAGS) -DPA_MODULE_NAME=module_tizenaudio_source module_sound_player_la_SOURCES = src/module-sound-player.c module_sound_player_la_LDFLAGS = $(MODULE_LDFLAGS) module_sound_player_la_LIBADD = $(MODULE_LIBADD) $(DBUS_LIBS) -module_sound_player_la_CFLAGS = $(MODULE_CFLAGS) $(DBUS_CFLAGS) +module_sound_player_la_CFLAGS = $(MODULE_CFLAGS) $(DBUS_CFLAGS) -DPA_MODULE_NAME=module_sound_player module_tone_player_la_SOURCES = src/module-tone-player.c module_tone_player_la_LDFLAGS = $(MODULE_LDFLAGS) module_tone_player_la_LIBADD = $(MODULE_LIBADD) $(DBUS_LIBS) -module_tone_player_la_CFLAGS = $(MODULE_CFLAGS) $(DBUS_CFLAGS) +module_tone_player_la_CFLAGS = $(MODULE_CFLAGS) $(DBUS_CFLAGS) -DPA_MODULE_NAME=module_tone_player module_tizenaudio_policy_la_SOURCES = \ src/module-tizenaudio-policy.c \ @@ -96,36 +96,36 @@ module_tizenaudio_policy_la_SOURCES = \ src/subscribe-observer.c src/subscribe-observer.h module_tizenaudio_policy_la_LDFLAGS = $(MODULE_LDFLAGS) -L$(pulsemodlibexecdir) module_tizenaudio_policy_la_LIBADD = $(MODULE_LIBADD) $(DBUS_LIBS) $(VCONF_LIBS) $(INIPARSER_LIBS) $(LIBJSON_LIBS) libhal-interface.la libcommunicator.la -module_tizenaudio_policy_la_CFLAGS = $(MODULE_CFLAGS) $(DBUS_CFLAGS) $(VCONF_CFLAGS) $(INIPARSER_CFLAGS) $(LIBJSON_CFLAGS) +module_tizenaudio_policy_la_CFLAGS = $(MODULE_CFLAGS) $(DBUS_CFLAGS) $(VCONF_CFLAGS) $(INIPARSER_CFLAGS) $(LIBJSON_CFLAGS) -DPA_MODULE_NAME=module_tizenaudio_policy if ENABLE_HALTC module_tizenaudio_haltc_la_SOURCES = src/module-tizenaudio-haltc.c module_tizenaudio_haltc_la_LDFLAGS = $(MODULE_LDFLAGS) module_tizenaudio_haltc_la_LIBADD = $(MODULE_LIBADD) libhal-interface.la -module_tizenaudio_haltc_la_CFLAGS = $(MODULE_CFLAGS) +module_tizenaudio_haltc_la_CFLAGS = $(MODULE_CFLAGS) -DPA_MODULE_NAME=module_tizenaudio_haltc endif module_poweroff_la_SOURCES = src/module-poweroff.c module_poweroff_la_LDFLAGS = $(MODULE_LDFLAGS) module_poweroff_la_LIBADD = $(MODULE_LIBADD) $(DBUS_LIBS) libhal-interface.la -module_poweroff_la_CFLAGS = $(MODULE_CFLAGS) $(DBUS_CFLAGS) +module_poweroff_la_CFLAGS = $(MODULE_CFLAGS) $(DBUS_CFLAGS) -DPA_MODULE_NAME=module_poweroff if ENABLE_ACM module_acm_sink_la_SOURCES = src/module-acm-sink.c src/acm.c src/acm.h module_acm_sink_la_LDFLAGS = $(MODULE_LDFLAGS) module_acm_sink_la_LIBADD = $(MODULE_LIBADD) -module_acm_sink_la_CFLAGS = $(MODULE_CFLAGS) +module_acm_sink_la_CFLAGS = $(MODULE_CFLAGS) -DPA_MODULE_NAME=module_acm_sink endif module_tizenaudio_discover_la_SOURCES = src/module-tizenaudio-discover.c module_tizenaudio_discover_la_LDFLAGS = $(MODULE_LDFLAGS) module_tizenaudio_discover_la_LIBADD = $(MODULE_LIBADD) $(DNSSD_LIBS) $(VCONF_LIBS) -module_tizenaudio_discover_la_CFLAGS = $(MODULE_CFLAGS) $(DNSSD_CFLAGS) $(VCONF_CFLAGS) +module_tizenaudio_discover_la_CFLAGS = $(MODULE_CFLAGS) $(DNSSD_CFLAGS) $(VCONF_CFLAGS) -DPA_MODULE_NAME=module_tizenaudio_discover module_tizenaudio_publish_la_SOURCES = src/module-tizenaudio-publish.c module_tizenaudio_publish_la_LDFLAGS = $(MODULE_LDFLAGS) module_tizenaudio_publish_la_LIBADD = $(MODULE_LIBADD) $(DNSSD_LIBS) -module_tizenaudio_publish_la_CFLAGS = $(AM_CFLAGS) $(DNSSD_CFLAGS) +module_tizenaudio_publish_la_CFLAGS = $(AM_CFLAGS) $(DNSSD_CFLAGS) -DPA_MODULE_NAME=module_tizenaudio_publish if ENABLE_VCONF_HELPER pulsemodlibexec_LTLIBRARIES += module-vconf.la @@ -133,7 +133,7 @@ pulsemodlibexec_LTLIBRARIES += module-vconf.la module_vconf_la_SOURCES = src/vconf/module-vconf.c module_vconf_la_LDFLAGS = $(MODULE_LDFLAGS) module_vconf_la_LIBADD = $(MODULE_LIBADD) libcommunicator.la -module_vconf_la_CFLAGS = $(MODULE_CFLAGS) -DPA_VCONF_HELPER=\"$(pulselibexecdir)/vconf-helper\" +module_vconf_la_CFLAGS = $(MODULE_CFLAGS) -DPA_VCONF_HELPER=\"$(pulselibexecdir)/vconf-helper\" -DPA_MODULE_NAME=module_vconf pulselibexec_PROGRAMS = vconf-helper diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index a622af5..0a6f996 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: 13.0.32 +Version: 13.0.33 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/module-tizenaudio-discover.c b/src/module-tizenaudio-discover.c index e507e39..e75e452 100644 --- a/src/module-tizenaudio-discover.c +++ b/src/module-tizenaudio-discover.c @@ -688,30 +688,6 @@ static int dnssd_browse_dns_service(struct userdata *u, const char *service_type return 0; } -void pa__done(pa_module *m) { - struct userdata *u; - pa_assert(m); - - if (!(u = m->userdata)) - return; - - if (u->tunnels) { - struct tunnel *t; - - while ((t = pa_hashmap_steal_first(u->tunnels))) { - pa_module_unload_request_by_index(u->core, t->module_index, true); - tunnel_free(t); - } - - pa_hashmap_free(u->tunnels); - } - - request_clear(u->module->core->mainloop, &u->browse_sink); - request_clear(u->module->core->mainloop, &u->browse_source); - - pa_xfree(u); -} - int pa__init(pa_module *m) { struct userdata *u; @@ -748,3 +724,27 @@ fail: return -1; } + +void pa__done(pa_module *m) { + struct userdata *u; + pa_assert(m); + + if (!(u = m->userdata)) + return; + + if (u->tunnels) { + struct tunnel *t; + + while ((t = pa_hashmap_steal_first(u->tunnels))) { + pa_module_unload_request_by_index(u->core, t->module_index, true); + tunnel_free(t); + } + + pa_hashmap_free(u->tunnels); + } + + request_clear(u->module->core->mainloop, &u->browse_sink); + request_clear(u->module->core->mainloop, &u->browse_source); + + pa_xfree(u); +} \ No newline at end of file diff --git a/src/module-tizenaudio-publish.c b/src/module-tizenaudio-publish.c index 0fb0602..1c502f2 100644 --- a/src/module-tizenaudio-publish.c +++ b/src/module-tizenaudio-publish.c @@ -450,38 +450,6 @@ static void unpublish_all_services(struct userdata *u) { DNSServiceRefDeallocate(u->main_service); } -void pa__done(pa_module *m) { - struct userdata *u; - pa_assert(m); - - if (!(u = m->userdata)) - return; - - unpublish_all_services(u); - - if (u->services) - pa_hashmap_free(u->services); - - if (u->sink_new_slot) - pa_hook_slot_free(u->sink_new_slot); - if (u->source_new_slot) - pa_hook_slot_free(u->source_new_slot); - if (u->sink_changed_slot) - pa_hook_slot_free(u->sink_changed_slot); - if (u->source_changed_slot) - pa_hook_slot_free(u->source_changed_slot); - if (u->sink_unlink_slot) - pa_hook_slot_free(u->sink_unlink_slot); - if (u->source_unlink_slot) - pa_hook_slot_free(u->source_unlink_slot); - - if (u->native) - pa_native_protocol_unref(u->native); - - pa_xfree(u->service_name); - pa_xfree(u); -} - int pa__init(pa_module *m) { struct userdata *u; pa_modargs *ma = NULL; @@ -527,3 +495,35 @@ fail: return -1; } + +void pa__done(pa_module *m) { + struct userdata *u; + pa_assert(m); + + if (!(u = m->userdata)) + return; + + unpublish_all_services(u); + + if (u->services) + pa_hashmap_free(u->services); + + if (u->sink_new_slot) + pa_hook_slot_free(u->sink_new_slot); + if (u->source_new_slot) + pa_hook_slot_free(u->source_new_slot); + if (u->sink_changed_slot) + pa_hook_slot_free(u->sink_changed_slot); + if (u->source_changed_slot) + pa_hook_slot_free(u->source_changed_slot); + if (u->sink_unlink_slot) + pa_hook_slot_free(u->sink_unlink_slot); + if (u->source_unlink_slot) + pa_hook_slot_free(u->source_unlink_slot); + + if (u->native) + pa_native_protocol_unref(u->native); + + pa_xfree(u->service_name); + pa_xfree(u); +} \ No newline at end of file diff --git a/src/stream-manager.c b/src/stream-manager.c index e8f107d..4507a71 100644 --- a/src/stream-manager.c +++ b/src/stream-manager.c @@ -44,7 +44,7 @@ #include #include #include - +#include #include #include "stream-manager.h" -- 2.7.4 From ff392108d7d644aaa7166259c52f6798ede1cc51 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Tue, 27 Oct 2020 20:08:46 +0900 Subject: [PATCH 11/16] device-manager-dbus: fix crash of getting empty supported samplerates/formats [Version] 13.0.34 [Issue Type] Bug Change-Id: I8faab3479f9bf2daa87d0f818b50f1a95e96caeb --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/device-manager-dbus.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 0a6f996..638827d 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: 13.0.33 +Version: 13.0.34 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/device-manager-dbus.c b/src/device-manager-dbus.c index b9ab071..7190965 100644 --- a/src/device-manager-dbus.c +++ b/src/device-manager-dbus.c @@ -1095,6 +1095,12 @@ static void handle_get_supported_sample_formats(DBusConnection *conn, DBusMessag return; } + if (!sink->supported_sample_formats) { + pa_log_error("supported sample formats is not set on this sink"); + pa_dbus_send_error(conn, msg, DBUS_ERROR_NOT_SUPPORTED, "%s", "org.tizen.multimedia.audio.InvalidOperation"); + return; + } + dbus_message_iter_init_append(reply, &msg_iter); pa_assert_se(dbus_message_iter_open_container(&msg_iter, DBUS_TYPE_ARRAY, "s", &array_iter)); for (i = 0; sink->supported_sample_formats[i] != PA_SAMPLE_MAX; i++) { @@ -1268,6 +1274,12 @@ static void handle_get_supported_sample_rates(DBusConnection *conn, DBusMessage return; } + if (!sink->supported_sample_rates) { + pa_log_error("supported sample rates is not set on this sink"); + pa_dbus_send_error(conn, msg, DBUS_ERROR_NOT_SUPPORTED, "%s", "org.tizen.multimedia.audio.InvalidOperation"); + return; + } + dbus_message_iter_init_append(reply, &msg_iter); pa_assert_se(dbus_message_iter_open_container(&msg_iter, DBUS_TYPE_ARRAY, "u", &array_iter)); for (i = 0; sink->supported_sample_rates[i]; i++) { -- 2.7.4 From d07b2271b0453d63ac22c9970313412140b90953 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Wed, 28 Oct 2020 20:17:32 +0900 Subject: [PATCH 12/16] device-manager-dbus: use pa dbus wrapper function if possible [Version] 13.0.35 [Issue Type] Revise Change-Id: I926a1860bc43b789ae5cf5490973f92b9ddd6cbd --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/device-manager-dbus.c | 306 +++++++++++--------------------- 2 files changed, 108 insertions(+), 200 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 638827d..e6f794d 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: 13.0.34 +Version: 13.0.35 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/device-manager-dbus.c b/src/device-manager-dbus.c index 7190965..52e87e1 100644 --- a/src/device-manager-dbus.c +++ b/src/device-manager-dbus.c @@ -507,10 +507,10 @@ static int handle_bluez_headset_property_changed(DBusConnection *c, DBusMessage static DBusHandlerResult dbus_filter_device_detect_handler(DBusConnection *c, DBusMessage *s, void *userdata) { DBusError error; int status = 0; - pa_device_manager *dm = (pa_device_manager *) userdata; + pa_device_manager *dm = (pa_device_manager *)userdata; device_detected_type_t detected; - pa_assert(userdata); + pa_assert(dm); if (dbus_message_get_type(s) != DBUS_MESSAGE_TYPE_SIGNAL) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; @@ -678,7 +678,7 @@ static int method_call_bt_get_name(DBusConnection *conn, const char *device_path } static void handle_get_connected_device_list(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *dm; + pa_device_manager *dm = (pa_device_manager *)userdata; DBusMessage *reply = NULL; DBusMessageIter msg_iter, array_iter, device_iter; pa_tz_device *device; @@ -692,10 +692,7 @@ static void handle_get_connected_device_list(DBusConnection *conn, DBusMessage * pa_assert(conn); pa_assert(msg); - pa_assert(userdata); - - - dm = (pa_device_manager*) userdata; + pa_assert(dm); pa_assert_se((reply = dbus_message_new_method_return(msg))); @@ -742,7 +739,7 @@ static void handle_get_connected_device_list(DBusConnection *conn, DBusMessage * } static void handle_get_device_by_id(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *manager; + pa_device_manager *dm = (pa_device_manager *)userdata; DBusMessage *reply; DBusMessageIter msg_iter; pa_tz_device *device; @@ -753,9 +750,7 @@ static void handle_get_device_by_id(DBusConnection *conn, DBusMessage *msg, void pa_assert(conn); pa_assert(msg); - pa_assert(userdata); - - manager = (pa_device_manager*) userdata; + pa_assert(dm); pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &device_id, @@ -763,7 +758,7 @@ static void handle_get_device_by_id(DBusConnection *conn, DBusMessage *msg, void pa_log_info("Get device by id(%d)", device_id); - if ((device = device_list_get_device_by_id(manager, device_id))) { + if ((device = device_list_get_device_by_id(dm, device_id))) { pa_assert_se((reply = dbus_message_new_method_return(msg))); dbus_message_iter_init_append(reply, &msg_iter); @@ -792,19 +787,15 @@ static void handle_get_device_by_id(DBusConnection *conn, DBusMessage *msg, void } } -static void handle_is_device_running_by_id(DBusConnection *conn, DBusMessage *msg, void *userdata) -{ - pa_device_manager *manager; - DBusMessage *reply; +static void handle_is_device_running_by_id(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_device_manager *dm = (pa_device_manager *)userdata; pa_tz_device *device; dbus_int32_t device_id; dbus_bool_t is_running; pa_assert(conn); pa_assert(msg); - pa_assert(userdata); - - manager = (pa_device_manager *)userdata; + pa_assert(dm); pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &device_id, @@ -812,28 +803,21 @@ static void handle_is_device_running_by_id(DBusConnection *conn, DBusMessage *ms pa_log_info("Is device running by id(%d)", device_id); - if ((device = device_list_get_device_by_id(manager, device_id))) { - pa_assert_se((reply = dbus_message_new_method_return(msg))); - + if ((device = device_list_get_device_by_id(dm, device_id))) { is_running = pa_tz_device_is_running(device); pa_log_info("device(id:%d) is %s", device_id, is_running ? "Running" : "Not Running"); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &is_running, - DBUS_TYPE_INVALID)); - - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_BOOLEAN, &is_running); } else { pa_dbus_send_error(conn, msg, DBUS_ERROR_FAILED, "%s", "org.tizen.multimedia.audio.Internal"); } } static void handle_is_stream_on_device(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *manager; - DBusMessage *reply; + pa_device_manager *dm = (pa_device_manager *)userdata; pa_tz_device *device; - dbus_bool_t is_on = false; + dbus_bool_t is_on = FALSE; dbus_int32_t stream_id, device_id; pa_intset *stream_id_set; int32_t stream_id_val; @@ -842,27 +826,22 @@ static void handle_is_stream_on_device(DBusConnection *conn, DBusMessage *msg, v pa_assert(conn); pa_assert(msg); - pa_assert(userdata); + pa_assert(dm); pa_log_info("Is stream on device"); - manager = (pa_device_manager*) userdata; - - pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &stream_id, DBUS_TYPE_INT32, &device_id, DBUS_TYPE_INVALID)); - if ((device = device_list_get_device_by_id(manager, device_id))) { - pa_assert_se((reply = dbus_message_new_method_return(msg))); - + if ((device = device_list_get_device_by_id(dm, device_id))) { state = pa_tz_device_get_state(device); if (state == DM_DEVICE_STATE_ACTIVATED) { stream_id_set = pa_tz_device_get_stream_list(device); PA_INTSET_FOREACH(stream_id_val, stream_id_set, ret) { if (stream_id_val == stream_id) { - is_on = true; + is_on = TRUE; pa_log_info("stream(%d) is on device(%d)", stream_id, device_id); break; } @@ -870,113 +849,106 @@ static void handle_is_stream_on_device(DBusConnection *conn, DBusMessage *msg, v pa_intset_free(stream_id_set); } else { pa_log_info("device(%d) is not activated, regard as no stream on it", device_id); - is_on = false; + is_on = FALSE; } - - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &is_on, - DBUS_TYPE_INVALID)); - - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_BOOLEAN, &is_on); } else { pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "%s", "org.tizen.multimedia.audio.Internal"); } } static void handle_get_bt_a2dp_status(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *dm; + pa_device_manager *dm = (pa_device_manager *)userdata; DBusMessage *reply = NULL; pa_tz_device *device; - dbus_bool_t is_bt_on = false; + dbus_bool_t is_bt_on = FALSE; const char *bt_name = "none"; pa_assert(conn); pa_assert(msg); - pa_assert(userdata); + pa_assert(dm); pa_log_info("Get BT A2DP list"); - dm = (pa_device_manager*) userdata; - - pa_assert_se((reply = dbus_message_new_method_return(msg))); - /* FIXME : Give system_id for multi device */ if ((device = device_list_get_device(dm, DEVICE_TYPE_BT_A2DP, NULL, NULL)) != NULL) { - is_bt_on = true; + is_bt_on = TRUE; bt_name = pa_tz_device_get_name(device); } + pa_assert_se((reply = dbus_message_new_method_return(msg))); pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &is_bt_on, DBUS_TYPE_STRING, &bt_name, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_connection_send(conn, reply, NULL)); dbus_message_unref(reply); } static void handle_load_sink(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *dm; + pa_device_manager *dm = (pa_device_manager *)userdata; char *type, *role; pa_sink *sink; - DBusMessage *reply = NULL; - dm = (pa_device_manager *) userdata; + pa_assert(conn); + pa_assert(msg); + pa_assert(dm); + pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &type, DBUS_TYPE_STRING, &role, DBUS_TYPE_INVALID)); - if (!(sink = pa_device_manager_load_sink(dm, type, role))) { + if (!(sink = pa_device_manager_load_sink(dm, type, role))) pa_dbus_send_error(conn, msg, DBUS_ERROR_FAILED, "%s", "org.tizen.multimedia.audio.Internal"); - return; - } - - pa_assert_se((reply = dbus_message_new_method_return(msg))); - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + else + pa_dbus_send_empty_reply(conn, msg); } static void handle_unload_sink(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *dm; + pa_device_manager *dm = (pa_device_manager *)userdata; char *type, *role; - DBusMessage *reply = NULL; - pa_assert_se((reply = dbus_message_new_method_return(msg))); - dm = (pa_device_manager *) userdata; + pa_assert(conn); + pa_assert(msg); + pa_assert(dm); + pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &type, DBUS_TYPE_STRING, &role, DBUS_TYPE_INVALID)); pa_device_manager_unload_sink(dm, type, role); - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + + pa_dbus_send_empty_reply(conn, msg); } static void handle_unload_sink_with_device_string(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *dm; + pa_device_manager *dm = (pa_device_manager *)userdata; char *device_string; - DBusMessage *reply = NULL; - pa_assert_se((reply = dbus_message_new_method_return(msg))); - dm = (pa_device_manager *) userdata; + pa_assert(conn); + pa_assert(msg); + pa_assert(dm); + pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &device_string, DBUS_TYPE_INVALID)); pa_device_manager_unload_sink_with_device_string(dm, device_string); - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + + pa_dbus_send_empty_reply(conn, msg); } static void handle_get_device_string(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *dm; + pa_device_manager *dm = (pa_device_manager *)userdata; char *type, *role; const char *device_string; dbus_bool_t is_playback; - DBusMessage *reply; - dm = (pa_device_manager *) userdata; + pa_assert(conn); + pa_assert(msg); + pa_assert(dm); + pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_BOOLEAN, &is_playback, DBUS_TYPE_STRING, &type, @@ -990,27 +962,24 @@ static void handle_get_device_string(DBusConnection *conn, DBusMessage *msg, voi } pa_log_info("device string : %s", device_string); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &device_string, - DBUS_TYPE_INVALID)); - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_STRING, &device_string); } static void handle_dump_device_list(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *dm; + pa_device_manager *dm = (pa_device_manager *)userdata; pa_tz_device *device; uint32_t device_idx; - DBusMessage *reply = NULL; - pa_assert_se((reply = dbus_message_new_method_return(msg))); - dm = (pa_device_manager *) userdata; + pa_assert(conn); + pa_assert(msg); + pa_assert(dm); PA_IDXSET_FOREACH(device, dm->device_list, device_idx) { pa_tz_device_dump_info(device, PA_LOG_INFO); } - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + + pa_dbus_send_empty_reply(conn, msg); } static bool is_usb_output_device(pa_tz_device *device) { @@ -1057,7 +1026,7 @@ static bool is_supported_sample_format(pa_sample_format_t *supported_sample_form } static void handle_get_supported_sample_formats(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *dm; + pa_device_manager *dm = (pa_device_manager *)userdata; DBusMessage *reply = NULL; DBusMessageIter msg_iter, array_iter; dbus_int32_t device_id; @@ -1068,9 +1037,7 @@ static void handle_get_supported_sample_formats(DBusConnection *conn, DBusMessag pa_assert(conn); pa_assert(msg); - pa_assert(userdata); - - dm = (pa_device_manager *)userdata; + pa_assert(dm); pa_assert_se((reply = dbus_message_new_method_return(msg))); @@ -1114,8 +1081,7 @@ static void handle_get_supported_sample_formats(DBusConnection *conn, DBusMessag } static void handle_set_sample_format(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *dm; - DBusMessage *reply = NULL; + pa_device_manager *dm = (pa_device_manager *)userdata; dbus_int32_t device_id; char *sample_format; pa_sample_format_t prev_selected_sample_format; @@ -1125,10 +1091,8 @@ static void handle_set_sample_format(DBusConnection *conn, DBusMessage *msg, voi pa_assert(conn); pa_assert(msg); - pa_assert(userdata); + pa_assert(dm); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - dm = (pa_device_manager *)userdata; pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &device_id, DBUS_TYPE_STRING, &sample_format, @@ -1172,13 +1136,12 @@ static void handle_set_sample_format(DBusConnection *conn, DBusMessage *msg, voi } pa_log_info("Set sample format(%s) of the device(id:%d) successfully", sample_format, device_id); - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + + pa_dbus_send_empty_reply(conn, msg); } static void handle_get_sample_format(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *dm; - DBusMessage *reply = NULL; + pa_device_manager *dm = (pa_device_manager *)userdata; dbus_int32_t device_id; pa_tz_device *device; pa_sink *sink; @@ -1186,11 +1149,7 @@ static void handle_get_sample_format(DBusConnection *conn, DBusMessage *msg, voi pa_assert(conn); pa_assert(msg); - pa_assert(userdata); - - dm = (pa_device_manager *)userdata; - - pa_assert_se((reply = dbus_message_new_method_return(msg))); + pa_assert(dm); pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &device_id, @@ -1215,10 +1174,8 @@ static void handle_get_sample_format(DBusConnection *conn, DBusMessage *msg, voi format = pa_sample_format_to_string(sink->selected_sample_format); pa_log_info("Get sample format(%s) of the device(id:%d) successfully", format, device_id); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &format, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_STRING, &format); } static bool is_supported_sample_rate(uint32_t *supported_sample_rates, uint32_t sample_rate) { @@ -1237,7 +1194,7 @@ static bool is_supported_sample_rate(uint32_t *supported_sample_rates, uint32_t } static void handle_get_supported_sample_rates(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *dm; + pa_device_manager *dm = (pa_device_manager *)userdata; DBusMessage *reply = NULL; DBusMessageIter msg_iter, array_iter; dbus_int32_t device_id; @@ -1247,9 +1204,7 @@ static void handle_get_supported_sample_rates(DBusConnection *conn, DBusMessage pa_assert(conn); pa_assert(msg); - pa_assert(userdata); - - dm = (pa_device_manager *)userdata; + pa_assert(dm); pa_assert_se((reply = dbus_message_new_method_return(msg))); @@ -1292,8 +1247,7 @@ static void handle_get_supported_sample_rates(DBusConnection *conn, DBusMessage } static void handle_set_sample_rate(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *dm; - DBusMessage *reply = NULL; + pa_device_manager *dm = (pa_device_manager *)userdata; dbus_int32_t device_id; dbus_uint32_t sample_rate; uint32_t prev_selected_sample_rate; @@ -1303,10 +1257,8 @@ static void handle_set_sample_rate(DBusConnection *conn, DBusMessage *msg, void pa_assert(conn); pa_assert(msg); - pa_assert(userdata); + pa_assert(dm); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - dm = (pa_device_manager *)userdata; pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &device_id, DBUS_TYPE_UINT32, &sample_rate, @@ -1350,24 +1302,19 @@ static void handle_set_sample_rate(DBusConnection *conn, DBusMessage *msg, void } pa_log_info("Set sample rate(%u) of the device(id:%d) successfully", sample_rate, device_id); - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + + pa_dbus_send_empty_reply(conn, msg); } static void handle_get_sample_rate(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *dm; - DBusMessage *reply = NULL; + pa_device_manager *dm = (pa_device_manager *)userdata; dbus_int32_t device_id; pa_tz_device *device; pa_sink *sink; pa_assert(conn); pa_assert(msg); - pa_assert(userdata); - - dm = (pa_device_manager *)userdata; - - pa_assert_se((reply = dbus_message_new_method_return(msg))); + pa_assert(dm); pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &device_id, @@ -1391,25 +1338,20 @@ static void handle_get_sample_rate(DBusConnection *conn, DBusMessage *msg, void } pa_log_info("Get sample rate(%u) of the device(id:%d) successfully", sink->selected_sample_rate, device_id); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, &sink->selected_sample_rate, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_UINT32, &sink->selected_sample_rate); } static void handle_set_specific_stream_only(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *dm; - DBusMessage *reply = NULL; + pa_device_manager *dm = (pa_device_manager *)userdata; dbus_int32_t device_id; char *stream_role; pa_tz_device *device; pa_assert(conn); pa_assert(msg); - pa_assert(userdata); + pa_assert(dm); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - dm = (pa_device_manager *)userdata; pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &device_id, DBUS_TYPE_STRING, &stream_role, @@ -1434,24 +1376,18 @@ static void handle_set_specific_stream_only(DBusConnection *conn, DBusMessage *m pa_xfree(device->specified_stream_role); device->specified_stream_role = pa_xstrdup(stream_role); - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + pa_dbus_send_empty_reply(conn, msg); } static void handle_get_specified_stream(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *dm; - DBusMessage *reply = NULL; + pa_device_manager *dm = (pa_device_manager *)userdata; dbus_int32_t device_id; char *specified_stream_role; pa_tz_device *device; pa_assert(conn); pa_assert(msg); - pa_assert(userdata); - - dm = (pa_device_manager *)userdata; - - pa_assert_se((reply = dbus_message_new_method_return(msg))); + pa_assert(dm); pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &device_id, @@ -1472,15 +1408,12 @@ static void handle_get_specified_stream(DBusConnection *conn, DBusMessage *msg, specified_stream_role = device->specified_stream_role; pa_log_info("stream role(%s) is specified for the device(id:%d)", device->specified_stream_role, device_id); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &specified_stream_role, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_STRING, &specified_stream_role); } static void handle_set_avoid_resampling(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *dm; - DBusMessage *reply = NULL; + pa_device_manager *dm = (pa_device_manager *)userdata; dbus_int32_t device_id; dbus_bool_t avoid_resampling; pa_tz_device *device; @@ -1488,10 +1421,8 @@ static void handle_set_avoid_resampling(DBusConnection *conn, DBusMessage *msg, pa_assert(conn); pa_assert(msg); - pa_assert(userdata); + pa_assert(dm); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - dm = (pa_device_manager *)userdata; pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &device_id, DBUS_TYPE_BOOLEAN, &avoid_resampling, @@ -1515,24 +1446,17 @@ static void handle_set_avoid_resampling(DBusConnection *conn, DBusMessage *msg, } if (sink->avoid_resampling == avoid_resampling) { pa_log_info("already set to %d", avoid_resampling); - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); - return; + } else { + sink->avoid_resampling = avoid_resampling; + save_preference(dm, sink); + pa_log_info("Set avoid-resampling(%d) to the device(id:%d)", avoid_resampling, device_id); } - sink->avoid_resampling = avoid_resampling; - - save_preference(dm, sink); - - pa_log_info("Set avoid-resampling(%d) to the device(id:%d)", avoid_resampling, device_id); - - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + pa_dbus_send_empty_reply(conn, msg); } static void handle_get_avoid_resampling(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *dm; - DBusMessage *reply = NULL; + pa_device_manager *dm = (pa_device_manager *)userdata; dbus_int32_t device_id; dbus_bool_t avoid_resampling; pa_tz_device *device; @@ -1540,11 +1464,7 @@ static void handle_get_avoid_resampling(DBusConnection *conn, DBusMessage *msg, pa_assert(conn); pa_assert(msg); - pa_assert(userdata); - - dm = (pa_device_manager *)userdata; - - pa_assert_se((reply = dbus_message_new_method_return(msg))); + pa_assert(dm); pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &device_id, @@ -1570,48 +1490,38 @@ static void handle_get_avoid_resampling(DBusConnection *conn, DBusMessage *msg, avoid_resampling = sink->avoid_resampling; pa_log_info("got avoid-resampling(%d) of the device(id:%d)", avoid_resampling, device_id); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &avoid_resampling, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_BOOLEAN, &avoid_resampling); } static void handle_test_device_status_change(DBusConnection *conn, DBusMessage *msg, void *userdata) { pa_device_manager *dm = (pa_device_manager *)userdata; char *type; dbus_int32_t status; - DBusMessage *reply = NULL; - DBusError error; - pa_assert_se((reply = dbus_message_new_method_return(msg))); + pa_assert(conn); + pa_assert(msg); + pa_assert(dm); - dbus_error_init(&error); - if (!dbus_message_get_args(msg, NULL, + pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &type, DBUS_TYPE_INT32, &status, - DBUS_TYPE_INVALID)) { - pa_log_error("failed to get dbus args : %s", error.message); - pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "%s", error.message); - dbus_error_free(&error); - } + DBUS_TYPE_INVALID)); pa_log_debug("handle_test_device_status_change, type:%s, status:%d", type, status); - handle_device_status_changed(dm, type, NULL, NULL, status); - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + handle_device_status_changed(dm, type, NULL, NULL, status); + + pa_dbus_send_empty_reply(conn, msg); } static void handle_set_acm_mode(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *dm; - DBusMessage *reply = NULL; + pa_device_manager *dm = (pa_device_manager *)userdata; uint32_t mode = 0; pa_assert(conn); pa_assert(msg); - pa_assert(userdata); + pa_assert(dm); - dm = (pa_device_manager *)userdata; pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &mode, DBUS_TYPE_INVALID)); @@ -1629,9 +1539,7 @@ static void handle_set_acm_mode(DBusConnection *conn, DBusMessage *msg, void *us } } - pa_assert_se((reply = dbus_message_new_method_return(msg))); - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + pa_dbus_send_empty_reply(conn, msg); } static DBusHandlerResult handle_introspect(DBusConnection *conn, DBusMessage *msg, void *userdata) { -- 2.7.4 From 7275b04d86b876e76c958170541c1d5922566828 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Thu, 29 Oct 2020 16:34:37 +0900 Subject: [PATCH 13/16] stream-manager-dbus: use pa dbus wrapper function if possible [Version] 13.0.36 [Issue Type] Revise Change-Id: Ib30dd5934fa4a2554652feb550937d15a2fa177f --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/stream-manager-dbus.c | 708 +++++++++++++------------------- 2 files changed, 278 insertions(+), 432 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index e6f794d..9f5b1f7 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: 13.0.35 +Version: 13.0.36 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/stream-manager-dbus.c b/src/stream-manager-dbus.c index c365345..d5c87b3 100644 --- a/src/stream-manager-dbus.c +++ b/src/stream-manager-dbus.c @@ -381,6 +381,28 @@ static pa_dbus_method_handler method_handlers[METHOD_HANDLER_MAX] = { .receive_cb = handle_publish_local_device }, }; +static int get_stream_type(const char *direction, stream_type_t *stream_type) { + if (pa_safe_streq(direction, "in")) + *stream_type = STREAM_SOURCE_OUTPUT; + else if (pa_safe_streq(direction, "out")) + *stream_type = STREAM_SINK_INPUT; + else + return -1; + + return 0; +} + +static int get_direction_type(const char *direction, stream_direction_t *direction_type) { + if (pa_safe_streq(direction, "in")) + *direction_type = STREAM_DIRECTION_IN; + else if (pa_safe_streq(direction, "out")) + *direction_type = STREAM_DIRECTION_OUT; + else + return -1; + + return 0; +} + static DBusHandlerResult handle_introspect(DBusConnection *conn, DBusMessage *msg, void *userdata) { const char *xml = STREAM_MGR_INTROSPECT_XML; DBusMessage *r = NULL; @@ -401,10 +423,10 @@ static DBusHandlerResult handle_introspect(DBusConnection *conn, DBusMessage *ms } static void handle_get_stream_list(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; stream_list list; DBusMessage *reply = NULL; DBusMessageIter msg_iter; - pa_stream_manager *m = (pa_stream_manager*)userdata; pa_assert(conn); pa_assert(msg); @@ -429,11 +451,11 @@ static void handle_get_stream_list(DBusConnection *conn, DBusMessage *msg, void } static void handle_get_stream_info(DBusConnection *conn, DBusMessage *msg, void *userdata) { - char *type; + pa_stream_manager *m = (pa_stream_manager *)userdata; + const char *type; stream_info_per_type info; DBusMessage *reply = NULL; DBusMessageIter msg_iter; - pa_stream_manager *m = (pa_stream_manager*)userdata; pa_assert(conn); pa_assert(msg); @@ -550,15 +572,14 @@ static ret_msg_t update_devices_and_trigger_routing(pa_stream_manager *m, stream } static void handle_set_stream_route_devices(DBusConnection *conn, DBusMessage *msg, void *userdata) { - uint32_t id = 0; + pa_stream_manager *m = (pa_stream_manager *)userdata; int i = 0; - uint32_t *in_device_list = NULL; - uint32_t *out_device_list = NULL; - int list_len_in = 0; - int list_len_out = 0; + dbus_uint32_t *in_device_list = NULL; + dbus_uint32_t *out_device_list = NULL; + dbus_uint32_t id = 0; + dbus_uint32_t list_len_in = 0; + dbus_uint32_t list_len_out = 0; 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); @@ -570,11 +591,9 @@ static void handle_set_stream_route_devices(DBusConnection *conn, DBusMessage *m DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &in_device_list, &list_len_in, DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &out_device_list, &list_len_out, DBUS_TYPE_INVALID)); - pa_log_info("id[%u], in_device_list[%p]:length[%d], out_device_list[%p]:length[%d]", + pa_log_info("id[%u], in_device_list[%p]:length[%u], out_device_list[%p]:length[%u]", id, in_device_list, list_len_in, out_device_list, list_len_out); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - sp = pa_hashmap_get(m->stream_parents, (const void*)id); if (!sp) { pa_log_error("could not find matching client for this parent_id[%u]", id); @@ -606,9 +625,9 @@ static void handle_set_stream_route_devices(DBusConnection *conn, DBusMessage *m } pa_idxset_remove_all(sp->idx_route_in_devices, pa_xfree); - if (in_device_list && list_len_in) { + if (in_device_list) { 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_idxset_put(sp->idx_route_in_devices, pa_xmemdup(&in_device_list[i], sizeof(dbus_uint32_t)), NULL); pa_log_debug(" -- [in] device id:%u", in_device_list[i]); } } @@ -616,30 +635,28 @@ static void handle_set_stream_route_devices(DBusConnection *conn, DBusMessage *m goto finish; pa_idxset_remove_all(sp->idx_route_out_devices, pa_xfree); - if (out_device_list && list_len_out) { + if (out_device_list) { 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_idxset_put(sp->idx_route_out_devices, pa_xmemdup(&out_device_list[i], sizeof(dbus_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; + + ret = update_devices_and_trigger_routing(m, sp, STREAM_SINK_INPUT); 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); + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret]); } static void handle_set_stream_route_option(DBusConnection *conn, DBusMessage *msg, void *userdata) { - uint32_t id = 0; + pa_stream_manager *m = (pa_stream_manager *)userdata; + dbus_uint32_t id = 0; const char *name = NULL; - int32_t value = 0; + dbus_int32_t value = 0; bool updated = false; stream_parent *sp = NULL; stream_route_option route_option; - DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; + ret_msg_t ret = RET_MSG_OK; pa_assert(conn); pa_assert(msg); @@ -650,9 +667,7 @@ static void handle_set_stream_route_option(DBusConnection *conn, DBusMessage *ms DBUS_TYPE_STRING, &name, DBUS_TYPE_INT32, &value, DBUS_TYPE_INVALID)); - pa_log_info("name[%s], value[%d]", name, value); - - pa_assert_se((reply = dbus_message_new_method_return(msg))); + pa_log_info("id[%u], name[%s], value[%d]", id, name, value); sp = pa_hashmap_get(m->stream_parents, (const void*)id); if (sp) { @@ -679,21 +694,18 @@ 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_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_OK], DBUS_TYPE_INVALID)); + ret = RET_MSG_ERROR_NO_STREAM; + } } else { pa_log_error("invalid arguments"); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INVALID_ARGUMENT], DBUS_TYPE_INVALID)); + ret = RET_MSG_ERROR_INVALID_ARGUMENT; } - } 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_ERROR_INTERNAL], DBUS_TYPE_INVALID)); + ret = RET_MSG_ERROR_INTERNAL; } - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret]); } static int get_device_for_preference(pa_stream_manager *m, stream_parent *sp, stream_direction_t direction, uint32_t device_id, pa_tz_device **device) { @@ -721,9 +733,10 @@ static int get_device_for_preference(pa_stream_manager *m, stream_parent *sp, st } static void handle_set_stream_preferred_device(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; const char *device_direction = NULL; - uint32_t sp_id = 0; - uint32_t device_id = 0; + dbus_uint32_t sp_id = 0; + dbus_uint32_t device_id = 0; uint32_t idx; uint32_t count = 0; stream_direction_t direction; @@ -741,9 +754,6 @@ static void handle_set_stream_preferred_device(DBusConnection *conn, DBusMessage pa_hashmap *devices; void *new_device = NULL; ret_msg_t ret = RET_MSG_OK; - DBusMessage *reply = NULL; - - pa_stream_manager *m = (pa_stream_manager*)userdata; pa_assert(conn); pa_assert(msg); @@ -756,19 +766,13 @@ static void handle_set_stream_preferred_device(DBusConnection *conn, DBusMessage DBUS_TYPE_INVALID)); pa_log_info("stream parent id[%u], device direction[%s], device_id[%u]", sp_id, device_direction, device_id); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - if (!(sp = pa_hashmap_get(m->stream_parents, (const void*)sp_id))) { pa_log_error("could not find matching client for this parent_id[%u]", sp_id); ret = RET_MSG_ERROR_INTERNAL; goto finish; } - if (pa_safe_streq(device_direction, "in")) - direction = STREAM_DIRECTION_IN; - else if (pa_safe_streq(device_direction, "out")) - direction = STREAM_DIRECTION_OUT; - else { + if (get_direction_type(device_direction, &direction) != 0) { ret = RET_MSG_ERROR_INVALID_ARGUMENT; goto finish; } @@ -863,14 +867,13 @@ static void handle_set_stream_preferred_device(DBusConnection *conn, DBusMessage } 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); + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret]); } static void handle_get_stream_preferred_device(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; stream_parent *sp = NULL; - uint32_t sp_id = 0; + dbus_uint32_t sp_id = 0; uint32_t in_device_id = 0; uint32_t out_device_id = 0; const char *pref_in_type, *pref_out_type; @@ -882,8 +885,6 @@ static void handle_get_stream_preferred_device(DBusConnection *conn, DBusMessage ret_msg_t ret = RET_MSG_OK; DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; - pa_assert(conn); pa_assert(msg); pa_assert(m); @@ -910,13 +911,13 @@ static void handle_get_stream_preferred_device(DBusConnection *conn, DBusMessage dm_device_list = pa_device_manager_get_device_list(m->dm); PA_IDXSET_FOREACH(dm_device, dm_device_list, idx) { dm_direction = pa_tz_device_get_direction(dm_device); - if (!in_device_id && dm_direction & DM_DEVICE_DIRECTION_IN) { + if (in_device_id == 0 && (dm_direction & DM_DEVICE_DIRECTION_IN)) { if (pa_safe_streq(pref_in_type, pa_tz_device_get_type(dm_device))) { if (pa_safe_streq(pref_in_role, pa_tz_device_get_role(dm_device, pref_in_role))) in_device_id = pa_tz_device_get_id(dm_device); } } - if (!out_device_id && dm_direction & DM_DEVICE_DIRECTION_OUT) { + if (out_device_id == 0 && (dm_direction & DM_DEVICE_DIRECTION_OUT)) { if (pa_safe_streq(pref_out_type, pa_tz_device_get_type(dm_device))) { if (pa_safe_streq(pref_out_role, pa_tz_device_get_role(dm_device, pref_out_role))) out_device_id = pa_tz_device_get_id(dm_device); @@ -928,9 +929,10 @@ static void handle_get_stream_preferred_device(DBusConnection *conn, DBusMessage pa_log_info("preferred OUT device: type[%s] role[%s] id[%u]", pref_out_type, pref_out_role, out_device_id); finish: - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, &in_device_id, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, &out_device_id, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, &in_device_id, + DBUS_TYPE_UINT32, &out_device_id, + 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); } @@ -1052,10 +1054,11 @@ static void rollback_process_from_preemptive_device(pa_stream_manager *m, stream } static void handle_set_stream_preemptive_device(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; const char *stream_type = NULL; const char *device_direction = NULL; stream_direction_t direction; - uint32_t device_id = 0; + dbus_uint32_t device_id = 0; stream_info *s = NULL; pa_tz_device *device = NULL; char *device_type = NULL; @@ -1064,9 +1067,6 @@ static void handle_set_stream_preemptive_device(DBusConnection *conn, DBusMessag uint32_t idx; bool found = false; ret_msg_t ret = RET_MSG_OK; - DBusMessage *reply = NULL; - - pa_stream_manager *m = (pa_stream_manager*)userdata; pa_assert(conn); pa_assert(msg); @@ -1079,19 +1079,13 @@ static void handle_set_stream_preemptive_device(DBusConnection *conn, DBusMessag DBUS_TYPE_INVALID)); pa_log_info("stream type[%s], device direction[%s], device_id[%u]", stream_type, device_direction, device_id); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - if ((s = pa_hashmap_get(m->stream_infos, stream_type)) == NULL) { pa_log_error("could not find this stream type(%s)", stream_type); ret = RET_MSG_ERROR_INTERNAL; goto finish; } - if (pa_safe_streq(device_direction, "in")) - direction = STREAM_DIRECTION_IN; - else if (pa_safe_streq(device_direction, "out")) - direction = STREAM_DIRECTION_OUT; - else { + if (get_direction_type(device_direction, &direction) != 0) { ret = RET_MSG_ERROR_INVALID_ARGUMENT; goto finish; } @@ -1141,7 +1135,8 @@ static void handle_set_stream_preemptive_device(DBusConnection *conn, DBusMessag /* move streams and change routing */ if (device_id == 0) { - if (!(device = pa_device_manager_get_device_by_id(m->dm, prev_device_id)) || !pa_safe_streq(device->type, prev_device_type)) { + if (!(device = pa_device_manager_get_device_by_id(m->dm, prev_device_id)) || + !pa_safe_streq(device->type, prev_device_type)) { pa_log_debug("could not find the previous device of id[%u], type[%s], nothing to do.", prev_device_id, prev_device_type); goto finish; } @@ -1151,12 +1146,11 @@ static void handle_set_stream_preemptive_device(DBusConnection *conn, DBusMessag } 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); + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret]); } static void handle_get_stream_preemptive_device(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; const char *stream_type = NULL; stream_info *s = NULL; uint32_t in_device_id = 0; @@ -1166,8 +1160,6 @@ static void handle_get_stream_preemptive_device(DBusConnection *conn, DBusMessag ret_msg_t ret = RET_MSG_OK; DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; - pa_assert(conn); pa_assert(msg); pa_assert(m); @@ -1194,22 +1186,21 @@ static void handle_get_stream_preemptive_device(DBusConnection *conn, DBusMessag pa_log_info("preemptive OUT device: type[%s] id[%u]", out_device_type, out_device_id); finish: - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, &in_device_id, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, &out_device_id, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret], DBUS_TYPE_INVALID)); + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, &in_device_id, + DBUS_TYPE_UINT32, &out_device_id, + 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); } static void handle_set_volume_level(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; const char *direction = NULL; const char *type = NULL; - uint32_t level = 0; + dbus_uint32_t level = 0; stream_type_t stream_type = STREAM_SINK_INPUT; - DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; int ret = 0; - ret_msg_t ret_msg = RET_MSG_ERROR_INTERNAL; pa_assert(conn); pa_assert(msg); @@ -1222,47 +1213,35 @@ static void handle_set_volume_level(DBusConnection *conn, DBusMessage *msg, void DBUS_TYPE_INVALID)); pa_log_info("direction[%s], type[%s], level[%u]", direction, type, level); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - - if (pa_safe_streq(direction, "in")) - stream_type = STREAM_SOURCE_OUTPUT; - else if (pa_safe_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], DBUS_TYPE_INVALID)); - ret = -1; + if (get_stream_type(direction, &stream_type) != 0) { + ret = RET_MSG_ERROR_INTERNAL; goto finish; } /* check vconf update here, volume will not be set if update fails */ if ((ret = update_volume_vconf(type, level))) { - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret_msg], DBUS_TYPE_INVALID)); + ret = RET_MSG_ERROR_INTERNAL; goto finish; } - if ((ret = set_volume_level_by_type(m, stream_type, type, level))) { - if (ret == -2) - ret_msg = RET_MSG_ERROR_INVALID_ARGUMENT; - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret_msg], DBUS_TYPE_INVALID)); - } else { - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_OK], DBUS_TYPE_INVALID)); - } + if ((ret = set_volume_level_by_type(m, stream_type, type, level)) != 0) + ret = (ret == -2) ? RET_MSG_ERROR_INVALID_ARGUMENT : RET_MSG_ERROR_INTERNAL; finish: - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret]); - if (!ret) + if (ret == 0) send_volume_changed_signal(conn, direction, type, level); } static void handle_get_volume_level(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; const char *direction = NULL; const char *type = NULL; uint32_t level = 0; stream_type_t stream_type = STREAM_SINK_INPUT; DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; + ret_msg_t ret = RET_MSG_OK; pa_assert(conn); pa_assert(msg); @@ -1276,36 +1255,30 @@ static void handle_get_volume_level(DBusConnection *conn, DBusMessage *msg, void pa_assert_se((reply = dbus_message_new_method_return(msg))); - if (pa_safe_streq(direction, "in")) - stream_type = STREAM_SOURCE_OUTPUT; - else if (pa_safe_streq(direction, "out")) - stream_type = STREAM_SINK_INPUT; - 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_ERROR_INTERNAL], DBUS_TYPE_INVALID)); + if (get_stream_type(direction, &stream_type) != 0) { + ret = RET_MSG_ERROR_INTERNAL; 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, &level, 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_OK], DBUS_TYPE_INVALID)); - } + if (get_volume_level_by_type(m, GET_VOLUME_CURRENT_LEVEL, stream_type, type, &level) != 0) + ret = RET_MSG_ERROR_INTERNAL; finish: + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, &level, + 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); } static void handle_get_volume_max_level(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; const char *direction = NULL; const char *type = NULL; uint32_t level = 0; stream_type_t stream_type = STREAM_SINK_INPUT; DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; + ret_msg_t ret = RET_MSG_OK; pa_assert(conn); pa_assert(msg); @@ -1319,36 +1292,29 @@ static void handle_get_volume_max_level(DBusConnection *conn, DBusMessage *msg, pa_assert_se((reply = dbus_message_new_method_return(msg))); - if (pa_safe_streq(direction, "in")) - stream_type = STREAM_SOURCE_OUTPUT; - else if (pa_safe_streq(direction, "out")) - stream_type = STREAM_SINK_INPUT; - 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_ERROR_INTERNAL], DBUS_TYPE_INVALID)); + if (get_stream_type(direction, &stream_type) != 0) { + ret = RET_MSG_ERROR_INTERNAL; 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, &level, 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_OK], DBUS_TYPE_INVALID)); - } + if (get_volume_level_by_type(m, GET_VOLUME_MAX_LEVEL, stream_type, type, &level) != 0) + ret = RET_MSG_ERROR_INTERNAL; + finish: + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, &level, + 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); } static void handle_set_volume_mute(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; const char *direction = NULL; const char *type = NULL; - uint32_t do_mute = 0; + dbus_uint32_t do_mute = 0; stream_type_t stream_type = STREAM_SINK_INPUT; - DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; - int ret = 0; + ret_msg_t ret = RET_MSG_OK; pa_assert(conn); pa_assert(msg); @@ -1361,40 +1327,33 @@ static void handle_set_volume_mute(DBusConnection *conn, DBusMessage *msg, void DBUS_TYPE_INVALID)); pa_log_info("direction[%s], type[%s], do_mute[%u]", direction, type, do_mute); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - - if (pa_safe_streq(direction, "in")) - stream_type = STREAM_SOURCE_OUTPUT; - else if (pa_safe_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_ERROR_INTERNAL], DBUS_TYPE_INVALID)); + if (get_stream_type(direction, &stream_type) != 0) { + ret = RET_MSG_ERROR_INTERNAL; goto finish; } /* check vconf update here, mute will not be set if update fails */ - if ((ret = update_mute_vconf(type, do_mute))) { - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INTERNAL], DBUS_TYPE_INVALID)); + if (update_mute_vconf(type, do_mute) != 0) { + ret = RET_MSG_ERROR_INTERNAL; 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_ERROR_INTERNAL], DBUS_TYPE_INVALID)); - else - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_OK], DBUS_TYPE_INVALID)); + if (set_volume_mute_by_type(m, stream_type, type, (bool)do_mute) != 0) + ret = RET_MSG_ERROR_INTERNAL; finish: - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret]); } static void handle_get_volume_mute(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; const char *direction = NULL; const char *type = NULL; - uint32_t is_muted = 0; + dbus_uint32_t is_muted = 0; stream_type_t stream_type = STREAM_SINK_INPUT; DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; + bool _is_muted = false; + ret_msg_t ret = RET_MSG_OK; pa_assert(conn); pa_assert(msg); @@ -1408,38 +1367,33 @@ static void handle_get_volume_mute(DBusConnection *conn, DBusMessage *msg, void pa_assert_se((reply = dbus_message_new_method_return(msg))); - if (pa_safe_streq(direction, "in")) - stream_type = STREAM_SOURCE_OUTPUT; - else if (pa_safe_streq(direction, "out")) - stream_type = STREAM_SINK_INPUT; - 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_ERROR_INTERNAL], DBUS_TYPE_INVALID)); - goto fail; + if (get_stream_type(direction, &stream_type) != 0) { + ret = RET_MSG_ERROR_INTERNAL; + goto finish; } - if (get_volume_mute_by_type(m, stream_type, type, (bool*)&is_muted)) { - 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_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_OK], DBUS_TYPE_INVALID)); + if (get_volume_mute_by_type(m, stream_type, type, &_is_muted) != 0) { + ret = RET_MSG_ERROR_INTERNAL; + goto finish; } -fail: + is_muted = (dbus_uint32_t)_is_muted; + +finish: + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, &is_muted, + 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); } static void handle_set_volume_ratio(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; const char *direction = NULL; - uint32_t idx; + dbus_uint32_t idx; double ratio; stream_type_t stream_type = STREAM_SINK_INPUT; - DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; - int ret = 0; - ret_msg_t ret_msg = RET_MSG_ERROR_INTERNAL; + ret_msg_t ret = RET_MSG_OK; pa_assert(conn); pa_assert(msg); @@ -1452,49 +1406,34 @@ static void handle_set_volume_ratio(DBusConnection *conn, DBusMessage *msg, void DBUS_TYPE_INVALID)); pa_log_info("direction[%s], idx[%u], ratio[%f]", direction, idx, ratio); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - - if (pa_safe_streq(direction, "in")) - stream_type = STREAM_SOURCE_OUTPUT; - else if (pa_safe_streq(direction, "out")) - stream_type = STREAM_SINK_INPUT; - else { + if (get_stream_type(direction, &stream_type) != 0) { pa_log_error("invalid direction[%s]", direction); - goto invalid_argument; + ret = RET_MSG_ERROR_INVALID_ARGUMENT; + goto finish; } /* Check the ratio range (0.0 ~ 1.0) */ if (ratio < 0 || ratio > 1) { pa_log_error("invalid range, ratio[%f]", ratio); - goto invalid_argument; - } - - if ((ret = set_volume_ratio_by_idx(m, stream_type, idx, ratio))) { - if (ret == -2) - ret_msg = RET_MSG_ERROR_NO_STREAM; - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret_msg], DBUS_TYPE_INVALID)); - } else { - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_OK], DBUS_TYPE_INVALID)); + ret = RET_MSG_ERROR_INVALID_ARGUMENT; + goto finish; } - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); - return; + if ((ret = set_volume_ratio_by_idx(m, stream_type, idx, ratio)) != 0) + ret = (ret == -2) ? RET_MSG_ERROR_NO_STREAM : RET_MSG_ERROR_INTERNAL; -invalid_argument: - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_ERROR_INVALID_ARGUMENT], - DBUS_TYPE_INVALID)); - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); +finish: + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret]); } static void handle_get_volume_ratio(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; const char *direction = NULL; - uint32_t idx = 0; + dbus_uint32_t idx = 0; double ratio; stream_type_t stream_type = STREAM_SINK_INPUT; DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; + ret_msg_t ret = RET_MSG_OK; pa_assert(conn); pa_assert(msg); @@ -1508,38 +1447,33 @@ static void handle_get_volume_ratio(DBusConnection *conn, DBusMessage *msg, void pa_assert_se((reply = dbus_message_new_method_return(msg))); - if (pa_safe_streq(direction, "in")) - stream_type = STREAM_SOURCE_OUTPUT; - else if (pa_safe_streq(direction, "out")) - stream_type = STREAM_SINK_INPUT; - else { - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_DOUBLE, &ratio, 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)); + if (get_stream_type(direction, &stream_type) != 0) { + pa_log_error("invalid direction[%s]", direction); + ret = RET_MSG_ERROR_INVALID_ARGUMENT; goto finish; } - if (get_volume_ratio_by_idx(m, stream_type, idx, &ratio)) { - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_DOUBLE, &ratio, 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_DOUBLE, &ratio, 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)); - } + if (get_volume_ratio_by_idx(m, stream_type, idx, &ratio) != 0) + ret = RET_MSG_ERROR_NO_STREAM; finish: + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_DOUBLE, &ratio, + 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); } static void handle_get_current_volume_type(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; const char *direction = NULL; - const char *type = NULL; + const char *type = dbus_str_none; void *s = NULL; stream_type_t stream_type = STREAM_SINK_INPUT; DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; uint32_t idx = 0; pa_idxset *streams = NULL; + ret_msg_t ret = RET_MSG_OK; pa_assert(conn); pa_assert(msg); @@ -1552,18 +1486,13 @@ static void handle_get_current_volume_type(DBusConnection *conn, DBusMessage *ms pa_assert_se((reply = dbus_message_new_method_return(msg))); - if (pa_safe_streq(direction, "in")) { - stream_type = STREAM_SOURCE_OUTPUT; - streams = m->core->source_outputs; - } else if (pa_safe_streq(direction, "out")) { - stream_type = STREAM_SINK_INPUT; - 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_ERROR_INTERNAL], DBUS_TYPE_INVALID)); - goto fail; + if (get_stream_type(direction, &stream_type) != 0) { + ret = RET_MSG_ERROR_INTERNAL; + goto finish; } + streams = (stream_type == STREAM_SOURCE_OUTPUT) ? m->core->source_outputs : m->core->sink_inputs; + /* Get a volume type of a stream that has the max priority role among all the running streams regardless of devices. Note that it does not represent any focus status of a stream rather only checking the priority of it */ if (pa_idxset_size(streams)) { @@ -1590,27 +1519,26 @@ static void handle_get_current_volume_type(DBusConnection *conn, DBusMessage *ms type = cur_max_type; } - 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_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_ERROR_NO_STREAM], DBUS_TYPE_INVALID)); - } + if (!strncmp(type, dbus_str_none, strlen(dbus_str_none))) + ret = RET_MSG_ERROR_NO_STREAM; -fail: +finish: + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &type, + 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); } static void handle_get_current_media_routing_path(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; const char *direction = NULL; - const char *device_type = NULL; + const char *device_type = dbus_str_none; dm_device_direction_t dm_device_direction = DM_DEVICE_DIRECTION_NONE; stream_info *s = NULL; DBusMessage *reply = NULL; pa_tz_device *device = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; + ret_msg_t ret = RET_MSG_ERROR_INTERNAL; pa_assert(conn); pa_assert(msg); @@ -1629,12 +1557,12 @@ static void handle_get_current_media_routing_path(DBusConnection *conn, DBusMess dm_device_direction = DM_DEVICE_DIRECTION_OUT; } else { pa_log_error("invalid direction[%s]", direction); - goto fail; + goto finish; } if ((s = pa_hashmap_get(m->stream_infos, STREAM_ROLE_MEDIA)) == NULL) { pa_log_error("could not find media role"); - goto fail; + goto finish; } if (s->route_type == STREAM_ROUTE_TYPE_AUTO) { @@ -1643,39 +1571,34 @@ static void handle_get_current_media_routing_path(DBusConnection *conn, DBusMess device = get_media_last_device(m, dm_device_direction); } else { pa_log_error("unexpected routing type for media[%d]", s->route_type); - goto fail; + goto finish; } if (device) { device_type = pa_tz_device_get_type(device); - goto success; + ret = RET_MSG_OK; } else { pa_log_error("could not found matched device"); } -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_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_OK], DBUS_TYPE_INVALID)); +finish: + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &device_type, + 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); } static void handle_update_focus_status(DBusConnection *conn, DBusMessage *msg, void *userdata) { - uint32_t id = 0; + pa_stream_manager *m = (pa_stream_manager *)userdata; + dbus_uint32_t id = 0; + dbus_uint32_t acquired_focus_status = 0; uint32_t idx = 0; uint32_t count = 0; - uint32_t acquired_focus_status = 0; stream_parent *sp = NULL; void *stream = NULL; - DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; int prev_status = STREAM_FOCUS_ACQUIRED_NONE; + ret_msg_t ret = RET_MSG_OK; pa_assert(conn); pa_assert(msg); @@ -1687,8 +1610,6 @@ static void handle_update_focus_status(DBusConnection *conn, DBusMessage *msg, v DBUS_TYPE_INVALID)); pa_log_info("id[%u], acquired_focus_status[0x%x]", id, acquired_focus_status); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - if ((sp = pa_hashmap_get(m->stream_parents, (const void*)id))) { if (sp->focus_status != acquired_focus_status) { /* need to update */ @@ -1717,24 +1638,21 @@ 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_ERROR_INTERNAL], DBUS_TYPE_INVALID)); - goto fail; + ret = RET_MSG_ERROR_INTERNAL; } - 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); + + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret]); } static void handle_update_focus_status_by_focus_id(DBusConnection *conn, DBusMessage *msg, void *userdata) { - int32_t id = 0; + pa_stream_manager *m = (pa_stream_manager *)userdata; + dbus_int32_t id = 0; + dbus_uint32_t acquired_focus_status = 0; uint32_t idx = 0; - uint32_t acquired_focus_status = 0; int32_t focus_id = 0; const char *focus_id_str; pa_sink_input *i = NULL; - DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; + ret_msg_t ret = RET_MSG_ERROR_INTERNAL; pa_assert(conn); pa_assert(msg); @@ -1746,36 +1664,37 @@ static void handle_update_focus_status_by_focus_id(DBusConnection *conn, DBusMes DBUS_TYPE_INVALID)); pa_log_info("id[%d], acquired_focus_status[0x%x]", id, acquired_focus_status); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - /* Currently, we only support sink-inputs */ PA_IDXSET_FOREACH(i, m->core->sink_inputs, idx) { if ((focus_id_str = pa_proplist_gets(GET_STREAM_PROPLIST(i, STREAM_SINK_INPUT), PA_PROP_MEDIA_FOCUS_ID))) { if (pa_atoi(focus_id_str, &focus_id)) - continue; - if (id == focus_id) { + continue; + + if (id != focus_id) + continue; + pa_log_info("found matching sink-input(%p, %u) - focus_id(%d)", i, i->index, id); pa_proplist_sets(GET_STREAM_PROPLIST(i, STREAM_SINK_INPUT), PA_PROP_MEDIA_FOCUS_STATUS, 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_OK], DBUS_TYPE_INVALID)); - goto success; + ret = RET_MSG_OK; + break; } - } } - 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_ERROR_INTERNAL], DBUS_TYPE_INVALID)); -success: - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + + if (ret != RET_MSG_OK) + pa_log_error("could not find matching stream for this focus_id[%d]", id); + + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret]); } static void handle_update_restriction(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; const char *name; - uint32_t value = 0; - DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; + dbus_uint32_t value = 0; + ret_msg_t ret = RET_MSG_OK; pa_assert(conn); pa_assert(msg); @@ -1787,17 +1706,10 @@ static void handle_update_restriction(DBusConnection *conn, DBusMessage *msg, vo DBUS_TYPE_INVALID)); pa_log_info("name[%s], value[%u]", name, value); - 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_ERROR_INTERNAL], DBUS_TYPE_INVALID)); - goto fail; - } + if (handle_restrictions(m, name, value) != 0) + ret = RET_MSG_ERROR_INTERNAL; - 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); + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret]); } #define MAX_CALL_PARAM_SIZE 32 @@ -1851,9 +1763,8 @@ static int32_t parse_call_parameters(const char *parameters, char *call_type, ch } static void handle_update_call_parameters(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; const char *parameters; - DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; char call_type[MAX_CALL_PARAM_SIZE] = {0,}; char call_domain[MAX_CALL_PARAM_SIZE] = {0,}; char network_band[MAX_CALL_PARAM_SIZE] = {0,}; @@ -1869,33 +1780,27 @@ static void handle_update_call_parameters(DBusConnection *conn, DBusMessage *msg DBUS_TYPE_INVALID)); pa_log_info("parameters[%s]", parameters); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - - if (parse_call_parameters(parameters, call_type, call_domain, network_band) < 0) { + if (parse_call_parameters(parameters, call_type, call_domain, network_band) != 0) { ret = RET_MSG_ERROR_INTERNAL; - goto fail; + goto finish; } pa_log_debug("call_type[%s], call_domain[%s], network_band[%s]", call_type, call_domain, network_band); /* Currently, we only use network band */ route_option.name = "call-wideband"; - if (pa_safe_streq(network_band, "wb")) - route_option.value = 1; - else - route_option.value = 0; + route_option.value = pa_safe_streq(network_band, "wb") ? 1 : 0; + ret = do_notify(m, NOTIFY_COMMAND_UPDATE_ROUTE_OPTION, STREAM_SINK_INPUT, false, &route_option); -fail: - 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); +finish: + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret]); } static void handle_set_filter(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; const char *filter_name, *filter_parameters, *filter_group, *stream_type; - DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; + ret_msg_t ret = RET_MSG_OK; pa_assert(conn); pa_assert(msg); @@ -1907,30 +1812,20 @@ static void handle_set_filter(DBusConnection *conn, DBusMessage *msg, void *user DBUS_TYPE_STRING, &filter_group, DBUS_TYPE_STRING, &stream_type, DBUS_TYPE_INVALID)); - pa_log_info("filter_name[%s], filter_parameters[%s], filter_group[%s], stream_type[%s]", filter_name, - filter_parameters, filter_group, stream_type); - - pa_assert_se((reply = dbus_message_new_method_return(msg))); + pa_log_info("filter_name[%s], filter_parameters[%s], filter_group[%s], stream_type[%s]", + filter_name, filter_parameters, filter_group, stream_type); /* 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_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_OK], - DBUS_TYPE_INVALID)); + if (update_filter(m, filter_name, filter_parameters, filter_group, stream_type) != 0) + ret = RET_MSG_ERROR_INTERNAL; -fail: - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret]); } static void handle_unset_filter(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; const char *stream_type; - DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; + ret_msg_t ret = RET_MSG_OK; pa_assert(conn); pa_assert(msg); @@ -1941,27 +1836,17 @@ static void handle_unset_filter(DBusConnection *conn, DBusMessage *msg, void *us DBUS_TYPE_INVALID)); pa_log_info("stream_type[%s]", stream_type); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - /* 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_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_OK], - DBUS_TYPE_INVALID)); + if (update_filter(m, NULL, NULL, NULL, stream_type) != 0) + ret = RET_MSG_ERROR_INTERNAL; -fail: - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret]); } static void handle_control_filter(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; const char *filter_name, *filter_controls, *stream_type; - DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; + ret_msg_t ret = RET_MSG_OK; pa_assert(conn); pa_assert(msg); @@ -1974,20 +1859,11 @@ static void handle_control_filter(DBusConnection *conn, DBusMessage *msg, void * DBUS_TYPE_INVALID)); pa_log_info("filter_name[%s], filter_controls[%s], stream_type[%s]", filter_name, filter_controls, stream_type); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - /* 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_ERROR_INTERNAL], - DBUS_TYPE_INVALID)); - goto fail; - } + if (control_filter(m, filter_name, filter_controls, stream_type, conn) != 0) + ret = RET_MSG_ERROR_INTERNAL; - 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); + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret]); } static bool check_stream_exist_by_pid(pa_stream_manager *m, uint32_t pid, const char *stream_role, stream_type_t type) { @@ -2025,12 +1901,12 @@ static bool check_stream_exist_by_pid(pa_stream_manager *m, uint32_t pid, const } static void handle_check_stream_exist_by_pid(DBusConnection *conn, DBusMessage *msg, void *userdata) { - uint32_t pid = 0; + pa_stream_manager *m = (pa_stream_manager *)userdata; + dbus_uint32_t pid = 0; const char *type; const char *direction; stream_type_t stream_type = STREAM_SINK_INPUT; - DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; + ret_msg_t ret = RET_MSG_OK; pa_assert(conn); pa_assert(msg); @@ -2043,29 +1919,16 @@ static void handle_check_stream_exist_by_pid(DBusConnection *conn, DBusMessage * DBUS_TYPE_INVALID)); pa_log_info("pid[%u], type[%s], direction[%s]", pid, type, direction); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - - if (pa_safe_streq(direction, "in")) - stream_type = STREAM_SOURCE_OUTPUT; - else if (pa_safe_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_ERROR_INVALID_ARGUMENT], - DBUS_TYPE_INVALID)); - goto fail; + if (get_stream_type(direction, &stream_type) != 0) { + ret = RET_MSG_ERROR_INVALID_ARGUMENT; + goto finish; } - 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_ERROR_NO_STREAM], - DBUS_TYPE_INVALID)); - goto fail; - } + if (!check_stream_exist_by_pid(m, pid, type, stream_type)) + ret = RET_MSG_ERROR_NO_STREAM; - 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); +finish: + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret]); } static bool find_the_lastest_stream(pa_stream_manager *m, stream_type_t type, const char ** stream_roles, int length, uint32_t *pid) { @@ -2126,15 +1989,15 @@ static bool find_the_lastest_stream(pa_stream_manager *m, stream_type_t type, co } static void handle_get_pid_of_latest_stream(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; const char *direction; const char **types; int length; stream_type_t stream_type = STREAM_SINK_INPUT; uint32_t pid = 0; - ret_msg_t ret_msg = RET_MSG_OK; + ret_msg_t ret = RET_MSG_OK; DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; pa_assert(conn); pa_assert(msg); @@ -2147,48 +2010,38 @@ static void handle_get_pid_of_latest_stream(DBusConnection *conn, DBusMessage *m pa_assert_se((reply = dbus_message_new_method_return(msg))); - if (pa_safe_streq(direction, "in")) - stream_type = STREAM_SOURCE_OUTPUT; - else if (pa_safe_streq(direction, "out")) - stream_type = STREAM_SINK_INPUT; - else { + if (get_stream_type(direction, &stream_type) != 0) { pa_log_error("invalid direction[%s]", direction); - goto invalid_argument; + ret = RET_MSG_ERROR_INVALID_ARGUMENT; + goto finish; } if (length <= 0) { pa_log_error("At least one stream type should be contained"); - goto invalid_argument; + ret = RET_MSG_ERROR_INVALID_ARGUMENT; + goto finish; } if (!find_the_lastest_stream(m, stream_type, types, length, &pid)) - ret_msg = RET_MSG_ERROR_NO_STREAM; - - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, &pid, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret_msg], - DBUS_TYPE_INVALID)); - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); - return; + ret = RET_MSG_ERROR_NO_STREAM; -invalid_argument: - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, &pid, 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)); +finish: + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, &pid, + 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); } static void handle_activate_ducking(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; dbus_uint32_t id = 0; dbus_bool_t enable = 0; const char *target_stream = NULL; - uint32_t idx = 0; - pa_sink_input *i = NULL; dbus_uint32_t duration = 0; double ratio = 0.0; - DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; + uint32_t idx = 0; + pa_sink_input *i = NULL; pa_cvolume vol; pa_cvolume_ramp vol_ramp; stream_ducking *sd = NULL; @@ -2210,8 +2063,6 @@ static void handle_activate_ducking(DBusConnection *conn, DBusMessage *msg, void pa_log_info("id[%u], enable[%u], target stream[%s], duration[%u], ratio[%lf]", id, enable, target_stream, duration, ratio); - pa_assert_se((reply = dbus_message_new_method_return(msg))); - /* get stream_ducking */ sd = pa_hashmap_get(m->stream_duckings, (const void*)id); if (!sd) { @@ -2281,9 +2132,7 @@ static void handle_activate_ducking(DBusConnection *conn, DBusMessage *msg, void pa_log_info("ducking stream count[%p,%d]", sd, sd->ducking_stream_count); _ACTIVATE_DUCKING_DONE: - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret_msg], DBUS_TYPE_INVALID)); - pa_assert_se(dbus_connection_send(conn, reply, NULL)); - dbus_message_unref(reply); + pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret_msg]); if (ret_msg != RET_MSG_OK) return; @@ -2315,9 +2164,9 @@ _ACTIVATE_DUCKING_DONE: } static void handle_get_ducking_state(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_stream_manager *m = (pa_stream_manager *)userdata; dbus_uint32_t id = 0; DBusMessage *reply = NULL; - pa_stream_manager *m = (pa_stream_manager*)userdata; stream_ducking *sd = NULL; dbus_bool_t is_ducked = FALSE; ret_msg_t ret_msg = RET_MSG_OK; @@ -2334,16 +2183,19 @@ static void handle_get_ducking_state(DBusConnection *conn, DBusMessage *msg, voi /* get stream_ducking */ sd = pa_hashmap_get(m->stream_duckings, (const void *)id); - if (sd) { - is_ducked = (dbus_bool_t)is_stream_ducked(sd); - pa_log_info("id[%u], is_ducked[%p,%d]", id, sd, is_ducked); - } else { - ret_msg = RET_MSG_ERROR_INTERNAL; + if (!sd) { pa_log_error("no matched stream ducking for id[%u]", id); + ret_msg = RET_MSG_ERROR_INTERNAL; + goto finish; } - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &is_ducked, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret_msg], DBUS_TYPE_INVALID)); + is_ducked = (dbus_bool_t)is_stream_ducked(sd); + pa_log_info("id[%u], is_ducked[%p,%d]", id, sd, is_ducked); + +finish: + pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &is_ducked, + DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret_msg], + DBUS_TYPE_INVALID)); pa_assert_se(dbus_connection_send(conn, reply, NULL)); dbus_message_unref(reply); @@ -2382,11 +2234,11 @@ static int dbus_launch_mdnsd(pa_stream_manager *m, DBusConnection *conn) { } static void handle_set_remote_permission(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_stream_manager *m = (pa_stream_manager*)userdata; + pa_stream_manager *m = (pa_stream_manager *)userdata; + const char *type = NULL; dbus_uint32_t index; dbus_bool_t allowed; pa_proplist *p = NULL; - char *type = NULL; pa_assert(conn); pa_assert(msg); @@ -2403,7 +2255,7 @@ static void handle_set_remote_permission(DBusConnection *conn, DBusMessage *msg, goto out; } - pa_log_info("type(%s), index(%d), allowed(%d)", type, index, allowed); + pa_log_info("type(%s), index(%u), allowed(%u)", type, index, allowed); p = pa_proplist_new(); if (!p) { @@ -2417,9 +2269,7 @@ static void handle_set_remote_permission(DBusConnection *conn, DBusMessage *msg, } if (pa_streq(type, "sink-input")) { - pa_sink_input *i; - - i = pa_idxset_get_by_index(m->core->sink_inputs, index); + pa_sink_input *i = pa_idxset_get_by_index(m->core->sink_inputs, index); if (!i) { pa_log_error("not found sink-input"); goto out; @@ -2431,9 +2281,7 @@ static void handle_set_remote_permission(DBusConnection *conn, DBusMessage *msg, } } else if (pa_streq(type, "source-output")) { - pa_source_output *o; - - o = pa_idxset_get_by_index(m->core->source_outputs, index); + pa_source_output *o = pa_idxset_get_by_index(m->core->source_outputs, index); if (!o) { pa_log_error("not found source-output"); goto out; @@ -2456,7 +2304,7 @@ out: } static void handle_discover_remote_device(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_stream_manager *m = (pa_stream_manager*)userdata; + pa_stream_manager *m = (pa_stream_manager *)userdata; pa_module *module; dbus_bool_t enable; @@ -2468,7 +2316,7 @@ static void handle_discover_remote_device(DBusConnection *conn, DBusMessage *msg DBUS_TYPE_BOOLEAN, &enable, DBUS_TYPE_INVALID)); - pa_log_info("discover module enable(%d)", enable); + pa_log_info("discover module enable(%u)", enable); if (enable) { if (m->m_discover) { @@ -2494,7 +2342,6 @@ static void handle_discover_remote_device(DBusConnection *conn, DBusMessage *msg } pa_dbus_send_empty_reply(conn, msg); - return; error: @@ -2503,7 +2350,7 @@ error: } static void handle_publish_local_device(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_stream_manager *m = (pa_stream_manager*)userdata; + pa_stream_manager *m = (pa_stream_manager *)userdata; pa_module *module; dbus_bool_t enable; @@ -2515,7 +2362,7 @@ static void handle_publish_local_device(DBusConnection *conn, DBusMessage *msg, DBUS_TYPE_BOOLEAN, &enable, DBUS_TYPE_INVALID)); - pa_log_info("publish module enable(%d)", enable); + pa_log_info("publish module enable(%u)", enable); if (enable) { if (m->m_protocol_tcp || m->m_publish) { @@ -2552,7 +2399,6 @@ static void handle_publish_local_device(DBusConnection *conn, DBusMessage *msg, } pa_dbus_send_empty_reply(conn, msg); - return; error: @@ -2562,7 +2408,7 @@ error: static DBusHandlerResult handle_methods(DBusConnection *conn, DBusMessage *msg, void *userdata) { int idx = 0; - pa_stream_manager *m = (pa_stream_manager*)userdata; + pa_stream_manager *m = (pa_stream_manager *)userdata; pa_assert(conn); pa_assert(msg); @@ -2586,7 +2432,7 @@ static DBusHandlerResult handle_methods(DBusConnection *conn, DBusMessage *msg, } static DBusHandlerResult method_handler_for_vt(DBusConnection *c, DBusMessage *m, void *userdata) { - pa_stream_manager *u = (pa_stream_manager*)userdata; + pa_stream_manager *u = (pa_stream_manager *)userdata; const char *path, *interface, *member; pa_assert(c); -- 2.7.4 From f7bc5b411064012739f3944ee98e96b1c676a0f8 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Thu, 29 Oct 2020 17:51:05 +0900 Subject: [PATCH 14/16] Fix various improper memory handling bugs - memory leaks due to missing message unref - memory leaks due to missing dbus string array free. - potential memory corruption due to passing different size of data type. - use-after-free of string retrieved by dbus_message_iter_get_basic() - use duplicated string for strtok_r() [Version] 13.0.37 [Issue Type] Bug Change-Id: I6dea62168cef2fd1387f1e1a3ffc37eb2fe47fa5 --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/device-manager-dbus.c | 17 +++++--- src/stream-manager-dbus.c | 72 +++++++++++++++++++-------------- src/subscribe-observer.c | 2 +- src/tizen-device.c | 18 ++++++--- 5 files changed, 67 insertions(+), 44 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 9f5b1f7..7c7715c 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: 13.0.36 +Version: 13.0.37 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/device-manager-dbus.c b/src/device-manager-dbus.c index 52e87e1..2bc5dbd 100644 --- a/src/device-manager-dbus.c +++ b/src/device-manager-dbus.c @@ -481,7 +481,7 @@ static int handle_bluez_headset_property_changed(DBusConnection *c, DBusMessage return -1; } handle_device_status_changed(dm, DEVICE_TYPE_BT_SCO, name, dbus_message_get_path(s), detected); - + pa_xfree(name); } else if (pa_safe_streq(property_name, "Playing")) { pa_tz_device *device; pa_log_info("SCO Playing : %d", value); @@ -639,6 +639,7 @@ static int method_call_bt_get_name(DBusConnection *conn, const char *device_path DBusMessage *msg, *reply; DBusMessageIter reply_iter, variant_iter; DBusError err; + const char *_name; pa_assert(conn); pa_assert(device_path); @@ -654,23 +655,27 @@ static int method_call_bt_get_name(DBusConnection *conn, const char *device_path DBUS_TYPE_INVALID)); dbus_error_init(&err); - if (!(reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err))) { + + reply = dbus_connection_send_with_reply_and_block(conn, msg, DBUS_TIMEOUT_USE_DEFAULT, &err); + dbus_message_unref(msg); + if (!reply) { pa_log_error("Failed to method call %s.%s, %s", DBUS_INTERFACE_BLUEZ_DEVICE, "Get", err.message); dbus_error_free(&err); return -1; } - dbus_message_iter_init(reply, &reply_iter); + dbus_message_iter_init(reply, &reply_iter); if (dbus_message_iter_get_arg_type(&reply_iter) != DBUS_TYPE_VARIANT) { pa_log_error("Cannot get reply argument"); return -1; } - dbus_message_iter_recurse(&reply_iter, &variant_iter); + dbus_message_iter_recurse(&reply_iter, &variant_iter); if (dbus_message_iter_get_arg_type(&variant_iter) == DBUS_TYPE_STRING) { - dbus_message_iter_get_basic(&variant_iter, name); + dbus_message_iter_get_basic(&variant_iter, &_name); + *name = pa_xstrdup(_name); } dbus_message_unref(reply); @@ -1666,7 +1671,7 @@ static void fill_signal_msg_with_device(const char *description, DBusMessageIter void send_device_connection_changed_signal(uint32_t event_id, pa_tz_device *device, bool connected, pa_device_manager *dm) { DBusMessage *signal_msg; DBusMessageIter msg_iter; - dbus_bool_t _connected = connected; + dbus_bool_t _connected = (dbus_bool_t)connected; pa_assert(device); pa_assert(dm); diff --git a/src/stream-manager-dbus.c b/src/stream-manager-dbus.c index d5c87b3..d81d157 100644 --- a/src/stream-manager-dbus.c +++ b/src/stream-manager-dbus.c @@ -1717,6 +1717,7 @@ static int32_t parse_call_parameters(const char *parameters, char *call_type, ch const char delimiter[] = ";"; char *token, *ptr = NULL; char key[32] = ""; + char *_parameters = NULL; pa_assert(parameters); pa_assert(call_type); @@ -1725,39 +1726,44 @@ static int32_t parse_call_parameters(const char *parameters, char *call_type, ch pa_log_info("parameters[%s]", parameters); - /*Reset the call parameters*/ + _parameters = pa_xstrdup(parameters); + if (!_parameters) { + pa_log_error("string duplication error!"); + return -1; + } + + /* Reset the call parameters */ memset(call_type, 0, MAX_CALL_PARAM_SIZE); memset(call_domain, 0, MAX_CALL_PARAM_SIZE); memset(network_band, 0, MAX_CALL_PARAM_SIZE); - if (parameters) { - token = strtok_r((char *)parameters, delimiter, &ptr); - while (token) { - char *delimiter_ptr = NULL; - char *value = NULL; - - delimiter_ptr = strstr(token, "="); - if (!delimiter_ptr) { - token = strtok_r(NULL, delimiter, &ptr); - continue; - } - strncpy(key, token, delimiter_ptr - token); - value = delimiter_ptr + 1; - pa_log_debug("key(%s), value(%s)", key, value); - if (!strncmp(key, "call-type", strlen("call-type"))) - pa_strlcpy(call_type, value, MAX_CALL_PARAM_SIZE); - else if (!strncmp(key, "call-domain", strlen("call-domain"))) - pa_strlcpy(call_domain, value, MAX_CALL_PARAM_SIZE); - else if (!strncmp(key, "network-band", strlen("network-band"))) - pa_strlcpy(network_band, value, MAX_CALL_PARAM_SIZE); - else - pa_log_warn("not supported key(%s)", key); + token = strtok_r(_parameters, delimiter, &ptr); + while (token) { + char *delimiter_ptr = NULL; + char *value = NULL; + delimiter_ptr = strstr(token, "="); + if (!delimiter_ptr) { token = strtok_r(NULL, delimiter, &ptr); - memset(key, 0, sizeof(key)); + continue; } - pa_log_info("call-type[%s], call-domain[%s], network-band[%s]", call_type, call_domain, network_band); + strncpy(key, token, delimiter_ptr - token); + value = delimiter_ptr + 1; + pa_log_debug("key(%s), value(%s)", key, value); + if (!strncmp(key, "call-type", strlen("call-type"))) + pa_strlcpy(call_type, value, MAX_CALL_PARAM_SIZE); + else if (!strncmp(key, "call-domain", strlen("call-domain"))) + pa_strlcpy(call_domain, value, MAX_CALL_PARAM_SIZE); + else if (!strncmp(key, "network-band", strlen("network-band"))) + pa_strlcpy(network_band, value, MAX_CALL_PARAM_SIZE); + else + pa_log_warn("not supported key(%s)", key); + + token = strtok_r(NULL, delimiter, &ptr); + memset(key, 0, sizeof(key)); } + pa_log_info("call-type[%s], call-domain[%s], network-band[%s]", call_type, call_domain, network_band); + pa_xfree(_parameters); return 0; } @@ -1991,7 +1997,7 @@ static bool find_the_lastest_stream(pa_stream_manager *m, stream_type_t type, co static void handle_get_pid_of_latest_stream(DBusConnection *conn, DBusMessage *msg, void *userdata) { pa_stream_manager *m = (pa_stream_manager *)userdata; const char *direction; - const char **types; + char **types; int length; stream_type_t stream_type = STREAM_SINK_INPUT; uint32_t pid = 0; @@ -2022,7 +2028,7 @@ static void handle_get_pid_of_latest_stream(DBusConnection *conn, DBusMessage *m goto finish; } - if (!find_the_lastest_stream(m, stream_type, types, length, &pid)) + if (!find_the_lastest_stream(m, stream_type, (const char **)types, length, &pid)) ret = RET_MSG_ERROR_NO_STREAM; finish: @@ -2031,6 +2037,8 @@ finish: DBUS_TYPE_INVALID)); pa_assert_se(dbus_connection_send(conn, reply, NULL)); dbus_message_unref(reply); + + dbus_free_string_array(types); } static void handle_activate_ducking(DBusConnection *conn, DBusMessage *msg, void *userdata) { @@ -2220,14 +2228,16 @@ static int dbus_launch_mdnsd(pa_stream_manager *m, DBusConnection *conn) { pa_assert_se(dbus_message_append_args(msg, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)); dbus_error_init(&err); - if (!(reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err))) { + + reply = dbus_connection_send_with_reply_and_block(conn, msg, DBUS_TIMEOUT_USE_DEFAULT, &err); + dbus_message_unref(msg); + if (!reply) { pa_log_error("Failed to method call : %s", err.message); dbus_error_free(&err); return -1; } dbus_message_unref(reply); - pa_log_info("success"); return 0; @@ -2523,7 +2533,7 @@ void send_remote_found_signal(DBusConnection *conn, int type, bool connected, un const char *name, const char *description) { DBusMessage *signal_msg; DBusMessageIter msg_iter; - dbus_bool_t c = (dbus_bool_t)connected; + dbus_bool_t _connected = (dbus_bool_t)connected; pa_assert(conn); @@ -2539,7 +2549,7 @@ void send_remote_found_signal(DBusConnection *conn, int type, bool connected, un dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_INT32, &type); dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_UINT32, &index); - dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_BOOLEAN, &c); + dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_BOOLEAN, &_connected); dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_STRING, &name); dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_STRING, &description); diff --git a/src/subscribe-observer.c b/src/subscribe-observer.c index a8ec66a..b6e7d70 100644 --- a/src/subscribe-observer.c +++ b/src/subscribe-observer.c @@ -193,7 +193,7 @@ static int get_sender_pid(DBusConnection *c, DBusMessage *got_msg, uint32_t *_se DBUS_TYPE_INVALID)); dbus_error_init(&err); - if (!(reply = dbus_connection_send_with_reply_and_block(c, msg, -1, &err))) { + if (!(reply = dbus_connection_send_with_reply_and_block(c, msg, DBUS_TIMEOUT_USE_DEFAULT, &err))) { pa_log_error("Failed to method call %s.%s, %s", intf, method, err.message); dbus_error_free(&err); goto fail; diff --git a/src/tizen-device.c b/src/tizen-device.c index 4f90d45..996098a 100644 --- a/src/tizen-device.c +++ b/src/tizen-device.c @@ -836,6 +836,7 @@ static int method_call_bt_sco_enable_pcm(pa_dbus_connection *conn, bool enable) DBusMessage *msg, *reply; DBusError err; const char *method = "SetVoiceDial"; + dbus_bool_t _enable = (dbus_bool_t)enable; pa_assert(conn); @@ -844,9 +845,12 @@ static int method_call_bt_sco_enable_pcm(pa_dbus_connection *conn, bool enable) return -1; } + pa_assert_se(dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &_enable, DBUS_TYPE_INVALID)); + dbus_error_init(&err); - pa_assert_se(dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &enable, DBUS_TYPE_INVALID)); - if (!(reply = dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(conn), msg, -1, &err))) { + reply = dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(conn), msg, DBUS_TIMEOUT_USE_DEFAULT, &err); + dbus_message_unref(msg); + if (!reply) { pa_log_error("Failed to method call %s.%s, %s", DBUS_INTERFACE_HFP_AGENT, method, err.message); dbus_error_free(&err); return -1; @@ -870,7 +874,9 @@ static int method_call_bt_sco(pa_dbus_connection *conn, bool onoff) { } dbus_error_init(&err); - if (!(reply = dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(conn), msg, -1, &err))) { + reply = dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(conn), msg, DBUS_TIMEOUT_USE_DEFAULT, &err); + dbus_message_unref(msg); + if (!reply) { pa_log_error("Failed to method call %s.%s, %s", DBUS_INTERFACE_HFP_AGENT, method, err.message); dbus_error_free(&err); return -1; @@ -900,7 +906,9 @@ static int method_call_bt_sco_get_property(pa_dbus_connection *conn, bool *is_wi } dbus_error_init(&err); - if (!(reply = dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(conn), msg, -1, &err))) { + reply = dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(conn), msg, DBUS_TIMEOUT_USE_DEFAULT, &err); + dbus_message_unref(msg); + if (!reply) { pa_log_error("Failed to method call %s.%s, %s", DBUS_INTERFACE_HFP_AGENT, "GetProperties", err.message); dbus_error_free(&err); return -1; @@ -936,7 +944,7 @@ static int method_call_bt_sco_get_property(pa_dbus_connection *conn, bool *is_wi if (dbus_message_iter_get_arg_type(&dict_entry_val) != DBUS_TYPE_BOOLEAN) continue; dbus_message_iter_get_basic(&dict_entry_val, &nrec); - pa_log_debug("nrec= [%d]", nrec); + pa_log_debug("nrec = [%d]", nrec); *is_nrec = nrec; } -- 2.7.4 From 80f842ad723832fd4acdb2fc73fedeb16c806227 Mon Sep 17 00:00:00 2001 From: Jaechul Lee Date: Wed, 4 Nov 2020 14:20:36 +0900 Subject: [PATCH 15/16] Add null-sink argument norewinds=1 null-sink takes almost 2 seconds when starting to play sound. [Version] 13.0.38 [Issue Type] Improvement Change-Id: If53a67c1f822f032f8f3590566b4eaa3b6265d7c Signed-off-by: Jaechul Lee --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/module-tizenaudio-policy.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 7c7715c..6178a05 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: 13.0.37 +Version: 13.0.38 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/module-tizenaudio-policy.c b/src/module-tizenaudio-policy.c index 2ba8198..f1563aa 100644 --- a/src/module-tizenaudio-policy.c +++ b/src/module-tizenaudio-policy.c @@ -1814,7 +1814,7 @@ int pa__init(pa_module *m) u->stream_manager = pa_stream_manager_get(u->core); /* load null sink/source */ - args = pa_sprintf_malloc("sink_name=%s", SINK_NAME_NULL); + args = pa_sprintf_malloc("sink_name=%s norewinds=1", SINK_NAME_NULL); if (pa_module_load(&u->module_null_sink, u->core, MODULE_NULL_SINK, args)) pa_log_error("failed to load module-null-sink"); pa_xfree(args); -- 2.7.4 From e65d41959c8558998c0093d892bddc6b2dfd65f3 Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Thu, 19 Nov 2020 15:37:20 +0900 Subject: [PATCH 16/16] stream-manager: Invoke ramp finish hook when ducking stream is corked If a user corks a stream that ducking is in progress, it can not get a ramp finish callback from the pulseaudio core. It leads to invalid state of the stream ducking handle, therefore it is fixed to trigger the callback forcedly when this situation happens. [Version] 13.0.39 [Issue Type] Bug fix Change-Id: Icbe7d4ce2d70fcbfbba9afb2555a38308df18349 Signed-off-by: Sangchul Lee --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/stream-manager.c | 31 ++++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 6178a05..ea1c478 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: 13.0.38 +Version: 13.0.39 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/stream-manager.c b/src/stream-manager.c index 4507a71..4c12613 100644 --- a/src/stream-manager.c +++ b/src/stream-manager.c @@ -2416,8 +2416,8 @@ static void remove_sink_input_from_muted_streams(pa_stream_manager *m, pa_sink_i pa_idxset_remove_by_data(streams, i, NULL); } -/* Remove the sink-input from ducking streams */ -static void remove_sink_input_from_ducking_streams(pa_stream_manager *m, pa_sink_input *i) { +/* It can be utilized when it requires to invoke the ramp finish hook forcedly */ +static stream_ducking* fire_ramp_finish_hook_when_ducking_or_unducking_state(pa_stream_manager *m, pa_sink_input *i) { uint32_t idx = 0; stream_ducking *sd = NULL; void *stream = NULL; @@ -2429,17 +2429,29 @@ static void remove_sink_input_from_ducking_streams(pa_stream_manager *m, pa_sink PA_IDXSET_FOREACH(stream, sd->idx_ducking_streams, idx) { if (stream != i) continue; - if (sd->state == STREAM_DUCKING_STATE_DUCKING || - sd->state == STREAM_DUCKING_STATE_UNDUCKING) + sd->state == STREAM_DUCKING_STATE_UNDUCKING) { + pa_log_debug("stream(%p, index:%u) ducking state[%s]", + i, i->index, sd->state == STREAM_DUCKING_STATE_DUCKING ? "DUCKING" : "UNDUCKING"); pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_RAMP_FINISH], i); + } + return sd; + } + } - pa_log_error("remove stream(idx:%u,%p) from idx_ducking_streams, trigger_index(%u)", - i->index, i, sd->trigger_index); - pa_idxset_remove_by_data(sd->idx_ducking_streams, i, NULL); + return NULL; +} - return; - } +/* Remove the sink-input from ducking streams */ +static void remove_sink_input_from_ducking_streams(pa_stream_manager *m, pa_sink_input *i) { + stream_ducking *sd; + + pa_assert(m); + + if ((sd = fire_ramp_finish_hook_when_ducking_or_unducking_state(m, i))) { + pa_log_error("remove stream(%p, index:%u) from idx_ducking_streams, trigger_index(%u)", + i, i->index, sd->trigger_index); + pa_idxset_remove_by_data(sd->idx_ducking_streams, i, NULL); } } @@ -2537,6 +2549,7 @@ static pa_hook_result_t sink_input_state_changed_cb(pa_core *core, pa_sink_input switch (i->state) { case PA_SINK_INPUT_CORKED: process_stream(m, i, STREAM_SINK_INPUT, PROCESS_COMMAND_CHANGE_ROUTE_BY_STATE_CHANGED_CORKED, false); + fire_ramp_finish_hook_when_ducking_or_unducking_state(m, i); break; case PA_SINK_INPUT_RUNNING: process_stream(m, i, STREAM_SINK_INPUT, PROCESS_COMMAND_CHANGE_ROUTE_BY_STATE_CHANGED_RUNNING, false); -- 2.7.4