1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-22 23:02:37 +00:00

mixer: don't restore volume with different --softvol-max settings

Changing --softvol-max and then resuming would change the volume level
on resume to something different than the original volume. This is
because the user volume setting is always between 0-100, and 100
corresponds to --softvol-max gain.

Avoid that changing -softvol-max and resuming an older file could lead
to a too loud volume level by refusing to restore if --softvol-max
changed.
This commit is contained in:
wm4 2014-05-06 20:09:36 +02:00
parent 0467e13725
commit b7669d533b

View File

@ -18,6 +18,7 @@
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <libavutil/common.h>
@ -235,8 +236,9 @@ char *mixer_get_volume_restore_data(struct mixer *mixer)
{
if (!mixer->driver[0])
return NULL;
return talloc_asprintf(NULL, "%s:%f:%f:%d", mixer->driver, mixer->vol_l,
mixer->vol_r, mixer->muted_by_us);
return talloc_asprintf(NULL, "%s:%f:%f:%d:%f", mixer->driver, mixer->vol_l,
mixer->vol_r, mixer->muted_by_us,
mixer->opts->softvol_max);
}
static void probe_softvol(struct mixer *mixer)
@ -299,19 +301,20 @@ static void restore_volume(struct mixer *mixer)
force_mute = opts->mixer_init_mute;
// Set parameters from playback resume.
char *restore_data = mixer->opts->mixer_restore_volume_data;
if (restore && restore_data && restore_data[0]) {
char *data = mixer->opts->mixer_restore_volume_data;
if (restore && data && data[0]) {
char drv[40];
float v_l, v_r;
float v_l, v_r, s;
int m;
if (sscanf(restore_data, "%39[^:]:%f:%f:%d", drv, &v_l, &v_r, &m) == 4) {
if (strcmp(mixer->driver, drv) == 0) {
if (sscanf(data, "%39[^:]:%f:%f:%d:%f", drv, &v_l, &v_r, &m, &s) == 5) {
float diff = fabs(mixer->opts->softvol_max - s);
if (strcmp(mixer->driver, drv) == 0 && diff < 0.01) {
force_vol_l = v_l;
force_vol_r = v_r;
force_mute = !!m;
}
}
talloc_free(restore_data);
talloc_free(mixer->opts->mixer_restore_volume_data);
mixer->opts->mixer_restore_volume_data = NULL;
}