summaryrefslogtreecommitdiffstats
path: root/mixer.c
diff options
context:
space:
mode:
authorwm4 <wm4@mplayer2.org>2012-01-06 16:23:43 +0100
committerwm4 <wm4@mplayer2.org>2012-01-18 04:21:45 +0100
commit29effe9593465f9096227edb79e09e51ca8a054d (patch)
tree5d451166dcaef5cd3c7d707195ca818e5f47f54b /mixer.c
parent95c52f865da2459f47ed708c41324f0cc5386da3 (diff)
downloadmpv-29effe9593465f9096227edb79e09e51ca8a054d.tar.bz2
mpv-29effe9593465f9096227edb79e09e51ca8a054d.tar.xz
mixer: restore volume with audio output drivers without persistent volume
Some audio outputs don't provide access to a system-wide mixer control, and do per-application audio mixing. Further, some of these forget the volume as soon as the audio device is closed. This can be annoying, because mplayer will "forget" the volume when playing a new file or when crossing ordered chapter boundaries. Support restoring the volume on audio reinitialization if an audio output driver knowingly behaves this way. (This doesn't change that mplayer never writes any settings into the config file, including volume settings.) This commit doesn't yet change any actual output driver to use this code. Hopefully make some logic in the volume restore code a bit more robust.
Diffstat (limited to 'mixer.c')
-rw-r--r--mixer.c47
1 files changed, 29 insertions, 18 deletions
diff --git a/mixer.c b/mixer.c
index 2f3d57b07e..5cd1b722d9 100644
--- a/mixer.c
+++ b/mixer.c
@@ -38,12 +38,14 @@ float soft_vol_max = 110.0;
// Called after the audio filter chain is built or rebuilt.
void mixer_reinit(mixer_t *mixer)
{
- if (mixer->restore_softvol) {
+ if (!mixer->ao)
+ return;
+ if (mixer->restore_volume) {
int muted = mixer->muted;
- mixer_setvolume(mixer, mixer->softvol_l, mixer->softvol_r);
+ mixer_setvolume(mixer, mixer->restore_vol_l, mixer->restore_vol_r);
mixer->muted = muted;
}
- if (mixer->balance != 0) {
+ if (mixer->restore_balance) {
mixer_setbalance(mixer, mixer->balance);
}
}
@@ -81,17 +83,21 @@ void mixer_setvolume(mixer_t *mixer, float l, float r)
vol.right = r;
vol.left = l;
if (mixer->ao) {
- if (soft_vol ||
- CONTROL_OK != ao_control(mixer->ao, AOCONTROL_SET_VOLUME, &vol))
- {
+ bool use_softvol = soft_vol;
+ if (!use_softvol) {
+ if (CONTROL_OK != ao_control(mixer->ao, AOCONTROL_SET_VOLUME, &vol))
+ {
+ use_softvol = true;
+ } else {
+ mixer->restore_volume = mixer->ao->no_persistent_volume;
+ }
+ }
+ if (use_softvol) {
if (!mixer->afilter)
return;
// af_volume uses values in dB
float db_vals[AF_NCH];
int i;
- mixer->softvol_l = l;
- mixer->softvol_r = r;
- mixer->restore_softvol = 1;
db_vals[0] = (l / 100.0) * (soft_vol_max / 100.0);
db_vals[1] = (r / 100.0) * (soft_vol_max / 100.0);
for (i = 2; i < AF_NCH; i++)
@@ -102,16 +108,20 @@ void mixer_setvolume(mixer_t *mixer, float l, float r)
{
mp_tmsg(MSGT_GLOBAL, MSGL_INFO,
"[Mixer] No hardware mixing, inserting volume filter.\n");
- if (af_add(mixer->afilter, "volume")) {
- if (!af_control_any_rev(mixer->afilter,
- AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_SET, db_vals))
- {
- mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
- "[Mixer] No volume control available.\n");
- return;
- }
+ if (!(af_add(mixer->afilter, "volume")
+ && af_control_any_rev(mixer->afilter,
+ AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_SET, db_vals)))
+ {
+ mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
+ "[Mixer] No volume control available.\n");
+ return;
}
}
+ mixer->restore_volume = true;
+ }
+ if (mixer->restore_volume) {
+ mixer->restore_vol_l = l;
+ mixer->restore_vol_r = r;
}
}
mixer->muted = 0;
@@ -181,6 +191,7 @@ void mixer_setbalance(mixer_t *mixer, float val)
return;
mixer->balance = val;
+ mixer->restore_balance = true;
if (af_control_any_rev(mixer->afilter,
AF_CONTROL_PAN_BALANCE | AF_CONTROL_SET, &val))
@@ -189,7 +200,7 @@ void mixer_setbalance(mixer_t *mixer, float val)
if (!(af_pan_balance = af_add(mixer->afilter, "pan"))) {
mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
"[Mixer] No balance control available.\n");
- mixer->balance = 0;
+ mixer->restore_balance = false;
return;
}