summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2008-12-17 10:00:51 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2008-12-17 10:00:51 +0000
commit7712fa5b08b45520cf63ad2be439a1d7d4e01154 (patch)
tree183f917b60d5862114cf83ffd2290cf007e3658c
parent135d40b6c3b96dc52e67c3f5a6d505400474a877 (diff)
stop using stderr in the library, wrap all diagnostic fprintfs
so they are visible only when the DEBUG macro is #defined and SIO_DEBUG env. variable is set. requested by many, discussed with jakemsr
-rw-r--r--lib/libsndio/aucat.c32
-rw-r--r--lib/libsndio/sio_open.34
-rw-r--r--lib/libsndio/sndio.c75
-rw-r--r--lib/libsndio/sndio_priv.h18
-rw-r--r--lib/libsndio/sun.c90
5 files changed, 121 insertions, 98 deletions
diff --git a/lib/libsndio/aucat.c b/lib/libsndio/aucat.c
index 1074959a84c..d371a5b3ec2 100644
--- a/lib/libsndio/aucat.c
+++ b/lib/libsndio/aucat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aucat.c,v 1.6 2008/12/17 07:31:38 ratchov Exp $ */
+/* $OpenBSD: aucat.c,v 1.7 2008/12/17 10:00:50 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -135,12 +135,12 @@ aucat_rmsg(struct aucat_hdl *hdl)
continue;
if (errno != EAGAIN) {
hdl->sa.eof = 1;
- perror("aucat_rmsg: read");
+ DPERROR(&hdl->sa, "aucat_rmsg: read");
}
return 0;
}
if (n == 0) {
- fprintf(stderr, "aucat_rmsg: eof\n");
+ DPRINTF(&hdl->sa, "aucat_rmsg: eof\n");
hdl->sa.eof = 1;
return 0;
}
@@ -166,7 +166,7 @@ aucat_wmsg(struct aucat_hdl *hdl)
continue;
if (errno != EAGAIN) {
hdl->sa.eof = 1;
- perror("aucat_wmsg: write");
+ DPERROR(&hdl->sa, "aucat_wmsg: write");
}
return 0;
}
@@ -187,7 +187,7 @@ aucat_runmsg(struct aucat_hdl *hdl)
case AMSG_DATA:
if (hdl->rmsg.u.data.size == 0 ||
hdl->rmsg.u.data.size % hdl->rbpf) {
- fprintf(stderr, "aucat_read: bad data message\n");
+ DPRINTF(&hdl->sa, "aucat_read: bad data message\n");
hdl->sa.eof = 1;
return 0;
}
@@ -206,7 +206,7 @@ aucat_runmsg(struct aucat_hdl *hdl)
hdl->rtodo = 0xdeadbeef;
break;
default:
- fprintf(stderr, "aucat_read: unknown mesg\n");
+ DPRINTF(&hdl->sa, "aucat_read: unknown mesg\n");
hdl->sa.eof = 1;
return 0;
}
@@ -246,7 +246,7 @@ aucat_start(struct sio_hdl *sh)
hdl->rstate = STATE_MSG;
hdl->rtodo = sizeof(struct amsg);
if (fcntl(hdl->fd, F_SETFL, O_NONBLOCK) < 0) {
- perror("aucat_start: fcntl(0)");
+ DPERROR(&hdl->sa, "aucat_start: fcntl(0)");
hdl->sa.eof = 1;
return 0;
}
@@ -262,7 +262,7 @@ aucat_stop(struct sio_hdl *sh)
unsigned n, count, todo;
if (fcntl(hdl->fd, F_SETFL, 0) < 0) {
- perror("aucat_stop: fcntl(0)");
+ DPERROR(&hdl->sa, "aucat_stop: fcntl(0)");
hdl->sa.eof = 1;
return 0;
}
@@ -353,7 +353,7 @@ aucat_getpar(struct sio_hdl *sh, struct sio_par *par)
if (!aucat_rmsg(hdl))
return 0;
if (hdl->rmsg.cmd != AMSG_GETPAR) {
- fprintf(stderr, "aucat_getpar: protocol err\n");
+ DPRINTF(&hdl->sa, "aucat_getpar: protocol err\n");
hdl->sa.eof = 1;
return 0;
}
@@ -388,7 +388,7 @@ aucat_getcap(struct sio_hdl *sh, struct sio_cap *cap)
if (!aucat_rmsg(hdl))
return 0;
if (hdl->rmsg.cmd != AMSG_GETCAP) {
- fprintf(stderr, "aucat_getcap: protocol err\n");
+ DPRINTF(&hdl->sa, "aucat_getcap: protocol err\n");
hdl->sa.eof = 1;
return 0;
}
@@ -421,7 +421,7 @@ aucat_read(struct sio_hdl *sh, void *buf, size_t len)
return 0;
break;
case STATE_IDLE:
- fprintf(stderr, "aucat_read: unexpected idle\n");
+ DPRINTF(&hdl->sa, "aucat_read: unexpected idle\n");
break;
}
}
@@ -432,12 +432,12 @@ aucat_read(struct sio_hdl *sh, void *buf, size_t len)
continue;
if (errno != EAGAIN) {
hdl->sa.eof = 1;
- perror("aucat_read: read");
+ DPERROR(&hdl->sa, "aucat_read: read");
}
return 0;
}
if (n == 0) {
- fprintf(stderr, "aucat_read: eof\n");
+ DPRINTF(&hdl->sa, "aucat_read: eof\n");
hdl->sa.eof = 1;
return 0;
}
@@ -497,7 +497,7 @@ aucat_write(struct sio_hdl *sh, void *buf, size_t len)
hdl->wstate = STATE_IDLE;
break;
default:
- fprintf(stderr, "aucat_write: bad state\n");
+ DPRINTF(&hdl->sa, "aucat_write: bad state\n");
abort();
}
}
@@ -508,7 +508,7 @@ aucat_write(struct sio_hdl *sh, void *buf, size_t len)
if (len > hdl->wtodo)
len = hdl->wtodo;
if (len == 0) {
- fprintf(stderr, "aucat_write: len == 0\n");
+ DPRINTF(&hdl->sa, "aucat_write: len == 0\n");
abort();
}
while ((n = write(hdl->fd, buf, len)) < 0) {
@@ -516,7 +516,7 @@ aucat_write(struct sio_hdl *sh, void *buf, size_t len)
continue;
if (errno != EAGAIN) {
hdl->sa.eof = 1;
- perror("aucat_write: write");
+ DPERROR(&hdl->sa, "aucat_write: write");
}
return 0;
}
diff --git a/lib/libsndio/sio_open.3 b/lib/libsndio/sio_open.3
index 120bd2b90bf..6f709175108 100644
--- a/lib/libsndio/sio_open.3
+++ b/lib/libsndio/sio_open.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sio_open.3,v 1.10 2008/12/17 09:04:06 jmc Exp $
+.\" $OpenBSD: sio_open.3,v 1.11 2008/12/17 10:00:50 ratchov Exp $
.\"
.\" Copyright (c) 2007 Alexandre Ratchov <alex@caoua.org>
.\"
@@ -720,7 +720,7 @@ Path to the
socket to connect to, or the
.Xr audio 4
device to use.
-.It Ev LIBSIO_DEBUG
+.It Ev SIO_DEBUG
The debug level:
may be a value between 0 and 2.
.El
diff --git a/lib/libsndio/sndio.c b/lib/libsndio/sndio.c
index 56392d64004..39539278918 100644
--- a/lib/libsndio/sndio.c
+++ b/lib/libsndio/sndio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sndio.c,v 1.9 2008/12/17 07:31:38 ratchov Exp $ */
+/* $OpenBSD: sndio.c,v 1.10 2008/12/17 10:00:50 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -29,6 +29,8 @@
#define SIO_PAR_MAGIC 0x83b905a4
+int sio_debug_level = 0;
+
void
sio_initpar(struct sio_par *par)
{
@@ -181,7 +183,7 @@ sio_create(struct sio_hdl *hdl, struct sio_ops *ops, unsigned mode, int nbio)
#ifdef DEBUG
char *dbg;
- dbg = getenv("LIBSIO_DEBUG");
+ dbg = getenv("SIO_DEBUG");
if (!dbg || sscanf(dbg, "%u", &hdl->debug) != 1)
hdl->debug = 0;
#endif
@@ -204,11 +206,11 @@ int
sio_start(struct sio_hdl *hdl)
{
if (hdl->eof) {
- fprintf(stderr, "sio_start: eof\n");
+ DPRINTF(hdl, "sio_start: eof\n");
return 0;
}
if (hdl->started) {
- fprintf(stderr, "sio_start: already started\n");
+ DPRINTF(hdl, "sio_start: already started\n");
hdl->eof = 1;
return 0;
}
@@ -228,21 +230,20 @@ int
sio_stop(struct sio_hdl *hdl)
{
if (hdl->eof) {
- fprintf(stderr, "sio_stop: eof\n");
+ DPRINTF(hdl, "sio_stop: eof\n");
return 0;
}
if (!hdl->started) {
- fprintf(stderr, "sio_stop: not started\n");
+ DPRINTF(hdl, "sio_stop: not started\n");
hdl->eof = 1;
return 0;
}
if (!hdl->ops->stop(hdl))
return 0;
#ifdef DEBUG
- if (hdl->debug)
- fprintf(stderr,
- "libsio: polls: %llu, written = %llu, read: %llu\n",
- hdl->pollcnt, hdl->wcnt, hdl->rcnt);
+ DPRINTF(hdl,
+ "libsio: polls: %llu, written = %llu, read: %llu\n",
+ hdl->pollcnt, hdl->wcnt, hdl->rcnt);
#endif
hdl->started = 0;
return 1;
@@ -252,22 +253,22 @@ int
sio_setpar(struct sio_hdl *hdl, struct sio_par *par)
{
if (hdl->eof) {
- fprintf(stderr, "sio_setpar: eof\n");
+ DPRINTF(hdl, "sio_setpar: eof\n");
return 0;
}
if (par->__magic != SIO_PAR_MAGIC) {
- fprintf(stderr,
+ DPRINTF(hdl,
"sio_setpar: use of uninitialized sio_par structure\n");
hdl->eof = 1;
return 0;
}
if (hdl->started) {
- fprintf(stderr, "sio_setpar: already started\n");
+ DPRINTF(hdl, "sio_setpar: already started\n");
hdl->eof = 1;
return 0;
}
if (par->bufsz != (unsigned)~0) {
- fprintf(stderr, "sio_setpar: setting bufsz is deprecated\n");
+ DPRINTF(hdl, "sio_setpar: setting bufsz is deprecated\n");
par->appbufsz = par->bufsz;
}
if (par->rate != (unsigned)~0 && par->appbufsz == (unsigned)~0)
@@ -279,11 +280,11 @@ int
sio_getpar(struct sio_hdl *hdl, struct sio_par *par)
{
if (hdl->eof) {
- fprintf(stderr, "sio_getpar: eof\n");
+ DPRINTF(hdl, "sio_getpar: eof\n");
return 0;
}
if (hdl->started) {
- fprintf(stderr, "sio_getpar: already started\n");
+ DPRINTF(hdl, "sio_getpar: already started\n");
hdl->eof = 1;
return 0;
}
@@ -299,11 +300,11 @@ int
sio_getcap(struct sio_hdl *hdl, struct sio_cap *cap)
{
if (hdl->eof) {
- fprintf(stderr, "sio_getcap: eof\n");
+ DPRINTF(hdl, "sio_getcap: eof\n");
return 0;
}
if (hdl->started) {
- fprintf(stderr, "sio_getcap: already started\n");
+ DPRINTF(hdl, "sio_getcap: already started\n");
hdl->eof = 1;
return 0;
}
@@ -321,13 +322,13 @@ sio_psleep(struct sio_hdl *hdl, int event)
while (poll(&pfd, 1, -1) < 0) {
if (errno == EINTR)
continue;
- perror("sio_psleep: poll");
+ DPERROR(hdl, "sio_psleep: poll");
hdl->eof = 1;
return 0;
}
revents = sio_revents(hdl, &pfd);
if (revents & POLLHUP) {
- fprintf(stderr, "sio_psleep: hang-up\n");
+ DPRINTF(hdl, "sio_psleep: hang-up\n");
return 0;
}
if (revents & event)
@@ -344,16 +345,16 @@ sio_read(struct sio_hdl *hdl, void *buf, size_t len)
size_t todo = len;
if (hdl->eof) {
- fprintf(stderr, "sio_read: eof\n");
+ DPRINTF(hdl, "sio_read: eof\n");
return 0;
}
if (!hdl->started || !(hdl->mode & SIO_REC)) {
- fprintf(stderr, "sio_read: recording not started\n");
+ DPRINTF(hdl, "sio_read: recording not started\n");
hdl->eof = 1;
return 0;
}
if (todo == 0) {
- fprintf(stderr, "sio_read: zero length read ignored\n");
+ DPRINTF(hdl, "sio_read: zero length read ignored\n");
return 0;
}
while (todo > 0) {
@@ -367,7 +368,9 @@ sio_read(struct sio_hdl *hdl, void *buf, size_t len)
}
data += n;
todo -= n;
+#ifdef DEBUG
hdl->rcnt += n;
+#endif
}
return len - todo;
}
@@ -387,16 +390,16 @@ sio_write(struct sio_hdl *hdl, void *buf, size_t len)
#endif
if (hdl->eof) {
- fprintf(stderr, "sio_write: eof\n");
+ DPRINTF(hdl, "sio_write: eof\n");
return 0;
}
if (!hdl->started || !(hdl->mode & SIO_PLAY)) {
- fprintf(stderr, "sio_write: playback not started\n");
+ DPRINTF(hdl, "sio_write: playback not started\n");
hdl->eof = 1;
return 0;
}
if (todo == 0) {
- fprintf(stderr, "sio_write: zero length write ignored\n");
+ DPRINTF(hdl, "sio_write: zero length write ignored\n");
return 0;
}
while (todo > 0) {
@@ -410,17 +413,19 @@ sio_write(struct sio_hdl *hdl, void *buf, size_t len)
}
data += n;
todo -= n;
+#ifdef DEBUG
hdl->wcnt += n;
+#endif
}
#ifdef DEBUG
if (hdl->debug >= 2) {
gettimeofday(&tv1, NULL);
timersub(&tv0, &hdl->tv, &dtv);
- fprintf(stderr, "%ld.%06ld: ", dtv.tv_sec, dtv.tv_usec);
+ DPRINTF(hdl, "%ld.%06ld: ", dtv.tv_sec, dtv.tv_usec);
timersub(&tv1, &tv0, &dtv);
us = dtv.tv_sec * 1000000 + dtv.tv_usec;
- fprintf(stderr,
+ DPRINTF(hdl,
"sio_write: wrote %d bytes of %d in %uus\n",
(int)(len - todo), (int)len, us);
}
@@ -462,17 +467,19 @@ sio_revents(struct sio_hdl *hdl, struct pollfd *pfd)
return POLLHUP;
if (!hdl->started)
return 0;
+#ifdef DEBUG
hdl->pollcnt++;
+#endif
revents = hdl->ops->revents(hdl, pfd);
#ifdef DEBUG
if (hdl->debug >= 2) {
gettimeofday(&tv1, NULL);
timersub(&tv0, &hdl->tv, &dtv);
- fprintf(stderr, "%ld.%06ld: ", dtv.tv_sec, dtv.tv_usec);
+ DPRINTF(hdl, "%ld.%06ld: ", dtv.tv_sec, dtv.tv_usec);
timersub(&tv1, &tv0, &dtv);
us = dtv.tv_sec * 1000000 + dtv.tv_usec;
- fprintf(stderr,
+ DPRINTF(hdl,
"sio_revents: revents = 0x%x, complete in %uus\n",
revents, us);
}
@@ -490,7 +497,7 @@ void
sio_onmove(struct sio_hdl *hdl, void (*cb)(void *, int), void *addr)
{
if (hdl->started) {
- fprintf(stderr, "sio_onmove: already started\n");
+ DPRINTF(hdl, "sio_onmove: already started\n");
hdl->eof = 1;
return;
}
@@ -508,10 +515,10 @@ sio_onmove_cb(struct sio_hdl *hdl, int delta)
if (hdl->debug >= 2 && (hdl->mode & SIO_PLAY)) {
gettimeofday(&tv0, NULL);
timersub(&tv0, &hdl->tv, &dtv);
- fprintf(stderr, "%ld.%06ld: ", dtv.tv_sec, dtv.tv_usec);
+ DPRINTF(hdl, "%ld.%06ld: ", dtv.tv_sec, dtv.tv_usec);
hdl->realpos += delta;
playpos = hdl->wcnt / (hdl->par.bps * hdl->par.pchan);
- fprintf(stderr,
+ DPRINTF(hdl,
"sio_onmove_cb: delta = %+7d, "
"plat = %+7lld, "
"realpos = %+7lld, "
@@ -541,7 +548,7 @@ void
sio_onvol(struct sio_hdl *hdl, void (*cb)(void *, unsigned), void *addr)
{
if (hdl->started) {
- fprintf(stderr, "sio_onvol: already started\n");
+ DPRINTF(hdl, "sio_onvol: already started\n");
hdl->eof = 1;
return;
}
diff --git a/lib/libsndio/sndio_priv.h b/lib/libsndio/sndio_priv.h
index 44284cf61e1..c9bbef87843 100644
--- a/lib/libsndio/sndio_priv.h
+++ b/lib/libsndio/sndio_priv.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sndio_priv.h,v 1.2 2008/11/11 19:39:35 ratchov Exp $ */
+/* $OpenBSD: sndio_priv.h,v 1.3 2008/12/17 10:00:50 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -67,4 +67,20 @@ void sio_destroy(struct sio_hdl *);
void sio_onmove_cb(struct sio_hdl *, int);
void sio_onvol_cb(struct sio_hdl *, unsigned);
+#ifdef DEBUG
+#define DPRINTF(hdl,...) \
+ do { \
+ if ((hdl)->debug) \
+ fprintf(stderr, __VA_ARGS__); \
+ } while(0)
+#define DPERROR(hdl,s) \
+ do { \
+ if ((hdl)->debug) \
+ perror(s); \
+ } while(0)
+#else
+#define DPRINTF(hdl,...) do {} while(0)
+#define DPERROR(hdl,s) do {} while(0)
+#endif
+
#endif /* !defined(LIBSIO_PRIV_H) */
diff --git a/lib/libsndio/sun.c b/lib/libsndio/sun.c
index 14dbbe14400..f98026d1218 100644
--- a/lib/libsndio/sun.c
+++ b/lib/libsndio/sun.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sun.c,v 1.8 2008/12/17 07:19:27 ratchov Exp $ */
+/* $OpenBSD: sun.c,v 1.9 2008/12/17 10:00:50 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -100,7 +100,7 @@ struct sun_pref {
* convert sun encoding to sio_par encoding
*/
void
-sun_infotoenc(struct audio_prinfo *ai, struct sio_par *par)
+sun_infotoenc(struct sun_hdl *hdl, struct audio_prinfo *ai, struct sio_par *par)
{
par->msb = 1;
par->bits = ai->precision;
@@ -131,7 +131,7 @@ sun_infotoenc(struct audio_prinfo *ai, struct sio_par *par)
par->sig = 0;
break;
default:
- fprintf(stderr, "sun_infotoenc: unsupported encoding\n");
+ DPRINTF(&hdl->sa, "sun_infotoenc: unsupported encoding\n");
exit(1);
}
}
@@ -140,7 +140,7 @@ sun_infotoenc(struct audio_prinfo *ai, struct sio_par *par)
* convert sio_par encoding to sun encoding
*/
void
-sun_enctoinfo(struct audio_prinfo *ai, struct sio_par *par)
+sun_enctoinfo(struct sun_hdl *hdl, struct audio_prinfo *ai, struct sio_par *par)
{
if (par->le && par->sig) {
ai->encoding = AUDIO_ENCODING_SLINEAR_LE;
@@ -194,12 +194,12 @@ sun_tryinfo(struct sun_hdl *hdl, struct sio_enc *enc,
if (ioctl(hdl->fd, AUDIO_SETINFO, &aui) < 0) {
if (errno == EINVAL)
return 0;
- perror("sun_tryinfo: setinfo");
+ DPERROR(&hdl->sa, "sun_tryinfo: setinfo");
hdl->sa.eof = 1;
return 0;
}
if (ioctl(hdl->fd, AUDIO_GETINFO, &aui) < 0) {
- perror("sun_tryinfo: getinfo");
+ DPERROR(&hdl->sa, "sun_tryinfo: getinfo");
hdl->sa.eof = 1;
return 0;
}
@@ -250,7 +250,7 @@ sun_getcap(struct sio_hdl *sh, struct sio_cap *cap)
if (ioctl(hdl->fd, AUDIO_GETENC, &ae) < 0) {
if (errno == EINVAL)
break;
- perror("sun_getcap: getenc");
+ DPERROR(&hdl->sa, "sun_getcap: getenc");
hdl->sa.eof = 1;
return 0;
}
@@ -360,7 +360,7 @@ sun_initvol(struct sun_hdl *hdl)
snprintf(path, PATH_MAX, "/dev/mixer%d", sb.st_rdev & 0xf);
fd = open(path, O_RDWR);
if (fd < 0) {
- fprintf(stderr, "%s: couldn't open mixer\n", path);
+ DPRINTF(&hdl->sa, "%s: couldn't open mixer\n", path);
return;
}
@@ -393,7 +393,7 @@ sun_initvol(struct sun_hdl *hdl)
m.type = AUDIO_MIXER_VALUE;
m.un.value.num_channels = 1;
if (ioctl(hdl->mix_fd, AUDIO_MIXER_READ, &m) < 0) {
- fprintf(stderr, "sun_getvol: %d: failed to get volume\n", m.dev);
+ DPRINTF(&hdl->sa, "sun_getvol: %d: failed to get volume\n", m.dev);
hdl->sa.eof = 1;
return;
}
@@ -432,7 +432,7 @@ sun_setvol(struct sio_hdl *sh, unsigned vol)
m.un.value.num_channels = 1;
m.un.value.level[0] = 2 * vol;
if (ioctl(hdl->mix_fd, AUDIO_MIXER_WRITE, &m) < 0) {
- fprintf(stderr, "sun_setvol: failed to set volume\n");
+ DPRINTF(&hdl->sa, "sun_setvol: failed to set volume\n");
hdl->sa.eof = 1;
return 0;
}
@@ -463,7 +463,7 @@ sio_open_sun(char *path, unsigned mode, int nbio)
while ((fd = open(path, flags | O_NONBLOCK)) < 0) {
if (errno == EINTR)
continue;
- perror(path);
+ DPERROR(&hdl->sa, path);
goto bad_free;
}
hdl->fd = fd;
@@ -476,7 +476,7 @@ sio_open_sun(char *path, unsigned mode, int nbio)
if (mode == (SIO_PLAY | SIO_REC)) {
fullduplex = 1;
if (ioctl(fd, AUDIO_SETFD, &fullduplex) < 0) {
- fprintf(stderr, "%s: can't set full-duplex\n", path);
+ DPRINTF(&hdl->sa, "%s: can't set full-duplex\n", path);
goto bad_close;
}
}
@@ -487,7 +487,7 @@ sio_open_sun(char *path, unsigned mode, int nbio)
if (hdl->sa.mode & SIO_REC)
aui.record.encoding = AUDIO_ENCODING_SLINEAR;
if (ioctl(hdl->fd, AUDIO_SETINFO, &aui) < 0) {
- perror("sio_open_sun: setinfo");
+ DPERROR(&hdl->sa, "sio_open_sun: setinfo");
goto bad_close;
}
sio_initpar(&par);
@@ -547,7 +547,7 @@ sun_start(struct sio_hdl *sh)
if (hdl->sa.mode & SIO_REC)
aui.record.pause = 1;
if (ioctl(hdl->fd, AUDIO_SETINFO, &aui) < 0) {
- perror("sun_start: setinfo2");
+ DPERROR(&hdl->sa, "sun_start: setinfo2");
hdl->sa.eof = 1;
return 0;
}
@@ -562,7 +562,7 @@ sun_start(struct sio_hdl *sh)
if (hdl->sa.mode & SIO_REC)
aui.record.pause = 0;
if (ioctl(hdl->fd, AUDIO_SETINFO, &aui) < 0) {
- perror("sun_start: setinfo");
+ DPERROR(&hdl->sa, "sun_start: setinfo");
hdl->sa.eof = 1;
return 0;
}
@@ -579,7 +579,7 @@ sun_stop(struct sio_hdl *sh)
int mode;
if (ioctl(hdl->fd, AUDIO_GETINFO, &aui) < 0) {
- perror("sun_start: setinfo1");
+ DPERROR(&hdl->sa, "sun_start: setinfo1");
hdl->sa.eof = 1;
return 0;
}
@@ -592,14 +592,14 @@ sun_stop(struct sio_hdl *sh)
AUDIO_INITINFO(&aui);
aui.mode = 0;
if (ioctl(hdl->fd, AUDIO_SETINFO, &aui) < 0) {
- perror("sun_stop: setinfo1");
+ DPERROR(&hdl->sa, "sun_stop: setinfo1");
hdl->sa.eof = 1;
return 0;
}
AUDIO_INITINFO(&aui);
aui.mode = mode;
if (ioctl(hdl->fd, AUDIO_SETINFO, &aui) < 0) {
- perror("sun_stop: setinfo2");
+ DPERROR(&hdl->sa, "sun_stop: setinfo2");
hdl->sa.eof = 1;
return 0;
}
@@ -622,15 +622,15 @@ sun_setpar(struct sio_hdl *sh, struct sio_par *par)
if (hdl->sa.mode & SIO_PLAY) {
aui.play.sample_rate = par->rate;
aui.play.channels = par->pchan;
- sun_enctoinfo(&aui.play, par);
+ sun_enctoinfo(hdl, &aui.play, par);
}
if (hdl->sa.mode & SIO_REC) {
aui.record.sample_rate = par->rate;
aui.record.channels = par->rchan;
- sun_enctoinfo(&aui.record, par);
+ sun_enctoinfo(hdl, &aui.record, par);
}
if (ioctl(hdl->fd, AUDIO_SETINFO, &aui) < 0 && errno != EINVAL) {
- perror("sun_setpar: setinfo");
+ DPERROR(&hdl->sa, "sun_setpar: setinfo");
hdl->sa.eof = 1;
return 0;
}
@@ -654,7 +654,7 @@ sun_setpar(struct sio_hdl *sh, struct sio_par *par)
* get the play/record frame size in bytes
*/
if (ioctl(hdl->fd, AUDIO_GETINFO, &aui) < 0) {
- perror("sun_setpar: GETINFO");
+ DPERROR(&hdl->sa, "sun_setpar: GETINFO");
hdl->sa.eof = 1;
return 0;
}
@@ -665,7 +665,7 @@ sun_setpar(struct sio_hdl *sh, struct sio_par *par)
#ifdef DEBUG
if (hdl->sa.debug)
- fprintf(stderr, "sun_setpar: bpf = (%u, %u)\n", ibpf, obpf);
+ DPRINTF(&hdl->sa, "sun_setpar: bpf = (%u, %u)\n", ibpf, obpf);
#endif
/*
* try to set parameters until the device accepts
@@ -680,12 +680,12 @@ sun_setpar(struct sio_hdl *sh, struct sio_par *par)
if (hdl->sa.mode & SIO_PLAY)
aui.play.block_size = round * obpf;
if (ioctl(hdl->fd, AUDIO_SETINFO, &aui) < 0) {
- perror("sun_setpar2: SETINFO");
+ DPERROR(&hdl->sa, "sun_setpar2: SETINFO");
hdl->sa.eof = 1;
return 0;
}
if (ioctl(hdl->fd, AUDIO_GETINFO, &aui) < 0) {
- perror("sun_setpar2: GETINFO");
+ DPERROR(&hdl->sa, "sun_setpar2: GETINFO");
hdl->sa.eof = 1;
return 0;
}
@@ -693,7 +693,7 @@ sun_setpar(struct sio_hdl *sh, struct sio_par *par)
onfr = aui.play.block_size / obpf;
#ifdef DEBUG
if (hdl->sa.debug) {
- fprintf(stderr,
+ DPRINTF(&hdl->sa,
"sun_setpar: %i: trying rond = %u -> (%u, %u)\n",
i, round, infr, onfr);
}
@@ -705,7 +705,7 @@ sun_setpar(struct sio_hdl *sh, struct sio_par *par)
if (hdl->sa.mode != (SIO_REC | SIO_PLAY) || infr == onfr) {
#ifdef DEBUG
if (hdl->sa.debug)
- fprintf(stderr, "sun_setpar: blocksize ok\n");
+ DPRINTF(&hdl->sa, "sun_setpar: blocksize ok\n");
#endif
return 1;
}
@@ -719,7 +719,7 @@ sun_setpar(struct sio_hdl *sh, struct sio_par *par)
else
round = infr < onfr ? onfr : infr;
}
- fprintf(stderr, "sun_setpar: couldn't find a working blocksize\n");
+ DPRINTF(&hdl->sa, "sun_setpar: couldn't find a working blocksize\n");
hdl->sa.eof = 1;
return 0;
#undef NRETRIES
@@ -732,16 +732,16 @@ sun_getpar(struct sio_hdl *sh, struct sio_par *par)
struct audio_info aui;
if (ioctl(hdl->fd, AUDIO_GETINFO, &aui) < 0) {
- perror("sun_getpar: setinfo");
+ DPERROR(&hdl->sa, "sun_getpar: setinfo");
hdl->sa.eof = 1;
return 0;
}
if (hdl->sa.mode & SIO_PLAY) {
par->rate = aui.play.sample_rate;
- sun_infotoenc(&aui.play, par);
+ sun_infotoenc(hdl, &aui.play, par);
} else if (hdl->sa.mode & SIO_REC) {
par->rate = aui.record.sample_rate;
- sun_infotoenc(&aui.record, par);
+ sun_infotoenc(hdl, &aui.record, par);
} else
return 0;
par->pchan = (hdl->sa.mode & SIO_PLAY) ?
@@ -772,20 +772,20 @@ sun_read(struct sio_hdl *sh, void *buf, size_t len)
if (errno == EINTR)
continue;
if (errno != EAGAIN) {
- perror("sun_read: read");
+ DPERROR(&hdl->sa, "sun_read: read");
hdl->sa.eof = 1;
}
return 0;
}
if (n == 0) {
- fprintf(stderr, "sun_read: eof\n");
+ DPRINTF(&hdl->sa, "sun_read: eof\n");
hdl->sa.eof = 1;
return 0;
}
hdl->offset -= (int)n / (int)hdl->ibpf;
#ifdef DEBUG
if (hdl->sa.debug)
- fprintf(stderr, "sun_read: dropped %ld/%ld bytes "
+ DPRINTF(&hdl->sa, "sun_read: dropped %ld/%ld bytes "
"to resync\n", n, todo);
#endif
}
@@ -794,13 +794,13 @@ sun_read(struct sio_hdl *sh, void *buf, size_t len)
if (errno == EINTR)
continue;
if (errno != EAGAIN) {
- perror("sun_read: read");
+ DPERROR(&hdl->sa, "sun_read: read");
hdl->sa.eof = 1;
}
return 0;
}
if (n == 0) {
- fprintf(stderr, "sun_read: eof\n");
+ DPRINTF(&hdl->sa, "sun_read: eof\n");
hdl->sa.eof = 1;
return 0;
}
@@ -818,7 +818,7 @@ sun_autostart(struct sun_hdl *hdl)
while (poll(&pfd, 1, 0) < 0) {
if (errno == EINTR)
continue;
- perror("sun_fill: poll");
+ DPERROR(&hdl->sa, "sun_fill: poll");
hdl->sa.eof = 1;
return 0;
}
@@ -830,7 +830,7 @@ sun_autostart(struct sun_hdl *hdl)
if (hdl->sa.mode & SIO_REC)
aui.record.pause = 0;
if (ioctl(hdl->fd, AUDIO_SETINFO, &aui) < 0) {
- perror("sun_start: setinfo");
+ DPERROR(&hdl->sa, "sun_start: setinfo");
hdl->sa.eof = 1;
return 0;
}
@@ -856,7 +856,7 @@ sun_write(struct sio_hdl *sh, void *buf, size_t len)
if (errno == EINTR)
continue;
if (errno != EAGAIN) {
- perror("sun_write: sil");
+ DPERROR(&hdl->sa, "sun_write: sil");
hdl->sa.eof = 1;
return 0;
}
@@ -865,7 +865,7 @@ sun_write(struct sio_hdl *sh, void *buf, size_t len)
hdl->offset += (int)n / (int)hdl->obpf;
#ifdef DEBUG
if (hdl->sa.debug)
- fprintf(stderr, "sun_write: inserted %ld/%ld bytes "
+ DPRINTF(&hdl->sa, "sun_write: inserted %ld/%ld bytes "
"of silence to resync\n", n, todo);
#endif
}
@@ -875,7 +875,7 @@ sun_write(struct sio_hdl *sh, void *buf, size_t len)
if (errno == EINTR)
continue;
if (errno != EAGAIN) {
- perror("sun_write: write");
+ DPERROR(&hdl->sa, "sun_write: write");
hdl->sa.eof = 1;
return 0;
}
@@ -908,7 +908,7 @@ sun_revents(struct sio_hdl *sh, struct pollfd *pfd)
if (hdl->sa.mode & SIO_PLAY) {
if (ioctl(hdl->fd, AUDIO_PERROR, &xrun) < 0) {
- perror("sun_revents: PERROR");
+ DPERROR(&hdl->sa, "sun_revents: PERROR");
exit(1);
}
doerr = xrun - hdl->oerr;
@@ -918,7 +918,7 @@ sun_revents(struct sio_hdl *sh, struct pollfd *pfd)
}
if (hdl->sa.mode & SIO_REC) {
if (ioctl(hdl->fd, AUDIO_RERROR, &xrun) < 0) {
- perror("sun_revents: RERROR");
+ DPERROR(&hdl->sa, "sun_revents: RERROR");
exit(1);
}
dierr = xrun - hdl->ierr;
@@ -933,7 +933,7 @@ sun_revents(struct sio_hdl *sh, struct pollfd *pfd)
if ((revents & POLLOUT) && !(hdl->sa.mode & SIO_REC)) {
if (ioctl(hdl->fd, AUDIO_GETOOFFS, &ao) < 0) {
- perror("sun_revents: GETOOFFS");
+ DPERROR(&hdl->sa, "sun_revents: GETOOFFS");
exit(1);
}
hdl->odelta += (ao.samples - hdl->obytes) / hdl->obpf;
@@ -945,7 +945,7 @@ sun_revents(struct sio_hdl *sh, struct pollfd *pfd)
}
if ((revents & POLLIN) && (hdl->sa.mode & SIO_REC)) {
if (ioctl(hdl->fd, AUDIO_GETIOFFS, &ao) < 0) {
- perror("sun_revents: GETIOFFS");
+ DPERROR(&hdl->sa, "sun_revents: GETIOFFS");
exit(1);
}
hdl->idelta += (ao.samples - hdl->ibytes) / hdl->ibpf;