From 5d711ebbda9c81120a11420fc0d2862d85747252 Mon Sep 17 00:00:00 2001 From: Doug Kelly Date: Mon, 18 Jan 2021 15:58:11 -0800 Subject: [PATCH] mac-capture: Adjust mHostTime to milliseconds The timestamp returned by mHostTime in the AudioTimeStamp structure is the current timestamp equivalent to mach_absolute_time(), which is relative to the machine's time base. In order to convert this to milliseconds, it's necessary to get the host's timebase with mach_timebase_info() and scale the timestamp accordingly, since the rest of the timestamp synchronization code expects the timestamp to be in milliseconds. This is effectively equivalent to the code which was previously in libobs/util/platform-coca.m, but must be applied here instead. --- plugins/mac-capture/mac-audio.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plugins/mac-capture/mac-audio.c b/plugins/mac-capture/mac-audio.c index 358f5ea8d..b2c22c0cd 100644 --- a/plugins/mac-capture/mac-audio.c +++ b/plugins/mac-capture/mac-audio.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -348,7 +349,16 @@ static OSStatus input_callback(void *data, audio.speakers = ca->speakers; audio.format = ca->format; audio.samples_per_sec = ca->sample_rate; - audio.timestamp = ts_data->mHostTime; + static double factor = 0.; + static mach_timebase_info_data_t info = {0, 0}; + if (info.numer == 0 && info.denom == 0) { + mach_timebase_info(&info); + factor = ((double)info.numer) / info.denom; + } + if (info.numer != info.denom) + audio.timestamp = (uint64_t)(factor * ts_data->mHostTime); + else + audio.timestamp = ts_data->mHostTime; obs_source_output_audio(ca->source, &audio);