From: Sangchul Lee Date: Mon, 17 Jun 2019 05:13:40 +0000 (+0900) Subject: tizen-device: Introduce default sink/source of device_get_sink/source() X-Git-Tag: submit/tizen/20190619.053430~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=74dbb9c47eb86005c673029abe4fa312f134862c;p=platform%2Fcore%2Fmultimedia%2Fpulseaudio-modules-tizen.git tizen-device: Introduce default sink/source of device_get_sink/source() If these two functions are invoked with 'NULL' role parameter, it will return the first sink/source of its device hashmap list. [Version] 11.1.51 [Issue type] Improvement Change-Id: I5b42c4dd536b3962af42294955481ff8e6639305 Signed-off-by: Sangchul Lee --- diff --git a/packaging/pulseaudio-modules-tizen.spec b/packaging/pulseaudio-modules-tizen.spec index b68e0b6..f13b60c 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: 11.1.50 +Version: 11.1.51 Release: 0 Group: Multimedia/Audio License: LGPL-2.1+ diff --git a/src/device-manager.c b/src/device-manager.c index f801e53..b2e377b 100644 --- a/src/device-manager.c +++ b/src/device-manager.c @@ -1815,7 +1815,7 @@ static pa_tz_device* _load_forwarding_device(pa_device_manager *dm) { return NULL; } - if ((spk_sink = pa_tz_device_get_sink(spk_device, DEVICE_ROLE_NORMAL)) == NULL) { + if ((spk_sink = pa_tz_device_get_sink(spk_device, NULL)) == NULL) { pa_log_error("Get speaker sink failed"); return NULL; } diff --git a/src/module-tizenaudio-policy.c b/src/module-tizenaudio-policy.c index 58540c2..674b0c3 100644 --- a/src/module-tizenaudio-policy.c +++ b/src/module-tizenaudio-policy.c @@ -813,12 +813,12 @@ static pa_hook_result_t select_proper_sink_or_source_hook_cb(pa_core *c, pa_stre /* currently, we support two sinks for combining */ if (data->stream_type == STREAM_SINK_INPUT) { if (!combine_sink_arg1) { - if ((sink = combine_sink_arg1 = pa_tz_device_get_sink(device, DEVICE_ROLE_NORMAL))) + if ((sink = combine_sink_arg1 = pa_tz_device_get_sink(device, NULL))) pa_log_info(" -- combine_sink_arg1[%s], combine_sink_arg2[%p]", sink->name, combine_sink_arg2); else pa_log_warn(" -- could not get combine_sink_arg1"); } else if (!combine_sink_arg2) { - sink = combine_sink_arg2 = pa_tz_device_get_sink(device, DEVICE_ROLE_NORMAL); + sink = combine_sink_arg2 = pa_tz_device_get_sink(device, NULL); if (sink && !pa_safe_streq(sink->name, combine_sink_arg1->name)) { uint32_t s_idx = 0; @@ -850,7 +850,7 @@ static pa_hook_result_t select_proper_sink_or_source_hook_cb(pa_core *c, pa_stre } } else if (data->stream_type == STREAM_SOURCE_OUTPUT) { - if ((source = pa_tz_device_get_source(device, DEVICE_ROLE_NORMAL))) { + if ((source = pa_tz_device_get_source(device, NULL))) { if (data->origins_from_new_data) *(data->proper_source) = source; else { @@ -940,7 +940,7 @@ static void route_change_move_streams(struct userdata *u, pa_stream_manager_hook CONVERT_TO_DEVICE_ROLE(data->stream_role, device_role); pa_log_info("[ROUTE][MOVE] stream_role[%s], device role[%s]", data->stream_role, device_role); if (data->stream_type == STREAM_SINK_INPUT) { - if (!(sink = pa_tz_device_get_sink(device, DEVICE_ROLE_NORMAL)) || + if (!(sink = pa_tz_device_get_sink(device, NULL)) || !(dst_sink = pa_tz_device_get_sink(device, device_role)) || sink == dst_sink) { pa_log_info("[ROUTE][MOVE][%s] no need to move streams, sink(%p), dst_sink(%p)", data->stream_role, sink, dst_sink); @@ -948,7 +948,7 @@ static void route_change_move_streams(struct userdata *u, pa_stream_manager_hook } streams = sink->inputs; } else if (data->stream_type == STREAM_SOURCE_OUTPUT) { - if (!(source = pa_tz_device_get_source(device, DEVICE_ROLE_NORMAL)) || + if (!(source = pa_tz_device_get_source(device, NULL)) || !(dst_source = pa_tz_device_get_source(device, device_role)) || source == dst_source) { pa_log_info("[ROUTE][MOVE][%s] no need to move streams, source(%p), dst_source(%p)", data->stream_role, source, dst_source); @@ -1360,9 +1360,9 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_ /* Check for in/out devices in case of loopback */ if (pa_safe_streq(data->stream_role, STREAM_ROLE_LOOPBACK)) { if ((data->stream_type == STREAM_SINK_INPUT) && (dm_device_direction & DM_DEVICE_DIRECTION_OUT)) - u->loopback_args.sink = pa_tz_device_get_sink(device, DEVICE_ROLE_NORMAL); + u->loopback_args.sink = pa_tz_device_get_sink(device, NULL); else if ((data->stream_type == STREAM_SOURCE_OUTPUT) && (dm_device_direction & DM_DEVICE_DIRECTION_IN)) - u->loopback_args.source = pa_tz_device_get_source(device, DEVICE_ROLE_NORMAL); + u->loopback_args.source = pa_tz_device_get_source(device, NULL); } if (IS_AVAILABLE_DIRECTION(data->stream_type, dm_device_direction)) { @@ -1486,7 +1486,7 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_tz_devi device_direction = pa_tz_device_get_direction(device); if (device_direction == DM_DEVICE_DIRECTION_OUT) { if ((use_internal_codec = pa_tz_device_is_use_internal_codec(device))) { - sink = pa_tz_device_get_sink(device, DEVICE_ROLE_NORMAL); + sink = pa_tz_device_get_sink(device, NULL); break; } } @@ -1498,13 +1498,13 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_tz_devi /* unload loopback module */ if (u->module_loopback) - if (u->loopback_args.sink == pa_tz_device_get_sink(conn->device, DEVICE_ROLE_NORMAL)) + if (u->loopback_args.sink == pa_tz_device_get_sink(conn->device, NULL)) update_loopback_module(u, false); } if (device_direction & DM_DEVICE_DIRECTION_IN) { /* unload loopback module */ if (u->module_loopback) - if (u->loopback_args.source == pa_tz_device_get_source(conn->device, DEVICE_ROLE_NORMAL)) + if (u->loopback_args.source == pa_tz_device_get_source(conn->device, NULL)) update_loopback_module(u, false); } } diff --git a/src/stream-manager.c b/src/stream-manager.c index 370b770..6574b31 100644 --- a/src/stream-manager.c +++ b/src/stream-manager.c @@ -2461,13 +2461,13 @@ static void process_stream_as_device_change_for_auto_route(pa_stream_manager *m, device_type = pa_tz_device_get_type(device); if (stream_type == STREAM_SINK_INPUT) { pa_sink *sink; - if ((sink = pa_tz_device_get_sink(device, DEVICE_ROLE_NORMAL))) + if ((sink = pa_tz_device_get_sink(device, NULL))) use_internal_codec = sink->use_internal_codec; else pa_log_warn("sink is null"); } else { pa_source *source; - if ((source = pa_tz_device_get_source(device, DEVICE_ROLE_NORMAL))) + if ((source = pa_tz_device_get_source(device, NULL))) use_internal_codec = source->use_internal_codec; else pa_log_warn("source is null"); @@ -2527,11 +2527,11 @@ static bool manage_filter_apply_stream(pa_stream_manager *m, pa_sink_input *si, const char *cur_device_type = pa_proplist_gets(si->proplist, PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV); char *device_type = pa_tz_device_get_type(device); pa_tz_device *cur_device = pa_device_manager_get_device(m->dm, cur_device_type); - pa_sink *sink = pa_tz_device_get_sink(device, DEVICE_ROLE_NORMAL); + pa_sink *sink = pa_tz_device_get_sink(device, NULL); if (is_connected) { bool available = false; - pa_sink *cur_sink = pa_tz_device_get_sink(cur_device, DEVICE_ROLE_NORMAL); + pa_sink *cur_sink = pa_tz_device_get_sink(cur_device, NULL); if (cur_sink == sink) return true; @@ -2551,7 +2551,7 @@ static bool manage_filter_apply_stream(pa_stream_manager *m, pa_sink_input *si, pa_sink *cur_sink = NULL; if (cur_device) - cur_sink = pa_tz_device_get_sink(cur_device, DEVICE_ROLE_NORMAL); + cur_sink = pa_tz_device_get_sink(cur_device, NULL); if (cur_sink && (cur_sink != sink)) return true; @@ -2562,7 +2562,7 @@ static bool manage_filter_apply_stream(pa_stream_manager *m, pa_sink_input *si, pa_log_error("failed to get next_device"); return true; } - next_sink = pa_tz_device_get_sink(next_device, DEVICE_ROLE_NORMAL); + next_sink = pa_tz_device_get_sink(next_device, NULL); if (!reload_filter(m, stream_role, next_sink)) { new_device_type = pa_tz_device_get_type(next_device); pa_proplist_sets(si->proplist, PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, new_device_type); @@ -2620,9 +2620,9 @@ static void update_sink_or_source_as_device_change(pa_stream_manager *m, stream_ pa_log_debug("[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_tz_device_get_sink(device, DEVICE_ROLE_NORMAL); + sink = pa_tz_device_get_sink(device, NULL); else - source = pa_tz_device_get_source(device, DEVICE_ROLE_NORMAL); + source = pa_tz_device_get_source(device, NULL); PA_IDXSET_FOREACH(s, streams, s_idx) { /* streams: core->source_outputs/core->sink_inputs */ if (get_route_type(s, stream_type, false, &route_type)) @@ -2679,7 +2679,7 @@ static void update_sink_or_source_as_device_change(pa_stream_manager *m, stream_ continue; find_next_device_for_auto_route(m, route_type, role, stream_type, device_type, &next_device); if (next_device) { - if ((next_sink = pa_tz_device_get_sink(next_device, DEVICE_ROLE_NORMAL))) { + if ((next_sink = pa_tz_device_get_sink(next_device, NULL))) { new_device_type = pa_tz_device_get_type(next_device); /* update activated device */ pa_proplist_sets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, new_device_type); @@ -2708,7 +2708,7 @@ static void update_sink_or_source_as_device_change(pa_stream_manager *m, stream_ continue; find_next_device_for_auto_route(m, route_type, role, stream_type, device_type, &next_device); if (next_device) { - if ((next_source = pa_tz_device_get_source(next_device, DEVICE_ROLE_NORMAL))) { + if ((next_source = pa_tz_device_get_source(next_device, NULL))) { new_device_type = pa_tz_device_get_type(next_device); /* update activated device */ pa_proplist_sets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, new_device_type); @@ -2932,7 +2932,7 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_tz_devi const char *media_role = NULL; hal_route_option route_option; - if ((sink = pa_tz_device_get_sink(data->device, DEVICE_ROLE_NORMAL))) { + if ((sink = pa_tz_device_get_sink(data->device, NULL))) { pa_idxset *filtered_streams = get_streams_for_matching_active_device(sink->inputs, device_type); mute_sink_inputs_as_device_disconnection(m, data->event_id, true, filtered_streams); pa_xfree(filtered_streams); @@ -2958,12 +2958,12 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_tz_devi /* Update streams belong to this external device that have MAUAL_EXT route type */ if (!use_internal_codec) { if (device_direction & DM_DEVICE_DIRECTION_IN) { - if ((source = pa_tz_device_get_source(data->device, DEVICE_ROLE_NORMAL))) + if ((source = pa_tz_device_get_source(data->device, NULL))) update_sink_or_source_as_device_change(m, STREAM_ROUTE_TYPE_MANUAL_EXT, source->outputs, STREAM_SOURCE_OUTPUT, data->device, data->is_connected); } if (device_direction & DM_DEVICE_DIRECTION_OUT) { - if ((sink = pa_tz_device_get_sink(data->device, DEVICE_ROLE_NORMAL))) + if ((sink = pa_tz_device_get_sink(data->device, NULL))) update_sink_or_source_as_device_change(m, STREAM_ROUTE_TYPE_MANUAL_EXT, sink->inputs, STREAM_SINK_INPUT, data->device, data->is_connected); } diff --git a/src/stream-manager.h b/src/stream-manager.h index 55f2572..8221dee 100644 --- a/src/stream-manager.h +++ b/src/stream-manager.h @@ -70,7 +70,7 @@ do { \ else if (pa_safe_streq(x_stream_role, STREAM_ROLE_VOIP)) \ x_device_role = DEVICE_ROLE_VOIP; \ else \ - x_device_role = DEVICE_ROLE_NORMAL; \ + x_device_role = NULL; \ } while (0) #define GET_STREAM_NEW_PROPLIST(stream, type) \ diff --git a/src/tizen-device.c b/src/tizen-device.c index d561d00..9ea1490 100644 --- a/src/tizen-device.c +++ b/src/tizen-device.c @@ -336,6 +336,16 @@ static pa_sink* device_get_sink(pa_tz_device *device, const char *role) { pa_assert(device); pa_assert(device->playback_devices); + /* If the role is null, it returns the first one. We consider it as default sink + * until the default value is newly defined in device-map.json later on. */ + if (!role) { + if ((sink = pa_hashmap_first(device->playback_devices)) == NULL) { + pa_log_warn("Failed to get sink for default"); + return NULL; + } + return sink; + } + if ((sink = pa_hashmap_get(device->playback_devices, role)) == NULL) { pa_log_warn("Failed to get sink for %s", role); return NULL; @@ -349,6 +359,16 @@ static pa_source* device_get_source(pa_tz_device *device, const char *role) { pa_assert(device); pa_assert(device->capture_devices); + /* If the role is null, it returns the first one. We consider it as default source + * until the default value is newly defined in device-map.json later on. */ + if (!role) { + if ((source = pa_hashmap_first(device->capture_devices)) == NULL) { + pa_log_warn("Failed to get source for default"); + return NULL; + } + return source; + } + if ((source = pa_hashmap_get(device->capture_devices, role)) == NULL) { pa_log_warn("Failed to get source for %s", role); return NULL; @@ -477,9 +497,9 @@ pa_tz_device* pa_tz_device_new(pa_tz_device_new_data *data) { device->specified_stream_role = pa_xstrdup("none"); if (device_type_is_use_external_card(device->type)) { - if ((sink = device_get_sink(device, DEVICE_ROLE_NORMAL))) + if ((sink = device_get_sink(device, NULL))) sink->device_item = device; - if ((source = device_get_source(device, DEVICE_ROLE_NORMAL))) + if ((source = device_get_source(device, NULL))) source->device_item = device; }