linux-jack: fix timestamp calculation
The previous calculation was completely broken, returning offset timestamps in the best case, and complete insanity in the worst case (e.g. if an xrun occurs or JACK otherwise has a glitch).master
parent
b7567f23fb
commit
a602fa8797
|
@ -61,6 +61,12 @@ static enum speaker_layout jack_channels_to_obs_speakers(uint_fast32_t channels)
|
|||
int jack_process_callback(jack_nframes_t nframes, void *arg)
|
||||
{
|
||||
struct jack_data *data = (struct jack_data *)arg;
|
||||
jack_nframes_t current_frames;
|
||||
jack_time_t current_usecs, next_usecs;
|
||||
float period_usecs;
|
||||
|
||||
uint64_t now = os_gettime_ns();
|
||||
|
||||
if (data == 0)
|
||||
return 0;
|
||||
|
||||
|
@ -78,8 +84,15 @@ int jack_process_callback(jack_nframes_t nframes, void *arg)
|
|||
}
|
||||
|
||||
out.frames = nframes;
|
||||
out.timestamp = os_gettime_ns() -
|
||||
jack_frames_to_time(data->jack_client, nframes);
|
||||
if (!jack_get_cycle_times(data->jack_client, ¤t_frames,
|
||||
¤t_usecs, &next_usecs, &period_usecs)) {
|
||||
out.timestamp = now - (int64_t)(period_usecs * 1000);
|
||||
} else {
|
||||
out.timestamp = now - util_mul_div64(nframes, 1000000000ULL,
|
||||
data->samples_per_sec);
|
||||
blog(LOG_WARNING,
|
||||
"jack_get_cycle_times error: guessing timestamp");
|
||||
}
|
||||
|
||||
/* FIXME: this function is not realtime-safe, we should do something
|
||||
* about this */
|
||||
|
|
Loading…
Reference in New Issue