diff options
author | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2010-05-02 11:54:28 +0000 |
---|---|---|
committer | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2010-05-02 11:54:28 +0000 |
commit | 4b106b8af0d7d4217dd1937dd7396d46b5d73a08 (patch) | |
tree | 2d2c8d1faabfdb0c3e5b09c6572ea7165aa34e04 /usr.bin/aucat/wav.c | |
parent | 2cbb14893098445118dbd76eb3a6da56a4848f23 (diff) |
Clean up device handling code to clarify different initialization phases
and different device states. Split initialization in two phases:
first global variables are initialized then the audio hardware is opened.
Allow devices that don't support full-duplex to work in play-only or
record-only mode, even if ``-m play'' or ``-m rec'' are not specified.
Diffstat (limited to 'usr.bin/aucat/wav.c')
-rw-r--r-- | usr.bin/aucat/wav.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/usr.bin/aucat/wav.c b/usr.bin/aucat/wav.c index afe5cee7ecb..84a374cf421 100644 --- a/usr.bin/aucat/wav.c +++ b/usr.bin/aucat/wav.c @@ -295,6 +295,7 @@ wav_close(struct file *file) } } pipe_close(file); + dev_unref(); } /* @@ -317,6 +318,13 @@ wav_attach(struct wav *f, int force) dbg_puts(": attaching\n"); } #endif + + /* + * start the device (dev_getpos() and dev_attach() must + * be called on a started device + */ + dev_wakeup(0); + dev_attach(f->pipe.file.name, f->mode, rbuf, &f->hpar, f->join ? dev_opar.cmax - dev_opar.cmin + 1 : 0, wbuf, &f->hpar, f->join ? dev_ipar.cmax - dev_ipar.cmin + 1 : 0, @@ -648,8 +656,14 @@ wav_new_in(struct fileops *ops, unsigned mode, char *name, unsigned hdr, perror(name); } f = (struct wav *)pipe_new(ops, fd, name); - if (f == NULL) + if (f == NULL) { + close(fd); + return NULL; + } + if (!dev_ref()) { + close(fd); return NULL; + } if (hdr == HDR_WAV) { if (!wav_readhdr(f->pipe.fd, par, &f->startpos, &f->rbytes, &f->map)) { file_del((struct file *)f); @@ -720,8 +734,14 @@ wav_new_out(struct fileops *ops, unsigned mode, char *name, unsigned hdr, } } f = (struct wav *)pipe_new(ops, fd, name); - if (f == NULL) + if (f == NULL) { + close(fd); return NULL; + } + if (!dev_ref()) { + close(fd); + return NULL; + } if (hdr == HDR_WAV) { par->le = 1; par->sig = (par->bits <= 8) ? 0 : 1; |