stream-manager: Move streams to a valid sink/source when a device is disconnected 34/66434/3
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 19 Apr 2016 00:36:59 +0000 (09:36 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 19 Apr 2016 04:22:50 +0000 (21:22 -0700)
fix codes to move other streams to a valid sink/source when a device is disconnected.
modify and remove some debug logs.

[Version] 5.0.45
[Profile] Common
[Issue Type] Bug Fix

Change-Id: I4ae21f4f214d2b41da9b876372f60ba8e204de59

packaging/pulseaudio-modules-tizen.spec
src/module-policy.c
src/stream-manager.c

index e4b8c94..61abd17 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          5.0.44
+Version:          5.0.45
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 5222d91..3e59a02 100644 (file)
@@ -677,7 +677,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_
                                                                                         CONVERT_TO_DEVICE_DIRECTION(data->stream_type),
                                                                                         data->device_role);
                     if (use_internal_codec) {
-                        /* set other device's state to deactivated */
+                        /* set other device's state to be deactivated */
                         PA_IDXSET_FOREACH(_device, conn_devices, conn_idx) {
                             if (device == _device)
                                 continue;
@@ -812,7 +812,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_
                     /* 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 */
+                    /* set other device's state to be deactivated */
                     PA_IDXSET_FOREACH(device, conn_devices, conn_idx) {
                         if (latest_device == device)
                             continue;
@@ -846,7 +846,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_ALL && route_info.num_of_devices) {
-            /* set other device's state to deactivated */
+            /* set other device's state to be deactivated */
             PA_IDXSET_FOREACH(_device, conn_devices, conn_idx) {
                 bool need_to_deactive = true;
                 dm_device_id = pa_device_manager_get_device_id(_device);
@@ -904,9 +904,9 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_
                                 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 = CONVERT_TO_HAL_DIRECTION(data->stream_type);
                                 route_info.device_infos[route_info.num_of_devices-1].id = *device_id;
-                                pa_log_info("  ** found a matched device and set state to ACTIVATED: type[%-16s], direction[0x%x], id[%u]",
+                                pa_log_info("  ** found a matched device and set state to be ACTIVATED: type[%-16s], direction[0x%x], id[%u]",
                                             route_info.device_infos[route_info.num_of_devices-1].type, dm_device_direction, *device_id);
-                                /* set device state to activated */
+                                /* set device state to be 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");
index da005c8..1914038 100644 (file)
@@ -2874,7 +2874,7 @@ static void update_sink_or_source_as_device_change(stream_route_type_t stream_ro
     const char *role = NULL;
     const char *device_type = NULL;
     const char *cur_device_type = NULL;
-    const char *init_device_type = NULL;
+    const char *new_device_type = NULL;
     dm_device *next_device = NULL;
     dm_device *_device = NULL;
     stream_route_type_t route_type;
@@ -2953,23 +2953,21 @@ 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)) {
-                        init_device_type = device_type;
                         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);
+                                new_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);
+                                pa_proplist_sets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, new_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;
+                                cached_prev_dev_list[cnt++].device_type = 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);
+                                             s, ((pa_sink_input*)s)->index, next_sink, next_sink->name, new_device_type);
                                 }
                         }
 
@@ -2980,23 +2978,21 @@ 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;
                         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);
+                                new_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);
+                                pa_proplist_sets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, new_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;
+                                cached_prev_dev_list[cnt++].device_type = 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);
+                                             s, ((pa_source_output*)s)->index, next_source, next_source->name, new_device_type);
                                 }
                         }
                         if (!next_device || !next_source) {
@@ -3009,31 +3005,29 @@ static void update_sink_or_source_as_device_change(stream_route_type_t stream_ro
             }
         }
 
-        /* set device state to deactivated */
+        /* set device state to be deactivated */
         if (cnt) {
+            if (stream_type == STREAM_SINK_INPUT) {
+                combine_sink = (pa_sink*)pa_namereg_get(m->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK);
+                if (combine_sink && pa_idxset_size(combine_sink->inputs)) {
+                    pa_log_warn("  -- combine sink has streams, skip it..");
+                    return;
+                }
+            }
+            /* retrieve all the streams for checking current activated device */
             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);
                         if (pa_streq(cur_device_type, cached_prev_dev_list[cnt].device_type))
                             cached_prev_dev_list[cnt].count++;
                     }
                 }
             }
-            if (stream_type == STREAM_SINK_INPUT) {
-                combine_sink = (pa_sink*)pa_namereg_get(m->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK);
-                if (combine_sink && pa_idxset_size(combine_sink->inputs)) {
-                    pa_log_warn("  -- combine sink has streams, skip it..");
-                    return;
-                }
-            }
+            /* if there's no activated device marked in previous device list, set it to be deactivated */
             for (cnt = 0; cached_prev_dev_list[cnt].device_type; cnt++) {
                 if (cached_prev_dev_list[cnt].count == 0) {
-                    pa_log_debug("  -- device_type(%s)", cached_prev_dev_list[cnt].device_type);
                     if ((_device = pa_device_manager_get_device(m->dm, cached_prev_dev_list[cnt].device_type)))
                         set_device_state_if_using_internal_codec(_device, stream_type, DM_DEVICE_STATE_DEACTIVATED);
-                    else
-                        pa_log_warn("  -- _device is null");
                 }
             }
         }
@@ -3334,9 +3328,6 @@ int32_t pa_stream_manager_get_route_type(void *stream, bool origins_from_new_dat
         return -1;
     }
 
-    pa_log_debug("stream(%p), origins_from_new_data(%d), stream_type(%d): route_type(%d)",
-                 stream, origins_from_new_data, stream_type, *stream_route_type);
-
     return 0;
 }