make sio_onvol() return an integer, 0 if the volume knob not available,

allowing the caller to setup a softvol layer
This commit is contained in:
Alexandre Ratchov 2010-10-25 09:45:16 +02:00
parent fe5100700d
commit 286994d187
4 changed files with 25 additions and 26 deletions

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: sio_open.3,v 1.24 2010/04/26 07:11:10 jakemsr Exp $
.\" $OpenBSD$
.\"
.\" 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$
.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

View File

@ -599,23 +599,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);
hdl->ops->getvol(hdl);
return 1;
}
void

View File

@ -146,7 +146,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 *);

View File

@ -65,8 +65,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,
@ -79,8 +77,8 @@ static struct sio_ops sun_ops = {
sun_stop,
sun_pollfd,
sun_revents,
sun_setvol,
sun_getvol
NULL, /* setvol */
NULL, /* getvol */
};
/*
@ -334,20 +332,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)
{