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;
}
}
- 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)
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)
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);