From 1d71fee4c0ba9be181fc48a447b7287754dc9bd1 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 23 Jan 2017 11:21:51 +0200 Subject: Move out non function hook code out of hooks.h Also reorder the code a bit --- glcapture.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'glcapture.c') diff --git a/glcapture.c b/glcapture.c index 2aefb69..8db96fe 100644 --- a/glcapture.c +++ b/glcapture.c @@ -103,12 +103,23 @@ struct fifo { #define ERRX(x, y, ...) do { errx(x, "glcapture: "y, ##__VA_ARGS__); } while (0) #define WARN_ONCE(x, ...) do { static bool o = false; if (!o) { WARNX(x, ##__VA_ARGS__); o = true; } } while (0) +// "entrypoints" exposed to hooks.h static void swap_buffers(void); static void alsa_writei(snd_pcm_t *pcm, const void *buffer, const snd_pcm_uframes_t size, const char *caller); +static uint64_t get_fake_time_ns(void); #include "hooks.h" #include "glwrangle.h" +static uint64_t +get_time_ns(void) +{ + struct timespec ts; + HOOK(clock_gettime); + _clock_gettime(CLOCK_MONOTONIC, &ts); + return (uint64_t)ts.tv_sec * (uint64_t)1e9 + (uint64_t)ts.tv_nsec; +} + static void reset_fifo(struct fifo *fifo) { @@ -447,3 +458,12 @@ alsa_writei(snd_pcm_t *pcm, const void *buffer, const snd_pcm_uframes_t size, co if (alsa_get_frame_info(pcm, &info, caller)) write_data(&info, buffer, snd_pcm_frames_to_bytes(pcm, size)); } + +static uint64_t +get_fake_time_ns(void) +{ + static __thread uint64_t base; + const uint64_t current = get_time_ns(); + base = (base ? base : current); + return base + (current - base) * SPEED_HACK; +} -- cgit v1.2.3