mirror of
https://github.com/python/cpython.git
synced 2024-12-01 13:55:45 +08:00
Rename LinuxAudioError to OSSAudioError ('ossaudiodev.error').
Use OSSAudioError much less frequently -- all real I/O errors (ie. any time open(), read(), write(), ioctl(), or select() return an error) become IOError. OSSAudioError is only used now for bad open() mode.
This commit is contained in:
parent
1e0f57d0bb
commit
97708bc6f8
@ -77,7 +77,7 @@ static int n_audio_types = sizeof(audio_types) / sizeof(audio_types[0]);
|
|||||||
|
|
||||||
static PyTypeObject Ladtype;
|
static PyTypeObject Ladtype;
|
||||||
|
|
||||||
static PyObject *LinuxAudioError;
|
static PyObject *OSSAudioError;
|
||||||
|
|
||||||
static lad_t *
|
static lad_t *
|
||||||
newladobject(PyObject *arg)
|
newladobject(PyObject *arg)
|
||||||
@ -106,7 +106,7 @@ newladobject(PyObject *arg)
|
|||||||
else if (strcmp(mode, "rw") == 0)
|
else if (strcmp(mode, "rw") == 0)
|
||||||
imode = O_RDWR;
|
imode = O_RDWR;
|
||||||
else {
|
else {
|
||||||
PyErr_SetString(LinuxAudioError, "mode must be 'r', 'w', or 'rw'");
|
PyErr_SetString(OSSAudioError, "mode must be 'r', 'w', or 'rw'");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,11 +126,11 @@ newladobject(PyObject *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((fd = open(basedev, imode)) == -1) {
|
if ((fd = open(basedev, imode)) == -1) {
|
||||||
PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev);
|
PyErr_SetFromErrnoWithFilename(PyExc_IOError, basedev);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) == -1) {
|
if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) == -1) {
|
||||||
PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev);
|
PyErr_SetFromErrnoWithFilename(PyExc_IOError, basedev);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* Create and initialize the object */
|
/* Create and initialize the object */
|
||||||
@ -184,7 +184,7 @@ _do_ioctl_1(lad_t *self, PyObject *args, char *fname, int cmd)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (ioctl(self->x_fd, cmd, &arg) == -1)
|
if (ioctl(self->x_fd, cmd, &arg) == -1)
|
||||||
return PyErr_SetFromErrno(LinuxAudioError);
|
return PyErr_SetFromErrno(PyExc_IOError);
|
||||||
return PyInt_FromLong(arg);
|
return PyInt_FromLong(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,7 +201,7 @@ _do_ioctl_0(lad_t *self, PyObject *args, char *fname, int cmd)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (ioctl(self->x_fd, cmd, 0) == -1)
|
if (ioctl(self->x_fd, cmd, 0) == -1)
|
||||||
return PyErr_SetFromErrno(LinuxAudioError);
|
return PyErr_SetFromErrno(PyExc_IOError);
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
@ -215,7 +215,7 @@ lad_nonblock(lad_t *self, PyObject *args)
|
|||||||
if (!PyArg_ParseTuple(args, ":nonblock"))
|
if (!PyArg_ParseTuple(args, ":nonblock"))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (ioctl(self->x_fd, SNDCTL_DSP_NONBLOCK, NULL) == -1)
|
if (ioctl(self->x_fd, SNDCTL_DSP_NONBLOCK, NULL) == -1)
|
||||||
return PyErr_SetFromErrno(LinuxAudioError);
|
return PyErr_SetFromErrno(PyExc_IOError);
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
@ -233,7 +233,7 @@ lad_getfmts(lad_t *self, PyObject *args)
|
|||||||
if (!PyArg_ParseTuple(args, ":getfmts"))
|
if (!PyArg_ParseTuple(args, ":getfmts"))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (ioctl(self->x_fd, SNDCTL_DSP_GETFMTS, &mask) == -1)
|
if (ioctl(self->x_fd, SNDCTL_DSP_GETFMTS, &mask) == -1)
|
||||||
return PyErr_SetFromErrno(LinuxAudioError);
|
return PyErr_SetFromErrno(PyExc_IOError);
|
||||||
return PyInt_FromLong(mask);
|
return PyInt_FromLong(mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,7 +285,7 @@ lad_read(lad_t *self, PyObject *args)
|
|||||||
return NULL;
|
return NULL;
|
||||||
cp = PyString_AS_STRING(rv);
|
cp = PyString_AS_STRING(rv);
|
||||||
if ((count = read(self->x_fd, cp, size)) < 0) {
|
if ((count = read(self->x_fd, cp, size)) < 0) {
|
||||||
PyErr_SetFromErrno(LinuxAudioError);
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
Py_DECREF(rv);
|
Py_DECREF(rv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -304,7 +304,7 @@ lad_write(lad_t *self, PyObject *args)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if ((rv = write(self->x_fd, cp, size)) == -1) {
|
if ((rv = write(self->x_fd, cp, size)) == -1) {
|
||||||
return PyErr_SetFromErrno(LinuxAudioError);
|
return PyErr_SetFromErrno(PyExc_IOError);
|
||||||
} else {
|
} else {
|
||||||
self->x_ocount += rv;
|
self->x_ocount += rv;
|
||||||
}
|
}
|
||||||
@ -337,7 +337,7 @@ lad_writeall(lad_t *self, PyObject *args)
|
|||||||
select_rv = select(self->x_fd+1, NULL, &write_set_fds, NULL, NULL);
|
select_rv = select(self->x_fd+1, NULL, &write_set_fds, NULL, NULL);
|
||||||
assert(select_rv != 0); /* no timeout, can't expire */
|
assert(select_rv != 0); /* no timeout, can't expire */
|
||||||
if (select_rv == -1)
|
if (select_rv == -1)
|
||||||
return PyErr_SetFromErrno(LinuxAudioError);
|
return PyErr_SetFromErrno(PyExc_IOError);
|
||||||
|
|
||||||
rv = write(self->x_fd, cp, size);
|
rv = write(self->x_fd, cp, size);
|
||||||
if (rv == -1) {
|
if (rv == -1) {
|
||||||
@ -345,7 +345,7 @@ lad_writeall(lad_t *self, PyObject *args)
|
|||||||
errno = 0;
|
errno = 0;
|
||||||
continue;
|
continue;
|
||||||
} else /* it's a real error */
|
} else /* it's a real error */
|
||||||
return PyErr_SetFromErrno(LinuxAudioError);
|
return PyErr_SetFromErrno(PyExc_IOError);
|
||||||
} else { /* wrote rv bytes */
|
} else { /* wrote rv bytes */
|
||||||
self->x_ocount += rv;
|
self->x_ocount += rv;
|
||||||
size -= rv;
|
size -= rv;
|
||||||
@ -431,15 +431,15 @@ lad_setparameters(lad_t *self, PyObject *args)
|
|||||||
}
|
}
|
||||||
if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT,
|
if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT,
|
||||||
&audio_types[n].a_fmt) == -1) {
|
&audio_types[n].a_fmt) == -1) {
|
||||||
PyErr_SetFromErrno(LinuxAudioError);
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, &nchannels) == -1) {
|
if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, &nchannels) == -1) {
|
||||||
PyErr_SetFromErrno(LinuxAudioError);
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (ioctl(self->x_fd, SNDCTL_DSP_SPEED, &rate) == -1) {
|
if (ioctl(self->x_fd, SNDCTL_DSP_SPEED, &rate) == -1) {
|
||||||
PyErr_SetFromErrno(LinuxAudioError);
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -492,11 +492,11 @@ lad_bufsize(lad_t *self, PyObject *args)
|
|||||||
if (!PyArg_ParseTuple(args, ":bufsize")) return NULL;
|
if (!PyArg_ParseTuple(args, ":bufsize")) return NULL;
|
||||||
|
|
||||||
if (_ssize(self, &nchannels, &ssize) < 0) {
|
if (_ssize(self, &nchannels, &ssize) < 0) {
|
||||||
PyErr_SetFromErrno(LinuxAudioError);
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
|
if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
|
||||||
PyErr_SetFromErrno(LinuxAudioError);
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return PyInt_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize));
|
return PyInt_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize));
|
||||||
@ -514,11 +514,11 @@ lad_obufcount(lad_t *self, PyObject *args)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (_ssize(self, &nchannels, &ssize) < 0) {
|
if (_ssize(self, &nchannels, &ssize) < 0) {
|
||||||
PyErr_SetFromErrno(LinuxAudioError);
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
|
if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
|
||||||
PyErr_SetFromErrno(LinuxAudioError);
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
|
return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
|
||||||
@ -537,11 +537,11 @@ lad_obuffree(lad_t *self, PyObject *args)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (_ssize(self, &nchannels, &ssize) < 0) {
|
if (_ssize(self, &nchannels, &ssize) < 0) {
|
||||||
PyErr_SetFromErrno(LinuxAudioError);
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
|
if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
|
||||||
PyErr_SetFromErrno(LinuxAudioError);
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return PyInt_FromLong(ai.bytes / (ssize * nchannels));
|
return PyInt_FromLong(ai.bytes / (ssize * nchannels));
|
||||||
@ -561,7 +561,7 @@ lad_getptr(lad_t *self, PyObject *args)
|
|||||||
else
|
else
|
||||||
req = SNDCTL_DSP_GETOPTR;
|
req = SNDCTL_DSP_GETOPTR;
|
||||||
if (ioctl(self->x_fd, req, &info) == -1) {
|
if (ioctl(self->x_fd, req, &info) == -1) {
|
||||||
PyErr_SetFromErrno(LinuxAudioError);
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr);
|
return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr);
|
||||||
@ -641,9 +641,9 @@ initlinuxaudiodev(void)
|
|||||||
|
|
||||||
m = Py_InitModule("linuxaudiodev", linuxaudiodev_methods);
|
m = Py_InitModule("linuxaudiodev", linuxaudiodev_methods);
|
||||||
|
|
||||||
LinuxAudioError = PyErr_NewException("linuxaudiodev.error", NULL, NULL);
|
OSSAudioError = PyErr_NewException("ossaudiodev.error", NULL, NULL);
|
||||||
if (LinuxAudioError)
|
if (OSSAudioError)
|
||||||
PyModule_AddObject(m, "error", LinuxAudioError);
|
PyModule_AddObject(m, "error", OSSAudioError);
|
||||||
|
|
||||||
/* Expose the audio format numbers -- essential! */
|
/* Expose the audio format numbers -- essential! */
|
||||||
_EXPORT_INT(m, AFMT_QUERY);
|
_EXPORT_INT(m, AFMT_QUERY);
|
||||||
|
Loading…
Reference in New Issue
Block a user