summaryrefslogtreecommitdiffstats
path: root/pulse
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2008-09-03 02:57:15 +0200
committerLennart Poettering <lennart@poettering.net>2008-09-03 20:25:37 +0200
commitc5759e34c179061dc02c9a28653a822cc586ec23 (patch)
treefab24c7ca63bd54af7e7c708ffa4e71aedd4ec45 /pulse
parentbc9eb41ea2cbe9a19e5d63ddc9e09ed5e7d1b77a (diff)
A bag of minor clean-ups for pulse.c
Use more error checking where appropriate, optimize a few things.
Diffstat (limited to 'pulse')
-rw-r--r--pulse/pulse.c82
1 files changed, 60 insertions, 22 deletions
diff --git a/pulse/pulse.c b/pulse/pulse.c
index 5babcea..9bd1d10 100644
--- a/pulse/pulse.c
+++ b/pulse/pulse.c
@@ -31,7 +31,9 @@ int pulse_check_connection(snd_pulse_t * p)
{
pa_context_state_t state;
- assert(p && p->context && p->mainloop);
+ assert(p);
+ assert(p->context);
+ assert(p->mainloop);
state = pa_context_get_state(p->context);
@@ -73,10 +75,23 @@ void pulse_context_success_cb(pa_context * c, int success, void *userdata)
int pulse_wait_operation(snd_pulse_t * p, pa_operation * o)
{
- assert(p && o && (p->state == PULSE_STATE_READY) && p->mainloop);
+ assert(p);
+ assert(o);
+ assert(p->state == PULSE_STATE_READY);
+ assert(p->mainloop);
+
+ for (;;) {
+ int err;
+
+ err = pulse_check_connection(p);
+ if (err < 0)
+ return err;
+
+ if (pa_operation_get_state(o) != PA_OPERATION_RUNNING)
+ break;
- while (pa_operation_get_state(o) == PA_OPERATION_RUNNING)
pa_threaded_mainloop_wait(p->mainloop);
+ }
return 0;
}
@@ -86,18 +101,27 @@ int pulse_wait_stream_state(snd_pulse_t * p, pa_stream * stream,
{
pa_stream_state_t state;
- assert(p && stream && (p->state == PULSE_STATE_READY)
- && p->mainloop);
+ assert(p);
+ assert(stream);
+ assert(p->state == PULSE_STATE_READY);
+ assert(p->mainloop);
- while (1) {
- state = pa_stream_get_state(stream);
+ for (;;) {
+ int err;
- if (state == PA_STREAM_FAILED)
- return -EIO;
+ err = pulse_check_connection(p);
+ if (err < 0)
+ return err;
+
+ state = pa_stream_get_state(stream);
if (state == target)
break;
+ if (state == PA_STREAM_FAILED ||
+ state == PA_STREAM_TERMINATED)
+ return -EIO;
+
pa_threaded_mainloop_wait(p->mainloop);
}
@@ -131,7 +155,9 @@ snd_pulse_t *pulse_new(void)
char proc[PATH_MAX], buf[PATH_MAX + 20];
p = calloc(1, sizeof(snd_pulse_t));
- assert(p);
+
+ if (!p)
+ return NULL;
p->state = PULSE_STATE_INIT;
@@ -147,15 +173,11 @@ snd_pulse_t *pulse_new(void)
fcntl(fd[1], F_SETFL, O_NONBLOCK);
p->mainloop = pa_threaded_mainloop_new();
- assert(p->mainloop);
+ if (!p->mainloop)
+ goto fail;
- if (pa_threaded_mainloop_start(p->mainloop) < 0) {
- pa_threaded_mainloop_free(p->mainloop);
- close(fd[0]);
- close(fd[1]);
- free(p);
- return NULL;
- }
+ if (pa_threaded_mainloop_start(p->mainloop) < 0)
+ goto fail;
if (pa_get_binary_name(proc, sizeof(proc)))
snprintf(buf, sizeof(buf), "ALSA plug-in [%s]",
@@ -168,7 +190,23 @@ snd_pulse_t *pulse_new(void)
pa_context_new(pa_threaded_mainloop_get_api(p->mainloop), buf);
assert(p->context);
+ pa_context_set_state_callback(p->context, context_state_cb, p);
+
return p;
+
+fail:
+ if (p->mainloop)
+ pa_threaded_mainloop_free(p->mainloop);
+
+ if (p->main_fd >= 0)
+ close(p->main_fd);
+
+ if (p->thread_fd >= 0)
+ close(p->thread_fd);
+
+ free(p);
+
+ return NULL;
}
void pulse_free(snd_pulse_t * p)
@@ -189,8 +227,10 @@ int pulse_connect(snd_pulse_t * p, const char *server)
{
int err;
- assert(p && p->context && p->mainloop
- && (p->state == PULSE_STATE_INIT));
+ assert(p);
+ assert(p->context);
+ assert(p->mainloop);
+ assert(p->state == PULSE_STATE_INIT);
pa_threaded_mainloop_lock(p->mainloop);
@@ -198,8 +238,6 @@ int pulse_connect(snd_pulse_t * p, const char *server)
if (err < 0)
goto error;
- pa_context_set_state_callback(p->context, context_state_cb, p);
-
pa_threaded_mainloop_wait(p->mainloop);
if (pa_context_get_state(p->context) != PA_CONTEXT_READY)