sink, source: Consolidate passthrough setup in reconfigure

This moves over the saving+resetting/restoring of volumes and source
suspending/unsuspending while entering/leaving passthrough mode into
reconfigure functions. This makes it easier to reason about exactly what
behaviour occurs at the time, as well as avoids loss of precision during
the remapping of the internal volume values in this case.
This commit is contained in:
Arun Raghavan 2018-09-19 18:24:50 +05:30 committed by Arun Raghavan
parent 0d85b18460
commit cbaf278f1e
6 changed files with 50 additions and 96 deletions

View file

@ -1091,6 +1091,10 @@ int pa_source_reconfigure(pa_source *s, pa_sample_spec *spec, pa_channel_map *ma
/* Save the previous sample spec and channel map, we will try to restore it when leaving passthrough */
s->saved_spec = s->sample_spec;
s->saved_map = s->channel_map;
/* Save the volume, we're going to reset it to NORM while in passthrough */
s->saved_volume = *pa_source_get_volume(s, true);
s->saved_save_volume = s->save_volume;
}
if (restore) {
@ -1205,8 +1209,8 @@ int pa_source_reconfigure(pa_source *s, pa_sample_spec *spec, pa_channel_map *ma
}
}
if (!pa_channel_map_equal(&old_map, &s->channel_map)) {
/* Remap stored volumes to the new channel map */
if (!restore && !pa_channel_map_equal(&old_map, &s->channel_map)) {
/* Remap stored volumes to the new channel map if we're not just restoring a previously saved volume */
pa_cvolume_remap(&s->reference_volume, &old_map, &s->channel_map);
pa_cvolume_remap(&s->real_volume, &old_map, &s->channel_map);
pa_cvolume_remap(&s->soft_volume, &old_map, &s->channel_map);
@ -1214,11 +1218,24 @@ int pa_source_reconfigure(pa_source *s, pa_sample_spec *spec, pa_channel_map *ma
pa_log_info("Reconfigured successfully");
if (passthrough) {
/* set the volume to NORM */
pa_cvolume volume;
pa_cvolume_set(&volume, s->sample_spec.channels, PA_MIN(s->base_volume, PA_VOLUME_NORM));
pa_source_set_volume(s, &volume, true, false);
}
if (restore) {
/* Reset saved spec and channel map to bail early if we inadvertently
* use them (which is not expected after this) */
pa_sample_spec_init(&s->saved_spec);
pa_channel_map_init(&s->saved_map);
/* Restore source volume to what it was before we entered passthrough mode */
pa_source_set_volume(s, &s->saved_volume, true, s->saved_save_volume);
pa_cvolume_init(&s->saved_volume);
s->saved_save_volume = false;
}
unsuspend:
@ -1332,27 +1349,6 @@ bool pa_source_is_passthrough(pa_source *s) {
return (s->monitor_of && pa_sink_is_passthrough(s->monitor_of));
}
/* Called from main context */
void pa_source_enter_passthrough(pa_source *s) {
pa_cvolume volume;
/* set the volume to NORM */
s->saved_volume = *pa_source_get_volume(s, true);
s->saved_save_volume = s->save_volume;
pa_cvolume_set(&volume, s->sample_spec.channels, PA_MIN(s->base_volume, PA_VOLUME_NORM));
pa_source_set_volume(s, &volume, true, false);
}
/* Called from main context */
void pa_source_leave_passthrough(pa_source *s) {
/* Restore source volume to what it was before we entered passthrough mode */
pa_source_set_volume(s, &s->saved_volume, true, s->saved_save_volume);
pa_cvolume_init(&s->saved_volume);
s->saved_save_volume = false;
}
/* Called from main context. */
static void compute_reference_ratio(pa_source_output *o) {
unsigned c = 0;