From d2a5f5c1ae5a3ab19f36463dfc9e04656de9a7f0 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 18 Dec 2020 09:48:26 +0100 Subject: [PATCH] pulse-server: also cleanup sample when error Remove the separate error event and merge with the done event with error code. This then also marks the sample as done when in error so that it gets cleaned up properly. Fixes #486 --- .../module-protocol-pulse/pulse-server.c | 17 +++++++---------- src/modules/module-protocol-pulse/sample.c | 11 ++++------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/modules/module-protocol-pulse/pulse-server.c b/src/modules/module-protocol-pulse/pulse-server.c index dee6031c3..cb959a1bb 100644 --- a/src/modules/module-protocol-pulse/pulse-server.c +++ b/src/modules/module-protocol-pulse/pulse-server.c @@ -2312,27 +2312,24 @@ static void sample_play_ready(void *data, uint32_t index) send_message(client, reply); } -static void sample_play_done(void *data) +static void sample_play_done(void *data, int res) { struct pending_sample *ps = data; struct client *client = ps->client; struct impl *impl = client->impl; - pw_log_info(NAME" %p: sample done tag:%u", client, ps->tag); + + if (res < 0) + reply_error(client, COMMAND_PLAY_SAMPLE, ps->tag, res); + else + pw_log_info(NAME" %p: PLAY_SAMPLE done tag:%u", client, ps->tag); + ps->done = true; pw_loop_signal_event(impl->loop, client->cleanup); } -static void sample_play_error(void *data, int err) -{ - struct pending_sample *ps = data; - struct client *client = ps->client; - reply_error(client, COMMAND_PLAY_SAMPLE, ps->tag, err); -} - static const struct sample_play_events sample_play_events = { VERSION_SAMPLE_PLAY_EVENTS, .ready = sample_play_ready, - .error = sample_play_error, .done = sample_play_done, }; diff --git a/src/modules/module-protocol-pulse/sample.c b/src/modules/module-protocol-pulse/sample.c index f620dcd15..ab213840a 100644 --- a/src/modules/module-protocol-pulse/sample.c +++ b/src/modules/module-protocol-pulse/sample.c @@ -40,14 +40,11 @@ struct sample_play_events { void (*ready) (void *data, uint32_t id); - void (*error) (void *data, int err); - - void (*done) (void *data); + void (*done) (void *data, int err); }; #define sample_play_emit_ready(p,i) spa_hook_list_call(&p->hooks, struct sample_play_events, ready, 0, i) -#define sample_play_emit_error(p,e) spa_hook_list_call(&p->hooks, struct sample_play_events, error, 0, e) -#define sample_play_emit_done(p) spa_hook_list_call(&p->hooks, struct sample_play_events, done, 0) +#define sample_play_emit_done(p,r) spa_hook_list_call(&p->hooks, struct sample_play_events, done, 0, r) struct sample_play { struct spa_list link; @@ -73,7 +70,7 @@ static void sample_play_stream_state_changed(void *data, enum pw_stream_state ol switch (state) { case PW_STREAM_STATE_UNCONNECTED: case PW_STREAM_STATE_ERROR: - sample_play_emit_error(p, -EIO); + sample_play_emit_done(p, -EIO); break; case PW_STREAM_STATE_PAUSED: p->index = pw_stream_get_node_id(p->stream); @@ -136,7 +133,7 @@ static void sample_play_stream_process(void *data) static void sample_play_stream_drained(void *data) { struct sample_play *p = data; - sample_play_emit_done(p); + sample_play_emit_done(p, 0); } struct pw_stream_events sample_play_stream_events = {