diff options
author | Wim Taymans <wtaymans@redhat.com> | 2019-12-18 12:59:42 +0100 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2019-12-18 12:59:42 +0100 |
commit | 686a5cf47e4b2dda6e9513843dea20eedb6fd35f (patch) | |
tree | 4d0ae0acde01d81cac837806c06bfb50712c4923 | |
parent | 24ab22db124a354f0346b21664ab0c2b6ec74f66 (diff) |
media-session: improve shutdown
First emit a remove of all objects. Then signal a session
destroy and then destroy the context.
-rw-r--r-- | src/examples/media-session/alsa-endpoint.c | 4 | ||||
-rw-r--r-- | src/examples/media-session/media-session.c | 13 | ||||
-rw-r--r-- | src/examples/media-session/v4l2-endpoint.c | 10 |
3 files changed, 22 insertions, 5 deletions
diff --git a/src/examples/media-session/alsa-endpoint.c b/src/examples/media-session/alsa-endpoint.c index 582edff4..47d564f9 100644 --- a/src/examples/media-session/alsa-endpoint.c +++ b/src/examples/media-session/alsa-endpoint.c @@ -405,6 +405,7 @@ static void proxy_destroy(void *data) spa_list_remove(&endpoint->link); spa_hook_remove(&endpoint->proxy_listener); spa_hook_remove(&endpoint->client_endpoint_listener); + endpoint->client_endpoint = NULL; } static void proxy_bound(void *data, uint32_t id) @@ -537,7 +538,8 @@ static struct endpoint *create_endpoint(struct node *node, struct endpoint *moni static void destroy_endpoint(struct endpoint *endpoint) { - pw_proxy_destroy((struct pw_proxy*)endpoint->client_endpoint); + if (endpoint->client_endpoint) + pw_proxy_destroy((struct pw_proxy*)endpoint->client_endpoint); } /** fallback, one stream for each node */ diff --git a/src/examples/media-session/media-session.c b/src/examples/media-session/media-session.c index 5dce8535..6deb45b5 100644 --- a/src/examples/media-session/media-session.c +++ b/src/examples/media-session/media-session.c @@ -1672,6 +1672,16 @@ static int start_policy(struct impl *impl) return 0; } +static void session_shutdown(struct impl *impl) +{ + struct sm_object *obj; + + spa_list_for_each(obj, &impl->global_list, link) + sm_media_session_emit_remove(impl, obj); + + sm_media_session_emit_destroy(impl); +} + int main(int argc, char *argv[]) { struct impl impl = { 0, }; @@ -1714,8 +1724,9 @@ int main(int argc, char *argv[]) goto exit; pw_main_loop_run(impl.loop); + exit: - sm_media_session_emit_destroy(&impl); + session_shutdown(&impl); pw_context_destroy(impl.this.context); pw_main_loop_destroy(impl.loop); diff --git a/src/examples/media-session/v4l2-endpoint.c b/src/examples/media-session/v4l2-endpoint.c index 96fa58dd..6c5ea30f 100644 --- a/src/examples/media-session/v4l2-endpoint.c +++ b/src/examples/media-session/v4l2-endpoint.c @@ -355,6 +355,7 @@ static void proxy_destroy(void *data) spa_list_remove(&endpoint->link); spa_hook_remove(&endpoint->proxy_listener); spa_hook_remove(&endpoint->client_endpoint_listener); + endpoint->client_endpoint = NULL; } static void proxy_bound(void *data, uint32_t id) @@ -473,7 +474,7 @@ static struct endpoint *create_endpoint(struct node *node) return endpoint; } -static void destroy_endpoint(struct endpoint *endpoint) +static void destroy_endpoint(struct impl *impl, struct endpoint *endpoint) { pw_log_debug("endpoint %p: destroy", endpoint); if (endpoint->client_endpoint) { @@ -513,10 +514,13 @@ static int activate_device(struct device *device) static int deactivate_device(struct device *device) { + struct impl *impl = device->impl; struct endpoint *e; - pw_log_debug("device %p: deactivate", device->device); + + pw_log_debug(NAME" %p: device %p deactivate", impl, device->device); spa_list_consume(e, &device->endpoint_list, link) - destroy_endpoint(e); + destroy_endpoint(impl, e); + return 0; } |