diff options
author | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2008-05-28 07:36:24 +0000 |
---|---|---|
committer | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2008-05-28 07:36:24 +0000 |
commit | deb0a4be82f1e2a1111ebf91be33050466864ed4 (patch) | |
tree | e09a344430c7361862fabe4e85d16fd6e8e37897 | |
parent | c542d89ee273cfdf04e73425647f95b5c354c9ac (diff) |
if aucat is resumed (after suspend), kernel buffers are empty, thus write()
syscall succedes and consumes aucat buffers until kernel buffers are full.
If aucat buffers are smaller than kernel ones, they will underrun, and aucat
will terminate, since underruns are not handled yet.
This changes is an improvement until SIGCONT handler is implemented. The
correct approach is to add a handler for SIGCONT to: call dev_stop(), reset
all buffers, bring play and record in sync, fill play buffers and call
dev_start().
ok jakemsr
-rw-r--r-- | usr.bin/aucat/conf.h | 4 | ||||
-rw-r--r-- | usr.bin/aucat/dev_sun.c | 33 |
2 files changed, 14 insertions, 23 deletions
diff --git a/usr.bin/aucat/conf.h b/usr.bin/aucat/conf.h index ac5779d815e..0246e6f81a7 100644 --- a/usr.bin/aucat/conf.h +++ b/usr.bin/aucat/conf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.h,v 1.1 2008/05/23 07:15:46 ratchov Exp $ */ +/* $OpenBSD: conf.h,v 1.2 2008/05/28 07:36:23 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -48,7 +48,7 @@ extern int debug_level; #define MIDI_TO_ADATA(m) ((ADATA_UNIT * (m) + 64) / 127) #define DEFAULT_NFR 0x400 /* buf size in frames */ -#define DEFAULT_NBLK 0x8 /* blocks per buffer */ +#define DEFAULT_NBLK 0x2 /* blocks per buffer */ #define DEFAULT_DEVICE "/dev/audio" /* defaul device */ #endif /* !defined(CONF_H) */ diff --git a/usr.bin/aucat/dev_sun.c b/usr.bin/aucat/dev_sun.c index 47abc6f06af..951a8a484f0 100644 --- a/usr.bin/aucat/dev_sun.c +++ b/usr.bin/aucat/dev_sun.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dev_sun.c,v 1.1 2008/05/23 07:15:46 ratchov Exp $ */ +/* $OpenBSD: dev_sun.c,v 1.2 2008/05/28 07:36:23 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -108,6 +108,7 @@ dev_init(char *path, struct aparams *ipar, struct aparams *opar, int fd; int fullduplex; struct audio_info aui; + struct audio_bufinfo aubi; if (!ipar && !opar) errx(1, "%s: must at least play or record", path); @@ -140,7 +141,6 @@ dev_init(char *path, struct aparams *ipar, struct aparams *opar, */ AUDIO_INITINFO(&aui); aui.mode = 0; - aui.lowat = UINT_MAX / 2; /* will set lowat = hiwat - 1 */ if (opar) { sun_partoinfo(&aui.play, opar); aui.play.pause = 1; @@ -170,30 +170,16 @@ dev_init(char *path, struct aparams *ipar, struct aparams *opar, return -1; } if (opar) { - /* - * We _must_ ensure that write() will accept at most - * one block when it unblocks. Here is our definition - * of the block size: the minimum amount of data - * write() accepts immediately when it unblocks. If - * write() accepts more that 1 block, then this means - * that we failed to provide the first block early - * enough thus underrun happened. - * - * If we fail to ensure that lowat = hiwat - 1, then - * we will trigger the underrun detection mechanism. - * Recording doesn't use the water mark non-sense. - */ - if (aui.lowat != aui.hiwat - 1) { - warnx("%s: failed to disable lowat: hiwat = %u, " - "lowat = %u", path, aui.hiwat, aui.lowat); + if (!sun_infotopar(&aui.play, opar)) { close(fd); return -1; } - if (!sun_infotopar(&aui.play, opar)) { + if (ioctl(fd, AUDIO_GETPRINFO, &aubi) < 0) { + warn("%s: AUDIO_GETPRINFO", path); close(fd); return -1; } - *onfr = aui.play.block_size / + *onfr = aubi.blksize * aubi.hiwat / (aui.play.channels * aui.play.precision / 8); } if (ipar) { @@ -201,7 +187,12 @@ dev_init(char *path, struct aparams *ipar, struct aparams *opar, close(fd); return -1; } - *infr = aui.record.block_size / + if (ioctl(fd, AUDIO_GETRRINFO, &aubi) < 0) { + warn("%s: AUDIO_GETRRINFO", path); + close(fd); + return -1; + } + *infr = aubi.blksize * aubi.hiwat / (aui.record.channels * aui.record.precision / 8); } return fd; |