summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2020-08-21 15:40:19 +0200
committerWim Taymans <wtaymans@redhat.com>2020-08-21 15:40:19 +0200
commit0b588b2bfdff47d3c7b3f98fc58cf01f7dfe4b2a (patch)
tree2af87ed56b3c00d8ebfe4a4cbbd77f19a42f7673
parent4370675d2bc54fecbd54e5d618644dca0f87aa41 (diff)
pulse: track loaded modules
Track the proxies we load in a module_info and free the proxy on unload or exit.
-rw-r--r--pipewire-pulseaudio/src/context.c4
-rw-r--r--pipewire-pulseaudio/src/internal.h8
-rw-r--r--pipewire-pulseaudio/src/introspect.c55
3 files changed, 62 insertions, 5 deletions
diff --git a/pipewire-pulseaudio/src/context.c b/pipewire-pulseaudio/src/context.c
index b89c9f06..fc5241e0 100644
--- a/pipewire-pulseaudio/src/context.c
+++ b/pipewire-pulseaudio/src/context.c
@@ -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;
}
diff --git a/pipewire-pulseaudio/src/internal.h b/pipewire-pulseaudio/src/internal.h
index a30f56ce..e67bcc59 100644
--- a/pipewire-pulseaudio/src/internal.h
+++ b/pipewire-pulseaudio/src/internal.h
@@ -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;
diff --git a/pipewire-pulseaudio/src/introspect.c b/pipewire-pulseaudio/src/introspect.c
index 6d587ba0..0e455fa0 100644
--- a/pipewire-pulseaudio/src/introspect.c
+++ b/pipewire-pulseaudio/src/introspect.c
@@ -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;