mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
system: use spa_system functions for fds
This commit is contained in:
parent
b14bb1f496
commit
68e94a2e7e
16 changed files with 96 additions and 60 deletions
|
|
@ -29,7 +29,6 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <bluetooth/bluetooth.h>
|
||||
|
|
@ -59,6 +58,7 @@ struct spa_bt_monitor {
|
|||
|
||||
struct spa_log *log;
|
||||
struct spa_loop *main_loop;
|
||||
struct spa_system *main_system;
|
||||
struct spa_dbus *dbus;
|
||||
struct spa_dbus_connection *dbus_connection;
|
||||
DBusConnection *conn;
|
||||
|
|
@ -546,7 +546,7 @@ static void device_timer_event(struct spa_source *source)
|
|||
struct spa_bt_monitor *monitor = device->monitor;
|
||||
uint64_t exp;
|
||||
|
||||
if (read(source->fd, &exp, sizeof(uint64_t)) != sizeof(uint64_t))
|
||||
if (spa_system_timerfd_read(monitor->main_system, source->fd, &exp) < 0)
|
||||
spa_log_warn(monitor->log, "error reading timerfd: %s", strerror(errno));
|
||||
|
||||
spa_log_debug(monitor->log, "device %p: timeout %08x %08x",
|
||||
|
|
@ -564,7 +564,8 @@ static int device_start_timer(struct spa_bt_device *device)
|
|||
if (device->timer.data == NULL) {
|
||||
device->timer.data = device;
|
||||
device->timer.func = device_timer_event;
|
||||
device->timer.fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
|
||||
device->timer.fd = spa_system_timerfd_create(monitor->main_system,
|
||||
CLOCK_MONOTONIC, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK);
|
||||
device->timer.mask = SPA_IO_IN;
|
||||
device->timer.rmask = 0;
|
||||
spa_loop_add_source(monitor->main_loop, &device->timer);
|
||||
|
|
@ -573,7 +574,7 @@ static int device_start_timer(struct spa_bt_device *device)
|
|||
ts.it_value.tv_nsec = 0;
|
||||
ts.it_interval.tv_sec = 0;
|
||||
ts.it_interval.tv_nsec = 0;
|
||||
timerfd_settime(device->timer.fd, 0, &ts, NULL);
|
||||
spa_system_timerfd_settime(monitor->main_system, device->timer.fd, 0, &ts, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -591,8 +592,8 @@ static int device_stop_timer(struct spa_bt_device *device)
|
|||
ts.it_value.tv_nsec = 0;
|
||||
ts.it_interval.tv_sec = 0;
|
||||
ts.it_interval.tv_nsec = 0;
|
||||
timerfd_settime(device->timer.fd, 0, &ts, NULL);
|
||||
close(device->timer.fd);
|
||||
spa_system_timerfd_settime(monitor->main_system, device->timer.fd, 0, &ts, NULL);
|
||||
spa_system_close(monitor->main_system, device->timer.fd);
|
||||
device->timer.data = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -2258,6 +2259,9 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
case SPA_TYPE_INTERFACE_Loop:
|
||||
this->main_loop = support[i].data;
|
||||
break;
|
||||
case SPA_TYPE_INTERFACE_System:
|
||||
this->main_system = support[i].data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (this->dbus == NULL) {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@
|
|||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/timerfd.h>
|
||||
|
||||
#include <jack/jack.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@
|
|||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/timerfd.h>
|
||||
|
||||
#include <jack/jack.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ static int impl_clear(struct spa_handle *handle)
|
|||
|
||||
if (this->have_source) {
|
||||
spa_loop_remove_source(this->source.loop, &this->source);
|
||||
close(this->source.fd);
|
||||
spa_system_close(this->system, this->source.fd);
|
||||
this->have_source = false;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -627,7 +627,7 @@ static void loop_destroy_source(void *object, struct spa_source *source)
|
|||
loop_remove_source(impl->impl, source);
|
||||
|
||||
if (source->fd != -1 && impl->close) {
|
||||
close(source->fd);
|
||||
spa_system_close(impl->impl->system, source->fd);
|
||||
source->fd = -1;
|
||||
}
|
||||
spa_list_insert(&impl->impl->destroy_list, &impl->link);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@
|
|||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/timerfd.h>
|
||||
|
||||
#include <spa/support/plugin.h>
|
||||
#include <spa/support/log.h>
|
||||
|
|
@ -80,6 +79,7 @@ struct impl {
|
|||
|
||||
struct spa_log *log;
|
||||
struct spa_loop *data_loop;
|
||||
struct spa_system *data_system;
|
||||
|
||||
uint64_t info_all;
|
||||
struct spa_node_info info;
|
||||
|
|
@ -205,7 +205,8 @@ static void set_timer(struct impl *this, bool enabled)
|
|||
this->timerspec.it_value.tv_sec = 0;
|
||||
this->timerspec.it_value.tv_nsec = 0;
|
||||
}
|
||||
timerfd_settime(this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
|
||||
spa_system_timerfd_settime(this->data_system,
|
||||
this->timer_source.fd, SPA_FD_TIMER_ABSTIME, &this->timerspec, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -214,7 +215,8 @@ static inline void read_timer(struct impl *this)
|
|||
uint64_t expirations;
|
||||
|
||||
if (this->callbacks.funcs || this->props.live) {
|
||||
if (read(this->timer_source.fd, &expirations, sizeof(uint64_t)) != sizeof(uint64_t))
|
||||
if (spa_system_timerfd_read(this->data_system,
|
||||
this->timer_source.fd, &expirations) < 0)
|
||||
perror("read timerfd");
|
||||
}
|
||||
}
|
||||
|
|
@ -704,7 +706,7 @@ static int impl_clear(struct spa_handle *handle)
|
|||
|
||||
if (this->data_loop)
|
||||
spa_loop_remove_source(this->data_loop, &this->timer_source);
|
||||
close(this->timer_source.fd);
|
||||
spa_system_close(this->data_system, this->timer_source.fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -736,10 +738,17 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
this = (struct impl *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (support[i].type == SPA_TYPE_INTERFACE_Log)
|
||||
switch (support[i].type) {
|
||||
case SPA_TYPE_INTERFACE_Log:
|
||||
this->log = support[i].data;
|
||||
else if (support[i].type == SPA_TYPE_INTERFACE_DataLoop)
|
||||
break;
|
||||
case SPA_TYPE_INTERFACE_DataLoop:
|
||||
this->data_loop = support[i].data;
|
||||
break;
|
||||
case SPA_TYPE_INTERFACE_DataSystem:
|
||||
this->data_system = support[i].data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
spa_hook_list_init(&this->hooks);
|
||||
|
|
@ -762,7 +771,7 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
|
||||
this->timer_source.func = on_input;
|
||||
this->timer_source.data = this;
|
||||
this->timer_source.fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
|
||||
this->timer_source.fd = spa_system_timerfd_create(this->data_system, CLOCK_MONOTONIC, SPA_FD_CLOEXEC);
|
||||
this->timer_source.mask = SPA_IO_IN;
|
||||
this->timer_source.rmask = 0;
|
||||
this->timerspec.it_value.tv_sec = 0;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@
|
|||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/timerfd.h>
|
||||
|
||||
#include <spa/support/plugin.h>
|
||||
#include <spa/support/log.h>
|
||||
|
|
@ -81,6 +80,7 @@ struct impl {
|
|||
|
||||
struct spa_log *log;
|
||||
struct spa_loop *data_loop;
|
||||
struct spa_system *data_system;
|
||||
|
||||
uint64_t info_all;
|
||||
struct spa_node_info info;
|
||||
|
|
@ -223,7 +223,8 @@ static void set_timer(struct impl *this, bool enabled)
|
|||
this->timerspec.it_value.tv_sec = 0;
|
||||
this->timerspec.it_value.tv_nsec = 0;
|
||||
}
|
||||
timerfd_settime(this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
|
||||
spa_system_timerfd_settime(this->data_system,
|
||||
this->timer_source.fd, SPA_FD_TIMER_ABSTIME, &this->timerspec, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -232,7 +233,8 @@ static inline void read_timer(struct impl *this)
|
|||
uint64_t expirations;
|
||||
|
||||
if (this->callbacks.funcs || this->props.live) {
|
||||
if (read(this->timer_source.fd, &expirations, sizeof(uint64_t)) != sizeof(uint64_t))
|
||||
if (spa_system_timerfd_read(this->data_system,
|
||||
this->timer_source.fd, &expirations) < 0)
|
||||
perror("read timerfd");
|
||||
}
|
||||
}
|
||||
|
|
@ -738,7 +740,7 @@ static int impl_clear(struct spa_handle *handle)
|
|||
|
||||
if (this->data_loop)
|
||||
spa_loop_remove_source(this->data_loop, &this->timer_source);
|
||||
close(this->timer_source.fd);
|
||||
spa_system_close(this->data_system, this->timer_source.fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -770,10 +772,17 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
this = (struct impl *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (support[i].type == SPA_TYPE_INTERFACE_Log)
|
||||
switch (support[i].type) {
|
||||
case SPA_TYPE_INTERFACE_Log:
|
||||
this->log = support[i].data;
|
||||
else if (support[i].type == SPA_TYPE_INTERFACE_DataLoop)
|
||||
break;
|
||||
case SPA_TYPE_INTERFACE_DataLoop:
|
||||
this->data_loop = support[i].data;
|
||||
break;
|
||||
case SPA_TYPE_INTERFACE_DataSystem:
|
||||
this->data_system = support[i].data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
spa_hook_list_init(&this->hooks);
|
||||
|
|
@ -795,7 +804,7 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
|
||||
this->timer_source.func = on_output;
|
||||
this->timer_source.data = this;
|
||||
this->timer_source.fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
|
||||
this->timer_source.fd = spa_system_timerfd_create(this->data_system, CLOCK_MONOTONIC, SPA_FD_CLOEXEC);
|
||||
this->timer_source.mask = SPA_IO_IN;
|
||||
this->timer_source.rmask = 0;
|
||||
this->timerspec.it_value.tv_sec = 0;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@
|
|||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/timerfd.h>
|
||||
|
||||
#include <spa/support/plugin.h>
|
||||
#include <spa/support/log.h>
|
||||
|
|
@ -100,6 +99,7 @@ struct impl {
|
|||
|
||||
struct spa_log *log;
|
||||
struct spa_loop *data_loop;
|
||||
struct spa_system *data_system;
|
||||
|
||||
uint64_t info_all;
|
||||
struct spa_node_info info;
|
||||
|
|
@ -272,7 +272,8 @@ static void set_timer(struct impl *this, bool enabled)
|
|||
this->timerspec.it_value.tv_sec = 0;
|
||||
this->timerspec.it_value.tv_nsec = 0;
|
||||
}
|
||||
timerfd_settime(this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
|
||||
spa_system_timerfd_settime(this->data_system,
|
||||
this->timer_source.fd, SPA_FD_TIMER_ABSTIME, &this->timerspec, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -281,7 +282,7 @@ static void read_timer(struct impl *this)
|
|||
uint64_t expirations;
|
||||
|
||||
if (this->async || this->props.live) {
|
||||
if (read(this->timer_source.fd, &expirations, sizeof(uint64_t)) != sizeof(uint64_t))
|
||||
if (spa_system_timerfd_read(this->data_system, this->timer_source.fd, &expirations) < 0)
|
||||
perror("read timerfd");
|
||||
}
|
||||
}
|
||||
|
|
@ -834,7 +835,7 @@ static int impl_clear(struct spa_handle *handle)
|
|||
|
||||
if (this->data_loop)
|
||||
spa_loop_remove_source(this->data_loop, &this->timer_source);
|
||||
close(this->timer_source.fd);
|
||||
spa_system_close(this->data_system, this->timer_source.fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -866,10 +867,17 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
this = (struct impl *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (support[i].type == SPA_TYPE_INTERFACE_Log)
|
||||
switch (support[i].type) {
|
||||
case SPA_TYPE_INTERFACE_Log:
|
||||
this->log = support[i].data;
|
||||
else if (support[i].type == SPA_TYPE_INTERFACE_DataLoop)
|
||||
break;
|
||||
case SPA_TYPE_INTERFACE_DataLoop:
|
||||
this->data_loop = support[i].data;
|
||||
break;
|
||||
case SPA_TYPE_INTERFACE_DataSystem:
|
||||
this->data_system = support[i].data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
spa_hook_list_init(&this->hooks);
|
||||
|
|
@ -893,7 +901,7 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
|
||||
this->timer_source.func = on_output;
|
||||
this->timer_source.data = this;
|
||||
this->timer_source.fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
|
||||
this->timer_source.fd = spa_system_timerfd_create(this->data_system, CLOCK_MONOTONIC, SPA_FD_CLOEXEC);
|
||||
this->timer_source.mask = SPA_IO_IN;
|
||||
this->timer_source.rmask = 0;
|
||||
this->timerspec.it_value.tv_sec = 0;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@
|
|||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/timerfd.h>
|
||||
|
||||
#include <spa/support/plugin.h>
|
||||
#include <spa/support/log.h>
|
||||
|
|
@ -96,6 +95,7 @@ struct impl {
|
|||
|
||||
struct spa_log *log;
|
||||
struct spa_loop *data_loop;
|
||||
struct spa_system *data_system;
|
||||
|
||||
uint64_t info_all;
|
||||
struct spa_node_info info;
|
||||
|
|
@ -244,7 +244,8 @@ static void set_timer(struct impl *this, bool enabled)
|
|||
this->timerspec.it_value.tv_sec = 0;
|
||||
this->timerspec.it_value.tv_nsec = 0;
|
||||
}
|
||||
timerfd_settime(this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
|
||||
spa_system_timerfd_settime(this->data_system,
|
||||
this->timer_source.fd, SPA_FD_TIMER_ABSTIME, &this->timerspec, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -253,7 +254,7 @@ static void read_timer(struct impl *this)
|
|||
uint64_t expirations;
|
||||
|
||||
if (this->async || this->props.live) {
|
||||
if (read(this->timer_source.fd, &expirations, sizeof(uint64_t)) != sizeof(uint64_t))
|
||||
if (spa_system_timerfd_read(this->data_system, this->timer_source.fd, &expirations) < 0)
|
||||
perror("read timerfd");
|
||||
}
|
||||
}
|
||||
|
|
@ -849,7 +850,7 @@ static int impl_clear(struct spa_handle *handle)
|
|||
|
||||
if (this->data_loop)
|
||||
spa_loop_remove_source(this->data_loop, &this->timer_source);
|
||||
close(this->timer_source.fd);
|
||||
spa_system_close(this->data_system, this->timer_source.fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -881,10 +882,17 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
this = (struct impl *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (support[i].type == SPA_TYPE_INTERFACE_Log)
|
||||
switch (support[i].type) {
|
||||
case SPA_TYPE_INTERFACE_Log:
|
||||
this->log = support[i].data;
|
||||
else if (support[i].type == SPA_TYPE_INTERFACE_DataLoop)
|
||||
break;
|
||||
case SPA_TYPE_INTERFACE_DataLoop:
|
||||
this->data_loop = support[i].data;
|
||||
break;
|
||||
case SPA_TYPE_INTERFACE_DataSystem:
|
||||
this->data_system = support[i].data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
spa_hook_list_init(&this->hooks);
|
||||
|
|
@ -908,7 +916,7 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
|
||||
this->timer_source.func = on_output;
|
||||
this->timer_source.data = this;
|
||||
this->timer_source.fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
|
||||
this->timer_source.fd = spa_system_timerfd_create(this->data_system, CLOCK_MONOTONIC, SPA_FD_CLOEXEC);
|
||||
this->timer_source.mask = SPA_IO_IN;
|
||||
this->timer_source.rmask = 0;
|
||||
this->timerspec.it_value.tv_sec = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue