shithub: pplay

Download patch

ref: 4f2673e8f15a3e15f897a892e1a5cd2b5dde4138
parent: b538a7f7e8552f9e190bf1746361cbe6d575977a
author: qwx <qwx@sciops.net>
date: Tue Nov 22 04:17:01 EST 2022

misc fixes; somewhat successful attempt to fix ^

with large buffers, must write and read stuff back at the same time,
so either refactor the reading code or fork.  one or both of getbuf
and writebuf are buggy, ^ is only usable when audio playback is
*paused*, otherwise audio in the dot after the command gets scrambled,
don't know what's going on yet.

--- a/cmd.c
+++ b/cmd.c
@@ -481,12 +481,14 @@
 			fprint(2, "writebuf: getbuf won't feed\n");
 			return -1;
 		}
-		if((n = write(fd, p, m)) != n){
+		if((n = write(fd, p, n)) != n){
 			fprint(2, "writebuf: short write not %zd\n", n);
 			return -1;
 		}
 		m -= n;
+		d.pos += n;
 	}
+	write(fd, plentyofroom, 0);	/* close pipe */
 	return 0;
 }
 
@@ -501,6 +503,14 @@
 	sysfatal("procexec: %r");
 }
 
+static void
+wproc(void *)
+{
+	close(epfd[0]);
+	writebuf(epfd[1]);
+	close(epfd[1]);
+}
+
 static int
 pipeline(char *arg, int rr, int wr)
 {
@@ -510,12 +520,16 @@
 		sysfatal("pipe: %r");
 	if(procrfork(rc, arg, mainstacksize, RFFDG|RFNOTEG|RFNAMEG) < 0)
 		sysfatal("procrfork: %r");
-	if(wr)
-		writebuf(epfd[1]);
+	if(wr){
+		if(procrfork(wproc, nil, mainstacksize, RFFDG) < 0)
+			sysfatal("procrfork: %r");
+	}
 	close(epfd[1]);
 	if(rr){
-		if((c = readintochunks(epfd[0])) == nil)
+		if((c = readintochunks(epfd[0])) == nil){
+			close(epfd[0]);
 			return -1;
+		}
 		paste(nil, c);
 	}
 	close(epfd[0]);