mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-05 13:30:02 -05:00
pipewire: improve memory cleanup
Add method to unload a spa interface. Various other memory cleanups
This commit is contained in:
parent
0dc036ac84
commit
d165b3b842
8 changed files with 362 additions and 80 deletions
|
|
@ -1084,6 +1084,10 @@ static int node_clear(struct node *this)
|
|||
{
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < this->n_params; i++)
|
||||
free(this->params[i]);
|
||||
free(this->params);
|
||||
|
||||
for (i = 0; i < MAX_INPUTS; i++) {
|
||||
if (this->in_ports[i].valid)
|
||||
clear_port(this, &this->in_ports[i], SPA_DIRECTION_INPUT, i);
|
||||
|
|
@ -1186,6 +1190,8 @@ static void node_free(void *data)
|
|||
if (impl->io_areas)
|
||||
pw_memblock_free(impl->io_areas);
|
||||
|
||||
pw_map_clear(&impl->io_map);
|
||||
|
||||
if (impl->fds[0] != -1)
|
||||
close(impl->fds[0]);
|
||||
if (impl->fds[1] != -1)
|
||||
|
|
|
|||
|
|
@ -442,14 +442,20 @@ static int negotiate_buffers(struct impl *impl)
|
|||
spa_buffer_alloc_fill_info(&info, 0, NULL, blocks, datas, aligns);
|
||||
info.skel_size = SPA_ROUND_UP_N(info.skel_size, 16);
|
||||
|
||||
if (impl->buffers)
|
||||
free(impl->buffers);
|
||||
impl->buffers = calloc(blocks, sizeof(struct spa_buffer *) + info.skel_size);
|
||||
if (impl->buffers == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
skel = SPA_MEMBER(impl->buffers, sizeof(struct spa_buffer *) * blocks, void);
|
||||
data_size = info.meta_size + info.chunk_size + info.data_size;
|
||||
|
||||
if (impl->mem) {
|
||||
pw_memblock_free(impl->mem);
|
||||
impl->mem = NULL;
|
||||
}
|
||||
|
||||
if ((res = pw_memblock_alloc(PW_MEMBLOCK_FLAG_WITH_FD |
|
||||
PW_MEMBLOCK_FLAG_MAP_READWRITE |
|
||||
PW_MEMBLOCK_FLAG_SEAL, blocks * data_size,
|
||||
|
|
@ -800,18 +806,32 @@ static void client_node_initialized(void *data)
|
|||
pw_node_set_active(impl->this.node, true);
|
||||
}
|
||||
|
||||
static void cleanup(struct impl *impl)
|
||||
{
|
||||
if (impl->use_converter) {
|
||||
if (impl->adapter)
|
||||
pw_unload_spa_interface(impl->adapter);
|
||||
}
|
||||
|
||||
if (impl->buffers)
|
||||
free(impl->buffers);
|
||||
if (impl->mem) {
|
||||
pw_memblock_free(impl->mem);
|
||||
impl->mem = NULL;
|
||||
}
|
||||
free(impl);
|
||||
}
|
||||
|
||||
static void client_node_destroy(void *data)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
|
||||
pw_log_debug("client-stream %p: destroy", &impl->this);
|
||||
|
||||
spa_hook_remove(&impl->client_node_listener);
|
||||
|
||||
spa_hook_remove(&impl->node_listener);
|
||||
pw_node_destroy(impl->this.node);
|
||||
|
||||
free(impl);
|
||||
cleanup(impl);
|
||||
}
|
||||
|
||||
static void client_node_async_complete(void *data, uint32_t seq, int res)
|
||||
|
|
@ -847,8 +867,7 @@ static void node_destroy(void *data)
|
|||
|
||||
spa_hook_remove(&impl->client_node_listener);
|
||||
pw_client_node_destroy(impl->client_node);
|
||||
|
||||
free(impl);
|
||||
cleanup(impl);
|
||||
}
|
||||
|
||||
static const struct pw_node_events node_events = {
|
||||
|
|
|
|||
|
|
@ -710,8 +710,10 @@ static void destroy_server(struct pw_protocol_server *server)
|
|||
spa_list_for_each_safe(client, tmp, &server->client_list, protocol_link)
|
||||
pw_client_destroy(client);
|
||||
|
||||
if (s->source)
|
||||
if (s->source) {
|
||||
spa_hook_remove(&s->hook);
|
||||
pw_loop_destroy_source(s->loop, s->source);
|
||||
}
|
||||
if (s->addr.sun_path[0])
|
||||
unlink(s->addr.sun_path);
|
||||
if (s->lock_addr[0])
|
||||
|
|
|
|||
|
|
@ -377,12 +377,36 @@ int pw_rtkit_make_high_priority(struct pw_rtkit_bus *connection, pid_t thread, i
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int do_remove_source(struct spa_loop *loop,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
const void *data,
|
||||
size_t size,
|
||||
void *user_data)
|
||||
{
|
||||
struct spa_source *source = user_data;
|
||||
spa_loop_remove_source(loop, source);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void module_destroy(void *data)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
|
||||
spa_hook_remove(&impl->module_listener);
|
||||
|
||||
if (impl->source.fd != -1) {
|
||||
spa_loop_invoke(impl->loop,
|
||||
do_remove_source,
|
||||
SPA_ID_INVALID,
|
||||
NULL,
|
||||
0,
|
||||
true,
|
||||
&impl->source);
|
||||
close(impl->source.fd);
|
||||
impl->source.fd = -1;
|
||||
}
|
||||
|
||||
if (impl->properties)
|
||||
pw_properties_free(impl->properties);
|
||||
|
||||
|
|
@ -448,6 +472,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
|||
struct spa_loop *loop;
|
||||
const struct spa_support *support;
|
||||
uint32_t n_support;
|
||||
int res;
|
||||
|
||||
support = pw_core_get_support(core, &n_support);
|
||||
|
||||
|
|
@ -471,11 +496,21 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
|||
impl->source.data = impl;
|
||||
impl->source.fd = eventfd(1, EFD_CLOEXEC | EFD_NONBLOCK);
|
||||
impl->source.mask = SPA_IO_IN;
|
||||
if (impl->source.fd == -1) {
|
||||
res = -errno;
|
||||
goto error;
|
||||
}
|
||||
|
||||
spa_loop_add_source(impl->loop, &impl->source);
|
||||
|
||||
pw_module_add_listener(module, &impl->module_listener, &module_events, impl);
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
free(impl);
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
int pipewire__module_init(struct pw_module *module, const char *args)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue