stream-manager: Revise fill_device_info_to_hook_data() to reduce if-else condition... 39/214239/4
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 19 Sep 2019 06:55:58 +0000 (15:55 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Fri, 20 Sep 2019 03:06:06 +0000 (03:06 +0000)
It'll reduce cyclomatic complexity of SAM.

[Version] 11.1.80
[Issue Type] Refactoring

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

index d2fecc6..04cc9e3 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          11.1.79
+Version:          11.1.80
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 9c9f56c..d4cc0f8 100644 (file)
@@ -1509,72 +1509,76 @@ 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;
-        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 || si->route_type == STREAM_ROUTE_TYPE_MANUAL_EXT) {
-                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_debug("  -- could not get the parent id of this stream, but keep going...");
-            }
-        } else
+        if (!(si = pa_hashmap_get(m->stream_infos, select_data->stream_role))) {
             pa_log_error("  -- could not find (%s)", select_data->stream_role);
+            break;
+        }
+        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 && si->route_type != STREAM_ROUTE_TYPE_MANUAL_EXT)
+            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)) {
+            pa_log_debug("  -- could not get the parent id of this stream, but keep going...");
+            break;
+        }
+        /* find parent idx, it's device info. and it's stream idxs */
+        if ((sp = pa_hashmap_get(m->stream_parents, (const void*)parent_idx))) {
+            select_data->idx_manual_devices = (type == STREAM_SINK_INPUT) ? (sp->idx_route_out_devices) : (sp->idx_route_in_devices);
+            break;
+        }
+        pa_log_warn("  -- failed to get the stream parent of idx(%u)", parent_idx);
         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)) {
-                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);
-            } else
-               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 || si->route_type == STREAM_ROUTE_TYPE_MANUAL_EXT) {
-                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
+        if (!(si = pa_hashmap_get(m->stream_infos, route_data->stream_role))) {
             pa_log_error("  -- could not find (%s)", route_data->stream_role);
+            break;
+        }
+        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;
+        }
 
+        route_data->idx_avail_devices = avail_devices;
+
+        if (si->route_type != STREAM_ROUTE_TYPE_MANUAL && si->route_type != STREAM_ROUTE_TYPE_MANUAL_EXT)
+            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)) {
+            pa_log_warn("  -- could not get the parent id of this stream, but keep going...");
+            break;
+        }
+        if (!(sp = pa_hashmap_get(m->stream_parents, (const void*)parent_idx))) {
+            pa_log_warn("  -- failed to get the stream parent of idx(%u)", parent_idx);
+            break;
+        }
+        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);
         break;
     }
     default: