diff options
author | J. Alexander Treuman <jat@spatialrift.net> | 2006-07-19 16:48:24 +0000 |
---|---|---|
committer | J. Alexander Treuman <jat@spatialrift.net> | 2006-07-19 16:48:24 +0000 |
commit | 2728853ec132a7b68caa269ed3f3f4839b391345 (patch) | |
tree | 44441dcf98a773e178be77c953f8f373bef40396 /src/audioOutputs | |
parent | 649a037e8d9639ddf8fa6bd3570b5ed8beb7a949 (diff) | |
download | mpd-2728853ec132a7b68caa269ed3f3f4839b391345.tar.gz mpd-2728853ec132a7b68caa269ed3f3f4839b391345.tar.xz mpd-2728853ec132a7b68caa269ed3f3f4839b391345.zip |
Throttle PuleAudio connection attempts so we don't spam the error log
git-svn-id: https://svn.musicpd.org/mpd/trunk@4403 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r-- | src/audioOutputs/audioOutput_pulse.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/audioOutputs/audioOutput_pulse.c b/src/audioOutputs/audioOutput_pulse.c index 08f2f3f46..cfd4f7c21 100644 --- a/src/audioOutputs/audioOutput_pulse.c +++ b/src/audioOutputs/audioOutput_pulse.c @@ -22,18 +22,23 @@ #ifdef HAVE_PULSE -#define MPD_PULSE_NAME "mpd" - #include "../conf.h" #include "../log.h" +#include <time.h> + #include <pulse/simple.h> #include <pulse/error.h> +#define MPD_PULSE_NAME "mpd" +#define CONN_ATTEMPT_INTERVAL 60 + typedef struct _PulseData { + pa_simple * s; char * server; char * sink; - pa_simple * s; + int connAttempts; + time_t lastAttempt; } PulseData; static PulseData * newPulseData() @@ -41,9 +46,13 @@ static PulseData * newPulseData() PulseData * ret; ret = malloc(sizeof(PulseData)); + + ret->s = NULL; ret->server = NULL; ret->sink = NULL; - ret->s = NULL; + ret->connAttempts = 0; + ret->lastAttempt = 0; + return ret; } @@ -106,11 +115,19 @@ static int pulse_openDevice(AudioOutput * audioOutput) PulseData * ad; AudioFormat * audioFormat; pa_sample_spec ss; + time_t t; int error; + t = time(NULL); ad = audioOutput->data; audioFormat = &audioOutput->outAudioFormat; + if (ad->connAttempts != 0 && + (t - ad->lastAttempt) < CONN_ATTEMPT_INTERVAL) return -1; + + ad->connAttempts++; + ad->lastAttempt = t; + if (audioFormat->bits != 16) { ERROR("PulseAudio doesn't support %i bit audio\n", audioFormat->bits); @@ -126,10 +143,12 @@ static int pulse_openDevice(AudioOutput * audioOutput) &error); if (!ad->s) { ERROR("Cannot connect to server in PulseAudio output " \ - "\"%s\": %s\n", audioOutput->name, pa_strerror(error)); + "\"%s\" (attempt %i): %s\n", audioOutput->name, + ad->connAttempts, pa_strerror(error)); return -1; } + ad->connAttempts = 0; audioOutput->open = 1; DEBUG("PulseAudio output \"%s\" connected and playing %i bit, %i " \ |