summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-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
4 files changed, 27 insertions, 148 deletions
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)
{