From 042c1abc6e1b0023a9f2964573102a332e598237 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 31 Aug 2011 20:58:36 +0200 Subject: output/pulse: use _delete_context() Eliminate duplicate code. --- src/output/pulse_output_plugin.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'src/output') diff --git a/src/output/pulse_output_plugin.c b/src/output/pulse_output_plugin.c index babb8e221..c09b6a6af 100644 --- a/src/output/pulse_output_plugin.c +++ b/src/output/pulse_output_plugin.c @@ -224,6 +224,20 @@ pulse_output_connect(struct pulse_output *po, GError **error_r) return true; } +/** + * Frees and clears the context. + */ +static void +pulse_output_delete_context(struct pulse_output *po) +{ + assert(po != NULL); + assert(po->context != NULL); + + pa_context_disconnect(po->context); + pa_context_unref(po->context); + po->context = NULL; +} + /** * Create, set up and connect a context. * @@ -249,28 +263,13 @@ pulse_output_setup_context(struct pulse_output *po, GError **error_r) pulse_output_subscribe_cb, po); if (!pulse_output_connect(po, error_r)) { - pa_context_unref(po->context); - po->context = NULL; + pulse_output_delete_context(po); return false; } return true; } -/** - * Frees and clears the context. - */ -static void -pulse_output_delete_context(struct pulse_output *po) -{ - assert(po != NULL); - assert(po->context != NULL); - - pa_context_disconnect(po->context); - pa_context_unref(po->context); - po->context = NULL; -} - static void * pulse_output_init(G_GNUC_UNUSED const struct audio_format *audio_format, const struct config_param *param, -- cgit v1.2.3 From e76c752987e0b943e0ee01d6e062e86befd9e8c5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 31 Aug 2011 21:00:55 +0200 Subject: output/pulse: add function _delete_stream() Merge common code. --- src/output/pulse_output_plugin.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/output') diff --git a/src/output/pulse_output_plugin.c b/src/output/pulse_output_plugin.c index c09b6a6af..8fcf26992 100644 --- a/src/output/pulse_output_plugin.c +++ b/src/output/pulse_output_plugin.c @@ -224,6 +224,20 @@ pulse_output_connect(struct pulse_output *po, GError **error_r) return true; } +/** + * Frees and clears the stream. + */ +static void +pulse_output_delete_stream(struct pulse_output *po) +{ + assert(po != NULL); + assert(po->stream != NULL); + + pa_stream_disconnect(po->stream); + pa_stream_unref(po->stream); + po->stream = NULL; +} + /** * Frees and clears the context. */ @@ -539,8 +553,7 @@ pulse_output_open(void *data, struct audio_format *audio_format, error = pa_stream_connect_playback(po->stream, po->sink, NULL, 0, NULL, NULL); if (error < 0) { - pa_stream_unref(po->stream); - po->stream = NULL; + pulse_output_delete_stream(po); g_set_error(error_r, pulse_output_quark(), 0, "pa_stream_connect_playback() has failed: %s", @@ -578,9 +591,7 @@ pulse_output_close(void *data) pulse_wait_for_operation(po->mainloop, o); } - pa_stream_disconnect(po->stream); - pa_stream_unref(po->stream); - po->stream = NULL; + pulse_output_delete_stream(po); if (po->context != NULL && pa_context_get_state(po->context) != PA_CONTEXT_READY) -- cgit v1.2.3 From 60f7ff3de594ef6b54a61b6ad630819ce026c760 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 31 Aug 2011 20:55:49 +0200 Subject: output/pulse: reset callbacks before closing stream/context Fixes assertion failure when a stream callback is invoked too late after a format change. --- src/output/pulse_output_plugin.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/output') diff --git a/src/output/pulse_output_plugin.c b/src/output/pulse_output_plugin.c index 8fcf26992..34d736546 100644 --- a/src/output/pulse_output_plugin.c +++ b/src/output/pulse_output_plugin.c @@ -233,6 +233,13 @@ pulse_output_delete_stream(struct pulse_output *po) assert(po != NULL); assert(po->stream != NULL); +#if PA_CHECK_VERSION(0,9,8) + pa_stream_set_suspended_callback(po->stream, NULL, NULL); +#endif + + pa_stream_set_state_callback(po->stream, NULL, NULL); + pa_stream_set_write_callback(po->stream, NULL, NULL); + pa_stream_disconnect(po->stream); pa_stream_unref(po->stream); po->stream = NULL; @@ -247,6 +254,9 @@ pulse_output_delete_context(struct pulse_output *po) assert(po != NULL); assert(po->context != NULL); + pa_context_set_state_callback(po->context, NULL, NULL); + pa_context_set_subscribe_callback(po->context, NULL, NULL); + pa_context_disconnect(po->context); pa_context_unref(po->context); po->context = NULL; -- cgit v1.2.3 From e7abdab58dd566d9b80fb5caf5dee867f184d913 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 1 Sep 2011 18:21:40 +0200 Subject: output/osx: signal the GCond while mutex is locked --- src/output/osx_plugin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/output') diff --git a/src/output/osx_plugin.c b/src/output/osx_plugin.c index ce82656bd..2c150fc41 100644 --- a/src/output/osx_plugin.c +++ b/src/output/osx_plugin.c @@ -143,8 +143,8 @@ osx_render(void *vdata, if (od->pos >= od->buffer_size) od->pos = 0; - g_mutex_unlock(od->mutex); g_cond_signal(od->condition); + g_mutex_unlock(od->mutex); buffer->mDataByteSize = buffer_size; -- cgit v1.2.3 From 596f36bb78425c8bd6aa4e9a81c796cb78b011c0 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 1 Sep 2011 18:13:05 +0200 Subject: output/osx: don't drain the buffer when closing Eliminate an unnecessary source of deadlocks. --- src/output/osx_plugin.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/output') diff --git a/src/output/osx_plugin.c b/src/output/osx_plugin.c index 2c150fc41..7639f3bd9 100644 --- a/src/output/osx_plugin.c +++ b/src/output/osx_plugin.c @@ -95,12 +95,6 @@ static void osx_output_close(void *data) { struct osx_output *od = data; - g_mutex_lock(od->mutex); - while (od->len) { - g_cond_wait(od->condition, od->mutex); - } - g_mutex_unlock(od->mutex); - AudioOutputUnitStop(od->au); AudioUnitUninitialize(od->au); CloseComponent(od->au); -- cgit v1.2.3