diff --git a/src/modules/module-example-sink.c b/src/modules/module-example-sink.c index b8eadb26c..d99992264 100644 --- a/src/modules/module-example-sink.c +++ b/src/modules/module-example-sink.c @@ -126,7 +126,6 @@ struct impl { struct pw_properties *props; struct pw_impl_module *module; - struct pw_work_queue *work; struct spa_hook module_listener; @@ -141,23 +140,8 @@ struct impl { uint32_t frame_size; unsigned int do_disconnect:1; - unsigned int unloading:1; }; -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; @@ -172,7 +156,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: case PW_STREAM_STATE_STREAMING: @@ -257,7 +241,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 = { @@ -270,7 +254,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 = { @@ -287,15 +271,12 @@ static void impl_destroy(struct impl *impl) pw_properties_free(impl->stream_props); pw_properties_free(impl->props); - 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); } @@ -444,7 +425,6 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args) impl->module = module; impl->context = context; - impl->work = pw_context_get_work_queue(context); if (pw_properties_get(props, PW_KEY_NODE_VIRTUAL) == NULL) pw_properties_set(props, PW_KEY_NODE_VIRTUAL, "true"); diff --git a/src/modules/module-example-source.c b/src/modules/module-example-source.c index b8ad61d71..1db62dff9 100644 --- a/src/modules/module-example-source.c +++ b/src/modules/module-example-source.c @@ -126,7 +126,6 @@ struct impl { struct pw_properties *props; struct pw_impl_module *module; - struct pw_work_queue *work; struct spa_hook module_listener; @@ -144,20 +143,6 @@ struct impl { unsigned int unloading:1; }; -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; @@ -172,7 +157,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: case PW_STREAM_STATE_STREAMING: @@ -261,7 +246,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 = { @@ -274,7 +259,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 = { @@ -291,8 +276,6 @@ static void impl_destroy(struct impl *impl) pw_properties_free(impl->stream_props); pw_properties_free(impl->props); - if (impl->work) - pw_work_queue_cancel(impl->work, impl, SPA_ID_INVALID); free(impl); } @@ -448,7 +431,6 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args) impl->module = module; impl->context = context; - impl->work = pw_context_get_work_queue(context); if (pw_properties_get(props, PW_KEY_NODE_VIRTUAL) == NULL) pw_properties_set(props, PW_KEY_NODE_VIRTUAL, "true"); diff --git a/src/pipewire/impl-module.h b/src/pipewire/impl-module.h index 281cd2a52..013549898 100644 --- a/src/pipewire/impl-module.h +++ b/src/pipewire/impl-module.h @@ -106,6 +106,9 @@ void pw_impl_module_add_listener(struct pw_impl_module *module, /** Destroy a module */ void pw_impl_module_destroy(struct pw_impl_module *module); +/** Schedule a destroy later on the main thread */ +void pw_impl_module_schedule_destroy(struct pw_impl_module *module); + /** * \} */ diff --git a/src/pipewire/private.h b/src/pipewire/private.h index e60a23ee1..6fa8d778f 100644 --- a/src/pipewire/private.h +++ b/src/pipewire/private.h @@ -1299,8 +1299,6 @@ void pw_settings_init(struct pw_context *context); int pw_settings_expose(struct pw_context *context); void pw_settings_clean(struct pw_context *context); -void pw_impl_module_schedule_destroy(struct pw_impl_module *module); - pthread_attr_t *pw_thread_fill_attr(const struct spa_dict *props, pthread_attr_t *attr); /** \endcond */