stream-manager-volume: Apply individual volume ratio 48/202848/1
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 5 Apr 2019 03:22:49 +0000 (12:22 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Fri, 5 Apr 2019 04:42:27 +0000 (13:42 +0900)
In Tizen, a stream has one volume type such as media, notification,
alarm. Each type is so-called a volume group which has its own volume
value of a certain volume level. Therefore, all streams that belong to
the same volume group have the same volume value of the group.

This patch adds to calculate volume value including the individual
volume ratio of each stream's volume value to the value of its volume
group.

[Version] 11.1.37
[Issue type] New feature

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

index bb0b593..dbf0505 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          11.1.36
+Version:          11.1.37
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 99beaeb..bbb7c90 100644 (file)
@@ -264,6 +264,35 @@ int32_t update_mute_vconf(const char *type, unsigned int mute)
     return 0;
 }
 
+void apply_individual_ratio(pa_stream_manager *m, pa_object *stream, double volume_linear, pa_cvolume *result) {
+        double individual_ratio;
+        double result_linear;
+        pa_volume_t volume;
+        uint32_t index;
+        unsigned channels;
+
+        pa_assert(m);
+        pa_assert(stream);
+        pa_assert(volume_linear);
+
+        if (pa_sink_input_isinstance(stream)) {
+            individual_ratio = ((pa_sink_input*)stream)->individual_volume_ratio;
+            index = ((pa_sink_input*)stream)->index;
+            channels = ((pa_sink_input*)stream)->sample_spec.channels;
+        } else {
+            individual_ratio = ((pa_source_output*)stream)->individual_volume_ratio;
+            index = ((pa_source_output*)stream)->index;
+            channels = ((pa_sink_input*)stream)->sample_spec.channels;
+        }
+
+        volume = pa_sw_volume_from_linear(volume_linear) * individual_ratio;
+        result = pa_cvolume_set(result, channels, volume);
+        result_linear = pa_sw_volume_to_linear(volume);
+
+        pa_log_info("apply the individual ratio[%f] to stream[idx:%u], result volume linear[%f]",
+                        individual_ratio, index, result_linear);
+}
+
 int32_t set_volume_level_by_type(pa_stream_manager *m, stream_type_t stream_type, const char *volume_type, uint32_t volume_level) {
     bool is_hal_volume = false;
     volume_info *v = NULL;
@@ -331,7 +360,8 @@ int32_t set_volume_level_by_type(pa_stream_manager *m, stream_type_t stream_type
                 }
             }
 
-            pa_cvolume_set(&cv, GET_STREAM_SAMPLE_SPEC(s, stream_type).channels, pa_sw_volume_from_linear(volume_linear));
+            apply_individual_ratio(m, s, volume_linear, &cv);
+
             if (stream_type == STREAM_SINK_INPUT)
                 pa_sink_input_set_volume((pa_sink_input*)s, &cv, true, true);
             else if (stream_type == STREAM_SOURCE_OUTPUT)
@@ -356,12 +386,13 @@ int32_t set_volume_level_by_type(pa_stream_manager *m, stream_type_t stream_type
             if (modifier_gain && m->volume_modifiers) {
                 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]",
+                    pa_log_info("apply the modifier for the gain value[%s=>%f], result volume_linear[%f]",
                                 modifier_gain, *modifier_gain_value, volume_linear);
                 }
             }
 
-            pa_cvolume_set(&cv, GET_STREAM_SAMPLE_SPEC(s, stream_type).channels, pa_sw_volume_from_linear(volume_linear));
+            apply_individual_ratio(m, s, volume_linear, &cv);
+
             if (stream_type == STREAM_SINK_INPUT)
                 pa_sink_input_set_volume((pa_sink_input*)s, &cv, true, true);
             else if (stream_type == STREAM_SOURCE_OUTPUT)
@@ -465,23 +496,26 @@ int32_t set_volume_level_by_idx(pa_stream_manager *m, stream_type_t stream_type,
         if (pa_hal_interface_set_volume_level(m->hal, volume_type_str, CONVERT_TO_HAL_DIRECTION(stream_type), volume_level))
             return -1;
 
+    if (get_volume_value(m, stream_type, is_hal_volume, volume_type_str, volume_level, &volume_linear))
+        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) {
-            if ((modifier_gain_value = pa_hashmap_get(m->volume_modifiers, modifier_gain))) {
-                volume_linear *= (*modifier_gain_value);
-                pa_log_info("apply the modifier for the gain value[%s=>%f], result volume_linear[%f]",
-                            modifier_gain, *modifier_gain_value, volume_linear);
-            }
+    if (modifier_gain && m->volume_modifiers) {
+        if ((modifier_gain_value = pa_hashmap_get(m->volume_modifiers, modifier_gain))) {
+            volume_linear *= (*modifier_gain_value);
+            pa_log_info("apply the modifier for the gain value[%s=>%f], result volume_linear[%f]",
+                        modifier_gain, *modifier_gain_value, volume_linear);
         }
-        pa_cvolume_set(&cv, GET_STREAM_SAMPLE_SPEC(s, stream_type).channels, pa_sw_volume_from_linear(volume_linear));
-        if (stream_type == STREAM_SINK_INPUT)
-            pa_sink_input_set_volume((pa_sink_input*)s, &cv, true, true);
-        else if (stream_type == STREAM_SOURCE_OUTPUT)
-            pa_source_output_set_volume((pa_source_output*)s, &cv, true, true);
     }
+
+    apply_individual_ratio(m, s, volume_linear, &cv);
+
+    if (stream_type == STREAM_SINK_INPUT)
+        pa_sink_input_set_volume((pa_sink_input*)s, &cv, true, true);
+    else if (stream_type == STREAM_SOURCE_OUTPUT)
+        pa_source_output_set_volume((pa_source_output*)s, &cv, true, true);
+
     pa_log_debug("stream_type[%d], idx[%u]=>volume_type[%s], level[%u], value[%f]",
                  stream_type, idx, volume_type_str, volume_level, volume_linear);