mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2026-05-09 05:08:04 +02:00
modules: unregister endpoints on global_removed instead of proxy destroyed
This commit is contained in:
parent
495a74d0e6
commit
7aded3a8c9
4 changed files with 61 additions and 31 deletions
|
|
@ -26,12 +26,14 @@ struct module_data
|
|||
{
|
||||
WpModule *module;
|
||||
WpRemotePipewire *remote_pipewire;
|
||||
GHashTable *registered_endpoints;
|
||||
};
|
||||
|
||||
static void
|
||||
on_endpoint_created(GObject *initable, GAsyncResult *res, gpointer d)
|
||||
{
|
||||
g_autoptr (WpEndpoint) endpoint = NULL;
|
||||
struct module_data *data = d;
|
||||
WpEndpoint *endpoint = NULL;
|
||||
guint global_id = 0;
|
||||
|
||||
/* Get the endpoint */
|
||||
|
|
@ -43,8 +45,10 @@ on_endpoint_created(GObject *initable, GAsyncResult *res, gpointer d)
|
|||
g_object_get (endpoint, "global-id", &global_id, NULL);
|
||||
g_debug ("Created client endpoint for global id %d", global_id);
|
||||
|
||||
/* Register the endpoint */
|
||||
/* Register the endpoint and add it to the table */
|
||||
wp_endpoint_register (endpoint);
|
||||
g_hash_table_insert (data->registered_endpoints, GUINT_TO_POINTER(global_id),
|
||||
endpoint);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -89,6 +93,23 @@ on_node_added (WpRemotePipewire *rp, guint id, guint parent_id, gconstpointer p,
|
|||
endpoint_props, on_endpoint_created, data);
|
||||
}
|
||||
|
||||
static void
|
||||
on_global_removed (WpRemotePipewire *rp, guint id, gpointer d)
|
||||
{
|
||||
struct module_data *data = d;
|
||||
WpEndpoint *endpoint = NULL;
|
||||
|
||||
/* Get the endpoint */
|
||||
endpoint = g_hash_table_lookup (data->registered_endpoints,
|
||||
GUINT_TO_POINTER(id));
|
||||
if (!endpoint)
|
||||
return;
|
||||
|
||||
/* Remove the endpoint from the table and unregister it */
|
||||
g_hash_table_remove (data->registered_endpoints, GUINT_TO_POINTER(id));
|
||||
wp_endpoint_unregister (endpoint);
|
||||
}
|
||||
|
||||
static void
|
||||
module_destroy (gpointer d)
|
||||
{
|
||||
|
|
@ -98,6 +119,10 @@ module_destroy (gpointer d)
|
|||
data->module = NULL;
|
||||
data->remote_pipewire = NULL;
|
||||
|
||||
/* Destroy the registered endpoints table */
|
||||
g_hash_table_unref(data->registered_endpoints);
|
||||
data->registered_endpoints = NULL;
|
||||
|
||||
/* Clean up */
|
||||
g_slice_free (struct module_data, data);
|
||||
}
|
||||
|
|
@ -122,12 +147,15 @@ wireplumber__module_init (WpModule * module, WpCore * core, GVariant * args)
|
|||
data = g_slice_new0 (struct module_data);
|
||||
data->module = module;
|
||||
data->remote_pipewire = rp;
|
||||
data->registered_endpoints = g_hash_table_new_full (g_direct_hash,
|
||||
g_direct_equal, NULL, (GDestroyNotify)g_object_unref);
|
||||
|
||||
/* Set the module destroy callback */
|
||||
wp_module_set_destroy_callback (module, module_destroy, data);
|
||||
|
||||
/* Register the global added/removed callbacks */
|
||||
g_signal_connect(rp, "global-added::node", (GCallback)on_node_added, data);
|
||||
g_signal_connect(rp, "global-removed", (GCallback)on_global_removed, data);
|
||||
|
||||
/* Init remoted endpoint */
|
||||
g_object_get (rp, "pw-core", &pw_core, "pw-remote", &pw_remote, NULL);
|
||||
|
|
|
|||
|
|
@ -116,15 +116,6 @@ static const struct pw_node_proxy_events node_node_proxy_events = {
|
|||
.param = node_proxy_param,
|
||||
};
|
||||
|
||||
static void
|
||||
on_proxy_node_destroyed (WpProxy* wp_proxy, WpEndpoint *endpoint)
|
||||
{
|
||||
g_return_if_fail(WP_IS_ENDPOINT(endpoint));
|
||||
|
||||
/* Unregister the endpoint */
|
||||
wp_endpoint_unregister(endpoint);
|
||||
}
|
||||
|
||||
static void
|
||||
on_all_ports_done(WpProxy *proxy, gpointer data)
|
||||
{
|
||||
|
|
@ -134,10 +125,6 @@ on_all_ports_done(WpProxy *proxy, gpointer data)
|
|||
if (!self->init_task)
|
||||
return;
|
||||
|
||||
/* Set destroy handler to unregister endpoint on proxy_node destruction */
|
||||
g_signal_connect (self->proxy_node, "destroyed",
|
||||
G_CALLBACK(on_proxy_node_destroyed), WP_ENDPOINT(self));
|
||||
|
||||
/* Finish the creation of the endpoint */
|
||||
g_task_return_boolean (self->init_task, TRUE);
|
||||
g_clear_object(&self->init_task);
|
||||
|
|
|
|||
|
|
@ -19,12 +19,14 @@ struct impl
|
|||
{
|
||||
WpModule *module;
|
||||
WpRemotePipewire *remote_pipewire;
|
||||
GHashTable *registered_endpoints;
|
||||
};
|
||||
|
||||
static void
|
||||
on_endpoint_created(GObject *initable, GAsyncResult *res, gpointer d)
|
||||
{
|
||||
g_autoptr (WpEndpoint) endpoint = NULL;
|
||||
struct impl *impl = d;
|
||||
WpEndpoint *endpoint = NULL;
|
||||
guint global_id = 0;
|
||||
|
||||
/* Get the endpoint */
|
||||
|
|
@ -36,8 +38,10 @@ on_endpoint_created(GObject *initable, GAsyncResult *res, gpointer d)
|
|||
g_object_get (endpoint, "global-id", &global_id, NULL);
|
||||
g_debug ("Created alsa endpoint for global id %d", global_id);
|
||||
|
||||
/* Register the endpoint */
|
||||
/* Register the endpoint and add it to the table */
|
||||
wp_endpoint_register (endpoint);
|
||||
g_hash_table_insert (impl->registered_endpoints, GUINT_TO_POINTER(global_id),
|
||||
endpoint);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -76,6 +80,23 @@ on_node_added(WpRemotePipewire *rp, guint id, guint parent_id, gconstpointer p,
|
|||
endpoint_props, on_endpoint_created, impl);
|
||||
}
|
||||
|
||||
static void
|
||||
on_global_removed (WpRemotePipewire *rp, guint id, gpointer d)
|
||||
{
|
||||
struct impl *impl = d;
|
||||
WpEndpoint *endpoint = NULL;
|
||||
|
||||
/* Get the endpoint */
|
||||
endpoint = g_hash_table_lookup (impl->registered_endpoints,
|
||||
GUINT_TO_POINTER(id));
|
||||
if (!endpoint)
|
||||
return;
|
||||
|
||||
/* Remove the endpoint from the table and unregister it */
|
||||
g_hash_table_remove (impl->registered_endpoints, GUINT_TO_POINTER(id));
|
||||
wp_endpoint_unregister (endpoint);
|
||||
}
|
||||
|
||||
static void
|
||||
module_destroy (gpointer data)
|
||||
{
|
||||
|
|
@ -85,6 +106,10 @@ module_destroy (gpointer data)
|
|||
impl->module = NULL;
|
||||
impl->remote_pipewire = NULL;
|
||||
|
||||
/* Destroy the registered endpoints table */
|
||||
g_hash_table_unref(impl->registered_endpoints);
|
||||
impl->registered_endpoints = NULL;
|
||||
|
||||
/* Clean up */
|
||||
g_slice_free (struct impl, impl);
|
||||
}
|
||||
|
|
@ -107,10 +132,13 @@ wireplumber__module_init (WpModule * module, WpCore * core, GVariant * args)
|
|||
impl = g_slice_new0(struct impl);
|
||||
impl->module = module;
|
||||
impl->remote_pipewire = rp;
|
||||
impl->registered_endpoints = g_hash_table_new_full (g_direct_hash,
|
||||
g_direct_equal, NULL, (GDestroyNotify)g_object_unref);
|
||||
|
||||
/* Set destroy callback for impl */
|
||||
wp_module_set_destroy_callback (module, module_destroy, impl);
|
||||
|
||||
/* Register the global addded callbacks */
|
||||
/* Register the global addded/removed callbacks */
|
||||
g_signal_connect(rp, "global-added::node", (GCallback)on_node_added, impl);
|
||||
g_signal_connect(rp, "global-removed", (GCallback)on_global_removed, impl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -242,15 +242,6 @@ static const struct pw_node_proxy_events dsp_node_events = {
|
|||
.param = dsp_node_event_param,
|
||||
};
|
||||
|
||||
static void
|
||||
on_proxy_node_destroyed (WpProxy* wp_proxy, WpEndpoint *endpoint)
|
||||
{
|
||||
g_return_if_fail(WP_IS_ENDPOINT(endpoint));
|
||||
|
||||
/* Unregister the endpoint */
|
||||
wp_endpoint_unregister(endpoint);
|
||||
}
|
||||
|
||||
static void
|
||||
on_proxy_dsp_done(WpProxy *proxy, gpointer data)
|
||||
{
|
||||
|
|
@ -260,10 +251,6 @@ on_proxy_dsp_done(WpProxy *proxy, gpointer data)
|
|||
if (!self->init_task)
|
||||
return;
|
||||
|
||||
/* Set destroy handler to unregister endpoint on proxy_node destruction */
|
||||
g_signal_connect (self->proxy_node, "destroyed",
|
||||
G_CALLBACK(on_proxy_node_destroyed), WP_ENDPOINT(self));
|
||||
|
||||
/* Finish the creation of the endpoint */
|
||||
g_task_return_boolean (self->init_task, TRUE);
|
||||
g_clear_object(&self->init_task);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue