diff options
author | Branislav Katreniak <bkatreniak@nuvotechnologies.com> | 2015-03-20 09:41:05 +0100 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.com> | 2018-01-22 20:24:00 +0000 |
commit | 4f88125b3ddc15367d528e850cc27739f5bb27fa (patch) | |
tree | 0a9c860b92a5d93364ab8d64c5c61d8e290a6af8 /ext | |
parent | a1af74feda8f4e5aeae97da2aebd43d2fe8432eb (diff) |
alsasrc: lock calls to snd_pcm_delay() with mutex as in alsasink
Alsasrc introduced delay_lock in commit 519f85a43e73efb8f3fb2c7be45226e
because alsa-lib is not thread safe for the same handle.
Alsasrc uses the same threading pattern, it should be locked too.
https://bugzilla.gnome.org/show_bug.cgi?id=746015
Diffstat (limited to 'ext')
-rw-r--r-- | ext/alsa/gstalsasrc.c | 10 | ||||
-rw-r--r-- | ext/alsa/gstalsasrc.h | 5 |
2 files changed, 14 insertions, 1 deletions
diff --git a/ext/alsa/gstalsasrc.c b/ext/alsa/gstalsasrc.c index 6ee0ca887..d665f6e3a 100644 --- a/ext/alsa/gstalsasrc.c +++ b/ext/alsa/gstalsasrc.c @@ -118,6 +118,7 @@ gst_alsasrc_finalize (GObject * object) g_free (src->device); g_mutex_clear (&src->alsa_lock); + g_mutex_clear (&src->delay_lock); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -275,6 +276,7 @@ gst_alsasrc_init (GstAlsaSrc * alsasrc) alsasrc->driver_timestamps = FALSE; g_mutex_init (&alsasrc->alsa_lock); + g_mutex_init (&alsasrc->delay_lock); } #define CHECK(call, error) \ @@ -958,7 +960,11 @@ gst_alsasrc_read (GstAudioSrc * asrc, gpointer data, guint length, GST_ALSA_SRC_LOCK (asrc); while (cptr > 0) { - if ((err = snd_pcm_readi (alsa->handle, ptr, cptr)) < 0) { + GST_DELAY_SRC_LOCK (asrc); + err = snd_pcm_readi (alsa->handle, ptr, cptr); + GST_DELAY_SRC_UNLOCK (asrc); + + if (err < 0) { if (err == -EAGAIN) { GST_DEBUG_OBJECT (asrc, "Read error: %s", snd_strerror (err)); continue; @@ -1005,7 +1011,9 @@ gst_alsasrc_delay (GstAudioSrc * asrc) alsa = GST_ALSA_SRC (asrc); + GST_DELAY_SRC_LOCK (asrc); res = snd_pcm_delay (alsa->handle, &delay); + GST_DELAY_SRC_UNLOCK (asrc); if (G_UNLIKELY (res < 0)) { GST_DEBUG_OBJECT (alsa, "snd_pcm_delay returned %d", res); delay = 0; diff --git a/ext/alsa/gstalsasrc.h b/ext/alsa/gstalsasrc.h index 57e27015a..54abb0a0c 100644 --- a/ext/alsa/gstalsasrc.h +++ b/ext/alsa/gstalsasrc.h @@ -39,6 +39,10 @@ G_BEGIN_DECLS #define GST_ALSA_SRC_LOCK(obj) (g_mutex_lock (GST_ALSA_SRC_GET_LOCK (obj))) #define GST_ALSA_SRC_UNLOCK(obj) (g_mutex_unlock (GST_ALSA_SRC_GET_LOCK (obj))) +#define GST_DELAY_SRC_GET_LOCK(obj) (&GST_ALSA_SRC_CAST (obj)->delay_lock) +#define GST_DELAY_SRC_LOCK(obj) (g_mutex_lock (GST_DELAY_SRC_GET_LOCK (obj))) +#define GST_DELAY_SRC_UNLOCK(obj) (g_mutex_unlock (GST_DELAY_SRC_GET_LOCK (obj))) + typedef struct _GstAlsaSrc GstAlsaSrc; typedef struct _GstAlsaSrcClass GstAlsaSrcClass; @@ -71,6 +75,7 @@ struct _GstAlsaSrc { snd_pcm_uframes_t period_size; GMutex alsa_lock; + GMutex delay_lock; }; struct _GstAlsaSrcClass { |