ref: 79e4a5f7c126b7b655f3bb0c4bd4a537705e37b3
parent: a1e3f35842de92b526422af05360c84cf233f07f
author: Janne Grunau <janne-vlc@jannau.net>
date: Sun Jun 16 09:10:12 EDT 2019
cli: use mach_absolute_time as fallback for clock_gettime on darwin. Fixes #283 clock_gettime() is only available since MacOS X 10.12 (Sierra).
--- a/tools/dav1d.c
+++ b/tools/dav1d.c
@@ -27,6 +27,7 @@
#include "config.h"
#include "vcs_version.h"
+#include "cli_config.h"
#include <assert.h>
#include <errno.h>
@@ -44,6 +45,9 @@
#ifdef _WIN32
# include <windows.h>
#endif
+#if defined(HAVE_MACH_ABSOLUTE_TIME)
+#include <mach/mach_time.h>
+#endif
#include "dav1d/dav1d.h"
@@ -60,10 +64,14 @@
LARGE_INTEGER t;
QueryPerformanceCounter(&t);
return 1000000000 * t.QuadPart / frequency.QuadPart;
-#else
+#elif defined(HAVE_CLOCK_GETTIME)
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return 1000000000ULL * ts.tv_sec + ts.tv_nsec;
+#elif defined(HAVE_MACH_ABSOLUTE_TIME)
+ mach_timebase_info_data_t info;
+ mach_timebase_info(&info);
+ return mach_absolute_time() * info.numer / info.denom;
#endif
}
--- a/tools/meson.build
+++ b/tools/meson.build
@@ -31,16 +31,26 @@
subdir_done()
endif
+
+# Configuratin data for cli_config.h
+cli_cdata = configuration_data()
+
rt_dependency = []
if host_machine.system() != 'windows'
- if not cc.has_function('clock_gettime', prefix : '#include <time.h>', args : test_args)
+ if cc.has_function('clock_gettime', prefix : '#include <time.h>', args : test_args)
+ cli_cdata.set('HAVE_CLOCK_GETTIME', 1)
+ elif host_machine.system() == 'darwin'
+ cli_cdata.set('HAVE_MACH_ABSOLUTE_TIME', 1)
+ else
rt_dependency = cc.find_library('rt', required: false)
if not cc.has_function('clock_gettime', prefix : '#include <time.h>', args : test_args, dependencies : rt_dependency)
error('clock_gettime not found')
endif
+ cli_cdata.set('HAVE_CLOCK_GETTIME', 1)
endif
endif
+cli_config_h_target = configure_file(output: 'cli_config.h', configuration: cli_cdata)
# dav1d cli tool sources
dav1d_sources = files(
@@ -58,7 +68,7 @@
dav1d = executable('dav1d',
dav1d_sources,
- rev_target,
+ rev_target, cli_config_h_target,
link_with : libdav1d,
include_directories : [dav1d_inc_dirs],