From 7a1c85a7519bcf08ed8d63ddfcf8fff417a7dc2c Mon Sep 17 00:00:00 2001 From: Mok Jeongho Date: Fri, 20 Nov 2015 09:34:33 +0900 Subject: [PATCH 01/16] device-manager : modify to create sco profile item when sco open Previously, bt-sco profile_item is created and notified when HFP connection dbus signal comes, but it is little confused because bt-a2dp is created right after that and notify 'direction-changed'. So, we just create bt-sco profile item when we sco open internally, and then it will be notified. [Version] 5.0.16 [Profile] Common [Issue Type] Change logic Change-Id: I78f5f9652b4dbb4e0e8bc73edd547a415f49363e --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/device-manager.c | 42 ++++++++++++--------------------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index bbb70e5..81d9364 100644 --- a/packaging/pulseaudio-modules-tizen.spec +++ b/packaging/pulseaudio-modules-tizen.spec @@ -1,6 +1,6 @@ Name: pulseaudio-modules-tizen Summary: Pulseaudio modules for Tizen -Version: 5.0.14 +Version: 5.0.16 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/device-manager.c b/src/device-manager.c index 0d3a792..3165ad8 100644 --- a/src/device-manager.c +++ b/src/device-manager.c @@ -1321,7 +1321,7 @@ static dm_device* _device_item_set_active_profile(dm_device *device_item, const if (prev_active_profile != device_item->active_profile) { pa_log_debug("%s's active profile : %u", device_item->name, device_item->active_profile); - notify_device_info_changed(device_item, DM_DEVICE_CHANGED_INFO_SUBTYPE, device_item->dm); + notify_device_info_changed(device_item, DM_DEVICE_CHANGED_INFO_IO_DIRECTION, device_item->dm); } return device_item; @@ -1330,9 +1330,9 @@ static dm_device* _device_item_set_active_profile(dm_device *device_item, const static int get_profile_priority(const char *device_profile) { if (!device_profile) { return 0; - } else if (pa_streq(device_profile, DEVICE_PROFILE_BT_SCO)) { - return 1; } else if (pa_streq(device_profile, DEVICE_PROFILE_BT_A2DP)) { + return 1; + } else if (pa_streq(device_profile, DEVICE_PROFILE_BT_SCO)) { return 2; } else { return -1; @@ -1384,9 +1384,10 @@ static dm_device* _device_item_set_active_profile_auto(dm_device *device_item) { } } - if (prev_active_profile != device_item->active_profile) { + /* notify direction changed, if only new added profile is active */ + if ((prev_active_profile != PA_INVALID_INDEX) && (prev_active_profile != device_item->active_profile)) { pa_log_debug("%s's active profile : %u", device_item->name, device_item->active_profile); - notify_device_info_changed(device_item, DM_DEVICE_CHANGED_INFO_SUBTYPE, device_item->dm); + notify_device_info_changed(device_item, DM_DEVICE_CHANGED_INFO_IO_DIRECTION, device_item->dm); } return device_item; @@ -3196,10 +3197,8 @@ static int handle_device_status_changed(pa_device_manager *dm, const char *devic } else if (pa_streq(device_type, DEVICE_TYPE_BT) && device_profile && pa_streq(device_profile, DEVICE_PROFILE_BT_SCO)) { if (detected_status == BT_SCO_DISCONNECTED) { dm->bt_sco_status = DM_DEVICE_BT_SCO_STATUS_DISCONNECTED; - handle_device_disconnected(dm, device_type, device_profile, identifier); } else if (detected_status == BT_SCO_CONNECTED) { dm->bt_sco_status = DM_DEVICE_BT_SCO_STATUS_CONNECTED; - handle_device_connected(dm, device_type, device_profile, name, identifier, DEVICE_DETECTED_BT_SCO); } else { pa_log_warn("Got invalid bt-sco detected value"); return -1; @@ -4144,12 +4143,8 @@ int pa_device_manager_bt_sco_open(pa_device_manager *dm) { pa_assert(dm); pa_assert(dm->dbus_conn); - if (!(status_info = _device_manager_get_status_info(dm->device_status, DEVICE_TYPE_BT, DEVICE_PROFILE_BT_SCO, NULL))) { - pa_log_error("No status info for bt-sco"); - return -1; - } - if (!status_info->detected) { - pa_log_error("bt-sco not detected"); + if (dm->bt_sco_status != DM_DEVICE_BT_SCO_STATUS_CONNECTED) { + pa_log_error("bt-sco not connected"); return -1; } @@ -4165,11 +4160,8 @@ int pa_device_manager_bt_sco_open(pa_device_manager *dm) { } pa_log_debug("bt sco open end"); - - if (_device_item_set_active_profile(bt_device, DEVICE_PROFILE_BT_SCO) == NULL) { - pa_log_error("set bt sco as active profile failed"); - } dm->bt_sco_status = DM_DEVICE_BT_SCO_STATUS_OPENED; + handle_device_connected(dm, DEVICE_TYPE_BT, DEVICE_PROFILE_BT_SCO, NULL, NULL, DEVICE_DETECTED_BT_SCO); return 0; } @@ -4190,12 +4182,8 @@ int pa_device_manager_bt_sco_close(pa_device_manager *dm) { pa_assert(dm); pa_assert(dm->dbus_conn); - if (!(status_info = _device_manager_get_status_info(dm->device_status, DEVICE_TYPE_BT, DEVICE_PROFILE_BT_SCO, NULL))) { - pa_log_error("No status info for bt-sco"); - return -1; - } - if (!status_info->detected) { - pa_log_error("bt-sco not detected"); + if (dm->bt_sco_status != DM_DEVICE_BT_SCO_STATUS_OPENED) { + pa_log_error("bt-sco not opened"); return -1; } @@ -4209,11 +4197,11 @@ int pa_device_manager_bt_sco_close(pa_device_manager *dm) { pa_log_error("Failed to bt sco close"); return -1; } - pa_log_debug("bt sco close end"); - if (_device_item_set_active_profile_auto(bt_device) == NULL) { - pa_log_error("set active profile auto failed"); - } + dm->bt_sco_status = DM_DEVICE_BT_SCO_STATUS_CONNECTED; + handle_device_disconnected(dm, DEVICE_TYPE_BT, DEVICE_PROFILE_BT_SCO, NULL); + + pa_log_debug("bt sco close end"); return 0; } -- 2.7.4 From 55c42a679e46421b5df2058626e8587a56c9dd44 Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Fri, 20 Nov 2015 11:22:36 +0900 Subject: [PATCH 02/16] policy/stream-manager: Support a new routing policy for having priority for the last connected device Added STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED route type. When a stream that has this route type(it should be defined to route-type with "auto-last-connected" in stream-map.json), it would use a device which is the most recently connected. Fix mute bug regarding moving sink-inputs. Do mute/unmute in case of moving source-ouputs. [Version] 5.0.17 [Profile] Common [Issue Type] Feature enhancement Change-Id: I139711b0178ba6f03244735cd728066ff7746c3c Signed-off-by: Sangchul Lee --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/device-manager.c | 14 + src/device-manager.h | 1 + src/module-policy.c | 451 +++++++++++++++++++------------- src/stream-manager-priv.h | 4 +- src/stream-manager.c | 313 ++++++++++++---------- src/stream-manager.h | 11 +- 7 files changed, 471 insertions(+), 325 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 81d9364..dc14501 100644 --- a/packaging/pulseaudio-modules-tizen.spec +++ b/packaging/pulseaudio-modules-tizen.spec @@ -1,6 +1,6 @@ Name: pulseaudio-modules-tizen Summary: Pulseaudio modules for Tizen -Version: 5.0.16 +Version: 5.0.17 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/device-manager.c b/src/device-manager.c index 3165ad8..1b3724c 100644 --- a/src/device-manager.c +++ b/src/device-manager.c @@ -332,6 +332,10 @@ typedef struct dm_device_profile { /* device belongs to */ dm_device *device_item; + + /* creation time */ + pa_usec_t creation_time; + } dm_device_profile; /* @@ -1559,6 +1563,7 @@ static dm_device_profile* create_device_profile(const char *device_profile, dm_d profile_item->capture_state = DM_DEVICE_STATE_DEACTIVATED; profile_item->playback_devices = playback; profile_item->capture_devices = capture; + profile_item->creation_time = pa_rtclock_now(); return profile_item; } @@ -4117,6 +4122,15 @@ dm_device_direction_t pa_device_manager_get_device_direction(dm_device *device_i return profile_item->direction; } +pa_usec_t pa_device_manager_get_device_creation_time(dm_device *device_item) { + dm_device_profile *profile_item; + + pa_assert(device_item); + pa_assert(profile_item = _device_item_get_active_profile(device_item)); + + return profile_item->creation_time; +} + pa_bool_t pa_device_manager_is_device_use_internal_codec(dm_device *device_item, dm_device_direction_t direction, const char *role) { pa_sink *sink; pa_source *source; diff --git a/src/device-manager.h b/src/device-manager.h index 335ada9..303a081 100644 --- a/src/device-manager.h +++ b/src/device-manager.h @@ -73,6 +73,7 @@ uint32_t pa_device_manager_get_device_id(dm_device *device_item); const char* pa_device_manager_get_device_type(dm_device *device_item); const char* pa_device_manager_get_device_subtype(dm_device *device_item); dm_device_direction_t pa_device_manager_get_device_direction(dm_device *device_item); +pa_usec_t pa_device_manager_get_device_creation_time(dm_device *device_item); pa_bool_t pa_device_manager_is_device_use_internal_codec(dm_device *device_item, dm_device_direction_t direction, const char *role); /* set/get device state */ diff --git a/src/module-policy.c b/src/module-policy.c index 080bf16..454cae4 100644 --- a/src/module-policy.c +++ b/src/module-policy.c @@ -296,11 +296,13 @@ static pa_hook_result_t select_proper_sink_or_source_hook_cb(pa_core *c, pa_stre uint32_t m_idx = 0; uint32_t conn_idx = 0; uint32_t *device_id = NULL; + uint32_t dm_device_id = 0; const char *device_type = NULL; const char *dm_device_type = NULL; const char *dm_device_subtype = NULL; + dm_device_direction_t dm_device_direction = DM_DEVICE_DIRECTION_NONE; dm_device *device = NULL; - dm_device_direction_t device_direction = DM_DEVICE_DIRECTION_NONE; + dm_device *latest_device = NULL; pa_idxset *conn_devices = NULL; pa_sink *sink = NULL; pa_sink *null_sink = NULL; @@ -311,7 +313,9 @@ static pa_hook_result_t select_proper_sink_or_source_hook_cb(pa_core *c, pa_stre char *args = NULL; void *s = NULL; uint32_t s_idx = 0; - pa_bool_t is_found = FALSE; + pa_bool_t is_found = 0; + pa_usec_t creation_time = 0; + pa_usec_t latest_creation_time = 0; pa_assert(c); pa_assert(data); @@ -327,49 +331,79 @@ static pa_hook_result_t select_proper_sink_or_source_hook_cb(pa_core *c, pa_stre return PA_HOOK_OK; } - if ((data->route_type == STREAM_ROUTE_TYPE_AUTO || data->route_type == STREAM_ROUTE_TYPE_AUTO_ALL) && data->idx_avail_devices) { + if ((data->route_type <= STREAM_ROUTE_TYPE_AUTO_ALL) && data->idx_avail_devices) { /* get current connected devices */ conn_devices = pa_device_manager_get_device_list(u->device_manager); - PA_IDXSET_FOREACH(device_type, data->idx_avail_devices, idx) { - pa_log_debug("[SELECT][AUTO(_ALL)] avail_device[%u] for this role[%-16s]: type[%-16s]", idx, data->stream_role, device_type); - PA_IDXSET_FOREACH(device, conn_devices, conn_idx) { - dm_device_type = pa_device_manager_get_device_type(device); - dm_device_subtype = pa_device_manager_get_device_subtype(device); - device_direction = pa_device_manager_get_device_direction(device); - pa_log_debug(" -- conn_devices, type[%-16s], subtype[%-5s], direction[0x%x]", dm_device_type, dm_device_subtype, device_direction); - if (pa_streq(device_type, dm_device_type) && IS_AVAILABLE_DIRECTION(data->stream_type, device_direction)) { - pa_log_debug(" ** found a matched device: type[%-16s], direction[0x%x]", device_type, device_direction); - is_found = TRUE; - if (data->stream_type == STREAM_SINK_INPUT) { - if (data->route_type == STREAM_ROUTE_TYPE_AUTO_ALL && u->module_combine_sink) { - *(data->proper_sink) = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK); - pa_log_debug(" -- found the combine-sink, set it to the sink"); + if (data->route_type == STREAM_ROUTE_TYPE_AUTO || data->route_type == STREAM_ROUTE_TYPE_AUTO_ALL) { + PA_IDXSET_FOREACH(device_type, data->idx_avail_devices, idx) { + pa_log_info("[SELECT][AUTO(_ALL)] avail_device[%u] for this role[%-16s]: type[%-16s]", idx, data->stream_role, device_type); + PA_IDXSET_FOREACH(device, conn_devices, conn_idx) { + dm_device_type = pa_device_manager_get_device_type(device); + dm_device_subtype = pa_device_manager_get_device_subtype(device); + dm_device_direction = pa_device_manager_get_device_direction(device); + dm_device_id = pa_device_manager_get_device_id(device); + pa_log_debug(" -- type[%-16s], subtype[%-5s], direction[0x%x], id[%u]", + dm_device_type, dm_device_subtype, dm_device_direction, dm_device_id); + if (pa_streq(device_type, dm_device_type) && IS_AVAILABLE_DIRECTION(data->stream_type, dm_device_direction)) { + is_found = TRUE; + pa_log_info(" ** found a matched device: type[%-16s], direction[0x%x]", dm_device_type, dm_device_direction); + if (data->stream_type == STREAM_SINK_INPUT) { + if (data->route_type == STREAM_ROUTE_TYPE_AUTO_ALL && u->module_combine_sink) { + *(data->proper_sink) = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK); + pa_log_debug(" -- found the combine-sink, set it to the sink"); + } else + *(data->proper_sink) = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL); } else - *(data->proper_sink) = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL); - } else - *(data->proper_source) = pa_device_manager_get_source(device, DEVICE_ROLE_NORMAL); + *(data->proper_source) = pa_device_manager_get_source(device, DEVICE_ROLE_NORMAL); + break; + } + } + if (is_found && data->route_type == STREAM_ROUTE_TYPE_AUTO) break; + } + } else if (data->route_type == STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED) { + PA_IDXSET_FOREACH(device_type, data->idx_avail_devices, idx) { + pa_log_info("[SELECT][AUTO_LAST_CONN] avail_device[%u] for this role[%-16s]: type[%-16s]", idx, data->stream_role, device_type); + PA_IDXSET_FOREACH(device, conn_devices, conn_idx) { + dm_device_type = pa_device_manager_get_device_type(device); + dm_device_subtype = pa_device_manager_get_device_subtype(device); + dm_device_direction = pa_device_manager_get_device_direction(device); + dm_device_id = pa_device_manager_get_device_id(device); + creation_time = pa_device_manager_get_device_creation_time(device); + pa_log_debug(" -- type[%-16s], subtype[%-5s], direction[0x%x], id[%u], creation_time[%llu]", + dm_device_type, dm_device_subtype, dm_device_direction, dm_device_id, creation_time); + if (pa_streq(device_type, dm_device_type) && IS_AVAILABLE_DIRECTION(data->stream_type, dm_device_direction)) { + if (!latest_device || (latest_creation_time <= creation_time)) { + latest_device = device; + latest_creation_time = creation_time; + pa_log_info(" ** updated the last connected device: type[%-16s], direction[0x%x]", dm_device_type, dm_device_direction); + } + } } } - /* update activated device if it has the AUTO route type */ - if (data->route_type == STREAM_ROUTE_TYPE_AUTO && is_found) { + /* update active device info. */ + if (latest_device) { + if (data->stream_type == STREAM_SINK_INPUT) + *(data->proper_sink) = pa_device_manager_get_sink(latest_device, DEVICE_ROLE_NORMAL); + else + *(data->proper_source) = pa_device_manager_get_source(latest_device, DEVICE_ROLE_NORMAL); + pa_proplist_sets(GET_STREAM_NEW_PROPLIST(data->stream, data->stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, dm_device_type); - break; } } } else if (data->route_type == STREAM_ROUTE_TYPE_MANUAL && data->idx_manual_devices && data->idx_avail_devices) { PA_IDXSET_FOREACH(device_type, data->idx_avail_devices, idx) { - pa_log_debug("[SELECT][MANUAL] avail_device[%u] for this role[%-16s]: type[%-16s]", idx, data->stream_role, device_type); + pa_log_info("[SELECT][MANUAL] avail_device[%u] for this role[%-16s]: type[%-16s]", idx, data->stream_role, device_type); PA_IDXSET_FOREACH(device_id, data->idx_manual_devices, m_idx) { if ((device = pa_device_manager_get_device_by_id(u->device_manager, *device_id))) { dm_device_type = pa_device_manager_get_device_type(device); dm_device_subtype = pa_device_manager_get_device_subtype(device); - device_direction = pa_device_manager_get_device_direction(device); - pa_log_debug(" -- manual_devices, type[%-16s], subtype[%-5s], direction[0x%x], device id[%u]", - dm_device_type, dm_device_subtype, device_direction, *device_id); - if (pa_streq(device_type, dm_device_type) && IS_AVAILABLE_DIRECTION(data->stream_type, device_direction)) { - pa_log_debug(" ** found a matched device: type[%-16s], direction[0x%x]", device_type, device_direction); + dm_device_direction = pa_device_manager_get_device_direction(device); + pa_log_debug(" -- type[%-16s], subtype[%-5s], direction[0x%x], device id[%u]", + dm_device_type, dm_device_subtype, dm_device_direction, *device_id); + if (pa_streq(device_type, dm_device_type) && IS_AVAILABLE_DIRECTION(data->stream_type, dm_device_direction)) { + pa_log_info(" ** found a matched device: type[%-16s], direction[0x%x]", device_type, dm_device_direction); if (data->stream_type == STREAM_SINK_INPUT) { if ((*(data->proper_sink)) == null_sink) pa_sink_input_move_to((pa_sink_input*)(data->stream), pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL), FALSE); @@ -388,31 +422,31 @@ static pa_hook_result_t select_proper_sink_or_source_hook_cb(pa_core *c, pa_stre } else if (data->route_type == STREAM_ROUTE_TYPE_MANUAL_EXT && data->idx_manual_devices && data->idx_avail_devices) { PA_IDXSET_FOREACH(device_type, data->idx_avail_devices, idx) { - pa_log_debug("[SELECT][MANUAL_EXT] avail_device[%u] for this role[%-16s]: type[%-16s]", idx, data->stream_role, device_type); + pa_log_info("[SELECT][MANUAL_EXT] avail_device[%u] for this role[%-16s]: type[%-16s]", idx, data->stream_role, device_type); PA_IDXSET_FOREACH(device_id, data->idx_manual_devices, m_idx) { if ((device = pa_device_manager_get_device_by_id(u->device_manager, *device_id))) { dm_device_type = pa_device_manager_get_device_type(device); dm_device_subtype = pa_device_manager_get_device_subtype(device); - device_direction = pa_device_manager_get_device_direction(device); - pa_log_debug(" -- manual_devices, type[%-16s], subtype[%-5s], direction[0x%x], device id[%u]", - dm_device_type, dm_device_subtype, device_direction, *device_id); - if (pa_streq(device_type, dm_device_type) && IS_AVAILABLE_DIRECTION(data->stream_type, device_direction)) { - pa_log_debug(" ** found a matched device: type[%-16s], direction[0x%x]", device_type, device_direction); + dm_device_direction = pa_device_manager_get_device_direction(device); + pa_log_debug(" -- type[%-16s], subtype[%-5s], direction[0x%x], device id[%u]", + dm_device_type, dm_device_subtype, dm_device_direction, *device_id); + if (pa_streq(device_type, dm_device_type) && IS_AVAILABLE_DIRECTION(data->stream_type, dm_device_direction)) { + pa_log_info(" ** found a matched device: type[%-16s], direction[0x%x]", device_type, dm_device_direction); /* currently, we support two sinks for combining */ if (data->stream_type == STREAM_SINK_INPUT) { if (!combine_sink_arg1) { if ((sink = combine_sink_arg1 = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL))) - pa_log_debug (" -- combine_sink_arg1[%s], combine_sink_arg2[%p]", sink->name, combine_sink_arg2); + pa_log_debug(" -- combine_sink_arg1[%s], combine_sink_arg2[%p]", sink->name, combine_sink_arg2); else - pa_log_warn (" -- could not get combine_sink_arg1"); + pa_log_warn(" -- could not get combine_sink_arg1"); } else if (!combine_sink_arg2) { sink = combine_sink_arg2 = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL); if(sink && !pa_streq(sink->name, combine_sink_arg1->name)) { - pa_log_debug (" -- combine_sink_arg2[%s]", sink->name); + pa_log_debug(" -- combine_sink_arg2[%s]", sink->name); /* load combine sink */ if (!u->module_combine_sink_for_ex) { args = pa_sprintf_malloc("sink_name=%s slaves=\"%s,%s\"", SINK_NAME_COMBINED_EX, combine_sink_arg1->name, combine_sink_arg2->name); - pa_log_debug (" -- combined sink is not prepared, now load module[%s]", args); + pa_log_info(" -- combined sink is not prepared, now load module[%s]", args); u->module_combine_sink_for_ex = pa_module_load(u->core, MODULE_COMBINE_SINK, args); pa_xfree(args); } @@ -467,11 +501,14 @@ static pa_hook_result_t select_proper_sink_or_source_hook_cb(pa_core *c, pa_stre * Regarding the state of an external device, those is handled in device-manager.c */ static void set_device_state_if_using_internal_codec(dm_device *device, stream_type_t stream_type, dm_device_state_t device_state) { pa_bool_t use_internal_codec = FALSE; + dm_device_direction_t direction; pa_assert(device); - if ((use_internal_codec = pa_device_manager_is_device_use_internal_codec(device, CONVERT_TO_DEVICE_DIRECTION(stream_type), DEVICE_ROLE_NORMAL))) - pa_device_manager_set_device_state(device, CONVERT_TO_DEVICE_DIRECTION(stream_type), device_state); + direction = pa_device_manager_get_device_direction(device); + if (IS_AVAILABLE_DIRECTION(stream_type, direction)) + if ((use_internal_codec = pa_device_manager_is_device_use_internal_codec(device, CONVERT_TO_DEVICE_DIRECTION(stream_type), DEVICE_ROLE_NORMAL))) + pa_device_manager_set_device_state(device, CONVERT_TO_DEVICE_DIRECTION(stream_type), device_state); return; } @@ -541,17 +578,17 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ hal_route_info route_info = {NULL, NULL, 0}; uint32_t conn_idx = 0; uint32_t *device_id = NULL; - uint32_t device_idx = 0; + uint32_t dm_device_id = 0; stream_route_type_t route_type; const char *device_type = NULL; - const char *cur_device_type = NULL; - const char *role = NULL; dm_device *device = NULL; dm_device *_device = NULL; + dm_device *latest_device = NULL; const char *dm_device_type = NULL; const char *dm_device_subtype = NULL; - dm_device_state_t device_state = DM_DEVICE_STATE_DEACTIVATED; - dm_device_direction_t device_direction = DM_DEVICE_DIRECTION_NONE; + dm_device_state_t dm_device_state = DM_DEVICE_STATE_DEACTIVATED; + dm_device_direction_t dm_device_direction = DM_DEVICE_DIRECTION_NONE; + io_direction_t hal_direction; void *s = NULL; pa_sink *sink = NULL; pa_source *source = NULL; @@ -562,7 +599,8 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ pa_sink *null_sink = NULL; char *args = NULL; pa_bool_t use_internal_codec = FALSE; - pa_bool_t available = FALSE; + pa_usec_t creation_time = 0; + pa_usec_t latest_creation_time = 0; pa_assert(c); pa_assert(data); @@ -582,10 +620,10 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ /* set device state to deactivate */ PA_IDXSET_FOREACH(device, conn_devices, conn_idx) { dm_device_type = pa_device_manager_get_device_type(device); - device_state = pa_device_manager_get_device_state(device, CONVERT_TO_DEVICE_DIRECTION(data->stream_type)); - device_direction = pa_device_manager_get_device_direction(device); - if (device_state == DM_DEVICE_STATE_ACTIVATED && IS_AVAILABLE_DIRECTION(data->stream_type, device_direction)) { - pa_log_debug("[ROUTE][RESET] found a matched device and set state to DE-ACTIVATED: type[%s], direction[0x%x]", dm_device_type, device_direction); + dm_device_state = pa_device_manager_get_device_state(device, CONVERT_TO_DEVICE_DIRECTION(data->stream_type)); + dm_device_direction = pa_device_manager_get_device_direction(device); + if (dm_device_state == DM_DEVICE_STATE_ACTIVATED && IS_AVAILABLE_DIRECTION(data->stream_type, dm_device_direction)) { + pa_log_info("[ROUTE][RESET] found a matched device and set state to DE-ACTIVATED: type[%s], direction[0x%x]", dm_device_type, dm_device_direction); set_device_state_if_using_internal_codec(device, data->stream_type, DM_DEVICE_STATE_DEACTIVATED); } } @@ -595,7 +633,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ /* unload combine sink */ if (data->stream_type==STREAM_SINK_INPUT && u->module_combine_sink) { - pa_log_debug ("[ROUTE][RESET] unload module[%s]", SINK_NAME_COMBINED); + pa_log_info("[ROUTE][RESET] unload module[%s]", SINK_NAME_COMBINED); combine_sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK); null_sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_NULL, PA_NAMEREG_SINK); if (!combine_sink || !null_sink) @@ -611,163 +649,205 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ u->module_combine_sink = NULL; } - } else if ((data->route_type == STREAM_ROUTE_TYPE_AUTO || data->route_type == STREAM_ROUTE_TYPE_AUTO_ALL) && data->idx_avail_devices) { + } else if ((data->route_type <= STREAM_ROUTE_TYPE_AUTO_ALL) && data->idx_avail_devices) { /* update BT SCO: close */ set_bt_sco_state(u->device_manager, FALSE); /* get current connected devices */ conn_devices = pa_device_manager_get_device_list(u->device_manager); - PA_IDXSET_FOREACH(device_type, data->idx_avail_devices, idx) { - pa_log_debug("[ROUTE][AUTO(_ALL)] avail_device[%u] for this role[%-16s]: type[%-16s]", idx, route_info.role, device_type); - PA_IDXSET_FOREACH(device, conn_devices, conn_idx) { - dm_device_type = pa_device_manager_get_device_type(device); - dm_device_subtype = pa_device_manager_get_device_subtype(device); - device_direction = pa_device_manager_get_device_direction(device); - device_idx = pa_device_manager_get_device_id(device); - pa_log_debug(" -- conn_devices, type[%-16s], subtype[%-5s], direction[0x%x], id[%u]", - dm_device_type, dm_device_subtype, device_direction, device_idx); - if (pa_streq(device_type, dm_device_type) && IS_AVAILABLE_DIRECTION(data->stream_type, device_direction)) { - pa_log_debug(" ** found a matched device: type[%-16s], direction[0x%x]", device_type, device_direction); - use_internal_codec = pa_device_manager_is_device_use_internal_codec(device, CONVERT_TO_DEVICE_DIRECTION(data->stream_type), DEVICE_ROLE_NORMAL); - if (use_internal_codec) { - route_info.num_of_devices++; - route_info.device_infos = pa_xrealloc(route_info.device_infos, sizeof(hal_device_info)*route_info.num_of_devices); - route_info.device_infos[route_info.num_of_devices-1].type = dm_device_type; - route_info.device_infos[route_info.num_of_devices-1].direction = (data->stream_type==STREAM_SINK_INPUT)?DIRECTION_OUT:DIRECTION_IN; - route_info.device_infos[route_info.num_of_devices-1].id = device_idx; - pa_log_debug(" ** found a matched device and set state to ACTIVATED: type[%-16s], direction[0x%x], id[%u]", - route_info.device_infos[route_info.num_of_devices-1].type, device_direction, device_idx); - /* set device state to activated */ - set_device_state_if_using_internal_codec(device, data->stream_type, DM_DEVICE_STATE_ACTIVATED); - } else - pa_log_debug(" -- it does not use internal audio codec, skip it"); - break; + if (data->route_type == STREAM_ROUTE_TYPE_AUTO || data->route_type == STREAM_ROUTE_TYPE_AUTO_ALL) { + PA_IDXSET_FOREACH(device_type, data->idx_avail_devices, idx) { + pa_log_info("[ROUTE][AUTO(_ALL)] avail_device[%u] for this role[%-16s]: type[%-16s]", idx, route_info.role, device_type); + PA_IDXSET_FOREACH(device, conn_devices, conn_idx) { + dm_device_type = pa_device_manager_get_device_type(device); + dm_device_subtype = pa_device_manager_get_device_subtype(device); + dm_device_direction = pa_device_manager_get_device_direction(device); + dm_device_id = pa_device_manager_get_device_id(device); + pa_log_debug(" -- type[%-16s], subtype[%-5s], direction[0x%x], id[%u]", + dm_device_type, dm_device_subtype, dm_device_direction, dm_device_id); + if (pa_streq(device_type, dm_device_type) && IS_AVAILABLE_DIRECTION(data->stream_type, dm_device_direction)) { + pa_log_debug(" ** found a matched device: type[%-16s], direction[0x%x]", dm_device_type, dm_device_direction); + use_internal_codec = pa_device_manager_is_device_use_internal_codec(device, CONVERT_TO_DEVICE_DIRECTION(data->stream_type), DEVICE_ROLE_NORMAL); + if (use_internal_codec) { + hal_direction = (data->stream_type==STREAM_SINK_INPUT)?DIRECTION_OUT:DIRECTION_IN; + route_info.num_of_devices++; + route_info.device_infos = pa_xrealloc(route_info.device_infos, sizeof(hal_device_info)*route_info.num_of_devices); + route_info.device_infos[route_info.num_of_devices-1].type = dm_device_type; + route_info.device_infos[route_info.num_of_devices-1].direction = hal_direction; + route_info.device_infos[route_info.num_of_devices-1].id = dm_device_id; + pa_log_info(" ** found a matched device and set state to ACTIVATED: type[%-16s], direction[0x%x], id[%u]", + route_info.device_infos[route_info.num_of_devices-1].type, hal_direction, dm_device_id); + /* set device state to activated */ + set_device_state_if_using_internal_codec(device, data->stream_type, DM_DEVICE_STATE_ACTIVATED); + } else + pa_log_debug(" -- it does not use internal audio codec, skip it"); + break; + } } - } - if (data->route_type == STREAM_ROUTE_TYPE_AUTO && device) { - /* check if this device uses internal codec */ - use_internal_codec = pa_device_manager_is_device_use_internal_codec(device, CONVERT_TO_DEVICE_DIRECTION(data->stream_type), DEVICE_ROLE_NORMAL); + if (device == NULL) + continue; - if(use_internal_codec) { - /* set other device's state to deactivated */ - PA_IDXSET_FOREACH(_device, conn_devices, conn_idx) { - if (device == _device) - continue; - set_device_state_if_using_internal_codec(_device, data->stream_type, DM_DEVICE_STATE_DEACTIVATED); + if (data->route_type == STREAM_ROUTE_TYPE_AUTO) { + /* check if this device uses internal codec */ + use_internal_codec = pa_device_manager_is_device_use_internal_codec(device, CONVERT_TO_DEVICE_DIRECTION(data->stream_type), DEVICE_ROLE_NORMAL); + if(use_internal_codec) { + /* set other device's state to deactivated */ + PA_IDXSET_FOREACH(_device, conn_devices, conn_idx) { + if (device == _device) + continue; + set_device_state_if_using_internal_codec(_device, data->stream_type, DM_DEVICE_STATE_DEACTIVATED); + } } - } + if (data->origins_from_new_data) + pa_proplist_sets(GET_STREAM_NEW_PROPLIST(data->stream, data->stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, dm_device_type); + else + pa_proplist_sets(GET_STREAM_PROPLIST(data->stream, data->stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, dm_device_type); /* move sink-inputs/source-outputs if needed */ if (data->stream_type == STREAM_SINK_INPUT) sink = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL); - else if (data->stream_type == STREAM_SOURCE_OUTPUT) - source = pa_device_manager_get_source(device, DEVICE_ROLE_NORMAL); - - if (data->idx_streams) { /* idx_streams: data->stream->sink->sink_inputs/data->stream->source->source_outputs */ - PA_IDXSET_FOREACH (s, data->idx_streams, s_idx) { - /* check if the route type is AUTO and new device is available */ - if (!pa_stream_manager_get_route_type(s, FALSE, data->stream_type, &route_type)) { - pa_log_debug(" -- idx(%u), route_type(%d)", s_idx, route_type); - if (route_type == STREAM_ROUTE_TYPE_AUTO) { + + /* unload combine sink */ + if (data->stream_type==STREAM_SINK_INPUT && u->module_combine_sink) { + if ((combine_sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK))) { + PA_IDXSET_FOREACH (s, combine_sink->inputs, s_idx) { + pa_sink_input_move_to(s, sink, FALSE); + pa_log_debug("[ROUTE][AUTO] *** sink-input(%p,%u) moves to sink(%p,%s)", s, ((pa_sink_input*)s)->index, sink, sink->name); + } + pa_sink_suspend(combine_sink, TRUE, PA_SUSPEND_USER); + } else + pa_log_error("[ROUTE][AUTO] could not get combine_sink"); + + pa_log_debug("[ROUTE][AUTO] unload module[%s]", SINK_NAME_COMBINED); + pa_module_unload(u->core, u->module_combine_sink, TRUE); + u->module_combine_sink = NULL; + } + break; + + } else if (data->route_type == STREAM_ROUTE_TYPE_AUTO_ALL) { + /* find the proper sink/source */ + /* currently, we support two sinks for combining */ + if (data->stream_type == STREAM_SINK_INPUT && u->module_combine_sink) { + sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK); + pa_log_info("[ROUTE][AUTO_ALL] found the combine_sink already existed"); + } else if (data->stream_type == STREAM_SINK_INPUT && !combine_sink_arg1) { + sink = combine_sink_arg1 = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL); + pa_log_debug("[ROUTE][AUTO_ALL] combine_sink_arg1[%s], combine_sink_arg2[%p]", sink->name, combine_sink_arg2); + } else if (data->stream_type == STREAM_SINK_INPUT && !combine_sink_arg2) { + sink = combine_sink_arg2 = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL); + if(sink && !pa_streq(sink->name, combine_sink_arg1->name)) { + pa_log_debug("[ROUTE][AUTO_ALL] combine_sink_arg2[%s]", sink->name); + /* load combine sink */ + if (!u->module_combine_sink) { + args = pa_sprintf_malloc("sink_name=%s slaves=\"%s,%s\"", SINK_NAME_COMBINED, combine_sink_arg1->name, combine_sink_arg2->name); + pa_log_info("[ROUTE][AUTO_ALL] combined sink is not prepared, now load module[%s]", args); + u->module_combine_sink = pa_module_load(u->core, MODULE_COMBINE_SINK, args); + pa_xfree(args); + } + sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK); + PA_IDXSET_FOREACH (s, combine_sink_arg1->inputs, s_idx) { + if (s == data->stream) { + pa_sink_input_move_to(s, sink, FALSE); + pa_log_debug("[ROUTE][AUTO_ALL] *** sink-#if 0input(%p,%u) moves to sink(%p,%s)", s, ((pa_sink_input*)s)->index, sink, sink->name); + } + } + } + } else if (data->stream_type == STREAM_SOURCE_OUTPUT) + source = pa_device_manager_get_source(device, DEVICE_ROLE_NORMAL); + + if (data->origins_from_new_data) { + if (data->stream_type == STREAM_SINK_INPUT) + *(data->proper_sink) = sink; + else + *(data->proper_source) = source; + } else { + /* move sink-inputs/source-outputs if needed */ + if (data->idx_streams) { + PA_IDXSET_FOREACH (s, data->idx_streams, s_idx) { /* data->idx_streams: null_sink */ if ((sink && (sink != ((pa_sink_input*)s)->sink)) || (source && (source != ((pa_source_output*)s)->source))) { - if ((cur_device_type = pa_proplist_gets(GET_STREAM_PROPLIST(s, data->stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV))) { - role = pa_proplist_gets(GET_STREAM_PROPLIST(s, data->stream_type), PA_PROP_MEDIA_ROLE); - pa_stream_manager_is_available_device_for_auto_route(cur_device_type, dm_device_type, role, data->stream_type, &available, u->stream_manager); - if (available) { - if (data->stream_type == STREAM_SINK_INPUT) { - pa_sink_input_move_to(s, sink, FALSE); - pa_log_debug("[ROUTE][AUTO] *** sink-input(%p,%u) moves to sink(%p,%s)", s, ((pa_sink_input*)s)->index, sink, sink->name); - } else { - pa_source_output_move_to(s, source, FALSE); - pa_log_debug("[ROUTE][AUTO] *** source-output(%p,%u) moves to source(%p,%s)", s, ((pa_source_output*)s)->index, source, source->name); - } - /* update activated device if it has the AUTO route type */ - pa_proplist_sets(GET_STREAM_PROPLIST(s, data->stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, dm_device_type); + if (!pa_stream_manager_get_route_type(s, FALSE, data->stream_type, &route_type) && (route_type == STREAM_ROUTE_TYPE_AUTO_ALL)) { + if (data->stream_type == STREAM_SINK_INPUT) { + pa_sink_input_move_to(s, sink, FALSE); + pa_log_debug("[ROUTE][AUTO_ALL] *** sink-input(%p,%u) moves to sink(%p,%s)", + s, ((pa_sink_input*)s)->index, sink, sink->name); + } else if (data->stream_type == STREAM_SOURCE_OUTPUT) { + pa_source_output_move_to(s, source, FALSE); + pa_log_debug("[ROUTE][AUTO_ALL] *** source-output(%p,%u) moves to source(%p,%s)", + s, ((pa_source_output*)s)->index, source, source->name); } } - } else if ((sink && (sink == ((pa_sink_input*)s)->sink)) || (source && (source == ((pa_source_output*)s)->source))) { - /* update activated device if it has the AUTO route type */ - pa_proplist_sets(GET_STREAM_PROPLIST(s, data->stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, dm_device_type); } } } } } + } + } else if (data->route_type == STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED) { + PA_IDXSET_FOREACH(device_type, data->idx_avail_devices, idx) { + pa_log_info("[ROUTE][AUTO_LAST_CONN] avail_device[%u] for this role[%-16s]: type[%-16s]", idx, data->stream_role, device_type); + PA_IDXSET_FOREACH(device, conn_devices, conn_idx) { + dm_device_type = pa_device_manager_get_device_type(device); + dm_device_subtype = pa_device_manager_get_device_subtype(device); + dm_device_direction = pa_device_manager_get_device_direction(device); + dm_device_id = pa_device_manager_get_device_id(device); + creation_time = pa_device_manager_get_device_creation_time(device); + pa_log_debug(" -- type[%-16s], subtype[%-5s], direction[0x%x], id[%u], creation_time[%llu]", + dm_device_type, dm_device_subtype, dm_device_direction, dm_device_id, creation_time); + if (pa_streq(device_type, dm_device_type) && IS_AVAILABLE_DIRECTION(data->stream_type, dm_device_direction)) { + if (!latest_device || (latest_creation_time <= creation_time)) { + latest_device = device; + latest_creation_time = creation_time; + pa_log_info(" ** updated the last connected device: type[%-16s], direction[0x%x]", dm_device_type, dm_device_direction); + } + } + } + } + /* update activated device if it is found */ + if (latest_device) { + dm_device_type = pa_device_manager_get_device_type(latest_device); + dm_device_id = pa_device_manager_get_device_id(latest_device); + use_internal_codec = pa_device_manager_is_device_use_internal_codec(latest_device, CONVERT_TO_DEVICE_DIRECTION(data->stream_type), DEVICE_ROLE_NORMAL); + if (use_internal_codec) { + hal_direction = (data->stream_type==STREAM_SINK_INPUT)?DIRECTION_OUT:DIRECTION_IN; + route_info.num_of_devices++; + route_info.device_infos = pa_xrealloc(route_info.device_infos, sizeof(hal_device_info)*route_info.num_of_devices); + route_info.device_infos[route_info.num_of_devices-1].type = dm_device_type; + route_info.device_infos[route_info.num_of_devices-1].direction = hal_direction; + route_info.device_infos[route_info.num_of_devices-1].id = dm_device_id; + pa_log_info(" ** found a matched device and set state to ACTIVATED: type[%-16s], direction[0x%x], id[%u]", + route_info.device_infos[route_info.num_of_devices-1].type, hal_direction, dm_device_id); + /* set device state to activated */ + set_device_state_if_using_internal_codec(latest_device, data->stream_type, DM_DEVICE_STATE_ACTIVATED); + + /* set other device's state to deactivated */ + PA_IDXSET_FOREACH(device, conn_devices, conn_idx) { + if (latest_device == device) + continue; + set_device_state_if_using_internal_codec(device, data->stream_type, DM_DEVICE_STATE_DEACTIVATED); + } + } else + pa_log_debug(" -- it does not use internal audio codec, skip it"); + + if (data->origins_from_new_data) + pa_proplist_sets(GET_STREAM_NEW_PROPLIST(data->stream, data->stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, dm_device_type); + else + pa_proplist_sets(GET_STREAM_PROPLIST(data->stream, data->stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, dm_device_type); /* unload combine sink */ - if (data->stream_type==STREAM_SINK_INPUT && u->module_combine_sink) { + if (data->stream_type == STREAM_SINK_INPUT && u->module_combine_sink) { if ((combine_sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK))) { PA_IDXSET_FOREACH (s, combine_sink->inputs, s_idx) { pa_sink_input_move_to(s, sink, FALSE); - pa_log_debug("[ROUTE][AUTO] *** sink-input(%p,%u) moves to sink(%p,%s)", s, ((pa_sink_input*)s)->index, sink, sink->name); + pa_log_debug("[ROUTE][AUTO_LAST_CONN] *** sink-input(%p,%u) moves to sink(%p,%s)", s, ((pa_sink_input*)s)->index, sink, sink->name); } pa_sink_suspend(combine_sink, TRUE, PA_SUSPEND_USER); } else - pa_log_error("[ROUTE][AUTO] could not get combine_sink"); + pa_log_error("[ROUTE][AUTO_LAST_CONN] could not get combine_sink"); - pa_log_debug ("[ROUTE][AUTO] unload module[%s]", SINK_NAME_COMBINED); + pa_log_info("[ROUTE][AUTO_LAST_CONN] unload module[%s]", SINK_NAME_COMBINED); pa_module_unload(u->core, u->module_combine_sink, TRUE); u->module_combine_sink = NULL; } - break; - - } else if (data->route_type == STREAM_ROUTE_TYPE_AUTO_ALL && device) { - /* find the proper sink/source */ - /* currently, we support two sinks for combining */ - if (data->stream_type == STREAM_SINK_INPUT && u->module_combine_sink) { - sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK); - pa_log_debug ("[ROUTE][AUTO_ALL] found the combine_sink already existed"); - } else if (data->stream_type == STREAM_SINK_INPUT && !combine_sink_arg1) { - sink = combine_sink_arg1 = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL); - pa_log_debug ("[ROUTE][AUTO_ALL] combine_sink_arg1[%s], combine_sink_arg2[%p]", sink->name, combine_sink_arg2); - } else if (data->stream_type == STREAM_SINK_INPUT && !combine_sink_arg2) { - sink = combine_sink_arg2 = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL); - if(sink && !pa_streq(sink->name, combine_sink_arg1->name)) { - pa_log_debug ("[ROUTE][AUTO_ALL] combine_sink_arg2[%s]", sink->name); - /* load combine sink */ - if (!u->module_combine_sink) { - args = pa_sprintf_malloc("sink_name=%s slaves=\"%s,%s\"", SINK_NAME_COMBINED, combine_sink_arg1->name, combine_sink_arg2->name); - pa_log_debug ("[ROUTE][AUTO_ALL] combined sink is not prepared, now load module[%s]", args); - u->module_combine_sink = pa_module_load(u->core, MODULE_COMBINE_SINK, args); - pa_xfree(args); - } - sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK); - PA_IDXSET_FOREACH (s, combine_sink_arg1->inputs, s_idx) { - if (s == data->stream) { - pa_sink_input_move_to(s, sink, FALSE); - pa_log_debug("[ROUTE][AUTO_ALL] *** sink-input(%p,%u) moves to sink(%p,%s)", s, ((pa_sink_input*)s)->index, sink, sink->name); - } - } - } - } else if (data->stream_type == STREAM_SOURCE_OUTPUT) { - source = pa_device_manager_get_source(device, DEVICE_ROLE_NORMAL); - } - - if (data->origins_from_new_data) { - if (data->stream_type == STREAM_SINK_INPUT) - *(data->proper_sink) = sink; - else - *(data->proper_source) = source; - } else { - /* move sink-inputs/source-outputs if needed */ - if (data->idx_streams) { - PA_IDXSET_FOREACH (s, data->idx_streams, s_idx) { /* data->idx_streams: null_sink */ - if ((sink && (sink != ((pa_sink_input*)s)->sink)) || (source && (source != ((pa_source_output*)s)->source))) { - if (!pa_stream_manager_get_route_type(s, FALSE, data->stream_type, &route_type) && (route_type == STREAM_ROUTE_TYPE_AUTO_ALL)) { - if (data->stream_type == STREAM_SINK_INPUT) { - pa_sink_input_move_to(s, sink, FALSE); - pa_log_debug("[ROUTE][AUTO_ALL] *** sink-input(%p,%u) moves to sink(%p,%s)", - s, ((pa_sink_input*)s)->index, sink, sink->name); - } else if (data->stream_type == STREAM_SOURCE_OUTPUT) { - pa_source_output_move_to(s, source, FALSE); - pa_log_debug("[ROUTE][AUTO_ALL] *** source-output(%p,%u) moves to source(%p,%s)", - s, ((pa_source_output*)s)->index, source, source->name); - } - } - } - } - } - } } } @@ -775,9 +855,9 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ /* set other device's state to deactivated */ PA_IDXSET_FOREACH(_device, conn_devices, conn_idx) { pa_bool_t need_to_deactive = TRUE; - device_idx = pa_device_manager_get_device_id(_device); + dm_device_id = pa_device_manager_get_device_id(_device); for (i = 0; i < route_info.num_of_devices; i++) { - if (device_idx == route_info.device_infos[i].id) { + if (dm_device_id == route_info.device_infos[i].id) { need_to_deactive = FALSE; break; } @@ -789,12 +869,11 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ } else if (data->route_type == STREAM_ROUTE_TYPE_MANUAL && data->idx_manual_devices && data->idx_avail_devices) { PA_IDXSET_FOREACH(device_type, data->idx_avail_devices, idx) { - pa_log_debug("[ROUTE][MANUAL] avail_device[%u] for this role[%-16s]: type[%-16s]", idx, data->stream_role, device_type); + pa_log_info("[ROUTE][MANUAL] avail_device[%u] for this role[%-16s]: type[%-16s]", idx, data->stream_role, device_type); PA_IDXSET_FOREACH(device_id, data->idx_manual_devices, d_idx) { pa_log_debug(" -- manual_device[%u] for this role[%-16s]: device_id(%u)", idx, data->stream_role, *device_id); if ((device = pa_device_manager_get_device_by_id(u->device_manager, *device_id))) { dm_device_type = pa_device_manager_get_device_type(device); - dm_device_subtype = pa_device_manager_get_device_subtype(device); if (pa_streq(device_type, dm_device_type)) { pa_log_debug(" ** found a matched device: type[%-16s]", device_type); if (pa_streq(dm_device_type, DEVICE_TYPE_BT)) { @@ -807,18 +886,18 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ /* update BT SCO: close */ set_bt_sco_state(u->device_manager, FALSE); } - device_direction = pa_device_manager_get_device_direction(device); + dm_device_direction = pa_device_manager_get_device_direction(device); dm_device_subtype = pa_device_manager_get_device_subtype(device); - pa_log_debug(" -- manual_device, type[%-16s], subtype[%-5s], direction[0x%x]", dm_device_type, dm_device_subtype, device_direction); - if (IS_AVAILABLE_DIRECTION(data->stream_type, device_direction)) { + pa_log_debug(" -- manual_device, type[%-16s], subtype[%-5s], direction[0x%x]", dm_device_type, dm_device_subtype, dm_device_direction); + if (IS_AVAILABLE_DIRECTION(data->stream_type, dm_device_direction)) { use_internal_codec = pa_device_manager_is_device_use_internal_codec(device, CONVERT_TO_DEVICE_DIRECTION(data->stream_type), DEVICE_ROLE_NORMAL); if (use_internal_codec) { route_info.num_of_devices++; route_info.device_infos = pa_xrealloc(route_info.device_infos, sizeof(hal_device_info)*route_info.num_of_devices); route_info.device_infos[route_info.num_of_devices-1].type = dm_device_type; route_info.device_infos[route_info.num_of_devices-1].direction = (data->stream_type==STREAM_SINK_INPUT)?DIRECTION_OUT:DIRECTION_IN; - pa_log_debug(" ** found a matched device and set state to ACTIVATED: type[%-16s], direction[0x%x]", - route_info.device_infos[route_info.num_of_devices-1].type, device_direction); + pa_log_info(" ** found a matched device and set state to ACTIVATED: type[%-16s], direction[0x%x]", + route_info.device_infos[route_info.num_of_devices-1].type, dm_device_direction); /* set device state to activated */ set_device_state_if_using_internal_codec(device, data->stream_type, DM_DEVICE_STATE_ACTIVATED); } else diff --git a/src/stream-manager-priv.h b/src/stream-manager-priv.h index 1647842..6305294 100644 --- a/src/stream-manager-priv.h +++ b/src/stream-manager-priv.h @@ -82,7 +82,9 @@ struct _stream_manager { *source_output_new_slot, *source_output_put_slot, *source_output_unlink_slot, - *source_output_state_changed_slot; + *source_output_state_changed_slot, + *source_output_move_start_slot, + *source_output_move_finish_slot; #ifdef HAVE_DBUS #ifdef USE_DBUS_PROTOCOL pa_dbus_protocol *dbus_protocol; diff --git a/src/stream-manager.c b/src/stream-manager.c index 2602e07..3895ed6 100644 --- a/src/stream-manager.c +++ b/src/stream-manager.c @@ -1164,6 +1164,8 @@ static int convert_route_type(stream_route_type_t *route_type, const char *route if (pa_streq("auto", route_type_string)) *route_type = STREAM_ROUTE_TYPE_AUTO; + else if (pa_streq("auto-last-connected", route_type_string)) + *route_type = STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED; else if (pa_streq("auto-all", route_type_string)) *route_type = STREAM_ROUTE_TYPE_AUTO_ALL; else if (pa_streq("manual", route_type_string)) @@ -1189,7 +1191,7 @@ static void dump_stream_map (pa_stream_manager *m) { while (m->stream_infos && (s = pa_hashmap_iterate(m->stream_infos, &state, (const void **)&role))) { pa_log_debug("[role : %s]", role); pa_log_debug(" - priority : %d", s->priority); - pa_log_debug(" - route-type : %d (0:auto,1:auto-all,2:manual,3:manual-ext)", s->route_type); + pa_log_debug(" - route-type : %d (0:auto,1:auto-last-conn,2:auto-all,3:manual,4:manual-ext)", s->route_type); pa_log_debug(" - volume-types : in[%s], out[%s]", s->volume_types[STREAM_DIRECTION_IN], s->volume_types[STREAM_DIRECTION_OUT]); pa_log_debug(" - avail-in-devices"); PA_IDXSET_FOREACH(name, s->idx_avail_in_devices, idx) @@ -1971,6 +1973,7 @@ static void do_notify(pa_stream_manager *m, notify_command_type_t command, strea (void*)(m->cur_highest_priority.source_output); if (s) { role = pa_proplist_gets(GET_STREAM_PROPLIST(s, type), PA_PROP_MEDIA_ROLE); + hook_call_route_data.stream = s; hook_call_route_data.stream_type = type; hook_call_route_data.stream_role = role; hook_call_route_data.sample_spec = GET_STREAM_SAMPLE_SPEC(s, type); @@ -2426,7 +2429,7 @@ static pa_hook_result_t sink_input_move_start_cb(pa_core *core, pa_sink_input *i pa_log_debug ("sink_input_move_start_cb, i(%p, index:%u)", i, i->index); - set_volume_mute_by_idx(m, STREAM_SINK_INPUT, i->index, TRUE); + set_volume_mute_by_idx(m, i->index, STREAM_SINK_INPUT, TRUE); return PA_HOOK_OK; } @@ -2441,7 +2444,7 @@ static pa_hook_result_t sink_input_move_finish_cb(pa_core *core, pa_sink_input * pa_log_debug ("sink_input_move_finish_cb, i(%p, index:%u)", i, i->index); - set_volume_mute_by_idx(m, STREAM_SINK_INPUT, i->index, FALSE); + set_volume_mute_by_idx(m, i->index, STREAM_SINK_INPUT, FALSE); return PA_HOOK_OK; } @@ -2508,33 +2511,85 @@ static pa_hook_result_t source_output_state_changed_cb(pa_core *core, pa_source_ return PA_HOOK_OK; } -static void find_next_priority_device_for_auto_route(const char *cur_device_type, const char *role, stream_type_t stream_type, char **next_device_type, pa_stream_manager *m) { +static pa_hook_result_t source_output_move_start_cb(pa_core *core, pa_source_output *o, pa_stream_manager *m) { + pa_core_assert_ref(core); + pa_source_output_assert_ref(o); + + /* There's no point in doing anything if the core is shut down anyway */ + if (core->state == PA_CORE_SHUTDOWN) + return PA_HOOK_OK; + + pa_log_debug ("source_output_move_start_cb, o(%p, index:%u)", o, o->index); + + set_volume_mute_by_idx(m, o->index, STREAM_SINK_INPUT, TRUE); + + return PA_HOOK_OK; +} + +static pa_hook_result_t source_output_move_finish_cb(pa_core *core, pa_source_output *o, pa_stream_manager *m) { + pa_core_assert_ref(core); + pa_source_output_assert_ref(o); + + /* There's no point in doing anything if the core is shut down anyway */ + if (core->state == PA_CORE_SHUTDOWN) + return PA_HOOK_OK; + + pa_log_debug ("source_output_move_finish_cb, o(%p, index:%u)", o, o->index); + + set_volume_mute_by_idx(m, o->index, STREAM_SINK_INPUT, FALSE); + + return PA_HOOK_OK; +} + +static void find_next_device_for_auto_route(pa_stream_manager *m, stream_route_type_t route_type, const char *role, stream_type_t stream_type, const char *cur_device_type, dm_device **next_device) { stream_info *si = NULL; pa_idxset *devices = NULL; uint32_t idx = 0; char *device_type = NULL; pa_bool_t ret_next = FALSE; + pa_usec_t creation_time = 0; + pa_usec_t latest_creation_time = 0; + dm_device* latest_device = NULL; pa_assert(m); pa_assert(role); pa_assert(cur_device_type); - pa_assert(next_device_type); + pa_assert(next_device); + pa_assert((route_type == STREAM_ROUTE_TYPE_AUTO || route_type == STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED)); + *next_device = NULL; if (m->stream_infos) { si = pa_hashmap_get(m->stream_infos, role); - if (si && si->route_type == STREAM_ROUTE_TYPE_AUTO) { + if (si && si->route_type == route_type) { devices = (stream_type == STREAM_SINK_INPUT) ? si->idx_avail_out_devices : si->idx_avail_in_devices; if (devices) { - PA_IDXSET_FOREACH(device_type, devices, idx) { - if (ret_next) { - *next_device_type = device_type; - pa_log_debug("found next device[%s]", *next_device_type); - break; + if (route_type == STREAM_ROUTE_TYPE_AUTO) { + PA_IDXSET_FOREACH(device_type, devices, idx) { + if (ret_next) { + if ((*next_device = pa_device_manager_get_device(m->dm, device_type))) { + pa_log_debug("found next device[%s, %p]", device_type, *next_device); + break; + } else + continue; + } + if (pa_streq(device_type, cur_device_type)) { + ret_next = TRUE; + continue; + } } - if (pa_streq(device_type, cur_device_type)) { - ret_next = TRUE; - continue; + + } else if (route_type == STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED) { + PA_IDXSET_FOREACH(device_type, devices, idx) { + if ((*next_device = pa_device_manager_get_device(m->dm, device_type))) { + creation_time = pa_device_manager_get_device_creation_time(*next_device); + if (!latest_device || (latest_creation_time <= creation_time)) { + latest_device = *next_device; + latest_creation_time = creation_time; + } + } } + *next_device = latest_device; + pa_log_debug("found next device[%s, %p], creation_time[%llu]", device_type, *next_device, latest_creation_time); } } else pa_log_error("could not found a device list for this role[%s], stream type[%d]", role, stream_type); @@ -2543,12 +2598,56 @@ static void find_next_priority_device_for_auto_route(const char *cur_device_type } else pa_log_error("stream_infos is null"); - pa_log_debug("next_device_type is [%s] for role[%s]/stream_type[%d]", *next_device_type, role, stream_type); + pa_log_debug("next_device is [%p] for role[%s]/route_type[%d]/stream_type[%d]", *next_device, role, route_type, stream_type); return; +} + +static void is_available_device_for_auto_route(pa_stream_manager *m, stream_route_type_t route_type, const char *cur_device_type, const char *new_device_type, const char *role, stream_type_t stream_type, pa_bool_t *available) { + stream_info *si = NULL; + pa_idxset *devices = NULL; + uint32_t idx = 0; + char *device_type = NULL; + + pa_assert(m); + pa_assert(role); + pa_assert(cur_device_type); + pa_assert(new_device_type); + pa_assert(available); + pa_assert((route_type == STREAM_ROUTE_TYPE_AUTO || route_type == STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED)); + + if (m->stream_infos) { + si = pa_hashmap_get(m->stream_infos, role); + if (si && si->route_type == route_type) { + *available = FALSE; + devices = (stream_type == STREAM_SINK_INPUT) ? si->idx_avail_out_devices : si->idx_avail_in_devices; + if (devices) { + PA_IDXSET_FOREACH(device_type, devices, idx) { + if (route_type == STREAM_ROUTE_TYPE_AUTO) { + if (cur_device_type && pa_streq(device_type, cur_device_type)) { + pa_log_debug("cur_device[%s]'s priority is more higher than new_device[%s]", cur_device_type, new_device_type); + break; + } + } + if (pa_streq(device_type, new_device_type)) { + *available = TRUE; + break; + } + } + } else { + pa_log_error("could not found a device list for this role[%s], stream type[%d]", role, stream_type); + *available = FALSE; + } + } else { + pa_log_warn("not support this role[%s]", role); + *available = FALSE; + } + } else { + pa_log_error("stream_infos is null"); + *available = FALSE; + } + pa_log_debug("is new_device[%s] available for role[%s]/stream_type[%d]:%d", new_device_type, role, stream_type, *available); -FAILURE: - *next_device_type = NULL; return; } @@ -2560,10 +2659,11 @@ static void process_stream_as_device_change_for_auto_route(pa_stream_manager *m, pa_assert(m); pa_assert(stream); - pa_log_debug("[SM][PROCESS_STREAM_FOR_AUTO] stream(%p), stream_type(%d), is_connected(%d), use_internal_codec(%d)", + pa_log_info("[SM][PROCESS_STREAM_FOR_AUTO] stream(%p), stream_type(%d), is_connected(%d), use_internal_codec(%d)", stream, stream_type, is_connected, use_internal_codec); - if (pa_stream_manager_get_route_type(stream, FALSE, stream_type, &route_type) || route_type != STREAM_ROUTE_TYPE_AUTO) + if (pa_stream_manager_get_route_type(stream, FALSE, stream_type, &route_type) || + (route_type != STREAM_ROUTE_TYPE_AUTO && route_type != STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED)) return; if (is_connected) { @@ -2610,7 +2710,6 @@ static void update_sink_or_source_as_device_change(stream_route_type_t stream_ro const char *device_type = NULL; const char *cur_device_type = NULL; const char *init_device_type = NULL; - char *next_device_type = NULL; dm_device *next_device = NULL; dm_device *_device = NULL; stream_route_type_t route_type; @@ -2638,8 +2737,9 @@ static void update_sink_or_source_as_device_change(stream_route_type_t stream_ro } device_type = pa_device_manager_get_device_type(device); - if (stream_route_type == STREAM_ROUTE_TYPE_AUTO) { - pa_log_debug("[SM][UPDATE_SINK_SOURCE][AUTO] deivce_type(%s), is_connected(%d))", device_type, is_connected); + if (stream_route_type == STREAM_ROUTE_TYPE_AUTO || stream_route_type == STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED) { + pa_log_info("[SM][UPDATE_SINK_SOURCE][AUTO] route_type(%d), deivce_type(%s), is_connected(%d))", + stream_route_type, device_type, is_connected); if (stream_type == STREAM_SINK_INPUT) sink = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL); else @@ -2653,27 +2753,29 @@ static void update_sink_or_source_as_device_change(stream_route_type_t stream_ro /* CONNECTED: move a stream to the new device if possible */ if (sink && (sink != ((pa_sink_input*)s)->sink)) { if ((cur_device_type = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV))) { - pa_stream_manager_is_available_device_for_auto_route(cur_device_type, device_type, role, stream_type, &available, m); + is_available_device_for_auto_route(m, route_type, cur_device_type, device_type, role, stream_type, &available); if (available) { pa_sink_input_move_to(s, sink, FALSE); pa_log_debug(" -- *** sink-input(%p,%u) moves to sink(%p,%s), new device(%s)", - s, ((pa_sink_input*)s)->index, sink, sink->name, device_type); + s, ((pa_sink_input*)s)->index, sink, sink->name, device_type); use_internal_codec = sink->use_internal_codec; } } else pa_log_error(" -- could not find current device type for s->sink(%p)", ((pa_sink_input*)s)->sink); } else if (source && (source != ((pa_source_output*)s)->source)) { if ((cur_device_type = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV))) { - pa_stream_manager_is_available_device_for_auto_route(cur_device_type, device_type, role, stream_type, &available, m); + is_available_device_for_auto_route(m, route_type, cur_device_type, device_type, role, stream_type, &available); if (available) { pa_source_output_move_to(s, source, FALSE); pa_log_debug(" -- *** source-output(%p,%u) moves to source(%p,%s), new device(%s)", - s, ((pa_source_output*)s)->index, source, source->name, device_type); + s, ((pa_source_output*)s)->index, source, source->name, device_type); use_internal_codec = source->use_internal_codec; } } else pa_log_error(" -- could not find current device type for s->source(%p)", ((pa_source_output*)s)->source); - } + } else + pa_log_debug("no need to move for stream(%p, idx:%u)", s, (stream_type == STREAM_SINK_INPUT ? + ((pa_sink_input*)s)->index : ((pa_source_output*)s)->index)); if (available) { /* update activated device */ pa_proplist_sets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, device_type); @@ -2687,33 +2789,26 @@ static void update_sink_or_source_as_device_change(stream_route_type_t stream_ro /* DISCONNECTED: find a connected device that has the next priority */ if (sink && (sink == ((pa_sink_input*)s)->sink)) { init_device_type = device_type; - do { - find_next_priority_device_for_auto_route(device_type, role, stream_type, &next_device_type, m); - pa_log_debug(" -- prev_device(%s), new_device(%s)", device_type, next_device_type); - if (next_device_type) { - if ((next_device = pa_device_manager_get_device(m->dm, next_device_type))) { - if ((next_sink = pa_device_manager_get_sink(next_device, DEVICE_ROLE_NORMAL))) { - /* update activated device */ - pa_proplist_sets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, next_device_type); - set_device_state_if_using_internal_codec(next_device, stream_type, DM_DEVICE_STATE_ACTIVATED); - cached_prev_dev_list[cnt++].device_type = init_device_type; - /* trigger to update routing path if the next device uses internal audio codec */ - if (next_sink->use_internal_codec) - process_stream_as_device_change_for_auto_route(m, s, stream_type, is_connected, next_sink->use_internal_codec); - - pa_sink_input_move_to(s, next_sink, FALSE); - pa_log_debug(" -- *** sink-input(%p,%u) moves to sink(%p,%s), new device(%s)", - s, ((pa_sink_input*)s)->index, next_sink, next_sink->name, next_device_type); - break; - } - } else { - device_type = next_device_type; - continue; + find_next_device_for_auto_route(m, route_type, role, stream_type, device_type, &next_device); + pa_log_debug(" -- prev_device(%s), new_device(%p)", device_type, next_device); + if (next_device) { + if ((next_sink = pa_device_manager_get_sink(next_device, DEVICE_ROLE_NORMAL))) { + device_type = pa_device_manager_get_device_type(next_device); + /* update activated device */ + pa_proplist_sets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, device_type); + set_device_state_if_using_internal_codec(next_device, stream_type, DM_DEVICE_STATE_ACTIVATED); + cached_prev_dev_list[cnt++].device_type = init_device_type; + /* trigger to update routing path if the next device uses internal audio codec */ + if (next_sink->use_internal_codec) + process_stream_as_device_change_for_auto_route(m, s, stream_type, is_connected, next_sink->use_internal_codec); + + pa_sink_input_move_to(s, next_sink, FALSE); + pa_log_debug(" -- *** sink-input(%p,%u) moves to sink(%p,%s), new device(%s)", + s, ((pa_sink_input*)s)->index, next_sink, next_sink->name, device_type); } - } - } while (next_device_type); + } - if (!next_device_type || !next_sink) { + if (!next_device || !next_sink) { pa_sink_input_move_to(s, null_sink, FALSE); pa_log_debug(" -- *** sink-input(%p,%u) moves to sink(%p,%s)", s, ((pa_sink_input*)s)->index, null_sink, null_sink->name); @@ -2721,33 +2816,25 @@ static void update_sink_or_source_as_device_change(stream_route_type_t stream_ro } else if (source && (source == ((pa_source_output*)s)->source)) { init_device_type = device_type; - do { - find_next_priority_device_for_auto_route(device_type, role, stream_type, &next_device_type, m); - pa_log_debug(" -- prev_device(%s), new_device(%s)", device_type, next_device_type); - if (next_device_type) { - if ((next_device = pa_device_manager_get_device(m->dm, next_device_type))) { - if ((next_source = pa_device_manager_get_source(next_device, DEVICE_ROLE_NORMAL))) { - /* update activated device */ - pa_proplist_sets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, next_device_type); - set_device_state_if_using_internal_codec(next_device, stream_type, DM_DEVICE_STATE_ACTIVATED); - cached_prev_dev_list[cnt++].device_type = init_device_type; - /* trigger to update routing path if the next device uses internal audio codec */ - if (next_source->use_internal_codec) - process_stream_as_device_change_for_auto_route(m, s, stream_type, is_connected, next_source->use_internal_codec); - - pa_source_output_move_to(s, next_source, FALSE); - pa_log_debug(" -- *** source-output(%p,%u) moves to source(%p,%s), new device(%s)", - s, ((pa_source_output*)s)->index, next_source, next_source->name, next_device_type); - break; - } - } else { - device_type = next_device_type; - continue; + find_next_device_for_auto_route(m, route_type, role, stream_type, device_type, &next_device); + pa_log_debug(" -- prev_device(%s), new_device(%p)", device_type, next_device); + if (next_device) { + if ((next_source = pa_device_manager_get_source(next_device, DEVICE_ROLE_NORMAL))) { + device_type = pa_device_manager_get_device_type(next_device); + /* update activated device */ + pa_proplist_sets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, device_type); + set_device_state_if_using_internal_codec(next_device, stream_type, DM_DEVICE_STATE_ACTIVATED); + cached_prev_dev_list[cnt++].device_type = init_device_type; + /* trigger to update routing path if the next device uses internal audio codec */ + if (next_source->use_internal_codec) + process_stream_as_device_change_for_auto_route(m, s, stream_type, is_connected, next_source->use_internal_codec); + + pa_source_output_move_to(s, next_source, FALSE); + pa_log_debug(" -- *** source-output(%p,%u) moves to source(%p,%s), new device(%s)", + s, ((pa_source_output*)s)->index, next_source, next_source->name, device_type); } - } - } while (next_device_type); - - if (!next_device_type || !next_source) { + } + if (!next_device || !next_source) { pa_source_output_move_to(s, null_source, FALSE); pa_log_debug(" -- *** source-output(%p,%u) moves to source(%p,%s)", s, ((pa_source_output*)s)->index, null_source, null_source->name); @@ -2787,7 +2874,7 @@ static void update_sink_or_source_as_device_change(stream_route_type_t stream_ro } } else if (stream_route_type == STREAM_ROUTE_TYPE_MANUAL_EXT) { - pa_log_debug("[SM][UPDATE_SINK_SOURCE][EXT] deivce_type(%s), is_connected(%d))", device_type, is_connected); + pa_log_info("[SM][UPDATE_SINK_SOURCE][EXT] deivce_type(%s), is_connected(%d))", device_type, is_connected); if (!is_connected) { PA_IDXSET_FOREACH (s, streams, s_idx) { /* streams: source->outputs/sink->inputs */ if (!pa_stream_manager_get_route_type(s, FALSE, stream_type, &route_type) && route_type == stream_route_type) { @@ -2850,12 +2937,18 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_device_ } /* Update all the streams that have AUTO route type */ - if (device_direction & DM_DEVICE_DIRECTION_IN) + if (device_direction & DM_DEVICE_DIRECTION_IN) { update_sink_or_source_as_device_change(STREAM_ROUTE_TYPE_AUTO, m->core->source_outputs, STREAM_SOURCE_OUTPUT, data->device, data->is_connected, m); - if (device_direction & DM_DEVICE_DIRECTION_OUT) + update_sink_or_source_as_device_change(STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED, m->core->source_outputs, + STREAM_SOURCE_OUTPUT, data->device, data->is_connected, m); + } + if (device_direction & DM_DEVICE_DIRECTION_OUT) { update_sink_or_source_as_device_change(STREAM_ROUTE_TYPE_AUTO, m->core->sink_inputs, STREAM_SINK_INPUT, data->device, data->is_connected, m); + update_sink_or_source_as_device_change(STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED, m->core->sink_inputs, + STREAM_SINK_INPUT, data->device, data->is_connected, m); + } /* If the route type of the stream is not manual, notify again */ @@ -2864,8 +2957,8 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_device_ if (route_type < STREAM_ROUTE_TYPE_MANUAL) { if (use_internal_codec) { PA_IDXSET_FOREACH (s, m->cur_highest_priority.source_output->source->outputs, s_idx) { - if (!pa_stream_manager_get_route_type(s, FALSE, STREAM_SOURCE_OUTPUT, &route_type) && - (route_type == STREAM_ROUTE_TYPE_AUTO) && !data->is_connected) { + if (!data->is_connected && !pa_stream_manager_get_route_type(s, FALSE, STREAM_SOURCE_OUTPUT, &route_type) && + ((route_type == STREAM_ROUTE_TYPE_AUTO) || (route_type == STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED))) { /* remove activated device info. if it has the AUTO route type */ active_dev = pa_proplist_gets(GET_STREAM_PROPLIST(s, STREAM_SOURCE_OUTPUT), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV); if (pa_streq(active_dev, device_type)) @@ -2888,8 +2981,8 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_device_ if (route_type < STREAM_ROUTE_TYPE_MANUAL) { if (use_internal_codec) { PA_IDXSET_FOREACH (s, m->cur_highest_priority.sink_input->sink->inputs, s_idx) { - if (!pa_stream_manager_get_route_type(s, FALSE, STREAM_SINK_INPUT, &route_type) && - (route_type == STREAM_ROUTE_TYPE_AUTO) && !data->is_connected) { + if (!data->is_connected && !pa_stream_manager_get_route_type(s, FALSE, STREAM_SINK_INPUT, &route_type) && + ((route_type == STREAM_ROUTE_TYPE_AUTO) || (route_type == STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED))) { /* remove activated device info. if it has the AUTO route type */ active_dev = pa_proplist_gets(GET_STREAM_PROPLIST(s, STREAM_SINK_INPUT), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV); if (pa_streq(active_dev, device_type)) @@ -2897,7 +2990,8 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_device_ } } do_notify(m, NOTIFY_COMMAND_CHANGE_ROUTE_START, STREAM_SINK_INPUT, FALSE, m->cur_highest_priority.sink_input); - if ((route_type == STREAM_ROUTE_TYPE_AUTO) && !((pa_sink_input*)(m->cur_highest_priority.sink_input))->sink->use_internal_codec) { + if (((route_type == STREAM_ROUTE_TYPE_AUTO) || (route_type == STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED)) && + !((pa_sink_input*)(m->cur_highest_priority.sink_input))->sink->use_internal_codec) { /* If the sink of the cur_highest_priority stream uses external codec, it should be updated. * As only the process_stream(PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_ENDED) * can update the cur_highest_priority, call it here */ @@ -3057,51 +3151,6 @@ int32_t pa_stream_manager_get_route_type(void *stream, pa_bool_t origins_from_ne return 0; } -void pa_stream_manager_is_available_device_for_auto_route(const char *cur_device_type, const char *new_device_type, const char *role, stream_type_t stream_type, pa_bool_t *available, pa_stream_manager *m) { - stream_info *si = NULL; - pa_idxset *devices = NULL; - uint32_t idx = 0; - char *device_type = NULL; - - pa_assert(m); - pa_assert(role); - pa_assert(cur_device_type); - pa_assert(new_device_type); - pa_assert(available); - - if (m->stream_infos) { - si = pa_hashmap_get(m->stream_infos, role); - if (si) { - *available = FALSE; - devices = (stream_type == STREAM_SINK_INPUT) ? si->idx_avail_out_devices : si->idx_avail_in_devices; - if (devices) { - PA_IDXSET_FOREACH(device_type, devices, idx) { - if (cur_device_type && pa_streq(device_type, cur_device_type)) { - pa_log_debug("cur_device[%s]'s priority is more higher than new_device[%s]", cur_device_type, new_device_type); - break; - } - if (pa_streq(device_type, new_device_type)) { - *available = TRUE; - break; - } - } - } else { - pa_log_error("could not found a device list for this role[%s], stream type[%d]", role, stream_type); - *available = FALSE; - } - } else { - pa_log_warn("not support this role[%s]", role); - *available = FALSE; - } - } else { - pa_log_error("stream_infos is null"); - *available = FALSE; - } - pa_log_debug("is new_device[%s] available for role[%s]/stream_type[%d]:%d", new_device_type, role, stream_type, *available); - - return; -} - pa_stream_manager* pa_stream_manager_init(pa_core *c) { pa_stream_manager *m; @@ -3141,6 +3190,8 @@ pa_stream_manager* pa_stream_manager_init(pa_core *c) { m->source_output_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PUT], PA_HOOK_EARLY, (pa_hook_cb_t) source_output_put_cb, m); m->source_output_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_UNLINK], PA_HOOK_EARLY, (pa_hook_cb_t) source_output_unlink_cb, m); m->source_output_state_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_STATE_CHANGED], PA_HOOK_EARLY, (pa_hook_cb_t) source_output_state_changed_cb, m); + m->sink_input_move_start_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_START], PA_HOOK_EARLY, (pa_hook_cb_t) source_output_move_start_cb, m); + m->sink_input_move_finish_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_FINISH], PA_HOOK_EARLY, (pa_hook_cb_t) source_output_move_finish_cb, m); m->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_CLIENT | PA_SUBSCRIPTION_MASK_SAMPLE_CACHE, (pa_subscription_cb_t)subscribe_cb, m); diff --git a/src/stream-manager.h b/src/stream-manager.h index 6c70594..a868721 100644 --- a/src/stream-manager.h +++ b/src/stream-manager.h @@ -26,10 +26,11 @@ typedef enum _stream_type { } stream_type_t; typedef enum stream_route_type { - STREAM_ROUTE_TYPE_AUTO, /* the policy of decision device(s) is automatic and it's routing path is particular to one device */ - STREAM_ROUTE_TYPE_AUTO_ALL, /* the policy of decision device(s) is automatic and it's routing path can be several devices */ - STREAM_ROUTE_TYPE_MANUAL, /* the policy of decision device(s) is manual */ - STREAM_ROUTE_TYPE_MANUAL_EXT, /* the policy of decision device(s) is manual and it's routing path is for only external devices */ + STREAM_ROUTE_TYPE_AUTO, /* the policy of decision device(s) is automatic and it's routing path is particular to one device based on priority */ + STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED,/* the policy of decision device(s) is automatic and it's routing path is particular to one device based on connected time */ + STREAM_ROUTE_TYPE_AUTO_ALL, /* the policy of decision device(s) is automatic and it's routing path can be several devices */ + STREAM_ROUTE_TYPE_MANUAL, /* the policy of decision device(s) is manual */ + STREAM_ROUTE_TYPE_MANUAL_EXT, /* the policy of decision device(s) is manual and it's routing path is for only external devices */ } stream_route_type_t; typedef struct _hook_call_data_for_select { @@ -66,8 +67,6 @@ typedef struct _hook_call_data_for_option { } pa_stream_manager_hook_data_for_option; int32_t pa_stream_manager_get_route_type(void *stream, pa_bool_t origins_from_new_data, stream_type_t stream_type, stream_route_type_t *stream_route_type); -void pa_stream_manager_is_available_device_for_auto_route(const char *cur_device_type, const char *new_device_type, const char *role, stream_type_t stream_type, pa_bool_t *available, pa_stream_manager *m); -void pa_stream_manager_find_next_priority_device_for_auto_route(const char *cur_device_type, const char *role, stream_type_t stream_type, char **next_device_type, pa_stream_manager *m); pa_stream_manager* pa_stream_manager_init(pa_core *c); void pa_stream_manager_done(pa_stream_manager* m); -- 2.7.4 From 2d98e9dae30f09ed6bb57cf949d05c3ed7e09659 Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Tue, 24 Nov 2015 12:13:04 +0900 Subject: [PATCH 03/16] hal-manager: Rename variables and change deinit API of audio HAL [Version] 5.0.18 [Profile] Common [Issue Type] Code clean up Change-Id: I2d7a42703d66e83ed41f2eeb752997f870626a08 Signed-off-by: Sangchul Lee --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/hal-manager.c | 48 ++++++++--------- src/tizen-audio.h | 96 ++++++++++++++++----------------- 3 files changed, 73 insertions(+), 73 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index dc14501..62805ae 100644 --- a/packaging/pulseaudio-modules-tizen.spec +++ b/packaging/pulseaudio-modules-tizen.spec @@ -1,6 +1,6 @@ Name: pulseaudio-modules-tizen Summary: Pulseaudio modules for Tizen -Version: 5.0.17 +Version: 5.0.18 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/hal-manager.c b/src/hal-manager.c index cb85c47..5866399 100644 --- a/src/hal-manager.c +++ b/src/hal-manager.c @@ -37,7 +37,7 @@ struct _pa_hal_manager { pa_core *core; void *dl_handle; - void *data; + void *ah_handle; audio_interface_t intf; }; @@ -80,7 +80,7 @@ pa_hal_manager* pa_hal_manager_get(pa_core *core) { h->intf.pcm_get_params = dlsym(h->dl_handle, "audio_pcm_get_params"); h->intf.pcm_set_params = dlsym(h->dl_handle, "audio_pcm_set_params"); if (h->intf.init) { - if (h->intf.init(&h->data) != AUDIO_RET_OK) + if (h->intf.init(&h->ah_handle) != AUDIO_RET_OK) pa_log_error("hal_manager init failed"); } @@ -112,7 +112,7 @@ void pa_hal_manager_unref(pa_hal_manager *h) { /* Deinit HAL manager & unload library */ if (h->intf.deinit) { - if (h->intf.deinit(&h->data) != AUDIO_RET_OK) { + if (h->intf.deinit(h->ah_handle) != AUDIO_RET_OK) { pa_log_error("hal_manager deinit failed"); } } @@ -138,7 +138,7 @@ int32_t pa_hal_manager_get_volume_level_max(pa_hal_manager *h, const char *volum info.type = volume_type; info.direction = direction; - if (AUDIO_IS_ERROR((hal_ret = h->intf.get_volume_level_max(h->data, &info, level)))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.get_volume_level_max(h->ah_handle, &info, level)))) { pa_log_error("get_volume_level_max returns error:0x%x", hal_ret); ret = -1; } @@ -157,7 +157,7 @@ int32_t pa_hal_manager_get_volume_level(pa_hal_manager *h, const char *volume_ty info.type = volume_type; info.direction = direction; - if (AUDIO_IS_ERROR((hal_ret = h->intf.get_volume_level(h->data, &info, level)))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.get_volume_level(h->ah_handle, &info, level)))) { pa_log_error("get_volume_level returns error:0x%x", hal_ret); ret = -1; } @@ -175,7 +175,7 @@ int32_t pa_hal_manager_set_volume_level(pa_hal_manager *h, const char *volume_ty info.type = volume_type; info.direction = direction; - if (AUDIO_IS_ERROR((hal_ret = h->intf.set_volume_level(h->data, &info, level)))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.set_volume_level(h->ah_handle, &info, level)))) { pa_log_error("set_volume_level returns error:0x%x", hal_ret); ret = -1; } @@ -196,7 +196,7 @@ int32_t pa_hal_manager_get_volume_value(pa_hal_manager *h, const char *volume_ty info.gain = gain_type; info.direction = direction; - if (AUDIO_IS_ERROR((hal_ret = h->intf.get_volume_value(h->data, &info, level, value)))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.get_volume_value(h->ah_handle, &info, level, value)))) { pa_log_error("get_volume_value returns error:0x%x", hal_ret); ret = -1; } @@ -216,7 +216,7 @@ int32_t pa_hal_manager_get_volume_mute(pa_hal_manager *h, const char *volume_typ info.type = volume_type; info.direction = direction; - if (AUDIO_IS_ERROR(hal_ret = h->intf.get_volume_mute(h->data, &info, mute))) { + if (AUDIO_IS_ERROR(hal_ret = h->intf.get_volume_mute(h->ah_handle, &info, mute))) { pa_log_error("get_mute returns error:0x%x", hal_ret); ret = -1; } @@ -234,7 +234,7 @@ int32_t pa_hal_manager_set_volume_mute(pa_hal_manager *h, const char *volume_typ info.type = volume_type; info.direction = direction; - if (AUDIO_IS_ERROR(hal_ret = h->intf.set_volume_mute(h->data, &info, mute))) { + if (AUDIO_IS_ERROR(hal_ret = h->intf.set_volume_mute(h->ah_handle, &info, mute))) { pa_log_error("set_mute returns error:0x%x", hal_ret); ret = -1; } @@ -248,7 +248,7 @@ int32_t pa_hal_manager_do_route(pa_hal_manager *h, hal_route_info *info) { pa_assert(h); pa_assert(info); - if (AUDIO_IS_ERROR(hal_ret = h->intf.do_route(h->data, (audio_route_info_t*)info))) { + if (AUDIO_IS_ERROR(hal_ret = h->intf.do_route(h->ah_handle, (audio_route_info_t*)info))) { pa_log_error("do_route returns error:0x%x", hal_ret); ret = -1; } @@ -262,7 +262,7 @@ int32_t pa_hal_manager_update_route_option(pa_hal_manager *h, hal_route_option * pa_assert(h); pa_assert(option); - if (AUDIO_IS_ERROR(hal_ret = h->intf.update_route_option(h->data, (audio_route_option_t*)option))) { + if (AUDIO_IS_ERROR(hal_ret = h->intf.update_route_option(h->ah_handle, (audio_route_option_t*)option))) { pa_log_error("update_route_option returns error:0x%x", hal_ret); ret = -1; } @@ -281,7 +281,7 @@ int32_t pa_hal_manager_update_stream_connection_info(pa_hal_manager *h, hal_stre hal_info.direction = info->direction; hal_info.idx = info->idx; - if (AUDIO_IS_ERROR(hal_ret = h->intf.update_stream_connection_info(h->data, &hal_info, (uint32_t)info->is_connected))) { + if (AUDIO_IS_ERROR(hal_ret = h->intf.update_stream_connection_info(h->ah_handle, &hal_info, (uint32_t)info->is_connected))) { pa_log_error("update_stream_connection_info returns error:0x%x", hal_ret); ret = -1; } @@ -299,7 +299,7 @@ int32_t pa_hal_manager_get_buffer_attribute(pa_hal_manager *h, hal_stream_info * pa_log_info("latency:%s, rate:%u, format:%d, channels:%u", info->latency, info->sample_spec->rate, info->sample_spec->format, info->sample_spec->channels); - if (AUDIO_IS_ERROR(hal_ret = h->intf.get_buffer_attr(h->data, info->direction, info->latency, info->sample_spec->rate, info->sample_spec->format, + if (AUDIO_IS_ERROR(hal_ret = h->intf.get_buffer_attr(h->ah_handle, info->direction, info->latency, info->sample_spec->rate, info->sample_spec->format, info->sample_spec->channels, maxlength, tlength, prebuf, minreq, fragsize))) { pa_log_error("get_buffer_attr returns error:0x%x", hal_ret); ret = -1; @@ -317,7 +317,7 @@ int32_t pa_hal_manager_pcm_open(pa_hal_manager *h, pcm_handle *pcm_h, io_directi pa_assert(pcm_h); pa_assert(sample_spec); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_open(h->data, pcm_h, direction, sample_spec, period_size, periods))) { + if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_open(h->ah_handle, pcm_h, direction, sample_spec, period_size, periods))) { pa_log_error("pcm_open returns error:0x%x", hal_ret); ret = -1; } @@ -331,7 +331,7 @@ int32_t pa_hal_manager_pcm_start(pa_hal_manager *h, pcm_handle pcm_h) { pa_assert(h); pa_assert(pcm_h); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_start(h->data, pcm_h))) { + if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_start(h->ah_handle, pcm_h))) { pa_log_error("pcm_start returns error:0x%x", hal_ret); ret = -1; } @@ -345,7 +345,7 @@ int32_t pa_hal_manager_pcm_stop(pa_hal_manager *h, pcm_handle pcm_h) { pa_assert(h); pa_assert(pcm_h); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_stop(h->data, pcm_h))) { + if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_stop(h->ah_handle, pcm_h))) { pa_log_error("pcm_stop returns error:0x%x", hal_ret); ret = -1; } @@ -359,7 +359,7 @@ int32_t pa_hal_manager_pcm_close(pa_hal_manager *h, pcm_handle pcm_h) { pa_assert(h); pa_assert(pcm_h); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_close(h->data, pcm_h))) { + if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_close(h->ah_handle, pcm_h))) { pa_log_error("pcm_close returns error:0x%x", hal_ret); ret = -1; } @@ -374,7 +374,7 @@ int32_t pa_hal_manager_pcm_available(pa_hal_manager *h, pcm_handle pcm_h, uint32 pa_assert(pcm_h); pa_assert(available); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_avail(h->data, pcm_h, available))) { + if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_avail(h->ah_handle, pcm_h, available))) { pa_log_error("pcm_avail returns error:0x%x", hal_ret); ret = -1; } @@ -389,7 +389,7 @@ int32_t pa_hal_manager_pcm_write(pa_hal_manager *h, pcm_handle pcm_h, const void pa_assert(pcm_h); pa_assert(buffer); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_write(h->data, pcm_h, buffer, frames))) { + if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_write(h->ah_handle, pcm_h, buffer, frames))) { pa_log_error("pcm_write returns error:0x%x", hal_ret); ret = -1; } @@ -404,7 +404,7 @@ int32_t pa_hal_manager_pcm_read(pa_hal_manager *h, pcm_handle pcm_h, void *buffe pa_assert(pcm_h); pa_assert(buffer); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_read(h->data, pcm_h, buffer, frames))) { + if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_read(h->ah_handle, pcm_h, buffer, frames))) { pa_log_error("pcm_read returns error:0x%x", hal_ret); ret = -1; } @@ -419,7 +419,7 @@ int32_t pa_hal_manager_pcm_get_fd(pa_hal_manager *h, pcm_handle pcm_h, int *fd) pa_assert(pcm_h); pa_assert(fd); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_get_fd(h->data, pcm_h, fd))) { + if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_get_fd(h->ah_handle, pcm_h, fd))) { pa_log_error("pcm_get_fd returns error:0x%x", hal_ret); ret = -1; } @@ -433,7 +433,7 @@ int32_t pa_hal_manager_pcm_recover(pa_hal_manager *h, pcm_handle pcm_h, int err) pa_assert(h); pa_assert(pcm_h); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_recover(h->data, pcm_h, err))) { + if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_recover(h->ah_handle, pcm_h, err))) { pa_log_error("pcm_recover returns error:0x%x", hal_ret); ret = -1; } @@ -449,7 +449,7 @@ int32_t pa_hal_manager_pcm_get_params(pa_hal_manager *h, pcm_handle pcm_h, uint3 pa_assert(period_size); pa_assert(periods); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_get_params(h->data, pcm_h, direction, sample_spec, period_size, periods))) { + if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_get_params(h->ah_handle, pcm_h, direction, sample_spec, period_size, periods))) { pa_log_error("pcm_get_params returns error:0x%x", hal_ret); ret = -1; } @@ -463,7 +463,7 @@ int32_t pa_hal_manager_pcm_set_params(pa_hal_manager *h, pcm_handle pcm_h, uint3 pa_assert(h); pa_assert(sample_spec); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_set_params(h->data, pcm_h, direction, sample_spec, period_size, periods))) { + if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_set_params(h->ah_handle, pcm_h, direction, sample_spec, period_size, periods))) { pa_log_error("pcm_set_params returns error:0x%x", hal_ret); ret = -1; } diff --git a/src/tizen-audio.h b/src/tizen-audio.h index 8f3161b..ce95101 100644 --- a/src/tizen-audio.h +++ b/src/tizen-audio.h @@ -20,6 +20,7 @@ USA. ***/ +#include /* Error code */ #define AUDIO_IS_ERROR(ret) (ret < 0) @@ -32,14 +33,13 @@ typedef enum audio_return { AUDIO_ERR_NOT_IMPLEMENTED = (int32_t)0x80001004, } audio_return_t ; -/* Direction */ typedef enum audio_direction { AUDIO_DIRECTION_IN, /**< Capture */ AUDIO_DIRECTION_OUT, /**< Playback */ } audio_direction_t; typedef struct device_info { - char *type; + const char *type; uint32_t direction; uint32_t id; } device_info_t; @@ -70,55 +70,55 @@ typedef struct audio_stream_info { /* Overall */ typedef struct audio_interface { - audio_return_t (*init)(void **userdata); - audio_return_t (*deinit)(void **userdata); - audio_return_t (*get_volume_level_max)(void *userdata, audio_volume_info_t *info, uint32_t *level); - audio_return_t (*get_volume_level)(void *userdata, audio_volume_info_t *info, uint32_t *level); - audio_return_t (*set_volume_level)(void *userdata, audio_volume_info_t *info, uint32_t level); - audio_return_t (*get_volume_value)(void *userdata, audio_volume_info_t *info, uint32_t level, double *value); - audio_return_t (*get_volume_mute)(void *userdata, audio_volume_info_t *info, uint32_t *mute); - audio_return_t (*set_volume_mute)(void *userdata, audio_volume_info_t *info, uint32_t mute); - audio_return_t (*do_route)(void *userdata, audio_route_info_t *info); - audio_return_t (*update_route_option)(void *userdata, audio_route_option_t *option); - audio_return_t (*update_stream_connection_info) (void *userdata, audio_stream_info_t *info, uint32_t is_connected); - audio_return_t (*get_buffer_attr)(void *userdata, uint32_t direction, const char *latency, uint32_t samplerate, int format, uint32_t channels, + audio_return_t (*init)(void **audio_handle); + audio_return_t (*deinit)(void *audio_handle); + audio_return_t (*get_volume_level_max)(void *audio_handle, audio_volume_info_t *info, uint32_t *level); + audio_return_t (*get_volume_level)(void *audio_handle, audio_volume_info_t *info, uint32_t *level); + audio_return_t (*set_volume_level)(void *audio_handle, audio_volume_info_t *info, uint32_t level); + audio_return_t (*get_volume_value)(void *audio_handle, audio_volume_info_t *info, uint32_t level, double *value); + audio_return_t (*get_volume_mute)(void *audio_handle, audio_volume_info_t *info, uint32_t *mute); + audio_return_t (*set_volume_mute)(void *audio_handle, audio_volume_info_t *info, uint32_t mute); + audio_return_t (*do_route)(void *audio_handle, audio_route_info_t *info); + audio_return_t (*update_route_option)(void *audio_handle, audio_route_option_t *option); + audio_return_t (*update_stream_connection_info) (void *audio_handle, audio_stream_info_t *info, uint32_t is_connected); + audio_return_t (*get_buffer_attr)(void *audio_handle, uint32_t direction, const char *latency, uint32_t samplerate, int format, uint32_t channels, uint32_t *maxlength, uint32_t *tlength, uint32_t *prebuf, uint32_t* minreq, uint32_t *fragsize); /* Interface of PCM device */ - audio_return_t (*pcm_open)(void *userdata, void **pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods); - audio_return_t (*pcm_start)(void *userdata, void *pcm_handle); - audio_return_t (*pcm_stop)(void *userdata, void *pcm_handle); - audio_return_t (*pcm_close)(void *userdata, void *pcm_handle); - audio_return_t (*pcm_avail)(void *userdata, void *pcm_handle, uint32_t *avail); - audio_return_t (*pcm_write)(void *userdata, void *pcm_handle, const void *buffer, uint32_t frames); - audio_return_t (*pcm_read)(void *userdata, void *pcm_handle, void *buffer, uint32_t frames); - audio_return_t (*pcm_get_fd)(void *userdata, void *pcm_handle, int *fd); - audio_return_t (*pcm_recover)(void *userdata, void *pcm_handle, int revents); - audio_return_t (*pcm_get_params)(void *userdata, void *pcm_handle, uint32_t direction, void **sample_spec, uint32_t *period_size, uint32_t *periods); - audio_return_t (*pcm_set_params)(void *userdata, void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods); + audio_return_t (*pcm_open)(void *audio_handle, void **pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods); + audio_return_t (*pcm_start)(void *audio_handle, void *pcm_handle); + audio_return_t (*pcm_stop)(void *audio_handle, void *pcm_handle); + audio_return_t (*pcm_close)(void *audio_handle, void *pcm_handle); + audio_return_t (*pcm_avail)(void *audio_handle, void *pcm_handle, uint32_t *avail); + audio_return_t (*pcm_write)(void *audio_handle, void *pcm_handle, const void *buffer, uint32_t frames); + audio_return_t (*pcm_read)(void *audio_handle, void *pcm_handle, void *buffer, uint32_t frames); + audio_return_t (*pcm_get_fd)(void *audio_handle, void *pcm_handle, int *fd); + audio_return_t (*pcm_recover)(void *audio_handle, void *pcm_handle, int revents); + audio_return_t (*pcm_get_params)(void *audio_handle, void *pcm_handle, uint32_t direction, void **sample_spec, uint32_t *period_size, uint32_t *periods); + audio_return_t (*pcm_set_params)(void *audio_handle, void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods); } audio_interface_t; -audio_return_t audio_init(void **userdata); -audio_return_t audio_deinit(void **userdata); -audio_return_t audio_get_volume_level_max(void *userdata, audio_volume_info_t *info, uint32_t *level); -audio_return_t audio_get_volume_level(void *userdata, audio_volume_info_t *info, uint32_t *level); -audio_return_t audio_set_volume_level(void *userdata, audio_volume_info_t *info, uint32_t level); -audio_return_t audio_get_volume_value(void *userdata, audio_volume_info_t *info, uint32_t level, double *value); -audio_return_t audio_get_volume_mute(void *userdata, audio_volume_info_t *info, uint32_t *mute); -audio_return_t audio_set_volume_mute(void *userdata, audio_volume_info_t *info, uint32_t mute); -audio_return_t audio_do_route(void *userdata, audio_route_info_t *info); -audio_return_t audio_update_route_option(void *userdata, audio_route_option_t *option); -audio_return_t audio_update_stream_connection_info(void *userdata, audio_stream_info_t *info, uint32_t is_connected); -audio_return_t audio_get_buffer_attr(void *userdata, uint32_t direction, const char *latency, uint32_t samplerate, int format, uint32_t channels, +audio_return_t audio_init(void **audio_handle); +audio_return_t audio_deinit(void *audio_handle); +audio_return_t audio_get_volume_level_max(void *audio_handle, audio_volume_info_t *info, uint32_t *level); +audio_return_t audio_get_volume_level(void *audio_handle, audio_volume_info_t *info, uint32_t *level); +audio_return_t audio_set_volume_level(void *audio_handle, audio_volume_info_t *info, uint32_t level); +audio_return_t audio_get_volume_value(void *audio_handle, audio_volume_info_t *info, uint32_t level, double *value); +audio_return_t audio_get_volume_mute(void *audio_handle, audio_volume_info_t *info, uint32_t *mute); +audio_return_t audio_set_volume_mute(void *audio_handle, audio_volume_info_t *info, uint32_t mute); +audio_return_t audio_do_route(void *audio_handle, audio_route_info_t *info); +audio_return_t audio_update_route_option(void *audio_handle, audio_route_option_t *option); +audio_return_t audio_update_stream_connection_info(void *audio_handle, audio_stream_info_t *info, uint32_t is_connected); +audio_return_t audio_get_buffer_attr(void *audio_handle, uint32_t direction, const char *latency, uint32_t samplerate, int format, uint32_t channels, uint32_t *maxlength, uint32_t *tlength, uint32_t *prebuf, uint32_t* minreq, uint32_t *fragsize); -audio_return_t audio_pcm_open(void *userdata, void **pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods); -audio_return_t audio_pcm_start(void *userdata, void *pcm_handle); -audio_return_t audio_pcm_stop(void *userdata, void *pcm_handle); -audio_return_t audio_pcm_close(void *userdata, void *pcm_handle); -audio_return_t audio_pcm_avail(void *userdata, void *pcm_handle, uint32_t *avail); -audio_return_t audio_pcm_write(void *userdata, void *pcm_handle, const void *buffer, uint32_t frames); -audio_return_t audio_pcm_read(void *userdata, void *pcm_handle, void *buffer, uint32_t frames); -audio_return_t audio_pcm_get_fd(void *userdata, void *pcm_handle, int *fd); -audio_return_t audio_pcm_recover(void *userdata, void *pcm_handle, int revents); -audio_return_t audio_pcm_get_params(void *userdata, void *pcm_handle, uint32_t direction, void **sample_spec, uint32_t *period_size, uint32_t *periods); -audio_return_t audio_pcm_set_params(void *userdata, void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods); +audio_return_t audio_pcm_open(void *audio_handle, void **pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods); +audio_return_t audio_pcm_start(void *audio_handle, void *pcm_handle); +audio_return_t audio_pcm_stop(void *audio_handle, void *pcm_handle); +audio_return_t audio_pcm_close(void *audio_handle, void *pcm_handle); +audio_return_t audio_pcm_avail(void *audio_handle, void *pcm_handle, uint32_t *avail); +audio_return_t audio_pcm_write(void *audio_handle, void *pcm_handle, const void *buffer, uint32_t frames); +audio_return_t audio_pcm_read(void *audio_handle, void *pcm_handle, void *buffer, uint32_t frames); +audio_return_t audio_pcm_get_fd(void *audio_handle, void *pcm_handle, int *fd); +audio_return_t audio_pcm_recover(void *audio_handle, void *pcm_handle, int revents); +audio_return_t audio_pcm_get_params(void *audio_handle, void *pcm_handle, uint32_t direction, void **sample_spec, uint32_t *period_size, uint32_t *periods); +audio_return_t audio_pcm_set_params(void *audio_handle, void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods); #endif -- 2.7.4 From c7d78508b46961fef0039cc4a6ff92912be03ca7 Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Tue, 24 Nov 2015 21:20:28 +0900 Subject: [PATCH 04/16] stream-manager: Skip selecting device logic if a new stream has aleady been set to a device [Version] 5.0.19 [Profile] Common [Issue Type] Feature Enhancement Change-Id: I654b6971347c1bb3c0e6ce869e7aeeeeb361bc00 Signed-off-by: Sangchul Lee --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/stream-manager.c | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 62805ae..9347987 100644 --- a/packaging/pulseaudio-modules-tizen.spec +++ b/packaging/pulseaudio-modules-tizen.spec @@ -1,6 +1,6 @@ Name: pulseaudio-modules-tizen Summary: Pulseaudio modules for Tizen -Version: 5.0.18 +Version: 5.0.19 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/stream-manager.c b/src/stream-manager.c index 3895ed6..808ca6c 100644 --- a/src/stream-manager.c +++ b/src/stream-manager.c @@ -1901,6 +1901,7 @@ static void do_notify(pa_stream_manager *m, notify_command_type_t command, strea hal_stream_connection_info stream_conn_info; const char *role = NULL; void *s = NULL; + const char *modifier_gain = NULL; pa_assert(m); pa_log_debug("do_notify(%s): type(%d), is_new_data(%d), user_data(%p)", notify_command_type_str[command], type, is_new_data, user_data); @@ -1917,10 +1918,23 @@ static void do_notify(pa_stream_manager *m, notify_command_type_t command, strea hook_call_select_data.stream_role = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(s, type), PA_PROP_MEDIA_ROLE); fill_device_info_to_hook_data(m, &hook_call_select_data, command, type, s, is_new_data); hook_call_select_data.sample_spec = GET_STREAM_NEW_SAMPLE_SPEC(s, type); - if (type == STREAM_SINK_INPUT) + if (type == STREAM_SINK_INPUT) { hook_call_select_data.proper_sink = &(((pa_sink_input_new_data*)s)->sink); - else if (type == STREAM_SOURCE_OUTPUT) + /* need to check modifier_gain, because we do not skip a stream that is from module-sound-player */ + modifier_gain = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(s, type), PA_PROP_MEDIA_TIZEN_VOLUME_GAIN_TYPE); + if (((pa_sink_input_new_data*)s)->sink && !modifier_gain) { + pa_log_info(" - sink(%s) has been already selected, skip selecting sink", + (((pa_sink_input_new_data*)s)->sink)->name); + break; + } + } else if (type == STREAM_SOURCE_OUTPUT) { hook_call_select_data.proper_source = &(((pa_source_output_new_data*)s)->source); + if (((pa_source_output_new_data*)s)->source) { + pa_log_info(" - source(%s) has been already selected, skip selecting source", + (((pa_source_output_new_data*)s)->source)->name); + break; + } + } } else { hook_call_select_data.stream_role = pa_proplist_gets(GET_STREAM_PROPLIST(s, type), PA_PROP_MEDIA_ROLE); fill_device_info_to_hook_data(m, &hook_call_select_data, command, type, s, is_new_data); -- 2.7.4 From 2d6365dfae9aa38ae5bb2a8397db31b300637c3c Mon Sep 17 00:00:00 2001 From: KimJeongYeon Date: Fri, 27 Nov 2015 14:35:43 +0900 Subject: [PATCH 05/16] hal: tizenaudio reference sink / source improve latency calculation [Version] 5.0.20 [Profile] Common [Issue Type] Feature Enhancement Signed-off-by: KimJeongYeon Change-Id: I92de9d7e01926ba618d570dcb3ac23052ac0ba3c --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/module-tizenaudio-sink.c | 46 +++++++++++++++++---------------- src/module-tizenaudio-source.c | 37 +++++++++++--------------- 3 files changed, 40 insertions(+), 45 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 9347987..ce81ace 100644 --- a/packaging/pulseaudio-modules-tizen.spec +++ b/packaging/pulseaudio-modules-tizen.spec @@ -1,6 +1,6 @@ Name: pulseaudio-modules-tizen Summary: Pulseaudio modules for Tizen -Version: 5.0.19 +Version: 5.0.20 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/module-tizenaudio-sink.c b/src/module-tizenaudio-sink.c index 17712df..ada5442 100644 --- a/src/module-tizenaudio-sink.c +++ b/src/module-tizenaudio-sink.c @@ -86,6 +86,7 @@ struct userdata { pa_usec_t block_usec; pa_usec_t timestamp; + pa_usec_t timestamp_written; char* device_name; bool first; @@ -225,7 +226,6 @@ static int sink_process_msg( return -PA_ERR_IO; } - u->timestamp = pa_rtclock_now(); if (u->sink->thread_info.state == PA_SINK_SUSPENDED) { if ((r = unsuspend(u)) < 0) return r; @@ -241,11 +241,14 @@ static int sink_process_msg( break; case PA_SINK_MESSAGE_GET_LATENCY: { - pa_usec_t now; - - now = pa_rtclock_now(); - *((pa_usec_t*)data) = u->timestamp > now ? u->timestamp - now : 0ULL; - + pa_usec_t now = pa_rtclock_now(); + pa_usec_t latency = 0ULL; + if (u->timestamp > now) { + if ((u->timestamp - now) > (now - u->timestamp_written)) { + latency = (u->timestamp - now) + (u->timestamp_written - now); + } + } + *((pa_usec_t*)data) = latency; return 0; } } @@ -332,6 +335,7 @@ static int process_render(struct userdata *u, pa_usec_t now) { if (u->first) { pa_log_debug("Fill initial buffer"); frames_to_write = (u->frag_size * u->nfrags) / frame_size; + u->timestamp = u->timestamp_written = now; } else { frames_to_write = u->sink->thread_info.max_request / frame_size; if (frames_to_write > avail) @@ -346,6 +350,7 @@ static int process_render(struct userdata *u, pa_usec_t now) { pa_memblock_release(chunk.memblock); pa_memblock_unref(chunk.memblock); u->timestamp += pa_bytes_to_usec(chunk.length, &u->sink->sample_spec); + u->timestamp_written = pa_rtclock_now(); work_done = 1; @@ -366,7 +371,6 @@ static void thread_func(void *userdata) { pa_log_debug("Thread starting up"); pa_thread_mq_install(&u->thread_mq); - u->timestamp = pa_rtclock_now(); for (;;) { pa_usec_t now = 0; @@ -380,24 +384,20 @@ static void thread_func(void *userdata) { /* Render some data and drop it immediately */ if (PA_SINK_IS_OPENED(u->sink->thread_info.state)) { - if (u->timestamp <= now) { - int work_done = process_render(u, now); + int work_done = process_render(u, now); - if (work_done < 0) - goto fail; + if (work_done < 0) + goto fail; - if (work_done == 0) { - pa_rtpoll_set_timer_relative(u->rtpoll, (10 * PA_USEC_PER_MSEC)); - } else { - if (u->first) { - pa_log_info("Starting playback."); - pa_hal_manager_pcm_start(u->hal_manager, u->pcm_handle); - u->first = false; - } - pa_rtpoll_set_timer_absolute(u->rtpoll, u->timestamp); - } + if (work_done == 0) { + pa_rtpoll_set_timer_relative(u->rtpoll, (10 * PA_USEC_PER_MSEC)); } else { - pa_rtpoll_set_timer_absolute(u->rtpoll, u->timestamp); + if (u->first) { + pa_log_info("Starting playback."); + pa_hal_manager_pcm_start(u->hal_manager, u->pcm_handle); + u->first = false; + } + pa_rtpoll_set_timer_relative(u->rtpoll, (10 * PA_USEC_PER_MSEC)); } } else { pa_rtpoll_set_timer_disabled(u->rtpoll); @@ -518,6 +518,8 @@ int pa__init(pa_module*m) { unsuspend (u); u->block_usec = BLOCK_USEC; + u->timestamp = 0ULL; + u->timestamp_written = 0ULL; nbytes = pa_usec_to_bytes(u->block_usec, &u->sink->sample_spec); pa_sink_set_max_rewind(u->sink, 0); diff --git a/src/module-tizenaudio-source.c b/src/module-tizenaudio-source.c index 7479cf4..db97fad 100644 --- a/src/module-tizenaudio-source.c +++ b/src/module-tizenaudio-source.c @@ -227,7 +227,6 @@ static int source_process_msg( return -PA_ERR_IO; } - u->timestamp = pa_rtclock_now(); if (u->source->thread_info.state == PA_SOURCE_SUSPENDED) { if ((r = unsuspend(u)) < 0) return r; @@ -243,11 +242,8 @@ static int source_process_msg( break; case PA_SOURCE_MESSAGE_GET_LATENCY: { - pa_usec_t now; - - now = pa_rtclock_now(); - *((pa_usec_t*)data) = u->timestamp > now ? u->timestamp - now : 0ULL; - + pa_usec_t now = pa_rtclock_now(); + *((pa_usec_t*)data) = u->timestamp > now ? 0ULL : now - u->timestamp; return 0; } } @@ -327,7 +323,6 @@ static void thread_func(void *userdata) { pa_assert(u); pa_log_debug("Thread starting up"); pa_thread_mq_install(&u->thread_mq); - u->timestamp = pa_rtclock_now(); for (;;) { pa_usec_t now = 0; @@ -338,25 +333,22 @@ static void thread_func(void *userdata) { /* Render some data and drop it immediately */ if (PA_SOURCE_IS_OPENED(u->source->thread_info.state)) { - if (u->timestamp <= now) { - int work_done; + int work_done; - if (u->first) { - pa_log_info("Starting capture."); - pa_hal_manager_pcm_start(u->hal_manager, u->pcm_handle); - u->first = false; - } + if (u->first) { + pa_log_info("Starting capture."); + pa_hal_manager_pcm_start(u->hal_manager, u->pcm_handle); + u->first = false; + u->timestamp = now; + } - work_done = process_render(u, now); + work_done = process_render(u, now); - if (work_done < 0) - goto fail; + if (work_done < 0) + goto fail; - if (work_done == 0) { - pa_rtpoll_set_timer_relative(u->rtpoll, (10 * PA_USEC_PER_MSEC)); - } else { - pa_rtpoll_set_timer_absolute(u->rtpoll, u->timestamp); - } + if (work_done == 0) { + pa_rtpoll_set_timer_relative(u->rtpoll, (10 * PA_USEC_PER_MSEC)); } else { pa_rtpoll_set_timer_absolute(u->rtpoll, u->timestamp); } @@ -479,6 +471,7 @@ int pa__init(pa_module*m) { u->block_usec = BLOCK_USEC; u->latency_time = u->block_usec; + u->timestamp = 0ULL; pa_source_set_max_rewind(u->source, 0); -- 2.7.4 From da369d719b38fcceacc70b4430731bda0477757d Mon Sep 17 00:00:00 2001 From: Mok Jeongho Date: Mon, 7 Dec 2015 17:21:02 +0900 Subject: [PATCH 06/16] device-manager : Fix svace issues [Version] 5.0.21 [Profile] Common [Issue Type] Static Analysis Change-Id: Ieb797826f339c46cd1c5f4e1b5c7dd749e7bf7fe --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/device-manager.c | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index ce81ace..0f5f8b7 100644 --- a/packaging/pulseaudio-modules-tizen.spec +++ b/packaging/pulseaudio-modules-tizen.spec @@ -1,6 +1,6 @@ Name: pulseaudio-modules-tizen Summary: Pulseaudio modules for Tizen -Version: 5.0.20 +Version: 5.0.21 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/device-manager.c b/src/device-manager.c index 1b3724c..6f44f03 100644 --- a/src/device-manager.c +++ b/src/device-manager.c @@ -2226,10 +2226,6 @@ failed : pa_hashmap_free(playback); if (capture) pa_hashmap_free(capture); - if (device_item && made_newly) - pa_xfree(device_item); - if (profile_item) - pa_xfree(profile_item); return NULL; } @@ -2856,8 +2852,6 @@ static struct device_file_info* parse_device_file_object(json_object *device_fil return file_info; failed : - if (roles) - pa_xfree(roles); return NULL; } @@ -3125,6 +3119,7 @@ static int handle_device_connected(pa_device_manager *dm, const char *device_typ if (!(type_info = _device_manager_get_type_info(dm->type_infos, device_type, device_profile))) { pa_log_error("Failed to get type_info for %s.%s", device_type, device_profile); + return -1; } if((device_item = _device_manager_get_device(dm->device_list, type_info->type))) { @@ -3800,8 +3795,8 @@ static void handle_get_bt_a2dp_status(DBusConnection *conn, DBusMessage *msg, vo pa_assert_se((reply = dbus_message_new_method_return(msg))); - if (!(device_item = _device_manager_get_device(dm->device_list, DEVICE_TYPE_BT))) { - if (!(profile_item = _device_item_get_profile(device_item, DEVICE_PROFILE_BT_A2DP))) { + if ((device_item = _device_manager_get_device(dm->device_list, DEVICE_TYPE_BT)) != NULL) { + if ((profile_item = _device_item_get_profile(device_item, DEVICE_PROFILE_BT_A2DP)) != NULL) { is_bt_on = TRUE; bt_name = device_item->name; } -- 2.7.4 From 1965ebf236297285846b824ee216d1747462f6dc Mon Sep 17 00:00:00 2001 From: KimJeongYeon Date: Mon, 7 Dec 2015 17:16:14 +0900 Subject: [PATCH 07/16] hal: tizenaudio reference sink / source support realtime scheduling [Version] 5.0.21 [Profile] Common [Issue Type] Feature Enhancement Signed-off-by: KimJeongYeon Change-Id: I53dc22d8af49f1da4e5978193b9e9af078876d08 --- src/module-tizenaudio-sink.c | 4 ++++ src/module-tizenaudio-source.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/module-tizenaudio-sink.c b/src/module-tizenaudio-sink.c index ada5442..07e7ed3 100644 --- a/src/module-tizenaudio-sink.c +++ b/src/module-tizenaudio-sink.c @@ -370,6 +370,10 @@ static void thread_func(void *userdata) { pa_assert(u); pa_log_debug("Thread starting up"); + + if (u->core->realtime_scheduling) + pa_make_realtime(u->core->realtime_priority); + pa_thread_mq_install(&u->thread_mq); for (;;) { diff --git a/src/module-tizenaudio-source.c b/src/module-tizenaudio-source.c index db97fad..4350264 100644 --- a/src/module-tizenaudio-source.c +++ b/src/module-tizenaudio-source.c @@ -322,6 +322,10 @@ static void thread_func(void *userdata) { pa_assert(u); pa_log_debug("Thread starting up"); + + if (u->core->realtime_scheduling) + pa_make_realtime(u->core->realtime_priority); + pa_thread_mq_install(&u->thread_mq); for (;;) { -- 2.7.4 From 0d5472be6635b46f2ed41b1ccf0a4d7c58ede7b6 Mon Sep 17 00:00:00 2001 From: Mok Jeongho Date: Tue, 24 Nov 2015 21:51:12 +0900 Subject: [PATCH 08/16] device-manager : remove not using enumeration [Version] 5.0.22 [Profile] Common [Issue Type] Code clean up Change-Id: Ibcca51b575f8cfcdc313789a8004f157d6581f78 --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/device-manager.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 0f5f8b7..4e68352 100644 --- a/packaging/pulseaudio-modules-tizen.spec +++ b/packaging/pulseaudio-modules-tizen.spec @@ -1,6 +1,6 @@ Name: pulseaudio-modules-tizen Summary: Pulseaudio modules for Tizen -Version: 5.0.21 +Version: 5.0.22 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/device-manager.h b/src/device-manager.h index 303a081..0e49f68 100644 --- a/src/device-manager.h +++ b/src/device-manager.h @@ -29,8 +29,7 @@ typedef enum dm_device_direction_type { typedef enum dm_device_changed_into_type { DM_DEVICE_CHANGED_INFO_STATE, - DM_DEVICE_CHANGED_INFO_IO_DIRECTION, - DM_DEVICE_CHANGED_INFO_SUBTYPE, + DM_DEVICE_CHANGED_INFO_IO_DIRECTION } dm_device_changed_info_t; typedef enum dm_device_state_type { -- 2.7.4 From 7db933dd91b00361c24a00a6deeb8a951612d3b1 Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Wed, 9 Dec 2015 16:03:33 +0900 Subject: [PATCH 09/16] module-policy/stream-manager: Fix svace issues [Version] 5.0.23 [Profile] Common [Issue Type] Static Analysis Change-Id: Ia1028ab8545d34efffad377f42470c9361dfbb13 Signed-off-by: Sangchul Lee --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/module-policy.c | 41 +++++------ src/stream-manager.c | 127 +++++++++++++++++--------------- 3 files changed, 89 insertions(+), 81 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 4e68352..9638f74 100644 --- a/packaging/pulseaudio-modules-tizen.spec +++ b/packaging/pulseaudio-modules-tizen.spec @@ -1,6 +1,6 @@ Name: pulseaudio-modules-tizen Summary: Pulseaudio modules for Tizen -Version: 5.0.22 +Version: 5.0.23 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/module-policy.c b/src/module-policy.c index 454cae4..7008639 100644 --- a/src/module-policy.c +++ b/src/module-policy.c @@ -735,7 +735,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ pa_log_debug("[ROUTE][AUTO_ALL] combine_sink_arg1[%s], combine_sink_arg2[%p]", sink->name, combine_sink_arg2); } else if (data->stream_type == STREAM_SINK_INPUT && !combine_sink_arg2) { sink = combine_sink_arg2 = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL); - if(sink && !pa_streq(sink->name, combine_sink_arg1->name)) { + if (sink && !pa_streq(sink->name, combine_sink_arg1->name)) { pa_log_debug("[ROUTE][AUTO_ALL] combine_sink_arg2[%s]", sink->name); /* load combine sink */ if (!u->module_combine_sink) { @@ -744,13 +744,16 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ u->module_combine_sink = pa_module_load(u->core, MODULE_COMBINE_SINK, args); pa_xfree(args); } - sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK); - PA_IDXSET_FOREACH (s, combine_sink_arg1->inputs, s_idx) { - if (s == data->stream) { - pa_sink_input_move_to(s, sink, FALSE); - pa_log_debug("[ROUTE][AUTO_ALL] *** sink-#if 0input(%p,%u) moves to sink(%p,%s)", s, ((pa_sink_input*)s)->index, sink, sink->name); + if ((sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK))) { + PA_IDXSET_FOREACH (s, combine_sink_arg1->inputs, s_idx) { + if (s == data->stream) { + pa_sink_input_move_to(s, sink, FALSE); + pa_log_debug("[ROUTE][AUTO_ALL] *** sink-nput(%p,%u) moves to sink(%p,%s)", + s, ((pa_sink_input*)s)->index, sink, sink->name); + } } - } + } else + pa_log_error("[ROUTE][AUTO_ALL] could not get combine_sink"); } } else if (data->stream_type == STREAM_SOURCE_OUTPUT) source = pa_device_manager_get_source(device, DEVICE_ROLE_NORMAL); @@ -764,17 +767,16 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ /* move sink-inputs/source-outputs if needed */ if (data->idx_streams) { PA_IDXSET_FOREACH (s, data->idx_streams, s_idx) { /* data->idx_streams: null_sink */ - if ((sink && (sink != ((pa_sink_input*)s)->sink)) || (source && (source != ((pa_source_output*)s)->source))) { - if (!pa_stream_manager_get_route_type(s, FALSE, data->stream_type, &route_type) && (route_type == STREAM_ROUTE_TYPE_AUTO_ALL)) { - if (data->stream_type == STREAM_SINK_INPUT) { - pa_sink_input_move_to(s, sink, FALSE); - pa_log_debug("[ROUTE][AUTO_ALL] *** sink-input(%p,%u) moves to sink(%p,%s)", - s, ((pa_sink_input*)s)->index, sink, sink->name); - } else if (data->stream_type == STREAM_SOURCE_OUTPUT) { - pa_source_output_move_to(s, source, FALSE); - pa_log_debug("[ROUTE][AUTO_ALL] *** source-output(%p,%u) moves to source(%p,%s)", - s, ((pa_source_output*)s)->index, source, source->name); - } + if (!pa_stream_manager_get_route_type(s, FALSE, data->stream_type, &route_type) && + (route_type == STREAM_ROUTE_TYPE_AUTO_ALL)) { + if ((data->stream_type == STREAM_SINK_INPUT) && (sink && (sink != ((pa_sink_input*)s)->sink))) { + pa_sink_input_move_to(s, sink, FALSE); + pa_log_debug("[ROUTE][AUTO_ALL] *** sink-input(%p,%u) moves to sink(%p,%s)", + s, ((pa_sink_input*)s)->index, sink, sink->name); + } else if ((data->stream_type == STREAM_SOURCE_OUTPUT) && (source && (source != ((pa_source_output*)s)->source))) { + pa_source_output_move_to(s, source, FALSE); + pa_log_debug("[ROUTE][AUTO_ALL] *** source-output(%p,%u) moves to source(%p,%s)", + s, ((pa_source_output*)s)->index, source, source->name); } } } @@ -1619,9 +1621,6 @@ int pa__init(pa_module *m) return 0; fail: - if (ma) - pa_modargs_free(ma); - pa__done(m); return -1; diff --git a/src/stream-manager.c b/src/stream-manager.c index 808ca6c..dd20e7e 100644 --- a/src/stream-manager.c +++ b/src/stream-manager.c @@ -1073,22 +1073,24 @@ static void handle_update_focus_status(DBusConnection *conn, DBusMessage *msg, v if (sp->focus_status != (acquired_focus_status & (STREAM_FOCUS_ACQUIRED_PLAYBACK|STREAM_FOCUS_ACQUIRED_CAPTURE))) { /* need to update */ sp->focus_status = acquired_focus_status & (STREAM_FOCUS_ACQUIRED_PLAYBACK|STREAM_FOCUS_ACQUIRED_CAPTURE); - if (sp->idx_sink_inputs) + if (sp->idx_sink_inputs) { count = pa_idxset_size(sp->idx_sink_inputs); - PA_IDXSET_FOREACH(stream, sp->idx_sink_inputs, idx) { - pa_proplist_sets(GET_STREAM_PROPLIST(stream, STREAM_SINK_INPUT), PA_PROP_MEDIA_FOCUS_STATUS, - IS_FOCUS_ACQUIRED(sp->focus_status, STREAM_SINK_INPUT)?STREAM_FOCUS_PLAYBACK:STREAM_FOCUS_NONE); + PA_IDXSET_FOREACH(stream, sp->idx_sink_inputs, idx) { + pa_proplist_sets(GET_STREAM_PROPLIST(stream, STREAM_SINK_INPUT), PA_PROP_MEDIA_FOCUS_STATUS, + IS_FOCUS_ACQUIRED(sp->focus_status, STREAM_SINK_INPUT)?STREAM_FOCUS_PLAYBACK:STREAM_FOCUS_NONE); if (--count == 0) process_stream(m, stream, STREAM_SINK_INPUT, PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_FOCUS_CHANGED, FALSE); } - if (sp->idx_source_outputs) + } + if (sp->idx_source_outputs) { count = pa_idxset_size(sp->idx_source_outputs); PA_IDXSET_FOREACH(stream, sp->idx_source_outputs, idx) { pa_proplist_sets(GET_STREAM_PROPLIST(stream, STREAM_SOURCE_OUTPUT), PA_PROP_MEDIA_FOCUS_STATUS, - IS_FOCUS_ACQUIRED(sp->focus_status, STREAM_SOURCE_OUTPUT)?STREAM_FOCUS_CAPTURE:STREAM_FOCUS_NONE); + IS_FOCUS_ACQUIRED(sp->focus_status, STREAM_SOURCE_OUTPUT)?STREAM_FOCUS_CAPTURE:STREAM_FOCUS_NONE); if (--count == 0) process_stream(m, stream, STREAM_SOURCE_OUTPUT, PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_FOCUS_CHANGED, FALSE); } + } } else pa_log_debug("same as before, skip updating focus status[0x%x]", acquired_focus_status); @@ -1826,66 +1828,73 @@ static void fill_device_info_to_hook_data(pa_stream_manager *m, void *hook_data, switch (command) { case NOTIFY_COMMAND_SELECT_PROPER_SINK_OR_SOURCE_FOR_INIT: { select_data = (pa_stream_manager_hook_data_for_select*)hook_data; - si = pa_hashmap_get(m->stream_infos, select_data->stream_role); - select_data->route_type = si->route_type; - avail_devices = (type == STREAM_SINK_INPUT) ? si->idx_avail_out_devices : si->idx_avail_in_devices; - list_len = pa_idxset_size(avail_devices); - device_none = pa_idxset_get_by_data(avail_devices, "none", NULL); - if (list_len == 0 || device_none) { - pa_log_warn(" -- there is no available device, stream_type(%d)", type); - break; - } - select_data->idx_avail_devices = avail_devices; - select_data->origins_from_new_data = is_new_data; - if (si->route_type >= STREAM_ROUTE_TYPE_MANUAL) { + if ((si = pa_hashmap_get(m->stream_infos, select_data->stream_role))) { + select_data->route_type = si->route_type; + avail_devices = (type == STREAM_SINK_INPUT) ? si->idx_avail_out_devices : si->idx_avail_in_devices; + list_len = pa_idxset_size(avail_devices); + device_none = pa_idxset_get_by_data(avail_devices, "none", NULL); + + if (list_len == 0 || device_none) { + pa_log_warn(" -- there is no available device, stream_type(%d)", type); + break; + } + select_data->idx_avail_devices = avail_devices; + select_data->origins_from_new_data = is_new_data; + if (si->route_type >= STREAM_ROUTE_TYPE_MANUAL) { + if (is_new_data) + p_idx = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_PARENT_ID); + 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)) { + /* find parent idx, it's device info. and it's stream idxs */ + sp = pa_hashmap_get(m->stream_parents, (const void*)parent_idx); + if (sp) + select_data->idx_manual_devices = (type == STREAM_SINK_INPUT) ? (sp->idx_route_out_devices) : (sp->idx_route_in_devices); + else + pa_log_warn(" -- failed to get the stream parent of idx(%u)", parent_idx); + } else + pa_log_warn(" -- could not get the parent id of this stream, but keep going..."); + } + } else + pa_log_error(" -- could not find (%s)", route_data->stream_role); + + break; + } + case NOTIFY_COMMAND_CHANGE_ROUTE_START: + case NOTIFY_COMMAND_CHANGE_ROUTE_END: { + route_data = (pa_stream_manager_hook_data_for_route*)hook_data; + if ((si = pa_hashmap_get(m->stream_infos, route_data->stream_role))) { + avail_devices = (type == STREAM_SINK_INPUT) ? si->idx_avail_out_devices : si->idx_avail_in_devices; + route_data->route_type = si->route_type; + list_len = pa_idxset_size(avail_devices); + device_none = pa_idxset_get_by_data(avail_devices, "none", NULL); + + if (list_len == 0 || device_none) { + pa_log_warn(" -- there is no available device, stream_type(%d)", type); + break; + } if (is_new_data) p_idx = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_PARENT_ID); 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)) { - /* find parent idx, it's device info. and it's stream idxs */ sp = pa_hashmap_get(m->stream_parents, (const void*)parent_idx); - if (sp) - select_data->idx_manual_devices = (type == STREAM_SINK_INPUT) ? (sp->idx_route_out_devices) : (sp->idx_route_in_devices); - else + if (!sp) pa_log_warn(" -- failed to get the stream parent of idx(%u)", parent_idx); } else - pa_log_warn(" -- could not get the parent id of this stream, but keep going..."); - } - break; - } - case NOTIFY_COMMAND_CHANGE_ROUTE_START: - case NOTIFY_COMMAND_CHANGE_ROUTE_END: { - route_data = (pa_stream_manager_hook_data_for_route*)hook_data; - si = pa_hashmap_get(m->stream_infos, route_data->stream_role); - avail_devices = (type == STREAM_SINK_INPUT) ? si->idx_avail_out_devices : si->idx_avail_in_devices; - route_data->route_type = si->route_type; - list_len = pa_idxset_size(avail_devices); - device_none = pa_idxset_get_by_data(avail_devices, "none", NULL); - - if (is_new_data) - p_idx = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_PARENT_ID); - 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)) { - sp = pa_hashmap_get(m->stream_parents, (const void*)parent_idx); - if (!sp) - pa_log_warn(" -- failed to get the stream parent of idx(%u)", parent_idx); + pa_log_warn(" -- could not get the parent id of this stream, but keep going..."); + + route_data->idx_avail_devices = avail_devices; + if (si->route_type >= STREAM_ROUTE_TYPE_MANUAL) { + if (sp) { + route_data->idx_manual_devices = (type == STREAM_SINK_INPUT) ? (sp->idx_route_out_devices) : (sp->idx_route_in_devices); + route_data->idx_streams = (type == STREAM_SINK_INPUT) ? (sp->idx_sink_inputs) : (sp->idx_source_outputs); + } else + pa_log_warn(" -- failed to get the stream parent of idx(%u)", parent_idx); + } } else - pa_log_warn(" -- could not get the parent id of this stream, but keep going..."); + pa_log_error(" -- could not find (%s)", route_data->stream_role); - if (list_len == 0 || device_none) { - pa_log_warn(" -- there is no available device, stream_type(%d)", type); - break; - } - route_data->idx_avail_devices = avail_devices; - if (si->route_type >= STREAM_ROUTE_TYPE_MANUAL) { - if (sp) { - route_data->idx_manual_devices = (type == STREAM_SINK_INPUT) ? (sp->idx_route_out_devices) : (sp->idx_route_in_devices); - route_data->idx_streams = (type == STREAM_SINK_INPUT) ? (sp->idx_sink_inputs) : (sp->idx_source_outputs); - } else - pa_log_warn(" -- failed to get the stream parent of idx(%u)", parent_idx); - } break; } default: @@ -2975,7 +2984,7 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_device_ ((route_type == STREAM_ROUTE_TYPE_AUTO) || (route_type == STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED))) { /* remove activated device info. if it has the AUTO route type */ active_dev = pa_proplist_gets(GET_STREAM_PROPLIST(s, STREAM_SOURCE_OUTPUT), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV); - if (pa_streq(active_dev, device_type)) + if (active_dev && pa_streq(active_dev, device_type)) pa_proplist_sets(GET_STREAM_PROPLIST(s, STREAM_SOURCE_OUTPUT), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, ACTIVE_DEV_REMOVED); } } @@ -2999,7 +3008,7 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_device_ ((route_type == STREAM_ROUTE_TYPE_AUTO) || (route_type == STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED))) { /* remove activated device info. if it has the AUTO route type */ active_dev = pa_proplist_gets(GET_STREAM_PROPLIST(s, STREAM_SINK_INPUT), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV); - if (pa_streq(active_dev, device_type)) + if (active_dev && pa_streq(active_dev, device_type)) pa_proplist_sets(GET_STREAM_PROPLIST(s, STREAM_SINK_INPUT), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, ACTIVE_DEV_REMOVED); } } @@ -3036,7 +3045,7 @@ static void subscribe_cb(pa_core *core, pa_subscription_event_type_t t, uint32_t return; } name = pa_proplist_gets(client->proplist, PA_PROP_APPLICATION_NAME); - if (strncmp (name, STREAM_MANAGER_CLIENT_NAME, strlen(STREAM_MANAGER_CLIENT_NAME))) { + if (name && strncmp (name, STREAM_MANAGER_CLIENT_NAME, strlen(STREAM_MANAGER_CLIENT_NAME))) { pa_log_warn(" - this is not a client(%s) that we should take care of, skip it", name); return; } -- 2.7.4 From a79cca9de3f87595c0c5bd8665fc0f55f378dd4a Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Mon, 14 Dec 2015 19:39:32 +0900 Subject: [PATCH 10/16] Fix SVACE defects Change-Id: I8c1cb7e3b19d55ef0742ba680d4616627346fba5 --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/hal-manager.c | 36 ++++++++++++++++----------------- src/module-sound-player.c | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 9638f74..10b6825 100644 --- a/packaging/pulseaudio-modules-tizen.spec +++ b/packaging/pulseaudio-modules-tizen.spec @@ -1,6 +1,6 @@ Name: pulseaudio-modules-tizen Summary: Pulseaudio modules for Tizen -Version: 5.0.23 +Version: 5.0.24 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/hal-manager.c b/src/hal-manager.c index 5866399..64888d8 100644 --- a/src/hal-manager.c +++ b/src/hal-manager.c @@ -216,7 +216,7 @@ int32_t pa_hal_manager_get_volume_mute(pa_hal_manager *h, const char *volume_typ info.type = volume_type; info.direction = direction; - if (AUDIO_IS_ERROR(hal_ret = h->intf.get_volume_mute(h->ah_handle, &info, mute))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.get_volume_mute(h->ah_handle, &info, mute)))) { pa_log_error("get_mute returns error:0x%x", hal_ret); ret = -1; } @@ -234,7 +234,7 @@ int32_t pa_hal_manager_set_volume_mute(pa_hal_manager *h, const char *volume_typ info.type = volume_type; info.direction = direction; - if (AUDIO_IS_ERROR(hal_ret = h->intf.set_volume_mute(h->ah_handle, &info, mute))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.set_volume_mute(h->ah_handle, &info, mute)))) { pa_log_error("set_mute returns error:0x%x", hal_ret); ret = -1; } @@ -248,7 +248,7 @@ int32_t pa_hal_manager_do_route(pa_hal_manager *h, hal_route_info *info) { pa_assert(h); pa_assert(info); - if (AUDIO_IS_ERROR(hal_ret = h->intf.do_route(h->ah_handle, (audio_route_info_t*)info))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.do_route(h->ah_handle, (audio_route_info_t*)info)))) { pa_log_error("do_route returns error:0x%x", hal_ret); ret = -1; } @@ -262,7 +262,7 @@ int32_t pa_hal_manager_update_route_option(pa_hal_manager *h, hal_route_option * pa_assert(h); pa_assert(option); - if (AUDIO_IS_ERROR(hal_ret = h->intf.update_route_option(h->ah_handle, (audio_route_option_t*)option))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.update_route_option(h->ah_handle, (audio_route_option_t*)option)))) { pa_log_error("update_route_option returns error:0x%x", hal_ret); ret = -1; } @@ -281,7 +281,7 @@ int32_t pa_hal_manager_update_stream_connection_info(pa_hal_manager *h, hal_stre hal_info.direction = info->direction; hal_info.idx = info->idx; - if (AUDIO_IS_ERROR(hal_ret = h->intf.update_stream_connection_info(h->ah_handle, &hal_info, (uint32_t)info->is_connected))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.update_stream_connection_info(h->ah_handle, &hal_info, (uint32_t)info->is_connected)))) { pa_log_error("update_stream_connection_info returns error:0x%x", hal_ret); ret = -1; } @@ -299,8 +299,8 @@ int32_t pa_hal_manager_get_buffer_attribute(pa_hal_manager *h, hal_stream_info * pa_log_info("latency:%s, rate:%u, format:%d, channels:%u", info->latency, info->sample_spec->rate, info->sample_spec->format, info->sample_spec->channels); - if (AUDIO_IS_ERROR(hal_ret = h->intf.get_buffer_attr(h->ah_handle, info->direction, info->latency, info->sample_spec->rate, info->sample_spec->format, - info->sample_spec->channels, maxlength, tlength, prebuf, minreq, fragsize))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.get_buffer_attr(h->ah_handle, info->direction, info->latency, info->sample_spec->rate, info->sample_spec->format, + info->sample_spec->channels, maxlength, tlength, prebuf, minreq, fragsize)))) { pa_log_error("get_buffer_attr returns error:0x%x", hal_ret); ret = -1; } else @@ -317,7 +317,7 @@ int32_t pa_hal_manager_pcm_open(pa_hal_manager *h, pcm_handle *pcm_h, io_directi pa_assert(pcm_h); pa_assert(sample_spec); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_open(h->ah_handle, pcm_h, direction, sample_spec, period_size, periods))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.pcm_open(h->ah_handle, pcm_h, direction, sample_spec, period_size, periods)))) { pa_log_error("pcm_open returns error:0x%x", hal_ret); ret = -1; } @@ -331,7 +331,7 @@ int32_t pa_hal_manager_pcm_start(pa_hal_manager *h, pcm_handle pcm_h) { pa_assert(h); pa_assert(pcm_h); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_start(h->ah_handle, pcm_h))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.pcm_start(h->ah_handle, pcm_h)))) { pa_log_error("pcm_start returns error:0x%x", hal_ret); ret = -1; } @@ -345,7 +345,7 @@ int32_t pa_hal_manager_pcm_stop(pa_hal_manager *h, pcm_handle pcm_h) { pa_assert(h); pa_assert(pcm_h); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_stop(h->ah_handle, pcm_h))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.pcm_stop(h->ah_handle, pcm_h)))) { pa_log_error("pcm_stop returns error:0x%x", hal_ret); ret = -1; } @@ -359,7 +359,7 @@ int32_t pa_hal_manager_pcm_close(pa_hal_manager *h, pcm_handle pcm_h) { pa_assert(h); pa_assert(pcm_h); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_close(h->ah_handle, pcm_h))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.pcm_close(h->ah_handle, pcm_h)))) { pa_log_error("pcm_close returns error:0x%x", hal_ret); ret = -1; } @@ -374,7 +374,7 @@ int32_t pa_hal_manager_pcm_available(pa_hal_manager *h, pcm_handle pcm_h, uint32 pa_assert(pcm_h); pa_assert(available); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_avail(h->ah_handle, pcm_h, available))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.pcm_avail(h->ah_handle, pcm_h, available)))) { pa_log_error("pcm_avail returns error:0x%x", hal_ret); ret = -1; } @@ -389,7 +389,7 @@ int32_t pa_hal_manager_pcm_write(pa_hal_manager *h, pcm_handle pcm_h, const void pa_assert(pcm_h); pa_assert(buffer); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_write(h->ah_handle, pcm_h, buffer, frames))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.pcm_write(h->ah_handle, pcm_h, buffer, frames)))) { pa_log_error("pcm_write returns error:0x%x", hal_ret); ret = -1; } @@ -404,7 +404,7 @@ int32_t pa_hal_manager_pcm_read(pa_hal_manager *h, pcm_handle pcm_h, void *buffe pa_assert(pcm_h); pa_assert(buffer); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_read(h->ah_handle, pcm_h, buffer, frames))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.pcm_read(h->ah_handle, pcm_h, buffer, frames)))) { pa_log_error("pcm_read returns error:0x%x", hal_ret); ret = -1; } @@ -419,7 +419,7 @@ int32_t pa_hal_manager_pcm_get_fd(pa_hal_manager *h, pcm_handle pcm_h, int *fd) pa_assert(pcm_h); pa_assert(fd); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_get_fd(h->ah_handle, pcm_h, fd))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.pcm_get_fd(h->ah_handle, pcm_h, fd)))) { pa_log_error("pcm_get_fd returns error:0x%x", hal_ret); ret = -1; } @@ -433,7 +433,7 @@ int32_t pa_hal_manager_pcm_recover(pa_hal_manager *h, pcm_handle pcm_h, int err) pa_assert(h); pa_assert(pcm_h); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_recover(h->ah_handle, pcm_h, err))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.pcm_recover(h->ah_handle, pcm_h, err)))) { pa_log_error("pcm_recover returns error:0x%x", hal_ret); ret = -1; } @@ -449,7 +449,7 @@ int32_t pa_hal_manager_pcm_get_params(pa_hal_manager *h, pcm_handle pcm_h, uint3 pa_assert(period_size); pa_assert(periods); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_get_params(h->ah_handle, pcm_h, direction, sample_spec, period_size, periods))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.pcm_get_params(h->ah_handle, pcm_h, direction, sample_spec, period_size, periods)))) { pa_log_error("pcm_get_params returns error:0x%x", hal_ret); ret = -1; } @@ -463,7 +463,7 @@ int32_t pa_hal_manager_pcm_set_params(pa_hal_manager *h, pcm_handle pcm_h, uint3 pa_assert(h); pa_assert(sample_spec); - if (AUDIO_IS_ERROR(hal_ret = h->intf.pcm_set_params(h->ah_handle, pcm_h, direction, sample_spec, period_size, periods))) { + if (AUDIO_IS_ERROR((hal_ret = h->intf.pcm_set_params(h->ah_handle, pcm_h, direction, sample_spec, period_size, periods)))) { pa_log_error("pcm_set_params returns error:0x%x", hal_ret); ret = -1; } diff --git a/src/module-sound-player.c b/src/module-sound-player.c index 1e6f0a6..9341c83 100644 --- a/src/module-sound-player.c +++ b/src/module-sound-player.c @@ -251,7 +251,7 @@ static int _sample_play(struct userdata *u, const char *sample_name, const char if (scache_idx != PA_IDXSET_INVALID) { pa_log_debug("pa_scache_play_item() start, scache idx[%u] for name[%s]", scache_idx, sample_name); /* for more precision, need to update volume value here */ - if ((ret = pa_scache_play_item(u->module->core, sample_name, sink, PA_VOLUME_NORM, p, &stream_idx) < 0)) { + if ((ret = pa_scache_play_item(u->module->core, sample_name, sink, PA_VOLUME_NORM, p, &stream_idx)) < 0) { pa_log_error("pa_scache_play_item fail"); goto exit; } -- 2.7.4 From fe463db3b052804ea51f2a71707a1fd9ad5dcbd3 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Tue, 15 Dec 2015 11:31:19 +0900 Subject: [PATCH 11/16] Fix for coding rules Change-Id: I74d3ba3b507126116bb38941bef5948bb14e75aa --- src/device-manager.c | 87 +++++++++++++++---------------- src/module-policy.c | 96 +++++++++++++++++----------------- src/module-sound-player.c | 18 +++---- src/module-tizenaudio-sink.c | 4 +- src/module-tizenaudio-source.c | 4 +- src/stream-manager-priv.h | 8 +-- src/stream-manager-volume.c | 18 +++---- src/stream-manager.c | 114 ++++++++++++++++++++--------------------- src/stream-manager.h | 4 +- 9 files changed, 175 insertions(+), 178 deletions(-) diff --git a/src/device-manager.c b/src/device-manager.c index 6f44f03..9a0ea06 100644 --- a/src/device-manager.c +++ b/src/device-manager.c @@ -199,7 +199,7 @@ static const char* const valid_alsa_device_modargs[] = { /* A macro to ease iteration through all entries */ #define PA_HASHMAP_FOREACH_KEY(e, h, state, key) \ - for ((state) = NULL, (e) = pa_hashmap_iterate((h), &(state),(const void**)&(key)); (e); (e) = pa_hashmap_iterate((h), &(state), (const void**)&(key))) + for ((state) = NULL, (e) = pa_hashmap_iterate((h), &(state), (const void**)&(key)); (e); (e) = pa_hashmap_iterate((h), &(state), (const void**)&(key))) #define PA_DEVICE(pulse_device, pdt) \ pdt == PA_DEVICE_TYPE_SINK ? ((pa_sink *) pulse_device) : ((pa_source *) pulse_device) @@ -655,7 +655,7 @@ static pa_bool_t pulse_device_is_alsa(pa_proplist *prop) { } if ((api_name = pa_proplist_gets(prop, PA_PROP_DEVICE_API))) { - if (pa_streq (api_name, DEVICE_API_ALSA)) { + if (pa_streq(api_name, DEVICE_API_ALSA)) { return TRUE; } else { return FALSE; @@ -674,7 +674,7 @@ static pa_bool_t pulse_device_is_bluez(pa_proplist *prop) { } if ((api_name = pa_proplist_gets(prop, PA_PROP_DEVICE_API))) { - if (pa_streq (api_name, DEVICE_API_BLUEZ)) { + if (pa_streq(api_name, DEVICE_API_BLUEZ)) { return TRUE; } else { return FALSE; @@ -703,7 +703,7 @@ static pa_bool_t pulse_device_is_usb(pa_proplist *prop) { const char *bus_name = NULL; if ((bus_name = pa_proplist_gets(prop, PA_PROP_DEVICE_BUS))) { - if (pa_streq (bus_name, DEVICE_BUS_USB)) { + if (pa_streq(bus_name, DEVICE_BUS_USB)) { return TRUE; } else { return FALSE; @@ -950,7 +950,7 @@ static void dump_playback_device_list(pa_hashmap *playback_devices) { } static void dump_capture_device_list(pa_hashmap *capture_devices) { - pa_source *source= NULL; + pa_source *source = NULL; void *state = NULL; const char *role; @@ -1019,7 +1019,7 @@ static pa_bool_t pulse_device_class_is_sound(pa_proplist *prop) { const char *device_class = NULL; if ((device_class = pa_proplist_gets(prop, PA_PROP_DEVICE_CLASS))) { - if (device_class && pa_streq (device_class, DEVICE_CLASS_SOUND)) { + if (device_class && pa_streq(device_class, DEVICE_CLASS_SOUND)) { return TRUE; } else { return FALSE; @@ -1037,7 +1037,7 @@ static pa_bool_t pulse_device_class_is_monitor(pa_proplist *prop) { } if ((device_class = pa_proplist_gets(prop, PA_PROP_DEVICE_CLASS))) { - if (device_class && pa_streq (device_class, DEVICE_CLASS_MONITOR)) { + if (device_class && pa_streq(device_class, DEVICE_CLASS_MONITOR)) { return TRUE; } else { return FALSE; @@ -1305,7 +1305,7 @@ static dm_device* _device_item_set_active_profile(dm_device *device_item, const dm_device_profile *profile_item = NULL; uint32_t idx, active_profile_idx = PA_INVALID_INDEX, prev_active_profile = PA_INVALID_INDEX; - if (!device_item || !device_item->profiles ) { + if (!device_item || !device_item->profiles) { pa_log_error("Invalid Parameter"); return NULL; } @@ -1363,7 +1363,7 @@ static dm_device* _device_item_set_active_profile_auto(dm_device *device_item) { uint32_t idx, prev_active_profile; unsigned int device_size; - if (!device_item || !device_item->profiles ) { + if (!device_item || !device_item->profiles) { pa_log_error("Invalid Parameter"); return NULL; } @@ -1630,12 +1630,12 @@ static dm_device_profile* _device_profile_add_pulse_device(dm_device_profile *pr if (pdt == PA_DEVICE_TYPE_SINK) { if (!(profile_item->playback_devices)) profile_item->playback_devices = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); - if(pa_hashmap_put(profile_item->playback_devices, (void *)role, pulse_device) < 0) + if (pa_hashmap_put(profile_item->playback_devices, (void *)role, pulse_device) < 0) return NULL; } else { if (!(profile_item->capture_devices)) profile_item->capture_devices = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); - if(pa_hashmap_put(profile_item->capture_devices, (void *)role, pulse_device) < 0) + if (pa_hashmap_put(profile_item->capture_devices, (void *)role, pulse_device) < 0) return NULL; } @@ -1650,7 +1650,7 @@ static dm_device_profile* _device_profile_add_sink(dm_device_profile *profile_it if (!(profile_item->playback_devices)) profile_item->playback_devices = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); - if(pa_hashmap_put(profile_item->playback_devices, (void *)role, sink) < 0) + if (pa_hashmap_put(profile_item->playback_devices, (void *)role, sink) < 0) return NULL; return profile_item; @@ -1673,7 +1673,7 @@ static dm_device_profile* _device_profile_add_source(dm_device_profile *profile_ if (!(profile_item->capture_devices)) profile_item->capture_devices = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); - if(pa_hashmap_put(profile_item->capture_devices, (void *)role, source) < 0) + if (pa_hashmap_put(profile_item->capture_devices, (void *)role, source) < 0) return NULL; return profile_item; @@ -1885,7 +1885,7 @@ static pa_source* _device_manager_set_default_source(pa_device_manager *dm, con return NULL; } - if (!(source= pa_hashmap_get(profile_item->capture_devices, role))) { + if (!(source = pa_hashmap_get(profile_item->capture_devices, role))) { pa_log_warn("cannot get source for %s", role); return NULL; } @@ -1904,7 +1904,7 @@ static dm_device_profile* handle_not_predefined_device_profile(void *pulse_devic else direc = DM_DEVICE_DIRECTION_IN; - if(!(profile_item = create_device_profile(device_profile, direc, NULL, NULL))) { + if (!(profile_item = create_device_profile(device_profile, direc, NULL, NULL))) { pa_log_error("create_device_profile failed"); goto failed; } @@ -1921,7 +1921,7 @@ static dm_device_profile* handle_not_predefined_device_profile(void *pulse_devic } return profile_item; -failed : +failed: if (profile_item) pa_xfree(profile_item); return NULL; @@ -1988,14 +1988,14 @@ static dm_device* handle_not_predefined_device(pa_device_manager *dm, void *puls } } - if(!(profile_item = handle_not_predefined_device_profile(pulse_device, pdt, device_profile))) { + if (!(profile_item = handle_not_predefined_device_profile(pulse_device, pdt, device_profile))) { pa_log_error("failed to handle unknown device profile"); goto failed; } _device_profile_update_direction(profile_item); if (device_class == DM_DEVICE_CLASS_BT) { - if((device_item = _device_manager_get_device(dm->device_list, DEVICE_TYPE_BT))) { + if ((device_item = _device_manager_get_device(dm->device_list, DEVICE_TYPE_BT))) { pa_log_debug("found bt device"); _device_item_add_profile(device_item, profile_item, NULL, dm); goto end; @@ -2221,7 +2221,7 @@ static dm_device* handle_device_type_available(struct device_type_info *type_inf return device_item; -failed : +failed: if (playback) pa_hashmap_free(playback); if (capture) @@ -2276,8 +2276,8 @@ static void handle_predefined_device_loaded(void *pulse_device, pa_device_type_t Check device_item is already exists. If already exists, add loaded sink or source to that. */ - if((device_item = _device_manager_get_device(dm->device_list, type_info->type))) { - if((profile_item = _device_item_get_profile(device_item, type_info->profile))) { + if ((device_item = _device_manager_get_device(dm->device_list, type_info->type))) { + if ((profile_item = _device_item_get_profile(device_item, type_info->profile))) { pa_log_debug("device_item for %s.%s already exists", type_info->type, type_info->profile); if (!_device_profile_add_pulse_device(profile_item, role, pulse_device, pdt)) pa_log_error("add pulse device to profile_item failed"); @@ -2315,7 +2315,7 @@ static pa_bool_t _device_type_direction_available(struct device_type_info *type_ } static void handle_sink_unloaded(pa_sink *sink, pa_device_manager *dm) { - dm_device_profile *profile_item= NULL; + dm_device_profile *profile_item = NULL; struct device_type_info *type_info; dm_device *device_item; uint32_t device_idx = 0, profile_idx; @@ -2378,7 +2378,7 @@ static void handle_sink_unloaded(pa_sink *sink, pa_device_manager *dm) { } static void handle_source_unloaded(pa_source *source, pa_device_manager *dm) { - dm_device_profile *profile_item= NULL; + dm_device_profile *profile_item = NULL; struct device_type_info *type_info; dm_device *device_item; uint32_t device_idx = 0, profile_idx; @@ -2386,7 +2386,7 @@ static void handle_source_unloaded(pa_source *source, pa_device_manager *dm) { void *state = NULL; const char *role; - if (!source|| !dm) { + if (!source || !dm) { pa_log_error("Invalid Paramter"); return; } @@ -2420,7 +2420,7 @@ static void handle_source_unloaded(pa_source *source, pa_device_manager *dm) { if (!pa_hashmap_size(profile_item->capture_devices)) { pa_hashmap_free(profile_item->capture_devices); - profile_item->capture_devices= NULL; + profile_item->capture_devices = NULL; if (profile_item->direction == DM_DEVICE_DIRECTION_BOTH) { type_info = _device_manager_get_type_info(dm->type_infos, profile_item->device_item->type, profile_item->profile); @@ -2478,7 +2478,7 @@ static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, pa_dev pa_log_debug("argument null"); return PA_HOOK_OK; } - if(!(role = device_file_info_get_role_with_params(file_info, device_string_removed_params))) { + if (!(role = device_file_info_get_role_with_params(file_info, device_string_removed_params))) { pa_log_error("No role for %s", file_info->device_string); return PA_HOOK_OK; } @@ -2601,7 +2601,7 @@ static pa_hook_result_t source_put_hook_callback(pa_core *c, pa_source *source, pa_log_debug("argument null"); return PA_HOOK_OK; } - if(!(role = device_file_info_get_role_with_params(file_info, device_string_removed_params))) { + if (!(role = device_file_info_get_role_with_params(file_info, device_string_removed_params))) { pa_log_error("No role for %s", file_info->device_string); return PA_HOOK_OK; } @@ -2851,7 +2851,7 @@ static struct device_file_info* parse_device_file_object(json_object *device_fil return file_info; -failed : +failed: return NULL; } @@ -2919,8 +2919,7 @@ static struct device_file_map *parse_device_file_map() { pa_log_debug("[DEBUG_PARSE] ----------------- Capture Device Files ------------------"); file_map->capture = parse_device_file_array_object(capture_devices_o); } - } - else { + } else { pa_log_error("Get device files object failed"); return NULL; } @@ -2966,7 +2965,7 @@ static pa_hashmap* parse_device_role_map(json_object *device_role_map_o) { return roles; -failed : +failed: if (roles) pa_xfree(roles); @@ -3016,7 +3015,7 @@ static pa_idxset* parse_device_type_infos() { if ((device_prop_o = json_object_object_get(device_o, "profile")) && json_object_is_type(device_prop_o, json_type_string)) { device_profile = json_object_get_string(device_prop_o); pa_log_debug("[DEBUG_PARSE] Profile: %s", device_profile); - type_info->profile= device_profile; + type_info->profile = device_profile; } else { pa_log_debug("no device-profile"); } @@ -3076,18 +3075,16 @@ static pa_idxset* parse_device_type_infos() { } pa_idxset_put(type_infos, type_info, NULL); - } - else { + } else { pa_log_debug("Get device type object failed"); } } - } - else { + } else { pa_log_debug("Get device type array object failed"); } return type_infos; -failed : +failed: if (type_infos) pa_xfree(type_infos); @@ -3122,8 +3119,8 @@ static int handle_device_connected(pa_device_manager *dm, const char *device_typ return -1; } - if((device_item = _device_manager_get_device(dm->device_list, type_info->type))) { - if((profile_item = _device_item_get_profile(device_item, type_info->profile))) { + if ((device_item = _device_manager_get_device(dm->device_list, type_info->type))) { + if ((profile_item = _device_item_get_profile(device_item, type_info->profile))) { pa_log_debug("device_item for %s.%s already exists", type_info->type, type_info->profile); return 0; } @@ -3157,7 +3154,7 @@ static int handle_device_disconnected(pa_device_manager *dm, const char *device_ PA_IDXSET_FOREACH(device_item, dm->device_list, device_idx) { if (pa_streq(device_item->type, device_type)) { - if((profile_item = _device_item_get_profile(device_item, device_profile))) { + if ((profile_item = _device_item_get_profile(device_item, device_profile))) { if (_device_item_get_size(device_item) == 1) { _device_list_remove_device(dm->device_list, device_item, dm); notify_device_connection_changed(device_item, FALSE, dm); @@ -3564,7 +3561,7 @@ static pa_bool_t device_item_match_for_mask(dm_device *device_item, int device_f } if (need_to_check_for_state) { match = FALSE; - if ((COMPOUND_STATE(profile_item)== DM_DEVICE_STATE_DEACTIVATED) && (device_flags & DEVICE_STATE_DEACTIVATED_FLAG)) + if ((COMPOUND_STATE(profile_item) == DM_DEVICE_STATE_DEACTIVATED) && (device_flags & DEVICE_STATE_DEACTIVATED_FLAG)) match = TRUE; else if ((COMPOUND_STATE(profile_item) == DM_DEVICE_STATE_ACTIVATED) && (device_flags & DEVICE_STATE_ACTIVATED_FLAG)) match = TRUE; @@ -3660,7 +3657,7 @@ static int method_call_bt_sco_get_property(DBusConnection *conn, pa_bool_t *is_w continue; dbus_message_iter_get_basic(&dict_entry_val, &codec); pa_log_debug("Codec = [%d]", codec); - *is_wide_band= codec == BT_MSBC_CODEC_ID ? TRUE : FALSE; + *is_wide_band = (codec == BT_MSBC_CODEC_ID) ? TRUE : FALSE; } else if (pa_streq("nrec", property) && nrec) { dbus_message_iter_next(&dict_entry); dbus_message_iter_recurse(&dict_entry, &dict_entry_val); @@ -3753,7 +3750,7 @@ static void handle_get_connected_device_list(DBusConnection *conn, DBusMessage * pa_assert_se(dbus_message_iter_open_container(&msg_iter, DBUS_TYPE_ARRAY, "(isiis)", &array_iter)); PA_IDXSET_FOREACH(device_item, dm->device_list, device_idx) { - if(!(profile_item = pa_idxset_get_by_index(device_item->profiles, device_item->active_profile))) { + if (!(profile_item = pa_idxset_get_by_index(device_item->profiles, device_item->active_profile))) { pa_log_error("no active profile"); continue; } @@ -3842,7 +3839,7 @@ static void handle_test_device_status_change(DBusConnection *conn, DBusMessage * pa_assert_se((reply = dbus_message_new_method_return(msg))); dbus_error_init(&error); - if(!dbus_message_get_args(msg, NULL, + if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &device_type, DBUS_TYPE_STRING, &device_profile, DBUS_TYPE_INT32, &status, @@ -3888,7 +3885,7 @@ static DBusHandlerResult handle_device_manager_methods(DBusConnection *conn, DBu pa_assert(userdata); for (method_idx = 0; method_idx < METHOD_HANDLER_MAX; method_idx++) { - if (dbus_message_is_method_call(msg, DBUS_INTERFACE_DEVICE_MANAGER, method_handlers[method_idx].method_name )) { + if (dbus_message_is_method_call(msg, DBUS_INTERFACE_DEVICE_MANAGER, method_handlers[method_idx].method_name)) { method_handlers[method_idx].receive_cb(conn, msg, userdata); return DBUS_HANDLER_RESULT_HANDLED; } diff --git a/src/module-policy.c b/src/module-policy.c index 7008639..1de03eb 100644 --- a/src/module-policy.c +++ b/src/module-policy.c @@ -211,9 +211,9 @@ enum signal_index { /* Macros */ #define CONVERT_TO_DEVICE_DIRECTION(stream_type)\ - ((stream_type==STREAM_SINK_INPUT)?DM_DEVICE_DIRECTION_OUT:DM_DEVICE_DIRECTION_IN) + ((stream_type == STREAM_SINK_INPUT) ? DM_DEVICE_DIRECTION_OUT : DM_DEVICE_DIRECTION_IN) #define IS_AVAILABLE_DIRECTION(stream_type, device_direction) \ - ((stream_type==STREAM_SINK_INPUT)?(device_direction & DM_DEVICE_DIRECTION_OUT):(device_direction & DM_DEVICE_DIRECTION_IN)) + ((stream_type == STREAM_SINK_INPUT) ? (device_direction & DM_DEVICE_DIRECTION_OUT) : (device_direction & DM_DEVICE_DIRECTION_IN)) /* PCM Dump */ #define PA_DUMP_INI_DEFAULT_PATH "/usr/etc/mmfw_audio_pcm_dump.ini" @@ -441,7 +441,7 @@ static pa_hook_result_t select_proper_sink_or_source_hook_cb(pa_core *c, pa_stre pa_log_warn(" -- could not get combine_sink_arg1"); } else if (!combine_sink_arg2) { sink = combine_sink_arg2 = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL); - if(sink && !pa_streq(sink->name, combine_sink_arg1->name)) { + if (sink && !pa_streq(sink->name, combine_sink_arg1->name)) { pa_log_debug(" -- combine_sink_arg2[%s]", sink->name); /* load combine sink */ if (!u->module_combine_sink_for_ex) { @@ -451,7 +451,7 @@ static pa_hook_result_t select_proper_sink_or_source_hook_cb(pa_core *c, pa_stre pa_xfree(args); } sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED_EX, PA_NAMEREG_SINK); - PA_IDXSET_FOREACH (s, combine_sink_arg1->inputs, s_idx) { + PA_IDXSET_FOREACH(s, combine_sink_arg1->inputs, s_idx) { if (s == data->stream) { pa_sink_input_move_to(s, sink, FALSE); pa_log_debug(" -- *** sink-input(%p,%u) moves to sink(%p,%s)", s, ((pa_sink_input*)s)->index, sink, sink->name); @@ -459,7 +459,7 @@ static pa_hook_result_t select_proper_sink_or_source_hook_cb(pa_core *c, pa_stre } } } else if (!sink) { - pa_log_warn (" -- could not get combine_sink_arg2"); + pa_log_warn(" -- could not get combine_sink_arg2"); } } if (data->origins_from_new_data) @@ -478,7 +478,7 @@ static pa_hook_result_t select_proper_sink_or_source_hook_cb(pa_core *c, pa_stre pa_source_output_move_to(data->stream, source, FALSE); } } else - pa_log_warn (" -- could not get source"); + pa_log_warn(" -- could not get source"); } } } @@ -486,7 +486,7 @@ static pa_hook_result_t select_proper_sink_or_source_hook_cb(pa_core *c, pa_stre } } - if ((data->stream_type==STREAM_SINK_INPUT)?!(*(data->proper_sink)):!(*(data->proper_source))) { + if ((data->stream_type == STREAM_SINK_INPUT) ? !(*(data->proper_sink)) : !(*(data->proper_source))) { pa_log_warn("[SELECT] could not find a proper sink/source, set it to null sink/source"); if (data->stream_type == STREAM_SINK_INPUT) *(data->proper_sink) = null_sink; @@ -629,17 +629,17 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ } route_info.num_of_devices = 1; route_info.device_infos = pa_xmalloc0(sizeof(hal_device_info)*route_info.num_of_devices); - route_info.device_infos[0].direction = (data->stream_type==STREAM_SINK_INPUT)?DIRECTION_OUT:DIRECTION_IN; + route_info.device_infos[0].direction = (data->stream_type == STREAM_SINK_INPUT) ? DIRECTION_OUT : DIRECTION_IN; /* unload combine sink */ - if (data->stream_type==STREAM_SINK_INPUT && u->module_combine_sink) { + if (data->stream_type == STREAM_SINK_INPUT && u->module_combine_sink) { pa_log_info("[ROUTE][RESET] unload module[%s]", SINK_NAME_COMBINED); combine_sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK); null_sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_NULL, PA_NAMEREG_SINK); if (!combine_sink || !null_sink) pa_log_error("[ROUTE][RESET] could not get combine_sink(%p) or null_sink(%p)", combine_sink, null_sink); else { - PA_IDXSET_FOREACH (s, combine_sink->inputs, s_idx) { + PA_IDXSET_FOREACH(s, combine_sink->inputs, s_idx) { pa_sink_input_move_to(s, null_sink, FALSE); pa_log_debug("[ROUTE][RESET] *** sink-input(%p,%u) moves to sink(%p,%s)", s, ((pa_sink_input*)s)->index, null_sink, null_sink->name); } @@ -669,7 +669,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ pa_log_debug(" ** found a matched device: type[%-16s], direction[0x%x]", dm_device_type, dm_device_direction); use_internal_codec = pa_device_manager_is_device_use_internal_codec(device, CONVERT_TO_DEVICE_DIRECTION(data->stream_type), DEVICE_ROLE_NORMAL); if (use_internal_codec) { - hal_direction = (data->stream_type==STREAM_SINK_INPUT)?DIRECTION_OUT:DIRECTION_IN; + hal_direction = (data->stream_type == STREAM_SINK_INPUT) ? DIRECTION_OUT : DIRECTION_IN; route_info.num_of_devices++; route_info.device_infos = pa_xrealloc(route_info.device_infos, sizeof(hal_device_info)*route_info.num_of_devices); route_info.device_infos[route_info.num_of_devices-1].type = dm_device_type; @@ -690,7 +690,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ if (data->route_type == STREAM_ROUTE_TYPE_AUTO) { /* check if this device uses internal codec */ use_internal_codec = pa_device_manager_is_device_use_internal_codec(device, CONVERT_TO_DEVICE_DIRECTION(data->stream_type), DEVICE_ROLE_NORMAL); - if(use_internal_codec) { + if (use_internal_codec) { /* set other device's state to deactivated */ PA_IDXSET_FOREACH(_device, conn_devices, conn_idx) { if (device == _device) @@ -708,9 +708,9 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ sink = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL); /* unload combine sink */ - if (data->stream_type==STREAM_SINK_INPUT && u->module_combine_sink) { + if (data->stream_type == STREAM_SINK_INPUT && u->module_combine_sink) { if ((combine_sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK))) { - PA_IDXSET_FOREACH (s, combine_sink->inputs, s_idx) { + PA_IDXSET_FOREACH(s, combine_sink->inputs, s_idx) { pa_sink_input_move_to(s, sink, FALSE); pa_log_debug("[ROUTE][AUTO] *** sink-input(%p,%u) moves to sink(%p,%s)", s, ((pa_sink_input*)s)->index, sink, sink->name); } @@ -745,7 +745,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ pa_xfree(args); } if ((sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK))) { - PA_IDXSET_FOREACH (s, combine_sink_arg1->inputs, s_idx) { + PA_IDXSET_FOREACH(s, combine_sink_arg1->inputs, s_idx) { if (s == data->stream) { pa_sink_input_move_to(s, sink, FALSE); pa_log_debug("[ROUTE][AUTO_ALL] *** sink-nput(%p,%u) moves to sink(%p,%s)", @@ -766,7 +766,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ } else { /* move sink-inputs/source-outputs if needed */ if (data->idx_streams) { - PA_IDXSET_FOREACH (s, data->idx_streams, s_idx) { /* data->idx_streams: null_sink */ + PA_IDXSET_FOREACH(s, data->idx_streams, s_idx) { /* data->idx_streams: null_sink */ if (!pa_stream_manager_get_route_type(s, FALSE, data->stream_type, &route_type) && (route_type == STREAM_ROUTE_TYPE_AUTO_ALL)) { if ((data->stream_type == STREAM_SINK_INPUT) && (sink && (sink != ((pa_sink_input*)s)->sink))) { @@ -810,7 +810,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ dm_device_id = pa_device_manager_get_device_id(latest_device); use_internal_codec = pa_device_manager_is_device_use_internal_codec(latest_device, CONVERT_TO_DEVICE_DIRECTION(data->stream_type), DEVICE_ROLE_NORMAL); if (use_internal_codec) { - hal_direction = (data->stream_type==STREAM_SINK_INPUT)?DIRECTION_OUT:DIRECTION_IN; + hal_direction = (data->stream_type == STREAM_SINK_INPUT) ? DIRECTION_OUT : DIRECTION_IN; route_info.num_of_devices++; route_info.device_infos = pa_xrealloc(route_info.device_infos, sizeof(hal_device_info)*route_info.num_of_devices); route_info.device_infos[route_info.num_of_devices-1].type = dm_device_type; @@ -838,7 +838,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ /* unload combine sink */ if (data->stream_type == STREAM_SINK_INPUT && u->module_combine_sink) { if ((combine_sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK))) { - PA_IDXSET_FOREACH (s, combine_sink->inputs, s_idx) { + PA_IDXSET_FOREACH(s, combine_sink->inputs, s_idx) { pa_sink_input_move_to(s, sink, FALSE); pa_log_debug("[ROUTE][AUTO_LAST_CONN] *** sink-input(%p,%u) moves to sink(%p,%s)", s, ((pa_sink_input*)s)->index, sink, sink->name); } @@ -897,7 +897,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ route_info.num_of_devices++; route_info.device_infos = pa_xrealloc(route_info.device_infos, sizeof(hal_device_info)*route_info.num_of_devices); route_info.device_infos[route_info.num_of_devices-1].type = dm_device_type; - route_info.device_infos[route_info.num_of_devices-1].direction = (data->stream_type==STREAM_SINK_INPUT)?DIRECTION_OUT:DIRECTION_IN; + route_info.device_infos[route_info.num_of_devices-1].direction = (data->stream_type == STREAM_SINK_INPUT) ? DIRECTION_OUT : DIRECTION_IN; pa_log_info(" ** found a matched device and set state to ACTIVATED: type[%-16s], direction[0x%x]", route_info.device_infos[route_info.num_of_devices-1].type, dm_device_direction); /* set device state to activated */ @@ -917,7 +917,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ else if (data->stream_type == STREAM_SOURCE_OUTPUT) source = pa_device_manager_get_source(device, DEVICE_ROLE_NORMAL); if (data->idx_streams) { - PA_IDXSET_FOREACH (s, data->idx_streams, idx) { + PA_IDXSET_FOREACH(s, data->idx_streams, idx) { if (sink && (sink != ((pa_sink_input*)s)->sink)) { pa_sink_input_move_to(s, sink, FALSE); pa_log_debug("[ROUTE][MANUAL] *** sink-input(%p,%u) moves to sink(%p,%s)", s, ((pa_sink_input*)s)->index, sink, sink->name); @@ -932,7 +932,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ if (route_info.device_infos) { /* send information to HAL to set routing */ - if(pa_hal_manager_do_route (u->hal_manager, &route_info)) + if (pa_hal_manager_do_route(u->hal_manager, &route_info)) pa_log_error("[ROUTE] Failed to pa_hal_manager_do_route()"); pa_xfree(route_info.device_infos); } @@ -954,7 +954,7 @@ static pa_hook_result_t route_option_update_hook_cb(pa_core *c, pa_stream_manage route_option.value = data->value; /* send information to HAL to update routing option */ - if(pa_hal_manager_update_route_option (u->hal_manager, &route_option)) + if (pa_hal_manager_update_route_option(u->hal_manager, &route_option)) pa_log_error("[ROUTE_OPT] Failed to pa_hal_manager_update_route_option()"); return PA_HOOK_OK; @@ -1007,7 +1007,7 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_device_ if (combine_sink->inputs) { if (!sink) sink = null_sink; - PA_IDXSET_FOREACH (s, combine_sink->inputs, idx) { + PA_IDXSET_FOREACH(s, combine_sink->inputs, idx) { /* re-route this stream to the remaining device using internal codec */ pa_sink_input_move_to(s, sink, FALSE); pa_log_debug("[CONN] *** sink-input(%p,%u) moves to sink(%p,%s)", s, ((pa_sink_input*)s)->index, sink, sink->name); @@ -1023,7 +1023,7 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_device_ /* unload combine sink for external devices */ if ((combine_sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED_EX, PA_NAMEREG_SINK))) { if (combine_sink->inputs) { - PA_IDXSET_FOREACH (s, combine_sink->inputs, idx) { + PA_IDXSET_FOREACH(s, combine_sink->inputs, idx) { pa_sink_input_move_to(s, null_sink, FALSE); pa_log_debug("[CONN] *** sink-input(%p,%u) moves to sink(%p,%s)", s, ((pa_sink_input*)s)->index, null_sink, null_sink->name); } @@ -1208,7 +1208,7 @@ static DBusHandlerResult dbus_filter_audio_handler(DBusConnection *c, DBusMessag pa_assert(userdata); - if(dbus_message_get_type(s)!=DBUS_MESSAGE_TYPE_SIGNAL) + if (dbus_message_get_type(s) != DBUS_MESSAGE_TYPE_SIGNAL) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; pa_log_info("Audio handler received msg"); @@ -1228,7 +1228,7 @@ static DBusHandlerResult dbus_filter_audio_handler(DBusConnection *c, DBusMessag DBUS_TYPE_STRING, &arg_s, DBUS_TYPE_INVALID)) { goto fail; - } else{ + } else { _do_something2(arg_s, userdata); } } else if (dbus_message_is_signal(s, AUDIO_CLIENT_INTERFACE_NAME, "TestSignalFromClient1")) { @@ -1236,7 +1236,7 @@ static DBusHandlerResult dbus_filter_audio_handler(DBusConnection *c, DBusMessag DBUS_TYPE_STRING, &arg_s, DBUS_TYPE_INVALID)) { goto fail; - } else{ + } else { _do_something2(arg_s, userdata); } } else { @@ -1278,10 +1278,10 @@ static DBusHandlerResult handle_get_property(DBusConnection *conn, DBusMessage * } } } - else{ + else { pa_log_warn("Not our interface, not handle it"); } - } else{ + } else { pa_log_warn("Wrong Signature"); pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_SIGNATURE, "Wrong Signature, Expected (ss)"); } @@ -1305,10 +1305,10 @@ static DBusHandlerResult handle_get_all_property(DBusConnection *conn, DBusMessa handle_get_all(conn, msg, userdata); return DBUS_HANDLER_RESULT_HANDLED; } - else{ + else { pa_log_warn("Not our interface, not handle it"); } - } else{ + } else { pa_log_warn("Wrong Signature"); pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_SIGNATURE, "Wrong Signature, Expected (ss)"); } @@ -1341,11 +1341,11 @@ static DBusHandlerResult handle_set_property(DBusConnection *conn, DBusMessage * if (pa_streq(interface_name, INTERFACE_POLICY)) { for (prop_idx = 0; prop_idx < PROPERTY_MAX; prop_idx++) { if (pa_streq(property_name, property_handlers[prop_idx].property_name)) { - if (pa_streq(property_handlers[prop_idx].type,property_sig)) { + if (pa_streq(property_handlers[prop_idx].type, property_sig)) { property_handlers[prop_idx].set_cb(conn, msg, &variant_iter, userdata); return DBUS_HANDLER_RESULT_HANDLED; } - else{ + else { pa_log_warn("Wrong Property Signature"); pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_SIGNATURE, "Wrong Signature, Expected (ssv)"); } @@ -1353,10 +1353,10 @@ static DBusHandlerResult handle_set_property(DBusConnection *conn, DBusMessage * } } } - else{ + else { pa_log_warn("Not our interface, not handle it"); } - } else{ + } else { pa_log_warn("Wrong Signature"); pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_SIGNATURE, "Wrong Signature, Expected (ssv)"); } @@ -1373,12 +1373,12 @@ static DBusHandlerResult handle_policy_methods(DBusConnection *conn, DBusMessage pa_assert(userdata); for (method_idx = 0; method_idx < METHOD_HANDLER_MAX; method_idx++) { - if (dbus_message_is_method_call(msg, INTERFACE_POLICY, method_handlers[method_idx].method_name )) { + if (dbus_message_is_method_call(msg, INTERFACE_POLICY, method_handlers[method_idx].method_name)) { if (pa_streq(dbus_message_get_signature(msg), method_arg_signatures[method_idx])) { method_handlers[method_idx].receive_cb(conn, msg, userdata); return DBUS_HANDLER_RESULT_HANDLED; } - else{ + else { pa_log_warn("Wrong Argument Signature"); pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_SIGNATURE, "Wrong Signature, Expected %s", method_arg_signatures[method_idx]); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; @@ -1429,13 +1429,13 @@ static DBusHandlerResult method_call_handler(DBusConnection *c, DBusMessage *m, if (dbus_message_is_method_call(m, "org.freedesktop.DBus.Introspectable", "Introspect")) { return handle_introspect(c, m, u); - } else if (dbus_message_is_method_call(m, "org.freedesktop.DBus.Properties", "Get")){ + } else if (dbus_message_is_method_call(m, "org.freedesktop.DBus.Properties", "Get")) { return handle_get_property(c, m, u); - } else if (dbus_message_is_method_call(m, "org.freedesktop.DBus.Properties", "Set")){ + } else if (dbus_message_is_method_call(m, "org.freedesktop.DBus.Properties", "Set")) { return handle_set_property(c, m, u); - } else if (dbus_message_is_method_call(m, "org.freedesktop.DBus.Properties", "GetAll")){ + } else if (dbus_message_is_method_call(m, "org.freedesktop.DBus.Properties", "GetAll")) { return handle_get_all_property(c, m, u); - } else{ + } else { return handle_policy_methods(c, m, u); } @@ -1451,9 +1451,9 @@ static void endpoint_init(struct userdata *u) pa_log_debug("Dbus endpoint init"); if (u && u->dbus_conn) { - if(!dbus_connection_register_object_path(pa_dbus_connection_get(u->dbus_conn), OBJECT_PATH, &vtable_endpoint, u)) + if (!dbus_connection_register_object_path(pa_dbus_connection_get(u->dbus_conn), OBJECT_PATH, &vtable_endpoint, u)) pa_log_error("Failed to register object path"); - } else{ + } else { pa_log_error("Cannot get dbus connection to register object path"); } } @@ -1462,9 +1462,9 @@ static void endpoint_done(struct userdata* u) { pa_log_debug("Dbus endpoint done"); if (u && u->dbus_conn) { - if(!dbus_connection_unregister_object_path(pa_dbus_connection_get(u->dbus_conn), OBJECT_PATH)) + if (!dbus_connection_unregister_object_path(pa_dbus_connection_get(u->dbus_conn), OBJECT_PATH)) pa_log_error("Failed to unregister object path"); - } else{ + } else { pa_log_error("Cannot get dbus connection to unregister object path"); } } @@ -1522,13 +1522,13 @@ static void dbus_init(struct userdata* u) } pa_log_error("Unable to contact D-Bus system bus: %s: %s", error.name, error.message); goto fail; - } else{ + } else { pa_log_debug("Got dbus connection"); } u->dbus_conn = connection; - if( watch_signals(u) < 0 ) + if (watch_signals(u) < 0) pa_log_error("dbus watch signals failed"); else pa_log_debug("dbus ready to get signals"); @@ -1548,7 +1548,7 @@ static void dbus_deinit(struct userdata* u) endpoint_done(u); unwatch_signals(u); - if (u->dbus_conn){ + if (u->dbus_conn) { pa_dbus_connection_unref(u->dbus_conn); u->dbus_conn = NULL; } diff --git a/src/module-sound-player.c b/src/module-sound-player.c index 9341c83..761ca21 100644 --- a/src/module-sound-player.c +++ b/src/module-sound-player.c @@ -79,10 +79,10 @@ enum method_handler_index { static pa_dbus_arg_info simple_play_args[] = { { "uri", "s", "in" }, { "role", "s", "in" }, - { "volume_gain", "s", "in" }}; + { "volume_gain", "s", "in" } }; static pa_dbus_arg_info sample_play_args[] = { { "sample_name", "s", "in" }, { "role", "s", "in" }, - { "volume_gain", "s", "in" }}; + { "volume_gain", "s", "in" } }; static const char* signature_args_for_in[] = { "sss", "sss" }; @@ -357,7 +357,7 @@ static DBusHandlerResult handle_methods(DBusConnection *conn, DBusMessage *msg, pa_assert(userdata); for (idx = 0; idx < METHOD_HANDLER_MAX; idx++) { - if (dbus_message_is_method_call(msg, SOUND_PLAYER_INTERFACE, method_handlers[idx].method_name )) { + if (dbus_message_is_method_call(msg, SOUND_PLAYER_INTERFACE, method_handlers[idx].method_name)) { if (pa_streq(dbus_message_get_signature(msg), signature_args_for_in[idx])) { method_handlers[idx].receive_cb(conn, msg, userdata); return DBUS_HANDLER_RESULT_HANDLED; @@ -412,7 +412,7 @@ static void send_signal_for_eos(struct userdata *u, int32_t stream_idx) { } #endif -static int init_ipc (struct userdata *u) { +static int init_ipc(struct userdata *u) { int pre_mask; #ifdef HAVE_DBUS #ifndef USE_DBUS_PROTOCOL @@ -428,7 +428,7 @@ static int init_ipc (struct userdata *u) { pa_log_info("Initialization for IPC"); pre_mask = umask(0); - if (mknod(KEYTONE_PATH,S_IFIFO|0660,0)<0) + if (mknod(KEYTONE_PATH, S_IFIFO|0660, 0) < 0) pa_log_warn("mknod failed. errno=[%d][%s]", errno, strerror(errno)); umask(pre_mask); @@ -443,11 +443,11 @@ static int init_ipc (struct userdata *u) { fcntl(u->fd, F_SETFL, O_NONBLOCK); /* change access mode so group can use keytone pipe */ - if (fchmod (u->fd, 0666) == -1) + if (fchmod(u->fd, 0666) == -1) pa_log_warn("Changing keytone access mode is failed. errno=[%d][%s]", errno, strerror(errno)); /* change group due to security request */ - if (fchown (u->fd, -1, KEYTONE_GROUP) == -1) + if (fchown(u->fd, -1, KEYTONE_GROUP) == -1) pa_log_warn("Changing keytone group is failed. errno=[%d][%s]", errno, strerror(errno)); u->io = u->module->core->mainloop->io_new(u->module->core->mainloop, u->fd, PA_IO_EVENT_INPUT|PA_IO_EVENT_HANGUP, io_event_callback, u); @@ -482,7 +482,7 @@ fail: return -1; } -static void deinit_ipc (struct userdata *u) { +static void deinit_ipc(struct userdata *u) { pa_assert(u); @@ -502,7 +502,7 @@ static void deinit_ipc (struct userdata *u) { } #else if (u->dbus_conn) { - if(!dbus_connection_unregister_object_path(pa_dbus_connection_get(u->dbus_conn), SOUND_PLAYER_OBJECT_PATH)) + if (!dbus_connection_unregister_object_path(pa_dbus_connection_get(u->dbus_conn), SOUND_PLAYER_OBJECT_PATH)) pa_log_error("Failed to unregister object path"); u->dbus_conn = NULL; } diff --git a/src/module-tizenaudio-sink.c b/src/module-tizenaudio-sink.c index 07e7ed3..577fde0 100644 --- a/src/module-tizenaudio-sink.c +++ b/src/module-tizenaudio-sink.c @@ -113,7 +113,7 @@ static const char* const valid_modargs[] = { NULL }; -static int build_pollfd (struct userdata *u) { +static int build_pollfd(struct userdata *u) { int32_t ret; struct pollfd *pollfd; int fd = -1; @@ -519,7 +519,7 @@ int pa__init(pa_module*m) { pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq); pa_sink_set_rtpoll(u->sink, u->rtpoll); - unsuspend (u); + unsuspend(u); u->block_usec = BLOCK_USEC; u->timestamp = 0ULL; diff --git a/src/module-tizenaudio-source.c b/src/module-tizenaudio-source.c index 4350264..41d175a 100644 --- a/src/module-tizenaudio-source.c +++ b/src/module-tizenaudio-source.c @@ -114,7 +114,7 @@ static const char* const valid_modargs[] = { NULL }; -static int build_pollfd (struct userdata *u) { +static int build_pollfd(struct userdata *u) { int32_t ret; struct pollfd *pollfd; int fd = -1; @@ -471,7 +471,7 @@ int pa__init(pa_module*m) { pa_source_set_asyncmsgq(u->source, u->thread_mq.inq); pa_source_set_rtpoll(u->source, u->rtpoll); - unsuspend (u); + unsuspend(u); u->block_usec = BLOCK_USEC; u->latency_time = u->block_usec; diff --git a/src/stream-manager-priv.h b/src/stream-manager-priv.h index 6305294..b7cd18f 100644 --- a/src/stream-manager-priv.h +++ b/src/stream-manager-priv.h @@ -27,16 +27,16 @@ typedef enum _stream_direction { } stream_direction_t; #define GET_STREAM_NEW_SAMPLE_SPEC_PTR(stream, type) \ - (type == STREAM_SINK_INPUT? &(((pa_sink_input_new_data*)stream)->sample_spec) : &(((pa_source_output_new_data*)stream)->sample_spec)) + (type == STREAM_SINK_INPUT ? &(((pa_sink_input_new_data*)stream)->sample_spec) : &(((pa_source_output_new_data*)stream)->sample_spec)) #define GET_STREAM_NEW_SAMPLE_SPEC(stream, type) \ - (type == STREAM_SINK_INPUT? ((pa_sink_input_new_data*)stream)->sample_spec : ((pa_source_output_new_data*)stream)->sample_spec) + (type == STREAM_SINK_INPUT ? ((pa_sink_input_new_data*)stream)->sample_spec : ((pa_source_output_new_data*)stream)->sample_spec) #define GET_STREAM_SAMPLE_SPEC(stream, type) \ - (type == STREAM_SINK_INPUT? ((pa_sink_input*)stream)->sample_spec : ((pa_source_output*)stream)->sample_spec) + (type == STREAM_SINK_INPUT ? ((pa_sink_input*)stream)->sample_spec : ((pa_source_output*)stream)->sample_spec) #define IS_FOCUS_ACQUIRED(focus, type) \ - (type == STREAM_SINK_INPUT? (focus & STREAM_FOCUS_ACQUIRED_PLAYBACK) : (focus & STREAM_FOCUS_ACQUIRED_CAPTURE)) + (type == STREAM_SINK_INPUT ? (focus & STREAM_FOCUS_ACQUIRED_PLAYBACK) : (focus & STREAM_FOCUS_ACQUIRED_CAPTURE)) typedef struct _stream_info { int32_t priority; diff --git a/src/stream-manager-volume.c b/src/stream-manager-volume.c index 35df3e5..3caa366 100644 --- a/src/stream-manager-volume.c +++ b/src/stream-manager-volume.c @@ -53,7 +53,7 @@ enum gain_type { }; /* TODO : after preparing gain map, we can remove it */ -static const char *__get_gain_type_string_by_idx (uint32_t gain_type_idx) { +static const char *__get_gain_type_string_by_idx(uint32_t gain_type_idx) { switch (gain_type_idx) { case GAIN_TYPE_DEFAULT: return "default"; case GAIN_TYPE_DIALER: return "dialer"; @@ -70,7 +70,7 @@ static const char *__get_gain_type_string_by_idx (uint32_t gain_type_idx) { } } -static int load_out_volume_conf_file (pa_stream_manager *m) { +static int load_out_volume_conf_file(pa_stream_manager *m) { int ret = 0; dictionary *dict = NULL; uint32_t gain_type_idx = 0; @@ -110,7 +110,7 @@ static int load_out_volume_conf_file (pa_stream_manager *m) { /* convert dB volume to linear volume */ double *vol_value = pa_xmalloc0(sizeof(double)); *vol_value = 0.0f; - if(strncmp(token, "0", strlen(token))) + if (strncmp(token, "0", strlen(token))) *vol_value = pow(10.0, (atof(token) - 100) / 20.0); if (!v->values[STREAM_DIRECTION_OUT].idx_volume_values) v->values[STREAM_DIRECTION_OUT].idx_volume_values = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); @@ -291,7 +291,7 @@ int32_t set_volume_level_by_type(pa_stream_manager *m, stream_type_t stream_type if (get_volume_value(m, stream_type, is_hal_volume, volume_type, volume_level, &volume_linear)) return -1; - PA_IDXSET_FOREACH(s, stream_type == STREAM_SINK_INPUT?m->core->sink_inputs:m->core->source_outputs, idx) { + PA_IDXSET_FOREACH(s, stream_type == STREAM_SINK_INPUT ? m->core->sink_inputs : m->core->source_outputs, idx) { if ((volume_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) { /* Get modifier for gain */ modifier_gain = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_GAIN_TYPE); @@ -318,7 +318,7 @@ int32_t set_volume_level_by_type(pa_stream_manager *m, stream_type_t stream_type } } } else { - PA_IDXSET_FOREACH(s, stream_type == STREAM_SINK_INPUT?m->core->sink_inputs:m->core->source_outputs, idx) { + PA_IDXSET_FOREACH(s, stream_type == STREAM_SINK_INPUT ? m->core->sink_inputs : m->core->source_outputs, idx) { if ((volume_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) { /* Get modifier for gain */ modifier_gain = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_GAIN_TYPE); @@ -436,7 +436,7 @@ int32_t set_volume_level_by_idx(pa_stream_manager *m, stream_type_t stream_type, const char *modifier_gain = NULL; pa_assert(m); - s = pa_idxset_get_by_index(stream_type == STREAM_SINK_INPUT?m->core->sink_inputs:m->core->source_outputs, idx); + s = pa_idxset_get_by_index(stream_type == STREAM_SINK_INPUT ? m->core->sink_inputs : m->core->source_outputs, idx); if ((volume_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) { /* Get modifier for gain */ modifier_gain = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_GAIN_TYPE); @@ -713,7 +713,7 @@ int32_t set_volume_mute_with_new_data(pa_stream_manager *m, void *stream, stream return 0; } -static void dump_volumes (pa_stream_manager *m) { +static void dump_volumes(pa_stream_manager *m) { volume_info *s = NULL; const char *volume_type = NULL; const char *modifier_gain = NULL; @@ -748,7 +748,7 @@ static void dump_volumes (pa_stream_manager *m) { return; } -int32_t init_volumes (pa_stream_manager *m) { +int32_t init_volumes(pa_stream_manager *m) { int ret = 0; void *state = NULL; volume_info *v = NULL; @@ -790,7 +790,7 @@ int32_t init_volumes (pa_stream_manager *m) { return ret; } -void deinit_volumes (pa_stream_manager *m) { +void deinit_volumes(pa_stream_manager *m) { volume_info *v = NULL; void *state = NULL; uint32_t idx = 0; diff --git a/src/stream-manager.c b/src/stream-manager.c index dd20e7e..822dc5c 100644 --- a/src/stream-manager.c +++ b/src/stream-manager.c @@ -195,7 +195,7 @@ static pa_dbus_method_handler method_handlers[METHOD_HANDLER_MAX] = { }; const char *dbus_str_none = "none"; -const char* stream_manager_dbus_ret_str[] = {"STREAM_MANAGER_RETURN_OK","STREAM_MANAGER_RETURN_ERROR", "STREAM_MANAGER_RETURN_ERROR_NO_STREAM"}; +const char* stream_manager_dbus_ret_str[] = {"STREAM_MANAGER_RETURN_OK", "STREAM_MANAGER_RETURN_ERROR", "STREAM_MANAGER_RETURN_ERROR_NO_STREAM"}; enum { RET_MSG_INDEX_OK, RET_MSG_INDEX_ERROR, @@ -430,7 +430,7 @@ static int get_available_streams(pa_stream_manager *m, stream_list *list) { } } list->num_of_streams = i; - pa_log_debug(" num_of_streams[%d]",i); + pa_log_debug(" num_of_streams[%d]", i); } else { pa_log_error("stream_map is not initialized.."); return -1; @@ -522,7 +522,7 @@ static void handle_get_stream_list(DBusConnection *conn, DBusMessage *msg, void memset(&list, 0, sizeof(stream_list)); pa_assert_se((reply = dbus_message_new_method_return(msg))); dbus_message_iter_init_append(reply, &msg_iter); - if(!get_available_streams(m, &list)) { + if (!get_available_streams(m, &list)) { pa_dbus_append_basic_array_variant(&msg_iter, DBUS_TYPE_STRING, &list.types, list.num_of_streams); pa_dbus_append_basic_array_variant(&msg_iter, DBUS_TYPE_INT32, &list.priorities, list.num_of_streams); } else { @@ -552,7 +552,7 @@ static void handle_get_stream_info(DBusConnection *conn, DBusMessage *msg, void memset(&info, 0, sizeof(stream_info_per_type)); pa_assert_se((reply = dbus_message_new_method_return(msg))); dbus_message_iter_init_append(reply, &msg_iter); - if(!get_stream_info(m, type, &info)) { + if (!get_stream_info(m, type, &info)) { pa_dbus_append_basic_variant(&msg_iter, DBUS_TYPE_INT32, &info.priority); pa_dbus_append_basic_variant(&msg_iter, DBUS_TYPE_INT32, &info.route_type); pa_dbus_append_basic_array_variant(&msg_iter, DBUS_TYPE_STRING, &info.volume_types, STREAM_DIRECTION_MAX); @@ -1030,7 +1030,7 @@ static void handle_get_current_volume_type(DBusConnection *conn, DBusMessage *ms goto FAILURE; } - s = (stream_type == STREAM_SINK_INPUT)?(void*)(m->cur_highest_priority.sink_input):(void*)(m->cur_highest_priority.source_output); + s = (stream_type == STREAM_SINK_INPUT) ? (void*)(m->cur_highest_priority.sink_input) : (void*)(m->cur_highest_priority.source_output); if (s) { type = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE); pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &type, DBUS_TYPE_INVALID)); @@ -1077,7 +1077,7 @@ static void handle_update_focus_status(DBusConnection *conn, DBusMessage *msg, v count = pa_idxset_size(sp->idx_sink_inputs); PA_IDXSET_FOREACH(stream, sp->idx_sink_inputs, idx) { pa_proplist_sets(GET_STREAM_PROPLIST(stream, STREAM_SINK_INPUT), PA_PROP_MEDIA_FOCUS_STATUS, - IS_FOCUS_ACQUIRED(sp->focus_status, STREAM_SINK_INPUT)?STREAM_FOCUS_PLAYBACK:STREAM_FOCUS_NONE); + IS_FOCUS_ACQUIRED(sp->focus_status, STREAM_SINK_INPUT) ? STREAM_FOCUS_PLAYBACK : STREAM_FOCUS_NONE); if (--count == 0) process_stream(m, stream, STREAM_SINK_INPUT, PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_FOCUS_CHANGED, FALSE); } @@ -1086,7 +1086,7 @@ static void handle_update_focus_status(DBusConnection *conn, DBusMessage *msg, v count = pa_idxset_size(sp->idx_source_outputs); PA_IDXSET_FOREACH(stream, sp->idx_source_outputs, idx) { pa_proplist_sets(GET_STREAM_PROPLIST(stream, STREAM_SOURCE_OUTPUT), PA_PROP_MEDIA_FOCUS_STATUS, - IS_FOCUS_ACQUIRED(sp->focus_status, STREAM_SOURCE_OUTPUT)?STREAM_FOCUS_CAPTURE:STREAM_FOCUS_NONE); + IS_FOCUS_ACQUIRED(sp->focus_status, STREAM_SOURCE_OUTPUT) ? STREAM_FOCUS_CAPTURE : STREAM_FOCUS_NONE); if (--count == 0) process_stream(m, stream, STREAM_SOURCE_OUTPUT, PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_FOCUS_CHANGED, FALSE); } @@ -1115,7 +1115,7 @@ static DBusHandlerResult handle_methods(DBusConnection *conn, DBusMessage *msg, pa_assert(m); for (idx = 0; idx < METHOD_HANDLER_MAX; idx++) { - if (dbus_message_is_method_call(msg, STREAM_MANAGER_INTERFACE, method_handlers[idx].method_name )) { + if (dbus_message_is_method_call(msg, STREAM_MANAGER_INTERFACE, method_handlers[idx].method_name)) { pa_log_debug("Message signature [%s] (Expected [%s])", dbus_message_get_signature(msg), signature_args_for_in[idx]); if (pa_streq(dbus_message_get_signature(msg), signature_args_for_in[idx])) { method_handlers[idx].receive_cb(conn, msg, userdata); @@ -1182,7 +1182,7 @@ static int convert_route_type(stream_route_type_t *route_type, const char *route return ret; } -static void dump_stream_map (pa_stream_manager *m) { +static void dump_stream_map(pa_stream_manager *m) { stream_info *s = NULL; const char *role = NULL; char *name = NULL; @@ -1209,7 +1209,7 @@ static void dump_stream_map (pa_stream_manager *m) { return; } -static int init_stream_map (pa_stream_manager *m) { +static int init_stream_map(pa_stream_manager *m) { volume_info *v; stream_info *s; json_object *o; @@ -1244,62 +1244,62 @@ static int init_stream_map (pa_stream_manager *m) { pa_assert(m); o = json_object_from_file(STREAM_MAP_FILE); - if(is_error(o)) { + if (is_error(o)) { pa_log_error("Read stream-map file(%s) failed", STREAM_MAP_FILE); return -1; } /* Volumes */ m->volume_infos = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); - if((volume_array_o = json_object_object_get(o, STREAM_MAP_VOLUMES)) && json_object_is_type(volume_array_o, json_type_array)) { + if ((volume_array_o = json_object_object_get(o, STREAM_MAP_VOLUMES)) && json_object_is_type(volume_array_o, json_type_array)) { num_of_volume_types = json_object_array_length(volume_array_o); for (i = 0; i < num_of_volume_types; i++) { - if((volume_o = json_object_array_get_idx(volume_array_o, i)) && json_object_is_type(volume_o, json_type_object)) { + if ((volume_o = json_object_array_get_idx(volume_array_o, i)) && json_object_is_type(volume_o, json_type_object)) { v = pa_xmalloc0(sizeof(volume_info)); pa_log_debug("volume found [%d]", i); - if((volume_type_o = json_object_object_get(volume_o, STREAM_MAP_VOLUME_TYPE)) && json_object_is_type(volume_type_o, json_type_string)) { + if ((volume_type_o = json_object_object_get(volume_o, STREAM_MAP_VOLUME_TYPE)) && json_object_is_type(volume_type_o, json_type_string)) { volume_type = json_object_get_string(volume_type_o); pa_log_debug(" - type : %s", volume_type); } else { pa_log_error("Get volume type failed"); goto failed; } - if((is_hal_volume_o = json_object_object_get(volume_o, STREAM_MAP_VOLUME_IS_FOR_HAL)) && json_object_is_type(is_hal_volume_o, json_type_int)) { + if ((is_hal_volume_o = json_object_object_get(volume_o, STREAM_MAP_VOLUME_IS_FOR_HAL)) && json_object_is_type(is_hal_volume_o, json_type_int)) { v->is_hal_volume_type = (pa_bool_t)json_object_get_int(is_hal_volume_o); pa_log_debug(" - is-hal-volume : %d", v->is_hal_volume_type); } else { pa_log_error("Get is-hal-volume failed"); goto failed; } - pa_hashmap_put(m->volume_infos,(void*)volume_type, v); + pa_hashmap_put(m->volume_infos, (void*)volume_type, v); } } } /* Streams */ m->stream_infos = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); - if((stream_array_o = json_object_object_get(o, STREAM_MAP_STREAMS)) && json_object_is_type(stream_array_o, json_type_array)) { + if ((stream_array_o = json_object_object_get(o, STREAM_MAP_STREAMS)) && json_object_is_type(stream_array_o, json_type_array)) { num_of_stream_types = json_object_array_length(stream_array_o); for (i = 0; i < num_of_stream_types; i++) { - if((stream_o = json_object_array_get_idx(stream_array_o, i)) && json_object_is_type(stream_o, json_type_object)) { + if ((stream_o = json_object_array_get_idx(stream_array_o, i)) && json_object_is_type(stream_o, json_type_object)) { s = pa_xmalloc0(sizeof(stream_info)); pa_log_debug("stream found [%d]", i); - if((role_o = json_object_object_get(stream_o, STREAM_MAP_STREAM_ROLE)) && json_object_is_type(role_o, json_type_string)) { + if ((role_o = json_object_object_get(stream_o, STREAM_MAP_STREAM_ROLE)) && json_object_is_type(role_o, json_type_string)) { role = json_object_get_string(role_o); pa_log_debug(" - role : %s", role); } else { pa_log_error("Get stream role failed"); goto failed; } - if((priority_o = json_object_object_get(stream_o, STREAM_MAP_STREAM_PRIORITY)) && json_object_is_type(priority_o, json_type_int)) { + if ((priority_o = json_object_object_get(stream_o, STREAM_MAP_STREAM_PRIORITY)) && json_object_is_type(priority_o, json_type_int)) { s->priority = json_object_get_int(priority_o); pa_log_debug(" - priority : %d", s->priority); } else { pa_log_error("Get stream priority failed"); goto failed; } - if((route_type_o = json_object_object_get(stream_o, STREAM_MAP_STREAM_ROUTE_TYPE)) && json_object_is_type(route_type_o, json_type_string)) { + if ((route_type_o = json_object_object_get(stream_o, STREAM_MAP_STREAM_ROUTE_TYPE)) && json_object_is_type(route_type_o, json_type_string)) { if (convert_route_type(&(s->route_type), json_object_get_string(route_type_o))) { pa_log_error("convert stream route-type failed"); goto failed; @@ -1309,14 +1309,14 @@ static int init_stream_map (pa_stream_manager *m) { pa_log_error("Get stream route-type failed"); goto failed; } - if((volume_types_o = json_object_object_get(stream_o, STREAM_MAP_STREAM_VOLUME_TYPES)) && json_object_is_type(volume_types_o, json_type_object)) { - if((volume_type_in_o = json_object_object_get(volume_types_o, STREAM_MAP_STREAM_VOLUME_TYPE_IN)) && json_object_is_type(volume_type_in_o, json_type_string)) + if ((volume_types_o = json_object_object_get(stream_o, STREAM_MAP_STREAM_VOLUME_TYPES)) && json_object_is_type(volume_types_o, json_type_object)) { + if ((volume_type_in_o = json_object_object_get(volume_types_o, STREAM_MAP_STREAM_VOLUME_TYPE_IN)) && json_object_is_type(volume_type_in_o, json_type_string)) s->volume_types[STREAM_DIRECTION_IN] = json_object_get_string(volume_type_in_o); else { pa_log_error("Get stream volume-type-in failed"); goto failed; } - if((volume_type_out_o = json_object_object_get(volume_types_o, STREAM_MAP_STREAM_VOLUME_TYPE_OUT)) && json_object_is_type(volume_type_out_o, json_type_string)) + if ((volume_type_out_o = json_object_object_get(volume_types_o, STREAM_MAP_STREAM_VOLUME_TYPE_OUT)) && json_object_is_type(volume_type_out_o, json_type_string)) s->volume_types[STREAM_DIRECTION_OUT] = json_object_get_string(volume_type_out_o); else { pa_log_error("Get stream volume-type-out failed"); @@ -1327,13 +1327,13 @@ static int init_stream_map (pa_stream_manager *m) { pa_log_error("Get stream volume-types failed"); goto failed; } - if((avail_in_devices_o = json_object_object_get(stream_o, STREAM_MAP_STREAM_AVAIL_IN_DEVICES)) && json_object_is_type(avail_in_devices_o, json_type_array)) { + if ((avail_in_devices_o = json_object_object_get(stream_o, STREAM_MAP_STREAM_AVAIL_IN_DEVICES)) && json_object_is_type(avail_in_devices_o, json_type_array)) { j = 0; s->idx_avail_in_devices = pa_idxset_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); num_of_avail_in_devices = json_object_array_length(avail_in_devices_o); pa_log_debug(" - avail-in-devices"); for (j = 0; j < num_of_avail_in_devices; j++) { - if((in_device_o = json_object_array_get_idx(avail_in_devices_o, j)) && json_object_is_type(in_device_o, json_type_string)) { + if ((in_device_o = json_object_array_get_idx(avail_in_devices_o, j)) && json_object_is_type(in_device_o, json_type_string)) { pa_idxset_put(s->idx_avail_in_devices, (void*)json_object_get_string(in_device_o), NULL); pa_log_debug(" device[%d] : %s", j, json_object_get_string(in_device_o)); } @@ -1342,13 +1342,13 @@ static int init_stream_map (pa_stream_manager *m) { pa_log_error("Get stream avail-in-devices failed"); goto failed; } - if((avail_out_devices_o = json_object_object_get(stream_o, STREAM_MAP_STREAM_AVAIL_OUT_DEVICES)) && json_object_is_type(avail_out_devices_o, json_type_array)) { + if ((avail_out_devices_o = json_object_object_get(stream_o, STREAM_MAP_STREAM_AVAIL_OUT_DEVICES)) && json_object_is_type(avail_out_devices_o, json_type_array)) { j = 0; s->idx_avail_out_devices = pa_idxset_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); num_of_avail_out_devices = json_object_array_length(avail_out_devices_o); pa_log_debug(" - avail-out-devices"); for (j = 0; j < num_of_avail_out_devices; j++) { - if((out_device_o = json_object_array_get_idx(avail_out_devices_o, j)) && json_object_is_type(out_device_o, json_type_string)) { + if ((out_device_o = json_object_array_get_idx(avail_out_devices_o, j)) && json_object_is_type(out_device_o, json_type_string)) { pa_idxset_put(s->idx_avail_out_devices, (void*)json_object_get_string(out_device_o), NULL); pa_log_debug(" device[%d] : %s", j, json_object_get_string(out_device_o)); } @@ -1357,13 +1357,13 @@ static int init_stream_map (pa_stream_manager *m) { pa_log_error("Get stream avail-out-devices failed"); goto failed; } - if((avail_frameworks_o = json_object_object_get(stream_o, STREAM_MAP_STREAM_AVAIL_FRAMEWORKS)) && json_object_is_type(avail_frameworks_o, json_type_array)) { + if ((avail_frameworks_o = json_object_object_get(stream_o, STREAM_MAP_STREAM_AVAIL_FRAMEWORKS)) && json_object_is_type(avail_frameworks_o, json_type_array)) { j = 0; s->idx_avail_frameworks = pa_idxset_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); num_of_avail_frameworks = json_object_array_length(avail_frameworks_o); pa_log_debug(" - avail-frameworks"); for (j = 0; j < num_of_avail_frameworks; j++) { - if((framework_o = json_object_array_get_idx(avail_frameworks_o, j)) && json_object_is_type(framework_o, json_type_string)) { + if ((framework_o = json_object_array_get_idx(avail_frameworks_o, j)) && json_object_is_type(framework_o, json_type_string)) { pa_idxset_put(s->idx_avail_frameworks, (void*)json_object_get_string(framework_o), NULL); pa_log_debug(" framework[%d] : %s", j, json_object_get_string(framework_o)); } @@ -1372,7 +1372,7 @@ static int init_stream_map (pa_stream_manager *m) { pa_log_error("Get stream avail-frameworks failed"); goto failed; } - pa_hashmap_put(m->stream_infos,(void*)role, s); + pa_hashmap_put(m->stream_infos, (void*)role, s); } } } else { @@ -1406,7 +1406,7 @@ failed: return -1; } -static void deinit_stream_map (pa_stream_manager *m) { +static void deinit_stream_map(pa_stream_manager *m) { stream_info *s = NULL; volume_info *v = NULL; void *state = NULL; @@ -2014,7 +2014,7 @@ static void do_notify(pa_stream_manager *m, notify_command_type_t command, strea case NOTIFY_COMMAND_UPDATE_ROUTE_OPTION: { pa_assert(user_data); memset(&hook_call_option_data, 0, sizeof(pa_stream_manager_hook_data_for_option)); - s = (type == STREAM_SINK_INPUT) ? (void*)(m->cur_highest_priority.sink_input): + s = (type == STREAM_SINK_INPUT) ? (void*)(m->cur_highest_priority.sink_input) : (void*)(m->cur_highest_priority.source_output); if (s) { role = pa_proplist_gets(GET_STREAM_PROPLIST(s, type), PA_PROP_MEDIA_ROLE); @@ -2034,7 +2034,7 @@ static void do_notify(pa_stream_manager *m, notify_command_type_t command, strea stream_conn_info.role = pa_proplist_gets(GET_STREAM_PROPLIST(s, type), PA_PROP_MEDIA_ROLE); stream_conn_info.direction = (type == STREAM_SINK_INPUT) ? DIRECTION_OUT : DIRECTION_IN; stream_conn_info.idx = (type == STREAM_SINK_INPUT) ? ((pa_sink_input*)s)->index : ((pa_source_output*)s)->index; - stream_conn_info.is_connected = (command == NOTIFY_COMMAND_INFORM_STREAM_CONNECTED)?TRUE:FALSE; + stream_conn_info.is_connected = (command == NOTIFY_COMMAND_INFORM_STREAM_CONNECTED) ? TRUE : FALSE; pa_hal_manager_update_stream_connection_info(m->hal, &stream_conn_info); } break; @@ -2080,18 +2080,18 @@ static process_stream_result_t process_stream(pa_stream_manager *m, void *stream /* set sample_spec */ rate_str = pa_proplist_gets(req_format->plist, PA_PROP_FORMAT_RATE); ch_str = pa_proplist_gets(req_format->plist, PA_PROP_FORMAT_CHANNELS); - if (pa_format_info_get_prop_string(req_format, PA_PROP_FORMAT_SAMPLE_FORMAT, &format_str)==0) + if (pa_format_info_get_prop_string(req_format, PA_PROP_FORMAT_SAMPLE_FORMAT, &format_str) == 0) ((pa_sink_input_new_data*)stream)->sample_spec.format = pa_parse_sample_format((const char*)format_str); pa_log_info("req rate(%s), req ch(%s), req format(%s)", rate_str, ch_str, format_str); if (ch_str) - ((pa_sink_input_new_data*)stream)->sample_spec.channels = atoi (ch_str); + ((pa_sink_input_new_data*)stream)->sample_spec.channels = atoi(ch_str); if (rate_str) - ((pa_sink_input_new_data*)stream)->sample_spec.rate = atoi (rate_str); + ((pa_sink_input_new_data*)stream)->sample_spec.rate = atoi(rate_str); /* set channel map if it is not set by client */ if (!((pa_sink_input_new_data*)stream)->channel_map_is_set) { pa_channel_map_init_auto(&(((pa_sink_input_new_data*)stream)->channel_map), ((pa_sink_input_new_data*)stream)->sample_spec.channels, PA_CHANNEL_MAP_ALSA); - pa_log_info("set default channel_map: channels(%u)",((pa_sink_input_new_data*)stream)->channel_map.channels); + pa_log_info("set default channel_map: channels(%u)", ((pa_sink_input_new_data*)stream)->channel_map.channels); ((pa_sink_input_new_data*)stream)->channel_map_is_set = TRUE; } } @@ -2425,7 +2425,7 @@ static pa_hook_result_t sink_input_state_changed_cb(pa_core *core, pa_sink_input state = pa_sink_input_get_state(i); pa_log_info("start sink_input_state_changed_cb(), sink-input(%p), state(%d)", i, state); - switch(state) { + switch (state) { case PA_SINK_INPUT_CORKED: { process_stream(m, i, STREAM_SINK_INPUT, PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_ENDED, FALSE); break; @@ -2450,7 +2450,7 @@ static pa_hook_result_t sink_input_move_start_cb(pa_core *core, pa_sink_input *i if (core->state == PA_CORE_SHUTDOWN) return PA_HOOK_OK; - pa_log_debug ("sink_input_move_start_cb, i(%p, index:%u)", i, i->index); + pa_log_debug("sink_input_move_start_cb, i(%p, index:%u)", i, i->index); set_volume_mute_by_idx(m, i->index, STREAM_SINK_INPUT, TRUE); @@ -2465,7 +2465,7 @@ static pa_hook_result_t sink_input_move_finish_cb(pa_core *core, pa_sink_input * if (core->state == PA_CORE_SHUTDOWN) return PA_HOOK_OK; - pa_log_debug ("sink_input_move_finish_cb, i(%p, index:%u)", i, i->index); + pa_log_debug("sink_input_move_finish_cb, i(%p, index:%u)", i, i->index); set_volume_mute_by_idx(m, i->index, STREAM_SINK_INPUT, FALSE); @@ -2518,7 +2518,7 @@ static pa_hook_result_t source_output_state_changed_cb(pa_core *core, pa_source_ state = pa_source_output_get_state(o); pa_log_debug("start source_output_state_changed_cb(), source-output(%p), state(%d)", o, state); - switch(state) { + switch (state) { case PA_SOURCE_OUTPUT_CORKED: { process_stream(m, o, STREAM_SOURCE_OUTPUT, PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_ENDED, FALSE); break; @@ -2542,7 +2542,7 @@ static pa_hook_result_t source_output_move_start_cb(pa_core *core, pa_source_out if (core->state == PA_CORE_SHUTDOWN) return PA_HOOK_OK; - pa_log_debug ("source_output_move_start_cb, o(%p, index:%u)", o, o->index); + pa_log_debug("source_output_move_start_cb, o(%p, index:%u)", o, o->index); set_volume_mute_by_idx(m, o->index, STREAM_SINK_INPUT, TRUE); @@ -2557,7 +2557,7 @@ static pa_hook_result_t source_output_move_finish_cb(pa_core *core, pa_source_ou if (core->state == PA_CORE_SHUTDOWN) return PA_HOOK_OK; - pa_log_debug ("source_output_move_finish_cb, o(%p, index:%u)", o, o->index); + pa_log_debug("source_output_move_finish_cb, o(%p, index:%u)", o, o->index); set_volume_mute_by_idx(m, o->index, STREAM_SINK_INPUT, FALSE); @@ -2744,7 +2744,7 @@ static void update_sink_or_source_as_device_change(stream_route_type_t stream_ro pa_source *null_source = NULL; pa_bool_t available = FALSE; pa_bool_t use_internal_codec = FALSE; - cached_device_list cached_prev_dev_list[MAX_CACHED_LEN] = {{NULL,0},}; + cached_device_list cached_prev_dev_list[MAX_CACHED_LEN] = {{NULL, 0}, }; uint32_t cnt = 0; pa_sink *combine_sink = NULL; @@ -2768,7 +2768,7 @@ static void update_sink_or_source_as_device_change(stream_route_type_t stream_ro else source = pa_device_manager_get_source(device, DEVICE_ROLE_NORMAL); - PA_IDXSET_FOREACH (s, streams, s_idx) { /* streams: core->source_outputs/core->sink_inputs */ + PA_IDXSET_FOREACH(s, streams, s_idx) { /* streams: core->source_outputs/core->sink_inputs */ if (!pa_stream_manager_get_route_type(s, FALSE, stream_type, &route_type) && (route_type == stream_route_type)) { role = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROLE); pa_log_debug(" -- idx(%u), route_type(%d), role(%s)", s_idx, route_type, role); @@ -2869,7 +2869,7 @@ static void update_sink_or_source_as_device_change(stream_route_type_t stream_ro /* set device state to deactivated */ if (cnt) { - PA_IDXSET_FOREACH (s, streams, s_idx) { /* streams: core->source_outputs/core->sink_inputs */ + PA_IDXSET_FOREACH(s, streams, s_idx) { /* streams: core->source_outputs/core->sink_inputs */ if ((cur_device_type = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV))) { for (cnt = 0; cached_prev_dev_list[cnt].device_type; cnt++) { pa_log_warn(" -- cur_device(%s), cached_device(%s)", cur_device_type, cached_prev_dev_list[cnt].device_type); @@ -2899,7 +2899,7 @@ static void update_sink_or_source_as_device_change(stream_route_type_t stream_ro } else if (stream_route_type == STREAM_ROUTE_TYPE_MANUAL_EXT) { pa_log_info("[SM][UPDATE_SINK_SOURCE][EXT] deivce_type(%s), is_connected(%d))", device_type, is_connected); if (!is_connected) { - PA_IDXSET_FOREACH (s, streams, s_idx) { /* streams: source->outputs/sink->inputs */ + PA_IDXSET_FOREACH(s, streams, s_idx) { /* streams: source->outputs/sink->inputs */ if (!pa_stream_manager_get_route_type(s, FALSE, stream_type, &route_type) && route_type == stream_route_type) { if (stream_type == STREAM_SOURCE_OUTPUT) { /* move it to null source if this role is for external device */ @@ -2954,7 +2954,7 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_device_ if (!use_internal_codec && (device_direction & DM_DEVICE_DIRECTION_OUT)) { if ((sink = pa_device_manager_get_sink(data->device, DEVICE_ROLE_NORMAL))) update_sink_or_source_as_device_change(STREAM_ROUTE_TYPE_MANUAL_EXT, sink->inputs, - STREAM_SINK_INPUT,data->device, data->is_connected, m); + STREAM_SINK_INPUT, data->device, data->is_connected, m); else pa_log_error("[SM][CONN] could not get sink"); } @@ -2979,7 +2979,7 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_device_ if (!pa_stream_manager_get_route_type(m->cur_highest_priority.source_output, FALSE, STREAM_SOURCE_OUTPUT, &route_type)) { if (route_type < STREAM_ROUTE_TYPE_MANUAL) { if (use_internal_codec) { - PA_IDXSET_FOREACH (s, m->cur_highest_priority.source_output->source->outputs, s_idx) { + PA_IDXSET_FOREACH(s, m->cur_highest_priority.source_output->source->outputs, s_idx) { if (!data->is_connected && !pa_stream_manager_get_route_type(s, FALSE, STREAM_SOURCE_OUTPUT, &route_type) && ((route_type == STREAM_ROUTE_TYPE_AUTO) || (route_type == STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED))) { /* remove activated device info. if it has the AUTO route type */ @@ -3003,7 +3003,7 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_device_ if (!pa_stream_manager_get_route_type(m->cur_highest_priority.sink_input, FALSE, STREAM_SINK_INPUT, &route_type)) { if (route_type < STREAM_ROUTE_TYPE_MANUAL) { if (use_internal_codec) { - PA_IDXSET_FOREACH (s, m->cur_highest_priority.sink_input->sink->inputs, s_idx) { + PA_IDXSET_FOREACH(s, m->cur_highest_priority.sink_input->sink->inputs, s_idx) { if (!data->is_connected && !pa_stream_manager_get_route_type(s, FALSE, STREAM_SINK_INPUT, &route_type) && ((route_type == STREAM_ROUTE_TYPE_AUTO) || (route_type == STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED))) { /* remove activated device info. if it has the AUTO route type */ @@ -3045,7 +3045,7 @@ static void subscribe_cb(pa_core *core, pa_subscription_event_type_t t, uint32_t return; } name = pa_proplist_gets(client->proplist, PA_PROP_APPLICATION_NAME); - if (name && strncmp (name, STREAM_MANAGER_CLIENT_NAME, strlen(STREAM_MANAGER_CLIENT_NAME))) { + if (name && strncmp(name, STREAM_MANAGER_CLIENT_NAME, strlen(STREAM_MANAGER_CLIENT_NAME))) { pa_log_warn(" - this is not a client(%s) that we should take care of, skip it", name); return; } @@ -3083,7 +3083,7 @@ static void subscribe_cb(pa_core *core, pa_subscription_event_type_t t, uint32_t } } -static int init_ipc (pa_stream_manager *m) { +static int init_ipc(pa_stream_manager *m) { #ifdef HAVE_DBUS #ifdef USE_DBUS_PROTOCOL pa_assert(m); @@ -3126,7 +3126,7 @@ fail: return -1; } -static void deinit_ipc (pa_stream_manager *m) { +static void deinit_ipc(pa_stream_manager *m) { pa_assert(m); #ifdef HAVE_DBUS @@ -3139,7 +3139,7 @@ static void deinit_ipc (pa_stream_manager *m) { } #else if (m->dbus_conn) { - if(!dbus_connection_unregister_object_path(pa_dbus_connection_get(m->dbus_conn), STREAM_MANAGER_OBJECT_PATH)) + if (!dbus_connection_unregister_object_path(pa_dbus_connection_get(m->dbus_conn), STREAM_MANAGER_OBJECT_PATH)) pa_log_error("failed to unregister object path"); m->dbus_conn = NULL; } @@ -3219,8 +3219,8 @@ pa_stream_manager* pa_stream_manager_init(pa_core *c) { m->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_CLIENT | PA_SUBSCRIPTION_MASK_SAMPLE_CACHE, (pa_subscription_cb_t)subscribe_cb, m); m->comm.comm = pa_communicator_get(c); - m->comm.comm_hook_device_connection_changed_slot = pa_hook_connect(pa_communicator_hook(m->comm.comm,PA_COMMUNICATOR_HOOK_DEVICE_CONNECTION_CHANGED), - PA_HOOK_EARLY + 10, (pa_hook_cb_t) device_connection_changed_hook_cb, m); + m->comm.comm_hook_device_connection_changed_slot = pa_hook_connect(pa_communicator_hook(m->comm.comm, PA_COMMUNICATOR_HOOK_DEVICE_CONNECTION_CHANGED), + PA_HOOK_EARLY + 10, (pa_hook_cb_t)device_connection_changed_hook_cb, m); return m; diff --git a/src/stream-manager.h b/src/stream-manager.h index a868721..93b3c3d 100644 --- a/src/stream-manager.h +++ b/src/stream-manager.h @@ -9,10 +9,10 @@ (route_type_str && !pa_atoi(route_type_str, (int32_t*)&route_type) && (route_type == STREAM_ROUTE_TYPE_AUTO)) #define GET_STREAM_NEW_PROPLIST(stream, type) \ - (type == STREAM_SINK_INPUT? ((pa_sink_input_new_data*)stream)->proplist : ((pa_source_output_new_data*)stream)->proplist) + (type == STREAM_SINK_INPUT ? ((pa_sink_input_new_data*)stream)->proplist : ((pa_source_output_new_data*)stream)->proplist) #define GET_STREAM_PROPLIST(stream, type) \ - (type == STREAM_SINK_INPUT? ((pa_sink_input*)stream)->proplist : ((pa_source_output*)stream)->proplist) + (type == STREAM_SINK_INPUT ? ((pa_sink_input*)stream)->proplist : ((pa_source_output*)stream)->proplist) #define SINK_NAME_COMBINED "sink_combined" #define SINK_NAME_NULL "sink_null" -- 2.7.4 From 315509c3d15dd205b579ea9119d6a1da35050ac4 Mon Sep 17 00:00:00 2001 From: Mok Jeongho Date: Mon, 14 Dec 2015 20:49:40 +0900 Subject: [PATCH 12/16] device-manager : increase max length of device param Previously, max length of device param was too short, so we cannot add more parameters for it. so increased it. [Version] 5.0.25 [Profile] Common [Issue Type] Feature Enhancement Change-Id: I48d0420eefcf6ffc4bf6b5e5a218d934d4e8ded1 --- 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 10b6825..bb293cc 100644 --- a/packaging/pulseaudio-modules-tizen.spec +++ b/packaging/pulseaudio-modules-tizen.spec @@ -1,6 +1,6 @@ Name: pulseaudio-modules-tizen Summary: Pulseaudio modules for Tizen -Version: 5.0.24 +Version: 5.0.25 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/device-manager.c b/src/device-manager.c index 9a0ea06..0b66b6e 100644 --- a/src/device-manager.c +++ b/src/device-manager.c @@ -34,7 +34,7 @@ #define DEVICE_PROFILE_MAX 2 #define DEVICE_STR_MAX 30 #define DEVICE_DIRECTION_MAX 3 -#define DEVICE_PARAM_STRING_MAX 50 +#define DEVICE_PARAM_STRING_MAX 150 #define DEVICE_AVAIL_COND_NUM_MAX 2 #define DEVICE_AVAIL_COND_STR_MAX 6 #define DEVICE_FILE_PER_TYPE_MAX 4 -- 2.7.4 From f358e10d70de77782f929cef8dd7614350ce7756 Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Mon, 21 Dec 2015 14:49:16 +0900 Subject: [PATCH 13/16] device-manager: set DEVICE_DETECTED_AUDIO_JACK_OUT_DIRECT temporarily when detecting audio jack regardless of its direction [Profile] Common [Issue Type] temporary code Change-Id: If541dc119998ac1cd6fc1493c755c63c38109611 --- src/device-manager.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/device-manager.c b/src/device-manager.c index 0b66b6e..6f8df21 100644 --- a/src/device-manager.c +++ b/src/device-manager.c @@ -3183,10 +3183,15 @@ static int handle_device_status_changed(pa_device_manager *dm, const char *devic if (pa_streq(device_type, DEVICE_TYPE_AUDIO_JACK)) { if (detected_status == EARJACK_DISCONNECTED) { handle_device_disconnected(dm, device_type, device_profile, identifier); +#if 0 /* disable this code temporarily, it will be fixed soon */ } else if (detected_status == EARJACK_TYPE_SPK_ONLY) { handle_device_connected(dm, device_type, device_profile, name, identifier, DEVICE_DETECTED_AUDIO_JACK_OUT_DIREC); } else if (detected_status == EARJACK_TYPE_SPK_WITH_MIC) { handle_device_connected(dm, device_type, device_profile, name, identifier, DEVICE_DETECTED_AUDIO_JACK_BOTH_DIREC); +#else + } else if (detected_status == EARJACK_TYPE_SPK_ONLY || detected_status == EARJACK_TYPE_SPK_WITH_MIC) { + handle_device_connected(dm, device_type, device_profile, name, identifier, DEVICE_DETECTED_AUDIO_JACK_OUT_DIREC); +#endif } else { pa_log_warn("Got invalid audio-jack detected value"); return -1; -- 2.7.4 From 814755a3f108272767ad34099cef38fc16b966b8 Mon Sep 17 00:00:00 2001 From: Mok Jeongho Date: Wed, 23 Dec 2015 10:40:54 +0900 Subject: [PATCH 14/16] device-manager : get use_internal_codec for both device correctly [Version] 5.0.26 [Profile] Common [Issue Type] Fix Bug Change-Id: Ie4efb1ce85c545c4c29f69b62baa989a5b3685b4 --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/device-manager.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index bb293cc..ace6df4 100644 --- a/packaging/pulseaudio-modules-tizen.spec +++ b/packaging/pulseaudio-modules-tizen.spec @@ -1,6 +1,6 @@ Name: pulseaudio-modules-tizen Summary: Pulseaudio modules for Tizen -Version: 5.0.25 +Version: 5.0.26 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/device-manager.c b/src/device-manager.c index 6f8df21..9ed5ed9 100644 --- a/src/device-manager.c +++ b/src/device-manager.c @@ -3183,15 +3183,10 @@ static int handle_device_status_changed(pa_device_manager *dm, const char *devic if (pa_streq(device_type, DEVICE_TYPE_AUDIO_JACK)) { if (detected_status == EARJACK_DISCONNECTED) { handle_device_disconnected(dm, device_type, device_profile, identifier); -#if 0 /* disable this code temporarily, it will be fixed soon */ } else if (detected_status == EARJACK_TYPE_SPK_ONLY) { handle_device_connected(dm, device_type, device_profile, name, identifier, DEVICE_DETECTED_AUDIO_JACK_OUT_DIREC); } else if (detected_status == EARJACK_TYPE_SPK_WITH_MIC) { handle_device_connected(dm, device_type, device_profile, name, identifier, DEVICE_DETECTED_AUDIO_JACK_BOTH_DIREC); -#else - } else if (detected_status == EARJACK_TYPE_SPK_ONLY || detected_status == EARJACK_TYPE_SPK_WITH_MIC) { - handle_device_connected(dm, device_type, device_profile, name, identifier, DEVICE_DETECTED_AUDIO_JACK_OUT_DIREC); -#endif } else { pa_log_warn("Got invalid audio-jack detected value"); return -1; @@ -4142,6 +4137,11 @@ pa_bool_t pa_device_manager_is_device_use_internal_codec(dm_device *device_item, } else if (direction == DM_DEVICE_DIRECTION_OUT) { if ((sink = pa_device_manager_get_sink(device_item, role))) use_internal_codec = sink->use_internal_codec; + } else if (direction == DM_DEVICE_DIRECTION_BOTH) { + if ((sink = pa_device_manager_get_sink(device_item, role)) && (source = pa_device_manager_get_source(device_item, role))) + use_internal_codec = sink->use_internal_codec & source->use_internal_codec; + } else { + pa_log_warn("invalid direction"); } return use_internal_codec; -- 2.7.4 From c4cc04006c0153ab915e0a2947a320933ce1473e Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Thu, 31 Dec 2015 09:04:11 +0900 Subject: [PATCH 15/16] policy: Modifications regarding device role/stream role for coping with a specific hardware Sets null sink or null source in case of a virtual stream made by sound-manager native API in stream-manager. Returns a sink or source of normal role when a requested device role is not available in device-manager(pa_device_manager_get_sink/_get_source). Moves streams if needed at the beginning and end of voice call scenario. Update active device info. to incoming stream(auto) even if the occupying stream does not need to change. [Version] 5.0.27 [Profile] Common [Issue Type] Feature Enhancement and Bug Fix Change-Id: Id0e4399c60dfa45063832606a50812184e8786d9 Signed-off-by: Sangchul Lee --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/device-manager.c | 24 ++++- src/device-manager.h | 2 + src/module-policy.c | 122 ++++++++++++++++------ src/stream-manager-priv.h | 2 + src/stream-manager.c | 179 ++++++++++++++++++++++++-------- src/stream-manager.h | 7 ++ 7 files changed, 258 insertions(+), 80 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index ace6df4..7828e1a 100644 --- a/packaging/pulseaudio-modules-tizen.spec +++ b/packaging/pulseaudio-modules-tizen.spec @@ -1,6 +1,6 @@ Name: pulseaudio-modules-tizen Summary: Pulseaudio modules for Tizen -Version: 5.0.26 +Version: 5.0.27 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/device-manager.c b/src/device-manager.c index 9ed5ed9..e6662bf 100644 --- a/src/device-manager.c +++ b/src/device-manager.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -536,6 +537,10 @@ static pa_bool_t device_role_is_valid(const char *device_role) { return FALSE; else if (pa_streq(device_role, DEVICE_ROLE_NORMAL)) return TRUE; + else if (pa_streq(device_role, DEVICE_ROLE_CALL_VOICE)) + return TRUE; + else if (pa_streq(device_role, DEVICE_ROLE_CALL_VIDEO)) + return TRUE; else if (pa_streq(device_role, DEVICE_ROLE_VOIP)) return TRUE; else if (pa_streq(device_role, DEVICE_ROLE_LOW_LATENCY)) @@ -4020,6 +4025,7 @@ dm_device* pa_device_manager_get_device_by_id(pa_device_manager *dm, uint32_t id pa_sink* pa_device_manager_get_sink(dm_device *device_item, const char *role) { dm_device_profile *profile_item; + pa_sink *sink; pa_assert(device_item); pa_assert(profile_item = _device_item_get_active_profile(device_item)); @@ -4028,12 +4034,19 @@ pa_sink* pa_device_manager_get_sink(dm_device *device_item, const char *role) { pa_log_warn("No playback device in %s", device_item->name); return NULL; } + if ((sink = pa_hashmap_get(profile_item->playback_devices, role))) + pa_log_debug("Got sink[%s] for [%s] role", sink->name, role); + else { + sink = pa_hashmap_get(profile_item->playback_devices, DEVICE_ROLE_NORMAL); + pa_log_debug("Could not get sink for [%s] role. so get sink[%s] for normal role", role, sink->name); + } - return pa_hashmap_get(profile_item->playback_devices, role); + return sink; } pa_source* pa_device_manager_get_source(dm_device *device_item, const char *role) { dm_device_profile *profile_item; + pa_source *source; pa_assert(device_item); pa_assert(profile_item = _device_item_get_active_profile(device_item)); @@ -4043,7 +4056,14 @@ pa_source* pa_device_manager_get_source(dm_device *device_item, const char *role return NULL; } - return pa_hashmap_get(profile_item->capture_devices, role); + if ((source = pa_hashmap_get(profile_item->capture_devices, role))) + pa_log_debug("Got source[%s] for [%s] role", source->name, role); + else { + source = pa_hashmap_get(profile_item->capture_devices, DEVICE_ROLE_NORMAL); + pa_log_debug("Could not get source for [%s] role. so get source[%s] for normal role", role, source->name); + } + + return source; } dm_device* pa_device_manager_get_device_with_sink(pa_sink *sink) { diff --git a/src/device-manager.h b/src/device-manager.h index 0e49f68..2d37ba9 100644 --- a/src/device-manager.h +++ b/src/device-manager.h @@ -15,6 +15,8 @@ #define DEVICE_PROFILE_BT_A2DP "a2dp" #define DEVICE_ROLE_NORMAL "normal" +#define DEVICE_ROLE_CALL_VOICE "call-voice" +#define DEVICE_ROLE_CALL_VIDEO "call-video" #define DEVICE_ROLE_VOIP "voip" #define DEVICE_ROLE_LOW_LATENCY "low-latency" #define DEVICE_ROLE_HIGH_LATENCY "high-latency" diff --git a/src/module-policy.c b/src/module-policy.c index 1de03eb..3fe8af7 100644 --- a/src/module-policy.c +++ b/src/module-policy.c @@ -321,8 +321,8 @@ static pa_hook_result_t select_proper_sink_or_source_hook_cb(pa_core *c, pa_stre pa_assert(data); pa_assert(u); - pa_log_info("[SELECT] select_proper_sink_or_source_hook_cb is called. (%p), stream_type(%d), stream_role(%s), route_type(%d)", - data, data->stream_type, data->stream_role, data->route_type); + pa_log_info("[SELECT] select_proper_sink_or_source_hook_cb is called. (%p), stream_type(%d), stream_role(%s), device_role(%s), route_type(%d)", + data, data->stream_type, data->stream_role, data->device_role, data->route_type); null_sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_NULL, PA_NAMEREG_SINK); null_source = (pa_source*)pa_namereg_get(u->core, SOURCE_NAME_NULL, PA_NAMEREG_SOURCE); @@ -331,6 +331,16 @@ static pa_hook_result_t select_proper_sink_or_source_hook_cb(pa_core *c, pa_stre return PA_HOOK_OK; } + /* check if the current occupying role is related to call. + * some targets use several pcm card as per their purpose. + * e.g) using a specific pcm card during voice call. */ + if (data->occupying_role) { + if (pa_streq(data->occupying_role, STREAM_ROLE_CALL_VOICE)) { + data->device_role = DEVICE_ROLE_CALL_VOICE; + pa_log_info("[SELECT] current occupying stream role is [%s], set deivce role to [%s]", data->occupying_role, data->device_role); + } + } + if ((data->route_type <= STREAM_ROUTE_TYPE_AUTO_ALL) && data->idx_avail_devices) { /* get current connected devices */ conn_devices = pa_device_manager_get_device_list(u->device_manager); @@ -352,9 +362,9 @@ static pa_hook_result_t select_proper_sink_or_source_hook_cb(pa_core *c, pa_stre *(data->proper_sink) = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK); pa_log_debug(" -- found the combine-sink, set it to the sink"); } else - *(data->proper_sink) = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL); + *(data->proper_sink) = pa_device_manager_get_sink(device, data->device_role); } else - *(data->proper_source) = pa_device_manager_get_source(device, DEVICE_ROLE_NORMAL); + *(data->proper_source) = pa_device_manager_get_source(device, data->device_role); break; } } @@ -384,9 +394,9 @@ static pa_hook_result_t select_proper_sink_or_source_hook_cb(pa_core *c, pa_stre /* update active device info. */ if (latest_device) { if (data->stream_type == STREAM_SINK_INPUT) - *(data->proper_sink) = pa_device_manager_get_sink(latest_device, DEVICE_ROLE_NORMAL); + *(data->proper_sink) = pa_device_manager_get_sink(latest_device, data->device_role); else - *(data->proper_source) = pa_device_manager_get_source(latest_device, DEVICE_ROLE_NORMAL); + *(data->proper_source) = pa_device_manager_get_source(latest_device, data->device_role); pa_proplist_sets(GET_STREAM_NEW_PROPLIST(data->stream, data->stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, dm_device_type); } @@ -406,14 +416,14 @@ static pa_hook_result_t select_proper_sink_or_source_hook_cb(pa_core *c, pa_stre pa_log_info(" ** found a matched device: type[%-16s], direction[0x%x]", device_type, dm_device_direction); if (data->stream_type == STREAM_SINK_INPUT) { if ((*(data->proper_sink)) == null_sink) - pa_sink_input_move_to((pa_sink_input*)(data->stream), pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL), FALSE); + pa_sink_input_move_to((pa_sink_input*)(data->stream), pa_device_manager_get_sink(device, data->device_role), FALSE); else - *(data->proper_sink) = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL); + *(data->proper_sink) = pa_device_manager_get_sink(device, data->device_role); } else { if ((*(data->proper_source)) == null_source) - pa_source_output_move_to((pa_source_output*)(data->stream), pa_device_manager_get_source(device, DEVICE_ROLE_NORMAL), FALSE); + pa_source_output_move_to((pa_source_output*)(data->stream), pa_device_manager_get_source(device, data->device_role), FALSE); else - *(data->proper_source) = pa_device_manager_get_source(device, DEVICE_ROLE_NORMAL); + *(data->proper_source) = pa_device_manager_get_source(device, data->device_role); } } } @@ -548,11 +558,11 @@ static int set_bt_sco_state(pa_device_manager *dm, pa_bool_t open) { /* Change the route setting according to the data from argument. * This function is called only when it needs to change routing path via HAL. - * - role is "reset" + * - stream is null * 1. It will be received when it is needed to terminate playback * or capture routing path. * 2. Update the state of the device to be deactivated. - * 3. Call HAL API to reset routing. + * 3. Call HAL API to "reset" routing. * - ROUTE_TYPE_AUTO * 1. Find the proper sink/source comparing between avail_devices * and current connected devices. @@ -590,8 +600,11 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ dm_device_direction_t dm_device_direction = DM_DEVICE_DIRECTION_NONE; io_direction_t hal_direction; void *s = NULL; + pa_idxset *streams = NULL; pa_sink *sink = NULL; + pa_sink *dst_sink = NULL; pa_source *source = NULL; + pa_source *dst_source = NULL; pa_idxset *conn_devices = NULL; pa_sink *combine_sink_arg1 = NULL; pa_sink *combine_sink_arg2 = NULL; @@ -611,7 +624,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ route_info.role = data->stream_role; - if (pa_streq(data->stream_role, "reset")) { + if (data->stream == NULL) { /* update BT SCO: close */ set_bt_sco_state(u->device_manager, FALSE); @@ -627,6 +640,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ set_device_state_if_using_internal_codec(device, data->stream_type, DM_DEVICE_STATE_DEACTIVATED); } } + route_info.role = "reset"; route_info.num_of_devices = 1; route_info.device_infos = pa_xmalloc0(sizeof(hal_device_info)*route_info.num_of_devices); route_info.device_infos[0].direction = (data->stream_type == STREAM_SINK_INPUT) ? DIRECTION_OUT : DIRECTION_IN; @@ -667,7 +681,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ dm_device_type, dm_device_subtype, dm_device_direction, dm_device_id); if (pa_streq(device_type, dm_device_type) && IS_AVAILABLE_DIRECTION(data->stream_type, dm_device_direction)) { pa_log_debug(" ** found a matched device: type[%-16s], direction[0x%x]", dm_device_type, dm_device_direction); - use_internal_codec = pa_device_manager_is_device_use_internal_codec(device, CONVERT_TO_DEVICE_DIRECTION(data->stream_type), DEVICE_ROLE_NORMAL); + use_internal_codec = pa_device_manager_is_device_use_internal_codec(device, CONVERT_TO_DEVICE_DIRECTION(data->stream_type), data->device_role); if (use_internal_codec) { hal_direction = (data->stream_type == STREAM_SINK_INPUT) ? DIRECTION_OUT : DIRECTION_IN; route_info.num_of_devices++; @@ -705,7 +719,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ /* move sink-inputs/source-outputs if needed */ if (data->stream_type == STREAM_SINK_INPUT) - sink = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL); + sink = pa_device_manager_get_sink(device, data->device_role); /* unload combine sink */ if (data->stream_type == STREAM_SINK_INPUT && u->module_combine_sink) { @@ -731,10 +745,10 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK); pa_log_info("[ROUTE][AUTO_ALL] found the combine_sink already existed"); } else if (data->stream_type == STREAM_SINK_INPUT && !combine_sink_arg1) { - sink = combine_sink_arg1 = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL); + sink = combine_sink_arg1 = pa_device_manager_get_sink(device, data->device_role); pa_log_debug("[ROUTE][AUTO_ALL] combine_sink_arg1[%s], combine_sink_arg2[%p]", sink->name, combine_sink_arg2); } else if (data->stream_type == STREAM_SINK_INPUT && !combine_sink_arg2) { - sink = combine_sink_arg2 = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL); + sink = combine_sink_arg2 = pa_device_manager_get_sink(device, data->device_role); if (sink && !pa_streq(sink->name, combine_sink_arg1->name)) { pa_log_debug("[ROUTE][AUTO_ALL] combine_sink_arg2[%s]", sink->name); /* load combine sink */ @@ -756,7 +770,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ pa_log_error("[ROUTE][AUTO_ALL] could not get combine_sink"); } } else if (data->stream_type == STREAM_SOURCE_OUTPUT) - source = pa_device_manager_get_source(device, DEVICE_ROLE_NORMAL); + source = pa_device_manager_get_source(device, data->device_role); if (data->origins_from_new_data) { if (data->stream_type == STREAM_SINK_INPUT) @@ -808,7 +822,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ if (latest_device) { dm_device_type = pa_device_manager_get_device_type(latest_device); dm_device_id = pa_device_manager_get_device_id(latest_device); - use_internal_codec = pa_device_manager_is_device_use_internal_codec(latest_device, CONVERT_TO_DEVICE_DIRECTION(data->stream_type), DEVICE_ROLE_NORMAL); + use_internal_codec = pa_device_manager_is_device_use_internal_codec(latest_device, CONVERT_TO_DEVICE_DIRECTION(data->stream_type), data->device_role); if (use_internal_codec) { hal_direction = (data->stream_type == STREAM_SINK_INPUT) ? DIRECTION_OUT : DIRECTION_IN; route_info.num_of_devices++; @@ -909,21 +923,61 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ } } } - - /* move sink-inputs/source-outputs if needed */ - if (device && !data->origins_from_new_data) { - if (data->stream_type == STREAM_SINK_INPUT) - sink = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL); - else if (data->stream_type == STREAM_SOURCE_OUTPUT) - source = pa_device_manager_get_source(device, DEVICE_ROLE_NORMAL); - if (data->idx_streams) { - PA_IDXSET_FOREACH(s, data->idx_streams, idx) { - if (sink && (sink != ((pa_sink_input*)s)->sink)) { - pa_sink_input_move_to(s, sink, FALSE); - pa_log_debug("[ROUTE][MANUAL] *** sink-input(%p,%u) moves to sink(%p,%s)", s, ((pa_sink_input*)s)->index, sink, sink->name); - } else if (source && (source != ((pa_source_output*)s)->source)) { - pa_source_output_move_to(s, source, FALSE); - pa_log_debug("[ROUTE][MANUAL] *** source-output(%p,%u) moves to source(%p,%s)", s, ((pa_source_output*)s)->index, source, source->name); + } + /* move streams to a proper sink/source if needed. + * some targets use several pcm card as per their purpose. + * e.g) using a specific pcm card during voice call. + * here is the code for roll-back. */ + if (device && data->stream && !data->origins_from_new_data && + data->route_type != STREAM_ROUTE_TYPE_MANUAL) { + if (data->stream_type == STREAM_SINK_INPUT) + sink = pa_device_manager_get_sink(device, data->device_role); + else if (data->stream_type == STREAM_SOURCE_OUTPUT) + source = pa_device_manager_get_source(device, data->device_role); + if (data->idx_streams) { + PA_IDXSET_FOREACH(s, data->idx_streams, idx) { + if (sink && sink != ((pa_sink_input*)s)->sink) { + pa_sink_input_move_to(s, sink, FALSE); + pa_log_debug("[ROUTE][ROLLBACK] *** sink-input(%p,%u) moves to sink(%p,%s)", + s, ((pa_sink_input*)s)->index, sink, sink->name); + } else if (source && source != ((pa_source_output*)s)->source) { + pa_source_output_move_to(s, source, FALSE); + pa_log_debug("[ROUTE][ROLLBACK] *** source-output(%p,%u) moves to source(%p,%s)", + s, ((pa_source_output*)s)->index, source, source->name); + } + } + } + } + /* move other streams that are belong to device of NORMAL role + * to a proper sink/source if needed */ + if (device && data->stream && data->origins_from_new_data && + data->route_type == STREAM_ROUTE_TYPE_MANUAL) { + if (pa_streq(data->stream_role, STREAM_ROLE_CALL_VOICE)) { + if (data->stream_type == STREAM_SINK_INPUT) { + if (!(sink = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL)) || + !(dst_sink = pa_device_manager_get_sink(device, DEVICE_ROLE_CALL_VOICE)) || + sink == dst_sink) + pa_log_debug("[ROUTE][CALL-VOICE] no need to move streams, sink(%p), dst_sink(%p)", sink, dst_sink); + else + streams = sink->inputs; + } else if (data->stream_type == STREAM_SOURCE_OUTPUT) { + if (!(source = pa_device_manager_get_source(device, DEVICE_ROLE_NORMAL)) || + !(dst_source = pa_device_manager_get_source(device, DEVICE_ROLE_CALL_VOICE)) || + source == dst_source) + pa_log_debug("[ROUTE][CALL-VOICE] no need to move streams, source(%p), dst_source(%p)", source, dst_source); + else + streams = source->outputs; + } + if (streams) { + PA_IDXSET_FOREACH(s, streams, idx) { + if (data->stream_type == STREAM_SINK_INPUT) { + pa_sink_input_move_to(s, dst_sink, FALSE); + pa_log_debug("[ROUTE][CALL-VOICE] *** sink-input(%p,%u) moves to sink(%p,%s)", + s, ((pa_sink_input*)s)->index, dst_sink, dst_sink->name); + } else if (data->stream_type == STREAM_SOURCE_OUTPUT) { + pa_source_output_move_to(s, dst_source, FALSE); + pa_log_debug("[ROUTE][CALL-VOICE] *** source-output(%p,%u) moves to source(%p,%s)", + s, ((pa_source_output*)s)->index, dst_source, dst_source->name); } } } diff --git a/src/stream-manager-priv.h b/src/stream-manager-priv.h index b7cd18f..f883c61 100644 --- a/src/stream-manager-priv.h +++ b/src/stream-manager-priv.h @@ -61,6 +61,8 @@ typedef struct _prior_max_priority_stream { pa_source_output *source_output; pa_bool_t need_to_update_si; pa_bool_t need_to_update_so; + const char *role_si; + const char *role_so; } cur_max_priority_stream; struct _stream_manager { diff --git a/src/stream-manager.c b/src/stream-manager.c index 822dc5c..fd8eb83 100644 --- a/src/stream-manager.c +++ b/src/stream-manager.c @@ -297,7 +297,8 @@ static pa_dbus_interface_info stream_manager_interface_info = { #endif -#define STREAM_MANAGER_CLIENT_NAME "SOUND_MANAGER_STREAM_INFO" +#define STREAM_MANAGER_CLIENT_NAME "SOUND_MANAGER_STREAM_INFO" /* The client via sound-manager */ +#define VIRTUAL_STREAM_NAME "VIRTUAL_STREAM" /* The virtual stream created by sound-manager */ #define DEFAULT_ROLE "media" #define SKIP_ROLE "skip" #define ACTIVE_DEV_REMOVED "removed" @@ -405,9 +406,39 @@ typedef struct _stream_route_option { int32_t value; } stream_route_option; -#define CONVERT_TO_DEVICE_DIRECTION(stream_type)\ +#define CONVERT_TO_DEVICE_DIRECTION(stream_type) \ ((stream_type == STREAM_SINK_INPUT) ? DM_DEVICE_DIRECTION_OUT : DM_DEVICE_DIRECTION_IN) +#define CONVERT_TO_DEVICE_ROLE(x_stream_role, x_device_role) { \ + pa_assert(x_stream_role); \ + if (pa_streq(x_stream_role, STREAM_ROLE_CALL_VOICE)) \ + x_device_role = DEVICE_ROLE_CALL_VOICE; \ + else if (pa_streq(x_stream_role, STREAM_ROLE_CALL_VIDEO)) \ + x_device_role = DEVICE_ROLE_CALL_VIDEO; \ + else if (pa_streq(x_stream_role, STREAM_ROLE_VOIP)) \ + x_device_role = DEVICE_ROLE_VOIP; \ + else \ + x_device_role = DEVICE_ROLE_NORMAL; \ +} \ + +#define SET_NEW_DATA_STREAM_TO_NULL_SINK_SOURCE(x_m, x_stream, x_stream_type) { \ + pa_sink *null_sink; \ + pa_source *null_source; \ + if (x_stream_type == STREAM_SINK_INPUT && \ + (!((pa_sink_input_new_data*)x_stream)->sink)) { \ + if ((null_sink = (pa_sink*)pa_namereg_get(x_m->core, SINK_NAME_NULL, PA_NAMEREG_SINK))) \ + ((pa_sink_input_new_data*)x_stream)->sink = null_sink; \ + else \ + pa_log_warn("could not get null_sink"); \ + } else if (x_stream_type == STREAM_SOURCE_OUTPUT && \ + (!((pa_source_output_new_data*)x_stream)->source)) { \ + if ((null_source = (pa_source*)pa_namereg_get(x_m->core, SOURCE_NAME_NULL, PA_NAMEREG_SOURCE))) \ + ((pa_source_output_new_data*)x_stream)->source = null_source; \ + else \ + pa_log_warn("could not get null_source"); \ + } \ +} \ + static void do_notify(pa_stream_manager *m, notify_command_type_t command, stream_type_t type, pa_bool_t is_new_data, void *user_data); static process_stream_result_t process_stream(pa_stream_manager *m, void *stream, stream_type_t type, process_command_type_t command, pa_bool_t is_new_data); @@ -477,6 +508,16 @@ static int get_stream_info(pa_stream_manager *m, const char *stream_role, stream pa_log_error(" avail-frameworks, out of range, [%d]", idx); } info->num_of_frameworks = pa_idxset_size(s->idx_avail_frameworks); + } else { + /* set variables for error */ + info->priority = -1; + info->num_of_in_devices = info->num_of_out_devices = info->num_of_frameworks = 1; + info->volume_types[0] = info->volume_types[1] = dbus_str_none; + info->avail_in_devices[0] = dbus_str_none; + info->avail_out_devices[0] = dbus_str_none; + info->avail_frameworks[0] = dbus_str_none; + pa_log_error("could not find the stream_role : %s", stream_role); + return -1; } } else { pa_log_error("stream_map is not initialized.."); @@ -552,21 +593,14 @@ static void handle_get_stream_info(DBusConnection *conn, DBusMessage *msg, void memset(&info, 0, sizeof(stream_info_per_type)); pa_assert_se((reply = dbus_message_new_method_return(msg))); dbus_message_iter_init_append(reply, &msg_iter); - if (!get_stream_info(m, type, &info)) { - pa_dbus_append_basic_variant(&msg_iter, DBUS_TYPE_INT32, &info.priority); - pa_dbus_append_basic_variant(&msg_iter, DBUS_TYPE_INT32, &info.route_type); - pa_dbus_append_basic_array_variant(&msg_iter, DBUS_TYPE_STRING, &info.volume_types, STREAM_DIRECTION_MAX); - pa_dbus_append_basic_array_variant(&msg_iter, DBUS_TYPE_STRING, &info.avail_in_devices, info.num_of_in_devices); - pa_dbus_append_basic_array_variant(&msg_iter, DBUS_TYPE_STRING, &info.avail_out_devices, info.num_of_out_devices); - pa_dbus_append_basic_array_variant(&msg_iter, DBUS_TYPE_STRING, &info.avail_frameworks, info.num_of_frameworks); - } else { - pa_dbus_append_basic_variant(&msg_iter, DBUS_TYPE_INT32, 0); - pa_dbus_append_basic_variant(&msg_iter, DBUS_TYPE_INT32, 0); - pa_dbus_append_basic_array_variant(&msg_iter, DBUS_TYPE_STRING, NULL, 0); - pa_dbus_append_basic_array_variant(&msg_iter, DBUS_TYPE_STRING, NULL, 0); - pa_dbus_append_basic_array_variant(&msg_iter, DBUS_TYPE_STRING, NULL, 0); - pa_dbus_append_basic_array_variant(&msg_iter, DBUS_TYPE_STRING, NULL, 0); - } + get_stream_info(m, type, &info); + pa_dbus_append_basic_variant(&msg_iter, DBUS_TYPE_INT32, &info.priority); + pa_dbus_append_basic_variant(&msg_iter, DBUS_TYPE_INT32, &info.route_type); + pa_dbus_append_basic_array_variant(&msg_iter, DBUS_TYPE_STRING, &info.volume_types, STREAM_DIRECTION_MAX); + pa_dbus_append_basic_array_variant(&msg_iter, DBUS_TYPE_STRING, &info.avail_in_devices, info.num_of_in_devices); + pa_dbus_append_basic_array_variant(&msg_iter, DBUS_TYPE_STRING, &info.avail_out_devices, info.num_of_out_devices); + pa_dbus_append_basic_array_variant(&msg_iter, DBUS_TYPE_STRING, &info.avail_frameworks, info.num_of_frameworks); + pa_assert_se(dbus_connection_send(conn, reply, NULL)); dbus_message_unref(reply); } @@ -1445,15 +1479,14 @@ static pa_bool_t check_name_to_skip(pa_stream_manager *m, process_command_type_t pa_assert(stream); if (command == PROCESS_COMMAND_PREPARE && is_new_data) { - name = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_NAME); - if (name) { + if ((name = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_NAME))) { for (i = 0; i < NAME_FOR_SKIP_MAX; i++) if (pa_streq(name, stream_manager_media_names_for_skip[i])) { ret = TRUE; pa_proplist_sets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE, SKIP_ROLE); break; } - pa_log_info("name is [%s], skip(%d)", name, ret); + pa_log_info("name is [%s], skip(%d) command(%s)", name, ret, process_command_type_str[command]); } } else { if (is_new_data) @@ -1461,7 +1494,7 @@ static pa_bool_t check_name_to_skip(pa_stream_manager *m, process_command_type_t else role = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE); - if (role && pa_streq(role, "skip")) + if (role && pa_streq(role, SKIP_ROLE)) ret = TRUE; } @@ -1503,6 +1536,30 @@ static pa_bool_t check_route_type_to_skip(process_command_type_t command, const return ret; } +static pa_bool_t check_name_is_vstream(pa_stream_manager *m, process_command_type_t command, void *stream, stream_type_t type, pa_bool_t is_new_data) { + pa_bool_t ret = FALSE; + const char *name = NULL; + + pa_assert(m); + pa_assert(stream); + + if (command == PROCESS_COMMAND_PREPARE) { + if (is_new_data) + name = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_NAME); + else + name = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_NAME); + if (name) { + if (pa_streq(name, VIRTUAL_STREAM_NAME)) { + ret = TRUE; + pa_log_info("name is [%s]", name); + } + } + } else + pa_log_warn("not supported command(%d)", command); + + return ret; +} + static pa_bool_t update_priority_of_stream(pa_stream_manager *m, void *stream, stream_type_t type, const char *role, pa_bool_t is_new_data) { pa_bool_t ret = FALSE; stream_info *s = NULL; @@ -1566,7 +1623,7 @@ static pa_bool_t update_volume_type_of_stream(pa_stream_manager *m, void *stream static pa_bool_t update_focus_status_of_stream(pa_stream_manager *m, void *stream, stream_type_t type, pa_bool_t is_new_data) { const char *p_idx; - uint32_t parent_idx; + uint32_t parent_idx = 0; stream_parent *sp = NULL; pa_assert(m); @@ -1577,20 +1634,17 @@ static pa_bool_t update_focus_status_of_stream(pa_stream_manager *m, void *strea 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)) { - pa_log_debug("p_idx(%s), idx(%u)", p_idx, parent_idx); sp = pa_hashmap_get(m->stream_parents, (const void*)parent_idx); if (sp) { if (is_new_data) pa_proplist_setf(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_FOCUS_STATUS, "%u", sp->focus_status); else pa_proplist_setf(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_FOCUS_STATUS, "%u", sp->focus_status); + pa_log_debug("p_idx(%s), idx(%u), focus_status(0x%x, 0x1:playback 0x2:capture 0x3:both)", p_idx, parent_idx, sp->focus_status); } else { pa_log_error("could not find matching client for this parent_id(%u)", parent_idx); return FALSE; } - } else { - pa_log_warn("p_idx(%s) or idx(%u) is not valid", p_idx, parent_idx); - return FALSE; } return TRUE; @@ -1628,10 +1682,9 @@ static pa_bool_t update_stream_parent_info(pa_stream_manager *m, process_command pa_log_error("could not find matching client for this parent_id(%u)", parent_idx); return FALSE; } - } else { - pa_log_warn("p_idx(%s) or idx(%u) is not valid", p_idx, parent_idx); + } else return FALSE; - } + return TRUE; } @@ -1643,6 +1696,7 @@ static pa_bool_t update_the_highest_priority_stream(pa_stream_manager *m, proces const char *route_type_str = NULL; stream_route_type_t route_type; const char *focus_status_str = NULL; + const char *active_dev = NULL; void *cur_max_stream = NULL; void *cur_max_stream_tmp = NULL; const int32_t *cur_max_priority = NULL; @@ -1724,7 +1778,14 @@ static pa_bool_t update_the_highest_priority_stream(pa_stream_manager *m, proces *need_to_update = TRUE; pa_log_debug("update cur_highest to mine(%s)", role); } else { - /* no need to trigger */ + /* no need to trigger, + * update active device info if possible */ + if ((active_dev = pa_proplist_gets(GET_STREAM_PROPLIST(cur_max_stream, type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV))) { + if (is_new_data) + pa_proplist_sets(GET_STREAM_NEW_PROPLIST(mine, type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, active_dev); + else + pa_proplist_sets(GET_STREAM_PROPLIST(mine, type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, active_dev); + } return TRUE; } } @@ -1773,6 +1834,7 @@ static pa_bool_t update_the_highest_priority_stream(pa_stream_manager *m, proces cur_max_priority = priority; cur_max_focus_status = focus_status; cur_max_stream_tmp = i; + cur_max_role = _role; } if (cur_max_priority && priority) { if (IS_FOCUS_ACQUIRED(cur_max_focus_status, type) || @@ -1782,6 +1844,7 @@ static pa_bool_t update_the_highest_priority_stream(pa_stream_manager *m, proces cur_max_priority = priority; cur_max_focus_status = focus_status; cur_max_stream_tmp = i; + cur_max_role = _role; } } } @@ -1789,21 +1852,29 @@ static pa_bool_t update_the_highest_priority_stream(pa_stream_manager *m, proces if (cur_max_stream_tmp) { if (type == STREAM_SINK_INPUT) { m->cur_highest_priority.sink_input = cur_max_stream_tmp; + m->cur_highest_priority.role_si = cur_max_role; } else if (type == STREAM_SOURCE_OUTPUT) { m->cur_highest_priority.source_output = cur_max_stream_tmp; + m->cur_highest_priority.role_so = cur_max_role; } } else { if (type == STREAM_SINK_INPUT) { m->cur_highest_priority.sink_input = NULL; + m->cur_highest_priority.role_si = NULL; } else if (type == STREAM_SOURCE_OUTPUT) { m->cur_highest_priority.source_output = NULL; + m->cur_highest_priority.role_so = NULL; } } *need_to_update = TRUE; - pa_log_info("need to update: type(%d), cur_highest_priority(sink_input=%p/source_output=%p)", - type, (void*)m->cur_highest_priority.sink_input, (void*)m->cur_highest_priority.source_output); + pa_log_info("need to update: type(%d), cur_highest_priority(sink_input=%p[%s]/source_output=%p[%s])", + type, (void*)m->cur_highest_priority.sink_input, m->cur_highest_priority.role_si, + (void*)m->cur_highest_priority.source_output, m->cur_highest_priority.role_so); } else { /* no need to trigger */ + pa_log_info("no need to update: type(%d), cur_highest_priority(sink_input=%p[%s]/source_output=%p[%s])", + type, (void*)m->cur_highest_priority.sink_input, m->cur_highest_priority.role_si, + (void*)m->cur_highest_priority.source_output, m->cur_highest_priority.role_so); return TRUE; } } @@ -1928,6 +1999,7 @@ static void do_notify(pa_stream_manager *m, notify_command_type_t command, strea fill_device_info_to_hook_data(m, &hook_call_select_data, command, type, s, is_new_data); hook_call_select_data.sample_spec = GET_STREAM_NEW_SAMPLE_SPEC(s, type); if (type == STREAM_SINK_INPUT) { + hook_call_select_data.occupying_role = m->cur_highest_priority.role_si; hook_call_select_data.proper_sink = &(((pa_sink_input_new_data*)s)->sink); /* need to check modifier_gain, because we do not skip a stream that is from module-sound-player */ modifier_gain = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(s, type), PA_PROP_MEDIA_TIZEN_VOLUME_GAIN_TYPE); @@ -1937,6 +2009,7 @@ static void do_notify(pa_stream_manager *m, notify_command_type_t command, strea break; } } else if (type == STREAM_SOURCE_OUTPUT) { + hook_call_select_data.occupying_role = m->cur_highest_priority.role_si; hook_call_select_data.proper_source = &(((pa_source_output_new_data*)s)->source); if (((pa_source_output_new_data*)s)->source) { pa_log_info(" - source(%s) has been already selected, skip selecting source", @@ -1953,6 +2026,7 @@ static void do_notify(pa_stream_manager *m, notify_command_type_t command, strea else if (type == STREAM_SOURCE_OUTPUT) hook_call_select_data.proper_source = &(((pa_source_output*)s)->source); } + CONVERT_TO_DEVICE_ROLE(hook_call_select_data.stream_role, hook_call_select_data.device_role); pa_hook_fire(pa_communicator_hook(m->comm.comm, PA_COMMUNICATOR_HOOK_SELECT_INIT_SINK_OR_SOURCE), &hook_call_select_data); } break; @@ -1979,6 +2053,7 @@ static void do_notify(pa_stream_manager *m, notify_command_type_t command, strea } hook_call_route_data.stream_type = type; hook_call_route_data.stream_role = role; + CONVERT_TO_DEVICE_ROLE(hook_call_route_data.stream_role, hook_call_route_data.device_role); fill_device_info_to_hook_data(m, &hook_call_route_data, command, type, s, is_new_data); if (hook_call_route_data.route_type >= STREAM_ROUTE_TYPE_MANUAL) { if (hook_call_route_data.idx_manual_devices && !pa_idxset_size(hook_call_route_data.idx_manual_devices)) { @@ -1995,18 +2070,19 @@ static void do_notify(pa_stream_manager *m, notify_command_type_t command, strea s = (type == STREAM_SINK_INPUT) ? (void*)(m->cur_highest_priority.sink_input) : (void*)(m->cur_highest_priority.source_output); if (s) { - role = pa_proplist_gets(GET_STREAM_PROPLIST(s, type), PA_PROP_MEDIA_ROLE); hook_call_route_data.stream = s; hook_call_route_data.stream_type = type; - hook_call_route_data.stream_role = role; + hook_call_route_data.stream_role = (type == STREAM_SINK_INPUT) ? (m->cur_highest_priority.role_si) : + (m->cur_highest_priority.role_so); + CONVERT_TO_DEVICE_ROLE(hook_call_route_data.stream_role, hook_call_route_data.device_role); hook_call_route_data.sample_spec = GET_STREAM_SAMPLE_SPEC(s, type); hook_call_route_data.idx_streams = (type == STREAM_SINK_INPUT) ? ((pa_sink_input*)s)->sink->inputs : ((pa_source_output*)s)->source->outputs; fill_device_info_to_hook_data(m, &hook_call_route_data, command, type, s, is_new_data); } else { pa_log_info("no stream for this type(%d), need to unset route", type); + hook_call_route_data.stream = NULL; hook_call_route_data.stream_type = type; - hook_call_route_data.stream_role = "reset"; } pa_hook_fire(pa_communicator_hook(m->comm.comm, PA_COMMUNICATOR_HOOK_CHANGE_ROUTE), &hook_call_route_data); break; @@ -2017,8 +2093,8 @@ static void do_notify(pa_stream_manager *m, notify_command_type_t command, strea s = (type == STREAM_SINK_INPUT) ? (void*)(m->cur_highest_priority.sink_input) : (void*)(m->cur_highest_priority.source_output); if (s) { - role = pa_proplist_gets(GET_STREAM_PROPLIST(s, type), PA_PROP_MEDIA_ROLE); - hook_call_option_data.stream_role = role; + hook_call_option_data.stream_role = (type == STREAM_SINK_INPUT) ? (m->cur_highest_priority.role_si) : + (m->cur_highest_priority.role_so); hook_call_option_data.name = ((stream_route_option*)user_data)->name; hook_call_option_data.value = ((stream_route_option*)user_data)->value; pa_hook_fire(pa_communicator_hook(m->comm.comm, PA_COMMUNICATOR_HOOK_UPDATE_ROUTE_OPTION), &hook_call_option_data); @@ -2068,6 +2144,9 @@ static process_stream_result_t process_stream(pa_stream_manager *m, void *stream if (check_name_to_skip(m, command, stream, type, is_new_data)) { result = PROCESS_STREAM_RESULT_SKIP; + /* set it to null sink/source */ + if (is_new_data) + SET_NEW_DATA_STREAM_TO_NULL_SINK_SOURCE(m, stream, type); goto FAILURE; } @@ -2139,8 +2218,17 @@ static process_stream_result_t process_stream(pa_stream_manager *m, void *stream } } - /* notify to select sink or source */ - do_notify(m, NOTIFY_COMMAND_SELECT_PROPER_SINK_OR_SOURCE_FOR_INIT, type, TRUE, stream); + /* check if it is a virtual stream */ + if (check_name_is_vstream(m, command, stream, type, is_new_data)) { + pa_log_debug("skip notifying for selecting sink/source, rather set it to null sink/source"); + /* set it to null sink/source */ + if (is_new_data) + SET_NEW_DATA_STREAM_TO_NULL_SINK_SOURCE(m, stream, type); + + } else { + /* notify to select sink or source */ + do_notify(m, NOTIFY_COMMAND_SELECT_PROPER_SINK_OR_SOURCE_FOR_INIT, type, TRUE, stream); + } } else if (command == PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_STARTED) { if (is_new_data) { @@ -2197,10 +2285,13 @@ static process_stream_result_t process_stream(pa_stream_manager *m, void *stream m->cur_highest_priority.need_to_update_so = TRUE; } else { do_notify(m, NOTIFY_COMMAND_CHANGE_ROUTE_START, type, FALSE, stream); - if (type == STREAM_SINK_INPUT) + if (type == STREAM_SINK_INPUT) { m->cur_highest_priority.sink_input = stream; - else + m->cur_highest_priority.role_si = role; + } else { m->cur_highest_priority.source_output = stream; + m->cur_highest_priority.role_so = role; + } } } if (!is_new_data) @@ -2320,10 +2411,12 @@ static process_stream_result_t process_stream(pa_stream_manager *m, void *stream if (command == PROCESS_COMMAND_ADD_PARENT_ID) { if (type == STREAM_SINK_INPUT && m->cur_highest_priority.need_to_update_si) { m->cur_highest_priority.sink_input = stream; + m->cur_highest_priority.role_si = role; m->cur_highest_priority.need_to_update_si = FALSE; } if (type == STREAM_SOURCE_OUTPUT && m->cur_highest_priority.need_to_update_so) { m->cur_highest_priority.source_output = stream; + m->cur_highest_priority.role_so = role; m->cur_highest_priority.need_to_update_so = FALSE; } do_notify(m, NOTIFY_COMMAND_INFORM_STREAM_CONNECTED, type, FALSE, stream); @@ -2333,7 +2426,7 @@ static process_stream_result_t process_stream(pa_stream_manager *m, void *stream /* update parent stream info. */ ret = update_stream_parent_info(m, command, type, stream); if (ret == FALSE) { - pa_log_warn("could not update the parent information of this stream"); + pa_log_debug("could not update the parent information of this stream"); //return PROCESS_STREAM_RESULT_STOP; } } @@ -3045,7 +3138,7 @@ static void subscribe_cb(pa_core *core, pa_subscription_event_type_t t, uint32_t return; } name = pa_proplist_gets(client->proplist, PA_PROP_APPLICATION_NAME); - if (name && strncmp(name, STREAM_MANAGER_CLIENT_NAME, strlen(STREAM_MANAGER_CLIENT_NAME))) { + if (name && !pa_streq(name, STREAM_MANAGER_CLIENT_NAME)) { pa_log_warn(" - this is not a client(%s) that we should take care of, skip it", name); return; } diff --git a/src/stream-manager.h b/src/stream-manager.h index 93b3c3d..c63e2da 100644 --- a/src/stream-manager.h +++ b/src/stream-manager.h @@ -14,6 +14,10 @@ #define GET_STREAM_PROPLIST(stream, type) \ (type == STREAM_SINK_INPUT ? ((pa_sink_input*)stream)->proplist : ((pa_source_output*)stream)->proplist) +#define STREAM_ROLE_CALL_VOICE "call-voice" +#define STREAM_ROLE_CALL_VIDEO "call-video" +#define STREAM_ROLE_VOIP "voip" + #define SINK_NAME_COMBINED "sink_combined" #define SINK_NAME_NULL "sink_null" #define SOURCE_NAME_NULL "source_null" @@ -36,6 +40,8 @@ typedef enum stream_route_type { typedef struct _hook_call_data_for_select { void *stream; const char *stream_role; + const char *device_role; + const char *occupying_role; stream_type_t stream_type; stream_route_type_t route_type; pa_sink **proper_sink; @@ -49,6 +55,7 @@ typedef struct _hook_call_data_for_select { typedef struct _hook_call_data_for_route { void *stream; const char *stream_role; + const char *device_role; stream_type_t stream_type; stream_route_type_t route_type; pa_sink **proper_sink; -- 2.7.4 From 47d98c058ba4994e9305cc08ecb82ea7bee34894 Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Thu, 7 Jan 2016 13:43:01 +0900 Subject: [PATCH 16/16] stream-manager/hal-manager: Support forwarding message from audio-hal Some audio-hal has to communicate with other frameworks/daemons. If stream-manager gets the notification from hal-manager, it would send dbus signal. Modify AUDIO_ERR_NOT_IMPLEMENTED value to 0x80001100. [Version] 5.0.28 [Profile] Common [Issue Type] Feature Enhancement Change-Id: Icad17ed97fb3c31510be5257b4179fcaea162ae6 --- packaging/pulseaudio-modules-tizen.spec | 2 +- src/hal-manager.c | 19 ++++++ src/hal-manager.h | 3 + src/stream-manager.c | 103 ++++++++++++++++++++++++-------- src/tizen-audio.h | 13 +++- 5 files changed, 112 insertions(+), 28 deletions(-) diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index 7828e1a..aa047ce 100644 --- a/packaging/pulseaudio-modules-tizen.spec +++ b/packaging/pulseaudio-modules-tizen.spec @@ -1,6 +1,6 @@ Name: pulseaudio-modules-tizen Summary: Pulseaudio modules for Tizen -Version: 5.0.27 +Version: 5.0.28 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/hal-manager.c b/src/hal-manager.c index 64888d8..903d3c9 100644 --- a/src/hal-manager.c +++ b/src/hal-manager.c @@ -79,6 +79,7 @@ pa_hal_manager* pa_hal_manager_get(pa_core *core) { h->intf.pcm_recover = dlsym(h->dl_handle, "audio_pcm_recover"); h->intf.pcm_get_params = dlsym(h->dl_handle, "audio_pcm_get_params"); h->intf.pcm_set_params = dlsym(h->dl_handle, "audio_pcm_set_params"); + h->intf.set_message_cb = dlsym(h->dl_handle, "audio_set_message_cb"); if (h->intf.init) { if (h->intf.init(&h->ah_handle) != AUDIO_RET_OK) pa_log_error("hal_manager init failed"); @@ -469,3 +470,21 @@ int32_t pa_hal_manager_pcm_set_params(pa_hal_manager *h, pcm_handle pcm_h, uint3 } return ret; } + +int32_t pa_hal_manager_set_messsage_callback(pa_hal_manager *h, hal_message_callback callback, void *user_data) { + int32_t ret = 0; + audio_return_t hal_ret = AUDIO_RET_OK; + + pa_assert(h); + pa_assert(callback); + + if (h->intf.set_message_cb == NULL) { + pa_log_error("there is no set_message_cb symbol in this audio hal"); + ret = -1; + } else if (AUDIO_IS_ERROR((hal_ret = h->intf.set_message_cb(h->ah_handle, (message_cb)callback, user_data)))) { + pa_log_error("set_message_cb returns error:0x%x", hal_ret); + ret = -1; + } + + return ret; +} diff --git a/src/hal-manager.h b/src/hal-manager.h index 5d445cc..583e6ca 100644 --- a/src/hal-manager.h +++ b/src/hal-manager.h @@ -43,6 +43,8 @@ typedef struct _hal_stream_info { typedef void* pcm_handle; +typedef void (*hal_message_callback)(const char *name, int value, void *user_data); + pa_hal_manager* pa_hal_manager_get(pa_core *core); pa_hal_manager* pa_hal_manager_ref(pa_hal_manager *h); void pa_hal_manager_unref(pa_hal_manager *h); @@ -67,5 +69,6 @@ int32_t pa_hal_manager_pcm_get_fd(pa_hal_manager *h, pcm_handle pcm_h, int *fd); int32_t pa_hal_manager_pcm_recover(pa_hal_manager *h, pcm_handle pcm_h, int err); int32_t pa_hal_manager_pcm_get_params(pa_hal_manager *h, pcm_handle pcm_h, uint32_t direction, void **sample_spec, uint32_t *period_size, uint32_t *periods); int32_t pa_hal_manager_pcm_set_params(pa_hal_manager *h, pcm_handle pcm_h, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods); +int32_t pa_hal_manager_set_messsage_callback(pa_hal_manager *h, hal_message_callback callback, void *user_data); #endif diff --git a/src/stream-manager.c b/src/stream-manager.c index fd8eb83..6f54f7c 100644 --- a/src/stream-manager.c +++ b/src/stream-manager.c @@ -49,6 +49,7 @@ #define ARR_ARG_MAX 32 #define STREAM_MANAGER_OBJECT_PATH "/org/pulseaudio/StreamManager" #define STREAM_MANAGER_INTERFACE "org.pulseaudio.StreamManager" +/* method */ #define STREAM_MANAGER_METHOD_NAME_GET_STREAM_INFO "GetStreamInfo" #define STREAM_MANAGER_METHOD_NAME_GET_STREAM_LIST "GetStreamList" #define STREAM_MANAGER_METHOD_NAME_SET_STREAM_ROUTE_DEVICES "SetStreamRouteDevices" @@ -60,6 +61,9 @@ #define STREAM_MANAGER_METHOD_NAME_GET_VOLUME_MUTE "GetVolumeMute" #define STREAM_MANAGER_METHOD_NAME_GET_CURRENT_VOLUME_TYPE "GetCurrentVolumeType" /* the type that belongs to the stream of the current max priority */ #define STREAM_MANAGER_METHOD_NAME_UPDATE_FOCUS_STATUS "UpdateFocusStatus" +/* signal */ +#define STREAM_MANAGER_SIGNAL_NAME_VOLUME_CHANGED "VolumeChanged" +#define STREAM_MANAGER_SIGNAL_NAME_COMMAND "Command" static DBusHandlerResult method_handler_for_vt(DBusConnection *c, DBusMessage *m, void *userdata); static DBusHandlerResult handle_introspect(DBusConnection *conn, DBusMessage *msg, void *userdata); @@ -75,6 +79,8 @@ static void handle_set_volume_mute(DBusConnection *conn, DBusMessage *msg, void static void handle_get_volume_mute(DBusConnection *conn, DBusMessage *msg, void *userdata); static void handle_get_current_volume_type(DBusConnection *conn, DBusMessage *msg, void *userdata); static void handle_update_focus_status(DBusConnection *conn, DBusMessage *msg, void *userdata); +static void send_volume_changed_signal(DBusConnection *conn, const char *direction, const char *volume_type, const uint32_t volume_level); +static void send_command_signal(DBusConnection *conn, const char *name, int value); enum method_handler_index { METHOD_HANDLER_GET_STREAM_INFO, @@ -286,6 +292,15 @@ static pa_dbus_interface_info stream_manager_interface_info = { " " \ " " \ " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ " " \ " " \ " " \ @@ -797,27 +812,6 @@ static void handle_set_stream_route_option(DBusConnection *conn, DBusMessage *ms return; } -static void send_volume_changed_signal(DBusConnection *conn, const char *direction, const char *volume_type, const uint32_t volume_level) { - DBusMessage *signal_msg; - DBusMessageIter msg_iter; - - pa_assert(conn); - pa_assert(volume_type); - - pa_log_debug("Send volume changed signal : direction %s, type %s, level %d", direction, volume_type, volume_level); - - pa_assert_se(signal_msg = dbus_message_new_signal(STREAM_MANAGER_OBJECT_PATH, STREAM_MANAGER_INTERFACE, "VolumeChanged")); - dbus_message_iter_init_append(signal_msg, &msg_iter); - - dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_STRING, &direction); - dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_STRING, &volume_type); - dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_UINT32, &volume_level); - - pa_assert_se(dbus_connection_send(conn, signal_msg, NULL)); - dbus_message_unref(signal_msg); - return; -} - static void handle_set_volume_level(DBusConnection *conn, DBusMessage *msg, void *userdata) { const char *direction = NULL; const char *type = NULL; @@ -846,6 +840,7 @@ static void handle_set_volume_level(DBusConnection *conn, DBusMessage *msg, void stream_type = STREAM_SINK_INPUT; else { pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[RET_MSG_INDEX_ERROR], DBUS_TYPE_INVALID)); + ret = -1; goto FAILURE; } @@ -860,6 +855,7 @@ FAILURE: if (!ret) send_volume_changed_signal(conn, direction, type, level); + return; } @@ -1190,6 +1186,47 @@ static DBusHandlerResult method_handler_for_vt(DBusConnection *c, DBusMessage *m return DBUS_HANDLER_RESULT_HANDLED; } + +static void send_volume_changed_signal(DBusConnection *conn, const char *direction, const char *volume_type, const uint32_t volume_level) { + DBusMessage *signal_msg; + DBusMessageIter msg_iter; + + pa_assert(conn); + pa_assert(direction); + pa_assert(volume_type); + + pa_log_debug("Send volume changed signal: direction(%s), type(%s), level(%d)", direction, volume_type, volume_level); + + pa_assert_se(signal_msg = dbus_message_new_signal(STREAM_MANAGER_OBJECT_PATH, STREAM_MANAGER_INTERFACE, STREAM_MANAGER_SIGNAL_NAME_VOLUME_CHANGED)); + dbus_message_iter_init_append(signal_msg, &msg_iter); + + dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_STRING, &direction); + dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_STRING, &volume_type); + dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_UINT32, &volume_level); + + pa_assert_se(dbus_connection_send(conn, signal_msg, NULL)); + dbus_message_unref(signal_msg); + return; +} + +static void send_command_signal(DBusConnection *conn, const char *name, int value) { + DBusMessage *signal_msg; + DBusMessageIter msg_iter; + + pa_assert(conn); + pa_assert(name); + + pa_log_debug("Send command signal: name(%s), value(%d)", name, value); + + pa_assert_se(signal_msg = dbus_message_new_signal(STREAM_MANAGER_OBJECT_PATH, STREAM_MANAGER_INTERFACE, STREAM_MANAGER_SIGNAL_NAME_COMMAND)); + dbus_message_iter_init_append(signal_msg, &msg_iter); + + dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_STRING, &name); + dbus_message_iter_append_basic(&msg_iter, DBUS_TYPE_INT32, &value); + + pa_assert_se(dbus_connection_send(conn, signal_msg, NULL)); + dbus_message_unref(signal_msg); +} #endif static int convert_route_type(stream_route_type_t *route_type, const char *route_type_string) { @@ -3128,6 +3165,7 @@ static void subscribe_cb(pa_core *core, pa_subscription_event_type_t t, uint32_t const char *name = NULL; uint32_t *device_id = NULL; uint32_t _idx = 0; + pa_core_assert_ref(core); pa_assert(m); @@ -3176,11 +3214,25 @@ static void subscribe_cb(pa_core *core, pa_subscription_event_type_t t, uint32_t } } -static int init_ipc(pa_stream_manager *m) { +static void message_cb(const char *name, int value, void *user_data) { + pa_stream_manager *m; + + pa_assert(user_data); + + m = (pa_stream_manager*)user_data; + #ifdef HAVE_DBUS -#ifdef USE_DBUS_PROTOCOL + send_command_signal(pa_dbus_connection_get(m->dbus_conn), name, value); +#endif + + return; +} + +static int init_ipc(pa_stream_manager *m) { pa_assert(m); pa_log_info("Initialization for IPC"); +#ifdef HAVE_DBUS +#ifdef USE_DBUS_PROTOCOL m->dbus_protocol = pa_dbus_protocol_get(m->core); pa_assert_se(pa_dbus_protocol_add_interface(m->dbus_protocol, STREAM_MANAGER_OBJECT_PATH, &stream_manager_interface_info, m) >= 0); pa_assert_se(pa_dbus_protocol_register_extension(m->dbus_protocol, STREAM_MANAGER_INTERFACE) >= 0); @@ -3191,9 +3243,6 @@ static int init_ipc(pa_stream_manager *m) { .message_function = method_handler_for_vt, }; - pa_assert(m); - pa_log_info("Initialization for IPC"); - dbus_error_init(&err); if (!(conn = pa_dbus_bus_get(m->core, DBUS_BUS_SYSTEM, &err)) || dbus_error_is_set(&err)) { @@ -3276,6 +3325,8 @@ pa_stream_manager* pa_stream_manager_init(pa_core *c) { m->core = c; m->hal = pa_hal_manager_get(c); + if (pa_hal_manager_set_messsage_callback(m->hal, message_cb, m)) + pa_log_warn("skip setting message callback"); m->dm = pa_device_manager_get(c); #ifdef HAVE_DBUS diff --git a/src/tizen-audio.h b/src/tizen-audio.h index ce95101..2c513c3 100644 --- a/src/tizen-audio.h +++ b/src/tizen-audio.h @@ -30,7 +30,10 @@ typedef enum audio_return { AUDIO_ERR_RESOURCE = (int32_t)0x80001001, AUDIO_ERR_PARAMETER = (int32_t)0x80001002, AUDIO_ERR_IOCTL = (int32_t)0x80001003, - AUDIO_ERR_NOT_IMPLEMENTED = (int32_t)0x80001004, + AUDIO_ERR_INVALID_STATE = (int32_t)0x80001004, + AUDIO_ERR_INTERNAL = (int32_t)0x80001005, + + AUDIO_ERR_NOT_IMPLEMENTED = (int32_t)0x80001100, } audio_return_t ; typedef enum audio_direction { @@ -68,19 +71,24 @@ typedef struct audio_stream_info { uint32_t idx; } audio_stream_info_t ; +typedef void (*message_cb)(const char *name, int value, void *user_data); + /* Overall */ typedef struct audio_interface { audio_return_t (*init)(void **audio_handle); audio_return_t (*deinit)(void *audio_handle); + /* Volume */ audio_return_t (*get_volume_level_max)(void *audio_handle, audio_volume_info_t *info, uint32_t *level); audio_return_t (*get_volume_level)(void *audio_handle, audio_volume_info_t *info, uint32_t *level); audio_return_t (*set_volume_level)(void *audio_handle, audio_volume_info_t *info, uint32_t level); audio_return_t (*get_volume_value)(void *audio_handle, audio_volume_info_t *info, uint32_t level, double *value); audio_return_t (*get_volume_mute)(void *audio_handle, audio_volume_info_t *info, uint32_t *mute); audio_return_t (*set_volume_mute)(void *audio_handle, audio_volume_info_t *info, uint32_t mute); + /* Routing */ audio_return_t (*do_route)(void *audio_handle, audio_route_info_t *info); audio_return_t (*update_route_option)(void *audio_handle, audio_route_option_t *option); audio_return_t (*update_stream_connection_info) (void *audio_handle, audio_stream_info_t *info, uint32_t is_connected); + /* Buffer Attribute */ audio_return_t (*get_buffer_attr)(void *audio_handle, uint32_t direction, const char *latency, uint32_t samplerate, int format, uint32_t channels, uint32_t *maxlength, uint32_t *tlength, uint32_t *prebuf, uint32_t* minreq, uint32_t *fragsize); /* Interface of PCM device */ @@ -95,6 +103,8 @@ typedef struct audio_interface { audio_return_t (*pcm_recover)(void *audio_handle, void *pcm_handle, int revents); audio_return_t (*pcm_get_params)(void *audio_handle, void *pcm_handle, uint32_t direction, void **sample_spec, uint32_t *period_size, uint32_t *periods); audio_return_t (*pcm_set_params)(void *audio_handle, void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods); + /* Message callback */ + audio_return_t (*set_message_cb)(void *audio_handle, message_cb callback, void *user_data); } audio_interface_t; audio_return_t audio_init(void **audio_handle); @@ -121,4 +131,5 @@ audio_return_t audio_pcm_get_fd(void *audio_handle, void *pcm_handle, int *fd); audio_return_t audio_pcm_recover(void *audio_handle, void *pcm_handle, int revents); audio_return_t audio_pcm_get_params(void *audio_handle, void *pcm_handle, uint32_t direction, void **sample_spec, uint32_t *period_size, uint32_t *periods); audio_return_t audio_pcm_set_params(void *audio_handle, void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods); +audio_return_t audio_set_message_cb(void *audio_handle, message_cb callback, void *user_data); #endif -- 2.7.4