mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-02-08 10:06:23 -05:00
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:
parent
b220f85790
commit
a75cea96fb
11 changed files with 157 additions and 238 deletions
|
|
@ -41,6 +41,7 @@ struct pw_avb *pw_avb_new(struct pw_context *context,
|
|||
|
||||
impl->context = context;
|
||||
impl->loop = pw_context_get_main_loop(context);
|
||||
impl->timer_queue = pw_context_get_timer_queue(context);
|
||||
impl->props = props;
|
||||
impl->core = pw_context_get_object(context, PW_TYPE_INTERFACE_Core);
|
||||
if (impl->core == NULL) {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include <spa/support/cpu.h>
|
||||
#include <spa/debug/mem.h>
|
||||
#include <spa/utils/result.h>
|
||||
|
||||
#include <pipewire/pipewire.h>
|
||||
|
||||
|
|
@ -39,12 +40,18 @@
|
|||
#define server_emit_periodic(s,n) server_emit(s, periodic, 0, n)
|
||||
#define server_emit_command(s,n,c,a,f) server_emit(s, command, 0, n, c, a, f)
|
||||
|
||||
static void on_timer_event(void *data, uint64_t expirations)
|
||||
static void on_timer_event(void *data)
|
||||
{
|
||||
struct server *server = data;
|
||||
struct impl *impl = server->impl;
|
||||
struct timespec now;
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &now);
|
||||
server_emit_periodic(server, SPA_TIMESPEC_TO_NSEC(&now));
|
||||
|
||||
pw_timer_queue_add(impl->timer_queue, &server->timer,
|
||||
&server->timer.timeout, DEFAULT_INTERVAL * SPA_NSEC_PER_SEC,
|
||||
on_timer_event, server);
|
||||
}
|
||||
|
||||
static void on_socket_data(void *data, int fd, uint32_t mask)
|
||||
|
|
@ -201,7 +208,6 @@ static int setup_socket(struct server *server)
|
|||
struct impl *impl = server->impl;
|
||||
int fd, res;
|
||||
static const uint8_t bmac[6] = AVB_BROADCAST_MAC;
|
||||
struct timespec value, interval;
|
||||
|
||||
fd = avb_server_make_socket(server, AVB_TSN_ETH, bmac);
|
||||
if (fd < 0)
|
||||
|
|
@ -215,18 +221,13 @@ static int setup_socket(struct server *server)
|
|||
pw_log_error("server %p: can't create server source: %m", impl);
|
||||
goto error_no_source;
|
||||
}
|
||||
server->timer = pw_loop_add_timer(impl->loop, on_timer_event, server);
|
||||
if (server->timer == NULL) {
|
||||
res = -errno;
|
||||
pw_log_error("server %p: can't create timer source: %m", impl);
|
||||
|
||||
if ((res = pw_timer_queue_add(impl->timer_queue, &server->timer,
|
||||
NULL, DEFAULT_INTERVAL * SPA_NSEC_PER_SEC,
|
||||
on_timer_event, server)) < 0) {
|
||||
pw_log_error("server %p: can't create timer: %s", impl, spa_strerror(res));
|
||||
goto error_no_timer;
|
||||
}
|
||||
value.tv_sec = 0;
|
||||
value.tv_nsec = 1;
|
||||
interval.tv_sec = DEFAULT_INTERVAL;
|
||||
interval.tv_nsec = 0;
|
||||
pw_loop_update_timer(impl->loop, server->timer, &value, &interval, false);
|
||||
|
||||
return 0;
|
||||
|
||||
error_no_timer:
|
||||
|
|
@ -310,8 +311,7 @@ void avdecc_server_free(struct server *server)
|
|||
spa_list_remove(&server->link);
|
||||
if (server->source)
|
||||
pw_loop_destroy_source(impl->loop, server->source);
|
||||
if (server->timer)
|
||||
pw_loop_destroy_source(impl->loop, server->timer);
|
||||
pw_timer_queue_cancel(&server->timer);
|
||||
spa_hook_list_clean(&server->listener_list);
|
||||
free(server);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ struct avb_mrp;
|
|||
|
||||
struct impl {
|
||||
struct pw_loop *loop;
|
||||
struct pw_timer_queue *timer_queue;
|
||||
struct pw_context *context;
|
||||
struct spa_hook context_listener;
|
||||
struct pw_core *core;
|
||||
|
|
@ -61,7 +62,7 @@ struct server {
|
|||
int ifindex;
|
||||
|
||||
struct spa_source *source;
|
||||
struct spa_source *timer;
|
||||
struct pw_timer timer;
|
||||
|
||||
struct spa_hook_list listener_list;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue