mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
media-session: improve cleanup
This commit is contained in:
parent
98c81fff93
commit
05f93cd750
8 changed files with 65 additions and 17 deletions
|
|
@ -403,6 +403,8 @@ static void proxy_destroy(void *data)
|
|||
|
||||
pw_properties_free(endpoint->props);
|
||||
spa_list_remove(&endpoint->link);
|
||||
spa_hook_remove(&endpoint->proxy_listener);
|
||||
spa_hook_remove(&endpoint->listener);
|
||||
}
|
||||
|
||||
static void proxy_bound(void *data, uint32_t id)
|
||||
|
|
|
|||
|
|
@ -413,7 +413,7 @@ static void set_profile(struct device *device, int index)
|
|||
char buf[1024];
|
||||
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buf, sizeof(buf));
|
||||
|
||||
pw_log_debug("%p: set profile %d", device, device->device_id);
|
||||
pw_log_debug("%p: set profile %d id:%d", device, index, device->device_id);
|
||||
|
||||
device->profile = index;
|
||||
if (device->device_id != 0) {
|
||||
|
|
@ -511,6 +511,16 @@ static const struct rd_device_callbacks reserve_callbacks = {
|
|||
.release = reserve_release,
|
||||
};
|
||||
|
||||
static void device_destroy(void *data)
|
||||
{
|
||||
struct device *device = data;
|
||||
struct node *node;
|
||||
|
||||
pw_log_debug("device %p destroy", device);
|
||||
|
||||
spa_list_consume(node, &device->node_list, link)
|
||||
alsa_remove_node(device, node);
|
||||
}
|
||||
|
||||
static void device_update(void *data)
|
||||
{
|
||||
|
|
@ -529,10 +539,12 @@ static void device_update(void *data)
|
|||
&alsa_device_events, device);
|
||||
|
||||
set_profile(device, device->profile);
|
||||
sm_object_sync_update(&device->sdevice->obj);
|
||||
}
|
||||
|
||||
static const struct sm_object_events device_events = {
|
||||
SM_VERSION_OBJECT_EVENTS,
|
||||
.destroy = device_destroy,
|
||||
.update = device_update,
|
||||
};
|
||||
|
||||
|
|
@ -634,14 +646,15 @@ static void alsa_remove_device(struct impl *impl, struct device *device)
|
|||
{
|
||||
pw_log_debug("remove device %u", device->id);
|
||||
spa_list_remove(&device->link);
|
||||
spa_hook_remove(&device->listener);
|
||||
spa_hook_remove(&device->device_listener);
|
||||
if (device->appeared)
|
||||
spa_hook_remove(&device->device_listener);
|
||||
if (device->seq != 0)
|
||||
spa_hook_remove(&device->sync_listener);
|
||||
if (device->reserve)
|
||||
rd_device_destroy(device->reserve);
|
||||
if (device->sdevice)
|
||||
sm_object_destroy(&device->sdevice->obj);
|
||||
spa_hook_remove(&device->listener);
|
||||
pw_unload_spa_handle(device->handle);
|
||||
free(device);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@
|
|||
#define sm_object_emit(o,m,v,...) spa_hook_list_call(&(o)->hooks, struct sm_object_events, m, v, ##__VA_ARGS__)
|
||||
|
||||
#define sm_object_emit_update(s) sm_object_emit(s, update, 0)
|
||||
#define sm_object_emit_destroy(s) sm_object_emit(s, destroy, 0)
|
||||
|
||||
#define sm_media_session_emit(s,m,v,...) spa_hook_list_call(&s->hooks, struct sm_media_session_events, m, v, ##__VA_ARGS__)
|
||||
|
||||
|
|
@ -228,7 +229,10 @@ int sm_object_remove_data(struct sm_object *obj, const char *id)
|
|||
|
||||
int sm_object_destroy(struct sm_object *obj)
|
||||
{
|
||||
pw_log_debug(NAME" %p: object %d", obj->session, obj->id);
|
||||
pw_proxy_destroy(obj->proxy);
|
||||
if (obj->handle)
|
||||
pw_proxy_destroy(obj->handle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -893,6 +897,8 @@ destroy_proxy(void *data)
|
|||
|
||||
remove_object(impl, obj);
|
||||
|
||||
sm_object_emit_destroy(obj);
|
||||
|
||||
if (obj->destroy)
|
||||
obj->destroy(obj);
|
||||
}
|
||||
|
|
@ -1073,7 +1079,10 @@ update_object(struct impl *impl, const struct object_info *info,
|
|||
if (obj->type == type)
|
||||
return 0;
|
||||
|
||||
pw_log_debug(NAME" %p: update type:%d -> type:%d", impl, obj->type, type);
|
||||
obj->handle = obj->proxy;
|
||||
spa_hook_remove(&obj->proxy_listener);
|
||||
|
||||
if (SPA_FLAG_IS_SET(obj->mask, SM_OBJECT_CHANGE_MASK_LISTENER))
|
||||
spa_hook_remove(&obj->object_listener);
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ struct sm_object {
|
|||
pw_destroy_t destroy;
|
||||
int pending;
|
||||
|
||||
struct pw_proxy *handle;
|
||||
struct spa_hook_list hooks;
|
||||
|
||||
struct spa_list data;
|
||||
|
|
|
|||
|
|
@ -346,11 +346,15 @@ static void proxy_destroy(void *data)
|
|||
struct endpoint *endpoint = data;
|
||||
struct stream *s;
|
||||
|
||||
pw_log_debug("endpoint %p: destroy", endpoint);
|
||||
|
||||
spa_list_consume(s, &endpoint->stream_list, link)
|
||||
destroy_stream(s);
|
||||
|
||||
pw_properties_free(endpoint->props);
|
||||
spa_list_remove(&endpoint->link);
|
||||
spa_hook_remove(&endpoint->proxy_listener);
|
||||
spa_hook_remove(&endpoint->listener);
|
||||
}
|
||||
|
||||
static void proxy_bound(void *data, uint32_t id)
|
||||
|
|
@ -471,7 +475,10 @@ static struct endpoint *create_endpoint(struct node *node)
|
|||
|
||||
static void destroy_endpoint(struct endpoint *endpoint)
|
||||
{
|
||||
pw_proxy_destroy((struct pw_proxy*)endpoint->client_endpoint);
|
||||
pw_log_debug("endpoint %p: destroy", endpoint);
|
||||
if (endpoint->client_endpoint) {
|
||||
pw_proxy_destroy((struct pw_proxy*)endpoint->client_endpoint);
|
||||
}
|
||||
}
|
||||
|
||||
/** fallback, one stream for each node */
|
||||
|
|
@ -507,6 +514,7 @@ static int activate_device(struct device *device)
|
|||
static int deactivate_device(struct device *device)
|
||||
{
|
||||
struct endpoint *e;
|
||||
pw_log_debug("device %p: deactivate", device->device);
|
||||
spa_list_consume(e, &device->endpoint_list, link)
|
||||
destroy_endpoint(e);
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -286,6 +286,17 @@ static void set_profile(struct device *device, int index)
|
|||
}
|
||||
}
|
||||
|
||||
static void device_destroy(void *data)
|
||||
{
|
||||
struct device *device = data;
|
||||
struct node *node;
|
||||
|
||||
pw_log_debug("device %p destroy", device);
|
||||
|
||||
spa_list_consume(node, &device->node_list, link)
|
||||
v4l2_remove_node(device, node);
|
||||
}
|
||||
|
||||
static void device_update(void *data)
|
||||
{
|
||||
struct device *device = data;
|
||||
|
|
@ -308,6 +319,7 @@ static void device_update(void *data)
|
|||
|
||||
static const struct sm_object_events device_events = {
|
||||
SM_VERSION_OBJECT_EVENTS,
|
||||
.destroy = device_destroy,
|
||||
.update = device_update,
|
||||
};
|
||||
|
||||
|
|
@ -363,6 +375,8 @@ static struct device *v4l2_create_device(struct impl *impl, uint32_t id,
|
|||
goto clean_device;
|
||||
}
|
||||
|
||||
pw_log_debug("got object %p", &dev->sdevice->obj);
|
||||
|
||||
sm_object_add_listener(&dev->sdevice->obj,
|
||||
&dev->listener,
|
||||
&device_events, dev);
|
||||
|
|
@ -385,10 +399,11 @@ static void v4l2_remove_device(struct impl *impl, struct device *dev)
|
|||
{
|
||||
pw_log_debug("remove device %u", dev->id);
|
||||
spa_list_remove(&dev->link);
|
||||
spa_hook_remove(&dev->listener);
|
||||
spa_hook_remove(&dev->device_listener);
|
||||
if (dev->appeared)
|
||||
spa_hook_remove(&dev->device_listener);
|
||||
if (dev->sdevice)
|
||||
sm_object_destroy(&dev->sdevice->obj);
|
||||
spa_hook_remove(&dev->listener);
|
||||
pw_unload_spa_handle(dev->handle);
|
||||
free(dev);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,11 +62,11 @@ struct pw_proxy *pw_core_spa_device_export(struct pw_core *core,
|
|||
struct device_data *data;
|
||||
|
||||
proxy = pw_core_create_object(core,
|
||||
"client-device",
|
||||
SPA_TYPE_INTERFACE_Device,
|
||||
SPA_VERSION_DEVICE,
|
||||
props,
|
||||
user_data_size + sizeof(struct device_data));
|
||||
"client-device",
|
||||
SPA_TYPE_INTERFACE_Device,
|
||||
SPA_VERSION_DEVICE,
|
||||
props,
|
||||
user_data_size + sizeof(struct device_data));
|
||||
if (proxy == NULL)
|
||||
return NULL;
|
||||
|
||||
|
|
|
|||
|
|
@ -425,20 +425,20 @@ pw_context_connect_self(struct pw_context *context, struct pw_properties *proper
|
|||
}
|
||||
|
||||
SPA_EXPORT
|
||||
int pw_core_steal_fd(struct pw_core *proxy)
|
||||
int pw_core_steal_fd(struct pw_core *core)
|
||||
{
|
||||
return pw_protocol_client_steal_fd(proxy->conn);
|
||||
return pw_protocol_client_steal_fd(core->conn);
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
struct pw_mempool * pw_core_get_mempool(struct pw_core *proxy)
|
||||
struct pw_mempool * pw_core_get_mempool(struct pw_core *core)
|
||||
{
|
||||
return proxy->pool;
|
||||
return core->pool;
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
int pw_core_disconnect(struct pw_core *proxy)
|
||||
int pw_core_disconnect(struct pw_core *core)
|
||||
{
|
||||
pw_proxy_destroy(&proxy->proxy);
|
||||
pw_proxy_remove(&core->proxy);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue