From 8985f990cb911b6c8af2f67ee96835256b74665b Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Wed, 7 Sep 2022 17:18:47 -0600 Subject: [PATCH] Switch from storing total seconds to storing deltas. This is conceptually simpler and makes the files easier to manipulate and concatenate. It also avoids a bug where we would send a large negative time when we loop for multiple playbacks. --- capture.c | 2 ++ playback.c | 8 ++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/capture.c b/capture.c index 1b0b94d..4b4d49e 100644 --- a/capture.c +++ b/capture.c @@ -73,6 +73,8 @@ int dump_event(struct timespec* start, struct input_event* event, char* type) { fprintf(stderr, "Unknown event type.\n"); return 1; } + start->tv_sec = now.tv_sec; + start->tv_nsec = now.tv_nsec; printf("%ld %ld,%s,%s\n", diff.tv_sec, diff --git a/playback.c b/playback.c index 40ad1af..4021053 100644 --- a/playback.c +++ b/playback.c @@ -51,8 +51,6 @@ int handle_keyboard(char* details, int udevice_fd) { } int handle_line(char* line, int udevice_fd) { - static time_t timer_seconds = 0; - static long timer_nanos = 0; static time_t total_seconds = 0; static long total_nanos = 0; @@ -74,8 +72,8 @@ int handle_line(char* line, int udevice_fd) { remaining.tv_sec = 0; remaining.tv_nsec = 0; - to_sleep.tv_sec = seconds - timer_seconds; - to_sleep.tv_nsec = nanos - timer_nanos; + to_sleep.tv_sec = seconds; + to_sleep.tv_nsec = nanos; if(to_sleep.tv_nsec < 0) { --to_sleep.tv_sec; to_sleep.tv_nsec += 1000000000L; @@ -102,8 +100,6 @@ int handle_line(char* line, int udevice_fd) { total_nanos -= 1000000000L; total_seconds += 1; } - timer_seconds = seconds; - timer_nanos = nanos; // printf("%ld %ld\tslept %ld %ld\n", // total_seconds, total_nanos, to_sleep.tv_sec, to_sleep.tv_nsec);