diff options
Diffstat (limited to 'firmware/target/hosted/maemo/pcm-gstreamer.c')
-rw-r--r-- | firmware/target/hosted/maemo/pcm-gstreamer.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/firmware/target/hosted/maemo/pcm-gstreamer.c b/firmware/target/hosted/maemo/pcm-gstreamer.c index d6879ea083..e5620d0702 100644 --- a/firmware/target/hosted/maemo/pcm-gstreamer.c +++ b/firmware/target/hosted/maemo/pcm-gstreamer.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include "playback.h" | 33 | #include "playback.h" |
34 | #include "kernel.h" | 34 | #include "kernel.h" |
35 | 35 | ||
36 | #include <pthread.h> | ||
36 | #include <SDL.h> | 37 | #include <SDL.h> |
37 | #include <glib.h> | 38 | #include <glib.h> |
38 | #include <gst/gst.h> | 39 | #include <gst/gst.h> |
@@ -92,14 +93,33 @@ GMainLoop *pcm_loop = NULL; | |||
92 | static __u8* pcm_data = NULL; | 93 | static __u8* pcm_data = NULL; |
93 | static size_t pcm_data_size = 0; | 94 | static size_t pcm_data_size = 0; |
94 | 95 | ||
96 | static int audio_locked = 0; | ||
97 | static pthread_mutex_t audio_lock_mutex = PTHREAD_MUTEX_INITIALIZER; | ||
95 | static int inside_feed_data = 0; | 98 | static int inside_feed_data = 0; |
96 | 99 | ||
100 | /* | ||
101 | * mutex lock/unlock wrappers neatness' sake | ||
102 | */ | ||
103 | static inline void lock_audio(void) | ||
104 | { | ||
105 | pthread_mutex_lock(&audio_lock_mutex); | ||
106 | } | ||
107 | |||
108 | static inline void unlock_audio(void) | ||
109 | { | ||
110 | pthread_mutex_unlock(&audio_lock_mutex); | ||
111 | } | ||
112 | |||
97 | void pcm_play_lock(void) | 113 | void pcm_play_lock(void) |
98 | { | 114 | { |
115 | if (++audio_locked == 1) | ||
116 | lock_audio(); | ||
99 | } | 117 | } |
100 | 118 | ||
101 | void pcm_play_unlock(void) | 119 | void pcm_play_unlock(void) |
102 | { | 120 | { |
121 | if (--audio_locked == 0) | ||
122 | unlock_audio(); | ||
103 | } | 123 | } |
104 | 124 | ||
105 | void pcm_dma_apply_settings(void) | 125 | void pcm_dma_apply_settings(void) |
@@ -163,6 +183,8 @@ static void feed_data(GstElement * appsrc, guint size_hint, void *unused) | |||
163 | (void)size_hint; | 183 | (void)size_hint; |
164 | (void)unused; | 184 | (void)unused; |
165 | 185 | ||
186 | lock_audio(); | ||
187 | |||
166 | /* Make sure we don't trigger a gst_element_set_state() call | 188 | /* Make sure we don't trigger a gst_element_set_state() call |
167 | from inside gstreamer's stream thread as it will deadlock */ | 189 | from inside gstreamer's stream thread as it will deadlock */ |
168 | inside_feed_data = 1; | 190 | inside_feed_data = 1; |
@@ -191,6 +213,8 @@ static void feed_data(GstElement * appsrc, guint size_hint, void *unused) | |||
191 | } | 213 | } |
192 | 214 | ||
193 | inside_feed_data = 0; | 215 | inside_feed_data = 0; |
216 | |||
217 | unlock_audio(); | ||
194 | } | 218 | } |
195 | 219 | ||
196 | const void * pcm_play_dma_get_peak_buffer(int *count) | 220 | const void * pcm_play_dma_get_peak_buffer(int *count) |
@@ -395,6 +419,8 @@ void pcm_shutdown_gstreamer(void) | |||
395 | 419 | ||
396 | g_main_loop_quit(pcm_loop); | 420 | g_main_loop_quit(pcm_loop); |
397 | g_main_loop_unref (pcm_loop); | 421 | g_main_loop_unref (pcm_loop); |
422 | |||
423 | pthread_mutex_destroy(&audio_lock_mutex); | ||
398 | } | 424 | } |
399 | 425 | ||
400 | void pcm_play_dma_postinit(void) | 426 | void pcm_play_dma_postinit(void) |