jack-tunnel: convert JACK time to MONOTONIC

JACK current_msec can be in MONOTONIC_RAW or MONOTONIC, depending on how
JACK was compiled (but it's likely MONOTONIC_RAW). PipeWire requires the
nsec field to be in MONOTONIC so take some time snapshots from both
clocks and apply a translation.

Also make sure we only get the nsec time from streams that exist.

See #3886
This commit is contained in:
Wim Taymans 2024-03-04 15:34:42 +01:00
parent f4e391dd41
commit f2f60ee0ec
4 changed files with 50 additions and 2 deletions

View file

@ -664,6 +664,18 @@ static int create_filters(struct impl *impl)
return res;
}
static inline uint64_t get_time_nsec(struct impl *impl)
{
uint64_t nsec;
if (impl->sink.filter)
nsec = pw_filter_get_nsec(impl->sink.filter);
else if (impl->source.filter)
nsec = pw_filter_get_nsec(impl->source.filter);
else
nsec = 0;
return nsec;
}
static void *jack_process_thread(void *arg)
{
struct impl *impl = arg;
@ -693,11 +705,22 @@ static void *jack_process_thread(void *arg)
jack_time_t next_usecs;
float period_usecs;
jack_position_t pos;
uint64_t t1, t2, t3;
int64_t d1;
jack.get_cycle_times(impl->client,
&current_frames, &current_usecs,
&next_usecs, &period_usecs);
/* convert from JACK (likely MONOTONIC_RAW) to MONOTONIC */
t1 = get_time_nsec(impl) / 1000;
t2 = jack.get_time();
t3 = get_time_nsec(impl) / 1000;
d1 = t1 + (t3 - t1) / 2 - t2;
current_usecs += d1;
next_usecs += d1;
c->nsec = current_usecs * SPA_NSEC_PER_USEC;
c->rate = SPA_FRACTION(1, impl->samplerate);
c->position = current_frames;