pipewire: use newly added function for deferred module destroy

Use the newly introduced `pw_impl_module_schedule_destroy()`
for deferred module destroy in all modules except
module-example-{sink,source}.
This commit is contained in:
Barnabás Pőcze 2022-02-17 03:34:05 +01:00
parent a13e7ef091
commit 45bd8532eb
9 changed files with 25 additions and 203 deletions

View file

@ -58,6 +58,7 @@
#include <pipewire/impl.h>
#include <pipewire/i18n.h>
#include <pipewire/private.h>
#include "module-raop/rtsp-client.h"
@ -134,7 +135,6 @@ struct impl {
struct pw_impl_module *module;
struct pw_loop *loop;
struct pw_work_queue *work;
struct spa_hook module_listener;
@ -160,7 +160,6 @@ struct impl {
char *password;
unsigned int do_disconnect:1;
unsigned int unloading:1;
uint8_t key[AES_CHUNK_SIZE]; /* Key for aes-cbc */
uint8_t iv[AES_CHUNK_SIZE]; /* Initialization vector for cbc */
@ -196,20 +195,6 @@ struct impl {
uint32_t filled;
};
static void do_unload_module(void *obj, void *data, int res, uint32_t id)
{
struct impl *impl = data;
pw_impl_module_destroy(impl->module);
}
static void unload_module(struct impl *impl)
{
if (!impl->unloading) {
impl->unloading = true;
pw_work_queue_add(impl->work, impl, 0, do_unload_module, impl);
}
}
static void stream_destroy(void *d)
{
struct impl *impl = d;
@ -1260,7 +1245,7 @@ static void stream_state_changed(void *d, enum pw_stream_state old,
switch (state) {
case PW_STREAM_STATE_ERROR:
case PW_STREAM_STATE_UNCONNECTED:
unload_module(impl);
pw_impl_module_schedule_destroy(impl->module);
break;
case PW_STREAM_STATE_PAUSED:
rtsp_do_flush(impl);
@ -1394,7 +1379,7 @@ static void core_error(void *data, uint32_t id, int seq, int res, const char *me
id, seq, res, spa_strerror(res), message);
if (id == PW_ID_CORE && res == -EPIPE)
unload_module(impl);
pw_impl_module_schedule_destroy(impl->module);
}
static const struct pw_core_events core_events = {
@ -1407,7 +1392,7 @@ static void core_destroy(void *d)
struct impl *impl = d;
spa_hook_remove(&impl->core_listener);
impl->core = NULL;
unload_module(impl);
pw_impl_module_schedule_destroy(impl->module);
}
static const struct pw_proxy_events core_proxy_events = {
@ -1428,15 +1413,12 @@ static void impl_destroy(struct impl *impl)
pw_properties_free(impl->stream_props);
pw_properties_free(impl->props);
free(impl->password);
if (impl->work)
pw_work_queue_cancel(impl->work, impl, SPA_ID_INVALID);
free(impl);
}
static void module_destroy(void *data)
{
struct impl *impl = data;
impl->unloading = true;
spa_hook_remove(&impl->module_listener);
impl_destroy(impl);
}
@ -1587,7 +1569,6 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
impl->module = module;
impl->context = context;
impl->loop = pw_context_get_main_loop(context);
impl->work = pw_context_get_work_queue(context);
if (pw_properties_get(props, PW_KEY_NODE_GROUP) == NULL)
pw_properties_set(props, PW_KEY_NODE_GROUP, "pipewire.dummy");