shithub: treason

Download patch

ref: 312cb68c9ee1e4eb0a24b811b5baf40668089712
parent: 7fff6826ea87e9162151a6b48f4d61d0ad509c6b
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Feb 11 05:35:27 EST 2021

h264: simplify main loop even further

--- a/decoder_h264.c
+++ b/decoder_h264.c
@@ -20,7 +20,7 @@
 	uint8_t *data[3];
 
 	/* reordering */
-	SPictInfo pics[16];
+	SPictInfo pics[64];
 	int npics;
 	int lastgopremain;
 	int lastwritten;
@@ -249,42 +249,38 @@
 	d = x;
 	a = d->aux;
 	lasttimestamp = 0;
-	start = nanosec();
 	for(res = 0, framenum = 0; res >= 0 && (res = Sread(d->s, &sf)) == 0 && sf.sz > 0; framenum++){
-		if(one(a, &sf) != 0)
-			goto failed;
+		start = nanosec();
+		if((res = one(a, &sf)) != 0)
+			break;
 		sf.buf = nil;
 		sf.sz = 0;
-		if(one(a, &sf) != 0){
-failed:
-			werrstr("frame %llud: %r", framenum);
+		if((res = one(a, &sf)) != 0)
 			break;
-		}
+		d->decodetime = nanosec() - start;
 
-		if(a->data[0] != nil && sf.timestamp >= lasttimestamp){
-			d->decodetime = nanosec() - start;
+		if(a->data[0] == nil || sf.timestamp < lasttimestamp)
+			continue;
 
-			w = a->info.UsrData.sSystemBuffer.iWidth;
-			h = a->info.UsrData.sSystemBuffer.iHeight;
-			stride = a->info.UsrData.sSystemBuffer.iStride;
-			if((f = newframe(w, h, a->data, stride[0], stride[1])) != nil){
-				f->crop.left = a->ctx.sFrameCrop.iLeftOffset;
-				f->crop.top = a->ctx.sFrameCrop.iTopOffset;
-				f->crop.right = w - a->ctx.sFrameCrop.iRightOffset;
-				f->crop.bottom = h - a->ctx.sFrameCrop.iBottomOffset;
-				f->dt = (sf.timestamp - lasttimestamp) * d->timebase * 1000000000ULL;
-				lasttimestamp = sf.timestamp;
+		w = a->info.UsrData.sSystemBuffer.iWidth;
+		h = a->info.UsrData.sSystemBuffer.iHeight;
+		stride = a->info.UsrData.sSystemBuffer.iStride;
+		if((f = newframe(w, h, a->data, stride[0], stride[1])) != nil){
+			f->crop.left = a->ctx.sFrameCrop.iLeftOffset;
+			f->crop.top = a->ctx.sFrameCrop.iTopOffset;
+			f->crop.right = w - a->ctx.sFrameCrop.iRightOffset;
+			f->crop.bottom = h - a->ctx.sFrameCrop.iBottomOffset;
+			f->dt = (sf.timestamp - lasttimestamp) * d->timebase * 1000000000ULL;
+			lasttimestamp = sf.timestamp;
 
-				if(sendp(d->frames, f) < 0){
-					free(f);
-					goto done;
-				}
+			if(sendp(d->frames, f) < 0){
+				free(f);
+				goto done;
 			}
-			start = nanosec();
 		}
 	}
 	if(res != 0)
-		fprint(2, "h264: %r\n");
+		fprint(2, "h264: frame %llud: %r\n", framenum);
 
 	/* FIXME the frames are finished but there might still be left-overs */
 	resetreorder(a, 0);