shithub: mcfs

Download patch

ref: a224b6326320150b23fb6fa641eee8da3a2e1dc4
parent: a076ccdfc2ed52cebd6d3db15644228826b0db67
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Sep 10 11:41:17 EDT 2020

use stts to provide IVF timestamps

--- a/iso.c
+++ b/iso.c
@@ -2,11 +2,14 @@
 #include <libc.h>
 #include <bio.h>
 
+#define MIN(a,b) ((a)<=(b)?(a):(b))
+
 typedef struct Audio Audio;
 typedef struct Box Box;
 typedef struct Moof Moof;
 typedef struct RunSample RunSample;
 typedef struct SampleToChunk SampleToChunk;
+typedef struct TimeToSample TimeToSample;
 typedef struct Track Track;
 typedef struct Video Video;
 
@@ -103,7 +106,7 @@
 
 		struct {
 			u32int entrycount;
-			/* FIXME entries */
+			TimeToSample *entry;
 		}stts;
 
 		struct {
@@ -162,6 +165,11 @@
 	u32int sdt;
 };
 
+struct TimeToSample {
+	u32int samplecount;
+	u32int sampledelta;
+};
+
 enum {
 	HandlerVideo = 0x76696465u,
 	HandlerAudio = 0x736f756eu,
@@ -242,6 +250,9 @@
 	SampleToChunk *stc;
 	u32int numstc;
 
+	TimeToSample *tts;
+	u32int numtts;
+
 	Moof *moof;
 	int nmoof;
 
@@ -281,6 +292,21 @@
 	return fmtstrcpy(f, t);
 }
 
+static u32int
+tts(Track *t, u32int s)
+{
+	u32int dt, n, e;
+
+	dt = 0;
+	for(e = 0; e < t->numtts && s > 0; e++){
+		n = MIN(t->tts[e].samplecount, s);
+		dt += t->tts[e].sampledelta * n;
+		s -= n;
+	}
+
+	return dt;
+}
+
 static void
 printbox(Box *b)
 {
@@ -391,6 +417,11 @@
 		}
 	}else if(b->type == BoxStts){
 		Bprint(&stderr, "\t%.*sentry_count\t%ud\n", dind, ind, b->stts.entrycount);
+		for(u = 0; dflag > 1 && u < b->stts.entrycount; u++){
+			Bprint(&stderr, "\t%.*sentry[%zd]\n", dind, ind, u);
+			Bprint(&stderr, "\t\t%.*ssample_count\t%ud\n", dind, ind, b->stts.entry[u].samplecount);
+			Bprint(&stderr, "\t\t%.*ssamples_delta\t%ud\n", dind, ind, b->stts.entry[u].sampledelta);
+		}
 	}else if(b->type == BoxStss){
 		Bprint(&stderr, "\t%.*sentry_count\t%ud\n", dind, ind, b->stss.entrycount);
 	}else if(b->type == BoxStsc){
@@ -534,8 +565,8 @@
 						werrstr("eof");
 						break;
 					}
-				}else if(t->video.format == FmtAv01){
-					ts = 0;
+				}else if(t->video.format != 0){ /* all video goes out as IVF */
+					ts = tts(t, sample);
 					frame[0] = samplesz;
 					frame[1] = samplesz >> 8;
 					frame[2] = samplesz >> 16;
@@ -996,7 +1027,15 @@
 	}else if(b->type == BoxStts){
 		eBread(4, "entry_count");
 		b->stts.entrycount = bu32(d);
-		/* FIXME not reading actual entries here */
+		b->stts.entry = calloc(b->stts.entrycount, sizeof(TimeToSample));
+		for(u = 0; u < b->stts.entrycount; u++){
+			eBread(4, "sample_count");
+			b->stts.entry[u].samplecount = bu32(d);
+			eBread(4, "sample_delta");
+			b->stts.entry[u].sampledelta = bu32(d);
+		}
+		track.tts = b->stts.entry;
+		track.numtts = b->stts.entrycount;
 		printbox(b);
 	}else if(b->type == BoxStss){
 		eBread(4, "entry_count");