Fix audio crash in ThreadExit and snd_pcm_prepare.

This commit is contained in:
Johns 2012-01-09 15:31:47 +01:00
parent f6df79e8e6
commit 5e005eeff5

View File

@ -296,6 +296,7 @@ static int AlsaPlayRingbuffer(void)
if (first) {
// happens with broken alsa drivers
Error(_("audio/alsa: broken driver %d\n"), avail);
usleep(5 * 1000);
}
Debug(4, "audio/alsa: break state %s\n",
snd_pcm_state_name(snd_pcm_state(AlsaPCMHandle)));
@ -373,14 +374,20 @@ static int AlsaPlayRingbuffer(void)
static void AlsaFlushBuffers(void)
{
int err;
snd_pcm_state_t state;
RingBufferReadAdvance(AlsaRingBuffer, RingBufferUsedBytes(AlsaRingBuffer));
state = snd_pcm_state(AlsaPCMHandle);
Debug(3, "audio/alsa: state %d - %s\n", state, snd_pcm_state_name(state));
if (state != SND_PCM_STATE_OPEN) {
if ((err = snd_pcm_drop(AlsaPCMHandle)) < 0) {
Error(_("audio: snd_pcm_drop(): %s\n"), snd_strerror(err));
}
// ****ing alsa crash, when in open state here
if ((err = snd_pcm_prepare(AlsaPCMHandle)) < 0) {
Error(_("audio: snd_pcm_prepare(): %s\n"), snd_strerror(err));
}
}
AudioPTS = INT64_C(0x8000000000000000);
}
@ -1662,6 +1669,7 @@ static void AudioExitThread(void)
{
void *retval;
if (AudioThread) {
if (pthread_cancel(AudioThread)) {
Error(_("audio: can't queue cancel play thread\n"));
}
@ -1670,6 +1678,7 @@ static void AudioExitThread(void)
}
pthread_cond_destroy(&AudioStartCond);
pthread_mutex_destroy(&AudioMutex);
}
}
#endif