volume: don't pass "fd" to changeVolumeLevel()
The "volume" library shouldn't talk to the client. Move error handling to command.c.
This commit is contained in:
parent
8e3c40f032
commit
f7e414d934
@ -911,21 +911,33 @@ static int handleListAll(int fd, mpd_unused int *permission,
|
|||||||
static int handleVolume(int fd, mpd_unused int *permission,
|
static int handleVolume(int fd, mpd_unused int *permission,
|
||||||
mpd_unused int argc, char *argv[])
|
mpd_unused int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int change;
|
int change, ret;
|
||||||
|
|
||||||
if (check_int(fd, &change, argv[1], need_integer) < 0)
|
if (check_int(fd, &change, argv[1], need_integer) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
return changeVolumeLevel(fd, change, 1);
|
|
||||||
|
ret = changeVolumeLevel(change, 1);
|
||||||
|
if (ret == -1)
|
||||||
|
commandError(fd, ACK_ERROR_SYSTEM,
|
||||||
|
"problems setting volume");
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handleSetVol(int fd, mpd_unused int *permission,
|
static int handleSetVol(int fd, mpd_unused int *permission,
|
||||||
mpd_unused int argc, char *argv[])
|
mpd_unused int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int level;
|
int level, ret;
|
||||||
|
|
||||||
if (check_int(fd, &level, argv[1], need_integer) < 0)
|
if (check_int(fd, &level, argv[1], need_integer) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
return changeVolumeLevel(fd, level, 0);
|
|
||||||
|
ret = changeVolumeLevel(level, 0);
|
||||||
|
if (ret == -1)
|
||||||
|
commandError(fd, ACK_ERROR_SYSTEM,
|
||||||
|
"problems setting volume");
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handleRepeat(int fd, mpd_unused int *permission,
|
static int handleRepeat(int fd, mpd_unused int *permission,
|
||||||
|
26
src/volume.c
26
src/volume.c
@ -17,13 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
#include "volume.h"
|
#include "volume.h"
|
||||||
|
|
||||||
#include "command.h"
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "player_control.h"
|
#include "player_control.h"
|
||||||
#include "gcc.h"
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "ack.h"
|
|
||||||
#include "os_compat.h"
|
#include "os_compat.h"
|
||||||
|
|
||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
@ -169,18 +166,15 @@ static int getOssVolumeLevel(void)
|
|||||||
return left;
|
return left;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int changeOssVolumeLevel(int fd, int change, int rel)
|
static int changeOssVolumeLevel(int change, int rel)
|
||||||
{
|
{
|
||||||
int current;
|
int current;
|
||||||
int new;
|
int new;
|
||||||
int level;
|
int level;
|
||||||
|
|
||||||
if (rel) {
|
if (rel) {
|
||||||
if ((current = getOssVolumeLevel()) < 0) {
|
if ((current = getOssVolumeLevel()) < 0)
|
||||||
commandError(fd, ACK_ERROR_SYSTEM,
|
|
||||||
"problem getting current volume");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
new = current + change;
|
new = current + change;
|
||||||
} else {
|
} else {
|
||||||
@ -198,7 +192,6 @@ static int changeOssVolumeLevel(int fd, int change, int rel)
|
|||||||
|
|
||||||
if (ioctl(volume_ossFd, MIXER_WRITE(volume_ossControl), &level) < 0) {
|
if (ioctl(volume_ossFd, MIXER_WRITE(volume_ossControl), &level) < 0) {
|
||||||
closeOssMixer();
|
closeOssMixer();
|
||||||
commandError(fd, ACK_ERROR_SYSTEM, "problems setting volume");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,7 +321,7 @@ static int getAlsaVolumeLevel(void)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int changeAlsaVolumeLevel(int fd, int change, int rel)
|
static int changeAlsaVolumeLevel(int change, int rel)
|
||||||
{
|
{
|
||||||
float vol;
|
float vol;
|
||||||
long level;
|
long level;
|
||||||
@ -361,7 +354,6 @@ static int changeAlsaVolumeLevel(int fd, int change, int rel)
|
|||||||
if ((err =
|
if ((err =
|
||||||
snd_mixer_selem_set_playback_volume_all(volume_alsaElem,
|
snd_mixer_selem_set_playback_volume_all(volume_alsaElem,
|
||||||
level)) < 0) {
|
level)) < 0) {
|
||||||
commandError(fd, ACK_ERROR_SYSTEM, "problems setting volume");
|
|
||||||
WARNING("problems setting alsa volume: %s\n",
|
WARNING("problems setting alsa volume: %s\n",
|
||||||
snd_strerror(err));
|
snd_strerror(err));
|
||||||
closeAlsaMixer();
|
closeAlsaMixer();
|
||||||
@ -469,7 +461,7 @@ int getVolumeLevel(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int changeSoftwareVolume(mpd_unused int fd, int change, int rel)
|
static int changeSoftwareVolume(int change, int rel)
|
||||||
{
|
{
|
||||||
int new = change;
|
int new = change;
|
||||||
|
|
||||||
@ -497,19 +489,19 @@ static int changeSoftwareVolume(mpd_unused int fd, int change, int rel)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int changeVolumeLevel(int fd, int change, int rel)
|
int changeVolumeLevel(int change, int rel)
|
||||||
{
|
{
|
||||||
switch (volume_mixerType) {
|
switch (volume_mixerType) {
|
||||||
#ifdef HAVE_ALSA
|
#ifdef HAVE_ALSA
|
||||||
case VOLUME_MIXER_TYPE_ALSA:
|
case VOLUME_MIXER_TYPE_ALSA:
|
||||||
return changeAlsaVolumeLevel(fd, change, rel);
|
return changeAlsaVolumeLevel(change, rel);
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_OSS
|
#ifdef HAVE_OSS
|
||||||
case VOLUME_MIXER_TYPE_OSS:
|
case VOLUME_MIXER_TYPE_OSS:
|
||||||
return changeOssVolumeLevel(fd, change, rel);
|
return changeOssVolumeLevel(change, rel);
|
||||||
#endif
|
#endif
|
||||||
case VOLUME_MIXER_TYPE_SOFTWARE:
|
case VOLUME_MIXER_TYPE_SOFTWARE:
|
||||||
return changeSoftwareVolume(fd, change, rel);
|
return changeSoftwareVolume(change, rel);
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -531,7 +523,7 @@ void read_sw_volume_state(FILE *fp)
|
|||||||
continue;
|
continue;
|
||||||
sv = strtol(buf + len, &end, 10);
|
sv = strtol(buf + len, &end, 10);
|
||||||
if (mpd_likely(!*end))
|
if (mpd_likely(!*end))
|
||||||
changeSoftwareVolume(STDERR_FILENO, sv, 0);
|
changeSoftwareVolume(sv, 0);
|
||||||
else
|
else
|
||||||
ERROR("Can't parse software volume: %s\n", buf);
|
ERROR("Can't parse software volume: %s\n", buf);
|
||||||
return;
|
return;
|
||||||
|
@ -33,7 +33,7 @@ void finishVolume(void);
|
|||||||
|
|
||||||
int getVolumeLevel(void);
|
int getVolumeLevel(void);
|
||||||
|
|
||||||
int changeVolumeLevel(int fd, int change, int rel);
|
int changeVolumeLevel(int change, int rel);
|
||||||
|
|
||||||
void read_sw_volume_state(FILE *fp);
|
void read_sw_volume_state(FILE *fp);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user