remove unused bits from libsndio

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Alexandre Ratchov
Date: Wednesday, October 27, 2010 - 5:34 am

this diff contains two independent changes that may require a major
version bump.

(1) libsndio still contains functions and macros that are neither
    documented nor used by any port; programs in regress/ use them
    though. This diff moves these functions from libsndio to a common
    file in regress/

(2) make sio_onvol(3) return an integer (boolean) exposing whether
    there is a volume knob associated to the stream.

AFAICS it doesn't affect ports, does it? Are there any other pending
changes that would require a major bump?

OK?

-- Alexandre

Index: include/sndio.h
===================================================================
RCS file: /cvs/src/include/sndio.h,v
retrieving revision 1.3
diff -u -p -r1.3 sndio.h
--- include/sndio.h	25 Jul 2009 11:27:14 -0000	1.3
+++ include/sndio.h	25 Oct 2010 10:07:11 -0000
@@ -1,4 +1,4 @@
-/*	$OpenBSD: sndio.h,v 1.3 2009/07/25 11:27:14 ratchov Exp $	*/
+/*	$OpenBSD$	*/
 /*
  * 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 
 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 *);
Index: lib/libsndio/shlib_version
===================================================================
RCS file: /cvs/src/lib/libsndio/shlib_version,v
retrieving revision 1.6
diff -u -p -r1.6 shlib_version
@@ -1,2 +1,2 @@
-major=3
-minor=3
+major=4
+minor=0
Index: lib/libsndio/sio_open.3
===================================================================
RCS file: /cvs/src/lib/libsndio/sio_open.3,v
retrieving revision 1.24
diff -u -p -r1.24 sio_open.3
--- lib/libsndio/sio_open.3	26 Apr 2010 07:11:10 -0000	1.24
+++ lib/libsndio/sio_open.3	25 Oct 2010 10:07:11 -0000
@@ -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
Index: lib/libsndio/sndio.c
===================================================================
RCS file: /cvs/src/lib/libsndio/sndio.c,v
retrieving revision 1.26
diff -u -p -r1.26 sndio.c
--- lib/libsndio/sndio.c	20 Aug 2010 06:56:53 -0000	1.26
+++ lib/libsndio/sndio.c	25 Oct 2010 10:07:12 -0000
@@ -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
 {
 	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
Index: lib/libsndio/sun.c
===================================================================
RCS file: /cvs/src/lib/libsndio/sun.c,v
retrieving revision 1.41
diff -u -p -r1.41 sun.c
--- lib/libsndio/sun.c	17 Sep 2010 08:08:23 -0000	1.41
+++ lib/libsndio/sun.c	25 Oct 2010 10:07:12 -0000
@@ -64,8 +64,6 @@ static size_t sun_read(struct sio_hdl *,
 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 */
 };
 
 /*
@@ -331,20 +329,6 @@ sun_getcap(struct sio_hdl *sh, struct si
 	return 1;
 #undef NCHANS
 #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 *
Index: regress/lib/libsndio/tools.c
===================================================================
RCS file: regress/lib/libsndio/tools.c
diff -N regress/lib/libsndio/tools.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ regress/lib/libsndio/tools.c	25 Oct 2010 10:07:12 -0000
@@ -0,0 +1,138 @@
+/*	$OpenBSD$	*/
+/*
+ * 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;
+}
Index: regress/lib/libsndio/tools.h
===================================================================
RCS file: regress/lib/libsndio/tools.h
diff -N regress/lib/libsndio/tools.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ regress/lib/libsndio/tools.h	25 Oct 2010 10:07:13 -0000
@@ -0,0 +1,49 @@
+/*	$OpenBSD$	*/
+/*
+ * 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.
+ */
+#ifndef TOOLS_H
+#define TOOLS_H
+
+/*
+ * maximum size of the encording string (the longest possible
+ * encoding is ``s24le3msb'')
+ */
+#define SIO_ENCMAX	10
+
+/*
+ * 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"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct sio_par;
+
+int sio_strtoenc(struct sio_par *, char *);
+int sio_enctostr(struct sio_par *, char *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !defined(TOOLS_H) */
Index: regress/lib/libsndio/fd/Makefile
===================================================================
RCS file: /cvs/src/regress/lib/libsndio/fd/Makefile,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile
--- regress/lib/libsndio/fd/Makefile	27 Oct 2008 00:26:33 -0000	1.1
+++ regress/lib/libsndio/fd/Makefile	25 Oct 2010 10:07:13 -0000
@@ -1,6 +1,7 @@
 #	$OpenBSD: Makefile,v 1.1 2008/10/27 00:26:33 ratchov Exp $
 PROG= fd
 LDADD= -lsndio
+SRCS = fd.c tools.c
 REGRESS_SKIP=
-
+.PATH: ${.CURDIR}/..
 .include <bsd.regress.mk>
Index: regress/lib/libsndio/play/Makefile
===================================================================
RCS file: /cvs/src/regress/lib/libsndio/play/Makefile,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile
--- regress/lib/libsndio/play/Makefile	27 Oct 2008 00:26:33 -0000	1.1
+++ regress/lib/libsndio/play/Makefile	25 Oct 2010 10:07:13 -0000
@@ -1,6 +1,7 @@
 #	$OpenBSD: Makefile,v 1.1 2008/10/27 00:26:33 ratchov Exp $
 PROG= play
 LDADD= -lsndio
+SRCS = play.c tools.c
 REGRESS_SKIP=
-
+.PATH: ${.CURDIR}/..
 .include <bsd.regress.mk>
Index: regress/lib/libsndio/rec/Makefile
===================================================================
RCS file: /cvs/src/regress/lib/libsndio/rec/Makefile,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile
--- regress/lib/libsndio/rec/Makefile	27 Oct 2008 00:26:33 -0000	1.1
+++ regress/lib/libsndio/rec/Makefile	25 Oct 2010 10:07:13 -0000
@@ -1,6 +1,7 @@
 #	$OpenBSD: Makefile,v 1.1 2008/10/27 00:26:33 ratchov Exp $
 PROG= rec
 LDADD= -lsndio
+SRCS = rec.c tools.c
 REGRESS_SKIP=
-
+.PATH: ${.CURDIR}/..
 .include <bsd.regress.mk>
Index: regress/lib/libsndio/vol/Makefile
===================================================================
RCS file: /cvs/src/regress/lib/libsndio/vol/Makefile,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile
--- regress/lib/libsndio/vol/Makefile	11 Nov 2008 19:39:35 -0000	1.1
+++ regress/lib/libsndio/vol/Makefile	25 Oct 2010 10:07:13 -0000
@@ -1,6 +1,7 @@
 #	$OpenBSD: Makefile,v 1.1 2008/11/11 19:39:35 ratchov Exp $
 PROG= vol
 LDADD= -lsndio
+SRCS = vol.c tools.c
 REGRESS_SKIP=
-
+.PATH: ${.CURDIR}/..
 .include <bsd.regress.mk>
Index: regress/lib/libsndio/vol/vol.c
===================================================================
RCS file: /cvs/src/regress/lib/libsndio/vol/vol.c,v
retrieving revision 1.1
diff -u -p -r1.1 vol.c
--- regress/lib/libsndio/vol/vol.c	11 Nov 2008 19:39:35 -0000	1.1
+++ regress/lib/libsndio/vol/vol.c	25 Oct 2010 10:07:13 -0000
@@ -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");
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
remove unused bits from libsndio, Alexandre Ratchov, (Wed Oct 27, 5:34 am)