From e07d1b397c9784e8b11a2055a4c54e84bd92468c Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 24 Mar 2015 22:20:58 +0100 Subject: mixer: fix how volume is restored with per-app system mixers This broke with PulseAudio: when changing some audio filters (like for playback speed), mixer_reinit_audio() was called - and it overwrote the volume with whatever mpv thought the volume was before. If the volume was changed externally before and while mpv was running, this would reset the volume to the old value. Fixes #1335. --- audio/mixer.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'audio') diff --git a/audio/mixer.c b/audio/mixer.c index ced2196215..2358835248 100644 --- a/audio/mixer.c +++ b/audio/mixer.c @@ -38,6 +38,7 @@ struct mixer { // Static, dependent on ao/softvol settings bool softvol; // use AO (false) or af_volume (true) bool ao_softvol; // AO has private or per-app volume + bool ao_perapp; // AO has persistent per-app volume bool emulate_mute; // if true, emulate mute with volume=0 // Last known values (possibly out of sync with reality) float vol_l, vol_r; @@ -246,9 +247,11 @@ char *mixer_get_volume_restore_data(struct mixer *mixer) static void probe_softvol(struct mixer *mixer) { - mixer->ao_softvol = - ao_control(mixer->ao, AOCONTROL_HAS_SOFT_VOLUME, 0) == 1 || + mixer->ao_perapp = ao_control(mixer->ao, AOCONTROL_HAS_PER_APP_VOLUME, 0) == 1; + mixer->ao_softvol = mixer->ao_perapp || + ao_control(mixer->ao, AOCONTROL_HAS_SOFT_VOLUME, 0) == 1; + if (mixer->opts->softvol == SOFTVOL_AUTO) { // No system-wide volume => fine with AO volume control. @@ -285,7 +288,7 @@ static void restore_volume(struct mixer *mixer) const char *prev_driver = mixer->driver; mixer->driver = mixer->softvol ? "softvol" : ao_get_name(ao); - bool restore = mixer->softvol || mixer->ao_softvol; + bool restore = mixer->softvol || (mixer->ao_softvol && !mixer->ao_perapp); // Restore old parameters if volume won't survive reinitialization. // But not if volume scale is possibly different. -- cgit v1.2.3