From ca9cb0ca289575e0224e5359046ee924e46e710d Mon Sep 17 00:00:00 2001
From: Jari Vetoniemi <mailroxas@gmail.com>
Date: Sun, 22 Jan 2017 22:26:37 +0200
Subject: Synchronize to single base time

Audio / Video can now delay by any amount but still be in sync.
---
 glcapture.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/glcapture.c b/glcapture.c
index 1907ef6..6df1d7d 100644
--- a/glcapture.c
+++ b/glcapture.c
@@ -93,9 +93,9 @@ struct frame_info {
 struct fifo {
    struct {
       struct frame_info info;
-      uint64_t base;
       bool ready;
    } stream[STREAM_LAST];
+   uint64_t base;
    size_t size;
    int fd;
    bool created;
@@ -196,13 +196,14 @@ write_data_unsafe(struct fifo *fifo, const struct frame_info *info, const void *
 
       WARNX("stream ready, writing headers");
       write(fifo->fd, header, (p + 1) - header);
+      fifo->base = get_time_ns();
    }
 
-   if (!fifo->stream[info->stream].base)
-      fifo->stream[info->stream].base = info->ts;
+   if (fifo->base > info->ts)
+      return;
 
    const uint64_t rate = 1e9 / (info->stream == STREAM_VIDEO ? info->video.fps : info->audio.rate);
-   const uint64_t pts = (info->ts - fifo->stream[info->stream].base) / rate;
+   const uint64_t pts = (info->ts - fifo->base) / rate;
 
    uint8_t frame[] = {
       info->stream,
-- 
cgit v1.2.3-70-g09d2