0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 04:42:18 +02:00

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).
This commit is contained in:
Hector Martin 2020-12-13 03:15:18 +09:00 committed by Jim
parent c38daa1934
commit df6446c573

View File

@ -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;
@ -80,8 +86,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, &current_frames,
&current_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");
}
obs_source_output_audio(data->source, &out);
pthread_mutex_unlock(&data->jack_mutex);