mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
context: use clock time as rttime when using our loop
This commit is contained in:
parent
520c2a0e16
commit
3255bc8eae
4 changed files with 46 additions and 7 deletions
|
|
@ -1691,7 +1691,7 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *
|
||||||
if (p)
|
if (p)
|
||||||
pw_properties_update_proplist(props, p);
|
pw_properties_update_proplist(props, p);
|
||||||
|
|
||||||
if (pa_mainloop_api_is_pipewire(mainloop))
|
if (pa_mainloop_api_is_our_api(mainloop))
|
||||||
loop = mainloop->userdata;
|
loop = mainloop->userdata;
|
||||||
else {
|
else {
|
||||||
loop = pw_loop_new(NULL);
|
loop = pw_loop_new(NULL);
|
||||||
|
|
@ -2196,7 +2196,7 @@ pa_time_event* pa_context_rttime_new(PA_CONST pa_context *c, pa_usec_t usec, pa_
|
||||||
if (usec == PA_USEC_INVALID)
|
if (usec == PA_USEC_INVALID)
|
||||||
return c->mainloop->time_new(c->mainloop, NULL, cb, userdata);
|
return c->mainloop->time_new(c->mainloop, NULL, cb, userdata);
|
||||||
|
|
||||||
pa_timeval_store(&tv, usec);
|
pa_timeval_rtstore(&tv, usec, !c->fallback_loop);
|
||||||
|
|
||||||
return c->mainloop->time_new(c->mainloop, &tv, cb, userdata);
|
return c->mainloop->time_new(c->mainloop, &tv, cb, userdata);
|
||||||
}
|
}
|
||||||
|
|
@ -2213,7 +2213,7 @@ void pa_context_rttime_restart(PA_CONST pa_context *c, pa_time_event *e, pa_usec
|
||||||
if (usec == PA_USEC_INVALID)
|
if (usec == PA_USEC_INVALID)
|
||||||
c->mainloop->time_restart(e, NULL);
|
c->mainloop->time_restart(e, NULL);
|
||||||
else {
|
else {
|
||||||
pa_timeval_store(&tv, usec);
|
pa_timeval_rtstore(&tv, usec, !c->fallback_loop);
|
||||||
c->mainloop->time_restart(e, &tv);
|
c->mainloop->time_restart(e, &tv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -506,10 +506,12 @@ struct pa_operation
|
||||||
void *state_userdata;
|
void *state_userdata;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool pa_mainloop_api_is_pipewire(pa_mainloop_api *api);
|
bool pa_mainloop_api_is_our_api(pa_mainloop_api *api);
|
||||||
|
|
||||||
#define PA_TIMEVAL_RTCLOCK ((time_t) (1LU << 30))
|
#define PA_TIMEVAL_RTCLOCK ((time_t) (1LU << 30))
|
||||||
struct timeval* pa_rtclock_from_wallclock(struct timeval *tv);
|
struct timeval* pa_rtclock_from_wallclock(struct timeval *tv);
|
||||||
|
struct timeval* pa_rtclock_to_wallclock(struct timeval *tv);
|
||||||
|
struct timeval* pa_timeval_rtstore(struct timeval *tv, pa_usec_t v, bool rtclock);
|
||||||
|
|
||||||
pa_operation *pa_operation_new(pa_context *c, pa_stream *s, pa_operation_cb_t cb, size_t userdata_size);
|
pa_operation *pa_operation_new(pa_context *c, pa_stream *s, pa_operation_cb_t cb, size_t userdata_size);
|
||||||
void pa_operation_done(pa_operation *o);
|
void pa_operation_done(pa_operation *o);
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ static void set_timer(pa_time_event *ev, const struct timeval *tv)
|
||||||
} else {
|
} else {
|
||||||
struct timeval ttv = *tv;
|
struct timeval ttv = *tv;
|
||||||
|
|
||||||
if (!!(ttv.tv_usec & PA_TIMEVAL_RTCLOCK))
|
if ((ttv.tv_usec & PA_TIMEVAL_RTCLOCK) != 0)
|
||||||
ttv.tv_usec &= ~PA_TIMEVAL_RTCLOCK;
|
ttv.tv_usec &= ~PA_TIMEVAL_RTCLOCK;
|
||||||
else
|
else
|
||||||
pa_rtclock_from_wallclock(&ttv);
|
pa_rtclock_from_wallclock(&ttv);
|
||||||
|
|
@ -292,9 +292,10 @@ pa_mainloop *pa_mainloop_new(void)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pa_mainloop_api_is_pipewire(pa_mainloop_api *api)
|
bool pa_mainloop_api_is_our_api(pa_mainloop_api *api)
|
||||||
{
|
{
|
||||||
return api && api->io_new == api_io_new;
|
pa_assert(api);
|
||||||
|
return api->io_new == api_io_new;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
|
|
@ -494,3 +495,4 @@ void pa_mainloop_api_once(pa_mainloop_api* m, void (*callback)(pa_mainloop_api *
|
||||||
pa_assert_se(e = m->defer_new(m, once_callback, i));
|
pa_assert_se(e = m->defer_new(m, once_callback, i));
|
||||||
m->defer_set_destroy(e, free_callback);
|
m->defer_set_destroy(e, free_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,3 +69,38 @@ struct timeval* pa_rtclock_from_wallclock(struct timeval *tv)
|
||||||
return tv;
|
return tv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct timeval* pa_rtclock_to_wallclock(struct timeval *tv)
|
||||||
|
{
|
||||||
|
struct timeval wc_now, rt_now;
|
||||||
|
|
||||||
|
pa_assert(tv);
|
||||||
|
|
||||||
|
pa_gettimeofday(&wc_now);
|
||||||
|
pa_rtclock_get(&rt_now);
|
||||||
|
|
||||||
|
if (pa_timeval_cmp(&rt_now, tv) < 0)
|
||||||
|
pa_timeval_add(&wc_now, pa_timeval_diff(tv, &rt_now));
|
||||||
|
else
|
||||||
|
pa_timeval_sub(&wc_now, pa_timeval_diff(&rt_now, tv));
|
||||||
|
|
||||||
|
*tv = wc_now;
|
||||||
|
|
||||||
|
return tv;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct timeval* pa_timeval_rtstore(struct timeval *tv, pa_usec_t v, bool rtclock)
|
||||||
|
{
|
||||||
|
pa_assert(tv);
|
||||||
|
|
||||||
|
if (v == PA_USEC_INVALID)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
pa_timeval_store(tv, v);
|
||||||
|
|
||||||
|
if (rtclock)
|
||||||
|
tv->tv_usec |= PA_TIMEVAL_RTCLOCK;
|
||||||
|
else
|
||||||
|
pa_rtclock_to_wallclock(tv);
|
||||||
|
|
||||||
|
return tv;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue