git: 9front

Download patch

ref: 70a13aa5cc5c2bcaa09b55774d4f29e4ba429324
parent: 11a51d0314aa45fbebccb995da4c670c7f7f407e
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Mar 26 14:39:58 EDT 2014

audio/oggdec: wait for pcmconv child process to exit

we have to wait for the pcmconv process to exit before
exiting yourselfs because otherwise pcmconv could
keep /dev/audio open and prevent further reopens for
a short period of time.

--- a/sys/src/cmd/audio/oggdec/oggdec.c
+++ b/sys/src/cmd/audio/oggdec/oggdec.c
@@ -26,15 +26,18 @@
 #include <stdlib.h>
 #include <math.h>
 #include <vorbis/codec.h>
+#include <sys/wait.h>
 
+static int ifd = -1;
+
 static void
 output(float **pcm, int samples, vorbis_info *vi)
 {
 	static int rate, chans;
 	static unsigned char *buf;
-	static int nbuf, ifd = -1;
+	static int nbuf;
 	unsigned char *p;
-	int i, j, n, v;
+	int i, j, n, v, status;
 	float *s;
 
 	/* start converter if format changed */
@@ -46,8 +49,10 @@
 		chans = vi->channels;
 		sprintf(fmt, "f%dr%dc%d", sizeof(float)*8, rate, chans);
 
-		if(ifd >= 0)
+		if(ifd >= 0){
 			close(ifd);
+			wait(&status);
+		}
 		if(pipe(pfd) < 0){
 			fprintf(stderr, "Error creating pipe\n");
 			exit(1);
@@ -105,8 +110,8 @@
   
   char *buffer;
   int  bytes;
+  int  status;
 
-
   /********** Decode setup ************/
 
   ogg_sync_init(&oy); /* Now we can read pages */
@@ -291,7 +296,12 @@
 
   /* OK, clean up the framer */
   ogg_sync_clear(&oy);
-  
+
+  if(ifd >= 0){
+    close(ifd);
+    wait(&status);
+  }
+
   fprintf(stderr,"Done.\n");
   return(0);
 }
--