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.
This commit is contained in:
cinap_lenrek 2014-03-26 18:39:58 +01:00
parent b964e60a49
commit 1641d9908b

View file

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