shithub: mcfs

Download patch

ref: 721b071f9ec209ead60c7c0ddf993e6e495f8b24
parent: f7bc176c6bb458b631d7792dd049aaa103eeeca4
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Feb 18 10:21:14 EST 2021

ogg: simplify

--- a/ogg.c
+++ b/ogg.c
@@ -75,7 +75,7 @@
 {
 	/*                     magic                            vendor len   list len */
 	u8int opuscomment[] = {'O','p','u','s','T','a','g','s', 0,0,0,0,     0,0,0,0};
-	int r, i, nsg, dsz, total;
+	int i, nsg, dsz, total;
 	u8int *d;
 	u64int gr;
 	int sgszs[4];
@@ -84,57 +84,50 @@
 	ts += ctx->seekpreroll - ctx->discardpad;
 	gr = (ts * 48) / 1000000;
 
-	r = 0;
 	if(ctx->frid == 0){ /* first packet? */
 		d = ctx->codec.priv.data;
 		dsz = ctx->codec.priv.sz;
 
+		if(dsz < 1){
+			werrstr("codec private data missing");
+			goto err;
+		}
+
 		/* id/codec setup header always goes first */
-		if(dsz > 0){ /* if we have codec setup data, write it */
-			if(ctx->fmt == FmtVorbis || ctx->fmt == FmtTheora){
-				i = *d++;
-				dsz--;
-				for(nsg = 0, total = 0; i > 0 && dsz > 0; total += sgszs[nsg], nsg++){
-					sgszs[nsg] = 0;
-					do{
-						sgszs[nsg] += *d;
-						dsz--;
-						i--;
-					}while(*d++ == 0xff);
-				}
-				if(total > dsz){
-					werrstr("setup data out of bounds");
-					goto err;
-				}
-				for(i = 0; i < nsg && dsz > 0; d += sgszs[i], dsz -= sgszs[i], i++){
-					onep.data = d;
-					onep.sz = sgszs[i];
-					if(packet(out, ctx, i == 0 ? 2 : 0, &onep, 1, 0) != 0)
-						goto err;
-				}
-				if(dsz > 0){
-					onep.data = d;
-					onep.sz = dsz;
-					r = packet(out, ctx, 0, &onep, 1, 0);
-				}
-			}else{
+		if(ctx->fmt == FmtVorbis || ctx->fmt == FmtTheora){
+			i = *d++;
+			dsz--;
+			for(nsg = 0, total = 0; i > 0 && dsz > 0; total += sgszs[nsg], nsg++){
+				sgszs[nsg] = 0;
+				do{
+					sgszs[nsg] += *d;
+					dsz--;
+					i--;
+				}while(*d++ == 0xff);
+			}
+			if(total > dsz){
+				werrstr("setup data out of bounds");
+				goto err;
+			}
+			for(i = 0; i < nsg && dsz > 0; d += sgszs[i], dsz -= sgszs[i], i++){
 				onep.data = d;
-				onep.sz = dsz;
-				r = packet(out, ctx, 2, &onep, 1, 0);
+				onep.sz = sgszs[i];
+				if(packet(out, ctx, i == 0 ? 2 : 0, &onep, 1, 0) != 0)
+					goto err;
 			}
 		}
-		/* otherwise let's hope the first packet has that data itself */
-		if(r != 0)
-			goto err;
-
-		/* comment */
-		if(ctx->fmt == FmtOpus){
+		if(dsz > 0){ /* either leftovers or other codecs, write as is */
+			onep.data = d;
+			onep.sz = dsz;
+			if(packet(out, ctx, 2, &onep, 1, 0) != 0)
+				goto err;
+		}
+		if(ctx->fmt == FmtOpus){ /* Opus requires a comment */
 			onep.data = opuscomment;
 			onep.sz = sizeof(opuscomment);
-			r = packet(out, ctx, 0, &onep, 1, 0);
+			if(packet(out, ctx, 0, &onep, 1, 0) != 0)
+				goto err;
 		}
-		if(r != 0)
-			goto err;
 	}
 
 	if(np > 0 && packet(out, ctx, ctx->discardpad ? 4 : 0, p, np, gr) != 0)