volume: use GLib logging
This commit is contained in:
parent
e9b96c6e56
commit
d4018c9966
55
src/volume.c
55
src/volume.c
@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include "volume.h"
|
#include "volume.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "log.h"
|
|
||||||
#include "player_control.h"
|
#include "player_control.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "idle.h"
|
#include "idle.h"
|
||||||
@ -38,6 +37,9 @@
|
|||||||
#include <alsa/asoundlib.h>
|
#include <alsa/asoundlib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#undef G_LOG_DOMAIN
|
||||||
|
#define G_LOG_DOMAIN "volume"
|
||||||
|
|
||||||
#define VOLUME_MIXER_TYPE_SOFTWARE 0
|
#define VOLUME_MIXER_TYPE_SOFTWARE 0
|
||||||
#define VOLUME_MIXER_TYPE_OSS 1
|
#define VOLUME_MIXER_TYPE_OSS 1
|
||||||
#define VOLUME_MIXER_TYPE_ALSA 2
|
#define VOLUME_MIXER_TYPE_ALSA 2
|
||||||
@ -108,7 +110,7 @@ static int prepOssMixer(const char *device)
|
|||||||
ConfigParam *param;
|
ConfigParam *param;
|
||||||
|
|
||||||
if ((volume_ossFd = open(device, O_RDONLY)) < 0) {
|
if ((volume_ossFd = open(device, O_RDONLY)) < 0) {
|
||||||
WARNING("unable to open oss mixer \"%s\"\n", device);
|
g_warning("unable to open oss mixer \"%s\"", device);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +119,7 @@ static int prepOssMixer(const char *device)
|
|||||||
int devmask = 0;
|
int devmask = 0;
|
||||||
|
|
||||||
if (ioctl(volume_ossFd, SOUND_MIXER_READ_DEVMASK, &devmask) < 0) {
|
if (ioctl(volume_ossFd, SOUND_MIXER_READ_DEVMASK, &devmask) < 0) {
|
||||||
WARNING("errors getting read_devmask for oss mixer\n");
|
g_warning("errors getting read_devmask for oss mixer");
|
||||||
closeOssMixer();
|
closeOssMixer();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -125,13 +127,13 @@ static int prepOssMixer(const char *device)
|
|||||||
i = oss_find_mixer(param->value);
|
i = oss_find_mixer(param->value);
|
||||||
|
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
WARNING("mixer control \"%s\" not found at line %i\n",
|
g_warning("mixer control \"%s\" not found at line %i",
|
||||||
param->value, param->line);
|
param->value, param->line);
|
||||||
closeOssMixer();
|
closeOssMixer();
|
||||||
return -1;
|
return -1;
|
||||||
} else if (!((1 << i) & devmask)) {
|
} else if (!((1 << i) & devmask)) {
|
||||||
WARNING("mixer control \"%s\" not usable at line %i\n",
|
g_warning("mixer control \"%s\" not usable at line %i",
|
||||||
param->value, param->line);
|
param->value, param->line);
|
||||||
closeOssMixer();
|
closeOssMixer();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -158,7 +160,7 @@ static int getOssVolumeLevel(void)
|
|||||||
|
|
||||||
if (ioctl(volume_ossFd, MIXER_READ(volume_ossControl), &level) < 0) {
|
if (ioctl(volume_ossFd, MIXER_READ(volume_ossControl), &level) < 0) {
|
||||||
closeOssMixer();
|
closeOssMixer();
|
||||||
WARNING("unable to read volume\n");
|
g_warning("unable to read volume");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,8 +168,8 @@ static int getOssVolumeLevel(void)
|
|||||||
right = (level & 0xff00) >> 8;
|
right = (level & 0xff00) >> 8;
|
||||||
|
|
||||||
if (left != right) {
|
if (left != right) {
|
||||||
WARNING("volume for left and right is not the same, \"%i\" and "
|
g_warning("volume for left and right is not the same, \"%i\" "
|
||||||
"\"%i\"\n", left, right);
|
"and \"%i\"", left, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
return left;
|
return left;
|
||||||
@ -223,14 +225,15 @@ static int prepAlsaMixer(const char *card)
|
|||||||
err = snd_mixer_open(&volume_alsaMixerHandle, 0);
|
err = snd_mixer_open(&volume_alsaMixerHandle, 0);
|
||||||
snd_config_update_free_global();
|
snd_config_update_free_global();
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
WARNING("problems opening alsa mixer: %s\n", snd_strerror(err));
|
g_warning("problems opening alsa mixer: %s",
|
||||||
|
snd_strerror(err));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = snd_mixer_attach(volume_alsaMixerHandle, card)) < 0) {
|
if ((err = snd_mixer_attach(volume_alsaMixerHandle, card)) < 0) {
|
||||||
closeAlsaMixer();
|
closeAlsaMixer();
|
||||||
WARNING("problems attaching alsa mixer: %s\n",
|
g_warning("problems attaching alsa mixer: %s",
|
||||||
snd_strerror(err));
|
snd_strerror(err));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,15 +241,15 @@ static int prepAlsaMixer(const char *card)
|
|||||||
snd_mixer_selem_register(volume_alsaMixerHandle, NULL,
|
snd_mixer_selem_register(volume_alsaMixerHandle, NULL,
|
||||||
NULL)) < 0) {
|
NULL)) < 0) {
|
||||||
closeAlsaMixer();
|
closeAlsaMixer();
|
||||||
WARNING("problems snd_mixer_selem_register'ing: %s\n",
|
g_warning("problems snd_mixer_selem_register'ing: %s",
|
||||||
snd_strerror(err));
|
snd_strerror(err));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = snd_mixer_load(volume_alsaMixerHandle)) < 0) {
|
if ((err = snd_mixer_load(volume_alsaMixerHandle)) < 0) {
|
||||||
closeAlsaMixer();
|
closeAlsaMixer();
|
||||||
WARNING("problems snd_mixer_selem_register'ing: %s\n",
|
g_warning("problems snd_mixer_selem_register'ing: %s",
|
||||||
snd_strerror(err));
|
snd_strerror(err));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,7 +279,7 @@ static int prepAlsaMixer(const char *card)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
WARNING("can't find alsa mixer_control \"%s\"\n", controlName);
|
g_warning("can't find alsa mixer_control \"%s\"", controlName);
|
||||||
|
|
||||||
closeAlsaMixer();
|
closeAlsaMixer();
|
||||||
return -1;
|
return -1;
|
||||||
@ -303,8 +306,8 @@ static int prep_alsa_get_level(long *level)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
WARNING("problems getting alsa volume: %s (snd_mixer_%s)\n",
|
g_warning("problems getting alsa volume: %s (snd_mixer_%s)",
|
||||||
snd_strerror(err), cmd);
|
snd_strerror(err), cmd);
|
||||||
closeAlsaMixer();
|
closeAlsaMixer();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -361,8 +364,8 @@ static int changeAlsaVolumeLevel(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) {
|
||||||
WARNING("problems setting alsa volume: %s\n",
|
g_warning("problems setting alsa volume: %s",
|
||||||
snd_strerror(err));
|
snd_strerror(err));
|
||||||
closeAlsaMixer();
|
closeAlsaMixer();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -425,8 +428,8 @@ void initVolume(void)
|
|||||||
volume_mixerType = VOLUME_MIXER_TYPE_SOFTWARE;
|
volume_mixerType = VOLUME_MIXER_TYPE_SOFTWARE;
|
||||||
volume_mixerDevice = VOLUME_MIXER_SOFTWARE_DEFAULT;
|
volume_mixerDevice = VOLUME_MIXER_SOFTWARE_DEFAULT;
|
||||||
} else {
|
} else {
|
||||||
FATAL("unknown mixer type %s at line %i\n",
|
g_error("unknown mixer type %s at line %i",
|
||||||
param->value, param->line);
|
param->value, param->line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,7 +443,7 @@ void initVolume(void)
|
|||||||
void openVolumeDevice(void)
|
void openVolumeDevice(void)
|
||||||
{
|
{
|
||||||
if (prepMixer(volume_mixerDevice) < 0) {
|
if (prepMixer(volume_mixerDevice) < 0) {
|
||||||
WARNING("using software volume\n");
|
g_message("using software volume");
|
||||||
volume_mixerType = VOLUME_MIXER_TYPE_SOFTWARE;
|
volume_mixerType = VOLUME_MIXER_TYPE_SOFTWARE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -533,7 +536,7 @@ void read_sw_volume_state(FILE *fp)
|
|||||||
if (G_LIKELY(!*end))
|
if (G_LIKELY(!*end))
|
||||||
changeSoftwareVolume(sv, 0);
|
changeSoftwareVolume(sv, 0);
|
||||||
else
|
else
|
||||||
ERROR("Can't parse software volume: %s\n", buf);
|
g_warning("Can't parse software volume: %s", buf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user