shithub: treason

Download patch

ref: d8a3992830fe6e04942a14c279aa9faac594dce2
parent: febd271a231c83b67d94e6cb2b9942edfe37e363
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Tue Aug 10 08:29:30 EDT 2021

stream: shift timestamps so the first one is always 0

--- a/stream.c
+++ b/stream.c
@@ -30,6 +30,7 @@
 			else
 				f++;
 			snprint(s->info, sizeof(s->info), "%s [%s]", ops[i].name, f);
+			s->t₀ = Zt₀;
 			return s;
 		}
 		if(failed){
@@ -57,9 +58,17 @@
 int
 Sread(Stream *s, Streamframe *f)
 {
+	int res;
+
 	if(s == nil || s->type < 0){
 		werrstr("invalid stream");
 		return -1;
 	}
-	return s->ops.read(s, f);
+	if((res = s->ops.read(s, f)) == 0){
+		if(s->t₀ == Zt₀)
+			s->t₀ = f->timestamp;
+		f->timestamp -= s->t₀;
+	}
+
+	return res;
 }
--- a/stream.h
+++ b/stream.h
@@ -73,6 +73,8 @@
 	char info[128];
 };
 
+#define Zt₀ (~0ULL)
+
 struct Stream {
 	Streaminfo;
 	Streamops ops;
@@ -79,6 +81,7 @@
 
 	/* private stuff */
 	uvlong timestamp;
+	uvlong t₀;
 	void *b;
 	u8int *buf;
 	int bufsz;