mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
pulse: track loaded modules
Track the proxies we load in a module_info and free the proxy on unload or exit.
This commit is contained in:
parent
4370675d2b
commit
0b588b2bfd
3 changed files with 62 additions and 5 deletions
|
|
@ -64,6 +64,7 @@ static void context_unlink(pa_context *c)
|
|||
pa_stream *s, *t;
|
||||
struct global *g;
|
||||
pa_operation *o;
|
||||
struct module_info *m;
|
||||
|
||||
pw_log_debug("context %p: unlink %d", c, c->state);
|
||||
|
||||
|
|
@ -88,6 +89,8 @@ static void context_unlink(pa_context *c)
|
|||
|
||||
spa_list_consume(o, &c->operations, link)
|
||||
pa_operation_cancel(o);
|
||||
spa_list_consume(m, &c->modules, link)
|
||||
pw_proxy_destroy(m->proxy);
|
||||
}
|
||||
|
||||
void pa_context_set_state(pa_context *c, pa_context_state_t st) {
|
||||
|
|
@ -1489,6 +1492,7 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *
|
|||
|
||||
spa_list_init(&c->streams);
|
||||
spa_list_init(&c->operations);
|
||||
spa_list_init(&c->modules);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -325,6 +325,13 @@ struct global {
|
|||
};
|
||||
};
|
||||
|
||||
struct module_info {
|
||||
struct spa_list link; /* link in context modules */
|
||||
uint32_t id;
|
||||
struct pw_proxy *proxy;
|
||||
struct spa_hook listener;
|
||||
};
|
||||
|
||||
struct pa_context {
|
||||
int refcount;
|
||||
uint32_t client_index;
|
||||
|
|
@ -359,6 +366,7 @@ struct pa_context {
|
|||
|
||||
struct spa_list streams;
|
||||
struct spa_list operations;
|
||||
struct spa_list modules;
|
||||
|
||||
int no_fail:1;
|
||||
int disconnect:1;
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ static int sink_callback(pa_context *c, struct global *g, struct sink_data *d)
|
|||
i.channel_map = g->node_info.channel_map;
|
||||
else
|
||||
pa_channel_map_init_auto(&i.channel_map, i.sample_spec.channels, PA_CHANNEL_MAP_OSS);
|
||||
i.owner_module = 0;
|
||||
i.owner_module = g->id;
|
||||
i.volume.channels = i.sample_spec.channels;
|
||||
for (n = 0; n < i.volume.channels; n++)
|
||||
i.volume.values[n] = g->node_info.volume * g->node_info.channel_volumes[n] * PA_VOLUME_NORM;
|
||||
|
|
@ -847,7 +847,7 @@ static int source_callback(pa_context *c, struct global *g, struct source_data *
|
|||
i.channel_map = g->node_info.channel_map;
|
||||
else
|
||||
pa_channel_map_init_auto(&i.channel_map, i.sample_spec.channels, PA_CHANNEL_MAP_OSS);
|
||||
i.owner_module = 0;
|
||||
i.owner_module = g->id;
|
||||
i.volume.channels = i.sample_spec.channels;
|
||||
for (n = 0; n < i.volume.channels; n++)
|
||||
i.volume.values[n] = g->node_info.volume * g->node_info.channel_volumes[n] * PA_VOLUME_NORM;
|
||||
|
|
@ -1402,6 +1402,16 @@ struct load_module {
|
|||
struct spa_hook listener;
|
||||
};
|
||||
|
||||
static struct module_info *find_module(pa_context *c, uint32_t idx)
|
||||
{
|
||||
struct module_info *m;
|
||||
spa_list_for_each(m, &c->modules, link) {
|
||||
if (m->id == idx)
|
||||
return m;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void on_load_module(pa_operation *o, void *userdata)
|
||||
{
|
||||
struct load_module *d = userdata;
|
||||
|
|
@ -1417,11 +1427,37 @@ static void on_load_module(pa_operation *o, void *userdata)
|
|||
spa_hook_remove(&d->listener);
|
||||
}
|
||||
|
||||
static void module_proxy_removed(void *data)
|
||||
{
|
||||
struct module_info *m = data;
|
||||
pw_proxy_destroy(m->proxy);
|
||||
}
|
||||
|
||||
static void module_proxy_destroy(void *data)
|
||||
{
|
||||
struct module_info *m = data;
|
||||
spa_hook_remove(&m->listener);
|
||||
spa_list_remove(&m->link);
|
||||
free(m);
|
||||
}
|
||||
|
||||
static void module_proxy_bound(void *data, uint32_t global_id)
|
||||
{
|
||||
struct module_info *m;
|
||||
pa_operation *o = data;
|
||||
pa_context *c = o->context;
|
||||
struct load_module *d = o->userdata;
|
||||
static const struct pw_proxy_events proxy_events = {
|
||||
.removed = module_proxy_removed,
|
||||
.destroy = module_proxy_destroy,
|
||||
};
|
||||
d->idx = global_id;
|
||||
|
||||
m = calloc(1, sizeof(struct module_info));
|
||||
m->id = global_id;
|
||||
m->proxy = d->proxy;
|
||||
pw_proxy_add_listener(m->proxy, &m->listener, &proxy_events, m);
|
||||
spa_list_append(&c->modules, &m->link);
|
||||
on_load_module(o, d);
|
||||
}
|
||||
|
||||
|
|
@ -1431,6 +1467,7 @@ static void module_proxy_error(void *data, int seq, int res, const char *message
|
|||
struct load_module *d = o->userdata;
|
||||
d->error = res;
|
||||
d->idx = PA_INVALID_INDEX;
|
||||
pw_proxy_destroy(d->proxy);
|
||||
on_load_module(o, d);
|
||||
}
|
||||
|
||||
|
|
@ -1544,13 +1581,21 @@ pa_operation* pa_context_unload_module(pa_context *c, uint32_t idx, pa_context_s
|
|||
{
|
||||
pa_operation *o;
|
||||
struct success_ack *d;
|
||||
struct module_info *m;
|
||||
int error;
|
||||
|
||||
pw_log_debug("context %p: %u", c, idx);
|
||||
if ((m = find_module(c, idx)) != NULL) {
|
||||
pw_proxy_destroy(m->proxy);
|
||||
error = 0;
|
||||
} else {
|
||||
error = PA_ERR_NOENTITY;
|
||||
}
|
||||
o = pa_operation_new(c, NULL, on_success, sizeof(struct success_ack));
|
||||
d = o->userdata;
|
||||
d->cb = cb;
|
||||
d->error = PA_ERR_NOTIMPLEMENTED;
|
||||
d->userdata = userdata;
|
||||
d->error = error;
|
||||
d->idx = idx;
|
||||
pa_operation_sync(o);
|
||||
|
||||
|
|
@ -1986,7 +2031,7 @@ static int sink_input_callback(pa_context *c, struct sink_input_data *d, struct
|
|||
spa_zero(i);
|
||||
i.index = g->id;
|
||||
i.name = name;
|
||||
i.owner_module = PA_INVALID_INDEX;
|
||||
i.owner_module = g->id;
|
||||
i.client = g->node_info.client_id;
|
||||
if (s)
|
||||
i.sink = s->device_index;
|
||||
|
|
@ -2387,7 +2432,7 @@ static int source_output_callback(struct source_output_data *d, pa_context *c, s
|
|||
spa_zero(i);
|
||||
i.index = g->id;
|
||||
i.name = name;
|
||||
i.owner_module = PA_INVALID_INDEX;
|
||||
i.owner_module = g->id;
|
||||
i.client = g->node_info.client_id;
|
||||
if (s)
|
||||
i.source = s->device_index;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue