summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/maemo
diff options
context:
space:
mode:
authorThomas Jarosch <tomj@simonv.com>2011-12-09 19:45:58 +0000
committerThomas Jarosch <tomj@simonv.com>2011-12-09 19:45:58 +0000
commit9d9d867bce364f1381a21c2a09eb7bac6b5c7df2 (patch)
treedfb0451634a5dcc8c3d5445f0accf08114f565c2 /firmware/target/hosted/maemo
parent8906b3e659ccfa7f9ada221a1d6166a7348d569e (diff)
downloadrockbox-9d9d867bce364f1381a21c2a09eb7bac6b5c7df2.tar.gz
rockbox-9d9d867bce364f1381a21c2a09eb7bac6b5c7df2.zip
Nokia N900: Implement pcm_play_lock() / pcm_play_unlock()
Shamelessly stolen from pcm-android.c Thanks to Michael Sevakis for pointing out that pcm_play_lock() is actually needed. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31190 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/hosted/maemo')
-rw-r--r--firmware/target/hosted/maemo/pcm-gstreamer.c26
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;
92static __u8* pcm_data = NULL; 93static __u8* pcm_data = NULL;
93static size_t pcm_data_size = 0; 94static size_t pcm_data_size = 0;
94 95
96static int audio_locked = 0;
97static pthread_mutex_t audio_lock_mutex = PTHREAD_MUTEX_INITIALIZER;
95static int inside_feed_data = 0; 98static int inside_feed_data = 0;
96 99
100/*
101 * mutex lock/unlock wrappers neatness' sake
102 */
103static inline void lock_audio(void)
104{
105 pthread_mutex_lock(&audio_lock_mutex);
106}
107
108static inline void unlock_audio(void)
109{
110 pthread_mutex_unlock(&audio_lock_mutex);
111}
112
97void pcm_play_lock(void) 113void pcm_play_lock(void)
98{ 114{
115 if (++audio_locked == 1)
116 lock_audio();
99} 117}
100 118
101void pcm_play_unlock(void) 119void pcm_play_unlock(void)
102{ 120{
121 if (--audio_locked == 0)
122 unlock_audio();
103} 123}
104 124
105void pcm_dma_apply_settings(void) 125void 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
196const void * pcm_play_dma_get_peak_buffer(int *count) 220const 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
400void pcm_play_dma_postinit(void) 426void pcm_play_dma_postinit(void)