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

@ -212,6 +212,7 @@ struct impl {
struct pw_impl_module *module;
struct pw_loop *loop;
struct pw_timer_queue *timer_queue;
struct spa_hook module_listener;
@ -245,7 +246,7 @@ struct impl {
uint16_t control_port;
int control_fd;
struct spa_source *control_source;
struct spa_source *feedback_timer;
struct pw_timer feedback_timer;
uint16_t timing_port;
int timing_fd;
@ -836,12 +837,16 @@ static int rtsp_send_volume(struct impl *impl)
return rtsp_send(impl, "SET_PARAMETER", "text/parameters", header, rtsp_log_reply_status);
}
static void rtsp_do_post_feedback(void *data, uint64_t expirations)
static void rtsp_do_post_feedback(void *data)
{
struct impl *impl = data;
pw_rtsp_client_url_send(impl->rtsp, "/feedback", "POST", &impl->headers->dict,
NULL, NULL, 0, rtsp_log_reply_status, impl);
pw_timer_queue_add(impl->timer_queue, &impl->feedback_timer,
&impl->feedback_timer.timeout, 2 * SPA_NSEC_PER_SEC,
rtsp_do_post_feedback, impl);
}
static uint32_t msec_to_samples(struct impl *impl, uint32_t msec)
@ -854,7 +859,6 @@ static int rtsp_record_reply(void *data, int status, const struct spa_dict *head
struct impl *impl = data;
const char *str;
char progress[128];
struct timespec timeout, interval;
struct spa_process_latency_info process_latency;
pw_log_info("record status: %d", status);
@ -866,16 +870,12 @@ static int rtsp_record_reply(void *data, int status, const struct spa_dict *head
return 0;
}
timeout.tv_sec = 2;
timeout.tv_nsec = 0;
interval.tv_sec = 2;
interval.tv_nsec = 0;
// feedback timer is only needed for auth_setup encryption
if (impl->encryption == CRYPTO_FP_SAP25) {
if (!impl->feedback_timer)
impl->feedback_timer = pw_loop_add_timer(impl->loop, rtsp_do_post_feedback, impl);
pw_loop_update_timer(impl->loop, impl->feedback_timer, &timeout, &interval, false);
pw_timer_queue_cancel(&impl->feedback_timer);
pw_timer_queue_add(impl->timer_queue, &impl->feedback_timer,
NULL, 2 * SPA_NSEC_PER_SEC,
rtsp_do_post_feedback, impl);
}
if ((str = spa_dict_lookup(headers, "Audio-Latency")) != NULL) {
@ -1476,10 +1476,8 @@ static void connection_cleanup(struct impl *impl)
close(impl->timing_fd);
impl->timing_fd = -1;
}
if (impl->feedback_timer != NULL) {
pw_loop_destroy_source(impl->loop, impl->feedback_timer);
impl->feedback_timer = NULL;
}
pw_timer_queue_cancel(&impl->feedback_timer);
free(impl->auth_method);
impl->auth_method = NULL;
free(impl->realm);
@ -1792,6 +1790,7 @@ 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->timer_queue = pw_context_get_timer_queue(context);
ip = pw_properties_get(props, "raop.ip");
port = pw_properties_get(props, "raop.port");