mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
audio-dsp: improve cleanup
This commit is contained in:
parent
8fee15457e
commit
f3dec52fd2
1 changed files with 47 additions and 31 deletions
|
|
@ -33,6 +33,7 @@
|
||||||
#include "pipewire/interfaces.h"
|
#include "pipewire/interfaces.h"
|
||||||
#include "pipewire/log.h"
|
#include "pipewire/log.h"
|
||||||
#include "pipewire/module.h"
|
#include "pipewire/module.h"
|
||||||
|
#include "pipewire/private.h"
|
||||||
|
|
||||||
#include "module-media-session/audio-dsp.h"
|
#include "module-media-session/audio-dsp.h"
|
||||||
|
|
||||||
|
|
@ -46,32 +47,34 @@ struct factory_data {
|
||||||
struct pw_factory *this;
|
struct pw_factory *this;
|
||||||
struct pw_properties *properties;
|
struct pw_properties *properties;
|
||||||
|
|
||||||
|
struct spa_list node_list;
|
||||||
|
|
||||||
struct pw_module *module;
|
struct pw_module *module;
|
||||||
struct spa_hook module_listener;
|
struct spa_hook module_listener;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct resource_data {
|
struct node_data {
|
||||||
struct factory_data *data;
|
struct factory_data *data;
|
||||||
|
struct spa_list link;
|
||||||
struct pw_resource *resource;
|
|
||||||
struct spa_hook resource_listener;
|
|
||||||
|
|
||||||
struct pw_node *dsp;
|
struct pw_node *dsp;
|
||||||
|
struct spa_hook resource_listener;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void resource_destroy(void *data)
|
static void resource_destroy(void *data)
|
||||||
{
|
{
|
||||||
struct resource_data *d = data;
|
struct node_data *nd = data;
|
||||||
if (d->dsp)
|
spa_list_remove(&nd->link);
|
||||||
pw_node_destroy(d->dsp);
|
spa_hook_remove(&nd->resource_listener);
|
||||||
|
if (nd->dsp)
|
||||||
|
pw_node_destroy(nd->dsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct pw_resource_events resource_events =
|
static const struct pw_resource_events resource_events = {
|
||||||
{
|
|
||||||
PW_VERSION_RESOURCE_EVENTS,
|
PW_VERSION_RESOURCE_EVENTS,
|
||||||
.destroy = resource_destroy
|
.destroy = resource_destroy
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static void *create_object(void *_data,
|
static void *create_object(void *_data,
|
||||||
struct pw_resource *resource,
|
struct pw_resource *resource,
|
||||||
uint32_t type,
|
uint32_t type,
|
||||||
|
|
@ -80,30 +83,19 @@ static void *create_object(void *_data,
|
||||||
uint32_t new_id)
|
uint32_t new_id)
|
||||||
{
|
{
|
||||||
struct factory_data *d = _data;
|
struct factory_data *d = _data;
|
||||||
struct resource_data *rd;
|
|
||||||
struct pw_resource *node_resource;
|
|
||||||
struct pw_client *client;
|
struct pw_client *client;
|
||||||
int channels, rate, maxbuffer;
|
struct pw_node *dsp;
|
||||||
|
int res, channels, rate, maxbuffer;
|
||||||
const char *str;
|
const char *str;
|
||||||
enum pw_direction direction;
|
enum pw_direction direction;
|
||||||
|
struct node_data *nd;
|
||||||
|
struct pw_resource *bound_resource;
|
||||||
|
|
||||||
if (resource == NULL)
|
if (resource == NULL)
|
||||||
goto no_resource;
|
goto no_resource;
|
||||||
|
|
||||||
client = pw_resource_get_client(resource);
|
client = pw_resource_get_client(resource);
|
||||||
|
|
||||||
node_resource = pw_resource_new(client,
|
|
||||||
new_id, PW_PERM_RWX, type, version,
|
|
||||||
sizeof(struct resource_data));
|
|
||||||
if (node_resource == NULL)
|
|
||||||
goto no_mem;
|
|
||||||
|
|
||||||
rd = pw_resource_get_user_data(node_resource);
|
|
||||||
rd->data = d;
|
|
||||||
rd->resource = node_resource;
|
|
||||||
|
|
||||||
pw_resource_add_listener(node_resource, &rd->resource_listener, &resource_events, rd);
|
|
||||||
|
|
||||||
if ((str = pw_properties_get(properties, "audio-dsp.direction")) == NULL)
|
if ((str = pw_properties_get(properties, "audio-dsp.direction")) == NULL)
|
||||||
goto no_props;
|
goto no_props;
|
||||||
|
|
||||||
|
|
@ -124,18 +116,34 @@ static void *create_object(void *_data,
|
||||||
|
|
||||||
maxbuffer = pw_properties_parse_int(str);
|
maxbuffer = pw_properties_parse_int(str);
|
||||||
|
|
||||||
rd->dsp = pw_audio_dsp_new(pw_module_get_core(d->module),
|
dsp = pw_audio_dsp_new(pw_module_get_core(d->module),
|
||||||
properties,
|
properties,
|
||||||
direction,
|
direction,
|
||||||
channels, rate, maxbuffer, 0);
|
channels, rate, maxbuffer,
|
||||||
|
sizeof(struct node_data));
|
||||||
|
|
||||||
if (rd->dsp == NULL)
|
if (dsp == NULL)
|
||||||
goto no_mem;
|
goto no_mem;
|
||||||
|
|
||||||
pw_node_register(rd->dsp, client, pw_module_get_global(d->module), NULL);
|
nd = pw_audio_dsp_get_user_data(dsp);
|
||||||
pw_node_set_active(rd->dsp, true);
|
nd->data = d;
|
||||||
|
nd->dsp = dsp;
|
||||||
|
spa_list_append(&d->node_list, &nd->link);
|
||||||
|
|
||||||
return rd->dsp;
|
pw_node_register(dsp, client, pw_module_get_global(d->module), NULL);
|
||||||
|
|
||||||
|
res = pw_global_bind(pw_node_get_global(dsp), client, PW_PERM_RWX, PW_VERSION_NODE, new_id);
|
||||||
|
if (res < 0)
|
||||||
|
goto no_bind;
|
||||||
|
|
||||||
|
if ((bound_resource = pw_client_find_resource(client, new_id)) == NULL)
|
||||||
|
goto no_bind;
|
||||||
|
|
||||||
|
pw_resource_add_listener(bound_resource, &nd->resource_listener, &resource_events, nd);
|
||||||
|
|
||||||
|
pw_node_set_active(dsp, true);
|
||||||
|
|
||||||
|
return dsp;
|
||||||
|
|
||||||
no_resource:
|
no_resource:
|
||||||
pw_log_error("audio-dsp needs a resource");
|
pw_log_error("audio-dsp needs a resource");
|
||||||
|
|
@ -149,6 +157,9 @@ static void *create_object(void *_data,
|
||||||
pw_log_error("can't create node");
|
pw_log_error("can't create node");
|
||||||
pw_resource_error(resource, -ENOMEM, "no memory");
|
pw_resource_error(resource, -ENOMEM, "no memory");
|
||||||
goto done;
|
goto done;
|
||||||
|
no_bind:
|
||||||
|
pw_resource_error(resource, res, "can't bind dsp node");
|
||||||
|
goto done;
|
||||||
done:
|
done:
|
||||||
if (properties)
|
if (properties)
|
||||||
pw_properties_free(properties);
|
pw_properties_free(properties);
|
||||||
|
|
@ -163,9 +174,13 @@ static const struct pw_factory_implementation impl_factory = {
|
||||||
static void module_destroy(void *data)
|
static void module_destroy(void *data)
|
||||||
{
|
{
|
||||||
struct factory_data *d = data;
|
struct factory_data *d = data;
|
||||||
|
struct node_data *nd, *t;
|
||||||
|
|
||||||
spa_hook_remove(&d->module_listener);
|
spa_hook_remove(&d->module_listener);
|
||||||
|
|
||||||
|
spa_list_for_each_safe(nd, t, &d->node_list, link)
|
||||||
|
pw_node_destroy(nd->dsp);
|
||||||
|
|
||||||
if (d->properties)
|
if (d->properties)
|
||||||
pw_properties_free(d->properties);
|
pw_properties_free(d->properties);
|
||||||
|
|
||||||
|
|
@ -196,6 +211,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
||||||
data->this = factory;
|
data->this = factory;
|
||||||
data->module = module;
|
data->module = module;
|
||||||
data->properties = properties;
|
data->properties = properties;
|
||||||
|
spa_list_init(&data->node_list);
|
||||||
|
|
||||||
pw_log_debug("module %p: new", module);
|
pw_log_debug("module %p: new", module);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue