提交 df6446c5 编写于 作者: H Hector Martin 提交者: Jim

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).
上级 c38daa19
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册