stream-manager: Improve visibility of source codes 51/59351/8 accepted/tizen/mobile/20160216.102945 accepted/tizen/tv/20160216.103003 accepted/tizen/wearable/20160216.103021 submit/tizen/20160216.062636 submit/tizen_common/20160218.142243
authorSangchul Lee <sc11.lee@samsung.com>
Sun, 14 Feb 2016 23:08:55 +0000 (08:08 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Mon, 15 Feb 2016 05:27:55 +0000 (14:27 +0900)
[Version] 5.0.33
[Profile] Common
[Issue Type] Code clean-up

Change-Id: I03c6d67356f43b72c6d47cef4f33a3f1792b18c7

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

index 1600e70..2995797 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          5.0.32
+Version:          5.0.33
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 3caa366..de18980 100644 (file)
@@ -84,6 +84,7 @@ static int load_out_volume_conf_file(pa_stream_manager *m) {
     volume_info* v = NULL;
     void *state = NULL;
     const char *vol_type_str = NULL;
+
     pa_assert(m);
 
     dict = iniparser_load(VOLUME_INI_TUNED_PATH);
@@ -170,28 +171,29 @@ FAILURE:
 
 static int is_hal_volume_by_type(pa_stream_manager *m, const char *volume_type, pa_bool_t *is_hal_volume) {
     volume_info *v = NULL;
+
     pa_assert(m);
+    pa_assert(m->volume_infos);
     pa_assert(volume_type);
     pa_assert(is_hal_volume);
 
-    if (m->volume_infos) {
-        v = pa_hashmap_get(m->volume_infos, volume_type);
-        if (v)
-            *is_hal_volume = v->is_hal_volume_type;
-        else
-            return -1;
-    } else
+    v = pa_hashmap_get(m->volume_infos, volume_type);
+    if (!v)
         return -1;
 
+    *is_hal_volume = v->is_hal_volume_type;
+
     return 0;
 }
 
 static int get_volume_value(pa_stream_manager *m, stream_type_t stream_type, pa_bool_t is_hal_volume, const char *volume_type, uint32_t volume_level, double *volume_value) {
-    int ret = 0;
     double volume_linear = 1.0;
     volume_info *v = NULL;
     void *volumes = NULL;
+    double *value = NULL;
+
     pa_assert(m);
+    pa_assert(m->volume_infos);
     pa_assert(volume_type);
     pa_assert(volume_value);
 
@@ -200,47 +202,37 @@ static int get_volume_value(pa_stream_manager *m, stream_type_t stream_type, pa_
         /* Get value from HAL */
         if (pa_hal_manager_get_volume_value(m->hal, volume_type, NULL,
                                             CONVERT_TO_HAL_DIRECTION(stream_type), volume_level, &volume_linear)) {
-            ret = -1;
-            goto FAILURE;
+            return -1;
         }
     } else {
         /* Get value from stream-manager */
-        if ((volumes = m->volume_infos)) {
-            v = pa_hashmap_get(volumes, volume_type);
-            if (v && v->values[stream_type].idx_volume_values) {
-                double *value = NULL;
-                value = pa_idxset_get_by_index(v->values[stream_type].idx_volume_values, volume_level);
-                if (value) {
-                    volume_linear = *value;
-                    /* Apply master volume */
-                    v = pa_hashmap_get(volumes, MASTER_VOLUME_TYPE);
-                    if (v && !v->is_hal_volume_type)
-                        volume_linear *= (double)(v->values[stream_type].current_level)/100.0;
-                } else {
-                    pa_log_error("failed to pa_idxset_get_by_index()");
-                    ret = -1;
-                    goto FAILURE;
-                }
-            } else {
-                pa_log_error("could not get volume value for stream_type[%d], volume_type[%s], level[%u]",
-                             stream_type, volume_type, volume_level);
-                ret = -1;
-                goto FAILURE;
-            }
-        } else {
-            pa_log_error("could not get volumes in volume infos, stream_type(%d), volume_type(%s)",
-                         stream_type, volume_type);
-            ret = -1;
-            goto FAILURE;
+        volumes = m->volume_infos;
+
+        v = pa_hashmap_get(volumes, volume_type);
+        if (!v || !(v->values[stream_type].idx_volume_values)) {
+            pa_log_error("could not get volume value for stream_type[%d], volume_type[%s], level[%u]",
+                         stream_type, volume_type, volume_level);
+            return -1;
+        }
+
+        if (!(value = pa_idxset_get_by_index(v->values[stream_type].idx_volume_values, volume_level))) {
+            pa_log_error("failed to pa_idxset_get_by_index()");
+            return -1;
         }
+
+        volume_linear = *value;
+        /* Apply master volume */
+        v = pa_hashmap_get(volumes, MASTER_VOLUME_TYPE);
+        if (v && !v->is_hal_volume_type)
+            volume_linear *= (double)(v->values[stream_type].current_level) / 100.0;
     }
 
     *volume_value = volume_linear;
 
     pa_log_debug("get_volume_value() : stream_type[%d], volume_type[%s], level[%u], value[%f]",
                  stream_type, volume_type, volume_level, volume_linear);
-FAILURE:
-    return ret;
+
+    return 0;
 }
 
 int32_t set_volume_level_by_type(pa_stream_manager *m, stream_type_t stream_type, const char *volume_type, uint32_t volume_level) {
@@ -254,7 +246,9 @@ int32_t set_volume_level_by_type(pa_stream_manager *m, stream_type_t stream_type
     void *s = NULL;
     pa_hashmap *volumes = NULL;
     pa_cvolume cv;
+
     pa_assert(m);
+    pa_assert(m->volume_infos);
     pa_assert(volume_type);
 
     /* Check if it is related to HAL volume */
@@ -267,43 +261,40 @@ int32_t set_volume_level_by_type(pa_stream_manager *m, stream_type_t stream_type
         if (pa_hal_manager_set_volume_level(m->hal, volume_type, CONVERT_TO_HAL_DIRECTION(stream_type), volume_level))
             return -1;
 
-    if ((volumes = m->volume_infos)) {
-        if ((v = pa_hashmap_get(volumes, volume_type))) {
-            if (pa_streq(volume_type, MASTER_VOLUME_TYPE) && MASTER_VOLUME_LEVEL_MAX < volume_level) {
-                pa_log_error("could not set volume level of MASTER type, out of range(%u)", volume_level);
-                return -1;
-            }
-            v->values[stream_type].current_level = volume_level;
-            if (is_hal_volume && pa_streq(volume_type, MASTER_VOLUME_TYPE)) {
-                /* no need to update the value of pulseaudio stream */
-                return 0;
-            }
-        } else {
-            pa_log_error("could not get volume_info, stream_type(%d), volume_type(%s)", stream_type, volume_type);
-            return -1;
-        }
-    } else {
-        pa_log_error("could not get volumes in volume infos, stream_type(%d), volume_type(%s)", stream_type, volume_type);
+    volumes = m->volume_infos;
+
+    if (!(v = pa_hashmap_get(volumes, volume_type))) {
+        pa_log_error("could not get volume_info, stream_type(%d), volume_type(%s)", stream_type, volume_type);
+        return -1;
+    }
+
+    if (pa_streq(volume_type, MASTER_VOLUME_TYPE) && MASTER_VOLUME_LEVEL_MAX < volume_level) {
+        pa_log_error("could not set volume level of MASTER type, out of range(%u)", volume_level);
         return -1;
     }
 
+    v->values[stream_type].current_level = volume_level;
+    if (is_hal_volume && pa_streq(volume_type, MASTER_VOLUME_TYPE)) {
+        /* no need to update the value of pulseaudio stream */
+        return 0;
+    }
+
     if (!pa_streq(volume_type, MASTER_VOLUME_TYPE)) {
         if (get_volume_value(m, stream_type, is_hal_volume, volume_type, volume_level, &volume_linear))
             return -1;
 
         PA_IDXSET_FOREACH(s, stream_type == STREAM_SINK_INPUT ? m->core->sink_inputs : m->core->source_outputs, idx) {
-            if ((volume_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
-                /* Get modifier for gain */
-                modifier_gain = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_GAIN_TYPE);
-            } else {
+            if (!(volume_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE)))
                 continue;
-            }
+
+            /* Get modifier for gain */
+            modifier_gain = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_GAIN_TYPE);
+
             /* Update volume level of stream if it has requested the volume type */
             if (pa_streq(volume_type_str, volume_type)) {
                 if (modifier_gain) {
                     if (m->volume_modifiers) {
-                       modifier_gain_value = pa_hashmap_get(m->volume_modifiers, modifier_gain);
-                        if (modifier_gain_value) {
+                       if ((modifier_gain_value = pa_hashmap_get(m->volume_modifiers, modifier_gain))) {
                             volume_linear *= (*modifier_gain_value);
                             pa_log_info("set_volume_level_by_type() : apply the modifier for the gain value(%s=>%f), result volume_linear(%f)",
                                         modifier_gain, *modifier_gain_value, volume_linear);
@@ -319,29 +310,24 @@ int32_t set_volume_level_by_type(pa_stream_manager *m, stream_type_t stream_type
         }
     } else {
         PA_IDXSET_FOREACH(s, stream_type == STREAM_SINK_INPUT ? m->core->sink_inputs : m->core->source_outputs, idx) {
-            if ((volume_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
-                /* Get modifier for gain */
-                modifier_gain = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_GAIN_TYPE);
-                /* Check if it is related to HAL volume */
-                if (is_hal_volume_by_type(m, volume_type_str, &is_hal_volume)) {
-                    pa_log_error("failed to is_hal_volume_by_type(), volume_type(%s)", volume_type_str);
-                    continue;
-                 }
-                /* Get volume level of this type */
-                if ((v = pa_hashmap_get(volumes, volume_type_str)))
-                    volume_level = v->values[stream_type].current_level;
-                else
-                    continue;
-            } else {
+            if (!(volume_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE)))
                 continue;
-            }
+
+            /* Get modifier for gain */
+            modifier_gain = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_GAIN_TYPE);
+
+            /* Get volume level of this type */
+            if (!(v = pa_hashmap_get(volumes, volume_type_str)))
+                continue;
+
+            volume_level = v->values[stream_type].current_level;
+
             if (get_volume_value(m, stream_type, is_hal_volume, volume_type_str, volume_level, &volume_linear))
                 continue;
 
             if (modifier_gain) {
                 if (m->volume_modifiers) {
-                   modifier_gain_value = pa_hashmap_get(m->volume_modifiers, modifier_gain);
-                    if (modifier_gain_value) {
+                   if ((modifier_gain_value = pa_hashmap_get(m->volume_modifiers, modifier_gain))) {
                         volume_linear *= (*modifier_gain_value);
                         pa_log_info("set_volume_level_by_type() : apply the modifier for the gain value(%s=>%f), result volume_linear(%f)",
                                     modifier_gain, *modifier_gain_value, volume_linear);
@@ -363,11 +349,12 @@ int32_t set_volume_level_by_type(pa_stream_manager *m, stream_type_t stream_type
 }
 
 int32_t get_volume_level_by_type(pa_stream_manager *m, pa_volume_get_command_t command, stream_type_t stream_type, const char *volume_type, uint32_t *volume_level) {
-    int32_t ret = 0;
     pa_bool_t is_hal_volume = FALSE;
     volume_info *v = NULL;
     pa_hashmap *volumes = NULL;
+
     pa_assert(m);
+    pa_assert(m->volume_infos);
     pa_assert(volume_type);
 
     /* Check if it is related to HAL volume */
@@ -376,25 +363,22 @@ int32_t get_volume_level_by_type(pa_stream_manager *m, pa_volume_get_command_t c
         return -1;
     }
 
+    volumes = m->volume_infos;
+
     if (command == GET_VOLUME_CURRENT_LEVEL) {
         /* Get level */
         if (is_hal_volume) {
             /* from HAL */
             if (pa_hal_manager_get_volume_level(m->hal, volume_type, CONVERT_TO_HAL_DIRECTION(stream_type), volume_level))
-                ret = -1;
+                return -1;
         } else {
             /* from stream-manager */
-            if ((volumes = m->volume_infos)) {
-                if ((v = pa_hashmap_get(volumes, volume_type)))
-                    *volume_level = v->values[stream_type].current_level;
-                else {
-                    pa_log_error("could not get volume_info, stream_type(%d), volume_type(%s)", stream_type, volume_type);
-                    return -1;
-                }
-            } else {
-                pa_log_error("could not get volumes in volume infos, stream_type(%d), volume_type(%s)", stream_type, volume_type);
+            if (!(v = pa_hashmap_get(volumes, volume_type))) {
+                pa_log_error("could not get volume_info, stream_type(%d), volume_type(%s)", stream_type, volume_type);
                 return -1;
             }
+            *volume_level = v->values[stream_type].current_level;
+
         }
     } else if (command == GET_VOLUME_MAX_LEVEL) {
         /* If it is the master volume type */
@@ -405,26 +389,21 @@ int32_t get_volume_level_by_type(pa_stream_manager *m, pa_volume_get_command_t c
             if (is_hal_volume) {
                 /* from HAL */
                 if (pa_hal_manager_get_volume_level_max(m->hal, volume_type, CONVERT_TO_HAL_DIRECTION(stream_type), volume_level))
-                    ret = -1;
+                    return -1;
             } else {
                 /* from stream-manager */
-                if ((volumes = m->volume_infos)) {
-                    v = pa_hashmap_get(volumes, volume_type);
-                    if (v && v->values[stream_type].idx_volume_values)
-                        *volume_level = pa_idxset_size(v->values[stream_type].idx_volume_values);
-                    else {
-                        pa_log_error("could not get volume_info, stream_type(%d), volume_type(%s)", stream_type, volume_type);
-                        return -1;
-                    }
-                } else {
-                    pa_log_error("could not get volumes in volume infos, stream_type(%d), volume_type(%s)", stream_type, volume_type);
+                v = pa_hashmap_get(volumes, volume_type);
+                if (v && v->values[stream_type].idx_volume_values)
+                    *volume_level = pa_idxset_size(v->values[stream_type].idx_volume_values);
+                else {
+                    pa_log_error("could not get volume_info, stream_type(%d), volume_type(%s)", stream_type, volume_type);
                     return -1;
                 }
             }
         }
     }
 
-    return ret;
+    return 0;
 }
 
 int32_t set_volume_level_by_idx(pa_stream_manager *m, stream_type_t stream_type, uint32_t idx, uint32_t volume_level) {
@@ -432,15 +411,14 @@ int32_t set_volume_level_by_idx(pa_stream_manager *m, stream_type_t stream_type,
     void *s = NULL;
     pa_cvolume cv;
     double volume_linear = 1.0;
+    double *modifier_gain_value = NULL;
     const char *volume_type_str = NULL;
     const char *modifier_gain = NULL;
+
     pa_assert(m);
 
     s = pa_idxset_get_by_index(stream_type == STREAM_SINK_INPUT ? m->core->sink_inputs : m->core->source_outputs, idx);
-    if ((volume_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
-        /* Get modifier for gain */
-        modifier_gain = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_GAIN_TYPE);
-    } else {
+    if (!(volume_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
         pa_log_debug("idx[%u] doesn't have volume type", idx);
         return -1;
     }
@@ -455,11 +433,12 @@ int32_t set_volume_level_by_idx(pa_stream_manager *m, stream_type_t stream_type,
         if (pa_hal_manager_set_volume_level(m->hal, volume_type_str, CONVERT_TO_HAL_DIRECTION(stream_type), volume_level))
             return -1;
 
+    /* Get modifier for gain */
+    modifier_gain = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_GAIN_TYPE);
+
     if (!get_volume_value(m, stream_type, is_hal_volume, volume_type_str, volume_level, &volume_linear)) {
         if (modifier_gain) {
-            double *modifier_gain_value = NULL;
-            modifier_gain_value = pa_hashmap_get(m->volume_modifiers, modifier_gain);
-            if (modifier_gain_value) {
+            if ((modifier_gain_value = pa_hashmap_get(m->volume_modifiers, modifier_gain))) {
                 volume_linear *= (*modifier_gain_value);
                 pa_log_info("set_volume_level_by_idx() : apply the modifier for the gain value(%s=>%f), result volume_linear(%f)",
                             modifier_gain, *modifier_gain_value, volume_linear);
@@ -483,13 +462,11 @@ int32_t set_volume_level_with_new_data(pa_stream_manager *m, void *stream, strea
     double volume_linear = 1.0;
     const char *volume_type_str = NULL;
     const char *modifier_gain = NULL;
+
     pa_assert(m);
     pa_assert(stream);
 
-    if ((volume_type_str = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
-        /* Get modifier for gain */
-        modifier_gain = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_GAIN_TYPE);
-    } else {
+    if (!(volume_type_str = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
         pa_log_debug("new_data[%p] doesn't have volume type", stream);
         return -1;
     }
@@ -504,11 +481,13 @@ int32_t set_volume_level_with_new_data(pa_stream_manager *m, void *stream, strea
         if (pa_hal_manager_set_volume_level(m->hal, volume_type_str, CONVERT_TO_HAL_DIRECTION(stream_type), volume_level))
             return -1;
 
+    /* Get modifier for gain */
+    modifier_gain = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_GAIN_TYPE);
+
     if (!get_volume_value(m, stream_type, is_hal_volume, volume_type_str, volume_level, &volume_linear)) {
         if (modifier_gain) {
             double *modifier_gain_value = NULL;
-            modifier_gain_value = pa_hashmap_get(m->volume_modifiers, modifier_gain);
-            if (modifier_gain_value) {
+            if ((modifier_gain_value = pa_hashmap_get(m->volume_modifiers, modifier_gain))) {
                 volume_linear *= (*modifier_gain_value);
                 pa_log_info("set_volume_level_by_idx() : apply the modifier for the gain value(%s=>%f), result volume_linear(%f)",
                             modifier_gain, *modifier_gain_value, volume_linear);
@@ -530,10 +509,11 @@ int32_t set_volume_mute_by_type(pa_stream_manager *m, stream_type_t stream_type,
     pa_bool_t is_hal_volume = FALSE;
     volume_info *v = NULL;
     void *s = NULL;
-    pa_hashmap *volumes = NULL;
     uint32_t idx;
     const char *volume_type_str = NULL;
+
     pa_assert(m);
+    pa_assert(m->volume_infos);
     pa_assert(volume_type);
 
     /* Check if it is related to HAL volume */
@@ -547,25 +527,18 @@ int32_t set_volume_mute_by_type(pa_stream_manager *m, stream_type_t stream_type,
             return -1;
 
     /* Set mute */
-    if ((volumes = m->volume_infos)) {
-        v = pa_hashmap_get(volumes, volume_type);
-        if (v)
-            v->values[stream_type].is_muted = volume_mute;
-        else {
-            pa_log_error("could not get volume_info, stream_type(%d), volume_type(%s)", stream_type, volume_type);
-            return -1;
-        }
-    } else {
-        pa_log_error("could not get volumes in volume infos, volume_type(%s)", volume_type);
+    if (!(v = pa_hashmap_get(m->volume_infos, volume_type))) {
+        pa_log_error("could not get volume_info, stream_type(%d), volume_type(%s)", stream_type, volume_type);
         return -1;
     }
 
+    v->values[stream_type].is_muted = volume_mute;
+
     PA_IDXSET_FOREACH(s, (stream_type == STREAM_SINK_INPUT) ? m->core->sink_inputs : m->core->source_outputs, idx) {
-        if ((volume_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
-            /* do nothing */
-        } else {
+        if (!(volume_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
             continue;
         }
+
         /* Update mute of stream if it has requested the volume type */
         if (pa_streq(volume_type_str, volume_type)) {
             if (stream_type == STREAM_SINK_INPUT)
@@ -582,24 +555,20 @@ int32_t set_volume_mute_by_type(pa_stream_manager *m, stream_type_t stream_type,
 
 int32_t get_volume_mute_by_type(pa_stream_manager *m, stream_type_t stream_type, const char *volume_type, pa_bool_t *volume_mute) {
     volume_info *v = NULL;
-    pa_hashmap *volumes = NULL;
+
     pa_assert(m);
+    pa_assert(m->volume_infos);
     pa_assert(volume_type);
     pa_assert(volume_mute);
 
     /* Get mute */
-    if ((volumes = m->volume_infos)) {
-        if ((v = pa_hashmap_get(volumes, volume_type)))
-            *volume_mute = v->values[stream_type].is_muted;
-        else {
-            pa_log_error("could not get volume_info, stream_type(%d), volume_type(%s)", stream_type, volume_type);
-            return -1;
-        }
-    } else {
-        pa_log_error("could not get volumes in volume infos, volume_type(%s)", volume_type);
+    if (!(v = pa_hashmap_get(m->volume_infos, volume_type))) {
+        pa_log_error("could not get volume_info, stream_type(%d), volume_type(%s)", stream_type, volume_type);
         return -1;
     }
 
+    *volume_mute = v->values[stream_type].is_muted;
+
     pa_log_info("pa_stream_manager_volume_get_mute, volume_type:%s mute:%d", volume_type, *volume_mute);
 
     return 0;
@@ -610,33 +579,22 @@ int32_t set_volume_mute_by_idx(pa_stream_manager *m, uint32_t stream_idx, stream
     uint32_t idx = 0;
     const char *volume_type_str = NULL;
     volume_info *v = NULL;
-    pa_hashmap *volumes = NULL;
     pa_bool_t muted_by_type = FALSE;
+
     pa_assert(m);
+    pa_assert(m->volume_infos);
 
     pa_log_info("set_volume_mute_by_idx, stream_idx:%u stream_type:%d mute:%d", stream_idx, stream_type, volume_mute);
 
-    if (stream_idx != (uint32_t)-1) {
-        if ((s = pa_idxset_get_by_index((stream_type == STREAM_SINK_INPUT) ? m->core->sink_inputs : m->core->source_outputs, stream_idx))) {
-            if ((volume_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
-                /* do nothing */
-            } else {
-                pa_log_warn("stream[%d] doesn't have volume type", stream_idx);
-            }
-        } else {
-            pa_log_warn("stream[%u] doesn't exist", stream_idx);
-        }
+    if (!(s = pa_idxset_get_by_index((stream_type == STREAM_SINK_INPUT) ? m->core->sink_inputs : m->core->source_outputs, stream_idx))) {
+        pa_log_warn("stream[%u] doesn't exist", stream_idx);
+        return -1;
     }
 
-    /* Get mute state of the volume type of this stream */
-    if (volume_type_str) {
-        if ((volumes = m->volume_infos)) {
-            if ((v = pa_hashmap_get(volumes, volume_type_str)))
-                muted_by_type = v->values[stream_type].is_muted;
-        } else {
-            pa_log_error("could not get volumes in volume map, stream_type(%d), volume_type(%s)", stream_type, volume_type_str);
-            return -1;
-        }
+    if ((volume_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(s, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
+        /* Get mute state of the volume type of this stream */
+        if ((v = pa_hashmap_get(m->volume_infos, volume_type_str)))
+            muted_by_type = v->values[stream_type].is_muted;
     }
 
     if (!muted_by_type) {
@@ -656,9 +614,9 @@ int32_t set_volume_mute_by_idx(pa_stream_manager *m, uint32_t stream_idx, stream
 }
 
 int32_t get_volume_mute_by_idx(pa_stream_manager *m, uint32_t stream_idx, stream_type_t stream_type, pa_bool_t *volume_mute) {
-    int32_t ret = 0;
     void *s = NULL;
     uint32_t idx = 0;
+
     pa_assert(m);
     pa_assert(volume_mute);
 
@@ -673,24 +631,23 @@ int32_t get_volume_mute_by_idx(pa_stream_manager *m, uint32_t stream_idx, stream
         }
     }
     if (!s)
-        ret = -1;
+        return -1;
 
-    pa_log_info("get_volume_mute_by_idx, stream_idx:%u stream_type:%d mute:%d, ret:%d", stream_idx, stream_type, *volume_mute, ret);
+    pa_log_info("get_volume_mute_by_idx, stream_idx:%u stream_type:%d mute:%d", stream_idx, stream_type, *volume_mute);
 
-    return ret;
+    return 0;
 }
 
 int32_t set_volume_mute_with_new_data(pa_stream_manager *m, void *stream, stream_type_t stream_type, pa_bool_t volume_mute) {
     pa_bool_t is_hal_volume = FALSE;
     const char *volume_type_str = NULL;
+
     pa_assert(m);
     pa_assert(stream);
 
     pa_log_info("set_volume_mute_with_new_data, stream_type:%d mute:%d", stream_type, volume_mute);
 
-    if ((volume_type_str = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
-        /* do nothing */
-    } else {
+    if (!(volume_type_str = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
         pa_log_debug("new_data[%p] doesn't have volume type", stream);
         return -1;
     }
@@ -721,23 +678,23 @@ static void dump_volumes(pa_stream_manager *m) {
     double *gain_value = NULL;
     void *state = NULL;
     uint32_t idx = 0;
+
     pa_assert(m);
+    pa_assert(m->volume_infos);
 
     pa_log_debug("==========[START volume infos dump]==========");
-    while (m->volume_infos && (s = pa_hashmap_iterate(m->volume_infos, &state, (const void**)&volume_type))) {
-        if (s) {
-            pa_log_debug("[volume_type : %s]", volume_type);
-            pa_log_debug("  - is_hal_volume_type : %d", s->is_hal_volume_type);
-            if (s->values[STREAM_DIRECTION_IN].idx_volume_values) {
-                pa_log_debug("  - (in)max level          : %u", pa_idxset_size(s->values[STREAM_DIRECTION_IN].idx_volume_values));
-                PA_IDXSET_FOREACH(level, s->values[STREAM_DIRECTION_IN].idx_volume_values, idx)
-                    pa_log_debug("  - (in)value[%u]          : %f", idx, *level);
-            }
-            if (s->values[STREAM_DIRECTION_OUT].idx_volume_values) {
-                pa_log_debug("  - (out)max level          : %u", pa_idxset_size(s->values[STREAM_DIRECTION_OUT].idx_volume_values));
-                PA_IDXSET_FOREACH(level, s->values[STREAM_DIRECTION_OUT].idx_volume_values, idx)
-                    pa_log_debug("  - (out)value[%u]          : %f", idx, *level);
-            }
+    while ((s = pa_hashmap_iterate(m->volume_infos, &state, (const void**)&volume_type))) {
+        pa_log_debug("[volume_type : %s]", volume_type);
+        pa_log_debug("  - is_hal_volume_type : %d", s->is_hal_volume_type);
+        if (s->values[STREAM_DIRECTION_IN].idx_volume_values) {
+            pa_log_debug("  - (in)max level          : %u", pa_idxset_size(s->values[STREAM_DIRECTION_IN].idx_volume_values));
+            PA_IDXSET_FOREACH(level, s->values[STREAM_DIRECTION_IN].idx_volume_values, idx)
+                pa_log_debug("  - (in)value[%u]          : %f", idx, *level);
+        }
+        if (s->values[STREAM_DIRECTION_OUT].idx_volume_values) {
+            pa_log_debug("  - (out)max level          : %u", pa_idxset_size(s->values[STREAM_DIRECTION_OUT].idx_volume_values));
+            PA_IDXSET_FOREACH(level, s->values[STREAM_DIRECTION_OUT].idx_volume_values, idx)
+                pa_log_debug("  - (out)value[%u]          : %f", idx, *level);
         }
     }
     state = NULL;
@@ -752,6 +709,7 @@ int32_t init_volumes(pa_stream_manager *m) {
     int ret = 0;
     void *state = NULL;
     volume_info *v = NULL;
+
     pa_assert(m);
 
     /* For now, we only care about volumes for the output stream */
@@ -797,6 +755,7 @@ void deinit_volumes(pa_stream_manager *m) {
     double *level = NULL;
     double *gain = NULL;
     int i = 0;
+
     pa_assert(m);
 
     if (m->volume_infos) {
@@ -821,6 +780,7 @@ void deinit_volumes(pa_stream_manager *m) {
 
 int32_t pa_stream_manager_volume_get_max_level(pa_stream_manager *m, stream_type_t stream_type, const char *volume_type, uint32_t *volume_level) {
     int32_t ret = 0;
+
     pa_assert(m);
     pa_assert(volume_type);
 
@@ -833,6 +793,7 @@ int32_t pa_stream_manager_volume_get_max_level(pa_stream_manager *m, stream_type
 
 int32_t pa_stream_manager_volume_get_level(pa_stream_manager *m, stream_type_t stream_type, const char *volume_type, uint32_t *volume_level) {
     int32_t ret = 0;
+
     pa_assert(m);
     pa_assert(volume_type);
 
@@ -845,6 +806,7 @@ int32_t pa_stream_manager_volume_get_level(pa_stream_manager *m, stream_type_t s
 
 int32_t pa_stream_manager_volume_set_level(pa_stream_manager *m, stream_type_t stream_type, const char *volume_type, uint32_t volume_level) {
     int32_t ret = 0;
+
     pa_assert(m);
     pa_assert(volume_type);
 
@@ -862,11 +824,3 @@ int32_t pa_stream_manager_volume_get_mute(pa_stream_manager *m, stream_type_t st
 int32_t pa_stream_manager_volume_set_mute(pa_stream_manager *m, stream_type_t stream_type, const char *volume_type, pa_bool_t volume_mute) {
     return set_volume_mute_by_type(m, stream_type, volume_type, volume_mute);
 }
-
-int32_t pa_stream_manager_volume_get_mute_by_idx(pa_stream_manager *m, uint32_t stream_idx, stream_type_t stream_type, pa_bool_t *volume_mute) {
-    return get_volume_mute_by_idx(m, stream_idx, stream_type, volume_mute);
-}
-
-int32_t pa_stream_manager_volume_set_mute_by_idx(pa_stream_manager *m, uint32_t stream_idx, stream_type_t stream_type, pa_bool_t volume_mute) {
-    return set_volume_mute_by_idx(m, stream_idx, stream_type, volume_mute);
-}
index 2f0340e..d8585f0 100644 (file)
@@ -2194,15 +2194,15 @@ static process_stream_result_t process_stream(pa_stream_manager *m, void *stream
                 req_format = pa_idxset_first(((pa_sink_input_new_data*)stream)->req_formats, NULL);
                 if (req_format && req_format->plist) {
                     /* set sample_spec */
-                    rate_str = pa_proplist_gets(req_format->plist, PA_PROP_FORMAT_RATE);
-                    ch_str = pa_proplist_gets(req_format->plist, PA_PROP_FORMAT_CHANNELS);
                     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);
-                    pa_log_info("req rate(%s), req ch(%s), req format(%s)", rate_str, ch_str, format_str);
-                    if (ch_str)
-                        ((pa_sink_input_new_data*)stream)->sample_spec.channels = atoi(ch_str);
-                    if (rate_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_info("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),
@@ -2415,15 +2415,13 @@ static process_stream_result_t process_stream(pa_stream_manager *m, void *stream
             v = pa_hashmap_get(m->volume_infos, si_volume_type_str);
             if (v && v->values[type].idx_volume_values) {
                 /* Update volume-level */
-                volume_ret = set_volume_level_with_new_data(m, stream, type, v->values[type].current_level);
-                if (volume_ret)
+                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_by_idx(), stream_type(%d), level(%u), ret(0x%x)",
-                        type, v->values[type].current_level, volume_ret);
+                                 type, v->values[type].current_level, volume_ret);
                 /* Update volume-mute */
-                volume_ret = set_volume_mute_with_new_data(m, stream, type, v->values[type].is_muted);
-                if (volume_ret)
+                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_by_idx(), stream_type(%d), mute(%d), ret(0x%x)",
-                        type, v->values[type].is_muted, volume_ret);
+                                 type, v->values[type].is_muted, volume_ret);
             }
         }
 
@@ -2705,51 +2703,55 @@ static void find_next_device_for_auto_route(pa_stream_manager *m, stream_route_t
     dm_device* latest_device = NULL;
 
     pa_assert(m);
+    pa_assert(m->stream_infos);
     pa_assert(role);
     pa_assert(cur_device_type);
     pa_assert(next_device);
     pa_assert((route_type == STREAM_ROUTE_TYPE_AUTO || route_type == STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED));
 
     *next_device = NULL;
-    if (m->stream_infos) {
-        si = pa_hashmap_get(m->stream_infos, role);
-        if (si && si->route_type == route_type) {
-            devices = (stream_type == STREAM_SINK_INPUT) ? si->idx_avail_out_devices : si->idx_avail_in_devices;
-            if (devices) {
-                if (route_type == STREAM_ROUTE_TYPE_AUTO) {
-                    PA_IDXSET_FOREACH(device_type, devices, idx) {
-                        if (ret_next) {
-                            if ((*next_device = pa_device_manager_get_device(m->dm, device_type))) {
-                                pa_log_debug("found next device[%s, %p]", device_type, *next_device);
-                                break;
-                            } else
-                                continue;
-                        }
-                        if (pa_streq(device_type, cur_device_type)) {
-                            ret_next = TRUE;
-                            continue;
-                        }
-                    }
 
-                } else if (route_type == STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED) {
-                    PA_IDXSET_FOREACH(device_type, devices, idx) {
-                        if ((*next_device = pa_device_manager_get_device(m->dm, device_type))) {
-                            creation_time = pa_device_manager_get_device_creation_time(*next_device);
-                            if (!latest_device || (latest_creation_time <= creation_time)) {
-                                latest_device = *next_device;
-                                latest_creation_time = creation_time;
-                            }
-                        }
-                    }
-                    *next_device = latest_device;
-                    pa_log_debug("found next device[%s, %p], creation_time[%llu]", device_type, *next_device, latest_creation_time);
+    if (!(si = pa_hashmap_get(m->stream_infos, role))) {
+        pa_log_warn("not support this role[%s]", role);
+        return;
+    }
+    if (si->route_type != route_type) {
+        pa_log_warn("skip this route_type[%d]", si->route_type);
+        return;
+    }
+
+    if (!(devices = (stream_type == STREAM_SINK_INPUT) ? si->idx_avail_out_devices : si->idx_avail_in_devices)) {
+        pa_log_error("could not found a device list for this role[%s], stream type[%d]", role, stream_type);
+        return;
+    }
+
+    if (route_type == STREAM_ROUTE_TYPE_AUTO) {
+        PA_IDXSET_FOREACH(device_type, devices, idx) {
+            if (pa_streq(device_type, cur_device_type)) {
+                ret_next = TRUE;
+                continue;
+            }
+            if (ret_next) {
+                if ((*next_device = pa_device_manager_get_device(m->dm, device_type))) {
+                    pa_log_debug("found next device[%s, %p]", device_type, *next_device);
+                    break;
+                } else
+                    continue;
+            }
+        }
+    } else if (route_type == STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED) {
+        PA_IDXSET_FOREACH(device_type, devices, idx) {
+            if ((*next_device = pa_device_manager_get_device(m->dm, device_type))) {
+                creation_time = pa_device_manager_get_device_creation_time(*next_device);
+                if (!latest_device || (latest_creation_time <= creation_time)) {
+                    latest_device = *next_device;
+                    latest_creation_time = creation_time;
                 }
-            } else
-                pa_log_error("could not found a device list for this role[%s], stream type[%d]", role, stream_type);
-        } else
-            pa_log_warn("not support this role[%s]", role);
-    } else
-        pa_log_error("stream_infos is null");
+            }
+        }
+        *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("next_device is [%p] for role[%s]/route_type[%d]/stream_type[%d]", *next_device, role, route_type, stream_type);
 
@@ -2763,42 +2765,42 @@ static void is_available_device_for_auto_route(pa_stream_manager *m, stream_rout
     char *device_type = NULL;
 
     pa_assert(m);
+    pa_assert(m->stream_infos);
     pa_assert(role);
     pa_assert(cur_device_type);
     pa_assert(new_device_type);
     pa_assert(available);
     pa_assert((route_type == STREAM_ROUTE_TYPE_AUTO || route_type == STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED));
 
-    if (m->stream_infos) {
-        si = pa_hashmap_get(m->stream_infos, role);
-        if (si && si->route_type == route_type) {
-            *available = FALSE;
-            devices = (stream_type == STREAM_SINK_INPUT) ? si->idx_avail_out_devices : si->idx_avail_in_devices;
-            if (devices) {
-                PA_IDXSET_FOREACH(device_type, devices, idx) {
-                    if (route_type == STREAM_ROUTE_TYPE_AUTO) {
-                        if (cur_device_type && pa_streq(device_type, cur_device_type)) {
-                            pa_log_debug("cur_device[%s]'s priority is more higher than new_device[%s]", cur_device_type, new_device_type);
-                            break;
-                        }
-                    }
-                    if (pa_streq(device_type, new_device_type)) {
-                        *available = TRUE;
-                        break;
-                    }
-                }
-            } else {
-                pa_log_error("could not found a device list for this role[%s], stream type[%d]", role, stream_type);
-                *available = FALSE;
+    *available = FALSE;
+
+    if (!(si = pa_hashmap_get(m->stream_infos, role))) {
+        pa_log_warn("not support this role[%s]", role);
+        return;
+    }
+    if (si->route_type != route_type) {
+        pa_log_warn("skip this route_type[%d]", si->route_type);
+        return;
+    }
+
+    if (!(devices = (stream_type == STREAM_SINK_INPUT) ? si->idx_avail_out_devices : si->idx_avail_in_devices)) {
+        pa_log_error("could not found a device list for this role[%s], stream type[%d]", role, stream_type);
+        return;
+    }
+
+    PA_IDXSET_FOREACH(device_type, devices, idx) {
+        if (route_type == STREAM_ROUTE_TYPE_AUTO) {
+            if (pa_streq(device_type, cur_device_type)) {
+                pa_log_debug("cur_device[%s]'s priority is more higher than new_device[%s]", cur_device_type, new_device_type);
+                break;
             }
-        } else {
-            pa_log_warn("not support this role[%s]", role);
-            *available = FALSE;
         }
-    } else {
-        pa_log_error("stream_infos is null");
-        *available = FALSE;
+        if (pa_streq(device_type, new_device_type)) {
+            *available = TRUE;
+            break;
+        }
     }
+
     pa_log_debug("is new_device[%s] available for role[%s]/stream_type[%d]:%d", new_device_type, role, stream_type, *available);
 
     return;
@@ -3176,7 +3178,7 @@ static void subscribe_cb(pa_core *core, pa_subscription_event_type_t t, uint32_t
         return;
     }
     name = pa_proplist_gets(client->proplist, PA_PROP_APPLICATION_NAME);
-    if (name && !pa_streq(name, STREAM_MANAGER_CLIENT_NAME)) {
+    if (!name || (name && !pa_streq(name, STREAM_MANAGER_CLIENT_NAME))) {
         pa_log_warn(" - this is not a client(%s) that we should take care of, skip it", name);
         return;
     }
@@ -3311,20 +3313,20 @@ int32_t pa_stream_manager_get_route_type(void *stream, pa_bool_t origins_from_ne
         route_type_str = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, stream_type), PA_PROP_MEDIA_ROLE_ROUTE_TYPE);
     else
         route_type_str = pa_proplist_gets(GET_STREAM_PROPLIST(stream, stream_type), PA_PROP_MEDIA_ROLE_ROUTE_TYPE);
-
-    if (route_type_str) {
-        if (!pa_atoi(route_type_str, (int32_t*)stream_route_type))
-            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);
-        else {
-            pa_log_error("could not convert route_type_str(%s) to int", route_type_str);
-            return -1;
-        }
-    } else {
+    if (!route_type_str) {
         pa_log_warn("could not get route type from the stream(%p)", stream);
         return -1;
+     }
+
+    if (pa_atoi(route_type_str, (int32_t*)stream_route_type)) {
+        pa_log_error("could not convert route_type_str(%s) to int", route_type_str);
+        return -1;
     }
 
-       return 0;
+    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;
 }
 
 pa_stream_manager* pa_stream_manager_init(pa_core *c) {