~ft/treason

d8a3992830fe6e04942a14c279aa9faac594dce2 — Sigrid Solveig Haflínudóttir 1 year, 1 month ago febd271
stream: shift timestamps so the first one is always 0
2 files changed, 13 insertions(+), 1 deletions(-)

M stream.c
M stream.h
M stream.c => stream.c +10 -1
@@ 30,6 30,7 @@ Sopen(char *filename, int *num)
			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 @@ Sclose(Stream *s)
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;
}

M stream.h => stream.h +3 -0
@@ 73,12 73,15 @@ struct Streaminfo {
	char info[128];
};

#define Zt₀ (~0ULL)

struct Stream {
	Streaminfo;
	Streamops ops;

	/* private stuff */
	uvlong timestamp;
	uvlong t₀;
	void *b;
	u8int *buf;
	int bufsz;