stream-manager: Revise device_connection_changed_hook_cb() to use new sub-function 53/214253/2
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 19 Sep 2019 08:13:25 +0000 (17:13 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Fri, 20 Sep 2019 03:06:16 +0000 (03:06 +0000)
It'll reduce cyclomatic complexity of SAM.

update_sink_or_source_as_device_change() is renamed to
check_and_move_streams_by_device_connection_change().

[Version] 11.1.81
[Issue Type] Refactoring

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

index 04cc9e3..d1fbf78 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          11.1.80
+Version:          11.1.81
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index d4cc0f8..156a690 100644 (file)
@@ -2857,8 +2857,8 @@ static bool manage_filter_apply_stream(pa_stream_manager *m, pa_sink_input *si,
     return false;
 }
 
-static void update_sink_or_source_as_device_change(pa_stream_manager *m, stream_route_type_t stream_route_type, pa_idxset *streams,
-                                                   stream_type_t stream_type, pa_tz_device *device, bool is_connected) {
+static void check_and_move_streams_by_device_connection_change(pa_stream_manager *m, stream_route_type_t stream_route_type,
+                                                        pa_idxset *streams, stream_type_t stream_type, pa_tz_device *device, bool is_connected) {
     #define MAX_CACHED_LEN 128
     typedef struct _cached_device_list {
         const char *device_type;
@@ -3193,6 +3193,41 @@ static pa_hook_result_t event_fully_handled_hook_cb(pa_core *c, pa_subscribe_obs
     return PA_HOOK_OK;
 }
 
+static void update_sink_or_source_by_device_connection_change(pa_stream_manager *m, pa_tz_device_hook_data_for_conn_changed *data,
+                                        bool use_internal_codec, dm_device_direction_t device_direction) {
+    pa_sink *sink = NULL;
+    pa_source *source = NULL;
+
+    pa_assert(m);
+    pa_assert(data);
+
+    /* Update streams belong to this external device that have MAUAL_EXT route type */
+    if (!use_internal_codec) {
+        if ((device_direction & DM_DEVICE_DIRECTION_IN) &&
+            (source = pa_tz_device_get_source(data->device, NULL)))
+            check_and_move_streams_by_device_connection_change(m, STREAM_ROUTE_TYPE_MANUAL_EXT, source->outputs,
+                                                   STREAM_SOURCE_OUTPUT, data->device, data->is_connected);
+        if ((device_direction & DM_DEVICE_DIRECTION_OUT) &&
+            (sink = pa_tz_device_get_sink(data->device, NULL)))
+            check_and_move_streams_by_device_connection_change(m, STREAM_ROUTE_TYPE_MANUAL_EXT, sink->inputs,
+                                                   STREAM_SINK_INPUT, data->device, data->is_connected);
+    }
+
+    /* Update all the streams that have AUTO route type */
+    if (device_direction & DM_DEVICE_DIRECTION_IN) {
+        check_and_move_streams_by_device_connection_change(m, STREAM_ROUTE_TYPE_AUTO, m->core->source_outputs,
+                                               STREAM_SOURCE_OUTPUT, data->device, data->is_connected);
+        check_and_move_streams_by_device_connection_change(m, STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED, m->core->source_outputs,
+                                               STREAM_SOURCE_OUTPUT, data->device, data->is_connected);
+    }
+    if (device_direction & DM_DEVICE_DIRECTION_OUT) {
+        check_and_move_streams_by_device_connection_change(m, STREAM_ROUTE_TYPE_AUTO, m->core->sink_inputs,
+                                               STREAM_SINK_INPUT, data->device, data->is_connected);
+        check_and_move_streams_by_device_connection_change(m, STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED, m->core->sink_inputs,
+                                               STREAM_SINK_INPUT, data->device, data->is_connected);
+    }
+}
+
 /* Reorganize routing when a device has been connected or disconnected */
 static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_tz_device_hook_data_for_conn_changed *data, pa_stream_manager *m) {
     const char *active_dev = NULL;
@@ -3204,7 +3239,6 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_tz_devi
     uint32_t s_idx = 0;
     uint32_t device_id = 0;
     pa_sink *sink = NULL;
-    pa_source *source = NULL;
     pa_sink_input *si = NULL;
     pa_sink_input *highest_prior_si = NULL;
     pa_source_output *highest_prior_so = NULL;
@@ -3249,33 +3283,7 @@ 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, 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, NULL)))
-                update_sink_or_source_as_device_change(m, STREAM_ROUTE_TYPE_MANUAL_EXT, sink->inputs,
-                                                       STREAM_SINK_INPUT, data->device, data->is_connected);
-        }
-    }
-
-    /* Update all the streams that have AUTO route type */
-    if (device_direction & DM_DEVICE_DIRECTION_IN) {
-        update_sink_or_source_as_device_change(m, STREAM_ROUTE_TYPE_AUTO, m->core->source_outputs,
-                                               STREAM_SOURCE_OUTPUT, data->device, data->is_connected);
-        update_sink_or_source_as_device_change(m, STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED, m->core->source_outputs,
-                                               STREAM_SOURCE_OUTPUT, data->device, data->is_connected);
-    }
-    if (device_direction & DM_DEVICE_DIRECTION_OUT) {
-        update_sink_or_source_as_device_change(m, STREAM_ROUTE_TYPE_AUTO, m->core->sink_inputs,
-                                               STREAM_SINK_INPUT, data->device, data->is_connected);
-        update_sink_or_source_as_device_change(m, STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED, m->core->sink_inputs,
-                                               STREAM_SINK_INPUT, data->device, data->is_connected);
-    }
+    update_sink_or_source_by_device_connection_change(m, data, use_internal_codec, device_direction);
 
     /* If the route type is AUTO SERIES, notify again */
     highest_prior_so = m->cur_highest_priority.source_output;