From 2dd01747f8aa7abbdfca49cc18603e4090ccdc95 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 20 Feb 2012 18:22:43 +0000 Subject: [PATCH] Fix crash on underrun in the alsa player Originally committed to SVN as r6497. --- aegisub/src/audio_player_alsa.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/aegisub/src/audio_player_alsa.cpp b/aegisub/src/audio_player_alsa.cpp index 8e5867dde..ddb862b51 100644 --- a/aegisub/src/audio_player_alsa.cpp +++ b/aegisub/src/audio_player_alsa.cpp @@ -270,7 +270,17 @@ do_setup: } // Fill buffer - avail = std::min(snd_pcm_avail(pcm), (snd_pcm_sframes_t)(ps.end_position-position)); + avail = snd_pcm_avail(pcm); + if (avail == -EPIPE) + { + if (snd_pcm_recover(pcm, -EPIPE, 1) < 0) + { + LOG_D("audio/player/alsa") << "failed to recover from underrun"; + return (void*)"snd_pcm_avail"; + } + avail = snd_pcm_avail(pcm); + } + avail = std::min(avail, (snd_pcm_sframes_t)(ps.end_position-position)); buf = new char[avail*framesize]; ps.provider->GetAudioWithVolume(buf, position, avail, ps.volume); written = 0;