[player] Check volume range when called for volume change + some adjustments in pipe input

This commit is contained in:
ejurgensen 2017-07-14 20:04:35 +02:00
parent 4085161e9a
commit b803c30dcd
2 changed files with 27 additions and 11 deletions

View File

@ -303,44 +303,42 @@ parse_progress(struct input_metadata *m, char *progress)
} }
static void static void
parse_volume(char *volume) parse_volume(const char *volume)
{ {
char *volume_next; char *volume_next;
float airplay_volume; float airplay_volume;
float local_volume; int local_volume;
errno = 0; errno = 0;
airplay_volume = strtof(volume, &volume_next); airplay_volume = strtof(volume, &volume_next);
if ((errno == ERANGE) || (volume == volume_next)) if ((errno == ERANGE) || (volume == volume_next))
{ {
DPRINTF(E_LOG, L_PLAYER, "Invalid airplay volume in string (%s): %s\n", volume, DPRINTF(E_LOG, L_PLAYER, "Invalid Shairport airplay volume in string (%s): %s\n", volume,
(errno == ERANGE ? strerror(errno) : "First token is not a number.")); (errno == ERANGE ? strerror(errno) : "First token is not a number."));
return; return;
} }
if (strcmp(volume_next, ",0.00,0.00,0.00") != 0) if (strcmp(volume_next, ",0.00,0.00,0.00") != 0)
{ {
DPRINTF(E_DBG, L_PLAYER, "Not applying airplay volume while software volume control is enabled (%s)\n", volume); DPRINTF(E_DBG, L_PLAYER, "Not applying Shairport airplay volume while software volume control is enabled (%s)\n", volume);
return; return;
} }
if (((int) airplay_volume) == -144) if (((int) airplay_volume) == -144)
{ {
DPRINTF(E_DBG, L_PLAYER, "Applying airplay volume ('mute', value: %.2f)\n", airplay_volume); DPRINTF(E_DBG, L_PLAYER, "Applying Shairport airplay volume ('mute', value: %.2f)\n", airplay_volume);
player_volume_set(0); player_volume_set(0);
} }
else if (airplay_volume >= -30.0 && airplay_volume <= 0.0) else if (airplay_volume >= -30.0 && airplay_volume <= 0.0)
{ {
local_volume = 100.0 + (airplay_volume / 30.0 * 100.0); local_volume = (int)(100.0 + (airplay_volume / 30.0 * 100.0));
if (local_volume < 0 || local_volume > 100)
return;
DPRINTF(E_DBG, L_PLAYER, "Applying airplay volume (percent: %.0f, value: %.2f)\n", local_volume, airplay_volume); DPRINTF(E_DBG, L_PLAYER, "Applying Shairport airplay volume (percent: %d, value: %.2f)\n", local_volume, airplay_volume);
player_volume_set((int) local_volume); player_volume_set(local_volume);
} }
else else
DPRINTF(E_LOG, L_PLAYER, "Airplay volume out of range (-144.0, [-30.0 - 0.0]): %.2f\n", airplay_volume); DPRINTF(E_LOG, L_PLAYER, "Shairport airplay volume out of range (-144.0, [-30.0 - 0.0]): %.2f\n", airplay_volume);
} }
// returns 1 on metadata found, 0 on nothing, -1 on error // returns 1 on metadata found, 0 on nothing, -1 on error

View File

@ -2984,6 +2984,12 @@ player_volume_set(int vol)
union player_arg cmdarg; union player_arg cmdarg;
int ret; int ret;
if (vol < 0 || vol > 100)
{
DPRINTF(E_LOG, L_PLAYER, "Volume (%d) for player_volume_set is out of range\n", vol);
return -1;
}
cmdarg.intval = vol; cmdarg.intval = vol;
ret = commands_exec_sync(cmdbase, volume_set, NULL, &cmdarg); ret = commands_exec_sync(cmdbase, volume_set, NULL, &cmdarg);
@ -2996,6 +3002,12 @@ player_volume_setrel_speaker(uint64_t id, int relvol)
union player_arg cmdarg; union player_arg cmdarg;
int ret; int ret;
if (relvol < 0 || relvol > 100)
{
DPRINTF(E_LOG, L_PLAYER, "Volume (%d) for player_volume_setrel_speaker is out of range\n", relvol);
return -1;
}
cmdarg.vol_param.spk_id = id; cmdarg.vol_param.spk_id = id;
cmdarg.vol_param.volume = relvol; cmdarg.vol_param.volume = relvol;
@ -3009,6 +3021,12 @@ player_volume_setabs_speaker(uint64_t id, int vol)
union player_arg cmdarg; union player_arg cmdarg;
int ret; int ret;
if (vol < 0 || vol > 100)
{
DPRINTF(E_LOG, L_PLAYER, "Volume (%d) for player_volume_setabs_speaker is out of range\n", vol);
return -1;
}
cmdarg.vol_param.spk_id = id; cmdarg.vol_param.spk_id = id;
cmdarg.vol_param.volume = vol; cmdarg.vol_param.volume = vol;