diff --git a/src/modules/module-protocol-pulse/client.c b/src/modules/module-protocol-pulse/client.c index 0f7f57f92..88e76e1e3 100644 --- a/src/modules/module-protocol-pulse/client.c +++ b/src/modules/module-protocol-pulse/client.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -48,6 +49,29 @@ #include "server.h" #include "stream.h" +struct client *client_new(struct server *server) +{ + struct client *client = calloc(1, sizeof(*client)); + if (client == NULL) + return NULL; + + client->ref = 1; + client->server = server; + client->impl = server->impl; + client->connect_tag = SPA_ID_INVALID; + + pw_map_init(&client->streams, 16, 16); + spa_list_init(&client->out_messages); + spa_list_init(&client->operations); + spa_list_init(&client->pending_samples); + spa_list_init(&client->pending_streams); + + spa_list_append(&server->clients, &client->link); + server->n_clients++; + + return client; +} + static int client_free_stream(void *item, void *data) { struct stream *s = item; diff --git a/src/modules/module-protocol-pulse/client.h b/src/modules/module-protocol-pulse/client.h index 1b923d281..ef16747d1 100644 --- a/src/modules/module-protocol-pulse/client.h +++ b/src/modules/module-protocol-pulse/client.h @@ -102,6 +102,7 @@ struct client { struct pw_manager_object *prev_default_source; }; +struct client *client_new(struct server *server); bool client_detach(struct client *client); void client_disconnect(struct client *client); void client_free(struct client *client); diff --git a/src/modules/module-protocol-pulse/server.c b/src/modules/module-protocol-pulse/server.c index 6417d1f82..6232177dc 100644 --- a/src/modules/module-protocol-pulse/server.c +++ b/src/modules/module-protocol-pulse/server.c @@ -379,22 +379,10 @@ on_connect(void *data, int fd, uint32_t mask) goto error; } - client = calloc(1, sizeof(*client)); + client = client_new(server); if (client == NULL) goto error; - client->impl = impl; - client->ref = 1; - client->connect_tag = SPA_ID_INVALID; - client->server = server; - spa_list_append(&server->clients, &client->link); - server->n_clients++; - pw_map_init(&client->streams, 16, 16); - spa_list_init(&client->out_messages); - spa_list_init(&client->operations); - spa_list_init(&client->pending_samples); - spa_list_init(&client->pending_streams); - pw_log_debug("server %p: new client %p fd:%d", server, client, client_fd); client->source = pw_loop_add_io(impl->loop,