mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
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:
parent
81d8ecf0dc
commit
f4e391dd41
16 changed files with 53 additions and 58 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue