static int oss_open (int in, struct oss_params *req,

                     struct oss_params *obt, int *pfd)

{

    int fd;

    int oflags;

    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";



    /* Kludge needed to have working mmap on Linux */

    oflags = conf.try_mmap ? O_RDWR : (in ? O_RDONLY : O_WRONLY);

    fd = open (dspname, oflags | 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);

        goto err;

    }



    if (ioctl (fd, SNDCTL_DSP_CHANNELS, &nchannels)) {

        oss_logerr2 (errno, typ, "Failed to set number of channels %d\n",

                     req->nchannels);

        goto err;

    }



    if (ioctl (fd, SNDCTL_DSP_SPEED, &freq)) {

        oss_logerr2 (errno, typ, "Failed to set frequency %d\n", req->freq);

        goto err;

    }



    if (ioctl (fd, SNDCTL_DSP_NONBLOCK, NULL)) {

        oss_logerr2 (errno, typ, "Failed to set non-blocking mode\n");

        goto err;

    }



    mmmmssss = (req->nfrags << 16) | ctz32 (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);

        goto err;

    }



    if (ioctl (fd, in ? SNDCTL_DSP_GETISPACE : SNDCTL_DSP_GETOSPACE, &abinfo)) {

        oss_logerr2 (errno, typ, "Failed to get buffer length\n");

        goto err;

    }



    if (!abinfo.fragstotal || !abinfo.fragsize) {

        AUD_log (AUDIO_CAP, "Returned bogus buffer information(%d, %d) for %s\n",

                 abinfo.fragstotal, abinfo.fragsize, typ);

        goto err;

    }



    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 oflags;

    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";



    

    oflags = conf.try_mmap ? O_RDWR : (in ? O_RDONLY : O_WRONLY);

    fd = open (dspname, oflags | 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);

        goto err;

    }



    if (ioctl (fd, SNDCTL_DSP_CHANNELS, &nchannels)) {

        oss_logerr2 (errno, typ, "Failed to set number of channels %d\n",

                     req->nchannels);

        goto err;

    }



    if (ioctl (fd, SNDCTL_DSP_SPEED, &freq)) {

        oss_logerr2 (errno, typ, "Failed to set frequency %d\n", req->freq);

        goto err;

    }



    if (ioctl (fd, SNDCTL_DSP_NONBLOCK, NULL)) {

        oss_logerr2 (errno, typ, "Failed to set non-blocking mode\n");

        goto err;

    }



    mmmmssss = (req->nfrags << 16) | ctz32 (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);

        goto err;

    }



    if (ioctl (fd, in ? SNDCTL_DSP_GETISPACE : SNDCTL_DSP_GETOSPACE, &abinfo)) {

        oss_logerr2 (errno, typ, "Failed to get buffer length\n");

        goto err;

    }



    if (!abinfo.fragstotal || !abinfo.fragsize) {

        AUD_log (AUDIO_CAP, "Returned bogus buffer information(%d, %d) for %s\n",

                 abinfo.fragstotal, abinfo.fragsize, typ);

        goto err;

    }



    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;

    int VAR_6;

    audio_buf_info abinfo;

    int VAR_7, VAR_8, VAR_9;

    const char *VAR_10 = VAR_0 ? conf.devpath_in : conf.devpath_out;

    const char *VAR_11 = VAR_0 ? "ADC" : "DAC";



    

    VAR_5 = conf.try_mmap ? O_RDWR : (VAR_0 ? O_RDONLY : O_WRONLY);

    VAR_4 = open (VAR_10, VAR_5 | O_NONBLOCK);

    if (-1 == VAR_4) {

        oss_logerr2 (errno, VAR_11, "Failed to open `%s'\n", VAR_10);

        return -1;

    }



    VAR_8 = VAR_1->VAR_8;

    VAR_9 = VAR_1->VAR_9;

    VAR_7 = VAR_1->VAR_7;



    if (ioctl (VAR_4, SNDCTL_DSP_SAMPLESIZE, &VAR_7)) {

        oss_logerr2 (errno, VAR_11, "Failed to set sample size %d\n", VAR_1->VAR_7);

        goto err;

    }



    if (ioctl (VAR_4, SNDCTL_DSP_CHANNELS, &VAR_9)) {

        oss_logerr2 (errno, VAR_11, "Failed to set number of channels %d\n",

                     VAR_1->VAR_9);

        goto err;

    }



    if (ioctl (VAR_4, SNDCTL_DSP_SPEED, &VAR_8)) {

        oss_logerr2 (errno, VAR_11, "Failed to set frequency %d\n", VAR_1->VAR_8);

        goto err;

    }



    if (ioctl (VAR_4, SNDCTL_DSP_NONBLOCK, NULL)) {

        oss_logerr2 (errno, VAR_11, "Failed to set non-blocking mode\n");

        goto err;

    }



    VAR_6 = (VAR_1->nfrags << 16) | ctz32 (VAR_1->fragsize);

    if (ioctl (VAR_4, SNDCTL_DSP_SETFRAGMENT, &VAR_6)) {

        oss_logerr2 (errno, VAR_11, "Failed to set buffer length (%d, %d)\n",

                     VAR_1->nfrags, VAR_1->fragsize);

        goto err;

    }



    if (ioctl (VAR_4, VAR_0 ? SNDCTL_DSP_GETISPACE : SNDCTL_DSP_GETOSPACE, &abinfo)) {

        oss_logerr2 (errno, VAR_11, "Failed to get buffer length\n");

        goto err;

    }



    if (!abinfo.fragstotal || !abinfo.fragsize) {

        AUD_log (AUDIO_CAP, "Returned bogus buffer information(%d, %d) for %s\n",

                 abinfo.fragstotal, abinfo.fragsize, VAR_11);

        goto err;

    }



    VAR_2->VAR_7 = VAR_7;

    VAR_2->VAR_9 = VAR_9;

    VAR_2->VAR_8 = VAR_8;

    VAR_2->nfrags = abinfo.fragstotal;

    VAR_2->fragsize = abinfo.fragsize;

    *VAR_3 = VAR_4;



#ifdef DEBUG_MISMATCHES

    if ((VAR_1->VAR_7 != VAR_2->VAR_7) ||

        (VAR_1->VAR_9 != VAR_2->VAR_9) ||

        (VAR_1->VAR_8 != VAR_2->VAR_8) ||

        (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; int VAR_6; audio_buf_info abinfo; int VAR_7, VAR_8, VAR_9; const char *VAR_10 = VAR_0 ? conf.devpath_in : conf.devpath_out; const char *VAR_11 = VAR_0 ? "ADC" : "DAC"; VAR_5 = conf.try_mmap ? O_RDWR : (VAR_0 ? O_RDONLY : O_WRONLY); VAR_4 = open (VAR_10, VAR_5 | O_NONBLOCK); if (-1 == VAR_4) { oss_logerr2 (errno, VAR_11, "Failed to open `%s'\n", VAR_10); return -1; } VAR_8 = VAR_1->VAR_8; VAR_9 = VAR_1->VAR_9; VAR_7 = VAR_1->VAR_7; if (ioctl (VAR_4, SNDCTL_DSP_SAMPLESIZE, &VAR_7)) { oss_logerr2 (errno, VAR_11, "Failed to set sample size %d\n", VAR_1->VAR_7); goto err; } if (ioctl (VAR_4, SNDCTL_DSP_CHANNELS, &VAR_9)) { oss_logerr2 (errno, VAR_11, "Failed to set number of channels %d\n",
VAR_1->VAR_9); goto err; } if (ioctl (VAR_4, SNDCTL_DSP_SPEED, &VAR_8)) { oss_logerr2 (errno, VAR_11, "Failed to set frequency %d\n", VAR_1->VAR_8); goto err; } if (ioctl (VAR_4, SNDCTL_DSP_NONBLOCK, NULL)) { oss_logerr2 (errno, VAR_11, "Failed to set non-blocking mode\n"); goto err; } VAR_6 = (VAR_1->nfrags << 16) | ctz32 (VAR_1->fragsize); if (ioctl (VAR_4, SNDCTL_DSP_SETFRAGMENT, &VAR_6)) { oss_logerr2 (errno, VAR_11, "Failed to set buffer length (%d, %d)\n",
VAR_1->nfrags, VAR_1->fragsize); goto err; } if (ioctl (VAR_4, VAR_0 ? SNDCTL_DSP_GETISPACE : SNDCTL_DSP_GETOSPACE, &abinfo)) { oss_logerr2 (errno, VAR_11, "Failed to get buffer length\n"); goto err; } if (!abinfo.fragstotal || !abinfo.fragsize) { AUD_log (AUDIO_CAP, "Returned bogus buffer information(%d, %d) for %s\n",
abinfo.fragstotal, abinfo.fragsize, VAR_11); goto err; } VAR_2->VAR_7 = VAR_7; VAR_2->VAR_9 = VAR_9; VAR_2->VAR_8 = VAR_8; VAR_2->nfrags = abinfo.fragstotal; VAR_2->fragsize = abinfo.fragsize; *VAR_3 = VAR_4; #ifdef DEBUG_MISMATCHES
if ((VAR_1->VAR_7 != VAR_2->VAR_7) ||
(VAR_1->VAR_9 != VAR_2->VAR_9) ||
(VAR_1->VAR_8 != VAR_2->VAR_8) ||
(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; }