From 1d5ad7d1da8afc410550c7c1b3f46dbebd029576 Mon Sep 17 00:00:00 2001 From: Doug Nazar Date: Wed, 7 Apr 2021 04:25:47 -0400 Subject: [PATCH] audio/alsa: Exit write loop if underlying device is already paused. If the alsasink thread starts the write loop but another thread pauses the underlying alsa device, the sink thread will endlessly loop. snd_pcm_writei() will return 0 if the state is SND_PCM_STATE_PAUSED and the loop will never make any progress. Part-of: --- ext/alsa/gstalsasink.c | 4 ++++ gst-libs/gst/audio/gstaudiosink.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/ext/alsa/gstalsasink.c b/ext/alsa/gstalsasink.c index e2eca19483..26cd1fca8e 100644 --- a/ext/alsa/gstalsasink.c +++ b/ext/alsa/gstalsasink.c @@ -1089,6 +1089,10 @@ gst_alsasink_write (GstAudioSink * asink, gpointer data, guint length) goto write_error; } continue; + } else if (err == 0 && alsa->hw_support_pause) { + /* We might be already paused, if so, just bail */ + if (snd_pcm_state (alsa->handle) == SND_PCM_STATE_PAUSED) + break; } ptr += snd_pcm_frames_to_bytes (alsa->handle, err); diff --git a/gst-libs/gst/audio/gstaudiosink.c b/gst-libs/gst/audio/gstaudiosink.c index bda51fe080..d7b26f1d9d 100644 --- a/gst-libs/gst/audio/gstaudiosink.c +++ b/gst-libs/gst/audio/gstaudiosink.c @@ -254,6 +254,9 @@ audioringbuffer_thread_func (GstAudioRingBuffer * buf) GST_DEBUG_FUNCPTR_NAME (writefunc), (errno > 1 ? g_strerror (errno) : "unknown"), left, written); break; + } else if (written == 0 && G_UNLIKELY (g_atomic_int_get (&buf->state) != + GST_AUDIO_RING_BUFFER_STATE_STARTED)) { + break; } left -= written; readptr += written;