Skip to content

Commit

Permalink
Work-around for a hang when USB devices are unplugged, contributed by…
Browse files Browse the repository at this point in the history
… James Zipperer
  • Loading branch information
slouken committed Oct 13, 2016
1 parent 14e7da7 commit 62310c6
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/audio/alsa/SDL_alsa_audio.c
Expand Up @@ -314,9 +314,20 @@ ALSA_PlayDevice(_THIS)
swizzle_alsa_channels(this, this->hidden->mixbuf, frames_left);

while ( frames_left > 0 && SDL_AtomicGet(&this->enabled) ) {
/* !!! FIXME: This works, but needs more testing before going live */
/* ALSA_snd_pcm_wait(this->hidden->pcm_handle, -1); */
int status = ALSA_snd_pcm_writei(this->hidden->pcm_handle,
int status;

/* This wait is a work-around for a hang when USB devices are
unplugged. Normally it should not result in any waiting,
but in the case of a USB unplug, it serves as a way to
join the playback thread after the timeout occurs */
status = ALSA_snd_pcm_wait(this->hidden->pcm_handle, 1000);
if (status == 0) {
/*fprintf(stderr, "ALSA timeout waiting for available buffer space\n");*/
SDL_OpenedAudioDeviceDisconnected(this);
return;
}

status = ALSA_snd_pcm_writei(this->hidden->pcm_handle,
sample_buf, frames_left);

if (status < 0) {
Expand Down

0 comments on commit 62310c6

Please sign in to comment.