shithub: mcfs

Download patch

ref: aad9511a85b15ced2fde315c693ce12a05f1f315
parent: a41e6c0c1ed77362a80443d65e8b9541a91793b6
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Tue Dec 15 12:54:51 EST 2020

ebml: tree-like debug printout

--- a/ebml.c
+++ b/ebml.c
@@ -18,6 +18,7 @@
 };
 
 static Packet packets[256];
+static vlong stack[32];
 
 int
 ebmluintb(u8int *b, int sz, vlong *out)
@@ -289,12 +290,13 @@
 int
 ebmlrun(Biobuf *f)
 {
-	int isebml, npackets, i;
+	int isebml, npackets, i, sti;
 	vlong left, id, n, sz, bufsz, track, off, packetsz, x, endtracks;
 	uvlong ts, timestamp, timestampscale;
 	uchar *buf;
 	double duration;
 	Ebml e, te;
+	Element *el;
 
 	buf = nil;
 	bufsz = 0;
@@ -307,6 +309,7 @@
 	e.tracknum = -1;
 	duration = 0;
 	ts = 0;
+	sti = 0;
 	for(isebml = 0; left != 0;){
 		if(id == EBlockDuration)
 			te.blockdur *= timestampscale;
@@ -321,14 +324,20 @@
 			werrstr("invalid ebml: %r at %#zx", off);
 			goto err;
 		}
+		while(sti > 0 && off >= stack[sti-1])
+			sti--;
+		left -= n;
 		if(dflag > 1){
-			Element *el;
-			if((el = ebmlid2elem(id)) != nil)
-				Bprint(&stderr, "%#zux\t%s\t%zd\t%zd\n", off, el->name, sz, left);
+			if((el = ebmlid2elem(id)) != nil){
+				for(i = 0; i < sti; i++)
+					Bputc(&stderr, '\t');
+				Bprint(&stderr, "%s\n", el->name);
+				if(el->type == Emaster && sti < nelem(stack))
+					stack[sti++] = off+n+sz;
+			}
 			else
-				Bprint(&stderr, "%#zux\t%#llx\t%zd\t%zd\n", off, id, sz, left);
+				Bprint(&stderr, "%#llx\n", id);
 		}
-		left -= n;
 
 		if(id == EEBML){ /* EBML comes first */
 			if(isebml != 0){