static int oss_open (int in, struct oss_params *req,
                     struct oss_params *obt, int *pfd)
{
    int fd;
    int mmmmssss;
    audio_buf_info abinfo;
    int fmt, freq, nchannels;
    const char *dspname = in ? conf.devpath_in : conf.devpath_out;
    const char *typ = in ? "ADC" : "DAC";
    fd = open (dspname, (in ? O_RDONLY : O_WRONLY) | O_NONBLOCK);
    if (-1 == fd) {
        oss_logerr2 (errno, typ, "Failed to open `%s'\n", dspname);
        return -1;
    freq = req->freq;
    nchannels = req->nchannels;
    fmt = req->fmt;
    if (ioctl (fd, SNDCTL_DSP_SAMPLESIZE, &fmt)) {
        oss_logerr2 (errno, typ, "Failed to set sample size %d\n", req->fmt);
    if (ioctl (fd, SNDCTL_DSP_CHANNELS, &nchannels)) {
        oss_logerr2 (errno, typ, "Failed to set number of channels %d\n",
                     req->nchannels);
    if (ioctl (fd, SNDCTL_DSP_SPEED, &freq)) {
        oss_logerr2 (errno, typ, "Failed to set frequency %d\n", req->freq);
    if (ioctl (fd, SNDCTL_DSP_NONBLOCK)) {
        oss_logerr2 (errno, typ, "Failed to set non-blocking mode\n");
    mmmmssss = (req->nfrags << 16) | lsbindex (req->fragsize);
    if (ioctl (fd, SNDCTL_DSP_SETFRAGMENT, &mmmmssss)) {
        oss_logerr2 (errno, typ, "Failed to set buffer length (%d, %d)\n",
                     req->nfrags, req->fragsize);
    if (ioctl (fd, in ? SNDCTL_DSP_GETISPACE : SNDCTL_DSP_GETOSPACE, &abinfo)) {
        oss_logerr2 (errno, typ, "Failed to get buffer length\n");
    obt->fmt = fmt;
    obt->nchannels = nchannels;
    obt->freq = freq;
    obt->nfrags = abinfo.fragstotal;
    obt->fragsize = abinfo.fragsize;
    *pfd = fd;
#ifdef DEBUG_MISMATCHES
    if ((req->fmt != obt->fmt) ||
        (req->nchannels != obt->nchannels) ||
        (req->freq != obt->freq) ||
        (req->fragsize != obt->fragsize) ||
        (req->nfrags != obt->nfrags)) {
        dolog ("Audio parameters mismatch\n");
        oss_dump_info (req, obt);
#endif
#ifdef DEBUG
    oss_dump_info (req, obt);
#endif
    return 0;
 err:
    oss_anal_close (&fd);
    return -1;
static int oss_open (int in, struct oss_params *req,
                     struct oss_params *obt, int *pfd)
{
    int fd;
    int mmmmssss;
    audio_buf_info abinfo;
    int fmt, freq, nchannels;
    const char *dspname = in ? conf.devpath_in : conf.devpath_out;
    const char *typ = in ? "ADC" : "DAC";
    fd = open (dspname, (in ? O_RDONLY : O_WRONLY) | O_NONBLOCK);
    if (-1 == fd) {
        oss_logerr2 (errno, typ, "Failed to open `%s'\n", dspname);
        return -1;
    freq = req->freq;
    nchannels = req->nchannels;
    fmt = req->fmt;
    if (ioctl (fd, SNDCTL_DSP_SAMPLESIZE, &fmt)) {
        oss_logerr2 (errno, typ, "Failed to set sample size %d\n", req->fmt);
    if (ioctl (fd, SNDCTL_DSP_CHANNELS, &nchannels)) {
        oss_logerr2 (errno, typ, "Failed to set number of channels %d\n",
                     req->nchannels);
    if (ioctl (fd, SNDCTL_DSP_SPEED, &freq)) {
        oss_logerr2 (errno, typ, "Failed to set frequency %d\n", req->freq);
    if (ioctl (fd, SNDCTL_DSP_NONBLOCK)) {
        oss_logerr2 (errno, typ, "Failed to set non-blocking mode\n");
    mmmmssss = (req->nfrags << 16) | lsbindex (req->fragsize);
    if (ioctl (fd, SNDCTL_DSP_SETFRAGMENT, &mmmmssss)) {
        oss_logerr2 (errno, typ, "Failed to set buffer length (%d, %d)\n",
                     req->nfrags, req->fragsize);
    if (ioctl (fd, in ? SNDCTL_DSP_GETISPACE : SNDCTL_DSP_GETOSPACE, &abinfo)) {
        oss_logerr2 (errno, typ, "Failed to get buffer length\n");
    obt->fmt = fmt;
    obt->nchannels = nchannels;
    obt->freq = freq;
    obt->nfrags = abinfo.fragstotal;
    obt->fragsize = abinfo.fragsize;
    *pfd = fd;
#ifdef DEBUG_MISMATCHES
    if ((req->fmt != obt->fmt) ||
        (req->nchannels != obt->nchannels) ||
        (req->freq != obt->freq) ||
        (req->fragsize != obt->fragsize) ||
        (req->nfrags != obt->nfrags)) {
        dolog ("Audio parameters mismatch\n");
        oss_dump_info (req, obt);
#endif
#ifdef DEBUG
    oss_dump_info (req, obt);
#endif
    return 0;
 err:
    oss_anal_close (&fd);
    return -1;
static int FUNC_0 (int VAR_0, struct oss_params *VAR_1,
                     struct oss_params *VAR_2, int *VAR_3)
{
    int VAR_4;
    int VAR_5;
    audio_buf_info abinfo;
    int VAR_6, VAR_7, VAR_8;
    const char *VAR_9 = VAR_0 ? conf.devpath_in : conf.devpath_out;
    const char *VAR_10 = VAR_0 ? "ADC" : "DAC";
    VAR_4 = open (VAR_9, (VAR_0 ? O_RDONLY : O_WRONLY) | O_NONBLOCK);
    if (-1 == VAR_4) {
        oss_logerr2 (errno, VAR_10, "Failed to open `%s'\n", VAR_9);
        return -1;
    VAR_7 = VAR_1->VAR_7;
    VAR_8 = VAR_1->VAR_8;
    VAR_6 = VAR_1->VAR_6;
    if (ioctl (VAR_4, SNDCTL_DSP_SAMPLESIZE, &VAR_6)) {
        oss_logerr2 (errno, VAR_10, "Failed to set sample size %d\n", VAR_1->VAR_6);
    if (ioctl (VAR_4, SNDCTL_DSP_CHANNELS, &VAR_8)) {
        oss_logerr2 (errno, VAR_10, "Failed to set number of channels %d\n",
                     VAR_1->VAR_8);
    if (ioctl (VAR_4, SNDCTL_DSP_SPEED, &VAR_7)) {
        oss_logerr2 (errno, VAR_10, "Failed to set frequency %d\n", VAR_1->VAR_7);
    if (ioctl (VAR_4, SNDCTL_DSP_NONBLOCK)) {
        oss_logerr2 (errno, VAR_10, "Failed to set non-blocking mode\n");
    VAR_5 = (VAR_1->nfrags << 16) | lsbindex (VAR_1->fragsize);
    if (ioctl (VAR_4, SNDCTL_DSP_SETFRAGMENT, &VAR_5)) {
        oss_logerr2 (errno, VAR_10, "Failed to set buffer length (%d, %d)\n",
                     VAR_1->nfrags, VAR_1->fragsize);
    if (ioctl (VAR_4, VAR_0 ? SNDCTL_DSP_GETISPACE : SNDCTL_DSP_GETOSPACE, &abinfo)) {
        oss_logerr2 (errno, VAR_10, "Failed to get buffer length\n");
    VAR_2->VAR_6 = VAR_6;
    VAR_2->VAR_8 = VAR_8;
    VAR_2->VAR_7 = VAR_7;
    VAR_2->nfrags = abinfo.fragstotal;
    VAR_2->fragsize = abinfo.fragsize;
    *VAR_3 = VAR_4;
#ifdef DEBUG_MISMATCHES
    if ((VAR_1->VAR_6 != VAR_2->VAR_6) ||
        (VAR_1->VAR_8 != VAR_2->VAR_8) ||
        (VAR_1->VAR_7 != VAR_2->VAR_7) ||
        (VAR_1->fragsize != VAR_2->fragsize) ||
        (VAR_1->nfrags != VAR_2->nfrags)) {
        dolog ("Audio parameters mismatch\n");
        oss_dump_info (VAR_1, VAR_2);
#endif
#ifdef DEBUG
    oss_dump_info (VAR_1, VAR_2);
#endif
    return 0;
 err:
    oss_anal_close (&VAR_4);
    return -1;
static int FUNC_0 (int VAR_0, struct oss_params *VAR_1,
struct oss_params *VAR_2, int *VAR_3)
{ int VAR_4; int VAR_5; audio_buf_info abinfo; int VAR_6, VAR_7, VAR_8; const char *VAR_9 = VAR_0 ? conf.devpath_in : conf.devpath_out; const char *VAR_10 = VAR_0 ? "ADC" : "DAC"; VAR_4 = open (VAR_9, (VAR_0 ? O_RDONLY : O_WRONLY) | O_NONBLOCK); if (-1 == VAR_4) { oss_logerr2 (errno, VAR_10, "Failed to open `%s'\n", VAR_9); return -1; VAR_7 = VAR_1->VAR_7; VAR_8 = VAR_1->VAR_8; VAR_6 = VAR_1->VAR_6; if (ioctl (VAR_4, SNDCTL_DSP_SAMPLESIZE, &VAR_6)) { oss_logerr2 (errno, VAR_10, "Failed to set sample size %d\n", VAR_1->VAR_6); if (ioctl (VAR_4, SNDCTL_DSP_CHANNELS, &VAR_8)) { oss_logerr2 (errno, VAR_10, "Failed to set number of channels %d\n",
VAR_1->VAR_8); if (ioctl (VAR_4, SNDCTL_DSP_SPEED, &VAR_7)) { oss_logerr2 (errno, VAR_10, "Failed to set frequency %d\n", VAR_1->VAR_7); if (ioctl (VAR_4, SNDCTL_DSP_NONBLOCK)) { oss_logerr2 (errno, VAR_10, "Failed to set non-blocking mode\n"); VAR_5 = (VAR_1->nfrags << 16) | lsbindex (VAR_1->fragsize); if (ioctl (VAR_4, SNDCTL_DSP_SETFRAGMENT, &VAR_5)) { oss_logerr2 (errno, VAR_10, "Failed to set buffer length (%d, %d)\n",
VAR_1->nfrags, VAR_1->fragsize); if (ioctl (VAR_4, VAR_0 ? SNDCTL_DSP_GETISPACE : SNDCTL_DSP_GETOSPACE, &abinfo)) { oss_logerr2 (errno, VAR_10, "Failed to get buffer length\n"); VAR_2->VAR_6 = VAR_6; VAR_2->VAR_8 = VAR_8; VAR_2->VAR_7 = VAR_7; VAR_2->nfrags = abinfo.fragstotal; VAR_2->fragsize = abinfo.fragsize; *VAR_3 = VAR_4; #ifdef DEBUG_MISMATCHES
if ((VAR_1->VAR_6 != VAR_2->VAR_6) ||
(VAR_1->VAR_8 != VAR_2->VAR_8) ||
(VAR_1->VAR_7 != VAR_2->VAR_7) ||
(VAR_1->fragsize != VAR_2->fragsize) ||
(VAR_1->nfrags != VAR_2->nfrags)) { dolog ("Audio parameters mismatch\n"); oss_dump_info (VAR_1, VAR_2); #endif
#ifdef DEBUG
oss_dump_info (VAR_1, VAR_2); #endif
return 0; err:
oss_anal_close (&VAR_4); return -1;