diff options
author | Wim Taymans <wtaymans@redhat.com> | 2019-08-01 13:46:49 +0200 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2019-08-01 13:46:49 +0200 |
commit | 46b9158bf9b47b5ac674bf70a159f483abf5591b (patch) | |
tree | d40d0f2298134ed5150701b44c0e9d33cbd1c9cf | |
parent | acf931abc5701475f38bb9237c4a05b05249ca9d (diff) |
improve cleanupold
-rw-r--r-- | src/modules/module-client-node/client-node.c | 4 | ||||
-rw-r--r-- | src/modules/module-client-node/remote-node.c | 109 | ||||
-rw-r--r-- | src/pipewire/device.c | 3 | ||||
-rw-r--r-- | src/pipewire/factory.c | 1 | ||||
-rw-r--r-- | src/pipewire/mem.c | 6 | ||||
-rw-r--r-- | src/pipewire/mem.h | 2 | ||||
-rw-r--r-- | src/pipewire/module.c | 1 | ||||
-rw-r--r-- | src/pipewire/proxy.c | 1 | ||||
-rw-r--r-- | src/pipewire/stream.c | 10 |
9 files changed, 85 insertions, 52 deletions
diff --git a/src/modules/module-client-node/client-node.c b/src/modules/module-client-node/client-node.c index b85ed665..2f2f2bc8 100644 --- a/src/modules/module-client-node/client-node.c +++ b/src/modules/module-client-node/client-node.c @@ -350,7 +350,7 @@ static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) mem_size = size; } else { - if ((mm = pw_mempool_find_tag(this->client->pool, tag)) != NULL) + if ((mm = pw_mempool_find_tag(this->client->pool, tag, sizeof(tag))) != NULL) pw_memmap_free(mm); memid = SPA_ID_INVALID; @@ -663,7 +663,7 @@ static int do_port_set_io(struct impl *impl, mem_size = size; } else { - if ((mm = pw_mempool_find_tag(this->client->pool, tag)) != NULL) + if ((mm = pw_mempool_find_tag(this->client->pool, tag, sizeof(tag))) != NULL) pw_memmap_free(mm); memid = SPA_ID_INVALID; diff --git a/src/modules/module-client-node/remote-node.c b/src/modules/module-client-node/remote-node.c index 7c81c527..fc8b9cd7 100644 --- a/src/modules/module-client-node/remote-node.c +++ b/src/modules/module-client-node/remote-node.c @@ -84,10 +84,12 @@ struct node_data { int do_free:1; int have_transport:1; - struct pw_client_node_proxy *node_proxy; - struct spa_hook node_proxy_listener; + struct pw_client_node_proxy *client_node; + struct spa_hook client_node_listener; + struct spa_hook client_node_proxy_listener; + + struct pw_proxy *proxy; struct spa_hook proxy_listener; - struct pw_proxy *proxy; struct spa_io_position *position; @@ -119,6 +121,8 @@ static void clear_link(struct node_data *data, struct link *link) static void clean_transport(struct node_data *data) { struct link *l; + uint32_t tag[1] = { data->remote_id, }; + struct pw_memmap *mm; if (!data->have_transport) return; @@ -127,6 +131,10 @@ static void clean_transport(struct node_data *data) if (l->node_id != SPA_ID_INVALID) clear_link(data, l); } + + while ((mm = pw_mempool_find_tag(data->remote->pool, tag, sizeof(tag))) != NULL) + pw_memmap_free(mm); + pw_array_clear(&data->links); pw_memmap_free(data->activation); @@ -232,11 +240,11 @@ static int client_node_transport(void *object, uint32_t node_id, { struct pw_proxy *proxy = object; struct node_data *data = proxy->user_data; - struct pw_remote *remote = proxy->remote; + struct pw_remote *remote = data->remote; clean_transport(data); - data->activation = pw_mempool_map_id(proxy->remote->pool, mem_id, + data->activation = pw_mempool_map_id(remote->pool, mem_id, PW_MEMMAP_FLAG_READWRITE, offset, size, NULL); if (data->activation == NULL) { pw_log_debug("remote-node %p: can't map activation: %m", proxy); @@ -256,7 +264,7 @@ static int client_node_transport(void *object, uint32_t node_id, data->have_transport = true; if (data->node->active) - pw_client_node_proxy_set_active(data->node_proxy, true); + pw_client_node_proxy_set_active(data->client_node, true); pw_remote_emit_exported(remote, data->proxy->id, node_id); return 0; @@ -306,7 +314,7 @@ static int add_node_update(struct pw_proxy *proxy, uint32_t change_mask) } - res = pw_client_node_proxy_update(data->node_proxy, + res = pw_client_node_proxy_update(data->client_node, change_mask, n_params, (const struct spa_pod **)params, @@ -364,7 +372,7 @@ static int add_port_update(struct pw_proxy *proxy, struct pw_port *port, uint32_ pi.params = port->info.params; } - res = pw_client_node_proxy_port_update(data->node_proxy, + res = pw_client_node_proxy_port_update(data->client_node, port->direction, port->port_id, change_mask, @@ -402,13 +410,13 @@ client_node_set_io(void *object, uint32_t tag[5] = { data->remote_id, id, }; if (memid == SPA_ID_INVALID) { - if ((mm = pw_mempool_find_tag(proxy->remote->pool, tag)) != NULL) + if ((mm = pw_mempool_find_tag(data->remote->pool, tag, sizeof(tag))) != NULL) pw_memmap_free(mm); mm = ptr = NULL; size = 0; } else { - mm = pw_mempool_map_id(proxy->remote->pool, memid, + mm = pw_mempool_map_id(data->remote->pool, memid, PW_MEMMAP_FLAG_READWRITE, offset, size, tag); if (mm == NULL) { pw_log_warn("can't map memory id %u: %m", memid); @@ -581,7 +589,7 @@ client_node_port_use_buffers(void *object, off_t offset; struct pw_memmap *mm; - mm = pw_mempool_map_id(proxy->remote->pool, buffers[i].mem_id, + mm = pw_mempool_map_id(data->remote->pool, buffers[i].mem_id, prot, buffers[i].offset, buffers[i].size, NULL); if (mm == NULL) { res = -errno; @@ -643,7 +651,7 @@ client_node_port_use_buffers(void *object, uint32_t mem_id = SPA_PTR_TO_UINT32(d->data); struct pw_memblock *bm; - bm = pw_mempool_find_id(proxy->remote->pool, mem_id); + bm = pw_mempool_find_id(data->remote->pool, mem_id); if (bm == NULL) { pw_log_error("unknown buffer mem %u", mem_id); res = -ENODEV; @@ -673,7 +681,7 @@ client_node_port_use_buffers(void *object, goto error_exit_cleanup; if (flags & SPA_NODE_BUFFERS_FLAG_ALLOC) { - pw_client_node_proxy_port_buffers(data->node_proxy, + pw_client_node_proxy_port_buffers(data->client_node, direction, port_id, mix_id, n_buffers, bufs); @@ -713,14 +721,14 @@ client_node_port_set_io(void *object, } if (memid == SPA_ID_INVALID) { - if ((mm = pw_mempool_find_tag(proxy->remote->pool, tag)) != NULL) + if ((mm = pw_mempool_find_tag(data->remote->pool, tag, sizeof(tag))) != NULL) pw_memmap_free(mm); mm = ptr = NULL; size = 0; } else { - mm = pw_mempool_map_id(proxy->remote->pool, memid, + mm = pw_mempool_map_id(data->remote->pool, memid, PW_MEMMAP_FLAG_READWRITE, offset, size, tag); if (mm == NULL) { res = -errno; @@ -796,7 +804,7 @@ client_node_set_activation(void *object, size = 0; } else { - mm = pw_mempool_map_id(proxy->remote->pool, memid, + mm = pw_mempool_map_id(data->remote->pool, memid, PW_MEMMAP_FLAG_READWRITE, offset, size, NULL); if (mm == NULL) { res = -errno; @@ -929,11 +937,8 @@ static void node_free(void *data) pw_log_debug("%p: free", d); - if (d->proxy) { - pw_proxy_destroy(d->proxy); - d->proxy = NULL; - } - pw_proxy_destroy((struct pw_proxy*)d->node_proxy); + if (d->client_node) + pw_proxy_destroy((struct pw_proxy*)d->client_node); } static void node_info_changed(void *data, const struct pw_node_info *info) @@ -949,7 +954,7 @@ static void node_info_changed(void *data, const struct pw_node_info *info) change_mask |= PW_CLIENT_NODE_UPDATE_PARAMS; change_mask |= PW_CLIENT_NODE_UPDATE_INFO; } - add_node_update((struct pw_proxy*)d->node_proxy, change_mask); + add_node_update((struct pw_proxy*)d->client_node, change_mask); } static void node_port_info_changed(void *data, struct pw_port *port, @@ -966,14 +971,14 @@ static void node_port_info_changed(void *data, struct pw_port *port, change_mask |= PW_CLIENT_NODE_PORT_UPDATE_PARAMS; change_mask |= PW_CLIENT_NODE_PORT_UPDATE_INFO; } - add_port_update((struct pw_proxy*)d->node_proxy, port, change_mask); + add_port_update((struct pw_proxy*)d->client_node, port, change_mask); } static void node_active_changed(void *data, bool active) { struct node_data *d = data; pw_log_debug("active %d", active); - pw_client_node_proxy_set_active(d->node_proxy, active); + pw_client_node_proxy_set_active(d->client_node, active); } static const struct pw_node_events node_events = { @@ -985,7 +990,7 @@ static const struct pw_node_events node_events = { .active_changed = node_active_changed, }; -static void node_proxy_destroy(void *_data) +static void client_node_proxy_destroy(void *_data) { struct node_data *data = _data; @@ -995,19 +1000,36 @@ static void node_proxy_destroy(void *_data) spa_hook_remove(&data->node_listener); - data->node_proxy = NULL; + data->client_node = NULL; - if (data->proxy) { + if (data->proxy) pw_proxy_destroy(data->proxy); - data->proxy = NULL; - } + if (data->do_free) pw_node_destroy(data->node); } +static const struct pw_proxy_events client_node_proxy_events = { + PW_VERSION_PROXY_EVENTS, + .destroy = client_node_proxy_destroy, +}; + +static void proxy_destroy(void *_data) +{ + struct node_data *data = _data; + + pw_log_debug("%p: destroy", data); + spa_hook_remove(&data->proxy_listener); + data->proxy = NULL; + + if (data->client_node) + pw_proxy_destroy((struct pw_proxy*)data->client_node); +} + + static const struct pw_proxy_events proxy_events = { PW_VERSION_PROXY_EVENTS, - .destroy = node_proxy_destroy, + .destroy = proxy_destroy, }; static int node_ready(void *d, int status) @@ -1051,25 +1073,25 @@ static struct pw_proxy *node_export(struct pw_remote *remote, void *object, bool size_t user_data_size) { struct pw_node *node = object; - struct pw_proxy *proxy; + struct pw_proxy *client_node; struct node_data *data; int i; - proxy = pw_core_proxy_create_object(remote->core_proxy, + client_node = pw_core_proxy_create_object(remote->core_proxy, "client-node", PW_TYPE_INTERFACE_ClientNode, PW_VERSION_CLIENT_NODE, &node->properties->dict, sizeof(struct node_data)); - if (proxy == NULL) + if (client_node == NULL) return NULL; - data = pw_proxy_get_user_data(proxy); + data = pw_proxy_get_user_data(client_node); data->remote = remote; data->node = node; data->do_free = do_free; data->core = pw_node_get_core(node); - data->node_proxy = (struct pw_client_node_proxy *)proxy; + data->client_node = (struct pw_client_node_proxy *)client_node; data->remote_id = SPA_ID_INVALID; node->exported = true; @@ -1083,19 +1105,24 @@ static struct pw_proxy *node_export(struct pw_remote *remote, void *object, bool pw_array_init(&data->links, 64); pw_array_ensure_size(&data->links, sizeof(struct link) * 64); - pw_proxy_add_listener(proxy, &data->proxy_listener, &proxy_events, data); + pw_proxy_add_listener(client_node, + &data->client_node_proxy_listener, + &client_node_proxy_events, data); + spa_node_set_callbacks(node->node, &node_callbacks, data); pw_node_add_listener(node, &data->node_listener, &node_events, data); - pw_client_node_proxy_add_listener(data->node_proxy, - &data->node_proxy_listener, + pw_client_node_proxy_add_listener(data->client_node, + &data->client_node_listener, &client_node_events, - proxy); - do_node_init(proxy); + client_node); + do_node_init(client_node); - data->proxy = (struct pw_proxy*) pw_client_node_proxy_get_node(data->node_proxy, + data->proxy = (struct pw_proxy*) pw_client_node_proxy_get_node(data->client_node, PW_VERSION_NODE_PROXY, user_data_size); + pw_proxy_add_listener(data->proxy, &data->proxy_listener, &proxy_events, data); + return data->proxy; } diff --git a/src/pipewire/device.c b/src/pipewire/device.c index c11e1934..af258e5f 100644 --- a/src/pipewire/device.c +++ b/src/pipewire/device.c @@ -142,7 +142,10 @@ void pw_device_destroy(struct pw_device *device) spa_hook_remove(&device->global_listener); pw_global_destroy(device->global); } + + pw_log_debug(NAME" %p: free", device); pw_device_emit_free(device); + free((char *)device->info.name); pw_properties_free(device->properties); diff --git a/src/pipewire/factory.c b/src/pipewire/factory.c index 7cda0336..a6b8654f 100644 --- a/src/pipewire/factory.c +++ b/src/pipewire/factory.c @@ -82,6 +82,7 @@ void pw_factory_destroy(struct pw_factory *factory) spa_hook_remove(&factory->global_listener); pw_global_destroy(factory->global); } + pw_log_debug("factory %p: free", factory); free((char *)factory->info.name); if (factory->properties) pw_properties_free(factory->properties); diff --git a/src/pipewire/mem.c b/src/pipewire/mem.c index 6d2937dc..d2edbc5e 100644 --- a/src/pipewire/mem.c +++ b/src/pipewire/mem.c @@ -692,15 +692,17 @@ struct pw_memblock * pw_mempool_find_fd(struct pw_mempool *pool, int fd) } SPA_EXPORT -struct pw_memmap * pw_mempool_find_tag(struct pw_mempool *pool, uint32_t tag[5]) +struct pw_memmap * pw_mempool_find_tag(struct pw_mempool *pool, uint32_t tag[5], size_t size) { struct mempool *impl = SPA_CONTAINER_OF(pool, struct mempool, this); struct memblock *b; struct memmap *mm; + pw_log_debug("pool %p: find tag %zd", pool, size); + spa_list_for_each(b, &impl->blocks, link) { spa_list_for_each(mm, &b->maps, link) { - if (memcmp(tag, mm->this.tag, sizeof(mm->this.tag)) == 0) { + if (memcmp(tag, mm->this.tag, size) == 0) { pw_log_debug("pool %p: found %p", pool, mm); return &mm->this; } diff --git a/src/pipewire/mem.h b/src/pipewire/mem.h index a9c22d87..7109d616 100644 --- a/src/pipewire/mem.h +++ b/src/pipewire/mem.h @@ -157,7 +157,7 @@ struct pw_memmap * pw_mempool_import_map(struct pw_mempool *pool, struct pw_mempool *other, void *data, uint32_t size, uint32_t tag[5]); /** find a map with the given tag */ -struct pw_memmap * pw_mempool_find_tag(struct pw_mempool *pool, uint32_t tag[5]); +struct pw_memmap * pw_mempool_find_tag(struct pw_mempool *pool, uint32_t tag[5], size_t size); /** Unmap a region */ int pw_memmap_free(struct pw_memmap *map); diff --git a/src/pipewire/module.c b/src/pipewire/module.c index 1837965b..03b0c1ab 100644 --- a/src/pipewire/module.c +++ b/src/pipewire/module.c @@ -329,6 +329,7 @@ void pw_module_destroy(struct pw_module *module) pw_global_destroy(module->global); } + pw_log_debug("module %p: free", module); free((char *) module->info.name); free((char *) module->info.filename); free((char *) module->info.args); diff --git a/src/pipewire/proxy.c b/src/pipewire/proxy.c index 0d4471b9..36300a70 100644 --- a/src/pipewire/proxy.c +++ b/src/pipewire/proxy.c @@ -173,6 +173,7 @@ void pw_proxy_destroy(struct pw_proxy *proxy) if (remote->core_proxy) pw_core_proxy_destroy(remote->core_proxy, proxy); } + pw_log_debug("proxy %p: free", proxy); free(impl); } diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index ba187780..ffd34388 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -1235,6 +1235,7 @@ void pw_stream_destroy(struct pw_stream *stream) clear_params(stream, PARAM_TYPE_INIT | PARAM_TYPE_OTHER | PARAM_TYPE_FORMAT); + pw_log_debug(NAME" %p: free", stream); free(stream->error); pw_properties_free(stream->properties); @@ -1434,16 +1435,13 @@ int pw_stream_disconnect(struct pw_stream *stream) pw_log_debug(NAME" %p: disconnect", stream); impl->disconnecting = true; - if (stream->proxy) { - stream->proxy = NULL; - spa_hook_remove(&stream->proxy_listener); - stream->node_id = SPA_ID_INVALID; - } + if (stream->proxy) + pw_proxy_destroy(stream->proxy); + if (impl->node) { pw_node_destroy(impl->node); impl->node = NULL; } - stream_set_state(stream, PW_STREAM_STATE_UNCONNECTED, NULL); return 0; } |