mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04: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
|
|
@ -148,6 +148,7 @@ static const struct spa_dict_item module_props[] = {
|
|||
struct impl {
|
||||
struct pw_context *context;
|
||||
struct pw_loop *main_loop;
|
||||
struct pw_timer_queue *timer_queue;
|
||||
|
||||
#define MODE_SINK 0
|
||||
#define MODE_SOURCE 1
|
||||
|
|
@ -194,7 +195,7 @@ struct impl {
|
|||
bool do_disconnect:1;
|
||||
bool stopping;
|
||||
|
||||
struct spa_source *timer;
|
||||
struct pw_timer timer;
|
||||
uint32_t reconnect_interval_ms;
|
||||
bool recovering;
|
||||
};
|
||||
|
|
@ -525,7 +526,7 @@ static void cleanup_streams(struct impl *impl)
|
|||
pw_stream_destroy(impl->stream);
|
||||
}
|
||||
|
||||
static void on_timer_event(void *data, uint64_t expirations)
|
||||
static void on_timer_event(void *data)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
cleanup_streams(impl);
|
||||
|
|
@ -538,13 +539,9 @@ do_schedule_recovery(struct spa_loop *loop,
|
|||
{
|
||||
struct impl *impl = user_data;
|
||||
if (impl->reconnect_interval_ms > 0) {
|
||||
struct timespec value;
|
||||
uint64_t timestamp;
|
||||
|
||||
timestamp = impl->reconnect_interval_ms * SPA_NSEC_PER_MSEC;
|
||||
value.tv_sec = timestamp / SPA_NSEC_PER_SEC;
|
||||
value.tv_nsec = timestamp % SPA_NSEC_PER_SEC;
|
||||
pw_loop_update_timer(impl->main_loop, impl->timer, &value, NULL, false);
|
||||
pw_timer_queue_add(impl->timer_queue, &impl->timer,
|
||||
NULL, impl->reconnect_interval_ms * SPA_NSEC_PER_MSEC,
|
||||
on_timer_event, impl);
|
||||
} else {
|
||||
if (impl->module)
|
||||
pw_impl_module_schedule_destroy(impl->module);
|
||||
|
|
@ -1029,8 +1026,7 @@ static void impl_destroy(struct impl *impl)
|
|||
pw_properties_free(impl->stream_props);
|
||||
pw_properties_free(impl->props);
|
||||
|
||||
if (impl->timer)
|
||||
pw_loop_destroy_source(impl->main_loop, impl->timer);
|
||||
pw_timer_queue_cancel(&impl->timer);
|
||||
|
||||
free(impl->buffer);
|
||||
free(impl);
|
||||
|
|
@ -1144,6 +1140,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);
|
||||
|
||||
spa_ringbuffer_init(&impl->ring);
|
||||
impl->buffer = calloc(1, RINGBUFFER_SIZE);
|
||||
|
|
@ -1165,13 +1162,6 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
|
|||
impl->reconnect_interval_ms = pw_properties_get_uint32(props,
|
||||
"reconnect.interval.ms", 0);
|
||||
|
||||
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");
|
||||
goto error;
|
||||
}
|
||||
|
||||
impl->latency_msec = pw_properties_get_uint32(props, "pulse.latency", DEFAULT_LATENCY_MSEC);
|
||||
|
||||
if (pw_properties_get(props, PW_KEY_NODE_VIRTUAL) == NULL)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue