From dccdfce721ffe730de2f55a67ecd1acfcb19bb0a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 8 Sep 2008 04:30:30 -0700 Subject: alsa: use blocking instead of non-blocking write The way we used non-blocking mode was HORRIBLE. It was non-blocking to ALSA, but we end up blocking in a busy loop that does absolutely NOTHING but retry. We don't check for playback cancellation (like we do in decoders) or anything. This is seriously broken and I can imagine it affects people on fast CPUs more because we do asynchronous output buffering and our ALSA device will always have data ready. --- src/audioOutputs/audioOutput_alsa.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/audioOutputs/audioOutput_alsa.c b/src/audioOutputs/audioOutput_alsa.c index 1f6d75d9d..b7b0a1151 100644 --- a/src/audioOutputs/audioOutput_alsa.c +++ b/src/audioOutputs/audioOutput_alsa.c @@ -38,6 +38,9 @@ static const char default_device[] = "default"; #include +/* #define MPD_SND_PCM_NONBLOCK SND_PCM_NONBLOCK */ +#define MPD_SND_PCM_NONBLOCK 0 + /* * This macro will evaluate both statements, but only returns the result * of the second statement to the reader. Thus it'll stringify the @@ -172,14 +175,16 @@ static int alsa_openDevice(AudioOutput * audioOutput) ad->device, audioFormat->bits); err = E(snd_pcm_open, &ad->pcmHandle, ad->device, - SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK); + SND_PCM_STREAM_PLAYBACK, MPD_SND_PCM_NONBLOCK); if (err < 0) { ad->pcmHandle = NULL; goto error; } +#if MPD_SND_PCM_NONBLOCK == SND_PCM_NONBLOCK if ((err = E(snd_pcm_nonblock, ad->pcmHandle, 0)) < 0) goto error; +#endif /* MPD_SND_PCM_NONBLOCK == SND_PCM_NONBLOCK */ period_time_ro = period_time = ad->period_time; configure_hw: -- cgit v1.2.3