shithub: aacenc

Download patch

ref: 0826f2e98f06d05257d66b9bd7368eda5802a534
parent: dc611893e30212f046b5e8b82a0f0700e1cfc361
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sat Aug 21 18:20:42 EDT 2021

add -b option to disable buffering and instead flush on each frame

--- a/frontend/aacenc.c
+++ b/frontend/aacenc.c
@@ -36,7 +36,7 @@
 static void
 usage(void)
 {
-	fprint(2, "usage: %s [-c CHAN] [-q QUANT] [-r RATE] [-t low|main|ltp] [-B BITRATE]\n", argv0);
+	fprint(2, "usage: %s [-b] [-c CHAN] [-q QUANT] [-r RATE] [-t low|main|ltp] [-B BITRATE]\n", argv0);
 	exits("usage");
 }
 
@@ -43,7 +43,7 @@
 void
 main(int argc, char **argv)
 {
-	int nch, srate, type, brate, sz, n, r, q, i;
+	int nch, srate, type, brate, sz, n, r, q, i, nobuffer;
 	ulong insamples, outsz, insz;
 	faacEncConfigurationPtr fmt;
 	u8int *obuf, ph[7+1+4+8];
@@ -53,6 +53,7 @@
 	uvlong ns;
 	char *s;
 
+	nobuffer = 0;
 	brate = 0;
 	srate = 44100;
 	nch = 2;
@@ -59,6 +60,9 @@
 	type = LOW;
 	q = 0;
 	ARGBEGIN{
+	case 'b':
+		nobuffer = 1;
+		break;
 	case 'B':
 		if((brate = atoi(EARGF(usage()))) < 0)
 			sysfatal("invalid bitrate %d", brate);
@@ -148,9 +152,12 @@
 			ns = 0;
 			if(Bwrite(&out, ph, sizeof(ph)) < 0)
 				break;
+			Bflush(&out);
 		}
 		if(Bwrite(&out, obuf, sz) < 0)
 			break;
+		if(nobuffer)
+			Bflush(&out);
 	}
 	Bflush(&out);