summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-03-31 23:59:36 +0200
committerwm4 <wm4@nowhere>2015-04-01 00:22:47 +0200
commit502f9a1450417a383ea95a98b1cd868932976815 (patch)
treec185315431e72cc42fa2e411ba7fac11c9895787 /audio
parent1d2b81b55017e1e0c60e140b6eb1edff6f260525 (diff)
downloadmpv-502f9a1450417a383ea95a98b1cd868932976815.tar.bz2
mpv-502f9a1450417a383ea95a98b1cd868932976815.tar.xz
mixer: cleanup volume logic slightly
Diffstat (limited to 'audio')
-rw-r--r--audio/mixer.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/audio/mixer.c b/audio/mixer.c
index 27c809c6eb..64735a199b 100644
--- a/audio/mixer.c
+++ b/audio/mixer.c
@@ -37,8 +37,7 @@ struct mixer {
struct af_stream *af;
// 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 persistent_volume; // volume does not need to be restored
bool emulate_mute; // if true, emulate mute with volume=0
// Last known values (possibly out of sync with reality)
float vol_l, vol_r;
@@ -249,18 +248,20 @@ char *mixer_get_volume_restore_data(struct mixer *mixer)
static void probe_softvol(struct mixer *mixer)
{
- 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;
+ bool ao_perapp = ao_control(mixer->ao, AOCONTROL_HAS_PER_APP_VOLUME, 0) == 1;
+ bool ao_softvol = ao_control(mixer->ao, AOCONTROL_HAS_SOFT_VOLUME, 0) == 1;
+ mixer->persistent_volume = !ao_softvol || ao_perapp;
if (mixer->opts->softvol == SOFTVOL_AUTO) {
// No system-wide volume => fine with AO volume control.
- mixer->softvol = !mixer->ao_softvol;
+ mixer->softvol = !ao_softvol && !ao_perapp;
} else {
mixer->softvol = mixer->opts->softvol == SOFTVOL_YES;
}
+ if (mixer->softvol)
+ mixer->persistent_volume = false;
+
MP_DBG(mixer, "Will use af_volume: %s\n", mixer->softvol ? "yes" : "no");
// If we can't use real volume control => force softvol.
@@ -291,11 +292,9 @@ 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 && !mixer->ao_perapp);
-
// Restore old parameters if volume won't survive reinitialization.
// But not if volume scale is possibly different.
- if (restore && strcmp(mixer->driver, prev_driver) == 0) {
+ if (!mixer->persistent_volume && strcmp(mixer->driver, prev_driver) == 0) {
force_vol_l = mixer->vol_l;
force_vol_r = mixer->vol_r;
}
@@ -312,7 +311,7 @@ static void restore_volume(struct mixer *mixer)
// Set parameters from playback resume.
char *data = mixer->opts->mixer_restore_volume_data;
- if (restore && data && data[0]) {
+ if (!mixer->persistent_volume && data && data[0]) {
char drv[40];
float v_l, v_r, s;
int m;
@@ -378,7 +377,7 @@ void mixer_uninit_audio(struct mixer *mixer)
MP_DBG(mixer, "Uninit...\n");
checkvolume(mixer);
- if (mixer->muted_by_us && !mixer->softvol && !mixer->ao_softvol) {
+ if (mixer->muted_by_us && mixer->persistent_volume) {
MP_DBG(mixer, "Draining.\n");
/* Current audio output API combines playing the remaining buffered
* audio and uninitializing the AO into one operation, even though