shithub: treason

Download patch

ref: 99bb4ede6aa7d3fdcabdbe02abe1f65261127972
parent: 8c8e7fad46c62082cb46d0e394239259b9baa1a0
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Tue Sep 15 11:06:13 EDT 2020

drain audio just as before

--- a/main.c
+++ b/main.c
@@ -30,11 +30,12 @@
 		recvp(audiosync);
 		chanclose(audiosync);
 	}else{
-		for(s = x; Sread(s, &f) == 0;){
+		for(s = x; Sread(s, &f) == 0 && f.sz > 0;){
 			recvp(audiosync);
 			chanclose(audiosync);
 			write(audiofd, f.buf, f.sz);
 		}
+		close(audiofd);
 	}
 
 	sendp(audiofinished, nil);
@@ -120,7 +121,7 @@
 	char *s, *audio;
 	Stream *stream, *svideo, *saudio;
 	Decoder *d;
-	int i, j, end, done, res, nstreams;
+	int i, j, end, done, forced, res, nstreams;
 	Alt a[Cnum+1] =
 	{
 		[Cframe] = { nil, &frame, CHANRCV },
@@ -203,7 +204,7 @@
 			proccreate(audioproc, saudio, 4096);
 		}
 
-		for(done = 0; !done && !end;){
+		for(done = forced = 0; !done && !end;){
 			res = alt(a);
 			switch(res){
 			case Cframe:
@@ -220,6 +221,7 @@
 			case Ckeyboard:
 				end = key == 'q' || key == Kdel;
 				done = key == '\n';
+				forced = 1;
 				break;
 
 			case Cresize:
@@ -242,13 +244,16 @@
 			}
 		}
 
-		Sclose(saudio);
-		saudio = nil;
+		if(forced)
+			Sclose(saudio);
 		if(audiofinished != nil){
 			recvp(audiofinished);
 			chanclose(audiofinished);
 			audiofinished = nil;
 		}
+		if(!forced)
+			Sclose(saudio);
+		saudio = nil;
 
 		Dclose(d);
 		for(i = 0; i < nstreams; i++)