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
This commit is contained in:
Wim Taymans 2020-12-18 09:48:26 +01:00
parent 1a690a0cbb
commit d2a5f5c1ae
2 changed files with 11 additions and 17 deletions

View file

@ -2312,27 +2312,24 @@ static void sample_play_ready(void *data, uint32_t index)
send_message(client, reply); 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 pending_sample *ps = data;
struct client *client = ps->client; struct client *client = ps->client;
struct impl *impl = client->impl; 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; ps->done = true;
pw_loop_signal_event(impl->loop, client->cleanup); 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 = { static const struct sample_play_events sample_play_events = {
VERSION_SAMPLE_PLAY_EVENTS, VERSION_SAMPLE_PLAY_EVENTS,
.ready = sample_play_ready, .ready = sample_play_ready,
.error = sample_play_error,
.done = sample_play_done, .done = sample_play_done,
}; };

View file

@ -40,14 +40,11 @@ struct sample_play_events {
void (*ready) (void *data, uint32_t id); void (*ready) (void *data, uint32_t id);
void (*error) (void *data, int err); void (*done) (void *data, int err);
void (*done) (void *data);
}; };
#define sample_play_emit_ready(p,i) spa_hook_list_call(&p->hooks, struct sample_play_events, ready, 0, i) #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,r) spa_hook_list_call(&p->hooks, struct sample_play_events, done, 0, r)
#define sample_play_emit_done(p) spa_hook_list_call(&p->hooks, struct sample_play_events, done, 0)
struct sample_play { struct sample_play {
struct spa_list link; struct spa_list link;
@ -73,7 +70,7 @@ static void sample_play_stream_state_changed(void *data, enum pw_stream_state ol
switch (state) { switch (state) {
case PW_STREAM_STATE_UNCONNECTED: case PW_STREAM_STATE_UNCONNECTED:
case PW_STREAM_STATE_ERROR: case PW_STREAM_STATE_ERROR:
sample_play_emit_error(p, -EIO); sample_play_emit_done(p, -EIO);
break; break;
case PW_STREAM_STATE_PAUSED: case PW_STREAM_STATE_PAUSED:
p->index = pw_stream_get_node_id(p->stream); 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) static void sample_play_stream_drained(void *data)
{ {
struct sample_play *p = 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 = { struct pw_stream_events sample_play_stream_events = {