From 2728853ec132a7b68caa269ed3f3f4839b391345 Mon Sep 17 00:00:00 2001 From: "J. Alexander Treuman" Date: Wed, 19 Jul 2006 16:48:24 +0000 Subject: 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 --- src/audioOutputs/audioOutput_pulse.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'src/audioOutputs') 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 + #include #include +#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 " \ -- cgit v1.2.3