From 1f10ca4e4bb1d1181cf16d6998e71d2be1fb1b19 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 23 Jul 2008 16:50:16 +0200 Subject: [PATCH] don't break if we fail to resume access to an audio device --- src/pulsecore/sink.c | 17 +++++++++++++---- src/pulsecore/source.c | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index 7497103..4102f31 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -261,22 +261,31 @@ pa_sink* pa_sink_new( static int sink_set_state(pa_sink *s, pa_sink_state_t state) { int ret; pa_bool_t suspend_change; + pa_sink_state_t original_state; pa_assert(s); if (s->state == state) return 0; + original_state = s->state; + suspend_change = - (s->state == PA_SINK_SUSPENDED && PA_SINK_IS_OPENED(state)) || - (PA_SINK_IS_OPENED(s->state) && state == PA_SINK_SUSPENDED); + (original_state == PA_SINK_SUSPENDED && PA_SINK_IS_OPENED(state)) || + (PA_SINK_IS_OPENED(original_state) && state == PA_SINK_SUSPENDED); if (s->set_state) if ((ret = s->set_state(s, state)) < 0) - return -1; + return ret; if (s->asyncmsgq) - pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_SET_STATE, PA_UINT_TO_PTR(state), 0, NULL) == 0); + if ((ret = pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_SET_STATE, PA_UINT_TO_PTR(state), 0, NULL)) < 0) { + + if (s->set_state) + s->set_state(s, original_state); + + return ret; + } s->state = state; diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index e62c6c2..95007af 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -224,22 +224,31 @@ pa_source* pa_source_new( static int source_set_state(pa_source *s, pa_source_state_t state) { int ret; pa_bool_t suspend_change; + pa_source_state_t original_state; pa_assert(s); if (s->state == state) return 0; + original_state = s->state; + suspend_change = - (s->state == PA_SOURCE_SUSPENDED && PA_SOURCE_IS_OPENED(state)) || - (PA_SOURCE_IS_OPENED(s->state) && state == PA_SOURCE_SUSPENDED); + (original_state == PA_SOURCE_SUSPENDED && PA_SOURCE_IS_OPENED(state)) || + (PA_SOURCE_IS_OPENED(original_state) && state == PA_SOURCE_SUSPENDED); if (s->set_state) if ((ret = s->set_state(s, state)) < 0) - return -1; + return ret; if (s->asyncmsgq) - pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_SET_STATE, PA_UINT_TO_PTR(state), 0, NULL) == 0); + if ((ret = pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_SET_STATE, PA_UINT_TO_PTR(state), 0, NULL)) < 0) { + + if (s->set_state) + s->set_state(s, original_state); + + return ret; + } s->state = state; -- 2.7.4