diff --git a/ext/alsa/gstalsasink.c b/ext/alsa/gstalsasink.c index 1ef6b91f74..81731b6bb6 100644 --- a/ext/alsa/gstalsasink.c +++ b/ext/alsa/gstalsasink.c @@ -118,6 +118,7 @@ gst_alsasink_finalise (GObject * object) g_free (sink->device); g_mutex_clear (&sink->alsa_lock); + g_mutex_clear (&sink->delay_lock); g_mutex_lock (&output_mutex); --output_ref; @@ -255,6 +256,7 @@ gst_alsasink_init (GstAlsaSink * alsasink) alsasink->handle = NULL; alsasink->cached_caps = NULL; g_mutex_init (&alsasink->alsa_lock); + g_mutex_init (&alsasink->delay_lock); g_mutex_lock (&output_mutex); if (output_ref == 0) { @@ -1011,7 +1013,9 @@ gst_alsasink_write (GstAudioSink * asink, gpointer data, guint length) if (err < 0) { GST_DEBUG_OBJECT (asink, "wait error, %d", err); } else { + GST_DELAY_SINK_LOCK (asink); err = snd_pcm_writei (alsa->handle, ptr, cptr); + GST_DELAY_SINK_UNLOCK (asink); } GST_DEBUG_OBJECT (asink, "written %d frames out of %d", err, cptr); @@ -1057,7 +1061,9 @@ gst_alsasink_delay (GstAudioSink * asink) alsa = GST_ALSA_SINK (asink); + GST_DELAY_SINK_LOCK (asink); res = snd_pcm_delay (alsa->handle, &delay); + GST_DELAY_SINK_UNLOCK (asink); if (G_UNLIKELY (res < 0)) { /* on errors, report 0 delay */ GST_DEBUG_OBJECT (alsa, "snd_pcm_delay returned %d", res); diff --git a/ext/alsa/gstalsasink.h b/ext/alsa/gstalsasink.h index 3a64a92f1d..8c4c1b0b47 100644 --- a/ext/alsa/gstalsasink.h +++ b/ext/alsa/gstalsasink.h @@ -43,6 +43,10 @@ typedef struct _GstAlsaSinkClass GstAlsaSinkClass; #define GST_ALSA_SINK_LOCK(obj) (g_mutex_lock (GST_ALSA_SINK_GET_LOCK (obj))) #define GST_ALSA_SINK_UNLOCK(obj) (g_mutex_unlock (GST_ALSA_SINK_GET_LOCK (obj))) +#define GST_DELAY_SINK_GET_LOCK(obj) (&GST_ALSA_SINK_CAST (obj)->delay_lock) +#define GST_DELAY_SINK_LOCK(obj) (g_mutex_lock (GST_DELAY_SINK_GET_LOCK (obj))) +#define GST_DELAY_SINK_UNLOCK(obj) (g_mutex_unlock (GST_DELAY_SINK_GET_LOCK (obj))) + /** * GstAlsaSink: * @@ -73,6 +77,7 @@ struct _GstAlsaSink { GstCaps *cached_caps; GMutex alsa_lock; + GMutex delay_lock; }; struct _GstAlsaSinkClass {