<sys/soundcard.h> seems to exist on both Linux and FreeBSD, so include
it instead of the OS-specific <linux/soundcard.h> or <machine/soundcard.h>. Mixers devices have an ioctl-only interface, no read/write -- so the flags passed to open() don't really matter. Thus, drop the 'mode' parameter to openmixer() (ie. second arg to newossmixerobject()) and always open mixers with O_RDWR.
This commit is contained in:
parent
f882c77d70
commit
0b6dfb808c
|
@ -29,19 +29,18 @@
|
||||||
#define O_WRONLY 01
|
#define O_WRONLY 01
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/soundcard.h>
|
||||||
|
|
||||||
#if defined(linux)
|
#if defined(linux)
|
||||||
#include <linux/soundcard.h>
|
|
||||||
|
|
||||||
typedef unsigned long uint32_t;
|
typedef unsigned long uint32_t;
|
||||||
|
|
||||||
#elif defined(__FreeBSD__)
|
#elif defined(__FreeBSD__)
|
||||||
#include <machine/soundcard.h>
|
|
||||||
|
|
||||||
#ifndef SNDCTL_DSP_CHANNELS
|
# ifndef SNDCTL_DSP_CHANNELS
|
||||||
#define SNDCTL_DSP_CHANNELS SOUND_PCM_WRITE_CHANNELS
|
# define SNDCTL_DSP_CHANNELS SOUND_PCM_WRITE_CHANNELS
|
||||||
#endif
|
# endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -169,11 +168,11 @@ oss_dealloc(oss_audio_t *self)
|
||||||
static oss_mixer_t *
|
static oss_mixer_t *
|
||||||
newossmixerobject(PyObject *arg)
|
newossmixerobject(PyObject *arg)
|
||||||
{
|
{
|
||||||
char *basedev = NULL, *mode = NULL;
|
char *basedev = NULL;
|
||||||
int fd, imode;
|
int fd;
|
||||||
oss_mixer_t *self;
|
oss_mixer_t *self;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(arg, "|ss", &basedev, &mode)) {
|
if (!PyArg_ParseTuple(arg, "|s", &basedev)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,22 +182,11 @@ newossmixerobject(PyObject *arg)
|
||||||
basedev = "/dev/mixer";
|
basedev = "/dev/mixer";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == NULL || strcmp(mode, "r") == 0)
|
if ((fd = open(basedev, O_RDWR)) == -1) {
|
||||||
imode = O_RDONLY;
|
|
||||||
else if (strcmp(mode, "w") == 0)
|
|
||||||
imode = O_WRONLY;
|
|
||||||
else if (strcmp(mode, "rw") == 0)
|
|
||||||
imode = O_RDWR;
|
|
||||||
else {
|
|
||||||
PyErr_SetString(OSSAudioError, "mode must be 'r', 'w', or 'rw'");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((fd = open(basedev, imode)) == -1) {
|
|
||||||
PyErr_SetFromErrnoWithFilename(PyExc_IOError, basedev);
|
PyErr_SetFromErrnoWithFilename(PyExc_IOError, basedev);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((self = PyObject_New(oss_mixer_t, &OSSMixerType)) == NULL) {
|
if ((self = PyObject_New(oss_mixer_t, &OSSMixerType)) == NULL) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue