pulse-server: send messges when killed and disconnected

This commit is contained in:
Wim Taymans 2020-10-08 17:49:34 +02:00
parent fde36ac6c2
commit d44fdabea1

View file

@ -83,6 +83,8 @@ struct client {
struct pw_map streams; struct pw_map streams;
struct spa_list free_messages; struct spa_list free_messages;
struct spa_list out_messages; struct spa_list out_messages;
unsigned int disconnecting:1;
}; };
struct device { struct device {
@ -335,6 +337,47 @@ static int send_overflow(struct stream *stream)
return send_message(client, reply); return send_message(client, reply);
} }
static int send_stream_killed(struct stream *stream)
{
struct client *client = stream->client;
struct message *reply;
uint32_t command;
command = stream->direction == PW_DIRECTION_OUTPUT ?
COMMAND_PLAYBACK_STREAM_KILLED :
COMMAND_RECORD_STREAM_KILLED;
pw_log_warn(NAME" %p: %s channel:%u", client,
commands[command].name, stream->channel);
if (client->version < 23)
return 0;
reply = message_alloc(client, -1, 0);
message_put(reply,
TAG_U32, command,
TAG_U32, -1,
TAG_U32, stream->channel,
TAG_INVALID);
return send_message(client, reply);
}
static int send_stream_started(struct stream *stream)
{
struct client *client = stream->client;
struct message *reply;
pw_log_info(NAME" %p: STARTED channel:%u", client, stream->channel);
reply = message_alloc(client, -1, 0);
message_put(reply,
TAG_U32, COMMAND_STARTED,
TAG_U32, -1,
TAG_U32, stream->channel,
TAG_INVALID);
return send_message(client, reply);
}
static int do_command_auth(struct client *client, uint32_t command, uint32_t tag, struct message *m) static int do_command_auth(struct client *client, uint32_t command, uint32_t tag, struct message *m)
{ {
struct impl *impl = client->impl; struct impl *impl = client->impl;
@ -656,13 +699,16 @@ static void stream_state_changed(void *data, enum pw_stream_state old,
reply_error(client, -1, ERR_INTERNAL); reply_error(client, -1, ERR_INTERNAL);
break; break;
case PW_STREAM_STATE_UNCONNECTED: case PW_STREAM_STATE_UNCONNECTED:
reply_error(client, -1, ERR_CONNECTIONTERMINATED); if (!client->disconnecting)
send_stream_killed(stream);
break; break;
case PW_STREAM_STATE_CONNECTING: case PW_STREAM_STATE_CONNECTING:
break; break;
case PW_STREAM_STATE_PAUSED: case PW_STREAM_STATE_PAUSED:
break; break;
case PW_STREAM_STATE_STREAMING: case PW_STREAM_STATE_STREAMING:
stream->playing_for = 0;
send_stream_started(stream);
break; break;
} }
} }
@ -2316,8 +2362,10 @@ static void client_free(struct client *client)
message_free(client, msg, true); message_free(client, msg, true);
spa_list_consume(msg, &client->out_messages, link) spa_list_consume(msg, &client->out_messages, link)
message_free(client, msg, true); message_free(client, msg, true);
if (client->core) if (client->core) {
client->disconnecting = true;
pw_core_disconnect(client->core); pw_core_disconnect(client->core);
}
if (client->props) if (client->props)
pw_properties_free(client->props); pw_properties_free(client->props);
if (client->source) if (client->source)