summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2017-02-16 00:53:53 +0200
committerJari Vetoniemi <mailroxas@gmail.com>2017-02-16 00:53:53 +0200
commita148ccbd6a8b6df3e7e7e4780820ef391e6a4e17 (patch)
treeb227d0df4e94d50d2f00e235ab1d7d7be3634f89
parent8ea6477a2c5bee6c5f294fd370aab31e358c04d4 (diff)
Apply speed hack to all clocks
Multiply the real clock instead of using MONOTONIC for everything. This means we track base of each clock.
-rw-r--r--glcapture.c25
-rw-r--r--hooks.h13
2 files changed, 20 insertions, 18 deletions
diff --git a/glcapture.c b/glcapture.c
index e90f5ca..c6fd494 100644
--- a/glcapture.c
+++ b/glcapture.c
@@ -55,7 +55,7 @@ static uint32_t TARGET_FPS = 60;
// If your target framerate is lower than game framerate set this to true (i.e. you want to record at lower fps)
static bool DROP_FRAMES = true;
-// Multiplier for system clock (MONOTONIC, RAW) can be used to make recordings of replays smoother (or speed hack)
+// Multiplier for system clock. Can be used to make recordings of replays smoother (or speed hack)
static double SPEED_HACK = 1.0;
// If your video is upside down set this to false
@@ -86,7 +86,7 @@ static const bool ENABLED_STREAMS[STREAM_LAST] = {
// "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);
+static uint64_t get_fake_time_ns(clockid_t clk_id);
static __thread GLint LAST_FRAMEBUFFER_BLIT[8];
#include "hooks.h"
@@ -158,14 +158,20 @@ buffer_resize(struct buffer *buffer, const size_t size)
}
static uint64_t
-get_time_ns(void)
+get_time_ns_clock(clockid_t clk_id)
{
struct timespec ts;
HOOK(clock_gettime);
- _clock_gettime(CLOCK_MONOTONIC, &ts);
+ _clock_gettime(clk_id, &ts);
return (uint64_t)ts.tv_sec * (uint64_t)1e9 + (uint64_t)ts.tv_nsec;
}
+static uint64_t
+get_time_ns(void)
+{
+ return get_time_ns_clock(CLOCK_MONOTONIC);
+}
+
static void
reset_fifo(struct fifo *fifo)
{
@@ -604,10 +610,11 @@ alsa_writei(snd_pcm_t *pcm, const void *buffer, const snd_pcm_uframes_t size, co
}
static uint64_t
-get_fake_time_ns(void)
+get_fake_time_ns(clockid_t clk_id)
{
- static __thread uint64_t base;
- const uint64_t current = get_time_ns();
- base = (base ? base : current);
- return base + (current - base) * SPEED_HACK;
+ static __thread uint64_t base[16];
+ assert((size_t)clk_id < ARRAY_SIZE(base));
+ const uint64_t current = get_time_ns_clock(clk_id);
+ base[clk_id] = (base[clk_id] ? base[clk_id] : current);
+ return base[clk_id] + (current - base[clk_id]) * SPEED_HACK;
}
diff --git a/hooks.h b/hooks.h
index e1c131e..e860ddd 100644
--- a/hooks.h
+++ b/hooks.h
@@ -103,15 +103,10 @@ int
clock_gettime(clockid_t clk_id, struct timespec *tp)
{
HOOK(clock_gettime);
-
- if ((clk_id == CLOCK_MONOTONIC || clk_id == CLOCK_MONOTONIC_RAW)) {
- const uint64_t fake = get_fake_time_ns();
- tp->tv_sec = fake / (uint64_t)1e9;
- tp->tv_nsec = (fake % (uint64_t)1e9);
- return 0;
- }
-
- return _clock_gettime(clk_id, tp);
+ const uint64_t fake = get_fake_time_ns(clk_id);
+ tp->tv_sec = fake / (uint64_t)1e9;
+ tp->tv_nsec = (fake % (uint64_t)1e9);
+ return 0;
}
static void*