shithub: mcfs

Download patch

ref: abd3c14c70b91a3f4f6111c59248ab00c95a95bb
parent: f2ea43a808a7f23093b318e6400c67690f2c026b
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Tue Mar 2 10:12:40 EST 2021

matroska: ogg: set Theora granule position according to the spec

--- a/ogg.c
+++ b/ogg.c
@@ -13,6 +13,14 @@
 	u32int crc;
 	int psz, i, n, ntot, ip;
 
+	if(ctx->frid == 0 && ctx->fmt == FmtTheora && np > 0 && p->sz > 41){
+		if(memcmp(p->data, "\x80theora", 7) != 0){
+			werrstr("invalid Theora packet");
+			return -1;
+		}
+		ctx->kfgshift = ((p->data[40]<<8 | p->data[41]) >> 5) & 0x1f;
+	}
+
 	h[5] = htype;
 	h[6] = granule;
 	h[7] = granule >> 8;
@@ -131,7 +139,12 @@
 	}
 
 	if(ctx->fmt == FmtTheora){
-		gr = 0;
+		ctx->nonkey++; /* FIXME VREV 1 vs 0 diff here, to make it work with 0 */
+		if(key){
+			ctx->key += ctx->nonkey;
+			ctx->nonkey = 0;
+		}
+		gr = (uvlong)ctx->key<<ctx->kfgshift | ctx->nonkey;
 	}else{
 		gr = (ts * 48) / 1000000;
 	}
--- a/packet.h
+++ b/packet.h
@@ -30,8 +30,6 @@
 	u32int trackuid;
 	u32int fmt;
 
-	int key;
-
 	struct {
 		int width;
 		int height;
@@ -50,6 +48,9 @@
 		int n;
 	}ps[16];
 	int nps;
+	int key;
+	int nonkey;
+	int kfgshift;
 };
 
 int aacpacket(Biobuf *out, Packetctx *ctx, Packet *p, int np, uvlong ts, int key);