stream: add pw_stream_get_nsec() to get current time

Make a method to get the current time to compare agains the pw_time-now
field. This is currently CLOCK_MONOTONIC but make this into a method
so that we can more easily change it later.
This commit is contained in:
Wim Taymans 2024-03-04 12:59:26 +01:00
parent 81d8ecf0dc
commit f4e391dd41
16 changed files with 53 additions and 58 deletions

View file

@ -679,13 +679,6 @@ static int create_filters(struct impl *impl)
return res;
}
static inline uint64_t get_time_ns(void)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return SPA_TIMESPEC_TO_NSEC(&ts);
}
static void *ffado_process_thread(void *arg)
{
struct impl *impl = arg;
@ -696,7 +689,7 @@ static void *ffado_process_thread(void *arg)
ffado_wait_response response;
response = ffado_streaming_wait(impl->dev);
nsec = get_time_ns();
nsec = pw_filter_get_nsec(impl->source.filter);
switch (response) {
case ffado_wait_ok:

View file

@ -608,13 +608,6 @@ static int create_filters(struct impl *impl)
}
static inline uint64_t get_time_ns(void)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return SPA_TIMESPEC_TO_NSEC(&ts);
}
static void
on_data_io(void *data, int fd, uint32_t mask)
{
@ -634,7 +627,7 @@ on_data_io(void *data, int fd, uint32_t mask)
if (nframes == 0)
return;
nsec = get_time_ns();
nsec = pw_filter_get_nsec(impl->source.filter);
if (!impl->done) {
impl->pw_xrun++;

View file

@ -325,11 +325,16 @@ static void clear_sdp_info(struct sdp_info *info)
spa_zero(*info);
}
static void session_touch(struct session *sess)
static uint64_t get_time_nsec(struct impl *impl)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
sess->timestamp = SPA_TIMESPEC_TO_NSEC(&ts);
return SPA_TIMESPEC_TO_NSEC(&ts);
}
static void session_touch(struct session *sess)
{
sess->timestamp = get_time_nsec(sess->impl);
}
static void session_free(struct session *sess)
@ -791,11 +796,9 @@ static void on_timer_event(void *data, uint64_t expirations)
{
struct impl *impl = data;
struct session *sess, *tmp;
struct timespec ts;
uint64_t timestamp, interval;
clock_gettime(CLOCK_MONOTONIC, &ts);
timestamp = SPA_TIMESPEC_TO_NSEC(&ts);
timestamp = get_time_nsec(impl);
interval = impl->cleanup_interval * SPA_NSEC_PER_SEC;
update_ts_refclk(impl);

View file

@ -137,16 +137,16 @@ static int parse_journal(struct impl *impl, uint8_t *packet, uint16_t seq, uint3
static double get_time(struct impl *impl)
{
struct timespec ts;
uint64_t now;
struct spa_io_position *pos;
double t;
clock_gettime(CLOCK_MONOTONIC, &ts);
now = pw_stream_get_nsec(impl->stream);
if ((pos = impl->io_position) != NULL) {
t = pos->clock.position / (double) pos->clock.rate.denom;
t += (SPA_TIMESPEC_TO_NSEC(&ts) - pos->clock.nsec) / (double)SPA_NSEC_PER_SEC;
t += (now - pos->clock.nsec) / (double)SPA_NSEC_PER_SEC;
} else {
t = SPA_TIMESPEC_TO_NSEC(&ts);
t = now;
}
return t;
}