stream-manager/hal-manager: revise codes for readability and rename functions 29/51229/3 accepted/tizen/mobile/20151106.045849 accepted/tizen/mobile/20151106.050120 accepted/tizen/tv/20151106.045859 accepted/tizen/tv/20151106.050129 accepted/tizen/wearable/20151106.045914 accepted/tizen/wearable/20151106.050140 submit/tizen/20151105.120840 submit/tizen/20151105.121151 submit/tizen/20151106.015515
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 5 Nov 2015 11:40:02 +0000 (20:40 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 5 Nov 2015 11:44:35 +0000 (20:44 +0900)
[Version] 5.0.11
[Profile] Common
[Issue Type] Code enhancement

Change-Id: I053cba292f891819013bc36b346b13d3e6dd7990
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/pulseaudio-modules-tizen.spec
src/hal-manager.c
src/hal-manager.h
src/module-policy.c
src/stream-manager-priv.h
src/stream-manager-volume.c
src/stream-manager.c

index c88ac51e710369d12b326b9f1203244c4da48538..f557b0aee9df7fb2c1674de22116c28b6e2be757 100644 (file)
@@ -3,7 +3,7 @@
 
 Name:             pulseaudio-modules-tizen
 Summary:          Improved Linux sound server
-Version:          5.0.10
+Version:          5.0.11
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index f23e8aa042f4abdd23402c3800513eb7603539cc..d102ca3b95392f57d43196aee7baaec318061ce9 100644 (file)
@@ -205,7 +205,7 @@ int32_t pa_hal_manager_get_volume_value(pa_hal_manager *h, const char *volume_ty
     return ret;
 }
 
-int32_t pa_hal_manager_get_mute(pa_hal_manager *h, const char *volume_type, io_direction_t direction, uint32_t *mute) {
+int32_t pa_hal_manager_get_volume_mute(pa_hal_manager *h, const char *volume_type, io_direction_t direction, uint32_t *mute) {
     int32_t ret = 0;
     audio_return_t hal_ret = AUDIO_RET_OK;
     audio_volume_info_t info = {NULL, NULL, 0};
@@ -224,7 +224,7 @@ int32_t pa_hal_manager_get_mute(pa_hal_manager *h, const char *volume_type, io_d
     return ret;
 }
 
-int32_t pa_hal_manager_set_mute(pa_hal_manager *h, const char *volume_type, io_direction_t direction, uint32_t mute) {
+int32_t pa_hal_manager_set_volume_mute(pa_hal_manager *h, const char *volume_type, io_direction_t direction, uint32_t mute) {
     int32_t ret = 0;
     audio_return_t hal_ret = AUDIO_RET_OK;
     audio_volume_info_t info = {NULL, NULL, 0};
index 40822a154aff99c932a8493522037094dd16c7a4..2154fb765f4be6d57af339d3fa1601646bdd1a3d 100644 (file)
@@ -50,8 +50,8 @@ int32_t pa_hal_manager_get_volume_level_max(pa_hal_manager *h, const char *volum
 int32_t pa_hal_manager_get_volume_level(pa_hal_manager *h, const char *volume_type, io_direction_t direction, uint32_t *level);
 int32_t pa_hal_manager_set_volume_level(pa_hal_manager *h, const char *volume_type, io_direction_t direction, uint32_t level);
 int32_t pa_hal_manager_get_volume_value(pa_hal_manager *h, const char *volume_type, const char *gain_type, io_direction_t direction, uint32_t level, double *value);
-int32_t pa_hal_manager_get_mute(pa_hal_manager *h, const char *volume_type, io_direction_t direction, uint32_t *mute);
-int32_t pa_hal_manager_set_mute(pa_hal_manager *h, const char *volume_type, io_direction_t direction, uint32_t mute);
+int32_t pa_hal_manager_get_volume_mute(pa_hal_manager *h, const char *volume_type, io_direction_t direction, uint32_t *mute);
+int32_t pa_hal_manager_set_volume_mute(pa_hal_manager *h, const char *volume_type, io_direction_t direction, uint32_t mute);
 int32_t pa_hal_manager_do_route(pa_hal_manager *h, hal_route_info *info);
 int32_t pa_hal_manager_update_route_option(pa_hal_manager *h, hal_route_option *option);
 int32_t pa_hal_manager_update_stream_connection_info(pa_hal_manager *h, hal_stream_connection_info *info);
index b321fccbce2be974c93b93832ec9322f1a606363..912fa386dbc38b29cca88f85a8967e9ffb758134 100644 (file)
@@ -43,7 +43,6 @@
 #include "communicator.h"
 #include "hal-manager.h"
 #include "stream-manager.h"
-#include "stream-manager-volume.h"
 #include "device-manager.h"
 
 PA_MODULE_AUTHOR("Seungbae Shin");
index f0fe81d9541b4f9b73a4c63a9b970c03107ae5d3..9e70effeb8c9fd809817ff74d831182855fd2b18 100644 (file)
@@ -20,11 +20,11 @@ typedef enum _focus_acquired_status {
     STREAM_FOCUS_ACQUIRED_CAPTURE  = 0x02,
 } focus_acquired_status_t;
 
-enum stream_direction {
-    STREAM_DIRECTION_IN,
+typedef enum _stream_direction {
     STREAM_DIRECTION_OUT,
+    STREAM_DIRECTION_IN,
     STREAM_DIRECTION_MAX,
-};
+} stream_direction_t;
 
 #define GET_STREAM_NEW_SAMPLE_SPEC(stream, type) \
       (type == STREAM_SINK_INPUT? ((pa_sink_input_new_data*)stream)->sample_spec : ((pa_source_output_new_data*)stream)->sample_spec)
index 2cf770bee777ae2479858222e8475404e66656ff..888e0b921752eb1fe051db143b636b736a33ec15 100644 (file)
@@ -203,15 +203,15 @@ static int get_volume_value(pa_stream_manager *m, stream_type_t stream_type, pa_
         /* Get value from stream-manager */
         if (volumes) {
             v = pa_hashmap_get(volumes, volume_type);
-            if (v && v->values[(stream_type==STREAM_SINK_INPUT)?STREAM_DIRECTION_OUT:STREAM_DIRECTION_IN].idx_volume_values) {
+            if (v && v->values[stream_type].idx_volume_values) {
                 double *value = NULL;
-                value = pa_idxset_get_by_index(v->values[(stream_type==STREAM_SINK_INPUT)?STREAM_DIRECTION_OUT:STREAM_DIRECTION_IN].idx_volume_values, volume_level);
+                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==STREAM_SINK_INPUT)?STREAM_DIRECTION_OUT:STREAM_DIRECTION_IN].current_level)/100.0;
+                        volume_linear *= (double)(v->values[stream_type].current_level)/100.0;
                 } else {
                     pa_log_error("failed to pa_idxset_get_by_index()");
                     ret = -1;
@@ -269,7 +269,7 @@ int32_t set_volume_level_by_type(pa_stream_manager *m, stream_type_t stream_type
                 pa_log_error("could not set volume level of MASTER type, out of range(%u)", volume_level);
                 return -1;
             }
-            v->values[(stream_type==STREAM_SINK_INPUT)?STREAM_DIRECTION_OUT:STREAM_DIRECTION_IN].current_level = volume_level;
+            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;
@@ -326,7 +326,7 @@ int32_t set_volume_level_by_type(pa_stream_manager *m, stream_type_t stream_type
                 /* Get volume level of this type */
                 v = pa_hashmap_get(volumes, volume_type_str);
                 if (v)
-                    volume_level = v->values[(stream_type==STREAM_SINK_INPUT)?STREAM_DIRECTION_OUT:STREAM_DIRECTION_IN].current_level;
+                    volume_level = v->values[stream_type].current_level;
                 else
                     continue;
             } else {
@@ -384,7 +384,7 @@ int32_t get_volume_level_by_type(pa_stream_manager *m, pa_volume_get_command_t c
             if (volumes) {
                 volume_info *v = pa_hashmap_get(volumes, volume_type);
                 if (v)
-                    *volume_level = v->values[(stream_type==STREAM_SINK_INPUT)?STREAM_DIRECTION_OUT:STREAM_DIRECTION_IN].current_level;
+                    *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;
@@ -409,8 +409,8 @@ int32_t get_volume_level_by_type(pa_stream_manager *m, pa_volume_get_command_t c
                 volumes = m->volume_infos;
                 if (volumes) {
                     volume_info *v = pa_hashmap_get(volumes, volume_type);
-                    if (v && v->values[(stream_type==STREAM_SINK_INPUT)?STREAM_DIRECTION_OUT:STREAM_DIRECTION_IN].idx_volume_values)
-                        *volume_level = pa_idxset_size(v->values[(stream_type==STREAM_SINK_INPUT)?STREAM_DIRECTION_OUT:STREAM_DIRECTION_IN].idx_volume_values);
+                    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;
@@ -541,7 +541,7 @@ int32_t set_volume_mute_by_type(pa_stream_manager *m, stream_type_t stream_type,
      }
 
     if (is_hal_volume)
-        if (pa_hal_manager_set_mute(m->hal, volume_type, (stream_type==STREAM_SINK_INPUT)?DIRECTION_OUT:DIRECTION_IN, (uint32_t)volume_mute))
+        if (pa_hal_manager_set_volume_mute(m->hal, volume_type, (stream_type==STREAM_SINK_INPUT)?DIRECTION_OUT:DIRECTION_IN, (uint32_t)volume_mute))
             return -1;
 
     /* Set mute */
@@ -549,7 +549,7 @@ int32_t set_volume_mute_by_type(pa_stream_manager *m, stream_type_t stream_type,
     if (volumes) {
         v = pa_hashmap_get(volumes, volume_type);
         if (v)
-            v->values[(stream_type==STREAM_SINK_INPUT)?STREAM_DIRECTION_OUT:STREAM_DIRECTION_IN].is_muted = volume_mute;
+            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;
@@ -591,7 +591,7 @@ int32_t get_volume_mute_by_type(pa_stream_manager *m, stream_type_t stream_type,
     if (volumes) {
         v = pa_hashmap_get(volumes, volume_type);
         if (v)
-            *volume_mute = v->values[(stream_type==STREAM_SINK_INPUT)?STREAM_DIRECTION_OUT:STREAM_DIRECTION_IN].is_muted;
+            *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;
@@ -635,7 +635,7 @@ int32_t set_volume_mute_by_idx(pa_stream_manager *m, stream_type_t stream_type,
         if (volumes) {
             v = pa_hashmap_get(volumes, volume_type_str);
             if (v)
-                muted_by_type = v->values[(stream_type==STREAM_SINK_INPUT)?STREAM_DIRECTION_OUT:STREAM_DIRECTION_IN].is_muted;
+                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;
@@ -704,7 +704,7 @@ int32_t set_volume_mute_with_new_data(pa_stream_manager *m, stream_type_t stream
      }
 
     if (is_hal_volume)
-        if (pa_hal_manager_set_mute(m->hal, volume_type_str, (stream_type==STREAM_SINK_INPUT)?DIRECTION_OUT:DIRECTION_IN, volume_mute))
+        if (pa_hal_manager_set_volume_mute(m->hal, volume_type_str, (stream_type==STREAM_SINK_INPUT)?DIRECTION_OUT:DIRECTION_IN, volume_mute))
             return -1;
 
     if (stream_type == STREAM_SINK_INPUT)
index 198ec55214eb71512e7e668c8a1be4dea1f5a975..0bc505f85689087b10f6903d864bfd7710239f37 100644 (file)
@@ -389,10 +389,10 @@ typedef struct _stream_info_per_type {
     int32_t num_of_in_devices;
     int32_t num_of_out_devices;
     int32_t num_of_frameworks;
-    char *volume_types[STREAM_DIRECTION_MAX];
-    char *avail_in_devices[AVAIL_DEVICES_MAX];
-    char *avail_out_devices[AVAIL_DEVICES_MAX];
-    char *avail_frameworks[AVAIL_FRAMEWORKS_MAX];
+    const char *volume_types[STREAM_DIRECTION_MAX];
+    const char *avail_in_devices[AVAIL_DEVICES_MAX];
+    const char *avail_out_devices[AVAIL_DEVICES_MAX];
+    const char *avail_frameworks[AVAIL_FRAMEWORKS_MAX];
 } stream_info_per_type;
 typedef struct _stream_list {
     int32_t num_of_streams;
@@ -1402,6 +1402,7 @@ static void deinit_stream_map (pa_stream_manager *m) {
     stream_info *s = NULL;
     volume_info *v = NULL;
     void *state = NULL;
+
     pa_assert(m);
 
     if (m->stream_infos) {
@@ -1464,13 +1465,12 @@ static pa_bool_t check_role_to_skip(pa_stream_manager *m, const char *role) {
     stream_info *s = NULL;
 
     pa_assert(m);
+    pa_assert(m->stream_infos);
     pa_assert(role);
 
-    if (m->stream_infos) {
-        s = pa_hashmap_get(m->stream_infos, role);
-        if (s)
-            ret = FALSE;
-    }
+    if ((s = pa_hashmap_get(m->stream_infos, role)))
+        ret = FALSE;
+
     pa_log_info("role is [%s], skip(%d)", role, ret);
 
     return ret;
@@ -1479,6 +1479,7 @@ static pa_bool_t check_role_to_skip(pa_stream_manager *m, const char *role) {
 static pa_bool_t check_route_type_to_skip(process_command_type_t command, const char *route_type_str) {
     pa_bool_t ret = FALSE;
     stream_route_type_t route_type;
+
     pa_assert(route_type_str);
 
     if (!pa_atoi(route_type_str, (int32_t*)&route_type)) {
@@ -1495,65 +1496,61 @@ static pa_bool_t check_route_type_to_skip(process_command_type_t command, const
 }
 
 static pa_bool_t update_priority_of_stream(pa_stream_manager *m, stream_type_t type, void *stream, const char *role, pa_bool_t is_new_data) {
+    pa_bool_t ret = FALSE;
     stream_info *s = NULL;
 
     pa_assert(m);
+    pa_assert(m->stream_infos);
     pa_assert(role);
 
-    if (m->stream_infos)
-        s = pa_hashmap_get(m->stream_infos, role);
-    else
-        return FALSE;
-
-    if (s) {
+    if ((s = pa_hashmap_get(m->stream_infos, role))) {
         if (is_new_data)
             pa_proplist_set(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE_PRIORITY, (const void*)&(s->priority), sizeof(s->priority));
         else
             pa_proplist_set(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE_PRIORITY, (const void*)&(s->priority), sizeof(s->priority));
+        ret = TRUE;
     }
 
-    return TRUE;
+    return ret;
 }
 
 static pa_bool_t update_route_type_of_stream(pa_stream_manager *m, void *stream, stream_type_t type, const char *role) {
+    pa_bool_t ret = FALSE;
     stream_route_type_t route_type = STREAM_ROUTE_TYPE_AUTO;
     stream_info *s = NULL;
 
     pa_assert(m);
+    pa_assert(m->stream_infos);
     pa_assert(role);
 
-    if (m->stream_infos) {
-        s = pa_hashmap_get(m->stream_infos, role);
-        if (s)
-            route_type = s->route_type;
-    } else
-        return FALSE;
-
-    pa_proplist_setf(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE_ROUTE_TYPE, "%d", route_type);
+    if ((s = pa_hashmap_get(m->stream_infos, role))) {
+        route_type = s->route_type;
+        pa_proplist_setf(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_ROLE_ROUTE_TYPE, "%d", route_type);
+        ret = TRUE;
+    }
 
-    return TRUE;
+    return ret;
 }
 
 static pa_bool_t update_volume_type_of_stream(pa_stream_manager *m, stream_type_t type, void *stream, const char *role) {
+    pa_bool_t ret = FALSE;
     const char *volume_type = NULL;
     stream_info *s = NULL;
 
     pa_assert(m);
+    pa_assert(m->stream_infos);
     pa_assert(role);
 
-    if (m->stream_infos) {
-        s = pa_hashmap_get(m->stream_infos, role);
-        if (s)
-            volume_type = s->volume_types[!type];
-    } else
-        return FALSE;
+    if ((s = pa_hashmap_get(m->stream_infos, role)))
+        volume_type = s->volume_types[type];
 
-    if (volume_type && (!pa_streq(volume_type, "none")))
+    if (volume_type && (!pa_streq(volume_type, "none"))) {
         pa_proplist_sets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE, volume_type);
-    else
+        ret = TRUE;
+    } else
         pa_log_warn("this stream[%p] does not have any volume type, skip updating volume type. stream_type[%d], role[%s]", stream, type, role);
 
-    return TRUE;
+    return ret;
 }
 
 static pa_bool_t update_focus_status_of_stream(pa_stream_manager *m, void *stream, stream_type_t type, pa_bool_t is_new_data) {
@@ -2253,17 +2250,17 @@ static process_stream_result_t process_stream(pa_stream_manager *m, stream_type_
     } else if (command == PROCESS_COMMAND_UPDATE_VOLUME && is_new_data) {
         if ((si_volume_type_str = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
             v = pa_hashmap_get(m->volume_infos, si_volume_type_str);
-            if (v && v->values[(type==STREAM_SINK_INPUT)?STREAM_DIRECTION_OUT:STREAM_DIRECTION_IN].idx_volume_values) {
+            if (v && v->values[type].idx_volume_values) {
                 /* Update volume-level */
-                volume_ret = set_volume_level_with_new_data(m, type, stream, v->values[(type==STREAM_SINK_INPUT)?STREAM_DIRECTION_OUT:STREAM_DIRECTION_IN].current_level);
+                volume_ret = set_volume_level_with_new_data(m, type, stream, v->values[type].current_level);
                 if (volume_ret)
                     pa_log_error("failed to set_volume_level_by_idx(), stream_type(%d), level(%u), ret(0x%x)",
-                            STREAM_SINK_INPUT, v->values[(type==STREAM_SINK_INPUT)?STREAM_DIRECTION_OUT:STREAM_DIRECTION_IN].current_level, volume_ret);
+                        type, v->values[type].current_level, volume_ret);
                 /* Update volume-mute */
-                volume_ret = set_volume_mute_with_new_data(m, type, stream, v->values[(type==STREAM_SINK_INPUT)?STREAM_DIRECTION_OUT:STREAM_DIRECTION_IN].is_muted);
+                volume_ret = set_volume_mute_with_new_data(m, type, stream, v->values[type].is_muted);
                 if (volume_ret)
                     pa_log_error("failed to set_volume_mute_by_idx(), stream_type(%d), mute(%d), ret(0x%x)",
-                            STREAM_SINK_INPUT, v->values[(type==STREAM_SINK_INPUT)?STREAM_DIRECTION_OUT:STREAM_DIRECTION_IN].is_muted, volume_ret);
+                        type, v->values[type].is_muted, volume_ret);
             }
         }