Ignore:
Timestamp:
Mar 19, 2014, 11:11:30 AM (11 years ago)
Author:
dmik
Message:

python: Update vendor to 2.7.6.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/vendor/current/Modules/linuxaudiodev.c

    r2 r388  
    1 /* Hey Emacs, this is -*-C-*- 
     1/* Hey Emacs, this is -*-C-*-
    22 ******************************************************************************
    33 * linuxaudiodev.c -- Linux audio device for python.
    4  * 
     4 *
    55 * Author          : Peter Bosch
    66 * Created On      : Thu Mar  2 21:10:33 2000
    77 * Status          : Unknown, Use with caution!
    8  * 
     8 *
    99 * Unless other notices are present in any part of this file
    10  * explicitly claiming copyrights for other people and/or 
    11  * organizations, the contents of this file is fully copyright 
     10 * explicitly claiming copyrights for other people and/or
     11 * organizations, the contents of this file is fully copyright
    1212 * (C) 2000 Peter Bosch, all rights reserved.
    1313 ******************************************************************************
     
    4444typedef struct {
    4545    PyObject_HEAD
    46     int         x_fd;           /* The open file */
     46    int         x_fd;           /* The open file */
    4747    int         x_mode;           /* file mode */
    48     int         x_icount;       /* Input count */
    49     int         x_ocount;       /* Output count */
    50     uint32_t    x_afmts;        /* Audio formats supported by hardware*/
     48    int         x_icount;       /* Input count */
     49    int         x_ocount;       /* Output count */
     50    uint32_t    x_afmts;        /* Audio formats supported by hardware*/
    5151} lad_t;
    5252
     
    5656
    5757static struct {
    58     int         a_bps;
    59     uint32_t    a_fmt;
     58    int         a_bps;
     59    uint32_t    a_fmt;
    6060    char       *a_name;
    6161} audio_types[] = {
    62     {  8,       AFMT_MU_LAW, "logarithmic mu-law 8-bit audio" },
    63     {  8,       AFMT_A_LAW,  "logarithmic A-law 8-bit audio" },
    64     {  8,       AFMT_U8,     "linear unsigned 8-bit audio" },
    65     {  8,       AFMT_S8,     "linear signed 8-bit audio" },
    66     { 16,       AFMT_U16_BE, "linear unsigned 16-bit big-endian audio" },
    67     { 16,       AFMT_U16_LE, "linear unsigned 16-bit little-endian audio" },
    68     { 16,       AFMT_S16_BE, "linear signed 16-bit big-endian audio" },
    69     { 16,       AFMT_S16_LE, "linear signed 16-bit little-endian audio" },
    70     { 16,       AFMT_S16_NE, "linear signed 16-bit native-endian audio" },
     62    {  8,       AFMT_MU_LAW, "logarithmic mu-law 8-bit audio" },
     63    {  8,       AFMT_A_LAW,  "logarithmic A-law 8-bit audio" },
     64    {  8,       AFMT_U8,     "linear unsigned 8-bit audio" },
     65    {  8,       AFMT_S8,     "linear signed 8-bit audio" },
     66    { 16,       AFMT_U16_BE, "linear unsigned 16-bit big-endian audio" },
     67    { 16,       AFMT_U16_LE, "linear unsigned 16-bit little-endian audio" },
     68    { 16,       AFMT_S16_BE, "linear signed 16-bit big-endian audio" },
     69    { 16,       AFMT_S16_LE, "linear signed 16-bit little-endian audio" },
     70    { 16,       AFMT_S16_NE, "linear signed 16-bit native-endian audio" },
    7171};
    7272
     
    109109     * AUDIODEV environment variable first, then /dev/dsp.  The
    110110     * control device tacks "ctl" onto the base device name.
    111      * 
     111     *
    112112     * Note that the only difference between /dev/audio and /dev/dsp
    113113     * is that the former uses logarithmic mu-law encoding and the
     
    150150    /* if already closed, don't reclose it */
    151151    if (xp->x_fd != -1)
    152         close(xp->x_fd);
     152        close(xp->x_fd);
    153153    PyObject_Del(xp);
    154154}
     
    160160    char *cp;
    161161    PyObject *rv;
    162        
     162
    163163    if (!PyArg_ParseTuple(args, "i:read", &size))
    164164        return NULL;
     
    185185    struct timeval tv;
    186186    int select_retval;
    187    
    188     if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) 
    189         return NULL;
     187
     188    if (!PyArg_ParseTuple(args, "s#:write", &cp, &size))
     189        return NULL;
    190190
    191191    /* use select to wait for audio device to be available */
     
    193193    FD_SET(self->x_fd, &write_set_fds);
    194194    tv.tv_sec = 4; /* timeout values */
    195     tv.tv_usec = 0; 
     195    tv.tv_usec = 0;
    196196
    197197    while (size > 0) {
     
    200200      if (select_retval) {
    201201        if ((rv = write(self->x_fd, cp, size)) == -1) {
    202           if (errno != EAGAIN) {
    203             PyErr_SetFromErrno(LinuxAudioError);
    204             return NULL;
    205           } else {
    206             errno = 0; /* EAGAIN: buffer is full, try again */
    207           }
     202          if (errno != EAGAIN) {
     203            PyErr_SetFromErrno(LinuxAudioError);
     204            return NULL;
     205          } else {
     206            errno = 0; /* EAGAIN: buffer is full, try again */
     207          }
    208208        } else {
    209           self->x_ocount += rv;
    210           size -= rv;
    211           cp += rv;
    212         }
     209          self->x_ocount += rv;
     210          size -= rv;
     211          cp += rv;
     212        }
    213213      } else {
    214         /* printf("Not able to write to linux audio device within %ld seconds\n", tv.tv_sec); */
    215         PyErr_SetFromErrno(LinuxAudioError);
    216         return NULL;
     214        /* printf("Not able to write to linux audio device within %ld seconds\n", tv.tv_sec); */
     215        PyErr_SetFromErrno(LinuxAudioError);
     216        return NULL;
    217217      }
    218218    }
     
    245245                          &rate, &ssize, &nchannels, &fmt, &emulate))
    246246        return NULL;
    247  
     247
    248248    if (rate < 0) {
    249         PyErr_Format(PyExc_ValueError, "expected rate >= 0, not %d",
    250                      rate);
    251         return NULL;
     249        PyErr_Format(PyExc_ValueError, "expected rate >= 0, not %d",
     250                     rate);
     251        return NULL;
    252252    }
    253253    if (ssize < 0) {
    254         PyErr_Format(PyExc_ValueError, "expected sample size >= 0, not %d",
    255                      ssize);
    256         return NULL;
     254        PyErr_Format(PyExc_ValueError, "expected sample size >= 0, not %d",
     255                     ssize);
     256        return NULL;
    257257    }
    258258    if (nchannels != 1 && nchannels != 2) {
    259         PyErr_Format(PyExc_ValueError, "nchannels must be 1 or 2, not %d",
    260                      nchannels);
    261         return NULL;
     259        PyErr_Format(PyExc_ValueError, "nchannels must be 1 or 2, not %d",
     260                     nchannels);
     261        return NULL;
    262262    }
    263263
     
    266266            break;
    267267    if (n == n_audio_types) {
    268         PyErr_Format(PyExc_ValueError, "unknown audio encoding: %d", fmt);
    269         return NULL;
     268        PyErr_Format(PyExc_ValueError, "unknown audio encoding: %d", fmt);
     269        return NULL;
    270270    }
    271271    if (audio_types[n].a_bps != ssize) {
    272         PyErr_Format(PyExc_ValueError,
    273                      "for %s, expected sample size %d, not %d",
    274                      audio_types[n].a_name, audio_types[n].a_bps, ssize);
    275         return NULL;
     272        PyErr_Format(PyExc_ValueError,
     273                     "for %s, expected sample size %d, not %d",
     274                     audio_types[n].a_name, audio_types[n].a_bps, ssize);
     275        return NULL;
    276276    }
    277277
    278278    if (emulate == 0) {
    279         if ((self->x_afmts & audio_types[n].a_fmt) == 0) {
    280             PyErr_Format(PyExc_ValueError,
    281                         "%s format not supported by device",
    282                         audio_types[n].a_name);
    283             return NULL;
    284         }
    285     }
    286     if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, 
    287               &audio_types[n].a_fmt) == -1) {
     279        if ((self->x_afmts & audio_types[n].a_fmt) == 0) {
     280            PyErr_Format(PyExc_ValueError,
     281                        "%s format not supported by device",
     282                        audio_types[n].a_name);
     283            return NULL;
     284        }
     285    }
     286    if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT,
     287              &audio_types[n].a_fmt) == -1) {
    288288        PyErr_SetFromErrno(LinuxAudioError);
    289289        return NULL;
     
    308308
    309309    fmt = 0;
    310     if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, &fmt) < 0) 
     310    if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
    311311        return -errno;
    312312
     
    335335
    336336
    337 /* bufsize returns the size of the hardware audio buffer in number 
     337/* bufsize returns the size of the hardware audio buffer in number
    338338   of samples */
    339339static PyObject *
     
    354354}
    355355
    356 /* obufcount returns the number of samples that are available in the 
     356/* obufcount returns the number of samples that are available in the
    357357   hardware for playing */
    358358static PyObject *
     
    370370        return NULL;
    371371    }
    372     return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) / 
     372    return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
    373373                          (ssize * nchannels));
    374374}
     
    411411
    412412    if (self->x_mode == O_RDONLY)
    413         req = SNDCTL_DSP_GETIPTR;
     413        req = SNDCTL_DSP_GETIPTR;
    414414    else
    415         req = SNDCTL_DSP_GETOPTR;
     415        req = SNDCTL_DSP_GETOPTR;
    416416    if (ioctl(self->x_fd, req, &info) == -1) {
    417417        PyErr_SetFromErrno(LinuxAudioError);
     
    422422
    423423static PyMethodDef lad_methods[] = {
    424     { "read",           (PyCFunction)lad_read, METH_VARARGS },
    425     { "write",          (PyCFunction)lad_write, METH_VARARGS },
    426     { "setparameters",  (PyCFunction)lad_setparameters, METH_VARARGS },
    427     { "bufsize",        (PyCFunction)lad_bufsize, METH_VARARGS },
    428     { "obufcount",      (PyCFunction)lad_obufcount, METH_NOARGS },
    429     { "obuffree",       (PyCFunction)lad_obuffree, METH_NOARGS },
    430     { "flush",          (PyCFunction)lad_flush, METH_NOARGS },
    431     { "close",          (PyCFunction)lad_close, METH_NOARGS },
    432     { "fileno",         (PyCFunction)lad_fileno, METH_NOARGS },
     424    { "read",           (PyCFunction)lad_read, METH_VARARGS },
     425    { "write",          (PyCFunction)lad_write, METH_VARARGS },
     426    { "setparameters",  (PyCFunction)lad_setparameters, METH_VARARGS },
     427    { "bufsize",        (PyCFunction)lad_bufsize, METH_VARARGS },
     428    { "obufcount",      (PyCFunction)lad_obufcount, METH_NOARGS },
     429    { "obuffree",       (PyCFunction)lad_obuffree, METH_NOARGS },
     430    { "flush",          (PyCFunction)lad_flush, METH_NOARGS },
     431    { "close",          (PyCFunction)lad_close, METH_NOARGS },
     432    { "fileno",         (PyCFunction)lad_fileno, METH_NOARGS },
    433433    { "getptr",         (PyCFunction)lad_getptr, METH_NOARGS },
    434     { NULL,             NULL}           /* sentinel */
     434    { NULL,             NULL}           /* sentinel */
    435435};
    436436
     
    444444    PyVarObject_HEAD_INIT(&PyType_Type, 0)
    445445    "linuxaudiodev.linux_audio_device", /*tp_name*/
    446     sizeof(lad_t),              /*tp_size*/
    447     0,                          /*tp_itemsize*/
     446    sizeof(lad_t),              /*tp_size*/
     447    0,                          /*tp_itemsize*/
    448448    /* methods */
    449     (destructor)lad_dealloc,    /*tp_dealloc*/
    450     0,                          /*tp_print*/
    451     (getattrfunc)lad_getattr,   /*tp_getattr*/
    452     0,                          /*tp_setattr*/
    453     0,                          /*tp_compare*/
    454     0,                          /*tp_repr*/
     449    (destructor)lad_dealloc,    /*tp_dealloc*/
     450    0,                          /*tp_print*/
     451    (getattrfunc)lad_getattr,   /*tp_getattr*/
     452    0,                          /*tp_setattr*/
     453    0,                          /*tp_compare*/
     454    0,                          /*tp_repr*/
    455455};
    456456
     
    470470{
    471471    PyObject *m;
    472    
     472
    473473    if (PyErr_WarnPy3k("the linuxaudiodev module has been removed in "
    474474                    "Python 3.0; use the ossaudiodev module instead", 2) < 0)
    475475        return;
    476  
     476
    477477    m = Py_InitModule("linuxaudiodev", linuxaudiodev_methods);
    478478    if (m == NULL)
    479         return;
     479        return;
    480480
    481481    LinuxAudioError = PyErr_NewException("linuxaudiodev.error", NULL, NULL);
    482482    if (LinuxAudioError)
    483         PyModule_AddObject(m, "error", LinuxAudioError);
     483        PyModule_AddObject(m, "error", LinuxAudioError);
    484484
    485485    if (PyModule_AddIntConstant(m, "AFMT_MU_LAW", (long)AFMT_MU_LAW) == -1)
    486         return;
     486        return;
    487487    if (PyModule_AddIntConstant(m, "AFMT_A_LAW", (long)AFMT_A_LAW) == -1)
    488         return;
     488        return;
    489489    if (PyModule_AddIntConstant(m, "AFMT_U8", (long)AFMT_U8) == -1)
    490         return;
     490        return;
    491491    if (PyModule_AddIntConstant(m, "AFMT_S8", (long)AFMT_S8) == -1)
    492         return;
     492        return;
    493493    if (PyModule_AddIntConstant(m, "AFMT_U16_BE", (long)AFMT_U16_BE) == -1)
    494         return;
     494        return;
    495495    if (PyModule_AddIntConstant(m, "AFMT_U16_LE", (long)AFMT_U16_LE) == -1)
    496         return;
     496        return;
    497497    if (PyModule_AddIntConstant(m, "AFMT_S16_BE", (long)AFMT_S16_BE) == -1)
    498         return;
     498        return;
    499499    if (PyModule_AddIntConstant(m, "AFMT_S16_LE", (long)AFMT_S16_LE) == -1)
    500         return;
     500        return;
    501501    if (PyModule_AddIntConstant(m, "AFMT_S16_NE", (long)AFMT_S16_NE) == -1)
    502         return;
     502        return;
    503503
    504504    return;
Note: See TracChangeset for help on using the changeset viewer.