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.
This commit is contained in:
parent
4ab5a3bea1
commit
5d711ebbda
@ -5,6 +5,7 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include <obs-module.h>
|
||||
#include <mach/mach_time.h>
|
||||
#include <util/threading.h>
|
||||
#include <util/c99defs.h>
|
||||
#include <util/apple/cfstring-utils.h>
|
||||
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user