2014-07-16 05:05:01 -05:00
|
|
|
/* $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 <errno.h>
|
|
|
|
#include <poll.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
#include "siomix_priv.h"
|
|
|
|
#include "bsd-compat.h"
|
|
|
|
|
|
|
|
struct siomix_hdl *
|
|
|
|
siomix_open(const char *str, unsigned int mode, int nbio)
|
|
|
|
{
|
|
|
|
static char devany[] = SIOMIX_DEVANY;
|
|
|
|
struct siomix_hdl *hdl;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
_sndio_debug_init();
|
|
|
|
#endif
|
|
|
|
if (str == NULL) /* backward compat */
|
|
|
|
str = devany;
|
|
|
|
if (strcmp(str, devany) == 0 && !issetugid()) {
|
|
|
|
str = getenv("AUDIODEVICE");
|
|
|
|
if (str == NULL)
|
|
|
|
str = devany;
|
|
|
|
}
|
|
|
|
if (strcmp(str, devany) == 0) {
|
2016-01-26 03:23:38 -06:00
|
|
|
hdl = _siomix_aucat_open("snd/0", mode, nbio);
|
2014-07-16 05:05:01 -05:00
|
|
|
if (hdl != NULL)
|
|
|
|
return hdl;
|
|
|
|
#if defined(USE_SUN_MIXER)
|
2016-01-26 03:23:38 -06:00
|
|
|
return _siomix_sun_open("rsnd/0", mode, nbio);
|
2014-07-16 05:05:01 -05:00
|
|
|
#elif defined(USE_ALSA_MIXER)
|
2016-01-26 03:23:38 -06:00
|
|
|
return _siomix_alsa_open("rsnd/0", mode, nbio);
|
2014-07-16 05:05:01 -05:00
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
}
|
2016-01-26 03:23:38 -06:00
|
|
|
if (_sndio_parsetype(str, "snd"))
|
|
|
|
return _siomix_aucat_open(str, mode, nbio);
|
|
|
|
if (_sndio_parsetype(str, "rsnd"))
|
2014-07-16 05:05:01 -05:00
|
|
|
#if defined(USE_SUN_MIXER)
|
2016-01-26 03:23:38 -06:00
|
|
|
return _siomix_sun_open(str, mode, nbio);
|
2014-07-16 05:05:01 -05:00
|
|
|
#elif defined(USE_ALSA_MIXER)
|
2016-01-26 03:23:38 -06:00
|
|
|
return _siomix_alsa_open(str, mode, nbio);
|
|
|
|
#else
|
|
|
|
return NULL;
|
2014-07-16 05:05:01 -05:00
|
|
|
#endif
|
|
|
|
DPRINTF("siomix_open: %s: unknown device type\n", str);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_siomix_create(struct siomix_hdl *hdl, struct siomix_ops *ops,
|
|
|
|
unsigned int mode, int nbio)
|
|
|
|
{
|
|
|
|
hdl->ops = ops;
|
|
|
|
hdl->mode = mode;
|
|
|
|
hdl->nbio = nbio;
|
|
|
|
hdl->eof = 0;
|
|
|
|
hdl->ctl_cb = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
_siomix_psleep(struct siomix_hdl *hdl, int event)
|
|
|
|
{
|
|
|
|
struct pollfd pfds[SIOMIX_MAXNFDS];
|
|
|
|
int revents, nfds;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
nfds = siomix_pollfd(hdl, pfds, event);
|
|
|
|
if (nfds == 0)
|
|
|
|
return 0;
|
|
|
|
while (poll(pfds, nfds, -1) < 0) {
|
|
|
|
if (errno == EINTR)
|
|
|
|
continue;
|
|
|
|
DPERROR("siomix_psleep: poll");
|
|
|
|
hdl->eof = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
revents = siomix_revents(hdl, pfds);
|
|
|
|
if (revents & POLLHUP) {
|
|
|
|
DPRINTF("siomix_psleep: hang-up\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (event == 0 || (revents & event))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
siomix_close(struct siomix_hdl *hdl)
|
|
|
|
{
|
|
|
|
hdl->ops->close(hdl);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
siomix_nfds(struct siomix_hdl *hdl)
|
|
|
|
{
|
|
|
|
return hdl->ops->nfds(hdl);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
siomix_pollfd(struct siomix_hdl *hdl, struct pollfd *pfd, int events)
|
|
|
|
{
|
|
|
|
if (hdl->eof)
|
|
|
|
return 0;
|
|
|
|
return hdl->ops->pollfd(hdl, pfd, events);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
siomix_revents(struct siomix_hdl *hdl, struct pollfd *pfd)
|
|
|
|
{
|
|
|
|
if (hdl->eof)
|
|
|
|
return POLLHUP;
|
|
|
|
return hdl->ops->revents(hdl, pfd);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
siomix_eof(struct siomix_hdl *hdl)
|
|
|
|
{
|
|
|
|
return hdl->eof;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
siomix_ondesc(struct siomix_hdl *hdl,
|
|
|
|
void (*cb)(void *, struct siomix_desc *, int), void *arg)
|
|
|
|
{
|
|
|
|
hdl->desc_cb = cb;
|
|
|
|
hdl->desc_arg = arg;
|
|
|
|
return hdl->ops->ondesc(hdl);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
siomix_onctl(struct siomix_hdl *hdl,
|
|
|
|
void (*cb)(void *, unsigned int, unsigned int), void *arg)
|
|
|
|
{
|
|
|
|
hdl->ctl_cb = cb;
|
|
|
|
hdl->ctl_arg = arg;
|
|
|
|
return hdl->ops->onctl(hdl);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_siomix_ondesc_cb(struct siomix_hdl *hdl,
|
|
|
|
struct siomix_desc *desc, unsigned int val)
|
|
|
|
{
|
|
|
|
if (desc) {
|
2015-09-04 10:08:12 -05:00
|
|
|
DPRINTF("_siomix_ondesc_cb: %u -> %s[%d].%s=%s[%d]:%d\n",
|
2014-07-16 05:05:01 -05:00
|
|
|
desc->addr,
|
2015-09-04 10:08:12 -05:00
|
|
|
desc->chan0.str, desc->chan0.unit,
|
2015-06-03 23:12:38 -05:00
|
|
|
desc->func,
|
2015-09-04 10:08:12 -05:00
|
|
|
desc->chan1.str, desc->chan1.unit,
|
|
|
|
val);
|
2014-07-16 05:05:01 -05:00
|
|
|
}
|
|
|
|
if (hdl->desc_cb)
|
|
|
|
hdl->desc_cb(hdl->desc_arg, desc, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_siomix_onctl_cb(struct siomix_hdl *hdl, unsigned int addr, unsigned int val)
|
|
|
|
{
|
2015-09-04 10:08:12 -05:00
|
|
|
DPRINTF("_siomix_onctl_cb: %u -> %u\n", addr, val);
|
2014-07-16 05:05:01 -05:00
|
|
|
if (hdl->ctl_cb)
|
|
|
|
hdl->ctl_cb(hdl->ctl_arg, addr, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
siomix_setctl(struct siomix_hdl *hdl, unsigned int addr, unsigned int val)
|
|
|
|
{
|
|
|
|
if (!(hdl->mode & SIOMIX_WRITE))
|
|
|
|
return 0;
|
|
|
|
return hdl->ops->setctl(hdl, addr, val);
|
|
|
|
}
|