aboutsummaryrefslogtreecommitdiffstats
path: root/src/audioOutputs/audioOutput_alsa.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/audioOutputs/audioOutput_alsa.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/audioOutputs/audioOutput_alsa.c b/src/audioOutputs/audioOutput_alsa.c
index 8149917c4..83c4f228c 100644
--- a/src/audioOutputs/audioOutput_alsa.c
+++ b/src/audioOutputs/audioOutput_alsa.c
@@ -37,9 +37,6 @@ static const char default_device[] = "default";
#include <alsa/asoundlib.h>
-/* #define MPD_SND_PCM_NONBLOCK SND_PCM_NONBLOCK */
-#define MPD_SND_PCM_NONBLOCK 0
-
typedef snd_pcm_sframes_t alsa_writei_t(snd_pcm_t * pcm, const void *buffer,
snd_pcm_uframes_t size);
@@ -49,6 +46,7 @@ typedef struct _AlsaData {
alsa_writei_t *writei;
unsigned int buffer_time;
unsigned int period_time;
+ unsigned int period_sleep;
int sampleSize;
int useMmap;
} AlsaData;
@@ -160,18 +158,16 @@ static int alsa_openDevice(struct audio_output *audioOutput)
ad->device, audioFormat->bits);
err = snd_pcm_open(&ad->pcmHandle, ad->device,
- SND_PCM_STREAM_PLAYBACK, MPD_SND_PCM_NONBLOCK);
+ SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
if (err < 0) {
ad->pcmHandle = NULL;
goto error;
}
-#if MPD_SND_PCM_NONBLOCK == SND_PCM_NONBLOCK
cmd = "snd_pcm_nonblock";
err = snd_pcm_nonblock(ad->pcmHandle, 0);
if (err < 0)
goto error;
-#endif /* MPD_SND_PCM_NONBLOCK == SND_PCM_NONBLOCK */
period_time_ro = period_time = ad->period_time;
configure_hw:
@@ -254,6 +250,8 @@ configure_hw:
if (retry != MPD_ALSA_RETRY_NR)
DEBUG("ALSA period_time set to %d\n", period_time);
+ ad->period_sleep = period_time >> 1;
+
cmd = "snd_pcm_hw_params_get_buffer_size";
err = snd_pcm_hw_params_get_buffer_size(hwparams, &alsa_buffer_size);
if (err < 0)
@@ -388,7 +386,12 @@ static int alsa_playAudio(struct audio_output *audioOutput,
while (size > 0) {
ret = ad->writei(ad->pcmHandle, playChunk, size);
- if (ret == -EAGAIN || ret == -EINTR)
+ if (ret == -EAGAIN) {
+ DEBUG("ALSA busy, sleeping %d\n", ad->period_sleep);
+ my_usleep(ad->period_sleep);
+ continue;
+ }
+ if (ret == -EINTR)
continue;
if (ret < 0) {