From 2114b2b49894bb46358229a1b814ec7447e56efa Mon Sep 17 00:00:00 2001 From: Jaechul Lee Date: Thu, 12 Aug 2021 14:45:46 +0900 Subject: [PATCH 01/16] device-manager: Support to load sink2/source2 pulseaudio tries to load tizenaudio-sink2/source2 instead of tizenaudio-sink/source if 'tizen2' keyword is found in device-map file. [Version] 13.0.71 [Issue Type] Improvement Change-Id: Ie9c67f4888fb628961811d906e4d6c396700b14e Signed-off-by: Jaechul Lee --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/device-manager.c | 75 ++++++++++++++++++++++++++------- 2 files changed, 61 insertions(+), 16 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 9935f28..3445223 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.70 +Version: 13.0.71 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/device-manager.c b/src/device-manager.c index a1a717e..c5491e0 100644 --- a/src/device-manager.c +++ b/src/device-manager.c @@ -58,6 +58,7 @@ #define DEVICE_MAP_FILE PA_DEFAULT_CONFIG_DIR"/device-map.json" #define DEVICE_STR_MAX 40 #define DEVICE_DIRECTION_MAX 3 +#define DEVICE_MODULE_STRING_MAX 256 #define DEVICE_PARAM_STRING_MAX 150 #define DEVICE_AVAIL_COND_NUM_MAX 2 #define DEVICE_AVAIL_COND_STR_MAX 6 @@ -424,16 +425,18 @@ static bool pulse_device_is_tunnel(pa_object *pdevice) { } static bool pulse_device_is_tizenaudio(pa_object *pdevice) { + char name[DEVICE_NAME_MAX]; + if (!pdevice) return false; - if (pa_sink_isinstance(pdevice)) { - pa_sink *sink = PA_SINK(pdevice); - return pa_safe_streq(sink->module->name, "module-tizenaudio-sink"); - } else { - pa_source *source = PA_SOURCE(pdevice); - return pa_safe_streq(source->module->name, "module-tizenaudio-source"); - } + if (!module_table[DM_DEVICE_CLASS_TIZEN].custom_device_get_func) + return false; + + if (module_table[DM_DEVICE_CLASS_TIZEN].custom_device_get_func(pdevice, name)) + return false; + + return true; } static bool pulse_device_is_usb(pa_object *pdevice) { @@ -572,11 +575,40 @@ static bool pulse_device_is_monitor(pa_object *pdevice) { return false; } -static const char* device_class_get_module_name(dm_device_class_t device_class, bool is_sink) { +static char* device_class_get_module_name(dm_device_class_t device_class, const char *device_string, bool is_sink) { + char version[8] = ""; + char module_name[DEVICE_MODULE_STRING_MAX]; + const char *_module_name; + if (device_class >= DM_DEVICE_CLASS_MAX) return NULL; - return module_table[device_class].module_name[is_sink]; + if (!device_string) + return NULL; + + _module_name = module_table[device_class].module_name[is_sink]; + + /* supports tizen[2-9] keyword in device-map */ + if (device_class == DM_DEVICE_CLASS_TIZEN) { + int v; + char *class; + const char *state = NULL, *prefix = "tizen"; + + class = pa_split(device_string, ":", &state); + + if (!pa_streq(class, prefix)) { + if (!pa_atoi(class + strlen(prefix), &v)) + snprintf(version, sizeof(version), "%d", v); + else + pa_log_warn("failed to get a version from class(%s)", class); + } + + pa_xfree(class); + } + + snprintf(module_name, DEVICE_MODULE_STRING_MAX, "%s%s", _module_name, version); + + return pa_xstrdup(module_name); } static device_type_info* _device_manager_get_type_info(pa_idxset *type_infos, const char *type, const char *role) { @@ -916,7 +948,8 @@ static int pulse_device_get_alsa_device_name(pa_object *pdevice, char *device_na static int pulse_device_get_tizen_device_name(pa_object *pdevice, char *device_name) { pa_proplist *prop; - const char *card, *device; + const char *card, *device, *version; + char class[8] = "tizen"; prop = pulse_device_get_proplist(pdevice); @@ -924,12 +957,17 @@ static int pulse_device_get_tizen_device_name(pa_object *pdevice, char *device_n pa_log_error("failed to get property 'tizen.card'"); return -1; } + if (!(device = pa_proplist_gets(prop, "tizen.device"))) { pa_log_error("failed to get property 'tizen.device'"); return -1; } - snprintf(device_name, DEVICE_NAME_MAX, "tizen:%s,%s", card, device); + if ((version = pa_proplist_gets(prop, "tizen.version"))) + snprintf(class, sizeof(class), "tizen%s", version); + + snprintf(device_name, DEVICE_NAME_MAX, "%s:%s,%s", class, card, device); + return 0; } @@ -1844,7 +1882,7 @@ static pa_hook_result_t sink_proplist_changed(pa_core *core, pa_sink *sink, pa_d Build params for load sink or source, and load it. */ static void* load_module(pa_core *c, bool is_sink, const char *device_string, const char *device_params, const char *device_role) { - const char *module_name; + char *module_name; pa_module *module; pa_sink *sink; pa_source *source; @@ -1865,7 +1903,7 @@ static void* load_module(pa_core *c, bool is_sink, const char *device_string, co } pa_log_info("device class : %d", device_class); - if (!(module_name = device_class_get_module_name(device_class, is_sink))) { + if (!(module_name = device_class_get_module_name(device_class, device_string, is_sink))) { pa_log_error("Get proper module name to load failed"); return NULL; } @@ -1873,16 +1911,19 @@ static void* load_module(pa_core *c, bool is_sink, const char *device_string, co if (build_params_to_load_module(device_string, device_params, device_class, full_params) < 0) { pa_log_error("build param to load module failed"); - return NULL; + goto exit; } pa_log_info("argument : %s", full_params); if (pa_module_load(&module, c, module_name, full_params)) { pa_log_error("Load module with name '%s' argument '%s' failed", module_name, full_params); - return NULL; + goto exit; } pa_log_info("module loaded : %s %u with '%s'", module->name, module->index, module->argument); + pa_xfree(module_name); + module_name = NULL; + if (is_sink) { PA_IDXSET_FOREACH(sink, c->sinks, device_idx) { if (sink->module == module) { @@ -1905,6 +1946,10 @@ static void* load_module(pa_core *c, bool is_sink, const char *device_string, co pa_log_warn("Failed to find matching %s after load module", is_sink ? "sink" : "source"); +exit: + if (module_name) + pa_xfree(module_name); + return NULL; } -- 2.7.4 From f3c72b7ab94bc6dd0eeb0b90eae8fdb793dadc89 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Mon, 15 Mar 2021 16:45:23 +0900 Subject: [PATCH 02/16] support external bt-sco device for tv [Version] 13.0.71 [Issue Type] Improvement Change-Id: Ic9d3d00c5a48e319203468550efa5fb40f6f243d --- packaging/pulseaudio-modules-tizen.spec | 4 +- src/device-manager-dbus.c | 10 +++- src/device-manager.c | 82 +++++++++++++++++++++++++++++++++ src/module-tizenaudio-policy.c | 47 +++++++++++++++++++ src/tizen-device.c | 6 +++ src/tizen-device.h | 4 ++ 6 files changed, 150 insertions(+), 3 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 9935f28..741064d 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.70 +Version: 13.0.71 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ @@ -43,6 +43,8 @@ PulseAudio module-acm-sink for sending PCM data to ACM core. export CFLAGS="%{optflags} -fno-strict-aliasing -D__TIZEN__ -DSYSCONFDIR=\\\"%{_hal_sysconfdir}\\\" " %if "%{tizen_profile_name}" == "tv" export CFLAGS+=" -DTIZEN_TV"; +%else + export CFLAGS+=" -D__TIZEN_INTERNAL_BT_SCO__" %endif export LD_AS_NEEDED=0 diff --git a/src/device-manager-dbus.c b/src/device-manager-dbus.c index ccab821..359d4f4 100644 --- a/src/device-manager-dbus.c +++ b/src/device-manager-dbus.c @@ -219,7 +219,9 @@ static void handle_dump_device_list(DBusConnection *conn, DBusMessage *msg, void static void handle_test_device_status_change(DBusConnection *conn, DBusMessage *msg, void *userdata); static void handle_set_acm_mode(DBusConnection *conn, DBusMessage *msg, void *userdata); +#ifdef __TIZEN_INTERNAL_BT_SCO__ static int method_call_bt_get_name(DBusConnection *conn, const char *device_path, char **name); +#endif enum method_handler_index { METHOD_HANDLER_GET_CONNECTED_DEVICE_LIST, @@ -431,6 +433,7 @@ static int _translate_external_value(const char *type, int value, device_detecte return 0; } +#ifdef __TIZEN_INTERNAL_BT_SCO__ static int handle_bluez_headset_property_changed(DBusConnection *c, DBusMessage *s, pa_device_manager *dm) { DBusMessageIter msg_iter, variant_iter; char *property_name; @@ -504,6 +507,7 @@ static int handle_bluez_headset_property_changed(DBusConnection *c, DBusMessage return 0; } +#endif /* __TIZEN_INTERNAL_BT_SCO__ */ static DBusHandlerResult dbus_filter_device_detect_handler(DBusConnection *c, DBusMessage *s, void *userdata) { DBusError error; @@ -550,11 +554,11 @@ static DBusHandlerResult dbus_filter_device_detect_handler(DBusConnection *c, DB goto fail; } handle_device_status_changed(dm, DEVICE_TYPE_FORWARDING, NULL, NULL, detected); - +#ifdef __TIZEN_INTERNAL_BT_SCO__ } else if (dbus_message_is_signal(s, DBUS_INTERFACE_BLUEZ_HEADSET, "PropertyChanged")) { if (handle_bluez_headset_property_changed(c, s, dm) < 0) goto fail; - +#endif } else { pa_log_debug("Unknown message, not handle it"); dbus_error_free(&error); @@ -635,6 +639,7 @@ static bool device_is_match_with_mask(pa_tz_device *device, int mask) { device_is_match_type(device, mask & DEVICE_TYPE_FLAGS)); } +#ifdef __TIZEN_INTERNAL_BT_SCO__ static int method_call_bt_get_name(DBusConnection *conn, const char *device_path, char **name) { const char *intf = DBUS_INTERFACE_BLUEZ_DEVICE, *prop = "Alias"; DBusMessage *msg, *reply; @@ -682,6 +687,7 @@ static int method_call_bt_get_name(DBusConnection *conn, const char *device_path dbus_message_unref(reply); return 0; } +#endif /* __TIZEN_INTERNAL_BT_SCO__ */ static void handle_get_connected_device_list(DBusConnection *conn, DBusMessage *msg, void *userdata) { pa_device_manager *dm = (pa_device_manager *)userdata; diff --git a/src/device-manager.c b/src/device-manager.c index a1a717e..114f28f 100644 --- a/src/device-manager.c +++ b/src/device-manager.c @@ -87,6 +87,9 @@ #define DEVICE_API_RAOP "raop" #define DEVICE_API_TUNNEL "tunnel" #define DEVICE_API_RTSP "rtsp" +#ifndef __TIZEN_INTERNAL_BT_SCO__ +#define DEVICE_API_BTSCO "btsco" +#endif #define DEVICE_BUS_USB "usb" #define DEVICE_CLASS_SOUND "sound" #define DEVICE_CLASS_MONITOR "monitor" @@ -480,6 +483,17 @@ static bool pulse_device_is_rtsp(pa_object *pdevice) { return pa_safe_streq(pa_proplist_gets(prop, PA_PROP_DEVICE_API), DEVICE_API_RTSP); } +#ifndef __TIZEN_INTERNAL_BT_SCO__ +static bool pulse_device_is_btsco(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_BTSCO); +} +#endif + static const char* pulse_device_get_device_string_removed_argument(pa_object *pdevice) { static char removed_param[DEVICE_PARAM_STRING_MAX] = {0,}; char *device_string_p = NULL; @@ -1156,6 +1170,10 @@ static const char* pulse_device_get_system_id(pa_object *pdevice) { return pa_proplist_gets(prop, PA_PROP_DEVICE_DESCRIPTION); else if (pulse_device_is_rtsp(pdevice)) return pa_proplist_gets(prop, PA_PROP_DEVICE_DESCRIPTION); +#ifndef __TIZEN_INTERNAL_BT_SCO__ + else if (pulse_device_is_btsco(pdevice)) + return pa_proplist_gets(prop, PA_PROP_DEVICE_DESCRIPTION); +#endif else return NULL; } @@ -1578,6 +1596,50 @@ static void handle_rtsp_pulse_device(pa_object *pdevice, bool is_loaded, pa_devi } } +#ifndef __TIZEN_INTERNAL_BT_SCO__ +static void handle_external_btsco_pulse_device(pa_object *pdevice, bool is_loaded, pa_device_manager *dm) { + const char *name, *system_id; + dm_device_direction_t direction; + pa_tz_device *device; + + pa_assert(pdevice); + pa_assert(dm); + + pa_log_info("Handle btsco pulse device"); + + system_id = pulse_device_get_system_id(pdevice); + direction = pulse_device_get_direction(pdevice); + + if (is_loaded) { + pa_tz_device_new_data data; + pa_proplist *prop; + + prop = pulse_device_get_proplist(pdevice); + name = pa_proplist_gets(prop, PA_PROP_DEVICE_DESCRIPTION); + + pa_tz_device_new_data_init(&data, dm->device_list, dm->comm, NULL); + pa_tz_device_new_data_set_type(&data, DEVICE_TYPE_BT_SCO); + pa_tz_device_new_data_set_name(&data, name); + pa_tz_device_new_data_set_direction(&data, direction); + pa_tz_device_new_data_set_system_id(&data, system_id); + pa_tz_device_new_data_set_use_internal_codec(&data, false); + if (direction == DM_DEVICE_DIRECTION_OUT) { + pa_tz_device_new_data_add_sink(&data, DEVICE_ROLE_NORMAL, PA_SINK(pdevice)); + } else { + pa_tz_device_new_data_add_source(&data, DEVICE_ROLE_NORMAL, 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_BT_SCO, NULL, system_id))) + pa_log_warn("Can't get btsco device for %s", system_id); + else + pa_tz_device_free(device); + } +} +#endif /* __TIZEN_INTERNAL_BT_SCO__ */ + static void handle_internal_pulse_device(pa_object *pdevice, bool is_loaded, pa_device_manager *dm) { pa_tz_device *device; struct composite_type *ctype; @@ -1661,6 +1723,12 @@ static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, pa_dev pulse_device_set_use_internal_codec(PA_OBJECT(sink), true); handle_internal_pulse_device(PA_OBJECT(sink), true, dm); return PA_HOOK_OK; +#ifndef __TIZEN_INTERNAL_BT_SCO__ + } else if (pulse_device_is_btsco(PA_OBJECT(sink))) { + pulse_device_set_use_internal_codec(PA_OBJECT(sink), false); + handle_external_btsco_pulse_device(PA_OBJECT(sink), true, dm); + return PA_HOOK_OK; +#endif } else { pa_log_debug("Don't care this sink"); } @@ -1705,6 +1773,11 @@ static pa_hook_result_t sink_unlink_hook_callback(pa_core *c, pa_sink *sink, pa_ } else if (pulse_device_is_alsa(PA_OBJECT(sink)) || pulse_device_is_tizenaudio(PA_OBJECT(sink))) { handle_internal_pulse_device(PA_OBJECT(sink), false, dm); return PA_HOOK_OK; +#ifndef __TIZEN_INTERNAL_BT_SCO__ + } else if (pulse_device_is_btsco(PA_OBJECT(sink))) { + handle_external_btsco_pulse_device(PA_OBJECT(sink), false, dm); + return PA_HOOK_OK; +#endif } else { pa_log_debug("Don't care this sink"); } @@ -1738,6 +1811,11 @@ static pa_hook_result_t source_put_hook_callback(pa_core *c, pa_source *source, pulse_device_set_use_internal_codec(PA_OBJECT(source), false); handle_rtsp_pulse_device(PA_OBJECT(source), true, dm); return PA_HOOK_OK; +#ifndef __TIZEN_INTERNAL_BT_SCO__ + } else if (pulse_device_is_btsco(PA_OBJECT(source))) { + pulse_device_set_use_internal_codec(PA_OBJECT(source), false); + handle_external_btsco_pulse_device(PA_OBJECT(source), true, dm); +#endif } else { pa_log_debug("Don't care this source"); } @@ -1778,7 +1856,11 @@ static pa_hook_result_t source_unlink_hook_callback(pa_core *c, pa_source *sourc return PA_HOOK_OK; } else if (pulse_device_is_rtsp(PA_OBJECT(source))) { handle_rtsp_pulse_device(PA_OBJECT(source), false, dm); +#ifndef __TIZEN_INTERNAL_BT_SCO__ + } else if (pulse_device_is_btsco(PA_OBJECT(source))) { + handle_external_btsco_pulse_device(PA_OBJECT(source), false, dm); return PA_HOOK_OK; +#endif } else { pa_log_debug("Don't care this source"); } diff --git a/src/module-tizenaudio-policy.c b/src/module-tizenaudio-policy.c index 2efbc89..44b1894 100644 --- a/src/module-tizenaudio-policy.c +++ b/src/module-tizenaudio-policy.c @@ -85,7 +85,9 @@ struct userdata; #define LOOPBACK_DEFAULT_LATENCY_MSEC 40 #define LOOPBACK_DEFAULT_ADJUST_SEC 3 +#ifdef __TIZEN_INTERNAL_BT_SCO__ #define TIMED_BT_SCO_CLOSE_USEC 3000000 +#endif /* Macros */ #define CONVERT_TO_HAL_DIRECTION(stream_type) \ @@ -183,7 +185,9 @@ struct userdata { int32_t latency_msec; int32_t adjust_sec; } loopback_args; +#ifdef __TIZEN_INTERNAL_BT_SCO__ pa_time_event *time_event_bt_sco_close; +#endif }; static void __load_dump_config(struct userdata *u) @@ -208,6 +212,7 @@ static void __load_dump_config(struct userdata *u) iniparser_freedict(dict); } +#ifdef __TIZEN_INTERNAL_BT_SCO__ /* threre is only one sco connected device */ static pa_tz_device* _get_sco_connected_device(pa_device_manager *dm) { pa_idxset *device_list; @@ -450,6 +455,7 @@ static void update_bt_sco_option(struct userdata *u, const char* role) { pa_log_warn("Failed to get property for wideband / nrec...."); } } +#endif static void update_loopback_module_args(struct userdata* u, int32_t parent_id, pa_sink *sink, pa_source *source) { @@ -690,6 +696,7 @@ static bool skip_device(const char *stream_role, const char *device_type) return false; } +#ifdef __TIZEN_INTERNAL_BT_SCO__ static bool skip_bt_sco_device(struct userdata *u, const char *stream_role, const char *device_type) { pa_assert(u); pa_assert(stream_role); @@ -719,6 +726,7 @@ static bool skip_bt_sco_device(struct userdata *u, const char *stream_role, cons return false; } +#endif static bool is_supported_stream_role_for_usb(const char *role) { pa_assert(role); @@ -819,8 +827,10 @@ static void select_device_by_auto_or_auto_all_routing(struct userdata *u, pa_str if (!pa_safe_streq(device_type, dm_device_type) || !IS_AVAILABLE_DIRECTION(data->stream_type, dm_device_direction)) continue; pa_log_info(" ** found a matched device: type[%-16s], direction[0x%x]", dm_device_type, dm_device_direction); +#ifdef __TIZEN_INTERNAL_BT_SCO__ if (skip_bt_sco_device(u, data->stream_role, dm_device_type)) continue; +#endif if (skip_usb_device(data->stream_role, device)) continue; @@ -891,8 +901,10 @@ static void select_device_by_auto_last_connected_routing(struct userdata *u, pa_ dm_device_type, dm_device_direction, dm_device_id, creation_time); if (!pa_safe_streq(device_type, dm_device_type) || !IS_AVAILABLE_DIRECTION(data->stream_type, dm_device_direction)) continue; +#ifdef __TIZEN_INTERNAL_BT_SCO__ if (skip_bt_sco_device(u, data->stream_role, dm_device_type)) continue; +#endif if (skip_usb_device(data->stream_role, device)) continue; @@ -1137,8 +1149,10 @@ static void reset_route(struct userdata *u, stream_type_t stream_type) { pa_assert(u); +#ifdef __TIZEN_INTERNAL_BT_SCO__ /* update BT SCO: close */ update_bt_sco_state(u, false, true, NULL); +#endif /* unload combine sink */ if (stream_type == STREAM_SINK_INPUT) { @@ -1291,9 +1305,15 @@ static void fill_device_info(hal_route_info *route_info, const char *type, uint3 route_info->num_of_devices -1, type, direction, id); } +#ifdef __TIZEN_INTERNAL_BT_SCO__ static pa_hook_result_t update_combine_sink_and_bt_sco(struct userdata *u, pa_stream_manager_hook_data_for_route *data, pa_tz_device *device, const char *stream_role, const char *dm_device_type, pa_sink **combine_sink_arg1, pa_sink **combine_sink_arg2) { +#else +static pa_hook_result_t update_combine_sink(struct userdata *u, pa_stream_manager_hook_data_for_route *data, + pa_tz_device *device, const char *stream_role, const char *dm_device_type, + pa_sink **combine_sink_arg1, pa_sink **combine_sink_arg2) { +#endif pa_sink *sink = NULL; pa_assert(u); @@ -1309,6 +1329,7 @@ static pa_hook_result_t update_combine_sink_and_bt_sco(struct userdata *u, pa_st else pa_log_error("[ROUTE][AUTO] could not get sink"); } +#ifdef __TIZEN_INTERNAL_BT_SCO__ if (pa_safe_streq(dm_device_type, DEVICE_TYPE_BT_SCO)) { if (IS_ROLE_AVAILABLE_BT_SCO_OPEN(stream_role)) { if (update_bt_sco_state(u, true, false, stream_role)) { @@ -1320,6 +1341,7 @@ static pa_hook_result_t update_combine_sink_and_bt_sco(struct userdata *u, pa_st return PA_HOOK_OK; } update_bt_sco_state(u, false, false, NULL); +#endif break; } case STREAM_ROUTE_TYPE_AUTO_ALL: { @@ -1328,7 +1350,9 @@ static pa_hook_result_t update_combine_sink_and_bt_sco(struct userdata *u, pa_st void *s = NULL; stream_route_type_t route_type; +#ifdef __TIZEN_INTERNAL_BT_SCO__ update_bt_sco_state(u, false, false, NULL); +#endif /* find the proper sink/source */ /* currently, we support two sinks for combining */ @@ -1412,8 +1436,10 @@ static int32_t update_route_by_preemptive_device(struct userdata *u, pa_stream_m /* if it needs to skip it, keep going to next device for proper UCM setting */ if (skip_device(data->stream_role, dm_device_type)) return -1; +#ifdef __TIZEN_INTERNAL_BT_SCO__ if (skip_bt_sco_device(u, data->stream_role, dm_device_type)) return -1; +#endif fill_device_info(route_info, dm_device_type, CONVERT_TO_HAL_DIRECTION(data->stream_type), dm_device_id); return 0; } @@ -1466,8 +1492,10 @@ static pa_hook_result_t handle_auto_or_auto_all_routing(struct userdata *u, pa_s /* if it needs to skip it, keep going to next device for proper UCM setting */ if (skip_device(data->stream_role, dm_device_type)) continue; +#ifdef __TIZEN_INTERNAL_BT_SCO__ if (skip_bt_sco_device(u, data->stream_role, dm_device_type)) continue; +#endif fill_device_info(route_info, dm_device_type, CONVERT_TO_HAL_DIRECTION(data->stream_type), dm_device_id); break; } @@ -1485,10 +1513,18 @@ update_auto_active_dev: else pa_proplist_sets(GET_STREAM_PROPLIST(data->stream, data->stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, dm_device_type); +#ifdef __TIZEN_INTERNAL_BT_SCO__ return update_combine_sink_and_bt_sco(u, data, *device, route_info->role, dm_device_type, NULL, NULL); +#else + return update_combine_sink(u, data, *device, route_info->role, dm_device_type, NULL, NULL); +#endif } else if (data->route_type == STREAM_ROUTE_TYPE_AUTO_ALL) { +#ifdef __TIZEN_INTERNAL_BT_SCO__ update_combine_sink_and_bt_sco(u, data, *device, NULL, NULL, &combine_sink_arg1, &combine_sink_arg2); +#else + update_combine_sink(u, data, *device, NULL, NULL, &combine_sink_arg1, &combine_sink_arg2); +#endif } } return PA_HOOK_OK; @@ -1539,8 +1575,12 @@ static pa_hook_result_t handle_auto_last_connected_routing(struct userdata *u, p continue; if ((use_internal_codec = pa_tz_device_is_use_internal_codec(*device))) { /* if it needs to skip it, keep going to next device for proper UCM setting */ +#ifdef __TIZEN_INTERNAL_BT_SCO__ if (skip_device(data->stream_role, dm_device_type) || skip_bt_sco_device(u, data->stream_role, dm_device_type)) +#else + if (skip_device(data->stream_role, dm_device_type)) +#endif continue; } if (!latest_device || (latest_creation_time <= creation_time)) { @@ -1582,6 +1622,7 @@ update_auto_active_dev: pa_log_error("[ROUTE][AUTO_LAST_CONN] could not get sink"); } +#ifdef __TIZEN_INTERNAL_BT_SCO__ if (pa_safe_streq(dm_device_type, DEVICE_TYPE_BT_SCO)) { if (IS_ROLE_AVAILABLE_BT_SCO_OPEN(route_info->role)) { if (update_bt_sco_state(u, true, false, route_info->role)) { @@ -1593,6 +1634,7 @@ update_auto_active_dev: } else { update_bt_sco_state(u, false, false, NULL); } +#endif /* Update device with latest_device to use be used later in this function */ *device = latest_device; @@ -1631,6 +1673,8 @@ static pa_hook_result_t handle_manual_routing(struct userdata *u, pa_stream_mana dm_device_direction = pa_tz_device_get_direction(*device); pa_log_debug(" ** found a matched device: type[%-16s], direction[0x%x]", dm_device_type, dm_device_direction); + +#ifdef __TIZEN_INTERNAL_BT_SCO__ /* Check for availability for opening Bluetooth SCO */ if (pa_safe_streq(dm_device_type, DEVICE_TYPE_BT_SCO) && IS_ROLE_AVAILABLE_BT_SCO_OPEN(route_info->role)) { /* update BT SCO: open */ @@ -1643,6 +1687,7 @@ static pa_hook_result_t handle_manual_routing(struct userdata *u, pa_stream_mana /* update BT SCO: close */ update_bt_sco_state(u, false, false, NULL); } +#endif if (IS_AVAILABLE_DIRECTION(data->stream_type, dm_device_direction)) { if ((use_internal_codec = pa_tz_device_is_use_internal_codec(*device))) @@ -1971,7 +2016,9 @@ void pa__done(pa_module *m) if (!(u = m->userdata)) return; +#ifdef __TIZEN_INTERNAL_BT_SCO__ bt_sco_close(u, false); +#endif if (u->loopback_modules) { pa_hashmap_remove_all(u->loopback_modules); diff --git a/src/tizen-device.c b/src/tizen-device.c index 996098a..cbeae10 100644 --- a/src/tizen-device.c +++ b/src/tizen-device.c @@ -145,8 +145,10 @@ static char* _device_get_info_str(pa_tz_device *device) { pa_strbuf_printf(buf, " Product ID : %04x\n", device->product_id); pa_strbuf_printf(buf, " Specified Stream role : %s\n", device->specified_stream_role); } +#ifdef __TIZEN_INTERNAL_BT_SCO__ if (device_type_is_equal(device->type, DEVICE_TYPE_BT_SCO)) pa_strbuf_printf(buf, " SCO opened : %s\n", pa_yes_no(device->sco_opened)); +#endif playback_str = get_playback_list_str(device->playback_devices); capture_str = get_capture_list_str(device->capture_devices); @@ -492,7 +494,9 @@ pa_tz_device* pa_tz_device_new(pa_tz_device_new_data *data) { device->state = DM_DEVICE_STATE_DEACTIVATED; device->creation_time = pa_rtclock_now(); device->use_internal_codec = data->use_internal_codec; +#ifdef __TIZEN_INTERNAL_BT_SCO__ device->sco_opened = false; +#endif device->is_running = false; device->specified_stream_role = pa_xstrdup("none"); @@ -832,6 +836,7 @@ pa_intset* pa_tz_device_get_stream_list(pa_tz_device *device) { return stream_id_set; } +#ifdef __TIZEN_INTERNAL_BT_SCO__ static int method_call_bt_sco_enable_pcm(pa_dbus_connection *conn, bool enable) { DBusMessage *msg, *reply; DBusError err; @@ -1081,4 +1086,5 @@ int pa_tz_device_sco_get_status(pa_tz_device *device, dm_device_bt_sco_status_t pa_log_info("BT SCO (%u) Get Status, %d", device->id, *status); return 0; } +#endif /* __TIZEN_INTERNAL_BT_SCO__ */ diff --git a/src/tizen-device.h b/src/tizen-device.h index 916a819..a7649ae 100644 --- a/src/tizen-device.h +++ b/src/tizen-device.h @@ -60,7 +60,9 @@ struct pa_tz_device { * false, if this device uses external card(bt-a2dp, usb */ bool use_internal_codec; /* If this is sco device, this can be used to */ +#ifdef __TIZEN_INTERNAL_BT_SCO__ bool sco_opened; +#endif /* Devices are contained in this list */ pa_idxset *list; @@ -153,12 +155,14 @@ bool pa_tz_device_is_use_internal_codec(pa_tz_device *device); bool pa_tz_device_is_all_suspended(pa_tz_device *device); pa_intset* pa_tz_device_get_stream_list(pa_tz_device *device); +#ifdef __TIZEN_INTERNAL_BT_SCO__ /* Only for BT SCO device */ int pa_tz_device_sco_enable_pcm(pa_tz_device *device, bool enable); int pa_tz_device_sco_open(pa_tz_device *device); int pa_tz_device_sco_close(pa_tz_device *device); int pa_tz_device_sco_get_property(pa_tz_device *device, bool *is_wide_band, bool *nrec); int pa_tz_device_sco_get_status(pa_tz_device *device, dm_device_bt_sco_status_t *status); +#endif /* Only for USB device */ int pa_tz_device_get_vendor_id(pa_tz_device *device); -- 2.7.4 From 324cb705d7953ea4f7a23c5d0ac08d1bbdd961a1 Mon Sep 17 00:00:00 2001 From: jungsup lee Date: Wed, 8 Sep 2021 13:54:40 +0900 Subject: [PATCH 03/16] device-manager-dbus: always place bt-sco device at first in device list [Version] 13.0.72 [Issue Type] Improvement Change-Id: I15efd7b12c48a3278ad64e9fdb7a2f409cf4183f --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/device-manager-dbus.c | 94 ++++++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 25 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 741064d..b58e363 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.71 +Version: 13.0.72 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/device-manager-dbus.c b/src/device-manager-dbus.c index 359d4f4..8c067af 100644 --- a/src/device-manager-dbus.c +++ b/src/device-manager-dbus.c @@ -689,35 +689,22 @@ static int method_call_bt_get_name(DBusConnection *conn, const char *device_path } #endif /* __TIZEN_INTERNAL_BT_SCO__ */ -static void handle_get_connected_device_list(DBusConnection *conn, DBusMessage *msg, void *userdata) { - pa_device_manager *dm = (pa_device_manager *)userdata; - DBusMessage *reply = NULL; - DBusMessageIter msg_iter, array_iter, device_iter; - pa_tz_device *device; - dm_device_state_t state; +static void array_iter_append(DBusMessageIter *array_iter, pa_idxset *device_list, int mask) { uint32_t device_idx; + dm_device_state_t state; dbus_int32_t device_id, direction; - int mask; char *type, *name; dbus_int32_t vendor_id, product_id; dbus_bool_t is_running; + pa_tz_device *device; + DBusMessageIter device_iter; - pa_assert(conn); - pa_assert(msg); - pa_assert(dm); - - pa_assert_se((reply = dbus_message_new_method_return(msg))); - - pa_assert_se(dbus_message_get_args(msg, NULL, - DBUS_TYPE_INT32, &mask, - DBUS_TYPE_INVALID)); - - pa_log_info("Get connected device list (mask : %d)", mask); + pa_assert(array_iter); - dbus_message_iter_init_append(reply, &msg_iter); - pa_assert_se(dbus_message_iter_open_container(&msg_iter, DBUS_TYPE_ARRAY, "(isiisiib)", &array_iter)); + if (!device_list) + return; - PA_IDXSET_FOREACH(device, dm->device_list, device_idx) { + PA_IDXSET_FOREACH(device, device_list, device_idx) { device_id = (dbus_int32_t)pa_tz_device_get_id(device); state = pa_tz_device_get_state(device); direction = pa_tz_device_get_direction(device); @@ -727,9 +714,9 @@ static void handle_get_connected_device_list(DBusConnection *conn, DBusMessage * product_id = (dbus_int32_t) pa_tz_device_get_product_id(device); product_id = (dbus_int32_t) pa_tz_device_get_product_id(device); is_running = (dbus_bool_t) pa_tz_device_is_running(device); - if (device_is_match_with_mask(device, mask)) { + if (device_is_match_with_mask(device, mask)) { simple_device_dump(PA_LOG_INFO, "[MATCH]", device_id, type, name, direction, state); - pa_assert_se(dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL, &device_iter)); + pa_assert_se(dbus_message_iter_open_container(array_iter, DBUS_TYPE_STRUCT, NULL, &device_iter)); dbus_message_iter_append_basic(&device_iter, DBUS_TYPE_INT32, &device_id); dbus_message_iter_append_basic(&device_iter, DBUS_TYPE_STRING, &type); dbus_message_iter_append_basic(&device_iter, DBUS_TYPE_INT32, &direction); @@ -738,11 +725,70 @@ static void handle_get_connected_device_list(DBusConnection *conn, DBusMessage * dbus_message_iter_append_basic(&device_iter, DBUS_TYPE_INT32, &vendor_id); dbus_message_iter_append_basic(&device_iter, DBUS_TYPE_INT32, &product_id); dbus_message_iter_append_basic(&device_iter, DBUS_TYPE_BOOLEAN, &is_running); - pa_assert_se(dbus_message_iter_close_container(&array_iter, &device_iter)); + pa_assert_se(dbus_message_iter_close_container(array_iter, &device_iter)); } else { simple_device_dump(PA_LOG_INFO, "[UNMATCH]", device_id, type, name, direction, state); } } +} + +#ifndef __TIZEN_INTERNAL_BT_SCO__ +static int include_device_filter_func(const void *d, const void *include_device_type) { + pa_tz_device *device = (pa_tz_device *)d; + + pa_assert(device); + pa_assert(include_device_type); + + return (int)pa_safe_streq(pa_tz_device_get_type(device), (const char *)include_device_type); +} + +static int exclude_device_filter_func(const void *d, const void *exclude_device_type) { + pa_tz_device *device = (pa_tz_device *)d; + + pa_assert(device); + pa_assert(exclude_device_type); + + return (int)!pa_safe_streq(pa_tz_device_get_type(device), (const char *)exclude_device_type); +} +#endif /* __TIZEN_INTERNAL_BT_SCO__ */ + +static void handle_get_connected_device_list(DBusConnection *conn, DBusMessage *msg, void *userdata) { + pa_device_manager *dm = (pa_device_manager *)userdata; + DBusMessage *reply = NULL; + DBusMessageIter msg_iter, array_iter; + int mask; +#ifndef __TIZEN_INTERNAL_BT_SCO__ + pa_idxset *idxset1, *idxset2; +#endif + + pa_assert(conn); + pa_assert(msg); + pa_assert(dm); + + pa_assert_se((reply = dbus_message_new_method_return(msg))); + + pa_assert_se(dbus_message_get_args(msg, NULL, + DBUS_TYPE_INT32, &mask, + DBUS_TYPE_INVALID)); + + pa_log_info("Get connected device list (mask : %d)", mask); + + dbus_message_iter_init_append(reply, &msg_iter); + pa_assert_se(dbus_message_iter_open_container(&msg_iter, DBUS_TYPE_ARRAY, "(isiisiib)", &array_iter)); + +#ifdef __TIZEN_INTERNAL_BT_SCO__ + array_iter_append(&array_iter, dm->device_list, mask); +#else + /* divide into two groups and merge them because dbus message doesn't support sorting or prepend */ + idxset1 = pa_idxset_filtered_copy(dm->device_list, NULL, include_device_filter_func, DEVICE_TYPE_BT_SCO); + idxset2 = pa_idxset_filtered_copy(dm->device_list, NULL, exclude_device_filter_func, DEVICE_TYPE_BT_SCO); + + array_iter_append(&array_iter, idxset1, mask); + array_iter_append(&array_iter, idxset2, mask); + + pa_idxset_free(idxset1, NULL); + pa_idxset_free(idxset2, NULL); +#endif /* __TIZEN_INTERNAL_BT_SCO__ */ pa_assert_se(dbus_message_iter_close_container(&msg_iter, &array_iter)); -- 2.7.4 From 64302e3895000bd0d1d1e9c6a068463ab049f1be Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Mon, 13 Sep 2021 09:16:49 +0900 Subject: [PATCH 04/16] device-manager: Fix svace defect (DEREF_OF_NULL.RET.PROC.STAT) [Version] 13.0.73 [Issue Type] Svace Change-Id: If07027bfc1f37a296aedf440e03fa04040c42ad1 --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/device-manager.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index b58e363..2092eeb 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.72 +Version: 13.0.73 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/device-manager.c b/src/device-manager.c index 4e3d132..16e5641 100644 --- a/src/device-manager.c +++ b/src/device-manager.c @@ -610,7 +610,7 @@ static char* device_class_get_module_name(dm_device_class_t device_class, const class = pa_split(device_string, ":", &state); - if (!pa_streq(class, prefix)) { + if (!pa_safe_streq(class, prefix)) { if (!pa_atoi(class + strlen(prefix), &v)) snprintf(version, sizeof(version), "%d", v); else -- 2.7.4 From 5a9800395039ec6f9f11ddac6d2e8d9dfaad8307 Mon Sep 17 00:00:00 2001 From: Jaechul Lee Date: Wed, 8 Sep 2021 13:49:32 +0900 Subject: [PATCH 05/16] tizenaudio-sink2/source2: Fix frames_to_write calculation [Version] 13.0.74 [Issue Type] Bug fix Change-Id: Ida9fcab0c380fc71125f64dc90d8a186840f40ae Signed-off-by: Jaechul Lee --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/module-tizenaudio-sink.c | 2 +- src/module-tizenaudio-sink2.c | 4 ++-- src/module-tizenaudio-source2.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 2092eeb..39724b8 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.73 +Version: 13.0.74 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/module-tizenaudio-sink.c b/src/module-tizenaudio-sink.c index 62a12d5..de01053 100644 --- a/src/module-tizenaudio-sink.c +++ b/src/module-tizenaudio-sink.c @@ -430,7 +430,7 @@ static int process_render(struct userdata *u, pa_usec_t now) { /* Write pcm every 10ms */ frames_to_write = pa_usec_to_bytes((10 * PA_USEC_PER_MSEC), &u->sink->sample_spec) / frame_size; #else - frames_to_write = (u->frag_size / u->nfrags); + frames_to_write = u->frag_size / frame_size; #endif if (frames_to_write > avail) break; diff --git a/src/module-tizenaudio-sink2.c b/src/module-tizenaudio-sink2.c index e4e61e9..fe064fb 100644 --- a/src/module-tizenaudio-sink2.c +++ b/src/module-tizenaudio-sink2.c @@ -312,7 +312,7 @@ do_nothing: static int process_render(struct userdata *u) { void *p; size_t frame_size = pa_frame_size(&u->sink->sample_spec); - size_t frames_to_write = u->frag_size / u->nfrags; + size_t frames_to_write = u->frag_size / frame_size; uint32_t avail = 0; pa_memchunk chunk; @@ -324,7 +324,7 @@ static int process_render(struct userdata *u) { return 0; } - pa_sink_render_full(u->sink, frames_to_write * frame_size, &chunk); + pa_sink_render_full(u->sink, u->frag_size, &chunk); p = pa_memblock_acquire(chunk.memblock); if (pa_hal_interface_pcm_write(u->hal_interface, u->pcm_handle, (const char*)p + chunk.index, (uint32_t)frames_to_write)) { diff --git a/src/module-tizenaudio-source2.c b/src/module-tizenaudio-source2.c index 333bdbb..55bc60a 100644 --- a/src/module-tizenaudio-source2.c +++ b/src/module-tizenaudio-source2.c @@ -275,7 +275,7 @@ static int source_process_msg( static int process_render(struct userdata *u) { void *p; size_t frame_size = pa_frame_size(&u->source->sample_spec); - size_t frames_to_read = u->frag_size / u->nfrags; + size_t frames_to_read = u->frag_size / frame_size; uint32_t avail = 0; pa_memchunk chunk; @@ -289,7 +289,7 @@ static int process_render(struct userdata *u) { return 0; } - chunk.length = frames_to_read * frame_size; + chunk.length = u->frag_size; chunk.memblock = pa_memblock_new(u->core->mempool, chunk.length); p = pa_memblock_acquire(chunk.memblock); -- 2.7.4 From 449b0c5375917f12473d396f3a9f2080a6baef95 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Thu, 23 Sep 2021 21:25:03 +0900 Subject: [PATCH 06/16] sound-player: fix memory leak in case of stopping playback eos signal with the cause must be sent to client to make proper subscription release [Version] 13.0.75 [Issue Type] Bug fix Change-Id: Id318f1a4d18eafeea4e343eef6c02ee63ca2960f --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/module-sound-player.c | 26 ++++++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 39724b8..137d868 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.74 +Version: 13.0.75 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/module-sound-player.c b/src/module-sound-player.c index 5e60af2..16212ae 100644 --- a/src/module-sound-player.c +++ b/src/module-sound-player.c @@ -80,6 +80,7 @@ static void handle_simple_stop_all(DBusConnection *conn, DBusMessage *msg, void static void handle_sample_play(DBusConnection *conn, DBusMessage *msg, void *userdata); static void handle_sound_play(DBusConnection *conn, DBusMessage *msg, void *userdata); static void handle_sound_stop(DBusConnection *conn, DBusMessage *msg, void *userdata); +static void send_signal_for_eos(DBusConnection *conn, int32_t stream_idx, dbus_bool_t stopped_by_user); enum method_handler_index { METHOD_HANDLER_SIMPLE_PLAY, @@ -537,10 +538,12 @@ static void handle_sound_stop(DBusConnection *conn, DBusMessage *msg, void *user pa_sink_input_kill(si); pa_dbus_send_empty_reply(conn, msg); + + send_signal_for_eos(conn, stream_idx, TRUE); } static DBusHandlerResult handle_methods(DBusConnection *conn, DBusMessage *msg, void *userdata) { - int idx = 0; + int idx = 0; pa_assert(conn); pa_assert(msg); @@ -588,16 +591,21 @@ static DBusHandlerResult method_handler_for_vt(DBusConnection *c, DBusMessage *m return DBUS_HANDLER_RESULT_HANDLED; } -static void send_signal_for_eos(struct userdata *u, int32_t stream_idx) { +static void send_signal_for_eos(DBusConnection *conn, int32_t stream_idx, dbus_bool_t stopped_by_user) { DBusMessage *signal_msg = NULL; - pa_assert(u); + pa_assert(conn); - pa_log_info("Send EOS signal for stream_idx(%d)", stream_idx); + pa_log_info("Send EOS signal for stream_idx(%d), stopped_by_user(%d)", stream_idx, stopped_by_user); - pa_assert_se((signal_msg = dbus_message_new_signal(SOUND_PLAYER_OBJECT_PATH, SOUND_PLAYER_INTERFACE, SOUND_PLAYER_SIGNAL_EOS))); - pa_assert_se(dbus_message_append_args(signal_msg, DBUS_TYPE_INT32, &stream_idx, DBUS_TYPE_INVALID)); - pa_assert_se(dbus_connection_send(pa_dbus_connection_get(u->dbus_conn), signal_msg, NULL)); + pa_assert_se((signal_msg = dbus_message_new_signal(SOUND_PLAYER_OBJECT_PATH, + SOUND_PLAYER_INTERFACE, + SOUND_PLAYER_SIGNAL_EOS))); + pa_assert_se(dbus_message_append_args(signal_msg, + DBUS_TYPE_INT32, &stream_idx, + DBUS_TYPE_BOOLEAN, &stopped_by_user, + DBUS_TYPE_INVALID)); + pa_assert_se(dbus_connection_send(conn, signal_msg, NULL)); dbus_message_unref(signal_msg); } #endif @@ -758,8 +766,10 @@ fail: static pa_hook_result_t sink_input_unlink_cb(pa_core *core, pa_sink_input *i, struct userdata *u) { int32_t *stream_idx = NULL; uint32_t idx = 0; + pa_core_assert_ref(core); pa_sink_input_assert_ref(i); + pa_assert(u); pa_log_debug("start sink_input_unlink_cb, i(%p, index:%u)", i, i->index); @@ -768,7 +778,7 @@ static pa_hook_result_t sink_input_unlink_cb(pa_core *core, pa_sink_input *i, st if (*stream_idx == (int32_t)(i->index)) { #ifndef USE_DBUS_PROTOCOL /* Send EOS signal for this stream */ - send_signal_for_eos(u, *stream_idx); + send_signal_for_eos(pa_dbus_connection_get(u->dbus_conn), *stream_idx, FALSE); #endif pa_idxset_remove_by_data(u->stream_idxs, stream_idx, NULL); pa_xfree(stream_idx); -- 2.7.4 From 4666f7e663bc2e9c1d1caeade4fdfc81c989c139 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Fri, 24 Sep 2021 21:27:12 +0900 Subject: [PATCH 07/16] Fix aarch64 build warnings Fixes following warnings: - cast to pointer from integer of different size [-Wint-to-pointer-cast] - format '%llu' expects argument of type 'long long unsigned int', but argument 9 has type 'pa_usec_t' {aka 'long unsigned int'} [-Wformat=] - format '%d' expects argument of type 'int', but argument 7 has type 'size_t' {aka 'long unsigned int'} [-Wformat=] [Version] 13.0.76 [Issue Type] Build Change-Id: I55a043c48107c3a3c6bf71cbb8b81f54c504180d --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/module-tizenaudio-policy.c | 16 ++++++++-------- src/module-tizenaudio-sink2.c | 4 ++-- src/module-tizenaudio-source2.c | 4 ++-- src/stream-manager-dbus.c | 14 +++++++------- src/stream-manager.c | 34 ++++++++++++++++----------------- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 137d868..49718ab 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.75 +Version: 13.0.76 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/module-tizenaudio-policy.c b/src/module-tizenaudio-policy.c index 44b1894..bb331e0 100644 --- a/src/module-tizenaudio-policy.c +++ b/src/module-tizenaudio-policy.c @@ -468,10 +468,10 @@ static void update_loopback_module_args(struct userdata* u, int32_t parent_id, p return; } - loopback = pa_hashmap_get(u->loopback_modules, (const void*)parent_id); + loopback = pa_hashmap_get(u->loopback_modules, PA_INT_TO_PTR(parent_id)); if (!loopback) { loopback = pa_xnew0(loopback_module, 1); - pa_hashmap_put(u->loopback_modules, (void*)parent_id, loopback); + pa_hashmap_put(u->loopback_modules, PA_INT_TO_PTR(parent_id), loopback); } if (sink) loopback->sink = sink; @@ -495,7 +495,7 @@ static void load_loopback_module_by_parent_id(struct userdata* u, int32_t parent return; } - loopback = pa_hashmap_get(u->loopback_modules, (const void*)parent_id); + loopback = pa_hashmap_get(u->loopback_modules, PA_INT_TO_PTR(parent_id)); if (!loopback) { pa_log_error("could not find loopback module for parent_id(%d)", parent_id); return; @@ -540,7 +540,7 @@ static void unload_loopback_modules_by_device_disconnect(struct userdata* u, pa_ ((sink && (loopback->sink == sink)) || (source && (loopback->source == source)))) { pa_log_info(" -- unload module-loopback(%p) for parent_id(%d)", loopback->module, parent_id); - pa_hashmap_remove_and_free(u->loopback_modules, (const void*)parent_id); + pa_hashmap_remove_and_free(u->loopback_modules, PA_INT_TO_PTR(parent_id)); } } } @@ -557,7 +557,7 @@ static void unload_loopback_modules_by_stream_disconnect(struct userdata* u, int if (!i && !o) return; - loopback = pa_hashmap_get(u->loopback_modules, (const void*)parent_id); + loopback = pa_hashmap_get(u->loopback_modules, PA_INT_TO_PTR(parent_id)); if (!loopback) return; @@ -582,7 +582,7 @@ static void unload_loopback_modules_by_stream_disconnect(struct userdata* u, int unload: pa_log_info(" -- unload module-loopback(%p) for parent_id(%d)", loopback->module, parent_id); - pa_hashmap_remove_and_free(u->loopback_modules, (const void*)parent_id); + pa_hashmap_remove_and_free(u->loopback_modules, PA_INT_TO_PTR(parent_id)); } static pa_sink *load_combine_sink_module(struct userdata *u, const char *combine_sink_name, pa_sink *sink1, pa_sink *sink2, pa_sink_input *stream) @@ -897,7 +897,7 @@ static void select_device_by_auto_last_connected_routing(struct userdata *u, pa_ dm_device_direction = pa_tz_device_get_direction(device); dm_device_id = pa_tz_device_get_id(device); creation_time = pa_tz_device_get_creation_time(device); - pa_log_debug(" -- type[%-16s], direction[0x%x], id[%u], creation_time[%llu]", + pa_log_debug(" -- type[%-16s], direction[0x%x], id[%u], creation_time[%" PRIu64 "]", dm_device_type, dm_device_direction, dm_device_id, creation_time); if (!pa_safe_streq(device_type, dm_device_type) || !IS_AVAILABLE_DIRECTION(data->stream_type, dm_device_direction)) continue; @@ -1567,7 +1567,7 @@ static pa_hook_result_t handle_auto_last_connected_routing(struct userdata *u, p dm_device_direction = pa_tz_device_get_direction(*device); dm_device_id = pa_tz_device_get_id(*device); creation_time = pa_tz_device_get_creation_time(*device); - pa_log_debug(" -- type[%-16s], direction[0x%x], id[%u], creation_time[%llu]", + pa_log_debug(" -- type[%-16s], direction[0x%x], id[%u], creation_time[%" PRIu64 "]", dm_device_type, dm_device_direction, dm_device_id, creation_time); if (!pa_safe_streq(device_type, dm_device_type) || !IS_AVAILABLE_DIRECTION(data->stream_type, dm_device_direction)) continue; diff --git a/src/module-tizenaudio-sink2.c b/src/module-tizenaudio-sink2.c index fe064fb..a5a5871 100644 --- a/src/module-tizenaudio-sink2.c +++ b/src/module-tizenaudio-sink2.c @@ -320,7 +320,7 @@ static int process_render(struct userdata *u) { pa_hal_interface_pcm_available(u->hal_interface, u->pcm_handle, &avail); if (frames_to_write > avail) { - pa_log_debug("not enough avail size. frames_to_write(%d), avail(%d)", frames_to_write, avail); + pa_log_debug("not enough avail size. frames_to_write(%zu), avail(%d)", frames_to_write, avail); return 0; } @@ -328,7 +328,7 @@ static int process_render(struct userdata *u) { p = pa_memblock_acquire(chunk.memblock); if (pa_hal_interface_pcm_write(u->hal_interface, u->pcm_handle, (const char*)p + chunk.index, (uint32_t)frames_to_write)) { - pa_log_error("failed to write pcm. p(%p), size(%d)", p, frames_to_write); + pa_log_error("failed to write pcm. p(%p), size(%zu)", p, frames_to_write); return -1; } diff --git a/src/module-tizenaudio-source2.c b/src/module-tizenaudio-source2.c index 55bc60a..3df3aef 100644 --- a/src/module-tizenaudio-source2.c +++ b/src/module-tizenaudio-source2.c @@ -285,7 +285,7 @@ static int process_render(struct userdata *u) { pa_hal_interface_pcm_available(u->hal_interface, u->pcm_handle, &avail); if (frames_to_read > avail) { - pa_log_debug("not enough avail size. frames_to_read(%d), avail(%d)", frames_to_read, avail); + pa_log_debug("not enough avail size. frames_to_read(%zu), avail(%d)", frames_to_read, avail); return 0; } @@ -294,7 +294,7 @@ static int process_render(struct userdata *u) { p = pa_memblock_acquire(chunk.memblock); if (pa_hal_interface_pcm_read(u->hal_interface, u->pcm_handle, p, (uint32_t)frames_to_read)) { - pa_log_error("failed to read pcm. p(%p), size(%d)", p, frames_to_read); + pa_log_error("failed to read pcm. p(%p), size(%zu)", p, frames_to_read); return -1; } pa_memblock_release(chunk.memblock); diff --git a/src/stream-manager-dbus.c b/src/stream-manager-dbus.c index f10e221..096ff5c 100644 --- a/src/stream-manager-dbus.c +++ b/src/stream-manager-dbus.c @@ -602,7 +602,7 @@ static void handle_set_stream_route_devices(DBusConnection *conn, DBusMessage *m 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); - sp = pa_hashmap_get(m->stream_parents, (const void*)id); + sp = pa_hashmap_get(m->stream_parents, PA_UINT_TO_PTR(id)); if (!sp) { pa_log_error("could not find matching client for this parent_id[%u]", id); ret = RET_MSG_ERROR_INTERNAL; @@ -677,7 +677,7 @@ static void handle_set_stream_route_option(DBusConnection *conn, DBusMessage *ms DBUS_TYPE_INVALID)); pa_log_info("id[%u], name[%s], value[%d]", id, name, value); - sp = pa_hashmap_get(m->stream_parents, (const void*)id); + sp = pa_hashmap_get(m->stream_parents, PA_UINT_TO_PTR(id)); if (sp) { if (name) { route_option.name = name; @@ -774,7 +774,7 @@ 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); - if (!(sp = pa_hashmap_get(m->stream_parents, (const void*)sp_id))) { + if (!(sp = pa_hashmap_get(m->stream_parents, PA_UINT_TO_PTR(sp_id)))) { pa_log_error("could not find matching client for this parent_id[%u]", sp_id); ret = RET_MSG_ERROR_INTERNAL; goto finish; @@ -904,7 +904,7 @@ static void handle_get_stream_preferred_device(DBusConnection *conn, DBusMessage pa_assert_se((reply = dbus_message_new_method_return(msg))); - if (!(sp = pa_hashmap_get(m->stream_parents, (const void*)sp_id))) { + if (!(sp = pa_hashmap_get(m->stream_parents, PA_UINT_TO_PTR(sp_id)))) { pa_log_error("could not find matching client for this parent_id[%u]", sp_id); ret = RET_MSG_ERROR_INTERNAL; goto finish; @@ -1637,7 +1637,7 @@ 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); - if ((sp = pa_hashmap_get(m->stream_parents, (const void*)id))) { + if ((sp = pa_hashmap_get(m->stream_parents, PA_UINT_TO_PTR(id)))) { if (sp->focus_status != acquired_focus_status) { /* need to update */ prev_status = sp->focus_status; @@ -2099,7 +2099,7 @@ static void handle_activate_ducking(DBusConnection *conn, DBusMessage *msg, void id, enable, target_stream, duration, ratio); /* get stream_ducking */ - sd = pa_hashmap_get(m->stream_duckings, (const void*)id); + sd = pa_hashmap_get(m->stream_duckings, PA_UINT_TO_PTR(id)); if (!sd) { pa_log_error("no matched stream ducking for id[%u]", id); ret_msg = RET_MSG_ERROR_INTERNAL; @@ -2219,7 +2219,7 @@ static void handle_get_ducking_state(DBusConnection *conn, DBusMessage *msg, voi pa_assert_se((reply = dbus_message_new_method_return(msg))); /* get stream_ducking */ - sd = pa_hashmap_get(m->stream_duckings, (const void *)id); + sd = pa_hashmap_get(m->stream_duckings, PA_UINT_TO_PTR(id)); if (!sd) { pa_log_error("no matched stream ducking for id[%u]", id); ret_msg = RET_MSG_ERROR_INTERNAL; diff --git a/src/stream-manager.c b/src/stream-manager.c index fe45e37..cb12cb9 100644 --- a/src/stream-manager.c +++ b/src/stream-manager.c @@ -376,7 +376,7 @@ static stream_parent* get_stream_parent(pa_stream_manager *m, pa_object *stream) return NULL; } - return pa_hashmap_get(m->stream_parents, (const void*)parent_id_u); + return pa_hashmap_get(m->stream_parents, PA_UINT_TO_PTR(parent_id_u)); } static pa_idxset* get_route_devices(pa_stream_manager *m, pa_object *stream) { @@ -1203,7 +1203,7 @@ static bool update_focus_status_of_stream(pa_stream_manager *m, void *stream, st else p_idx = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_PARENT_ID); if (p_idx && !pa_atou(p_idx, &parent_idx)) { - if (!(sp = pa_hashmap_get(m->stream_parents, (const void*)parent_idx))) { + if (!(sp = pa_hashmap_get(m->stream_parents, PA_UINT_TO_PTR(parent_idx)))) { pa_log_error("could not find matching client for this parent_id(%u)", parent_idx); return false; } @@ -1233,7 +1233,7 @@ static void update_preferred_device_role(pa_stream_manager *m, void *stream, str if (!p_idx_str || pa_atou(p_idx_str, &parent_idx)) return; - if (!(sp = pa_hashmap_get(m->stream_parents, (const void*)parent_idx))) { + if (!(sp = pa_hashmap_get(m->stream_parents, PA_UINT_TO_PTR(parent_idx)))) { pa_log_error("could not find matching client for this parent_id(%u)", parent_idx); return; } @@ -1258,7 +1258,7 @@ static void get_preferred_device_type_and_role(pa_stream_manager *m, void *strea if (!p_idx_str || pa_atou(p_idx_str, &parent_idx)) { return; } - if (!(sp = pa_hashmap_get(m->stream_parents, (const void*)parent_idx))) { + if (!(sp = pa_hashmap_get(m->stream_parents, PA_UINT_TO_PTR(parent_idx)))) { pa_log_warn("could not find matching client for this parent_id(%u)", parent_idx); return; } @@ -1283,7 +1283,7 @@ static bool update_stream_parent_info(pa_stream_manager *m, process_command_type p_idx = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_PARENT_ID); if (p_idx && !pa_atou(p_idx, &parent_idx)) { pa_log_debug("p_idx(%s), idx(%u)", p_idx, parent_idx); - sp = pa_hashmap_get(m->stream_parents, (const void*)parent_idx); + sp = pa_hashmap_get(m->stream_parents, PA_UINT_TO_PTR(parent_idx)); if (sp) { uint32_t idx = GET_STREAM_INDEX(stream, type); if (command == PROCESS_COMMAND_ADD_STREAM) { @@ -1662,7 +1662,7 @@ static void fill_device_info_to_hook_data(pa_stream_manager *m, void *hook_data, break; } /* find parent idx, it's device info. and it's stream idxs */ - if ((sp = pa_hashmap_get(m->stream_parents, (const void*)parent_idx))) { + if ((sp = pa_hashmap_get(m->stream_parents, PA_UINT_TO_PTR(parent_idx)))) { select_data->idx_manual_devices = (type == STREAM_SINK_INPUT) ? (sp->idx_route_out_devices) : (sp->idx_route_in_devices); break; } @@ -1699,7 +1699,7 @@ static void fill_device_info_to_hook_data(pa_stream_manager *m, void *hook_data, pa_log_warn(" -- could not get the parent id of this stream, but keep going..."); break; } - if (!(sp = pa_hashmap_get(m->stream_parents, (const void*)parent_idx))) { + if (!(sp = pa_hashmap_get(m->stream_parents, PA_UINT_TO_PTR(parent_idx)))) { pa_log_warn(" -- failed to get the stream parent of idx(%u)", parent_idx); break; } @@ -2930,7 +2930,7 @@ static void find_next_device_for_auto_route(pa_stream_manager *m, stream_route_t } } *next_device = latest_device; - pa_log_debug("found next device[%p], creation_time[%llu]", *next_device, latest_creation_time); + pa_log_debug("found next device[%p], creation_time[%" PRIu64 "]", *next_device, latest_creation_time); } pa_log_debug("next_device is [%p] for stream_role[%s]/route_type[%d]/stream_type[%d]", *next_device, stream_role, route_type, stream_type); @@ -3427,19 +3427,19 @@ static void mute_sink_inputs_as_device_disconnection(pa_stream_manager *m, uint3 return; } apply_volume_factor_to_streams(streams_of_disconnected_device, &applied_streams); - pa_hashmap_put(m->muted_streams, (void*)event_id, applied_streams); + pa_hashmap_put(m->muted_streams, PA_UINT_TO_PTR(event_id), applied_streams); /* If PA_COMMUNICATOR_HOOK_EVENT_FULLY_HANDLED is not called for some reason, * volume factor should be removed forcedly. */ if (!m->time_event_for_unmute) m->time_event_for_unmute = pa_core_rttime_new(m->core, pa_rtclock_now() + TIMED_UNMUTE_USEC, timed_unmute_cb, m); } else { - if (!(applied_streams = pa_hashmap_get(m->muted_streams, (void*)event_id))) { + if (!(applied_streams = pa_hashmap_get(m->muted_streams, PA_UINT_TO_PTR(event_id)))) { pa_log_debug("could not find applied_streams for event_id(%u)", event_id); return; } clear_volume_factor_from_streams(applied_streams); - pa_hashmap_remove(m->muted_streams, (void*)event_id); + pa_hashmap_remove(m->muted_streams, PA_UINT_TO_PTR(event_id)); } return; @@ -3640,7 +3640,7 @@ static void subscribe_cb(pa_core *core, pa_subscription_event_type_t t, uint32_t sp->idx_source_outputs = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); sp->idx_route_in_devices = pa_idxset_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); sp->idx_route_out_devices = pa_idxset_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); - pa_hashmap_put(m->stream_parents, (void*)idx, sp); + pa_hashmap_put(m->stream_parents, PA_UINT_TO_PTR(idx), sp); pa_log_debug(" - add sp(%p), idx(%u)", sp, idx); return; } else if (pa_safe_streq(name, STREAM_MANAGER_CLIENT_DUCKING)) { @@ -3648,16 +3648,16 @@ static void subscribe_cb(pa_core *core, pa_subscription_event_type_t t, uint32_t sd = pa_xmalloc0(sizeof(stream_ducking)); sd->idx_ducking_streams = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); sd->trigger_index = idx; - pa_hashmap_put(m->stream_duckings, (void *)idx, sd); + pa_hashmap_put(m->stream_duckings, PA_UINT_TO_PTR(idx), sd); pa_log_debug(" - add sd(%p), trigger_index(%u)", sd, idx); return; } } else if (t == (PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_REMOVE)) { /* try to find stream parent with idx */ - sp = pa_hashmap_get(m->stream_parents, (const void*)idx); + sp = pa_hashmap_get(m->stream_parents, PA_UINT_TO_PTR(idx)); if (sp) { pa_log_debug(" - remove sp(%p), idx(%u)", sp, idx); - pa_hashmap_remove(m->stream_parents, (const void*)idx); + pa_hashmap_remove(m->stream_parents, PA_UINT_TO_PTR(idx)); pa_idxset_free(sp->idx_sink_inputs, NULL); pa_idxset_free(sp->idx_source_outputs, NULL); if (sp->idx_route_in_devices) @@ -3669,7 +3669,7 @@ static void subscribe_cb(pa_core *core, pa_subscription_event_type_t t, uint32_t } /* try to find sd with idx */ - sd = pa_hashmap_get(m->stream_duckings, (const void*)idx); + sd = pa_hashmap_get(m->stream_duckings, PA_UINT_TO_PTR(idx)); if (sd) { uint32_t ducking_idx = 0; pa_sink_input *stream = NULL; @@ -3698,7 +3698,7 @@ static void subscribe_cb(pa_core *core, pa_subscription_event_type_t t, uint32_t } pa_idxset_free(sd->idx_ducking_streams, NULL); - pa_hashmap_remove(m->stream_duckings, (const void*)idx); + pa_hashmap_remove(m->stream_duckings, PA_UINT_TO_PTR(idx)); pa_xfree(sd); return; } -- 2.7.4 From 0a3c62ee00b3f4810a903278066b53897adf739a Mon Sep 17 00:00:00 2001 From: Jaechul Lee Date: Mon, 27 Sep 2021 14:58:18 +0900 Subject: [PATCH 08/16] Fix DEREF_OF_NULL.RET.PROC.STAT [Version] 13.0.77 [Issue Type] VD svace DF210918-00186 Change-Id: I21b72e6fd96ab07521cb807bc26c44e148c00162 Signed-off-by: Jaechul Lee --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/device-manager.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 49718ab..0130020 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.76 +Version: 13.0.77 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/device-manager.c b/src/device-manager.c index 16e5641..a57fc46 100644 --- a/src/device-manager.c +++ b/src/device-manager.c @@ -609,6 +609,10 @@ static char* device_class_get_module_name(dm_device_class_t device_class, const const char *state = NULL, *prefix = "tizen"; class = pa_split(device_string, ":", &state); + if (!class) { + pa_log_error("Failed to parse device_string %s", device_string); + return NULL; + } if (!pa_safe_streq(class, prefix)) { if (!pa_atoi(class + strlen(prefix), &v)) -- 2.7.4 From 2b6a54f1afcca09e1a1210145e6b4af4a4f52505 Mon Sep 17 00:00:00 2001 From: jungsup lee Date: Thu, 14 Oct 2021 17:33:19 +0900 Subject: [PATCH 09/16] tizenaudio-sink: Print log when snd_pcm_avail() return small value continuously [Version] 13.0.78 [Issue Type] Debugging Change-Id: I982d1ee7cf7a5d0546902aec9f7a498278b4014a --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/module-tizenaudio-sink.c | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 0130020..88816a2 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.77 +Version: 13.0.78 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/module-tizenaudio-sink.c b/src/module-tizenaudio-sink.c index de01053..a941adf 100644 --- a/src/module-tizenaudio-sink.c +++ b/src/module-tizenaudio-sink.c @@ -76,7 +76,8 @@ PA_MODULE_USAGE( /* Sink device consumes that amount of maximum buffer at every request */ #define DEFAULT_MAX_REQUEST_USEC (PA_USEC_PER_SEC * 0.032) -#define DEVICE_NAME_MAX 30 +#define DEVICE_NAME_MAX 30 +#define SMALL_AVAIL_LOG_PERIOD 20 #ifdef SUPPORT_AEC enum { @@ -109,6 +110,7 @@ struct userdata { pa_rtpoll_item *rtpoll_item; + uint64_t small_avail_count; uint64_t write_count; pa_hal_interface *hal_interface; @@ -432,10 +434,18 @@ static int process_render(struct userdata *u, pa_usec_t now) { #else frames_to_write = u->frag_size / frame_size; #endif - if (frames_to_write > avail) + if (frames_to_write > avail) { + u->small_avail_count++; + + if ((u->small_avail_count % SMALL_AVAIL_LOG_PERIOD) == 0) + pa_log_error("avail is too small : %u(repeat count : %llu)", avail, u->small_avail_count); + break; + } } + u->small_avail_count = 0; + pa_sink_render_full(u->sink, frames_to_write * frame_size, &chunk); p = pa_memblock_acquire(chunk.memblock); -- 2.7.4 From b64118838111be16086491b900eab5ff3e742d61 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Thu, 21 Oct 2021 11:33:28 +0900 Subject: [PATCH 10/16] Fix coverity issues (CHECKED_RETURN / PW.PARAMETER_HIDDEN) + Fix minor aarch64 build warning [Version] 13.0.79 [Issue Type] Build Change-Id: Ie7ed49cf73beb95ce5db332d6595aa6c6def27ab --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/aec-manager.c | 12 +++++++++--- src/module-tizenaudio-sink.c | 2 +- src/stream-manager.c | 6 +++--- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 88816a2..dc69171 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.78 +Version: 13.0.79 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/aec-manager.c b/src/aec-manager.c index 8ed96b5..c349f71 100644 --- a/src/aec-manager.c +++ b/src/aec-manager.c @@ -144,7 +144,8 @@ static void send_get_param_reply(DBusConnection *conn, DBusMessage *msg, aec_par dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_INT32, ¶m->nfrags); dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_STRING, &ptr1); dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_STRING, &ptr2); - dbus_connection_send(conn, reply, NULL); + if (!dbus_connection_send(conn, reply, NULL)) + pa_log_error("reply send error!"); dbus_message_unref(reply); } @@ -205,8 +206,13 @@ static DBusHandlerResult method_handler_for_vt(DBusConnection *conn, DBusMessage r = dbus_message_new_method_return(m); if (r) { const char *xml = AEC_MANAGER_INTROSPECT_XML; - dbus_message_append_args(r, DBUS_TYPE_STRING, &xml, DBUS_TYPE_INVALID); - dbus_connection_send((conn), r, NULL); + if (dbus_message_append_args(r, DBUS_TYPE_STRING, &xml, DBUS_TYPE_INVALID)) { + if (!dbus_connection_send(conn, r, NULL)) + pa_log_error("reply send error!"); + } else { + pa_log_error("args append error!"); + } + dbus_message_unref(r); } } else { diff --git a/src/module-tizenaudio-sink.c b/src/module-tizenaudio-sink.c index a941adf..9dc3226 100644 --- a/src/module-tizenaudio-sink.c +++ b/src/module-tizenaudio-sink.c @@ -438,7 +438,7 @@ static int process_render(struct userdata *u, pa_usec_t now) { u->small_avail_count++; if ((u->small_avail_count % SMALL_AVAIL_LOG_PERIOD) == 0) - pa_log_error("avail is too small : %u(repeat count : %llu)", avail, u->small_avail_count); + pa_log_error("avail is too small : %u(repeat count : %" PRIu64 ")", avail, u->small_avail_count); break; } diff --git a/src/stream-manager.c b/src/stream-manager.c index cb12cb9..4b8b1a1 100644 --- a/src/stream-manager.c +++ b/src/stream-manager.c @@ -3172,11 +3172,11 @@ static void check_and_move_streams_by_device_connection_change(pa_stream_manager if (is_connected) { uint32_t preemptive_device_id = 0; if (!pa_stream_manager_get_preemptive_device_id(m, stream_type, stream_role, &preemptive_device_id)) { - pa_tz_device *device = pa_device_manager_get_device_by_id(m->dm, preemptive_device_id); - if (device) { + pa_tz_device *_device = pa_device_manager_get_device_by_id(m->dm, preemptive_device_id); + if (_device) { pa_log_debug("Skip moving this stream[%s, idx:%u] set to the preemptive device(%s, id:%u)", stream_role, (stream_type == STREAM_SINK_INPUT) ? PA_SINK_INPUT(s)->index : PA_SOURCE_OUTPUT(s)->index, - device->type, preemptive_device_id); + _device->type, preemptive_device_id); continue; } } -- 2.7.4 From 7ee613ac6b48f52d15f98a688a144ae7a379afb4 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Wed, 27 Oct 2021 19:48:01 +0900 Subject: [PATCH 11/16] device-manager: use container dedicated device-map json [Version] 13.0.80 [Issue Type] Container Change-Id: If81c7aed340369e451980142d7c677ff22053f98 --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/device-manager.c | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index dc69171..8520637 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.79 +Version: 13.0.80 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/device-manager.c b/src/device-manager.c index a57fc46..7cb46c9 100644 --- a/src/device-manager.c +++ b/src/device-manager.c @@ -56,6 +56,7 @@ #define SHARED_DEVICE_MANAGER "tizen-device-manager" #define DEVICE_MAP_FILE PA_DEFAULT_CONFIG_DIR"/device-map.json" +#define DEVICE_MAP_FILE_CONTAINER PA_DEFAULT_CONFIG_DIR"/device-map-container.json" #define DEVICE_STR_MAX 40 #define DEVICE_DIRECTION_MAX 3 #define DEVICE_MODULE_STRING_MAX 256 @@ -2439,17 +2440,22 @@ fail: return NULL; } +static const char * get_device_map_json() +{ + return (access("/run/systemd/container", F_OK) == 0) ? DEVICE_MAP_FILE_CONTAINER : DEVICE_MAP_FILE; +} + static struct device_file_map *parse_device_file_map() { struct device_file_map *file_map = NULL; json_object *o, *device_files_o; json_object *playback_devices_o = NULL, *capture_devices_o = NULL; + const char *device_map_file = get_device_map_json(); pa_log_info("\nParse device files"); - o = json_object_from_file(DEVICE_MAP_FILE); - + o = json_object_from_file(device_map_file); if (o == NULL) { - pa_log_error("Read device-map file failed"); + pa_log_error("Read %s file failed", device_map_file); return NULL; } @@ -2522,12 +2528,12 @@ static pa_idxset* parse_device_type_infos() { int device_type_num = 0; int device_type_idx = 0; device_type_info *type_info = NULL; - //pa_hashmap *type_infos = NULL; pa_idxset *type_infos = NULL; + const char *device_map_file = get_device_map_json(); - o = json_object_from_file(DEVICE_MAP_FILE); + o = json_object_from_file(device_map_file); if (o == NULL) { - pa_log_error("Read device-map file failed"); + pa_log_error("Read %s file failed", device_map_file); return NULL; } -- 2.7.4 From 2ec3aa4311bf6dcf887f9541c7e811acb8f05e3d Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Tue, 28 Dec 2021 14:36:01 +0900 Subject: [PATCH 12/16] stream-manager: Deactivate ducking for audio HAL when stream ducking is removed Previously, deactivation ducking for audio HAL could be missed. [Version] 13.0.81 [Issue Type] Bug fix Change-Id: Ide1206dc98f1dd354cb23e6c8cf06361a1d815e3 Signed-off-by: Jeongmo Yang --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/stream-manager.c | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 8520637..57aea54 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.80 +Version: 13.0.81 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/stream-manager.c b/src/stream-manager.c index 4b8b1a1..e50e13b 100644 --- a/src/stream-manager.c +++ b/src/stream-manager.c @@ -3673,11 +3673,16 @@ static void subscribe_cb(pa_core *core, pa_subscription_event_type_t t, uint32_t if (sd) { uint32_t ducking_idx = 0; pa_sink_input *stream = NULL; + hal_ducking_activation_info ducking_activation_info = { + sd->target_role, sd->duration, sd->ratio, false + }; - pa_log_info(" - remove sd(%p), trigger_index(%u)", sd, idx); + pa_log_info(" - remove sd(%p) state(%d), trigger_index(%u)", sd, sd->state, idx); + + if (sd->state == STREAM_DUCKING_STATE_UNDUCKED || sd->state == STREAM_DUCKING_STATE_UNDUCKING) + goto skip_unducking; PA_IDXSET_FOREACH(stream, sd->idx_ducking_streams, ducking_idx) { - hal_ducking_activation_info ducking_activation_info; /* Note: It is added temporarily to find missing index of idx_ducking_streams */ if (!pa_idxset_get_by_data(m->core->sink_inputs, stream, NULL)) { pa_log_error("could not find stream(%p), skip it", stream); @@ -3687,16 +3692,11 @@ static void subscribe_cb(pa_core *core, pa_subscription_event_type_t t, uint32_t pa_log_info(" -- remove volume ramp, key(%s) from remained stream(idx:%u)", sd->vol_key, stream->index); pa_sink_input_remove_volume_factor(stream, sd->vol_key); pa_sink_input_remove_volume_ramp_factor(stream, sd->vol_key, true); - - /* notify ducking activation */ - ducking_activation_info.target_role = sd->target_role; - ducking_activation_info.duration = sd->duration; - ducking_activation_info.ratio = sd->ratio; - ducking_activation_info.is_activated = false; - - pa_hal_interface_notify_ducking_activation_changed(m->hal, &ducking_activation_info); } + pa_hal_interface_notify_ducking_activation_changed(m->hal, &ducking_activation_info); + + skip_unducking: pa_idxset_free(sd->idx_ducking_streams, NULL); pa_hashmap_remove(m->stream_duckings, PA_UINT_TO_PTR(idx)); pa_xfree(sd); -- 2.7.4 From e11d1a025b12ff11401a614bc7b3a41949beefa6 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Mon, 27 Dec 2021 14:56:49 +0900 Subject: [PATCH 13/16] Fix for pulseaudio 15.0 upgrade [Version] 15.0.0 [Issue Type] Core Upgrade Change-Id: Ie55fa522a3d1e08c8e898ce626a1a199c0f994e6 --- Makefile.am | 2 +- configure.ac | 2 +- packaging/pulseaudio-modules-tizen.spec | 32 +++++++++++++++++--------------- src/device-manager-db.c | 14 +++++++------- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/Makefile.am b/Makefile.am index 6869eaa..260a272 100644 --- a/Makefile.am +++ b/Makefile.am @@ -17,7 +17,7 @@ ACLOCAL_AMFLAGS = -I m4 -pulsemodlibexecdir= $(libdir)/pulse-13.0/modules +pulsemodlibexecdir= $(libdir)/pulse-15.0/modules pulselibexecdir=$(libexecdir)/pulse AM_CFLAGS = \ diff --git a/configure.ac b/configure.ac index d1720a3..acaaf3d 100644 --- a/configure.ac +++ b/configure.ac @@ -22,7 +22,7 @@ AC_PREREQ(2.63) -AC_INIT([pulseaudio-module-tizen],[0.1]) +AC_INIT([pulseaudio-module-tizen],[15.0]) AC_CONFIG_SRCDIR([src/module-tizenaudio-policy.c]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_HEADERS([config.h]) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 57aea54..2194382 100644 --- a/packaging/pulseaudio-modules-tizen.spec +++ b/packaging/pulseaudio-modules-tizen.spec @@ -1,6 +1,8 @@ +%define module_ver 15.0 + Name: pulseaudio-modules-tizen Summary: Pulseaudio modules for Tizen -Version: 13.0.81 +Version: 15.0.0 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ @@ -76,21 +78,21 @@ install -m 0644 %SOURCE1 %{buildroot}%{_tmpfilesdir}/pulseaudio.conf %manifest %{name}.manifest %defattr(-,root,root,-) %license LICENSE.LGPL-2.1+ -%{_libdir}/pulse-13.0/modules/module-poweroff.so -%{_libdir}/pulse-13.0/modules/module-sound-player.so -%{_libdir}/pulse-13.0/modules/module-tone-player.so -%{_libdir}/pulse-13.0/modules/module-tizenaudio-policy.so -%{_libdir}/pulse-13.0/modules/module-tizenaudio-sink.so -%{_libdir}/pulse-13.0/modules/module-tizenaudio-source.so -%{_libdir}/pulse-13.0/modules/module-tizenaudio-sink2.so -%{_libdir}/pulse-13.0/modules/module-tizenaudio-source2.so -%{_libdir}/pulse-13.0/modules/module-tizenaudio-discover.so -%{_libdir}/pulse-13.0/modules/module-tizenaudio-publish.so -%{_libdir}/pulse-13.0/modules/libhal-interface.so -%{_libdir}/pulse-13.0/modules/libcommunicator.so +%{_libdir}/pulse-%{module_ver}/modules/module-poweroff.so +%{_libdir}/pulse-%{module_ver}/modules/module-sound-player.so +%{_libdir}/pulse-%{module_ver}/modules/module-tone-player.so +%{_libdir}/pulse-%{module_ver}/modules/module-tizenaudio-policy.so +%{_libdir}/pulse-%{module_ver}/modules/module-tizenaudio-sink.so +%{_libdir}/pulse-%{module_ver}/modules/module-tizenaudio-source.so +%{_libdir}/pulse-%{module_ver}/modules/module-tizenaudio-sink2.so +%{_libdir}/pulse-%{module_ver}/modules/module-tizenaudio-source2.so +%{_libdir}/pulse-%{module_ver}/modules/module-tizenaudio-discover.so +%{_libdir}/pulse-%{module_ver}/modules/module-tizenaudio-publish.so +%{_libdir}/pulse-%{module_ver}/modules/libhal-interface.so +%{_libdir}/pulse-%{module_ver}/modules/libcommunicator.so %{_tmpfilesdir}/pulseaudio.conf %if "%{tizen_profile_name}" == "tv" -%{_libdir}/pulse-13.0/modules/module-vconf.so +%{_libdir}/pulse-%{module_ver}/modules/module-vconf.so %{_libexecdir}/pulse/vconf-helper %endif %{_libdir}/ladspa/*.so @@ -100,5 +102,5 @@ install -m 0644 %SOURCE1 %{buildroot}%{_tmpfilesdir}/pulseaudio.conf %manifest %{name}.manifest %defattr(-,root,root,-) %license LICENSE.LGPL-2.1+ -%{_libdir}/pulse-13.0/modules/module-acm-sink.so +%{_libdir}/pulse-%{module_ver}/modules/module-acm-sink.so diff --git a/src/device-manager-db.c b/src/device-manager-db.c index f1cfaa8..40d0350 100644 --- a/src/device-manager-db.c +++ b/src/device-manager-db.c @@ -36,23 +36,23 @@ static void dump_prefer_entry(prefer_entry *e) { } int32_t init_database(pa_device_manager *dm) { - char *db_path; + char *state_path; pa_assert(dm); - if (!(db_path = pa_state_path("device-preferences", true))) { + if (!(state_path = pa_state_path(NULL, true))) { pa_log_error("failed to get path for database"); return -1; } - if (!(dm->database = pa_database_open(db_path, true))) { - pa_log_error("failed to open database '%s': %s", db_path, pa_cstrerror(errno)); - pa_xfree(db_path); + if (!(dm->database = pa_database_open(state_path, "device-preferences", true, true))) { + pa_log_error("failed to open database '%s': %s", state_path, pa_cstrerror(errno)); + pa_xfree(state_path); return -1; } - pa_log_info("database file '%s'", db_path); + pa_log_info("database file '%s'", state_path); - pa_xfree(db_path); + pa_xfree(state_path); return 0; } -- 2.7.4 From 290a87181918376a0a1130885010358ab9106668 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Tue, 22 Feb 2022 19:34:43 +0900 Subject: [PATCH 14/16] device-manager: Fix svace issues (DEREF_OF_NULL.RET.STAT) - Add null check for pulse_device_get_proplist() - Use foreach macro for dynarray on handle_internal_pulse_device() - Remove unnecessary braces - Fix some invalid indents - Revise some code format [Version] 15.0.1 [Issue Type] Svace Change-Id: I9ae16c35194f94633063b38b49ff133d9372538d --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/device-manager.c | 261 ++++++++++++-------------------- 2 files changed, 100 insertions(+), 163 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 2194382..f19401e 100644 --- a/packaging/pulseaudio-modules-tizen.spec +++ b/packaging/pulseaudio-modules-tizen.spec @@ -2,7 +2,7 @@ Name: pulseaudio-modules-tizen Summary: Pulseaudio modules for Tizen -Version: 15.0.0 +Version: 15.0.1 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/device-manager.c b/src/device-manager.c index 7cb46c9..510ef24 100644 --- a/src/device-manager.c +++ b/src/device-manager.c @@ -315,21 +315,19 @@ static void file_info_free_func(struct device_file_info *file_info) { } static dm_device_class_t device_string_get_class(const char *device_string) { - if (!device_string) { + if (!device_string) return DM_DEVICE_CLASS_NONE; - } - if (device_string == strstr(device_string, "alsa")) { + if (device_string == strstr(device_string, "alsa")) return DM_DEVICE_CLASS_ALSA; - } else if (device_string == strstr(device_string, "null")) { + else if (device_string == strstr(device_string, "null")) return DM_DEVICE_CLASS_NULL; - } else if (device_string == strstr(device_string, "tizen")) { + else if (device_string == strstr(device_string, "tizen")) return DM_DEVICE_CLASS_TIZEN; - } else if (device_string == strstr(device_string, "acm")) { + else if (device_string == strstr(device_string, "acm")) return DM_DEVICE_CLASS_ACM; - } else { - return DM_DEVICE_CLASS_NONE; - } + + return DM_DEVICE_CLASS_NONE; } /* device_string looks like "alsa:0,0" or "tizen:0,0" @@ -359,46 +357,37 @@ static int device_string_get_name(const char *device_string, char *name) { } static pa_proplist* pulse_device_get_proplist(pa_object *pdevice) { - if (pa_sink_isinstance(pdevice)) - return PA_SINK(pdevice)->proplist; - else - return PA_SOURCE(pdevice)->proplist; + if (!pdevice) + return NULL; + + return pa_sink_isinstance(pdevice) ? PA_SINK(pdevice)->proplist : + PA_SOURCE(pdevice)->proplist; } static bool pulse_device_is_alsa(pa_object *pdevice) { const char *api_name = NULL; - pa_proplist *prop; + pa_proplist *prop = pulse_device_get_proplist(pdevice); - if ((prop = pulse_device_get_proplist(pdevice)) == NULL) + if (!prop) return false; - if ((api_name = pa_proplist_gets(prop, PA_PROP_DEVICE_API))) { - if (pa_safe_streq(api_name, DEVICE_API_ALSA)) { - return true; - } else { - return false; - } - } else { - return false; - } + if ((api_name = pa_proplist_gets(prop, PA_PROP_DEVICE_API))) + return pa_safe_streq(api_name, DEVICE_API_ALSA); + + return false; } static bool pulse_device_is_bluez(pa_object *pdevice) { const char *api_name = NULL; - pa_proplist *prop; + pa_proplist *prop = pulse_device_get_proplist(pdevice); - if ((prop = pulse_device_get_proplist(pdevice)) == NULL) + if (!prop) return false; - if ((api_name = pa_proplist_gets(prop, PA_PROP_DEVICE_API))) { - if (pa_safe_streq(api_name, DEVICE_API_BLUEZ)) { - return true; - } else { - return false; - } - } else { - return false; - } + if ((api_name = pa_proplist_gets(prop, PA_PROP_DEVICE_API))) + return pa_safe_streq(api_name, DEVICE_API_BLUEZ); + + return false; } static bool pulse_device_is_acm(pa_object *pdevice) { @@ -445,37 +434,26 @@ static bool pulse_device_is_tizenaudio(pa_object *pdevice) { static bool pulse_device_is_usb(pa_object *pdevice) { const char *bus_name = NULL; - pa_proplist *prop; + pa_proplist *prop = pulse_device_get_proplist(pdevice); - if ((prop = pulse_device_get_proplist(pdevice)) == NULL) + if (!prop) return false; - if ((bus_name = pa_proplist_gets(prop, PA_PROP_DEVICE_BUS))) { - if (pa_safe_streq(bus_name, DEVICE_BUS_USB)) { - return true; - } else { - return false; - } - } else { - pa_log_debug("This device doesn't have property '%s'", PA_PROP_DEVICE_BUS); - return false; - } + if ((bus_name = pa_proplist_gets(prop, PA_PROP_DEVICE_BUS))) + return pa_safe_streq(bus_name, DEVICE_BUS_USB); + + pa_log_debug("This device doesn't have property '%s'", PA_PROP_DEVICE_BUS); + return false; } static bool pulse_device_is_null(pa_object *pdevice) { - pa_sink *sink; - pa_source *source; - if (!pdevice) return false; - if (pa_sink_isinstance(pdevice)) { - sink = PA_SINK(pdevice); - return pa_safe_streq(sink->module->name, "module-null-sink"); - } else { - source = PA_SOURCE(pdevice); - return pa_safe_streq(source->module->name, "module-null-source"); - } + if (pa_sink_isinstance(pdevice)) + return pa_safe_streq(PA_SINK(pdevice)->module->name, "module-null-sink"); + else + return pa_safe_streq(PA_SOURCE(pdevice)->module->name, "module-null-source"); } static bool pulse_device_is_rtsp(pa_object *pdevice) { @@ -505,33 +483,24 @@ static const char* pulse_device_get_device_string_removed_argument(pa_object *pd const char *params_p, *params; char *end_p = NULL; int len = 0, prev_len = 0; - pa_sink *sink; - pa_source *source; - if (pa_sink_isinstance(pdevice)) { - sink = PA_SINK(pdevice); - params = sink->module->argument; - } else { - source = PA_SOURCE(pdevice); - params = source->module->argument; - } + params = pa_sink_isinstance(pdevice) ? PA_SINK(pdevice)->module->argument : + PA_SOURCE(pdevice)->module->argument; params_p = params; - if (!params) { + if (!params) return NULL; - } - if (!(device_string_p = strstr(params, "device="))) { + + if (!(device_string_p = strstr(params, "device="))) return params; - } next_p = device_string_p; - while (!isblank(*next_p)) { + while (!isblank(*next_p)) next_p++; - } - while (isblank(*next_p)) { + + while (isblank(*next_p)) next_p++; - } pa_strlcpy(removed_param, next_p, DEVICE_PARAM_STRING_MAX); @@ -554,38 +523,33 @@ static dm_device_class_t pulse_device_get_class(pa_object *pdevice) { return DM_DEVICE_CLASS_NONE; } - if (pulse_device_is_null(pdevice)) { + if (pulse_device_is_null(pdevice)) return DM_DEVICE_CLASS_NULL; - } else if (pulse_device_is_alsa(pdevice)) { + else if (pulse_device_is_alsa(pdevice)) return DM_DEVICE_CLASS_ALSA; - } else if (pulse_device_is_tizenaudio(pdevice)) { + else if (pulse_device_is_tizenaudio(pdevice)) return DM_DEVICE_CLASS_TIZEN; - } else if (pulse_device_is_bluez(pdevice)) { + else if (pulse_device_is_bluez(pdevice)) return DM_DEVICE_CLASS_BT; - } else if (pulse_device_is_acm(pdevice)) { + else if (pulse_device_is_acm(pdevice)) return DM_DEVICE_CLASS_ACM; - } else { - return DM_DEVICE_CLASS_NONE; - } + + return DM_DEVICE_CLASS_NONE; } static dm_device_direction_t pulse_device_get_direction(pa_object *pdevice) { - if (pa_sink_isinstance(pdevice)) - return DM_DEVICE_DIRECTION_OUT; - else - return DM_DEVICE_DIRECTION_IN; + return pa_sink_isinstance(pdevice) ? DM_DEVICE_DIRECTION_OUT : DM_DEVICE_DIRECTION_IN; } static bool pulse_device_is_monitor(pa_object *pdevice) { const char *device_class = NULL; - pa_proplist *prop; + pa_proplist *prop = pulse_device_get_proplist(pdevice); - prop = pulse_device_get_proplist(pdevice); + if (!prop) + return false; - if ((device_class = pa_proplist_gets(prop, PA_PROP_DEVICE_CLASS))) { - if (pa_safe_streq(device_class, DEVICE_CLASS_MONITOR)) - return true; - } + if ((device_class = pa_proplist_gets(prop, PA_PROP_DEVICE_CLASS))) + return pa_safe_streq(device_class, DEVICE_CLASS_MONITOR); return false; } @@ -671,9 +635,8 @@ static struct device_file_info* _device_manager_get_file_info(pa_idxset *file_in pa_assert(file_infos); PA_IDXSET_FOREACH(file_info, file_infos, file_idx) { - if (pa_safe_streq(file_info->device_string, device_string)) { + if (pa_safe_streq(file_info->device_string, device_string)) return file_info; - } } return NULL; @@ -694,7 +657,7 @@ static struct device_status_info* _device_status_new(const char *type, static void _device_status_free(struct device_status_info *status_info) { if (!status_info) - return ; + return; pa_xfree(status_info->type); pa_xfree(status_info->name); @@ -773,7 +736,7 @@ void device_set_detected(pa_device_manager *manager, const char *type, pa_assert(type); if (!device_type_is_need_detect(type)) - return ; + return; pa_log_info("Set device detected, type(%s) system_id(%s) -> %s(%d)", type, pa_strempty(system_id), @@ -832,10 +795,10 @@ pa_tz_device* device_list_get_device_by_id(pa_device_manager *manager, uint32_t pa_assert(manager->device_list); PA_IDXSET_FOREACH(device, manager->device_list, idx) { - if (pa_tz_device_get_id(device) == id) { + if (pa_tz_device_get_id(device) == id) return device; - } } + return NULL; } @@ -923,18 +886,11 @@ finish: static bool pulse_device_params_is_equal(pa_object *pdevice, const char *params) { const char *removed_module_args; const char *module_args; - pa_sink *sink; - pa_source *source; pa_assert(pdevice); - if (pa_sink_isinstance(pdevice)) { - sink = PA_SINK(pdevice); - module_args = sink->module->argument; - } else { - source = PA_SOURCE(pdevice); - module_args = source->module->argument; - } + module_args = pa_sink_isinstance(pdevice) ? PA_SINK(pdevice)->module->argument : + PA_SOURCE(pdevice)->module->argument; if (!params && !module_args) return 0; @@ -942,6 +898,7 @@ static bool pulse_device_params_is_equal(pa_object *pdevice, const char *params) return -1; removed_module_args = pulse_device_get_device_string_removed_argument(pdevice); + return device_params_is_equal(params, removed_module_args); } @@ -1189,13 +1146,10 @@ static int pulse_device_get_product_id(pa_object *pdevice) { static void pulse_device_set_use_internal_codec(pa_object *pdevice, bool use_internal_codec) { pa_assert(pdevice); - if (pa_sink_isinstance(pdevice)) { - pa_sink *sink = PA_SINK(pdevice); - sink->use_internal_codec = use_internal_codec; - } else { - pa_source *source = PA_SOURCE(pdevice); - source->use_internal_codec = use_internal_codec; - } + if (pa_sink_isinstance(pdevice)) + PA_SINK(pdevice)->use_internal_codec = use_internal_codec; + else + PA_SOURCE(pdevice)->use_internal_codec = use_internal_codec; } /* Get system_id of physical device, it should be a unique id */ @@ -1203,6 +1157,7 @@ static const char* pulse_device_get_system_id(pa_object *pdevice) { pa_proplist *prop; prop = pulse_device_get_proplist(pdevice); + if (pulse_device_is_usb(pdevice)) return pa_proplist_gets(prop, "sysfs.path"); else if (pulse_device_is_bluez(pdevice)) @@ -1217,8 +1172,8 @@ static const char* pulse_device_get_system_id(pa_object *pdevice) { else if (pulse_device_is_btsco(pdevice)) return pa_proplist_gets(prop, PA_PROP_DEVICE_DESCRIPTION); #endif - else - return NULL; + + return NULL; } static pa_sink* _core_get_sink(pa_core *core, const char *device_string, const char *params) { @@ -1231,12 +1186,10 @@ static pa_sink* _core_get_sink(pa_core *core, const char *device_string, const c PA_IDXSET_FOREACH(sink, core->sinks, device_idx) { if (pulse_device_is_monitor(PA_OBJECT(sink))) continue; - if (pulse_device_same_device_string(PA_OBJECT(sink), device_string)) { - if (params == NULL) - return sink; - else if (pulse_device_params_is_equal(PA_OBJECT(sink), params)) + + if (pulse_device_same_device_string(PA_OBJECT(sink), device_string)) + if (params == NULL || pulse_device_params_is_equal(PA_OBJECT(sink), params)) return sink; - } } return NULL; @@ -1252,12 +1205,10 @@ static pa_source* _core_get_source(pa_core *core, const char *device_string, con PA_IDXSET_FOREACH(source, core->sources, device_idx) { if (pulse_device_is_monitor(PA_OBJECT(source))) continue; - if (pulse_device_same_device_string(PA_OBJECT(source), device_string)) { - if (params == NULL) - return source; - else if (pulse_device_params_is_equal(PA_OBJECT(source), params)) + + if (pulse_device_same_device_string(PA_OBJECT(source), device_string)) + if (params == NULL || pulse_device_params_is_equal(PA_OBJECT(source), params)) return source; - } } return NULL; @@ -1688,6 +1639,7 @@ static void handle_internal_pulse_device(pa_object *pdevice, bool is_loaded, pa_ struct composite_type *ctype; pa_dynarray *ctypes; dm_device_direction_t direction; + int idx; pa_assert(pdevice); pa_assert(dm); @@ -1698,38 +1650,27 @@ static void handle_internal_pulse_device(pa_object *pdevice, bool is_loaded, pa_ /* Get types which this pulse_device belongs to */ if ((ctypes = pulse_device_get_belongs_type(pdevice, dm)) == NULL) { pa_log_debug("Failed to get device type. Skip this"); - return ; + return; } - if (is_loaded) { - /* Put this pulse_device to already loaded devices */ - for (int i = 0; i < pa_dynarray_size(ctypes); i++) { - ctype = pa_dynarray_get(ctypes, i); - pa_log_info("Found belongs type %s.%s", ctype->type, ctype->role); - if ((device = device_list_get_device(dm, ctype->type, ctype->role, NULL))) { - pa_log_info("Add this pulse_device to device(%u)", pa_tz_device_get_id(device)); + /* Put/Remove this pulse_device to already loaded devices */ + PA_DYNARRAY_FOREACH(ctype, ctypes, idx) { + pa_log_info("Found belongs type %s.%s", ctype->type, ctype->role); + if ((device = device_list_get_device(dm, ctype->type, ctype->role, NULL))) { + pa_log_info("%s this pulse_device to device(%u)", is_loaded ? "Add" : "Remove", pa_tz_device_get_id(device)); + if (is_loaded) { if (direction == DM_DEVICE_DIRECTION_OUT) pa_tz_device_add_sink(device, ctype->role, PA_SINK(pdevice)); else pa_tz_device_add_source(device, ctype->role, PA_SOURCE(pdevice)); } else { - pa_log_info("No device for %s.%s", ctype->type, ctype->role); - } - } - } else { - /* Remove this pulse_device from already loaded devices */ - for (int i = 0; i < pa_dynarray_size(ctypes); i++) { - ctype = pa_dynarray_get(ctypes, i); - pa_log_info("Found belongs type %s.%s", ctype->type, ctype->role); - if ((device = device_list_get_device(dm, ctype->type, ctype->role, NULL))) { - pa_log_info("Remove this pulse_device from device(%u)", pa_tz_device_get_id(device)); if (direction == DM_DEVICE_DIRECTION_OUT) pa_tz_device_remove_sink(device, PA_SINK(pdevice)); else pa_tz_device_remove_source(device, PA_SOURCE(pdevice)); - } else { - pa_log_info("No device for %s.%s", ctype->type, ctype->role); } + } else { + pa_log_info("No device for %s.%s", ctype->type, ctype->role); } } @@ -1772,10 +1713,10 @@ static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, pa_dev handle_external_btsco_pulse_device(PA_OBJECT(sink), true, dm); return PA_HOOK_OK; #endif - } else { - pa_log_debug("Don't care this sink"); } + pa_log_debug("Don't care this sink"); + return PA_HOOK_OK; } @@ -1821,10 +1762,10 @@ static pa_hook_result_t sink_unlink_hook_callback(pa_core *c, pa_sink *sink, pa_ handle_external_btsco_pulse_device(PA_OBJECT(sink), false, dm); return PA_HOOK_OK; #endif - } else { - pa_log_debug("Don't care this sink"); } + pa_log_debug("Don't care this sink"); + return PA_HOOK_OK; } @@ -1859,10 +1800,10 @@ static pa_hook_result_t source_put_hook_callback(pa_core *c, pa_source *source, pulse_device_set_use_internal_codec(PA_OBJECT(source), false); handle_external_btsco_pulse_device(PA_OBJECT(source), true, dm); #endif - } else { - pa_log_debug("Don't care this source"); } + pa_log_debug("Don't care this source"); + return PA_HOOK_OK; } @@ -1904,10 +1845,10 @@ static pa_hook_result_t source_unlink_hook_callback(pa_core *c, pa_source *sourc handle_external_btsco_pulse_device(PA_OBJECT(source), false, dm); return PA_HOOK_OK; #endif - } else { - pa_log_debug("Don't care this source"); } + pa_log_debug("Don't care this source"); + return PA_HOOK_OK; } @@ -1962,6 +1903,7 @@ static pa_hook_result_t sink_proplist_changed(pa_core *core, pa_sink *sink, pa_d 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; } @@ -2245,11 +2187,9 @@ void handle_device_connected(pa_device_manager *dm, const char *type, const char pa_tz_device_new_data_done(&data); } else { pa_log_error("Invalid case : not static direction"); - return ; + return; } } - - return ; } static int load_builtin_devices(pa_device_manager *dm) { @@ -2621,10 +2561,10 @@ static void device_type_status_init(pa_device_manager *manager) { pa_log_warn("Unknown earjack status : %d", earjack_status); } else if (device_type_is_equal(type, DEVICE_TYPE_BT_SCO)) { - device_set_detected(manager, type, NULL, NULL, DEVICE_DISCONNECTED); + device_set_detected(manager, type, NULL, NULL, DEVICE_DISCONNECTED); } else if (device_type_is_equal(type, DEVICE_TYPE_HDMI)) { - device_set_detected(manager, type, NULL, NULL, DEVICE_DISCONNECTED); + device_set_detected(manager, type, NULL, NULL, DEVICE_DISCONNECTED); } else if (device_type_is_equal(type, DEVICE_TYPE_FORWARDING)) { int miracast_wfd_status = 0; @@ -2639,7 +2579,6 @@ static void device_type_status_init(pa_device_manager *manager) { device_set_detected(manager, type, NULL, NULL, DEVICE_CONNECTED); } } - return ; } static pa_sink* load_sink(pa_device_manager *dm, const char *type, const char *role) { @@ -2849,8 +2788,6 @@ void unload_acm_sink(pa_device_manager *dm) { } unload_sink(dm, DEVICE_TYPE_NETWORK, DEVICE_ROLE_ACM); - - return; } pa_idxset* pa_device_manager_get_device_list(pa_device_manager *dm) { -- 2.7.4 From d972a340200f90a0b9afffb50d10cf139ebd1640 Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Wed, 23 Feb 2022 14:40:50 +0900 Subject: [PATCH 15/16] device-manager: Add null check in handle_device_connected() When the last parameter of handle_device_connected() is NULL, it gets the required structure again from the list referring to device-map.json. The result is checked now to avoid unwanted assertion by other functions. [Version] 15.0.2 [Issue Type] Improvement Change-Id: Id3c07d579b1d273386a6eab2e6618abf27baabf8 Signed-off-by: Sangchul Lee --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/device-manager.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index f19401e..667909a 100644 --- a/packaging/pulseaudio-modules-tizen.spec +++ b/packaging/pulseaudio-modules-tizen.spec @@ -2,7 +2,7 @@ Name: pulseaudio-modules-tizen Summary: Pulseaudio modules for Tizen -Version: 15.0.1 +Version: 15.0.2 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/device-manager.c b/src/device-manager.c index 510ef24..51fdba9 100644 --- a/src/device-manager.c +++ b/src/device-manager.c @@ -2128,8 +2128,10 @@ void handle_device_connected(pa_device_manager *dm, const char *type, const char pa_log_info("Device connected, type(%s) name(%s) system_id(%s) detected_type(%d)", type, pa_strempty(name), pa_strempty(system_id), detected_type); - if (!type_info) - type_info = _device_manager_get_type_info(dm->type_infos, type, NULL); + if (!type_info && !(type_info = _device_manager_get_type_info(dm->type_infos, type, NULL))) { + pa_log_error("failed to _device_manager_get_type_info(), check device-map.json first"); + return; + } if (device_type_is_equal(type, DEVICE_TYPE_BT_SCO)) { pa_tz_device_new_data_init(&data, dm->device_list, dm->comm, dm->dbus_conn); -- 2.7.4 From 6353d6c26a851101dbe98234748fb6bcecd07535 Mon Sep 17 00:00:00 2001 From: jungsup lee Date: Mon, 21 Feb 2022 13:17:50 +0900 Subject: [PATCH 16/16] tizenaudio-sink: Reset pollfd's revents after use revents should be cleared after handling POLLERR. mainloop send a lot of async message to I/O thread that is stucking on writing pcm. After that, I/O thread couldn't call poll api because of handling asyncq message. [Version] 15.0.3 [Issue Type] Bug fix Change-Id: Ib806cdd77a86fae648b08a5b5e1edc1ed60fbec5 Signed-off-by: jungsup lee --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/module-tizenaudio-sink.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 667909a..64ffcb3 100644 --- a/packaging/pulseaudio-modules-tizen.spec +++ b/packaging/pulseaudio-modules-tizen.spec @@ -2,7 +2,7 @@ Name: pulseaudio-modules-tizen Summary: Pulseaudio modules for Tizen -Version: 15.0.2 +Version: 15.0.3 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/module-tizenaudio-sink.c b/src/module-tizenaudio-sink.c index 9dc3226..6c56de9 100644 --- a/src/module-tizenaudio-sink.c +++ b/src/module-tizenaudio-sink.c @@ -150,6 +150,9 @@ static int build_pollfd(struct userdata *u) { u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1); pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL); ret = pa_hal_interface_pcm_get_fd(u->hal_interface, u->pcm_handle, &fd); + + pa_log_info("get fd(%d) of PCM device successfully", fd); + if (ret < 0 || fd < 0) { pa_log_error("Failed to get fd(%d) of PCM device %d", fd, ret); return -1; @@ -402,6 +405,7 @@ static int process_render(struct userdata *u, pa_usec_t now) { void *p; size_t frames_to_write, frame_size; uint32_t avail = 0; + pa_usec_t before_write, after_write; pa_assert(u); @@ -449,7 +453,12 @@ static int process_render(struct userdata *u, pa_usec_t now) { pa_sink_render_full(u->sink, frames_to_write * frame_size, &chunk); p = pa_memblock_acquire(chunk.memblock); + before_write = pa_rtclock_now(); pa_hal_interface_pcm_write(u->hal_interface, u->pcm_handle, (const char*)p + chunk.index, (uint32_t)frames_to_write); + after_write = pa_rtclock_now(); + + if (after_write - before_write > 10 * PA_USEC_PER_MSEC) + pa_log_warn("write takes long time %" PRIu64 " : (%" PRIu64 " - %" PRIu64 ")", 10 * PA_USEC_PER_MSEC, after_write, before_write); pa_memblock_release(chunk.memblock); pa_memblock_unref(chunk.memblock); @@ -532,9 +541,12 @@ static void thread_func(void *userdata) { pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL); revents = pollfd->revents; if (revents & ~POLLOUT) { - pa_log_debug("Poll error 0x%x occured, try recover.", revents); + pa_log_error("Poll error 0x%x(%d) occured, try recover.", revents, pollfd->fd); pa_hal_interface_pcm_recover(u->hal_interface, u->pcm_handle, revents); u->first = true; + + /* Need to reset revents because pa_rtpoll_run just returns without calling poll */ + pollfd->revents = 0; revents = 0; } else { //pa_log_debug("Poll wakeup.", revents); -- 2.7.4