--- ext/pulse/pulsesink.c 2008/11/23 15:08:45 1.11
+++ ext/pulse/pulsesink.c 2009/01/05 17:31:13 1.12
@@ -279,7 +279,6 @@
{
if (pulsesink->stream) {
pa_stream_disconnect (pulsesink->stream);
- pa_threaded_mainloop_wait (pulsesink->mainloop);
pa_stream_unref (pulsesink->stream);
pulsesink->stream = NULL;
}
@@ -588,16 +587,14 @@
if (!pulsesink->context
|| pa_context_get_state (pulsesink->context) != PA_CONTEXT_READY) {
GST_ELEMENT_ERROR (pulsesink, RESOURCE, FAILED, ("Bad context state: %s",
- pulsesink->
- context ? pa_strerror (pa_context_errno (pulsesink->context)) :
- NULL), (NULL));
+ pulsesink->context ? pa_strerror (pa_context_errno (pulsesink->
+ context)) : NULL), (NULL));
goto unlock_and_fail;
}
if (!(pulsesink->stream = pa_stream_new (pulsesink->context,
- pulsesink->
- stream_name ? pulsesink->stream_name : "Playback Stream",
- &pulsesink->sample_spec,
+ pulsesink->stream_name ? pulsesink->
+ stream_name : "Playback Stream", &pulsesink->sample_spec,
gst_pulse_gst_to_channel_map (&channel_map, spec)))) {
GST_ELEMENT_ERROR (pulsesink, RESOURCE, FAILED,
("Failed to create stream: %s",
--- ext/pulse/pulsesink.c 2009/01/05 17:31:13 1.12
+++ ext/pulse/pulsesink.c 2009/01/07 20:38:50 1.13
@@ -264,6 +264,8 @@
pulsesink->context = NULL;
pulsesink->stream = NULL;
+ pulsesink->stream_mutex = g_mutex_new ();
+
pulsesink->mainloop = pa_threaded_mainloop_new ();
g_assert (pulsesink->mainloop);
@@ -277,11 +279,13 @@
static void
gst_pulsesink_destroy_stream (GstPulseSink * pulsesink)
{
+ g_mutex_lock (pulsesink->stream_mutex);
if (pulsesink->stream) {
pa_stream_disconnect (pulsesink->stream);
pa_stream_unref (pulsesink->stream);
pulsesink->stream = NULL;
}
+ g_mutex_unlock (pulsesink->stream_mutex);
g_free (pulsesink->stream_name);
pulsesink->stream_name = NULL;
@@ -290,7 +294,6 @@
static void
gst_pulsesink_destroy_context (GstPulseSink * pulsesink)
{
-
gst_pulsesink_destroy_stream (pulsesink);
if (pulsesink->context) {
@@ -313,6 +316,8 @@
g_free (pulsesink->device);
g_free (pulsesink->stream_name);
+ g_mutex_free (pulsesink->stream_mutex);
+
pa_threaded_mainloop_free (pulsesink->mainloop);
if (pulsesink->probe) {
@@ -482,8 +487,16 @@
case PA_STREAM_READY:
case PA_STREAM_FAILED:
- case PA_STREAM_TERMINATED:
- pa_threaded_mainloop_signal (pulsesink->mainloop, 0);
+ case PA_STREAM_TERMINATED:{
+ pa_stream *cur_stream;
+
+ g_mutex_lock (pulsesink->stream_mutex);
+ cur_stream = pulsesink->stream;
+ g_mutex_unlock (pulsesink->stream_mutex);
+
+ if (cur_stream == s)
+ pa_threaded_mainloop_signal (pulsesink->mainloop, 0);
+ }
break;
case PA_STREAM_UNCONNECTED:
@@ -496,16 +509,28 @@
gst_pulsesink_stream_request_cb (pa_stream * s, size_t length, void *userdata)
{
GstPulseSink *pulsesink = GST_PULSESINK (userdata);
+ pa_stream *cur_stream;
- pa_threaded_mainloop_signal (pulsesink->mainloop, 0);
+ g_mutex_lock (pulsesink->stream_mutex);
+ cur_stream = pulsesink->stream;
+ g_mutex_unlock (pulsesink->stream_mutex);
+
+ if (cur_stream == s)
+ pa_threaded_mainloop_signal (pulsesink->mainloop, 0);
}
static void
gst_pulsesink_stream_latency_update_cb (pa_stream * s, void *userdata)
{
GstPulseSink *pulsesink = GST_PULSESINK (userdata);
+ pa_stream *cur_stream;
- pa_threaded_mainloop_signal (pulsesink->mainloop, 0);
+ g_mutex_lock (pulsesink->stream_mutex);
+ cur_stream = pulsesink->stream;
+ g_mutex_unlock (pulsesink->stream_mutex);
+
+ if (cur_stream == s)
+ pa_threaded_mainloop_signal (pulsesink->mainloop, 0);
}
static gboolean
@@ -592,15 +617,18 @@
goto unlock_and_fail;
}
+ g_mutex_lock (pulsesink->stream_mutex);
if (!(pulsesink->stream = pa_stream_new (pulsesink->context,
pulsesink->stream_name ? pulsesink->
stream_name : "Playback Stream", &pulsesink->sample_spec,
gst_pulse_gst_to_channel_map (&channel_map, spec)))) {
+ g_mutex_unlock (pulsesink->stream_mutex);
GST_ELEMENT_ERROR (pulsesink, RESOURCE, FAILED,
("Failed to create stream: %s",
pa_strerror (pa_context_errno (pulsesink->context))), (NULL));
goto unlock_and_fail;
}
+ g_mutex_unlock (pulsesink->stream_mutex);
pa_stream_set_state_callback (pulsesink->stream,
gst_pulsesink_stream_state_cb, pulsesink);
--- ext/pulse/pulsesink.h 2008/08/13 13:57:01 1.3
+++ ext/pulse/pulsesink.h 2009/01/07 20:38:50 1.4
@@ -57,6 +57,7 @@
pa_context *context;
pa_stream *stream;
+ GMutex *stream_mutex;
pa_sample_spec sample_spec;