stream-manager-volume: Apply volume ratio to the stream that does not have any volume... 82/228582/3
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 24 Mar 2020 04:27:30 +0000 (13:27 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 24 Mar 2020 06:40:02 +0000 (15:40 +0900)
There are some cases required to apply the volume ratio to the stream
without volume type. For example, if 'emergency' stream role is configured
not to have any volume type as known as the group volume in stream-map.json
and it still need to the volume ratio feature, there was no way to apply it.

It is now supported by this patch. Note that setting volume level and mute
feature based on the group volume still not possible for those who do not
have any volume type.

[Version] 11.1.97
[Issue Type] Improvement

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

index 7d4aa328ff387d38033364cf24dd900cd201a449..eae842bd50954da2258a29a57462f7450ace51eb 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          11.1.96
+Version:          11.1.97
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index f5244440a650dca93e6323a6de9fa03678e5d720..8edc0b2246734634b40f3e62b503ec177fd866fb 100644 (file)
@@ -267,10 +267,10 @@ int32_t update_mute_vconf(const char *type, unsigned int mute)
 void apply_individual_ratio(pa_stream_manager *m, pa_object *stream, double volume_linear, pa_cvolume *result) {
     bool is_sink_input = false;
     double result_linear;
-    double individual_ratio;
-    double master_ratio;
-    double group_ratio;
-    double result_ratio;
+    double individual_ratio = 1.0;
+    double master_ratio = 1.0;
+    double group_ratio = 1.0;
+    double result_ratio = 1.0;
     pa_volume_t volume;
     uint32_t index;
     unsigned channels;
@@ -307,10 +307,6 @@ void apply_individual_ratio(pa_stream_manager *m, pa_object *stream, double volu
                 individual_ratio, index, result_linear);
 
     /* Here's calculation before calling HAL API */
-    if (!(volume_type = pa_proplist_gets(GET_STREAM_PROPLIST(stream, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
-        pa_log_error("no volume type");
-        return;
-    }
     role = pa_proplist_gets(GET_STREAM_PROPLIST(stream, stream_type), PA_PROP_MEDIA_ROLE);
     stream_direction = is_sink_input ? STREAM_DIRECTION_OUT : STREAM_DIRECTION_IN;
     volumes = m->volume_infos;
@@ -318,12 +314,20 @@ void apply_individual_ratio(pa_stream_manager *m, pa_object *stream, double volu
         pa_log_error("could not get volume_info, volume_type[%s]", MASTER_VOLUME_TYPE);
         return;
     }
-    master_ratio = v->is_hal_volume_type ? 1.0 : (double)v->values[stream_direction].current_level / MASTER_VOLUME_LEVEL_MAX;
-    if (!(v = pa_hashmap_get(volumes, volume_type))) {
-        pa_log_error("could not get volume_info, volume_type[%s]", volume_type);
-        return;
+    if (!v->is_hal_volume_type)
+        master_ratio = (double)v->values[stream_direction].current_level / MASTER_VOLUME_LEVEL_MAX;
+
+    /* Update a group ratio only when the volume type exists */
+    if ((volume_type = pa_proplist_gets(GET_STREAM_PROPLIST(stream, stream_type), PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
+        if (!(v = pa_hashmap_get(volumes, volume_type))) {
+            pa_log_error("could not get volume_info, volume_type[%s]", volume_type);
+            return;
+        }
+        if (!v->is_hal_volume_type)
+            group_ratio = (double)v->values[stream_direction].current_level /
+                          (pa_idxset_size(v->values[stream_direction].idx_volume_values) - 1);
     }
-    group_ratio = v->is_hal_volume_type ? 1.0 : (double)v->values[stream_direction].current_level / (pa_idxset_size(v->values[stream_direction].idx_volume_values) - 1);
+
     result_ratio = master_ratio * group_ratio * individual_ratio;
     pa_log_debug("role(%s), volume_type(%s) : master_ratio(%f), group_ratio(%f), individual_ratio(%f) => result_ratio(%f) to HAL",
                 role, volume_type, master_ratio, group_ratio, individual_ratio, result_ratio);
@@ -628,7 +632,7 @@ int32_t set_volume_ratio_by_idx(pa_stream_manager *m, stream_type_t stream_type,
 
     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;
+        goto apply_individual_ratio;
     }
 
     /* Check if it is related to HAL volume */
@@ -658,6 +662,7 @@ int32_t set_volume_ratio_by_idx(pa_stream_manager *m, stream_type_t stream_type,
                     modifier_gain, *modifier_gain_value, volume_linear);
     }
 
+apply_individual_ratio:
     if (stream_type == STREAM_SINK_INPUT) {
         ((pa_sink_input*)s)->individual_volume_ratio = ratio;
         apply_individual_ratio(m, s, volume_linear, &cv);