summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2010-11-06 20:25:43 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2010-11-06 20:25:43 +0000
commitdae71a31376ac2f8fff6b5a1f86744dde7cb55ae (patch)
treee739cf0513bafb0ec391d421c23e023d87360a87
parentacf4823d51288be7611de9109bc7594c025a0879 (diff)
make sio_onvol(3) return a integer exposing whether a volume knob
is available for the stream. As we're at it, remove macros and functions that are neither used nor documented.
-rw-r--r--include/sndio.h23
-rw-r--r--lib/libsndio/shlib_version4
-rw-r--r--lib/libsndio/sio_open.318
-rw-r--r--lib/libsndio/sndio.c131
-rw-r--r--lib/libsndio/sun.c22
-rw-r--r--regress/lib/libsndio/fd/Makefile5
-rw-r--r--regress/lib/libsndio/play/Makefile5
-rw-r--r--regress/lib/libsndio/rec/Makefile5
-rw-r--r--regress/lib/libsndio/tools.c138
-rw-r--r--regress/lib/libsndio/vol/Makefile5
-rw-r--r--regress/lib/libsndio/vol/vol.c3
11 files changed, 181 insertions, 178 deletions
diff --git a/include/sndio.h b/include/sndio.h
index c3fcde700ba..3bb8e46dca1 100644
--- a/include/sndio.h
+++ b/include/sndio.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sndio.h,v 1.3 2009/07/25 11:27:14 ratchov Exp $ */
+/* $OpenBSD: sndio.h,v 1.4 2010/11/06 20:25:42 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -87,12 +87,6 @@ struct sio_cap {
#define MIO_IN 8
/*
- * maximum size of the encording string (the longest possible
- * encoding is ``s24le3msb'')
- */
-#define SIO_ENCMAX 10
-
-/*
* default bytes per sample for the given bits per sample
*/
#define SIO_BPS(bits) (((bits) <= 8) ? 1 : (((bits) <= 16) ? 2 : 4))
@@ -107,16 +101,6 @@ struct sio_cap {
#endif
/*
- * default device for the sun audio(4) back-end
- */
-#define SIO_SUN_PATH "/dev/audio"
-
-/*
- * default socket name for the aucat(1) back-end
- */
-#define SIO_AUCAT_PATH "default"
-
-/*
* maximum value of volume, eg. for sio_setvol()
*/
#define SIO_MAXVOL 127
@@ -127,10 +111,7 @@ extern "C" {
struct pollfd;
-int sio_strtoenc(struct sio_par *, char *);
-int sio_enctostr(struct sio_par *, char *);
void sio_initpar(struct sio_par *);
-
struct sio_hdl *sio_open(const char *, unsigned, int);
void sio_close(struct sio_hdl *);
int sio_setpar(struct sio_hdl *, struct sio_par *);
@@ -146,7 +127,7 @@ int sio_pollfd(struct sio_hdl *, struct pollfd *, int);
int sio_revents(struct sio_hdl *, struct pollfd *);
int sio_eof(struct sio_hdl *);
int sio_setvol(struct sio_hdl *, unsigned);
-void sio_onvol(struct sio_hdl *, void (*)(void *, unsigned), void *);
+int sio_onvol(struct sio_hdl *, void (*)(void *, unsigned), void *);
struct mio_hdl *mio_open(const char *, unsigned, int);
void mio_close(struct mio_hdl *);
diff --git a/lib/libsndio/shlib_version b/lib/libsndio/shlib_version
index b25072f4e52..d9961ea9fef 100644
--- a/lib/libsndio/shlib_version
+++ b/lib/libsndio/shlib_version
@@ -1,2 +1,2 @@
-major=3
-minor=3
+major=4
+minor=0
diff --git a/lib/libsndio/sio_open.3 b/lib/libsndio/sio_open.3
index 91135d05c25..f0c31f7f3fd 100644
--- a/lib/libsndio/sio_open.3
+++ b/lib/libsndio/sio_open.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sio_open.3,v 1.24 2010/04/26 07:11:10 jakemsr Exp $
+.\" $OpenBSD: sio_open.3,v 1.25 2010/11/06 20:25:42 ratchov Exp $
.\"
.\" Copyright (c) 2007 Alexandre Ratchov <alex@caoua.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: April 26 2010 $
+.Dd $Mdocdate: November 6 2010 $
.Dt SIO_OPEN 3
.Os
.Sh NAME
@@ -68,7 +68,7 @@
.Fn "sio_eof" "struct sio_hdl *hdl"
.Ft "int"
.Fn "sio_setvol" "struct sio_hdl *hdl" "unsigned vol"
-.Ft "void"
+.Ft "int"
.Fn "sio_onvol" "struct sio_hdl *hdl" "void (*cb)(void *arg, unsigned vol)" "void *arg"
.Ft "void"
.Fn "sio_initpar" "struct sio_par *par"
@@ -669,8 +669,18 @@ The callback is always invoked when
is called in order to provide the initial volume.
An application can safely assume that once
.Fn sio_onvol
-returns, the callback has already been invoked and thus
+returns non-zero value, the callback has already been invoked and thus
the current volume is available.
+If there's no volume setting available,
+.Fn sio_onvol
+returns 0 and the callback is never invoked and calls to
+.Fn sio_setvol
+are ignored.
+.Pp
+The
+.Fn sio_onvol
+function can be called with a NULL argument to check whether
+a volume knob is available.
.Ss Error handling
Errors related to the audio subsystem
(like hardware errors, dropped connections) and
diff --git a/lib/libsndio/sndio.c b/lib/libsndio/sndio.c
index 075e1779534..eb07c42d63b 100644
--- a/lib/libsndio/sndio.c
+++ b/lib/libsndio/sndio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sndio.c,v 1.26 2010/08/20 06:56:53 ratchov Exp $ */
+/* $OpenBSD: sndio.c,v 1.27 2010/11/06 20:25:42 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -46,126 +46,6 @@ sio_initpar(struct sio_par *par)
par->__magic = SIO_PAR_MAGIC;
}
-/*
- * Generate a string corresponding to the encoding in par,
- * return the length of the resulting string
- */
-int
-sio_enctostr(struct sio_par *par, char *ostr)
-{
- char *p = ostr;
-
- *p++ = par->sig ? 's' : 'u';
- if (par->bits > 9)
- *p++ = '0' + par->bits / 10;
- *p++ = '0' + par->bits % 10;
- if (par->bps > 1) {
- *p++ = par->le ? 'l' : 'b';
- *p++ = 'e';
- if (par->bps != SIO_BPS(par->bits) ||
- par->bits < par->bps * 8) {
- *p++ = par->bps + '0';
- if (par->bits < par->bps * 8) {
- *p++ = par->msb ? 'm' : 'l';
- *p++ = 's';
- *p++ = 'b';
- }
- }
- }
- *p++ = '\0';
- return p - ostr - 1;
-}
-
-/*
- * Parse an encoding string, examples: s8, u8, s16, s16le, s24be ...
- * Return the number of bytes consumed
- */
-int
-sio_strtoenc(struct sio_par *par, char *istr)
-{
- char *p = istr;
- int i, sig, bits, le, bps, msb;
-
-#define IS_SEP(c) \
- (((c) < 'a' || (c) > 'z') && \
- ((c) < 'A' || (c) > 'Z') && \
- ((c) < '0' || (c) > '9'))
-
- /*
- * get signedness
- */
- if (*p == 's') {
- sig = 1;
- } else if (*p == 'u') {
- sig = 0;
- } else
- return 0;
- p++;
-
- /*
- * get number of bits per sample
- */
- bits = 0;
- for (i = 0; i < 2; i++) {
- if (*p < '0' || *p > '9')
- break;
- bits = (bits * 10) + *p - '0';
- p++;
- }
- if (bits < 1 || bits > 32)
- return 0;
- bps = SIO_BPS(bits);
- le = SIO_LE_NATIVE;
- msb = 1;
-
- /*
- * get (optional) endianness
- */
- if (p[0] == 'l' && p[1] == 'e') {
- le = 1;
- p += 2;
- } else if (p[0] == 'b' && p[1] == 'e') {
- le = 0;
- p += 2;
- } else if (IS_SEP(*p)) {
- goto done;
- } else
- return 0;
-
- /*
- * get (optional) number of bytes
- */
- if (*p >= '1' && *p <= '4') {
- bps = *p - '0';
- if (bps * 8 < bits)
- return 0;
- p++;
-
- /*
- * get (optional) alignment
- */
- if (p[0] == 'm' && p[1] == 's' && p[2] == 'b') {
- msb = 1;
- p += 3;
- } else if (p[0] == 'l' && p[1] == 's' && p[2] == 'b') {
- msb = 0;
- p += 3;
- } else if (IS_SEP(*p)) {
- goto done;
- } else
- return 0;
- } else if (!IS_SEP(*p))
- return 0;
-
-done:
- par->msb = msb;
- par->sig = sig;
- par->bits = bits;
- par->bps = bps;
- par->le = le;
- return p - istr;
-}
-
struct sio_hdl *
sio_open(const char *str, unsigned mode, int nbio)
{
@@ -575,23 +455,28 @@ sio_setvol(struct sio_hdl *hdl, unsigned ctl)
{
if (hdl->eof)
return 0;
+ if (!hdl->ops->setvol)
+ return 1;
if (!hdl->ops->setvol(hdl, ctl))
return 0;
hdl->ops->getvol(hdl);
return 1;
}
-void
+int
sio_onvol(struct sio_hdl *hdl, void (*cb)(void *, unsigned), void *addr)
{
if (hdl->started) {
DPRINTF("sio_onvol: already started\n");
hdl->eof = 1;
- return;
+ return 0;
}
+ if (!hdl->ops->setvol)
+ return 0;
hdl->vol_cb = cb;
hdl->vol_addr = addr;
hdl->ops->getvol(hdl);
+ return 1;
}
void
diff --git a/lib/libsndio/sun.c b/lib/libsndio/sun.c
index b1f17f691eb..22795e2a097 100644
--- a/lib/libsndio/sun.c
+++ b/lib/libsndio/sun.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sun.c,v 1.41 2010/09/17 08:08:23 ratchov Exp $ */
+/* $OpenBSD: sun.c,v 1.42 2010/11/06 20:25:42 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -64,8 +64,6 @@ static size_t sun_read(struct sio_hdl *, void *, size_t);
static size_t sun_write(struct sio_hdl *, const void *, size_t);
static int sun_pollfd(struct sio_hdl *, struct pollfd *, int);
static int sun_revents(struct sio_hdl *, struct pollfd *);
-static int sun_setvol(struct sio_hdl *, unsigned);
-static void sun_getvol(struct sio_hdl *);
static struct sio_ops sun_ops = {
sun_close,
@@ -78,8 +76,8 @@ static struct sio_ops sun_ops = {
sun_stop,
sun_pollfd,
sun_revents,
- sun_setvol,
- sun_getvol
+ NULL, /* setvol */
+ NULL, /* getvol */
};
/*
@@ -333,20 +331,6 @@ sun_getcap(struct sio_hdl *sh, struct sio_cap *cap)
#undef NRATES
}
-static void
-sun_getvol(struct sio_hdl *sh)
-{
- struct sun_hdl *hdl = (struct sun_hdl *)sh;
-
- sio_onvol_cb(&hdl->sio, SIO_MAXVOL);
-}
-
-int
-sun_setvol(struct sio_hdl *sh, unsigned vol)
-{
- return 1;
-}
-
struct sio_hdl *
sio_open_sun(const char *str, unsigned mode, int nbio)
{
diff --git a/regress/lib/libsndio/fd/Makefile b/regress/lib/libsndio/fd/Makefile
index 431850655cd..ca36f9006ea 100644
--- a/regress/lib/libsndio/fd/Makefile
+++ b/regress/lib/libsndio/fd/Makefile
@@ -1,6 +1,7 @@
-# $OpenBSD: Makefile,v 1.1 2008/10/27 00:26:33 ratchov Exp $
+# $OpenBSD: Makefile,v 1.2 2010/11/06 20:25:42 ratchov Exp $
PROG= fd
LDADD= -lsndio
+SRCS = fd.c tools.c
REGRESS_SKIP=
-
+.PATH: ${.CURDIR}/..
.include <bsd.regress.mk>
diff --git a/regress/lib/libsndio/play/Makefile b/regress/lib/libsndio/play/Makefile
index 5e2f2020ea0..3ea4d99d94b 100644
--- a/regress/lib/libsndio/play/Makefile
+++ b/regress/lib/libsndio/play/Makefile
@@ -1,6 +1,7 @@
-# $OpenBSD: Makefile,v 1.1 2008/10/27 00:26:33 ratchov Exp $
+# $OpenBSD: Makefile,v 1.2 2010/11/06 20:25:42 ratchov Exp $
PROG= play
LDADD= -lsndio
+SRCS = play.c tools.c
REGRESS_SKIP=
-
+.PATH: ${.CURDIR}/..
.include <bsd.regress.mk>
diff --git a/regress/lib/libsndio/rec/Makefile b/regress/lib/libsndio/rec/Makefile
index 773e9789f26..2a5738e024e 100644
--- a/regress/lib/libsndio/rec/Makefile
+++ b/regress/lib/libsndio/rec/Makefile
@@ -1,6 +1,7 @@
-# $OpenBSD: Makefile,v 1.1 2008/10/27 00:26:33 ratchov Exp $
+# $OpenBSD: Makefile,v 1.2 2010/11/06 20:25:42 ratchov Exp $
PROG= rec
LDADD= -lsndio
+SRCS = rec.c tools.c
REGRESS_SKIP=
-
+.PATH: ${.CURDIR}/..
.include <bsd.regress.mk>
diff --git a/regress/lib/libsndio/tools.c b/regress/lib/libsndio/tools.c
new file mode 100644
index 00000000000..6d8cb3f62ff
--- /dev/null
+++ b/regress/lib/libsndio/tools.c
@@ -0,0 +1,138 @@
+/* $OpenBSD: tools.c,v 1.1 2010/11/06 20:25:42 ratchov Exp $ */
+/*
+ * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#include <sndio.h>
+#include "tools.h"
+
+/*
+ * Generate a string corresponding to the encoding in par,
+ * return the length of the resulting string
+ */
+int
+sio_enctostr(struct sio_par *par, char *ostr)
+{
+ char *p = ostr;
+
+ *p++ = par->sig ? 's' : 'u';
+ if (par->bits > 9)
+ *p++ = '0' + par->bits / 10;
+ *p++ = '0' + par->bits % 10;
+ if (par->bps > 1) {
+ *p++ = par->le ? 'l' : 'b';
+ *p++ = 'e';
+ if (par->bps != SIO_BPS(par->bits) ||
+ par->bits < par->bps * 8) {
+ *p++ = par->bps + '0';
+ if (par->bits < par->bps * 8) {
+ *p++ = par->msb ? 'm' : 'l';
+ *p++ = 's';
+ *p++ = 'b';
+ }
+ }
+ }
+ *p++ = '\0';
+ return p - ostr - 1;
+}
+
+/*
+ * Parse an encoding string, examples: s8, u8, s16, s16le, s24be ...
+ * Return the number of bytes consumed
+ */
+int
+sio_strtoenc(struct sio_par *par, char *istr)
+{
+ char *p = istr;
+ int i, sig, bits, le, bps, msb;
+
+#define IS_SEP(c) \
+ (((c) < 'a' || (c) > 'z') && \
+ ((c) < 'A' || (c) > 'Z') && \
+ ((c) < '0' || (c) > '9'))
+
+ /*
+ * get signedness
+ */
+ if (*p == 's') {
+ sig = 1;
+ } else if (*p == 'u') {
+ sig = 0;
+ } else
+ return 0;
+ p++;
+
+ /*
+ * get number of bits per sample
+ */
+ bits = 0;
+ for (i = 0; i < 2; i++) {
+ if (*p < '0' || *p > '9')
+ break;
+ bits = (bits * 10) + *p - '0';
+ p++;
+ }
+ if (bits < 1 || bits > 32)
+ return 0;
+ bps = SIO_BPS(bits);
+ le = SIO_LE_NATIVE;
+ msb = 1;
+
+ /*
+ * get (optional) endianness
+ */
+ if (p[0] == 'l' && p[1] == 'e') {
+ le = 1;
+ p += 2;
+ } else if (p[0] == 'b' && p[1] == 'e') {
+ le = 0;
+ p += 2;
+ } else if (IS_SEP(*p)) {
+ goto done;
+ } else
+ return 0;
+
+ /*
+ * get (optional) number of bytes
+ */
+ if (*p >= '1' && *p <= '4') {
+ bps = *p - '0';
+ if (bps * 8 < bits)
+ return 0;
+ p++;
+
+ /*
+ * get (optional) alignment
+ */
+ if (p[0] == 'm' && p[1] == 's' && p[2] == 'b') {
+ msb = 1;
+ p += 3;
+ } else if (p[0] == 'l' && p[1] == 's' && p[2] == 'b') {
+ msb = 0;
+ p += 3;
+ } else if (IS_SEP(*p)) {
+ goto done;
+ } else
+ return 0;
+ } else if (!IS_SEP(*p))
+ return 0;
+
+done:
+ par->msb = msb;
+ par->sig = sig;
+ par->bits = bits;
+ par->bps = bps;
+ par->le = le;
+ return p - istr;
+}
diff --git a/regress/lib/libsndio/vol/Makefile b/regress/lib/libsndio/vol/Makefile
index 7e1f32bec17..06bd08fd561 100644
--- a/regress/lib/libsndio/vol/Makefile
+++ b/regress/lib/libsndio/vol/Makefile
@@ -1,6 +1,7 @@
-# $OpenBSD: Makefile,v 1.1 2008/11/11 19:39:35 ratchov Exp $
+# $OpenBSD: Makefile,v 1.2 2010/11/06 20:25:42 ratchov Exp $
PROG= vol
LDADD= -lsndio
+SRCS = vol.c tools.c
REGRESS_SKIP=
-
+.PATH: ${.CURDIR}/..
.include <bsd.regress.mk>
diff --git a/regress/lib/libsndio/vol/vol.c b/regress/lib/libsndio/vol/vol.c
index 2ee08e35c7a..8173af547b6 100644
--- a/regress/lib/libsndio/vol/vol.c
+++ b/regress/lib/libsndio/vol/vol.c
@@ -103,7 +103,8 @@ main(int argc, char **argv) {
fprintf(stderr, "sio_setpar() failed\n");
exit(1);
}
- sio_onvol(hdl, onvol, NULL);
+ if (!sio_onvol(hdl, onvol, NULL))
+ fprintf(stderr, "warning: no volume knob on this device\n");
fprintf(stderr, "use ``+'' and ``-'' to adjust the volume\n");
if (!sio_start(hdl)) {
fprintf(stderr, "sio_start() failed\n");