summaryrefslogtreecommitdiffstats
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 @@
#include "playback.h"
#include "kernel.h"
+#include <pthread.h>
#include <SDL.h>
#include <glib.h>
#include <gst/gst.h>
@@ -92,14 +93,33 @@ GMainLoop *pcm_loop = NULL;
static __u8* pcm_data = NULL;
static size_t pcm_data_size = 0;
+static int audio_locked = 0;
+static pthread_mutex_t audio_lock_mutex = PTHREAD_MUTEX_INITIALIZER;
static int inside_feed_data = 0;
+/*
+ * mutex lock/unlock wrappers neatness' sake
+ */
+static inline void lock_audio(void)
+{
+ pthread_mutex_lock(&audio_lock_mutex);
+}
+
+static inline void unlock_audio(void)
+{
+ pthread_mutex_unlock(&audio_lock_mutex);
+}
+
void pcm_play_lock(void)
{
+ if (++audio_locked == 1)
+ lock_audio();
}
void pcm_play_unlock(void)
{
+ if (--audio_locked == 0)
+ unlock_audio();
}
void pcm_dma_apply_settings(void)
@@ -163,6 +183,8 @@ static void feed_data(GstElement * appsrc, guint size_hint, void *unused)
(void)size_hint;
(void)unused;
+ lock_audio();
+
/* Make sure we don't trigger a gst_element_set_state() call
from inside gstreamer's stream thread as it will deadlock */
inside_feed_data = 1;
@@ -191,6 +213,8 @@ static void feed_data(GstElement * appsrc, guint size_hint, void *unused)
}
inside_feed_data = 0;
+
+ unlock_audio();
}
const void * pcm_play_dma_get_peak_buffer(int *count)
@@ -395,6 +419,8 @@ void pcm_shutdown_gstreamer(void)
g_main_loop_quit(pcm_loop);
g_main_loop_unref (pcm_loop);
+
+ pthread_mutex_destroy(&audio_lock_mutex);
}
void pcm_play_dma_postinit(void)