diff --git a/src/daemon/daemon-config.c b/src/daemon/daemon-config.c index 6590ad55e..66306f715 100644 --- a/src/daemon/daemon-config.c +++ b/src/daemon/daemon-config.c @@ -58,7 +58,7 @@ parse_line(struct pw_daemon_config *config, free(local_err); ret = false; } else { - spa_list_insert(config->commands.prev, &command->link); + spa_list_append(&config->commands, &command->link); } return ret; @@ -194,9 +194,8 @@ bool pw_daemon_config_run_commands(struct pw_daemon_config *config, struct pw_co } } - spa_list_for_each_safe(command, tmp, &config->commands, link) { + spa_list_for_each_safe(command, tmp, &config->commands, link) pw_command_free(command); - } return ret; } diff --git a/src/pipewire/client.c b/src/pipewire/client.c index 20ab8621c..c94f2f542 100644 --- a/src/pipewire/client.c +++ b/src/pipewire/client.c @@ -181,7 +181,8 @@ void *pw_client_get_user_data(struct pw_client *client) static void destroy_resource(void *object, void *data) { - pw_resource_destroy(object); + if (object) + pw_resource_destroy(object); } /** Destroy a client object diff --git a/src/pipewire/node.c b/src/pipewire/node.c index 7965ceb29..8987c4f64 100644 --- a/src/pipewire/node.c +++ b/src/pipewire/node.c @@ -153,7 +153,7 @@ static void update_port_map(struct pw_node *node, enum pw_direction direction, port = pw_map_lookup(portmap, o); if (n >= ns || o < ids[n]) { - pw_log_debug("node %p: %s port removed %d", node, + pw_log_debug("node %p: %s port %d removed", node, pw_direction_as_string(direction), o); if (port != NULL) @@ -161,8 +161,8 @@ static void update_port_map(struct pw_node *node, enum pw_direction direction, o++; } - else if (o >= os || (n < ns && o > ids[n])) { - pw_log_debug("node %p: %s port added %d", node, + else if (o >= os || o > ids[n]) { + pw_log_debug("node %p: %s port %d added", node, pw_direction_as_string(direction), ids[n]); if (port == NULL) @@ -172,8 +172,8 @@ static void update_port_map(struct pw_node *node, enum pw_direction direction, n++; } else { - pw_log_debug("node %p: %s port unchanged %d", node, - pw_direction_as_string(direction), ids[n]); + pw_log_debug("node %p: %s port %d unchanged", node, + pw_direction_as_string(direction), o); n++; o++; } @@ -719,7 +719,6 @@ struct pw_port *pw_node_get_free_port(struct pw_node *node, enum pw_direction di port = pw_port_new(direction, port_id, NULL, 0); if (port == NULL) goto no_mem; - pw_port_add(port, node); } else { port = mixport; diff --git a/src/pipewire/port.c b/src/pipewire/port.c index 4591b041f..ddf8beb12 100644 --- a/src/pipewire/port.c +++ b/src/pipewire/port.c @@ -155,7 +155,7 @@ struct pw_port *pw_port_new(enum pw_direction direction, return NULL; this = &impl->this; - pw_log_debug("port %p: new", this); + pw_log_debug("port %p: new %s %d", this, pw_direction_as_string(direction), port_id); if (properties == NULL) properties = pw_properties_new(NULL, NULL); diff --git a/src/pipewire/port.h b/src/pipewire/port.h index 64f942b39..14f730798 100644 --- a/src/pipewire/port.h +++ b/src/pipewire/port.h @@ -81,14 +81,6 @@ struct pw_port_events { void (*properties_changed) (void *data, const struct pw_properties *properties); }; -/** Create a new port \memberof pw_port - * \return a newly allocated port */ -struct pw_port * -pw_port_new(enum pw_direction direction, - uint32_t port_id, - struct pw_properties *properties, - size_t user_data_size); - /** Get the port direction */ enum pw_direction pw_port_get_direction(struct pw_port *port); @@ -110,9 +102,6 @@ void pw_port_add_listener(struct pw_port *port, const struct pw_port_events *events, void *data); -/** Get the user data of a port, the size of the memory was given \ref in pw_port_new */ -void * pw_port_get_user_data(struct pw_port *port); - #ifdef __cplusplus } #endif diff --git a/src/pipewire/private.h b/src/pipewire/private.h index c6cbe5d7b..1efbcf2ed 100644 --- a/src/pipewire/private.h +++ b/src/pipewire/private.h @@ -372,6 +372,17 @@ struct pw_node_factory { void *user_data; }; +/** Create a new port \memberof pw_port + * \return a newly allocated port */ +struct pw_port * +pw_port_new(enum pw_direction direction, + uint32_t port_id, + struct pw_properties *properties, + size_t user_data_size); + +/** Get the user data of a port, the size of the memory was given \ref in pw_port_new */ +void * pw_port_get_user_data(struct pw_port *port); + /** Add a port to a node \memberof pw_port */ bool pw_port_add(struct pw_port *port, struct pw_node *node); diff --git a/src/tools/pipewire-monitor.c b/src/tools/pipewire-monitor.c index c46497e8d..62019e1fa 100644 --- a/src/tools/pipewire-monitor.c +++ b/src/tools/pipewire-monitor.c @@ -18,6 +18,7 @@ */ #include +#include #include @@ -26,8 +27,7 @@ #include struct data { - bool running; - struct pw_loop *loop; + struct pw_main_loop *loop; struct pw_core *core; struct pw_remote *remote; @@ -355,7 +355,7 @@ static void on_state_changed(void *_data, enum pw_remote_state old, switch (state) { case PW_REMOTE_STATE_ERROR: printf("remote error: %s\n", error); - data->running = false; + pw_main_loop_quit(data->loop); break; case PW_REMOTE_STATE_CONNECTED: @@ -382,28 +382,35 @@ static const struct pw_remote_events remote_events = { .state_changed = on_state_changed, }; +static void do_quit(void *data, int signal_number) +{ + struct data *d = data; + pw_main_loop_quit(d->loop); +} + int main(int argc, char *argv[]) { struct data data = { 0 }; + struct pw_loop *l; pw_init(&argc, &argv); - data.loop = pw_loop_new(NULL); - data.running = true; - data.core = pw_core_new(data.loop, NULL); + data.loop = pw_main_loop_new(NULL); + l = pw_main_loop_get_loop(data.loop); + pw_loop_add_signal(l, SIGINT, do_quit, &data); + pw_loop_add_signal(l, SIGTERM, do_quit, &data); + + data.core = pw_core_new(l, NULL); data.remote = pw_remote_new(data.core, NULL); pw_remote_add_listener(data.remote, &data.remote_listener, &remote_events, &data); pw_remote_connect(data.remote); - pw_loop_enter(data.loop); - while (data.running) { - pw_loop_iterate(data.loop, -1); - } - pw_loop_leave(data.loop); + pw_main_loop_run(data.loop); pw_remote_destroy(data.remote); - pw_loop_destroy(data.loop); + pw_core_destroy(data.core); + pw_main_loop_destroy(data.loop); return 0; }