modules: port modules to timer-queue

Instead of using timerfd, use the context timer-queue to schedule
timeouts. This saves fds and removes some redundant code.

Make the rtp-source timeout and standby code a bit better by using
atomic operations.
This commit is contained in:
Wim Taymans 2025-10-15 16:57:24 +02:00
parent b220f85790
commit a75cea96fb
11 changed files with 157 additions and 238 deletions

View file

@ -168,6 +168,7 @@ struct impl {
struct pw_loop *main_loop;
struct pw_loop *data_loop;
struct pw_timer_queue *timer_queue;
struct pw_core *core;
struct spa_hook core_listener;
@ -180,7 +181,7 @@ struct impl {
struct pw_properties *stream_props;
struct spa_source *timer;
struct pw_timer timer;
uint16_t src_port;
struct sockaddr_storage src_addr;
@ -562,7 +563,7 @@ static void destroy_stream(struct stream *s)
free(s);
}
static void on_timer_event(void *data, uint64_t expirations)
static void on_timer_event(void *data)
{
struct impl *impl = data;
struct stream *s;
@ -576,6 +577,9 @@ static void on_timer_event(void *data, uint64_t expirations)
}
s->receiving = false;
}
pw_timer_queue_add(impl->timer_queue, &impl->timer,
&impl->timer.timeout, impl->cleanup_interval * SPA_NSEC_PER_SEC,
on_timer_event, impl);
}
static void core_destroy(void *d)
@ -602,8 +606,7 @@ static void impl_destroy(struct impl *impl)
if (impl->core && impl->do_disconnect)
pw_core_disconnect(impl->core);
if (impl->timer)
pw_loop_destroy_source(impl->main_loop, impl->timer);
pw_timer_queue_cancel(&impl->timer);
if (impl->data_loop)
pw_context_release_loop(impl->context, impl->data_loop);
@ -658,7 +661,6 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
struct pw_context *context = pw_impl_module_get_context(module);
struct impl *impl;
const char *str;
struct timespec value, interval;
struct pw_properties *props, *stream_props;
int res = 0;
@ -682,6 +684,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
impl->module = module;
impl->context = context;
impl->main_loop = pw_context_get_main_loop(context);
impl->timer_queue = pw_context_get_timer_queue(context);
impl->data_loop = pw_context_acquire_loop(context, &props->dict);
spa_list_init(&impl->streams);
@ -747,17 +750,12 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
&impl->core_listener,
&core_events, impl);
impl->timer = pw_loop_add_timer(impl->main_loop, on_timer_event, impl);
if (impl->timer == NULL) {
res = -errno;
pw_log_error("can't create timer source: %m");
if ((res = pw_timer_queue_add(impl->timer_queue, &impl->timer,
NULL, impl->cleanup_interval * SPA_NSEC_PER_SEC,
on_timer_event, impl)) < 0) {
pw_log_error("can't add timer: %s", spa_strerror(res));
goto out;
}
value.tv_sec = impl->cleanup_interval;
value.tv_nsec = 0;
interval.tv_sec = impl->cleanup_interval;
interval.tv_nsec = 0;
pw_loop_update_timer(impl->main_loop, impl->timer, &value, &interval, false);
if ((res = listen_start(impl)) < 0) {
pw_log_error("failed to start VBAN stream: %s", spa_strerror(res));