aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-08-14 17:56:00 -0400
committerDave Reisner <dreisner@archlinux.org>2012-08-14 18:09:29 -0400
commit95452a7f21153e12a598a477b1af3feaa0605710 (patch)
tree697d2ab1b64d478b020206ef3399da460793e92c
parent7911dbe2226e3f177fb92d4028844cafda847655 (diff)
downloadmirror-ponymix-95452a7f21153e12a598a477b1af3feaa0605710.tar.gz
mirror-ponymix-95452a7f21153e12a598a477b1af3feaa0605710.tar.bz2
mirror-ponymix-95452a7f21153e12a598a477b1af3feaa0605710.zip
remove connectstate from pulseaudio_t
this isn't needed outside of the conneciton logic, so there's no point in making room for it on the heap for the whole process.
-rw-r--r--ponymix.c45
1 files changed, 17 insertions, 28 deletions
diff --git a/ponymix.c b/ponymix.c
index 8445f97..fa7fb80 100644
--- a/ponymix.c
+++ b/ponymix.c
@@ -127,7 +127,6 @@ struct io_t {
struct pulseaudio_t {
pa_context *cxt;
pa_mainloop *mainloop;
- enum connectstate state;
int success;
struct io_t *head;
@@ -292,22 +291,17 @@ static void source_info_cb(pa_context UNUSED *c, const pa_server_info *i, void *
*source_name = i->default_source_name;
}
-static void state_cb(pa_context UNUSED *c, void *raw)
+static void state_cb(pa_context *cxt, void *raw)
{
- struct pulseaudio_t *pulse = raw;
+ enum connectstate *state = raw;
- switch (pa_context_get_state(pulse->cxt)) {
+ switch (pa_context_get_state(cxt)) {
case PA_CONTEXT_READY:
- pulse->state = STATE_CONNECTED;
+ *state = STATE_CONNECTED;
break;
case PA_CONTEXT_FAILED:
- pulse->state = STATE_ERROR;
- break;
- case PA_CONTEXT_UNCONNECTED:
- case PA_CONTEXT_AUTHORIZING:
- case PA_CONTEXT_SETTING_NAME:
- case PA_CONTEXT_CONNECTING:
- case PA_CONTEXT_TERMINATED:
+ *state = STATE_ERROR;
+ default:
break;
}
}
@@ -590,33 +584,28 @@ static int set_default(struct pulseaudio_t *pulse, struct io_t *dev)
return !pulse->success;
}
-static int pulse_connect(struct pulseaudio_t *pulse)
+static int pulse_init(struct pulseaudio_t *pulse)
{
+ enum connectstate state = STATE_CONNECTING;
+
+ pulse->mainloop = pa_mainloop_new();
+ pulse->cxt = pa_context_new(pa_mainloop_get_api(pulse->mainloop), "bestpony");
+ pulse->head = NULL;
+
+ pa_context_set_state_callback(pulse->cxt, state_cb, &state);
pa_context_connect(pulse->cxt, NULL, PA_CONTEXT_NOFLAGS, NULL);
- while (pulse->state == STATE_CONNECTING)
+ while (state == STATE_CONNECTING)
pa_mainloop_iterate(pulse->mainloop, 1, NULL);
- if (pulse->state == STATE_ERROR) {
- int r = pa_context_errno(pulse->cxt);
+ if (state == STATE_ERROR) {
fprintf(stderr, "failed to connect to pulse daemon: %s\n",
- pa_strerror(r));
+ pa_strerror(pa_context_errno(pulse->cxt)));
return 1;
}
return 0;
}
-static int pulse_init(struct pulseaudio_t *pulse)
-{
- pulse->mainloop = pa_mainloop_new();
- pulse->cxt = pa_context_new(pa_mainloop_get_api(pulse->mainloop), "bestpony");
- pulse->state = STATE_CONNECTING;
- pulse->head = NULL;
-
- pa_context_set_state_callback(pulse->cxt, state_cb, pulse);
- return pulse_connect(pulse);
-}
-
static void pulse_deinit(struct pulseaudio_t *pulse)
{
struct io_t *node = pulse->head;