stream-manager: Revise process_stream() to use sub-functions 17/214217/2
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 19 Sep 2019 05:35:06 +0000 (14:35 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Fri, 20 Sep 2019 03:03:47 +0000 (12:03 +0900)
It'll reduce cyclomatic complexity of SAM.

[Version] 11.1.79
[Issue Type] Refactoring

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

index 891bf20..d2fecc6 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          11.1.78
+Version:          11.1.79
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index c098970..9c9f56c 100644 (file)
@@ -1830,384 +1830,431 @@ static bool check_preferred_role_of_active_device_exist(pa_stream_manager *m, vo
     return false;
 }
 
-process_stream_result_t process_stream(pa_stream_manager *m, void *stream, stream_type_t type, process_command_type_t command, bool is_new_data) {
-    process_stream_result_t result = PROCESS_STREAM_RESULT_OK;
-    const char *role = NULL;
-    const char *route_type_str = NULL;
-    stream_route_type_t route_type;
-    bool ret = true;
-    bool need_update = false;
-    int32_t volume_ret = 0;
-    volume_info *v = NULL;
-    const char *si_volume_type_str = NULL;
-    const int32_t *prior_priority = NULL;
-    size_t size = 0;
+static process_stream_result_t handle_command_prepare(pa_stream_manager *m, void *stream, stream_type_t type, bool is_new_data) {
     pa_format_info *req_format = NULL;
     char *format_str = NULL;
     const char *rate_str = NULL;
     const char *ch_str = NULL;
-    filter_info *f = NULL;
-
-    pa_log_info(">>> [%s]: stream(%p), stream_type(%d), is_new_data(%d)",
-                process_command_type_str[command], stream, type, is_new_data);
+    const char *role = NULL;
+    const char *route_type_str = NULL;
 
     pa_assert(m);
     pa_assert(stream);
 
-    if (check_name_to_skip(m, command, stream, type, is_new_data)) {
-        result = PROCESS_STREAM_RESULT_SKIP;
-        /* set it to null sink/source */
-        if (is_new_data)
-            set_new_data_stream_to_null_sink_source(m, stream, type);
-        goto finish;
-    }
-
-    if (command == PROCESS_COMMAND_PREPARE) {
-        if (type == STREAM_SINK_INPUT) {
-            /* Parse request formats for samplerate, channel, format infomation */
-            if (((pa_sink_input_new_data*)stream)->req_formats) {
-                req_format = pa_idxset_first(((pa_sink_input_new_data*)stream)->req_formats, NULL);
-                if (req_format && req_format->plist) {
-                    /* set sample_spec */
-                    if (pa_format_info_get_prop_string(req_format, PA_PROP_FORMAT_SAMPLE_FORMAT, &format_str) == 0)
-                        ((pa_sink_input_new_data*)stream)->sample_spec.format = pa_parse_sample_format((const char*)format_str);
-                    if ((rate_str = pa_proplist_gets(req_format->plist, PA_PROP_FORMAT_RATE)))
-                        ((pa_sink_input_new_data*)stream)->sample_spec.rate = atoi(rate_str);
-                    if ((ch_str = pa_proplist_gets(req_format->plist, PA_PROP_FORMAT_CHANNELS)))
-                        ((pa_sink_input_new_data*)stream)->sample_spec.channels = atoi(ch_str);
-
-                    pa_log_debug("req rate(%s), req ch(%s), req format(%s)", rate_str, ch_str, format_str);
-
-                    /* set channel map if it is not set by client */
-                    if (!((pa_sink_input_new_data*)stream)->channel_map_is_set) {
-                        pa_channel_map_init_auto(&(((pa_sink_input_new_data*)stream)->channel_map),
-                                                ((pa_sink_input_new_data*)stream)->sample_spec.channels, PA_CHANNEL_MAP_ALSA);
-                        pa_log_debug("set default channel_map: channels(%u)", ((pa_sink_input_new_data*)stream)->channel_map.channels);
-                        ((pa_sink_input_new_data*)stream)->channel_map_is_set = true;
-                    }
-                    pa_xfree(format_str);
+    if (type == STREAM_SINK_INPUT) {
+        /* Parse request formats for samplerate, channel, format infomation */
+        if (((pa_sink_input_new_data*)stream)->req_formats) {
+            req_format = pa_idxset_first(((pa_sink_input_new_data*)stream)->req_formats, NULL);
+            if (req_format && req_format->plist) {
+                /* set sample_spec */
+                if (pa_format_info_get_prop_string(req_format, PA_PROP_FORMAT_SAMPLE_FORMAT, &format_str) == 0)
+                    ((pa_sink_input_new_data*)stream)->sample_spec.format = pa_parse_sample_format((const char*)format_str);
+                if ((rate_str = pa_proplist_gets(req_format->plist, PA_PROP_FORMAT_RATE)))
+                    ((pa_sink_input_new_data*)stream)->sample_spec.rate = atoi(rate_str);
+                if ((ch_str = pa_proplist_gets(req_format->plist, PA_PROP_FORMAT_CHANNELS)))
+                    ((pa_sink_input_new_data*)stream)->sample_spec.channels = atoi(ch_str);
+
+                pa_log_debug("req rate(%s), req ch(%s), req format(%s)", rate_str, ch_str, format_str);
+
+                /* set channel map if it is not set by client */
+                if (!((pa_sink_input_new_data*)stream)->channel_map_is_set) {
+                    pa_channel_map_init_auto(&(((pa_sink_input_new_data*)stream)->channel_map),
+                                            ((pa_sink_input_new_data*)stream)->sample_spec.channels, PA_CHANNEL_MAP_ALSA);
+                    pa_log_debug("set default channel_map: channels(%u)", ((pa_sink_input_new_data*)stream)->channel_map.channels);
+                    ((pa_sink_input_new_data*)stream)->channel_map_is_set = true;
                 }
-            } else {
-                pa_log_debug("no request formats available");
+                pa_xfree(format_str);
             }
-        }
-        role = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE);
-        if (!role) {
-            /* set default value for role and priority */
-            role = DEFAULT_ROLE;
-            pa_proplist_sets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE, role);
-            pa_log_warn("role is null, set default to [%s]", role);
         } else {
-            /* skip roles */
-            if (check_role_to_skip(m, command, role)) {
-                result = PROCESS_STREAM_RESULT_SKIP;
-                goto finish;
-            }
-            /* load forwarding device */
-            if (type == STREAM_SOURCE_OUTPUT && pa_safe_streq(role, STREAM_ROLE_LOOPBACK_MIRRORING))
-                update_forwarding_device(m, true);
-        }
-        /* update the priority of this stream */
-        ret = update_priority_of_stream(m, stream, type, role, is_new_data);
-        if (ret == false) {
-            pa_log_error("could not update the priority of '%s' role.", role);
-            result = PROCESS_STREAM_RESULT_STOP;
-            goto finish;
-        }
-        /* update the route type of this stream */
-        ret = update_route_type_of_stream(m, stream, type, role);
-        if (ret == false) {
-            pa_log_error("could not update the route type of '%s' role.", role);
-            result = PROCESS_STREAM_RESULT_STOP;
-            goto finish;
-        }
-        /* update the volume type of this stream */
-        ret = update_volume_type_of_stream(m, stream, type, role);
-        if (ret == false)
-            pa_log_warn("could not update the volume type of '%s' role.", role);
-
-        /* skip route types */
-        if ((route_type_str = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE_ROUTE_TYPE))) {
-            if (check_route_type_to_skip(command, route_type_str)) {
-                result = PROCESS_STREAM_RESULT_SKIP;
-                goto finish;
-            }
+            pa_log_debug("no request formats available");
         }
+    }
+    role = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE);
+    if (!role) {
+        /* set default value for role and priority */
+        role = DEFAULT_ROLE;
+        pa_proplist_sets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE, role);
+        pa_log_warn("role is null, set default to [%s]", role);
+    } else {
+        /* skip roles */
+        if (check_role_to_skip(m, PROCESS_COMMAND_PREPARE, role))
+            return PROCESS_STREAM_RESULT_SKIP;
 
-        /* update the preferred device role, it will affect only built-in devices. */
-        update_preferred_device_role(m, stream, type);
+        /* load forwarding device */
+        if (type == STREAM_SOURCE_OUTPUT && pa_safe_streq(role, STREAM_ROLE_LOOPBACK_MIRRORING))
+            update_forwarding_device(m, true);
+    }
+    /* update the priority of this stream */
+    if (!update_priority_of_stream(m, stream, type, role, is_new_data)) {
+        pa_log_error("could not update the priority of '%s' role.", role);
+        return PROCESS_STREAM_RESULT_STOP;
+    }
+    /* update the route type of this stream */
+    if (!update_route_type_of_stream(m, stream, type, role)) {
+        pa_log_error("could not update the route type of '%s' role.", role);
+        return PROCESS_STREAM_RESULT_STOP;
+    }
+    /* update the volume type of this stream */
+    if (!update_volume_type_of_stream(m, stream, type, role))
+        pa_log_warn("could not update the volume type of '%s' role.", role);
 
-        /* check if it is a virtual stream */
-        if (check_name_is_vstream(stream, type, is_new_data)) {
-            pa_log_debug("skip notifying for selecting sink/source, rather set it to null sink/source");
-            /* set it to null sink/source */
-            if (is_new_data)
-                set_new_data_stream_to_null_sink_source(m, stream, type);
+    /* skip route types */
+    if ((route_type_str = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE_ROUTE_TYPE))) {
+        if (check_route_type_to_skip(PROCESS_COMMAND_PREPARE, route_type_str))
+            return PROCESS_STREAM_RESULT_SKIP;
+    }
 
-        } else {
-            /* notify to select sink or source */
-            do_notify(m, NOTIFY_COMMAND_SELECT_PROPER_SINK_OR_SOURCE_FOR_INIT, type, true, stream);
-        }
+    /* update the preferred device role, it will affect only built-in devices. */
+    update_preferred_device_role(m, stream, type);
+
+    /* check if it is a virtual stream */
+    if (check_name_is_vstream(stream, type, is_new_data)) {
+        pa_log_debug("skip notifying for selecting sink/source, rather set it to null sink/source");
+        /* set it to null sink/source */
+        if (is_new_data)
+            set_new_data_stream_to_null_sink_source(m, stream, type);
+
+    } else {
+        /* notify to select sink or source */
+        do_notify(m, NOTIFY_COMMAND_SELECT_PROPER_SINK_OR_SOURCE_FOR_INIT, type, true, stream);
+    }
+
+    return PROCESS_STREAM_RESULT_OK;
+}
+
+static process_stream_result_t handle_command_change_route_by_stream_started(pa_stream_manager *m, void *stream,
+                                                                        stream_type_t type, bool is_new_data) {
+    const char *role = NULL;
+    const char *route_type_str = NULL;
+    const char *preferred_device_role;
+    bool need_update = false;
+
+    pa_assert(m);
+    pa_assert(stream);
 
-    } else if (command == PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_STARTED) {
-        const char *preferred_device_role;
+    if (is_new_data) {
+        role = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE);
+        route_type_str = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE_ROUTE_TYPE);
+        preferred_device_role =  pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type),
+                                                            PA_PROP_MEDIA_ROUTE_AUTO_PREFERRED_DEVICE_ROLE);
+    } else {
+        role = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE);
+        route_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE_ROUTE_TYPE);
+        preferred_device_role =  pa_proplist_gets(GET_STREAM_PROPLIST(stream, type),
+                                                            PA_PROP_MEDIA_ROUTE_AUTO_PREFERRED_DEVICE_ROLE);
+    }
 
+    /* skip updating priority, focus status, the highest priority, ucm to HAL */
+    if (preferred_device_role) {
         if (is_new_data) {
-            role = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE);
-            route_type_str = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE_ROUTE_TYPE);
-            preferred_device_role =  pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type),
-                                                                PA_PROP_MEDIA_ROUTE_AUTO_PREFERRED_DEVICE_ROLE);
+            pa_log_debug("skip updating priority, focus status, the highest priority, ucm to HAL");
+            goto skip_notifying_route_start;
         } else {
-            role = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE);
-            route_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE_ROUTE_TYPE);
-            preferred_device_role =  pa_proplist_gets(GET_STREAM_PROPLIST(stream, type),
-                                                                PA_PROP_MEDIA_ROUTE_AUTO_PREFERRED_DEVICE_ROLE);
-        }
-
-        /* skip updating priority, focus status, the highest priority, ucm to HAL */
-        if (preferred_device_role) {
-            if (is_new_data) {
+            if (check_preferred_role_of_active_device_exist(m, stream, type, preferred_device_role)) {
                 pa_log_debug("skip updating priority, focus status, the highest priority, ucm to HAL");
                 goto skip_notifying_route_start;
-            } else {
-                if (check_preferred_role_of_active_device_exist(m, stream, type, preferred_device_role)) {
-                    pa_log_debug("skip updating priority, focus status, the highest priority, ucm to HAL");
-                    goto skip_notifying_route_start;
-                }
             }
         }
+    }
 
-        /* skip roles */
-        if (check_role_to_skip(m, command, role)) {
-            result = PROCESS_STREAM_RESULT_SKIP;
-            goto finish;
-        }
+    /* skip roles */
+    if (check_role_to_skip(m, PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_STARTED, role))
+        return PROCESS_STREAM_RESULT_SKIP;
 
-        /* skip route types */
-        if (check_route_type_to_skip(command, route_type_str)) {
-            result = PROCESS_STREAM_RESULT_SKIP;
-            goto finish;
-        }
+    /* skip route types */
+    if (check_route_type_to_skip(PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_STARTED, route_type_str))
+        return PROCESS_STREAM_RESULT_SKIP;
 
-        if (!is_new_data) {
-            /* update the priority of this stream */
-            ret = update_priority_of_stream(m, stream, type, role, is_new_data);
-            if (ret == false) {
-                pa_log_error("could not update the priority of '%s' role.", role);
-                result = PROCESS_STREAM_RESULT_STOP;
-                goto finish;
-            }
+    if (!is_new_data) {
+        /* update the priority of this stream */
+        if (!update_priority_of_stream(m, stream, type, role, is_new_data)) {
+            pa_log_error("could not update the priority of '%s' role.", role);
+            return PROCESS_STREAM_RESULT_STOP;
         }
+    }
 
-        /* update the focus status */
-        ret = update_focus_status_of_stream(m, stream, type, is_new_data);
-        if (ret == false)
-            pa_log_warn("could not update focus status");
-
-        /* update the highest priority */
-        ret = update_the_highest_priority_stream(m, command, stream, type, role, is_new_data, &need_update);
-        if (ret == false) {
-            pa_log_error("could not update the highest priority stream");
-            result = PROCESS_STREAM_RESULT_SKIP;
-            goto finish;
-        }
+    /* update the focus status */
+    if (!update_focus_status_of_stream(m, stream, type, is_new_data))
+        pa_log_warn("could not update focus status");
 
-        /* need to skip if this stream does not belong to internal device */
-        /* if needed, notify to update */
-        if (need_update) {
-            if (is_new_data) {
-                do_notify(m, NOTIFY_COMMAND_CHANGE_ROUTE_START, type, true, stream);
-                if (type == STREAM_SINK_INPUT)
-                    m->cur_highest_priority.need_to_update_si = true;
-                else
-                    m->cur_highest_priority.need_to_update_so = true;
+    /* update the highest priority */
+    if (!update_the_highest_priority_stream(m, PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_STARTED, stream, type, role, is_new_data, &need_update)) {
+        pa_log_error("could not update the highest priority stream");
+        return PROCESS_STREAM_RESULT_SKIP;
+    }
+
+    /* need to skip if this stream does not belong to internal device */
+    /* if needed, notify to update */
+    if (need_update) {
+        if (is_new_data) {
+            do_notify(m, NOTIFY_COMMAND_CHANGE_ROUTE_START, type, true, stream);
+            if (type == STREAM_SINK_INPUT)
+                m->cur_highest_priority.need_to_update_si = true;
+            else
+                m->cur_highest_priority.need_to_update_so = true;
+        } else {
+            do_notify(m, NOTIFY_COMMAND_CHANGE_ROUTE_START, type, false, stream);
+            if (type == STREAM_SINK_INPUT) {
+                m->cur_highest_priority.sink_input = stream;
+                m->cur_highest_priority.role_si = role;
             } else {
-                do_notify(m, NOTIFY_COMMAND_CHANGE_ROUTE_START, type, false, stream);
-                if (type == STREAM_SINK_INPUT) {
-                    m->cur_highest_priority.sink_input = stream;
-                    m->cur_highest_priority.role_si = role;
-                } else {
-                    m->cur_highest_priority.source_output = stream;
-                    m->cur_highest_priority.role_so = role;
-                }
+                m->cur_highest_priority.source_output = stream;
+                m->cur_highest_priority.role_so = role;
             }
         }
+    }
 
 skip_notifying_route_start:
-        if (!is_new_data)
-            do_notify(m, NOTIFY_COMMAND_INFORM_STREAM_CONNECTED, type, false, stream);
+    if (!is_new_data)
+        do_notify(m, NOTIFY_COMMAND_INFORM_STREAM_CONNECTED, type, false, stream);
 
-    } else if (command == PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_ENDED) {
-        const char *preferred_device_role;
+    return PROCESS_STREAM_RESULT_OK;
+}
 
-        if (!(role = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE))) {
-            pa_log_warn("role is null, skip it");
-            goto finish;
-        }
+static process_stream_result_t handle_command_change_route_by_stream_ended(pa_stream_manager *m, void *stream,
+                                                                        stream_type_t type, bool is_new_data) {
+    const char *role = NULL;
+    const char *route_type_str = NULL;
+    const char *preferred_device_role;
+    bool need_update = false;
+    const int32_t *prior_priority = NULL;
+    size_t size = 0;
 
-        preferred_device_role =  pa_proplist_gets(GET_STREAM_PROPLIST(stream, type),
-                                                    PA_PROP_MEDIA_ROUTE_AUTO_PREFERRED_DEVICE_ROLE);
-        /* skip updating the highest priority, ucm to HAL */
-        if (preferred_device_role) {
-            if (check_preferred_role_of_active_device_exist(m, stream, type, preferred_device_role)) {
-                pa_log_debug("skip updating the highest priority, ucm to HAL");
-                goto skip_notifying_route_end;
-            }
-        }
+    pa_assert(m);
+    pa_assert(stream);
 
-        /* unload forwarding device */
-        if (type == STREAM_SOURCE_OUTPUT && pa_safe_streq(role, STREAM_ROLE_LOOPBACK_MIRRORING))
-            update_forwarding_device(m, false);
+    if (!(role = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE))) {
+        pa_log_warn("role is null, skip it");
+        return PROCESS_STREAM_RESULT_SKIP;
+    }
 
-        /* skip roles */
-        if (check_role_to_skip(m, command, role)) {
-            result = PROCESS_STREAM_RESULT_SKIP;
-            goto finish;
+    preferred_device_role =  pa_proplist_gets(GET_STREAM_PROPLIST(stream, type),
+                                            PA_PROP_MEDIA_ROUTE_AUTO_PREFERRED_DEVICE_ROLE);
+    /* skip updating the highest priority, ucm to HAL */
+    if (preferred_device_role) {
+        if (check_preferred_role_of_active_device_exist(m, stream, type, preferred_device_role)) {
+            pa_log_debug("skip updating the highest priority, ucm to HAL");
+            goto skip_notifying_route_end;
         }
+    }
 
-        /* skip route types */
-        if ((route_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE_ROUTE_TYPE))) {
-            if (check_route_type_to_skip(command, route_type_str)) {
-                result = PROCESS_STREAM_RESULT_SKIP;
-                goto finish;
-            }
-        }
+    /* unload forwarding device */
+    if (type == STREAM_SOURCE_OUTPUT && pa_safe_streq(role, STREAM_ROLE_LOOPBACK_MIRRORING))
+        update_forwarding_device(m, false);
 
-        /* check if it has already been processed (unlink or state_changed_cb) */
-        if (pa_proplist_get(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE_PRIORITY, (const void**)&prior_priority, &size)) {
-            pa_log_debug("it has already been processed for PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_ENDED, skip it..");
-            result = PROCESS_STREAM_RESULT_SKIP;
-            goto finish;
-        }
+    /* skip roles */
+    if (check_role_to_skip(m, PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_ENDED, role))
+        return PROCESS_STREAM_RESULT_SKIP;
 
-        ret = update_the_highest_priority_stream(m, command, stream, type, role, is_new_data, &need_update);
-        if (ret == false) {
-            pa_log_error("could not update the highest priority stream");
-            result = PROCESS_STREAM_RESULT_STOP;
-            goto finish;
-        }
+    /* skip route types */
+    if ((route_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE_ROUTE_TYPE))) {
+        if (check_route_type_to_skip(PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_ENDED, route_type_str))
+            return PROCESS_STREAM_RESULT_SKIP;
+    }
+
+    /* check if it has already been processed (unlink or state_changed_cb) */
+    if (pa_proplist_get(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE_PRIORITY, (const void**)&prior_priority, &size)) {
+        pa_log_debug("it has already been processed for PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_ENDED, skip it..");
+        return PROCESS_STREAM_RESULT_SKIP;
+    }
+
+    if (!update_the_highest_priority_stream(m, PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_ENDED, stream, type,
+                                        role, is_new_data, &need_update)) {
+        pa_log_error("could not update the highest priority stream");
+        return PROCESS_STREAM_RESULT_STOP;
+    }
 
 skip_notifying_route_end:
-        do_notify(m, NOTIFY_COMMAND_INFORM_STREAM_DISCONNECTED, type, false, stream);
+    do_notify(m, NOTIFY_COMMAND_INFORM_STREAM_DISCONNECTED, type, false, stream);
 
-        /* need to skip if this stream does not belong to internal device */
-        /* if needed, notify to update */
-        if (need_update)
-            do_notify(m, NOTIFY_COMMAND_CHANGE_ROUTE_END, type, false, NULL);
+    /* need to skip if this stream does not belong to internal device */
+    /* if needed, notify to update */
+    if (need_update)
+        do_notify(m, NOTIFY_COMMAND_CHANGE_ROUTE_END, type, false, NULL);
 
-    } else if (command == PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_FOCUS_CHANGED) {
-        if (!(role = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE))) {
-            pa_log_warn("role is null, skip it");
-            goto finish;
-        }
+    return PROCESS_STREAM_RESULT_OK;
+}
 
-        /* skip roles */
-        if (check_role_to_skip(m, command, role)) {
-            result = PROCESS_STREAM_RESULT_SKIP;
-            goto finish;
-        }
+static process_stream_result_t handle_command_change_route_by_stream_focus_changed(pa_stream_manager *m, void *stream,
+                                                                                stream_type_t type, bool is_new_data) {
+    const char *role = NULL;
+    const char *route_type_str = NULL;
+    bool need_update = false;
 
-        /* skip route types */
-        if ((route_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE_ROUTE_TYPE))) {
-            if (check_route_type_to_skip(command, route_type_str)) {
-                result = PROCESS_STREAM_RESULT_SKIP;
-                goto finish;
-            }
-        }
+    pa_assert(m);
+    pa_assert(stream);
+
+    if (!(role = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE))) {
+        pa_log_warn("role is null, skip it");
+        return PROCESS_STREAM_RESULT_SKIP;
+    }
 
-        ret = update_the_highest_priority_stream(m, command, stream, type, role, is_new_data, &need_update);
-        if (ret == false) {
-            pa_log_error("could not update the highest priority stream");
-            result = PROCESS_STREAM_RESULT_STOP;
-            goto finish;
+    /* skip roles */
+    if (check_role_to_skip(m, PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_FOCUS_CHANGED, role))
+        return PROCESS_STREAM_RESULT_SKIP;
+
+    /* skip route types */
+    if ((route_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE_ROUTE_TYPE))) {
+        if (check_route_type_to_skip(PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_FOCUS_CHANGED, route_type_str))
+            return PROCESS_STREAM_RESULT_SKIP;
+    }
+
+    if (!update_the_highest_priority_stream(m, PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_FOCUS_CHANGED, stream, type, role,
+                                            is_new_data, &need_update)) {
+        pa_log_error("could not update the highest priority stream");
+        return PROCESS_STREAM_RESULT_STOP;
+    }
+
+    /* need to skip if this stream does not belong to internal device */
+    /* if needed, notify to update */
+    if (need_update)
+        do_notify(m, NOTIFY_COMMAND_CHANGE_ROUTE_END, type, false, NULL);
+
+    return PROCESS_STREAM_RESULT_OK;
+}
+
+static process_stream_result_t handle_command_update_volume(pa_stream_manager *m, void *stream, stream_type_t type, bool is_new_data) {
+    int32_t volume_ret = 0;
+    volume_info *v = NULL;
+    const char *si_volume_type_str = NULL;
+
+    pa_assert(m);
+    pa_assert(stream);
+
+    if (is_new_data) {
+        si_volume_type_str = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE);
+    } else {
+        si_volume_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE);
+        if (si_volume_type_str && is_active_device_of_stream(stream, STREAM_SINK_INPUT, DEVICE_TYPE_NETWORK)) {
+            /* In case of network device, reset the volume of this sink-input. */
+            pa_cvolume cv;
+            pa_cvolume_reset(&cv, ((pa_sink_input*)stream)->sample_spec.channels) ;
+            pa_sink_input_set_volume((pa_sink_input*)stream, &cv, true, true);
+            pa_log_debug("This stream belongs to a network device, reset volume.");
+            return PROCESS_STREAM_RESULT_OK;
         }
+    }
 
-        /* need to skip if this stream does not belong to internal device */
-        /* if needed, notify to update */
-        if (need_update)
-            do_notify(m, NOTIFY_COMMAND_CHANGE_ROUTE_END, type, false, NULL);
+    if (!si_volume_type_str)
+        return PROCESS_STREAM_RESULT_SKIP;
 
-    } else if (command == PROCESS_COMMAND_UPDATE_VOLUME) {
+    v = pa_hashmap_get(m->volume_infos, si_volume_type_str);
+    if (v && v->values[type].idx_volume_values) {
         if (is_new_data) {
-            si_volume_type_str = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE);
+            /* Update volume-level */
+            if ((volume_ret = set_volume_level_with_new_data(m, stream, type, v->values[type].current_level)))
+                pa_log_error("failed to set_volume_level_with_new_data(), stream_type(%d), level(%u), ret(0x%x)",
+                                type, v->values[type].current_level, volume_ret);
+            /* Update volume-mute */
+            if ((volume_ret = set_volume_mute_with_new_data(m, stream, type, v->values[type].is_muted)))
+                pa_log_error("failed to set_volume_mute_with_new_data(), stream_type(%d), mute(%d), ret(0x%x)",
+                                type, v->values[type].is_muted, volume_ret);
         } else {
-            si_volume_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE);
-            if (si_volume_type_str && is_active_device_of_stream(stream, STREAM_SINK_INPUT, DEVICE_TYPE_NETWORK)) {
-                /* In case of network device, reset the volume of this sink-input. */
-                pa_cvolume cv;
-                pa_cvolume_reset(&cv, ((pa_sink_input*)stream)->sample_spec.channels) ;
-                pa_sink_input_set_volume((pa_sink_input*)stream, &cv, true, true);
-                pa_log_debug("This stream belongs to a network device, reset volume.");
-                goto finish;
-            }
+            /* Update volume-level by stream index*/
+            if ((volume_ret = set_volume_level_by_idx(m, type, GET_STREAM_INDEX(stream, type), v->values[type].current_level)))
+                pa_log_error("failed to set_volume_level_by_idx(), stream_type(%d), index(%u), level(%u), ret(0x%x)",
+                                type, GET_STREAM_INDEX(stream, type), v->values[type].current_level, volume_ret);
         }
+    }
 
-        if (!si_volume_type_str)
-            goto finish;
+    return PROCESS_STREAM_RESULT_OK;
+}
 
-        v = pa_hashmap_get(m->volume_infos, si_volume_type_str);
-        if (v && v->values[type].idx_volume_values) {
-            if (is_new_data) {
-                /* Update volume-level */
-                if ((volume_ret = set_volume_level_with_new_data(m, stream, type, v->values[type].current_level)))
-                    pa_log_error("failed to set_volume_level_with_new_data(), stream_type(%d), level(%u), ret(0x%x)",
-                                    type, v->values[type].current_level, volume_ret);
-                /* Update volume-mute */
-                if ((volume_ret = set_volume_mute_with_new_data(m, stream, type, v->values[type].is_muted)))
-                    pa_log_error("failed to set_volume_mute_with_new_data(), stream_type(%d), mute(%d), ret(0x%x)",
-                                    type, v->values[type].is_muted, volume_ret);
-            } else {
-                /* Update volume-level by stream index*/
-                if ((volume_ret = set_volume_level_by_idx(m, type, GET_STREAM_INDEX(stream, type), v->values[type].current_level)))
-                    pa_log_error("failed to set_volume_level_by_idx(), stream_type(%d), index(%u), level(%u), ret(0x%x)",
-                                    type, GET_STREAM_INDEX(stream, type), v->values[type].current_level, volume_ret);
-            }
-        }
+static process_stream_result_t handle_command_add_remove_parent_id(pa_stream_manager *m, process_command_type_t command,
+                                            void *stream, stream_type_t type, bool is_new_data) {
+    const char *role = NULL;
+    const char *route_type_str = NULL;
+    stream_route_type_t route_type;
 
-    } else if (command == PROCESS_COMMAND_ADD_PARENT_ID || command == PROCESS_COMMAND_REMOVE_PARENT_ID) {
-        if (!(role = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE)))
-            goto finish;
+    pa_assert(m);
+    pa_assert(stream);
 
-        /* skip roles */
-        if (check_role_to_skip(m, command, role)) {
-            result = PROCESS_STREAM_RESULT_SKIP;
-            goto finish;
-        }
+    if (command != PROCESS_COMMAND_ADD_PARENT_ID && PROCESS_COMMAND_REMOVE_PARENT_ID)
+        return PROCESS_STREAM_RESULT_SKIP;
 
-        /* skip route types */
-        if ((route_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE_ROUTE_TYPE))) {
-            if (check_route_type_to_skip(command, route_type_str)) {
-                result = PROCESS_STREAM_RESULT_SKIP;
-                goto finish;
-            }
-        }
+    if (!(role = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE))) {
+        pa_log_warn("role is null, skip it");
+        return PROCESS_STREAM_RESULT_SKIP;
+    }
 
-        if (!IS_ROUTE_TYPE_FOR_EXTERNAL_DEV(route_type_str, route_type)) {
-            if (command == PROCESS_COMMAND_ADD_PARENT_ID) {
-                if (type == STREAM_SINK_INPUT && m->cur_highest_priority.need_to_update_si) {
-                    m->cur_highest_priority.sink_input = stream;
-                    m->cur_highest_priority.role_si = role;
-                    m->cur_highest_priority.need_to_update_si = false;
-                }
-                if (type == STREAM_SOURCE_OUTPUT && m->cur_highest_priority.need_to_update_so) {
-                    m->cur_highest_priority.source_output = stream;
-                    m->cur_highest_priority.role_so = role;
-                    m->cur_highest_priority.need_to_update_so = false;
-                }
-                do_notify(m, NOTIFY_COMMAND_INFORM_STREAM_CONNECTED, type, false, stream);
+    /* skip roles */
+    if (check_role_to_skip(m, command, role))
+        return PROCESS_STREAM_RESULT_SKIP;
+
+    /* skip route types */
+    if ((route_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE_ROUTE_TYPE))) {
+        if (check_route_type_to_skip(command, route_type_str))
+            return PROCESS_STREAM_RESULT_SKIP;
+    }
+
+    if (!IS_ROUTE_TYPE_FOR_EXTERNAL_DEV(route_type_str, route_type)) {
+        if (command == PROCESS_COMMAND_ADD_PARENT_ID) {
+            if (type == STREAM_SINK_INPUT && m->cur_highest_priority.need_to_update_si) {
+                m->cur_highest_priority.sink_input = stream;
+                m->cur_highest_priority.role_si = role;
+                m->cur_highest_priority.need_to_update_si = false;
+            }
+            if (type == STREAM_SOURCE_OUTPUT && m->cur_highest_priority.need_to_update_so) {
+                m->cur_highest_priority.source_output = stream;
+                m->cur_highest_priority.role_so = role;
+                m->cur_highest_priority.need_to_update_so = false;
             }
+            do_notify(m, NOTIFY_COMMAND_INFORM_STREAM_CONNECTED, type, false, stream);
         }
+    }
 
-        /* update parent stream info. */
-        ret = update_stream_parent_info(m, command, type, stream);
-        if (ret == false) {
-            pa_log_debug("could not update the parent information of this stream");
-            //return PROCESS_STREAM_RESULT_STOP;
-        }
+    /* update parent stream info. */
+    if (!update_stream_parent_info(m, command, type, stream)) {
+        pa_log_debug("could not update the parent information of this stream");
+        //return PROCESS_STREAM_RESULT_STOP;
+    }
+
+    return PROCESS_STREAM_RESULT_OK;
+}
 
-    } else if (command == PROCESS_COMMAND_UPDATE_BUFFER_ATTR) {
+process_stream_result_t process_stream(pa_stream_manager *m, void *stream, stream_type_t type, process_command_type_t command, bool is_new_data) {
+    process_stream_result_t result = PROCESS_STREAM_RESULT_OK;
+
+    pa_log_info(">>> [%s]: stream(%p), stream_type(%d), is_new_data(%d)",
+                process_command_type_str[command], stream, type, is_new_data);
+
+    pa_assert(m);
+    pa_assert(stream);
+
+    if (check_name_to_skip(m, command, stream, type, is_new_data)) {
+        result = PROCESS_STREAM_RESULT_SKIP;
+        /* set it to null sink/source */
+        if (is_new_data)
+            set_new_data_stream_to_null_sink_source(m, stream, type);
+        goto finish;
+    }
+
+    switch (command) {
+    case PROCESS_COMMAND_PREPARE:
+        result = handle_command_prepare(m, stream, type, is_new_data);
+        break;
+    case PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_STARTED:
+        result = handle_command_change_route_by_stream_started(m, stream, type, is_new_data);
+        break;
+    case PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_ENDED:
+        result = handle_command_change_route_by_stream_ended(m, stream, type, is_new_data);
+        break;
+    case PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_FOCUS_CHANGED:
+        result = handle_command_change_route_by_stream_focus_changed(m, stream, type, is_new_data);
+        break;
+    case PROCESS_COMMAND_UPDATE_VOLUME:
+        result = handle_command_update_volume(m, stream, type, is_new_data);
+        break;
+    case PROCESS_COMMAND_ADD_PARENT_ID:
+    case PROCESS_COMMAND_REMOVE_PARENT_ID:
+        result = handle_command_add_remove_parent_id(m, command, stream, type, is_new_data);
+        break;
+    case PROCESS_COMMAND_UPDATE_BUFFER_ATTR:
         update_buffer_attribute(m, stream, type, is_new_data);
-    } else if (command == PROCESS_COMMAND_APPLY_FILTER) {
+        break;
+    case PROCESS_COMMAND_APPLY_FILTER: {
+        const char *role = NULL;
+        filter_info *f = NULL;
         /* Apply filter using module-filter-apply when put sink-input. */
         if (type == STREAM_SINK_INPUT) {
             role = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE);
@@ -2217,6 +2264,8 @@ skip_notifying_route_end:
                     apply_filter_to_sink_input((pa_sink_input *)stream, f, false);
             }
         }
+        break;
+    }
     }
 
 finish: