aboutsummaryrefslogtreecommitdiff
path: root/src/output
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-08-14 22:22:55 +0200
committerMax Kellermann <max@duempel.org>2012-08-14 22:22:55 +0200
commit51d793bec1f61e7048188ac4f86964486ab79142 (patch)
tree48c2fd2aa1efc14c6d8a8969678ec6ea6250a10c /src/output
parent249dcd967ede5ad20cda92a7c6c85ba303eed87f (diff)
output/pulse: simplify _wait_stream()
One large loop and only one pa_stream_get_state() call.
Diffstat (limited to 'src/output')
-rw-r--r--src/output/pulse_output_plugin.c71
1 files changed, 16 insertions, 55 deletions
diff --git a/src/output/pulse_output_plugin.c b/src/output/pulse_output_plugin.c
index 0dc9be0e..42908fbc 100644
--- a/src/output/pulse_output_plugin.c
+++ b/src/output/pulse_output_plugin.c
@@ -682,35 +682,6 @@ pulse_output_close(struct audio_output *ao)
}
/**
- * Check if the stream is (already) connected, and waits for a signal
- * if not. The mainloop must be locked before calling this function.
- *
- * @return the current stream state
- */
-static pa_stream_state_t
-pulse_output_check_stream(struct pulse_output *po)
-{
- pa_stream_state_t state = pa_stream_get_state(po->stream);
-
- assert(po->mainloop != NULL);
-
- switch (state) {
- case PA_STREAM_READY:
- case PA_STREAM_FAILED:
- case PA_STREAM_TERMINATED:
- case PA_STREAM_UNCONNECTED:
- break;
-
- case PA_STREAM_CREATING:
- pa_threaded_mainloop_wait(po->mainloop);
- state = pa_stream_get_state(po->stream);
- break;
- }
-
- return state;
-}
-
-/**
* Check if the stream is (already) connected, and waits if not. The
* mainloop must be locked before calling this function.
*
@@ -719,35 +690,25 @@ pulse_output_check_stream(struct pulse_output *po)
static bool
pulse_output_wait_stream(struct pulse_output *po, GError **error_r)
{
- pa_stream_state_t state = pa_stream_get_state(po->stream);
-
- switch (state) {
- case PA_STREAM_READY:
- return true;
-
- case PA_STREAM_FAILED:
- case PA_STREAM_TERMINATED:
- case PA_STREAM_UNCONNECTED:
- g_set_error(error_r, pulse_output_quark(), 0,
- "disconnected");
- return false;
-
- case PA_STREAM_CREATING:
- break;
- }
+ while (true) {
+ switch (pa_stream_get_state(po->stream)) {
+ case PA_STREAM_READY:
+ return true;
- do {
- state = pulse_output_check_stream(po);
- } while (state == PA_STREAM_CREATING);
+ case PA_STREAM_FAILED:
+ case PA_STREAM_TERMINATED:
+ case PA_STREAM_UNCONNECTED:
+ g_set_error(error_r, pulse_output_quark(),
+ pa_context_errno(po->context),
+ "failed to connect the stream: %s",
+ pa_strerror(pa_context_errno(po->context)));
+ return false;
- if (state != PA_STREAM_READY) {
- g_set_error(error_r, pulse_output_quark(), 0,
- "failed to connect the stream: %s",
- pa_strerror(pa_context_errno(po->context)));
- return false;
+ case PA_STREAM_CREATING:
+ pa_threaded_mainloop_wait(po->mainloop);
+ break;
+ }
}
-
- return true;
}
/**