mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
audio(7I) suggests that applications do the following to get the
device and control pseudo-device: - first look for the device filename in the environment variable AUDIODEV. - if not found, use /dev/audio - calculate the control device by tacking "ctl" onto the base device name. We now do this. Also, if the open fails, we call PyErr_SetFromErrnoWithFilename() to give a more informative error message. Added a fileno() method to the audio object returned from open(). This returns the file descriptor which can be used by applications to set up SIGPOLL notification, as per the manpage.
This commit is contained in:
parent
2c8b35bdd2
commit
b0d1b068d9
1 changed files with 43 additions and 8 deletions
|
@ -79,6 +79,7 @@ static PyObject *SunAudioError;
|
||||||
#define is_sadobject(v) ((v)->ob_type == &Sadtype)
|
#define is_sadobject(v) ((v)->ob_type == &Sadtype)
|
||||||
#define is_sadstatusobject(v) ((v)->ob_type == &Sadstatustype)
|
#define is_sadstatusobject(v) ((v)->ob_type == &Sadstatustype)
|
||||||
|
|
||||||
|
|
||||||
static sadobject *
|
static sadobject *
|
||||||
newsadobject(arg)
|
newsadobject(arg)
|
||||||
PyObject *arg;
|
PyObject *arg;
|
||||||
|
@ -87,6 +88,9 @@ newsadobject(arg)
|
||||||
int fd;
|
int fd;
|
||||||
char *mode;
|
char *mode;
|
||||||
int imode;
|
int imode;
|
||||||
|
char* basedev;
|
||||||
|
char* ctldev;
|
||||||
|
char* opendev;
|
||||||
|
|
||||||
/* Check arg for r/w/rw */
|
/* Check arg for r/w/rw */
|
||||||
if (!PyArg_Parse(arg, "s", &mode))
|
if (!PyArg_Parse(arg, "s", &mode))
|
||||||
|
@ -105,16 +109,34 @@ newsadobject(arg)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open the correct device */
|
/* Open the correct device. The base device name comes from the
|
||||||
if (imode < 0)
|
* AUDIODEV environment variable first, then /dev/audio. The
|
||||||
/* XXXX Check that this works */
|
* control device tacks "ctl" onto the base device name.
|
||||||
fd = open("/dev/audioctl", 2);
|
*/
|
||||||
else
|
basedev = getenv("AUDIODEV");
|
||||||
fd = open("/dev/audio", imode);
|
if (!basedev)
|
||||||
if (fd < 0) {
|
basedev = "/dev/audio";
|
||||||
PyErr_SetFromErrno(SunAudioError);
|
ctldev = PyMem_NEW(char, strlen(basedev) + 4);
|
||||||
|
if (!ctldev) {
|
||||||
|
PyErr_NoMemory();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
strcpy(ctldev, basedev);
|
||||||
|
strcat(ctldev, "ctl");
|
||||||
|
|
||||||
|
if (imode < 0) {
|
||||||
|
opendev = ctldev;
|
||||||
|
fd = open(ctldev, 2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
opendev = basedev;
|
||||||
|
fd = open(basedev, imode);
|
||||||
|
}
|
||||||
|
if (fd < 0) {
|
||||||
|
PyErr_SetFromErrnoWithFilename(SunAudioError, opendev);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
PyMem_DEL(ctldev);
|
||||||
|
|
||||||
/* Create and initialize the object */
|
/* Create and initialize the object */
|
||||||
xp = PyObject_NEW(sadobject, &Sadtype);
|
xp = PyObject_NEW(sadobject, &Sadtype);
|
||||||
|
@ -344,6 +366,18 @@ sad_close(self, args)
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
sad_fileno(self, args)
|
||||||
|
sadobject *self;
|
||||||
|
PyObject *args;
|
||||||
|
{
|
||||||
|
if (!PyArg_Parse(args, ""))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return PyInt_FromLong(self->x_fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static PyMethodDef sad_methods[] = {
|
static PyMethodDef sad_methods[] = {
|
||||||
{ "read", (PyCFunction)sad_read },
|
{ "read", (PyCFunction)sad_read },
|
||||||
{ "write", (PyCFunction)sad_write },
|
{ "write", (PyCFunction)sad_write },
|
||||||
|
@ -358,6 +392,7 @@ static PyMethodDef sad_methods[] = {
|
||||||
{ "getdev", (PyCFunction)sad_getdev },
|
{ "getdev", (PyCFunction)sad_getdev },
|
||||||
#endif
|
#endif
|
||||||
{ "close", (PyCFunction)sad_close },
|
{ "close", (PyCFunction)sad_close },
|
||||||
|
{ "fileno", (PyCFunction)sad_fileno },
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue