stream-manager: Revise decision condition which stream should be muted 87/116087/4 accepted/tizen/3.0/common/20170302.075700 accepted/tizen/3.0/ivi/20170302.034035 accepted/tizen/3.0/mobile/20170302.033917 accepted/tizen/3.0/tv/20170302.033954 accepted/tizen/3.0/wearable/20170302.034014 submit/tizen_3.0/20170223.055304 submit/tizen_3.0/20170228.000412
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 23 Feb 2017 00:27:27 +0000 (09:27 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 23 Feb 2017 05:39:49 +0000 (14:39 +0900)
If a stream that has an active device type same as the current disconnecting device type, it'll be choosen for muting/unmuting target.

[Version] 5.0.136
[Profile] Common
[Issue Type] Bug fix

Change-Id: I8f686206217f8cafbdf706a6d2904faec1d03bc1
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/pulseaudio-modules-tizen.spec
src/stream-manager.c

index c1fe629..5fb5646 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          5.0.135
+Version:          5.0.136
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index f667b79..fbafbbb 100644 (file)
@@ -3457,7 +3457,7 @@ static void find_next_device_for_auto_route(pa_stream_manager *m, stream_route_t
             }
         }
         *next_device = latest_device;
-        pa_log_debug("found next device[%s, %p], creation_time[%llu]", device_type, *next_device, latest_creation_time);
+        pa_log_debug("found next device[%p], creation_time[%llu]", *next_device, latest_creation_time);
     }
 
     pa_log_debug("next_device is [%p] for role[%s]/route_type[%d]/stream_type[%d]", *next_device, role, route_type, stream_type);
@@ -3509,6 +3509,21 @@ static void is_available_device_for_auto_route(pa_stream_manager *m, stream_rout
     pa_log_debug("is new_device[%s] available for role[%s]/stream_type[%d]:%d", new_device_type, role, stream_type, *available);
 }
 
+static bool is_active_device_of_stream(const void *stream, stream_type_t stream_type, const char *device_type) {
+    const char *active_dev;
+
+    pa_assert(stream);
+    pa_assert(device_type);
+
+    active_dev = pa_proplist_gets(GET_STREAM_PROPLIST(stream, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV);
+    if (pa_safe_streq(active_dev, device_type)) {
+        pa_log_info("stream(%p)'s active_dev(%s) is same as device_type(%s)", stream, active_dev, device_type);
+        return true;
+    }
+
+    return false;
+}
+
 /* Re-trigger for routing update for streams using auto route type */
 static void process_stream_as_device_change_for_auto_route(pa_stream_manager *m, void *stream, stream_type_t stream_type,
                                                            bool is_connected, bool use_internal_codec) {
@@ -3626,6 +3641,8 @@ static void update_sink_or_source_as_device_change(stream_route_type_t stream_ro
                 } else if (!is_connected) {
                     /* DISCONNECTED: find a connected device that has the next priority */
                     if ((sink && (sink == ((pa_sink_input*)s)->sink))) {
+                        if (!is_active_device_of_stream(s, stream_type, device_type))
+                            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))) {
@@ -3650,6 +3667,8 @@ static void update_sink_or_source_as_device_change(stream_route_type_t stream_ro
                         }
 
                     } else if (source && (source == ((pa_source_output*)s)->source)) {
+                        if (!is_active_device_of_stream(s, stream_type, device_type))
+                            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))) {
@@ -3725,18 +3744,12 @@ static void apply_volume_factor_to_streams(pa_idxset *all_streams, pa_idxset **a
     pa_assert(all_streams);
     pa_assert(applied_streams);
 
-    pa_log_debug("apply_volume_factor_to_streams is called");
+    pa_log_info("apply_volume_factor_to_streams is called");
 
     vol.channels = 1;
     pa_parse_volume("0%", &vol.values[0]);
     *applied_streams = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
     PA_IDXSET_FOREACH(i, all_streams, idx) {
-        stream_route_type_t route_type = STREAM_ROUTE_TYPE_AUTO;
-        /* skip in case of auto-all type or manual-ext type */
-        if (!get_route_type(i, STREAM_SINK_INPUT, false, &route_type) &&
-            (route_type == STREAM_ROUTE_TYPE_AUTO_ALL || route_type == STREAM_ROUTE_TYPE_MANUAL_EXT))
-            continue;
-
         pa_log_info("found a stream(%p, %u) that should be muted.", i, i->index);
         /* remove MUTE_KEY before adding to avoid abort-case in pa_sink_input_add_volume_factor */
         pa_hashmap_remove(i->volume_factor_items, MUTE_KEY);
@@ -3751,7 +3764,7 @@ static void clear_volume_factor_from_streams(pa_idxset *applied_streams) {
 
     pa_assert(applied_streams);
 
-    pa_log_debug("clear_volume_factor_from_streams is called");
+    pa_log_info("clear_volume_factor_from_streams is called");
 
     PA_IDXSET_FOREACH(i, applied_streams, idx) {
         pa_idxset_remove_by_data(applied_streams, i, NULL);
@@ -3781,6 +3794,26 @@ static void timed_unmute_cb(pa_mainloop_api *a, pa_time_event *e, const struct t
     m->time_event_for_unmute = NULL;
 }
 
+static int active_device_filter_func(const void *i, const void *device_type) {
+    pa_assert(i);
+    pa_assert(device_type);
+
+    if (is_active_device_of_stream(i, STREAM_SINK_INPUT, (const char *)device_type))
+        return 1;
+
+    return 0;
+}
+
+static pa_idxset* get_streams_for_matching_active_device(pa_idxset *streams, const char *device_type) {
+    pa_idxset *filtered_streams;
+
+    pa_assert(streams);
+
+    filtered_streams = pa_idxset_filtered_copy(streams, NULL, active_device_filter_func, device_type);
+
+    return filtered_streams;
+}
+
 static void mute_sink_inputs_as_device_disconnection(pa_stream_manager *m, uint32_t event_id, bool need_to_mute, pa_idxset *streams_of_disconnected_device) {
     pa_idxset *applied_streams;
 
@@ -3858,8 +3891,11 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_tz_devi
 
     /* mute all the streams belong to this device, those will be un-muted in event_fully_handled_hook_cb */
     if (!data->is_connected && (device_direction & DM_DEVICE_DIRECTION_OUT)) {
-        if ((sink = pa_tz_device_get_sink(data->device, DEVICE_ROLE_NORMAL)))
-            mute_sink_inputs_as_device_disconnection(m, data->event_id, true, sink->inputs);
+        if ((sink = pa_tz_device_get_sink(data->device, DEVICE_ROLE_NORMAL))) {
+            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);
+        }
 
         /* If Earjack is disconnected, search for sink-input which has radio role,
            if found, let radio mute to avoid intermediate noise */