| 1 | n/a | /* |
|---|
| 2 | n/a | * ossaudiodev -- Python interface to the OSS (Open Sound System) API. |
|---|
| 3 | n/a | * This is the standard audio API for Linux and some |
|---|
| 4 | n/a | * flavours of BSD [XXX which ones?]; it is also available |
|---|
| 5 | n/a | * for a wide range of commercial Unices. |
|---|
| 6 | n/a | * |
|---|
| 7 | n/a | * Originally written by Peter Bosch, March 2000, as linuxaudiodev. |
|---|
| 8 | n/a | * |
|---|
| 9 | n/a | * Renamed to ossaudiodev and rearranged/revised/hacked up |
|---|
| 10 | n/a | * by Greg Ward <gward@python.net>, November 2002. |
|---|
| 11 | n/a | * Mixer interface by Nicholas FitzRoy-Dale <wzdd@lardcave.net>, Dec 2002. |
|---|
| 12 | n/a | * |
|---|
| 13 | n/a | * (c) 2000 Peter Bosch. All Rights Reserved. |
|---|
| 14 | n/a | * (c) 2002 Gregory P. Ward. All Rights Reserved. |
|---|
| 15 | n/a | * (c) 2002 Python Software Foundation. All Rights Reserved. |
|---|
| 16 | n/a | * |
|---|
| 17 | n/a | * XXX need a license statement |
|---|
| 18 | n/a | * |
|---|
| 19 | n/a | * $Id$ |
|---|
| 20 | n/a | */ |
|---|
| 21 | n/a | |
|---|
| 22 | n/a | #define PY_SSIZE_T_CLEAN |
|---|
| 23 | n/a | #include "Python.h" |
|---|
| 24 | n/a | #include "structmember.h" |
|---|
| 25 | n/a | |
|---|
| 26 | n/a | #ifdef HAVE_FCNTL_H |
|---|
| 27 | n/a | #include <fcntl.h> |
|---|
| 28 | n/a | #else |
|---|
| 29 | n/a | #define O_RDONLY 00 |
|---|
| 30 | n/a | #define O_WRONLY 01 |
|---|
| 31 | n/a | #endif |
|---|
| 32 | n/a | |
|---|
| 33 | n/a | #include <sys/ioctl.h> |
|---|
| 34 | n/a | #ifdef __ANDROID__ |
|---|
| 35 | n/a | #include <linux/soundcard.h> |
|---|
| 36 | n/a | #else |
|---|
| 37 | n/a | #include <sys/soundcard.h> |
|---|
| 38 | n/a | #endif |
|---|
| 39 | n/a | |
|---|
| 40 | n/a | #ifdef __linux__ |
|---|
| 41 | n/a | |
|---|
| 42 | n/a | #ifndef HAVE_STDINT_H |
|---|
| 43 | n/a | typedef unsigned long uint32_t; |
|---|
| 44 | n/a | #endif |
|---|
| 45 | n/a | |
|---|
| 46 | n/a | #elif defined(__FreeBSD__) |
|---|
| 47 | n/a | |
|---|
| 48 | n/a | # ifndef SNDCTL_DSP_CHANNELS |
|---|
| 49 | n/a | # define SNDCTL_DSP_CHANNELS SOUND_PCM_WRITE_CHANNELS |
|---|
| 50 | n/a | # endif |
|---|
| 51 | n/a | |
|---|
| 52 | n/a | #endif |
|---|
| 53 | n/a | |
|---|
| 54 | n/a | typedef struct { |
|---|
| 55 | n/a | PyObject_HEAD |
|---|
| 56 | n/a | char *devicename; /* name of the device file */ |
|---|
| 57 | n/a | int fd; /* file descriptor */ |
|---|
| 58 | n/a | int mode; /* file mode (O_RDONLY, etc.) */ |
|---|
| 59 | n/a | Py_ssize_t icount; /* input count */ |
|---|
| 60 | n/a | Py_ssize_t ocount; /* output count */ |
|---|
| 61 | n/a | uint32_t afmts; /* audio formats supported by hardware */ |
|---|
| 62 | n/a | } oss_audio_t; |
|---|
| 63 | n/a | |
|---|
| 64 | n/a | typedef struct { |
|---|
| 65 | n/a | PyObject_HEAD |
|---|
| 66 | n/a | int fd; /* The open mixer device */ |
|---|
| 67 | n/a | } oss_mixer_t; |
|---|
| 68 | n/a | |
|---|
| 69 | n/a | |
|---|
| 70 | n/a | static PyTypeObject OSSAudioType; |
|---|
| 71 | n/a | static PyTypeObject OSSMixerType; |
|---|
| 72 | n/a | |
|---|
| 73 | n/a | static PyObject *OSSAudioError; |
|---|
| 74 | n/a | |
|---|
| 75 | n/a | |
|---|
| 76 | n/a | /* ---------------------------------------------------------------------- |
|---|
| 77 | n/a | * DSP object initialization/deallocation |
|---|
| 78 | n/a | */ |
|---|
| 79 | n/a | |
|---|
| 80 | n/a | static oss_audio_t * |
|---|
| 81 | n/a | newossobject(PyObject *arg) |
|---|
| 82 | n/a | { |
|---|
| 83 | n/a | oss_audio_t *self; |
|---|
| 84 | n/a | int fd, afmts, imode; |
|---|
| 85 | n/a | char *devicename = NULL; |
|---|
| 86 | n/a | char *mode = NULL; |
|---|
| 87 | n/a | |
|---|
| 88 | n/a | /* Two ways to call open(): |
|---|
| 89 | n/a | open(device, mode) (for consistency with builtin open()) |
|---|
| 90 | n/a | open(mode) (for backwards compatibility) |
|---|
| 91 | n/a | because the *first* argument is optional, parsing args is |
|---|
| 92 | n/a | a wee bit tricky. */ |
|---|
| 93 | n/a | if (!PyArg_ParseTuple(arg, "s|s:open", &devicename, &mode)) |
|---|
| 94 | n/a | return NULL; |
|---|
| 95 | n/a | if (mode == NULL) { /* only one arg supplied */ |
|---|
| 96 | n/a | mode = devicename; |
|---|
| 97 | n/a | devicename = NULL; |
|---|
| 98 | n/a | } |
|---|
| 99 | n/a | |
|---|
| 100 | n/a | if (strcmp(mode, "r") == 0) |
|---|
| 101 | n/a | imode = O_RDONLY; |
|---|
| 102 | n/a | else if (strcmp(mode, "w") == 0) |
|---|
| 103 | n/a | imode = O_WRONLY; |
|---|
| 104 | n/a | else if (strcmp(mode, "rw") == 0) |
|---|
| 105 | n/a | imode = O_RDWR; |
|---|
| 106 | n/a | else { |
|---|
| 107 | n/a | PyErr_SetString(OSSAudioError, "mode must be 'r', 'w', or 'rw'"); |
|---|
| 108 | n/a | return NULL; |
|---|
| 109 | n/a | } |
|---|
| 110 | n/a | |
|---|
| 111 | n/a | /* Open the correct device: either the 'device' argument, |
|---|
| 112 | n/a | or the AUDIODEV environment variable, or "/dev/dsp". */ |
|---|
| 113 | n/a | if (devicename == NULL) { /* called with one arg */ |
|---|
| 114 | n/a | devicename = getenv("AUDIODEV"); |
|---|
| 115 | n/a | if (devicename == NULL) /* $AUDIODEV not set */ |
|---|
| 116 | n/a | devicename = "/dev/dsp"; |
|---|
| 117 | n/a | } |
|---|
| 118 | n/a | |
|---|
| 119 | n/a | /* Open with O_NONBLOCK to avoid hanging on devices that only allow |
|---|
| 120 | n/a | one open at a time. This does *not* affect later I/O; OSS |
|---|
| 121 | n/a | provides a special ioctl() for non-blocking read/write, which is |
|---|
| 122 | n/a | exposed via oss_nonblock() below. */ |
|---|
| 123 | n/a | fd = _Py_open(devicename, imode|O_NONBLOCK); |
|---|
| 124 | n/a | if (fd == -1) |
|---|
| 125 | n/a | return NULL; |
|---|
| 126 | n/a | |
|---|
| 127 | n/a | /* And (try to) put it back in blocking mode so we get the |
|---|
| 128 | n/a | expected write() semantics. */ |
|---|
| 129 | n/a | if (fcntl(fd, F_SETFL, 0) == -1) { |
|---|
| 130 | n/a | close(fd); |
|---|
| 131 | n/a | PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename); |
|---|
| 132 | n/a | return NULL; |
|---|
| 133 | n/a | } |
|---|
| 134 | n/a | |
|---|
| 135 | n/a | if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) == -1) { |
|---|
| 136 | n/a | close(fd); |
|---|
| 137 | n/a | PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename); |
|---|
| 138 | n/a | return NULL; |
|---|
| 139 | n/a | } |
|---|
| 140 | n/a | /* Create and initialize the object */ |
|---|
| 141 | n/a | if ((self = PyObject_New(oss_audio_t, &OSSAudioType)) == NULL) { |
|---|
| 142 | n/a | close(fd); |
|---|
| 143 | n/a | return NULL; |
|---|
| 144 | n/a | } |
|---|
| 145 | n/a | self->devicename = devicename; |
|---|
| 146 | n/a | self->fd = fd; |
|---|
| 147 | n/a | self->mode = imode; |
|---|
| 148 | n/a | self->icount = self->ocount = 0; |
|---|
| 149 | n/a | self->afmts = afmts; |
|---|
| 150 | n/a | return self; |
|---|
| 151 | n/a | } |
|---|
| 152 | n/a | |
|---|
| 153 | n/a | static void |
|---|
| 154 | n/a | oss_dealloc(oss_audio_t *self) |
|---|
| 155 | n/a | { |
|---|
| 156 | n/a | /* if already closed, don't reclose it */ |
|---|
| 157 | n/a | if (self->fd != -1) |
|---|
| 158 | n/a | close(self->fd); |
|---|
| 159 | n/a | PyObject_Del(self); |
|---|
| 160 | n/a | } |
|---|
| 161 | n/a | |
|---|
| 162 | n/a | |
|---|
| 163 | n/a | /* ---------------------------------------------------------------------- |
|---|
| 164 | n/a | * Mixer object initialization/deallocation |
|---|
| 165 | n/a | */ |
|---|
| 166 | n/a | |
|---|
| 167 | n/a | static oss_mixer_t * |
|---|
| 168 | n/a | newossmixerobject(PyObject *arg) |
|---|
| 169 | n/a | { |
|---|
| 170 | n/a | char *devicename = NULL; |
|---|
| 171 | n/a | int fd; |
|---|
| 172 | n/a | oss_mixer_t *self; |
|---|
| 173 | n/a | |
|---|
| 174 | n/a | if (!PyArg_ParseTuple(arg, "|s", &devicename)) { |
|---|
| 175 | n/a | return NULL; |
|---|
| 176 | n/a | } |
|---|
| 177 | n/a | |
|---|
| 178 | n/a | if (devicename == NULL) { |
|---|
| 179 | n/a | devicename = getenv("MIXERDEV"); |
|---|
| 180 | n/a | if (devicename == NULL) /* MIXERDEV not set */ |
|---|
| 181 | n/a | devicename = "/dev/mixer"; |
|---|
| 182 | n/a | } |
|---|
| 183 | n/a | |
|---|
| 184 | n/a | fd = _Py_open(devicename, O_RDWR); |
|---|
| 185 | n/a | if (fd == -1) |
|---|
| 186 | n/a | return NULL; |
|---|
| 187 | n/a | |
|---|
| 188 | n/a | if ((self = PyObject_New(oss_mixer_t, &OSSMixerType)) == NULL) { |
|---|
| 189 | n/a | close(fd); |
|---|
| 190 | n/a | return NULL; |
|---|
| 191 | n/a | } |
|---|
| 192 | n/a | |
|---|
| 193 | n/a | self->fd = fd; |
|---|
| 194 | n/a | |
|---|
| 195 | n/a | return self; |
|---|
| 196 | n/a | } |
|---|
| 197 | n/a | |
|---|
| 198 | n/a | static void |
|---|
| 199 | n/a | oss_mixer_dealloc(oss_mixer_t *self) |
|---|
| 200 | n/a | { |
|---|
| 201 | n/a | /* if already closed, don't reclose it */ |
|---|
| 202 | n/a | if (self->fd != -1) |
|---|
| 203 | n/a | close(self->fd); |
|---|
| 204 | n/a | PyObject_Del(self); |
|---|
| 205 | n/a | } |
|---|
| 206 | n/a | |
|---|
| 207 | n/a | |
|---|
| 208 | n/a | /* Methods to wrap the OSS ioctls. The calling convention is pretty |
|---|
| 209 | n/a | simple: |
|---|
| 210 | n/a | nonblock() -> ioctl(fd, SNDCTL_DSP_NONBLOCK) |
|---|
| 211 | n/a | fmt = setfmt(fmt) -> ioctl(fd, SNDCTL_DSP_SETFMT, &fmt) |
|---|
| 212 | n/a | etc. |
|---|
| 213 | n/a | */ |
|---|
| 214 | n/a | |
|---|
| 215 | n/a | |
|---|
| 216 | n/a | /* ---------------------------------------------------------------------- |
|---|
| 217 | n/a | * Helper functions |
|---|
| 218 | n/a | */ |
|---|
| 219 | n/a | |
|---|
| 220 | n/a | /* Check if a given file descriptor is valid (i.e. hasn't been closed). |
|---|
| 221 | n/a | * If true, return 1. Otherwise, raise ValueError and return 0. |
|---|
| 222 | n/a | */ |
|---|
| 223 | n/a | static int _is_fd_valid(int fd) |
|---|
| 224 | n/a | { |
|---|
| 225 | n/a | /* the FD is set to -1 in oss_close()/oss_mixer_close() */ |
|---|
| 226 | n/a | if (fd >= 0) { |
|---|
| 227 | n/a | return 1; |
|---|
| 228 | n/a | } else { |
|---|
| 229 | n/a | PyErr_SetString(PyExc_ValueError, |
|---|
| 230 | n/a | "Operation on closed OSS device."); |
|---|
| 231 | n/a | return 0; |
|---|
| 232 | n/a | } |
|---|
| 233 | n/a | } |
|---|
| 234 | n/a | |
|---|
| 235 | n/a | /* _do_ioctl_1() is a private helper function used for the OSS ioctls -- |
|---|
| 236 | n/a | SNDCTL_DSP_{SETFMT,CHANNELS,SPEED} -- that are called from C |
|---|
| 237 | n/a | like this: |
|---|
| 238 | n/a | ioctl(fd, SNDCTL_DSP_cmd, &arg) |
|---|
| 239 | n/a | |
|---|
| 240 | n/a | where arg is the value to set, and on return the driver sets arg to |
|---|
| 241 | n/a | the value that was actually set. Mapping this to Python is obvious: |
|---|
| 242 | n/a | arg = dsp.xxx(arg) |
|---|
| 243 | n/a | */ |
|---|
| 244 | n/a | static PyObject * |
|---|
| 245 | n/a | _do_ioctl_1(int fd, PyObject *args, char *fname, int cmd) |
|---|
| 246 | n/a | { |
|---|
| 247 | n/a | char argfmt[33] = "i:"; |
|---|
| 248 | n/a | int arg; |
|---|
| 249 | n/a | |
|---|
| 250 | n/a | assert(strlen(fname) <= 30); |
|---|
| 251 | n/a | strncat(argfmt, fname, 30); |
|---|
| 252 | n/a | if (!PyArg_ParseTuple(args, argfmt, &arg)) |
|---|
| 253 | n/a | return NULL; |
|---|
| 254 | n/a | |
|---|
| 255 | n/a | if (ioctl(fd, cmd, &arg) == -1) |
|---|
| 256 | n/a | return PyErr_SetFromErrno(PyExc_IOError); |
|---|
| 257 | n/a | return PyLong_FromLong(arg); |
|---|
| 258 | n/a | } |
|---|
| 259 | n/a | |
|---|
| 260 | n/a | |
|---|
| 261 | n/a | /* _do_ioctl_1_internal() is a wrapper for ioctls that take no inputs |
|---|
| 262 | n/a | but return an output -- ie. we need to pass a pointer to a local C |
|---|
| 263 | n/a | variable so the driver can write its output there, but from Python |
|---|
| 264 | n/a | all we see is the return value. For example, |
|---|
| 265 | n/a | SOUND_MIXER_READ_DEVMASK returns a bitmask of available mixer |
|---|
| 266 | n/a | devices, but does not use the value of the parameter passed-in in any |
|---|
| 267 | n/a | way. |
|---|
| 268 | n/a | */ |
|---|
| 269 | n/a | static PyObject * |
|---|
| 270 | n/a | _do_ioctl_1_internal(int fd, PyObject *args, char *fname, int cmd) |
|---|
| 271 | n/a | { |
|---|
| 272 | n/a | char argfmt[32] = ":"; |
|---|
| 273 | n/a | int arg = 0; |
|---|
| 274 | n/a | |
|---|
| 275 | n/a | assert(strlen(fname) <= 30); |
|---|
| 276 | n/a | strncat(argfmt, fname, 30); |
|---|
| 277 | n/a | if (!PyArg_ParseTuple(args, argfmt, &arg)) |
|---|
| 278 | n/a | return NULL; |
|---|
| 279 | n/a | |
|---|
| 280 | n/a | if (ioctl(fd, cmd, &arg) == -1) |
|---|
| 281 | n/a | return PyErr_SetFromErrno(PyExc_IOError); |
|---|
| 282 | n/a | return PyLong_FromLong(arg); |
|---|
| 283 | n/a | } |
|---|
| 284 | n/a | |
|---|
| 285 | n/a | |
|---|
| 286 | n/a | |
|---|
| 287 | n/a | /* _do_ioctl_0() is a private helper for the no-argument ioctls: |
|---|
| 288 | n/a | SNDCTL_DSP_{SYNC,RESET,POST}. */ |
|---|
| 289 | n/a | static PyObject * |
|---|
| 290 | n/a | _do_ioctl_0(int fd, PyObject *args, char *fname, int cmd) |
|---|
| 291 | n/a | { |
|---|
| 292 | n/a | char argfmt[32] = ":"; |
|---|
| 293 | n/a | int rv; |
|---|
| 294 | n/a | |
|---|
| 295 | n/a | assert(strlen(fname) <= 30); |
|---|
| 296 | n/a | strncat(argfmt, fname, 30); |
|---|
| 297 | n/a | if (!PyArg_ParseTuple(args, argfmt)) |
|---|
| 298 | n/a | return NULL; |
|---|
| 299 | n/a | |
|---|
| 300 | n/a | /* According to hannu@opensound.com, all three of the ioctls that |
|---|
| 301 | n/a | use this function can block, so release the GIL. This is |
|---|
| 302 | n/a | especially important for SYNC, which can block for several |
|---|
| 303 | n/a | seconds. */ |
|---|
| 304 | n/a | Py_BEGIN_ALLOW_THREADS |
|---|
| 305 | n/a | rv = ioctl(fd, cmd, 0); |
|---|
| 306 | n/a | Py_END_ALLOW_THREADS |
|---|
| 307 | n/a | |
|---|
| 308 | n/a | if (rv == -1) |
|---|
| 309 | n/a | return PyErr_SetFromErrno(PyExc_IOError); |
|---|
| 310 | n/a | Py_RETURN_NONE; |
|---|
| 311 | n/a | } |
|---|
| 312 | n/a | |
|---|
| 313 | n/a | |
|---|
| 314 | n/a | /* ---------------------------------------------------------------------- |
|---|
| 315 | n/a | * Methods of DSP objects (OSSAudioType) |
|---|
| 316 | n/a | */ |
|---|
| 317 | n/a | |
|---|
| 318 | n/a | static PyObject * |
|---|
| 319 | n/a | oss_nonblock(oss_audio_t *self, PyObject *unused) |
|---|
| 320 | n/a | { |
|---|
| 321 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 322 | n/a | return NULL; |
|---|
| 323 | n/a | |
|---|
| 324 | n/a | /* Hmmm: it doesn't appear to be possible to return to blocking |
|---|
| 325 | n/a | mode once we're in non-blocking mode! */ |
|---|
| 326 | n/a | if (ioctl(self->fd, SNDCTL_DSP_NONBLOCK, NULL) == -1) |
|---|
| 327 | n/a | return PyErr_SetFromErrno(PyExc_IOError); |
|---|
| 328 | n/a | Py_RETURN_NONE; |
|---|
| 329 | n/a | } |
|---|
| 330 | n/a | |
|---|
| 331 | n/a | static PyObject * |
|---|
| 332 | n/a | oss_setfmt(oss_audio_t *self, PyObject *args) |
|---|
| 333 | n/a | { |
|---|
| 334 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 335 | n/a | return NULL; |
|---|
| 336 | n/a | |
|---|
| 337 | n/a | return _do_ioctl_1(self->fd, args, "setfmt", SNDCTL_DSP_SETFMT); |
|---|
| 338 | n/a | } |
|---|
| 339 | n/a | |
|---|
| 340 | n/a | static PyObject * |
|---|
| 341 | n/a | oss_getfmts(oss_audio_t *self, PyObject *unused) |
|---|
| 342 | n/a | { |
|---|
| 343 | n/a | int mask; |
|---|
| 344 | n/a | |
|---|
| 345 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 346 | n/a | return NULL; |
|---|
| 347 | n/a | |
|---|
| 348 | n/a | if (ioctl(self->fd, SNDCTL_DSP_GETFMTS, &mask) == -1) |
|---|
| 349 | n/a | return PyErr_SetFromErrno(PyExc_IOError); |
|---|
| 350 | n/a | return PyLong_FromLong(mask); |
|---|
| 351 | n/a | } |
|---|
| 352 | n/a | |
|---|
| 353 | n/a | static PyObject * |
|---|
| 354 | n/a | oss_channels(oss_audio_t *self, PyObject *args) |
|---|
| 355 | n/a | { |
|---|
| 356 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 357 | n/a | return NULL; |
|---|
| 358 | n/a | |
|---|
| 359 | n/a | return _do_ioctl_1(self->fd, args, "channels", SNDCTL_DSP_CHANNELS); |
|---|
| 360 | n/a | } |
|---|
| 361 | n/a | |
|---|
| 362 | n/a | static PyObject * |
|---|
| 363 | n/a | oss_speed(oss_audio_t *self, PyObject *args) |
|---|
| 364 | n/a | { |
|---|
| 365 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 366 | n/a | return NULL; |
|---|
| 367 | n/a | |
|---|
| 368 | n/a | return _do_ioctl_1(self->fd, args, "speed", SNDCTL_DSP_SPEED); |
|---|
| 369 | n/a | } |
|---|
| 370 | n/a | |
|---|
| 371 | n/a | static PyObject * |
|---|
| 372 | n/a | oss_sync(oss_audio_t *self, PyObject *args) |
|---|
| 373 | n/a | { |
|---|
| 374 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 375 | n/a | return NULL; |
|---|
| 376 | n/a | |
|---|
| 377 | n/a | return _do_ioctl_0(self->fd, args, "sync", SNDCTL_DSP_SYNC); |
|---|
| 378 | n/a | } |
|---|
| 379 | n/a | |
|---|
| 380 | n/a | static PyObject * |
|---|
| 381 | n/a | oss_reset(oss_audio_t *self, PyObject *args) |
|---|
| 382 | n/a | { |
|---|
| 383 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 384 | n/a | return NULL; |
|---|
| 385 | n/a | |
|---|
| 386 | n/a | return _do_ioctl_0(self->fd, args, "reset", SNDCTL_DSP_RESET); |
|---|
| 387 | n/a | } |
|---|
| 388 | n/a | |
|---|
| 389 | n/a | static PyObject * |
|---|
| 390 | n/a | oss_post(oss_audio_t *self, PyObject *args) |
|---|
| 391 | n/a | { |
|---|
| 392 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 393 | n/a | return NULL; |
|---|
| 394 | n/a | |
|---|
| 395 | n/a | return _do_ioctl_0(self->fd, args, "post", SNDCTL_DSP_POST); |
|---|
| 396 | n/a | } |
|---|
| 397 | n/a | |
|---|
| 398 | n/a | |
|---|
| 399 | n/a | /* Regular file methods: read(), write(), close(), etc. as well |
|---|
| 400 | n/a | as one convenience method, writeall(). */ |
|---|
| 401 | n/a | |
|---|
| 402 | n/a | static PyObject * |
|---|
| 403 | n/a | oss_read(oss_audio_t *self, PyObject *args) |
|---|
| 404 | n/a | { |
|---|
| 405 | n/a | Py_ssize_t size, count; |
|---|
| 406 | n/a | PyObject *rv; |
|---|
| 407 | n/a | |
|---|
| 408 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 409 | n/a | return NULL; |
|---|
| 410 | n/a | |
|---|
| 411 | n/a | if (!PyArg_ParseTuple(args, "n:read", &size)) |
|---|
| 412 | n/a | return NULL; |
|---|
| 413 | n/a | |
|---|
| 414 | n/a | rv = PyBytes_FromStringAndSize(NULL, size); |
|---|
| 415 | n/a | if (rv == NULL) |
|---|
| 416 | n/a | return NULL; |
|---|
| 417 | n/a | |
|---|
| 418 | n/a | count = _Py_read(self->fd, PyBytes_AS_STRING(rv), size); |
|---|
| 419 | n/a | if (count == -1) { |
|---|
| 420 | n/a | Py_DECREF(rv); |
|---|
| 421 | n/a | return NULL; |
|---|
| 422 | n/a | } |
|---|
| 423 | n/a | |
|---|
| 424 | n/a | self->icount += count; |
|---|
| 425 | n/a | _PyBytes_Resize(&rv, count); |
|---|
| 426 | n/a | return rv; |
|---|
| 427 | n/a | } |
|---|
| 428 | n/a | |
|---|
| 429 | n/a | static PyObject * |
|---|
| 430 | n/a | oss_write(oss_audio_t *self, PyObject *args) |
|---|
| 431 | n/a | { |
|---|
| 432 | n/a | Py_buffer data; |
|---|
| 433 | n/a | Py_ssize_t rv; |
|---|
| 434 | n/a | |
|---|
| 435 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 436 | n/a | return NULL; |
|---|
| 437 | n/a | |
|---|
| 438 | n/a | if (!PyArg_ParseTuple(args, "y*:write", &data)) { |
|---|
| 439 | n/a | return NULL; |
|---|
| 440 | n/a | } |
|---|
| 441 | n/a | |
|---|
| 442 | n/a | rv = _Py_write(self->fd, data.buf, data.len); |
|---|
| 443 | n/a | PyBuffer_Release(&data); |
|---|
| 444 | n/a | if (rv == -1) |
|---|
| 445 | n/a | return NULL; |
|---|
| 446 | n/a | |
|---|
| 447 | n/a | self->ocount += rv; |
|---|
| 448 | n/a | return PyLong_FromLong(rv); |
|---|
| 449 | n/a | } |
|---|
| 450 | n/a | |
|---|
| 451 | n/a | static PyObject * |
|---|
| 452 | n/a | oss_writeall(oss_audio_t *self, PyObject *args) |
|---|
| 453 | n/a | { |
|---|
| 454 | n/a | Py_buffer data; |
|---|
| 455 | n/a | const char *cp; |
|---|
| 456 | n/a | Py_ssize_t size; |
|---|
| 457 | n/a | Py_ssize_t rv; |
|---|
| 458 | n/a | fd_set write_set_fds; |
|---|
| 459 | n/a | int select_rv; |
|---|
| 460 | n/a | |
|---|
| 461 | n/a | /* NB. writeall() is only useful in non-blocking mode: according to |
|---|
| 462 | n/a | Guenter Geiger <geiger@xdv.org> on the linux-audio-dev list |
|---|
| 463 | n/a | (http://eca.cx/lad/2002/11/0380.html), OSS guarantees that |
|---|
| 464 | n/a | write() in blocking mode consumes the whole buffer. In blocking |
|---|
| 465 | n/a | mode, the behaviour of write() and writeall() from Python is |
|---|
| 466 | n/a | indistinguishable. */ |
|---|
| 467 | n/a | |
|---|
| 468 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 469 | n/a | return NULL; |
|---|
| 470 | n/a | |
|---|
| 471 | n/a | if (!PyArg_ParseTuple(args, "y*:writeall", &data)) |
|---|
| 472 | n/a | return NULL; |
|---|
| 473 | n/a | |
|---|
| 474 | n/a | if (!_PyIsSelectable_fd(self->fd)) { |
|---|
| 475 | n/a | PyErr_SetString(PyExc_ValueError, |
|---|
| 476 | n/a | "file descriptor out of range for select"); |
|---|
| 477 | n/a | PyBuffer_Release(&data); |
|---|
| 478 | n/a | return NULL; |
|---|
| 479 | n/a | } |
|---|
| 480 | n/a | /* use select to wait for audio device to be available */ |
|---|
| 481 | n/a | FD_ZERO(&write_set_fds); |
|---|
| 482 | n/a | FD_SET(self->fd, &write_set_fds); |
|---|
| 483 | n/a | cp = (const char *)data.buf; |
|---|
| 484 | n/a | size = data.len; |
|---|
| 485 | n/a | |
|---|
| 486 | n/a | while (size > 0) { |
|---|
| 487 | n/a | Py_BEGIN_ALLOW_THREADS |
|---|
| 488 | n/a | select_rv = select(self->fd+1, NULL, &write_set_fds, NULL, NULL); |
|---|
| 489 | n/a | Py_END_ALLOW_THREADS |
|---|
| 490 | n/a | |
|---|
| 491 | n/a | assert(select_rv != 0); /* no timeout, can't expire */ |
|---|
| 492 | n/a | if (select_rv == -1) { |
|---|
| 493 | n/a | PyBuffer_Release(&data); |
|---|
| 494 | n/a | return PyErr_SetFromErrno(PyExc_IOError); |
|---|
| 495 | n/a | } |
|---|
| 496 | n/a | |
|---|
| 497 | n/a | rv = _Py_write(self->fd, cp, Py_MIN(size, INT_MAX)); |
|---|
| 498 | n/a | if (rv == -1) { |
|---|
| 499 | n/a | /* buffer is full, try again */ |
|---|
| 500 | n/a | if (errno == EAGAIN) { |
|---|
| 501 | n/a | PyErr_Clear(); |
|---|
| 502 | n/a | continue; |
|---|
| 503 | n/a | } |
|---|
| 504 | n/a | /* it's a real error */ |
|---|
| 505 | n/a | PyBuffer_Release(&data); |
|---|
| 506 | n/a | return NULL; |
|---|
| 507 | n/a | } |
|---|
| 508 | n/a | |
|---|
| 509 | n/a | /* wrote rv bytes */ |
|---|
| 510 | n/a | self->ocount += rv; |
|---|
| 511 | n/a | size -= rv; |
|---|
| 512 | n/a | cp += rv; |
|---|
| 513 | n/a | } |
|---|
| 514 | n/a | PyBuffer_Release(&data); |
|---|
| 515 | n/a | Py_RETURN_NONE; |
|---|
| 516 | n/a | } |
|---|
| 517 | n/a | |
|---|
| 518 | n/a | static PyObject * |
|---|
| 519 | n/a | oss_close(oss_audio_t *self, PyObject *unused) |
|---|
| 520 | n/a | { |
|---|
| 521 | n/a | if (self->fd >= 0) { |
|---|
| 522 | n/a | Py_BEGIN_ALLOW_THREADS |
|---|
| 523 | n/a | close(self->fd); |
|---|
| 524 | n/a | Py_END_ALLOW_THREADS |
|---|
| 525 | n/a | self->fd = -1; |
|---|
| 526 | n/a | } |
|---|
| 527 | n/a | Py_RETURN_NONE; |
|---|
| 528 | n/a | } |
|---|
| 529 | n/a | |
|---|
| 530 | n/a | static PyObject * |
|---|
| 531 | n/a | oss_self(PyObject *self, PyObject *unused) |
|---|
| 532 | n/a | { |
|---|
| 533 | n/a | Py_INCREF(self); |
|---|
| 534 | n/a | return self; |
|---|
| 535 | n/a | } |
|---|
| 536 | n/a | |
|---|
| 537 | n/a | static PyObject * |
|---|
| 538 | n/a | oss_exit(PyObject *self, PyObject *unused) |
|---|
| 539 | n/a | { |
|---|
| 540 | n/a | _Py_IDENTIFIER(close); |
|---|
| 541 | n/a | |
|---|
| 542 | n/a | PyObject *ret = _PyObject_CallMethodId(self, &PyId_close, NULL); |
|---|
| 543 | n/a | if (!ret) |
|---|
| 544 | n/a | return NULL; |
|---|
| 545 | n/a | Py_DECREF(ret); |
|---|
| 546 | n/a | Py_RETURN_NONE; |
|---|
| 547 | n/a | } |
|---|
| 548 | n/a | |
|---|
| 549 | n/a | static PyObject * |
|---|
| 550 | n/a | oss_fileno(oss_audio_t *self, PyObject *unused) |
|---|
| 551 | n/a | { |
|---|
| 552 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 553 | n/a | return NULL; |
|---|
| 554 | n/a | |
|---|
| 555 | n/a | return PyLong_FromLong(self->fd); |
|---|
| 556 | n/a | } |
|---|
| 557 | n/a | |
|---|
| 558 | n/a | |
|---|
| 559 | n/a | /* Convenience methods: these generally wrap a couple of ioctls into one |
|---|
| 560 | n/a | common task. */ |
|---|
| 561 | n/a | |
|---|
| 562 | n/a | static PyObject * |
|---|
| 563 | n/a | oss_setparameters(oss_audio_t *self, PyObject *args) |
|---|
| 564 | n/a | { |
|---|
| 565 | n/a | int wanted_fmt, wanted_channels, wanted_rate, strict=0; |
|---|
| 566 | n/a | int fmt, channels, rate; |
|---|
| 567 | n/a | |
|---|
| 568 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 569 | n/a | return NULL; |
|---|
| 570 | n/a | |
|---|
| 571 | n/a | if (!PyArg_ParseTuple(args, "iii|i:setparameters", |
|---|
| 572 | n/a | &wanted_fmt, &wanted_channels, &wanted_rate, |
|---|
| 573 | n/a | &strict)) |
|---|
| 574 | n/a | return NULL; |
|---|
| 575 | n/a | |
|---|
| 576 | n/a | fmt = wanted_fmt; |
|---|
| 577 | n/a | if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) == -1) { |
|---|
| 578 | n/a | return PyErr_SetFromErrno(PyExc_IOError); |
|---|
| 579 | n/a | } |
|---|
| 580 | n/a | if (strict && fmt != wanted_fmt) { |
|---|
| 581 | n/a | return PyErr_Format |
|---|
| 582 | n/a | (OSSAudioError, |
|---|
| 583 | n/a | "unable to set requested format (wanted %d, got %d)", |
|---|
| 584 | n/a | wanted_fmt, fmt); |
|---|
| 585 | n/a | } |
|---|
| 586 | n/a | |
|---|
| 587 | n/a | channels = wanted_channels; |
|---|
| 588 | n/a | if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, &channels) == -1) { |
|---|
| 589 | n/a | return PyErr_SetFromErrno(PyExc_IOError); |
|---|
| 590 | n/a | } |
|---|
| 591 | n/a | if (strict && channels != wanted_channels) { |
|---|
| 592 | n/a | return PyErr_Format |
|---|
| 593 | n/a | (OSSAudioError, |
|---|
| 594 | n/a | "unable to set requested channels (wanted %d, got %d)", |
|---|
| 595 | n/a | wanted_channels, channels); |
|---|
| 596 | n/a | } |
|---|
| 597 | n/a | |
|---|
| 598 | n/a | rate = wanted_rate; |
|---|
| 599 | n/a | if (ioctl(self->fd, SNDCTL_DSP_SPEED, &rate) == -1) { |
|---|
| 600 | n/a | return PyErr_SetFromErrno(PyExc_IOError); |
|---|
| 601 | n/a | } |
|---|
| 602 | n/a | if (strict && rate != wanted_rate) { |
|---|
| 603 | n/a | return PyErr_Format |
|---|
| 604 | n/a | (OSSAudioError, |
|---|
| 605 | n/a | "unable to set requested rate (wanted %d, got %d)", |
|---|
| 606 | n/a | wanted_rate, rate); |
|---|
| 607 | n/a | } |
|---|
| 608 | n/a | |
|---|
| 609 | n/a | /* Construct the return value: a (fmt, channels, rate) tuple that |
|---|
| 610 | n/a | tells what the audio hardware was actually set to. */ |
|---|
| 611 | n/a | return Py_BuildValue("(iii)", fmt, channels, rate); |
|---|
| 612 | n/a | } |
|---|
| 613 | n/a | |
|---|
| 614 | n/a | static int |
|---|
| 615 | n/a | _ssize(oss_audio_t *self, int *nchannels, int *ssize) |
|---|
| 616 | n/a | { |
|---|
| 617 | n/a | int fmt; |
|---|
| 618 | n/a | |
|---|
| 619 | n/a | fmt = 0; |
|---|
| 620 | n/a | if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) < 0) |
|---|
| 621 | n/a | return -errno; |
|---|
| 622 | n/a | |
|---|
| 623 | n/a | switch (fmt) { |
|---|
| 624 | n/a | case AFMT_MU_LAW: |
|---|
| 625 | n/a | case AFMT_A_LAW: |
|---|
| 626 | n/a | case AFMT_U8: |
|---|
| 627 | n/a | case AFMT_S8: |
|---|
| 628 | n/a | *ssize = 1; /* 8 bit formats: 1 byte */ |
|---|
| 629 | n/a | break; |
|---|
| 630 | n/a | case AFMT_S16_LE: |
|---|
| 631 | n/a | case AFMT_S16_BE: |
|---|
| 632 | n/a | case AFMT_U16_LE: |
|---|
| 633 | n/a | case AFMT_U16_BE: |
|---|
| 634 | n/a | *ssize = 2; /* 16 bit formats: 2 byte */ |
|---|
| 635 | n/a | break; |
|---|
| 636 | n/a | case AFMT_MPEG: |
|---|
| 637 | n/a | case AFMT_IMA_ADPCM: |
|---|
| 638 | n/a | default: |
|---|
| 639 | n/a | return -EOPNOTSUPP; |
|---|
| 640 | n/a | } |
|---|
| 641 | n/a | if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, nchannels) < 0) |
|---|
| 642 | n/a | return -errno; |
|---|
| 643 | n/a | return 0; |
|---|
| 644 | n/a | } |
|---|
| 645 | n/a | |
|---|
| 646 | n/a | |
|---|
| 647 | n/a | /* bufsize returns the size of the hardware audio buffer in number |
|---|
| 648 | n/a | of samples */ |
|---|
| 649 | n/a | static PyObject * |
|---|
| 650 | n/a | oss_bufsize(oss_audio_t *self, PyObject *unused) |
|---|
| 651 | n/a | { |
|---|
| 652 | n/a | audio_buf_info ai; |
|---|
| 653 | n/a | int nchannels=0, ssize=0; |
|---|
| 654 | n/a | |
|---|
| 655 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 656 | n/a | return NULL; |
|---|
| 657 | n/a | |
|---|
| 658 | n/a | if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) { |
|---|
| 659 | n/a | PyErr_SetFromErrno(PyExc_IOError); |
|---|
| 660 | n/a | return NULL; |
|---|
| 661 | n/a | } |
|---|
| 662 | n/a | if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) { |
|---|
| 663 | n/a | PyErr_SetFromErrno(PyExc_IOError); |
|---|
| 664 | n/a | return NULL; |
|---|
| 665 | n/a | } |
|---|
| 666 | n/a | return PyLong_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize)); |
|---|
| 667 | n/a | } |
|---|
| 668 | n/a | |
|---|
| 669 | n/a | /* obufcount returns the number of samples that are available in the |
|---|
| 670 | n/a | hardware for playing */ |
|---|
| 671 | n/a | static PyObject * |
|---|
| 672 | n/a | oss_obufcount(oss_audio_t *self, PyObject *unused) |
|---|
| 673 | n/a | { |
|---|
| 674 | n/a | audio_buf_info ai; |
|---|
| 675 | n/a | int nchannels=0, ssize=0; |
|---|
| 676 | n/a | |
|---|
| 677 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 678 | n/a | return NULL; |
|---|
| 679 | n/a | |
|---|
| 680 | n/a | if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) { |
|---|
| 681 | n/a | PyErr_SetFromErrno(PyExc_IOError); |
|---|
| 682 | n/a | return NULL; |
|---|
| 683 | n/a | } |
|---|
| 684 | n/a | if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) { |
|---|
| 685 | n/a | PyErr_SetFromErrno(PyExc_IOError); |
|---|
| 686 | n/a | return NULL; |
|---|
| 687 | n/a | } |
|---|
| 688 | n/a | return PyLong_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) / |
|---|
| 689 | n/a | (ssize * nchannels)); |
|---|
| 690 | n/a | } |
|---|
| 691 | n/a | |
|---|
| 692 | n/a | /* obufcount returns the number of samples that can be played without |
|---|
| 693 | n/a | blocking */ |
|---|
| 694 | n/a | static PyObject * |
|---|
| 695 | n/a | oss_obuffree(oss_audio_t *self, PyObject *unused) |
|---|
| 696 | n/a | { |
|---|
| 697 | n/a | audio_buf_info ai; |
|---|
| 698 | n/a | int nchannels=0, ssize=0; |
|---|
| 699 | n/a | |
|---|
| 700 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 701 | n/a | return NULL; |
|---|
| 702 | n/a | |
|---|
| 703 | n/a | if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) { |
|---|
| 704 | n/a | PyErr_SetFromErrno(PyExc_IOError); |
|---|
| 705 | n/a | return NULL; |
|---|
| 706 | n/a | } |
|---|
| 707 | n/a | if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) { |
|---|
| 708 | n/a | PyErr_SetFromErrno(PyExc_IOError); |
|---|
| 709 | n/a | return NULL; |
|---|
| 710 | n/a | } |
|---|
| 711 | n/a | return PyLong_FromLong(ai.bytes / (ssize * nchannels)); |
|---|
| 712 | n/a | } |
|---|
| 713 | n/a | |
|---|
| 714 | n/a | static PyObject * |
|---|
| 715 | n/a | oss_getptr(oss_audio_t *self, PyObject *unused) |
|---|
| 716 | n/a | { |
|---|
| 717 | n/a | count_info info; |
|---|
| 718 | n/a | int req; |
|---|
| 719 | n/a | |
|---|
| 720 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 721 | n/a | return NULL; |
|---|
| 722 | n/a | |
|---|
| 723 | n/a | if (self->mode == O_RDONLY) |
|---|
| 724 | n/a | req = SNDCTL_DSP_GETIPTR; |
|---|
| 725 | n/a | else |
|---|
| 726 | n/a | req = SNDCTL_DSP_GETOPTR; |
|---|
| 727 | n/a | if (ioctl(self->fd, req, &info) == -1) { |
|---|
| 728 | n/a | PyErr_SetFromErrno(PyExc_IOError); |
|---|
| 729 | n/a | return NULL; |
|---|
| 730 | n/a | } |
|---|
| 731 | n/a | return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr); |
|---|
| 732 | n/a | } |
|---|
| 733 | n/a | |
|---|
| 734 | n/a | |
|---|
| 735 | n/a | /* ---------------------------------------------------------------------- |
|---|
| 736 | n/a | * Methods of mixer objects (OSSMixerType) |
|---|
| 737 | n/a | */ |
|---|
| 738 | n/a | |
|---|
| 739 | n/a | static PyObject * |
|---|
| 740 | n/a | oss_mixer_close(oss_mixer_t *self, PyObject *unused) |
|---|
| 741 | n/a | { |
|---|
| 742 | n/a | if (self->fd >= 0) { |
|---|
| 743 | n/a | close(self->fd); |
|---|
| 744 | n/a | self->fd = -1; |
|---|
| 745 | n/a | } |
|---|
| 746 | n/a | Py_RETURN_NONE; |
|---|
| 747 | n/a | } |
|---|
| 748 | n/a | |
|---|
| 749 | n/a | static PyObject * |
|---|
| 750 | n/a | oss_mixer_fileno(oss_mixer_t *self, PyObject *unused) |
|---|
| 751 | n/a | { |
|---|
| 752 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 753 | n/a | return NULL; |
|---|
| 754 | n/a | |
|---|
| 755 | n/a | return PyLong_FromLong(self->fd); |
|---|
| 756 | n/a | } |
|---|
| 757 | n/a | |
|---|
| 758 | n/a | /* Simple mixer interface methods */ |
|---|
| 759 | n/a | |
|---|
| 760 | n/a | static PyObject * |
|---|
| 761 | n/a | oss_mixer_controls(oss_mixer_t *self, PyObject *args) |
|---|
| 762 | n/a | { |
|---|
| 763 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 764 | n/a | return NULL; |
|---|
| 765 | n/a | |
|---|
| 766 | n/a | return _do_ioctl_1_internal(self->fd, args, "controls", |
|---|
| 767 | n/a | SOUND_MIXER_READ_DEVMASK); |
|---|
| 768 | n/a | } |
|---|
| 769 | n/a | |
|---|
| 770 | n/a | static PyObject * |
|---|
| 771 | n/a | oss_mixer_stereocontrols(oss_mixer_t *self, PyObject *args) |
|---|
| 772 | n/a | { |
|---|
| 773 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 774 | n/a | return NULL; |
|---|
| 775 | n/a | |
|---|
| 776 | n/a | return _do_ioctl_1_internal(self->fd, args, "stereocontrols", |
|---|
| 777 | n/a | SOUND_MIXER_READ_STEREODEVS); |
|---|
| 778 | n/a | } |
|---|
| 779 | n/a | |
|---|
| 780 | n/a | static PyObject * |
|---|
| 781 | n/a | oss_mixer_reccontrols(oss_mixer_t *self, PyObject *args) |
|---|
| 782 | n/a | { |
|---|
| 783 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 784 | n/a | return NULL; |
|---|
| 785 | n/a | |
|---|
| 786 | n/a | return _do_ioctl_1_internal(self->fd, args, "reccontrols", |
|---|
| 787 | n/a | SOUND_MIXER_READ_RECMASK); |
|---|
| 788 | n/a | } |
|---|
| 789 | n/a | |
|---|
| 790 | n/a | static PyObject * |
|---|
| 791 | n/a | oss_mixer_get(oss_mixer_t *self, PyObject *args) |
|---|
| 792 | n/a | { |
|---|
| 793 | n/a | int channel, volume; |
|---|
| 794 | n/a | |
|---|
| 795 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 796 | n/a | return NULL; |
|---|
| 797 | n/a | |
|---|
| 798 | n/a | /* Can't use _do_ioctl_1 because of encoded arg thingy. */ |
|---|
| 799 | n/a | if (!PyArg_ParseTuple(args, "i:get", &channel)) |
|---|
| 800 | n/a | return NULL; |
|---|
| 801 | n/a | |
|---|
| 802 | n/a | if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) { |
|---|
| 803 | n/a | PyErr_SetString(OSSAudioError, "Invalid mixer channel specified."); |
|---|
| 804 | n/a | return NULL; |
|---|
| 805 | n/a | } |
|---|
| 806 | n/a | |
|---|
| 807 | n/a | if (ioctl(self->fd, MIXER_READ(channel), &volume) == -1) |
|---|
| 808 | n/a | return PyErr_SetFromErrno(PyExc_IOError); |
|---|
| 809 | n/a | |
|---|
| 810 | n/a | return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8); |
|---|
| 811 | n/a | } |
|---|
| 812 | n/a | |
|---|
| 813 | n/a | static PyObject * |
|---|
| 814 | n/a | oss_mixer_set(oss_mixer_t *self, PyObject *args) |
|---|
| 815 | n/a | { |
|---|
| 816 | n/a | int channel, volume, leftVol, rightVol; |
|---|
| 817 | n/a | |
|---|
| 818 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 819 | n/a | return NULL; |
|---|
| 820 | n/a | |
|---|
| 821 | n/a | /* Can't use _do_ioctl_1 because of encoded arg thingy. */ |
|---|
| 822 | n/a | if (!PyArg_ParseTuple(args, "i(ii):set", &channel, &leftVol, &rightVol)) |
|---|
| 823 | n/a | return NULL; |
|---|
| 824 | n/a | |
|---|
| 825 | n/a | if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) { |
|---|
| 826 | n/a | PyErr_SetString(OSSAudioError, "Invalid mixer channel specified."); |
|---|
| 827 | n/a | return NULL; |
|---|
| 828 | n/a | } |
|---|
| 829 | n/a | |
|---|
| 830 | n/a | if (leftVol < 0 || rightVol < 0 || leftVol > 100 || rightVol > 100) { |
|---|
| 831 | n/a | PyErr_SetString(OSSAudioError, "Volumes must be between 0 and 100."); |
|---|
| 832 | n/a | return NULL; |
|---|
| 833 | n/a | } |
|---|
| 834 | n/a | |
|---|
| 835 | n/a | volume = (rightVol << 8) | leftVol; |
|---|
| 836 | n/a | |
|---|
| 837 | n/a | if (ioctl(self->fd, MIXER_WRITE(channel), &volume) == -1) |
|---|
| 838 | n/a | return PyErr_SetFromErrno(PyExc_IOError); |
|---|
| 839 | n/a | |
|---|
| 840 | n/a | return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8); |
|---|
| 841 | n/a | } |
|---|
| 842 | n/a | |
|---|
| 843 | n/a | static PyObject * |
|---|
| 844 | n/a | oss_mixer_get_recsrc(oss_mixer_t *self, PyObject *args) |
|---|
| 845 | n/a | { |
|---|
| 846 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 847 | n/a | return NULL; |
|---|
| 848 | n/a | |
|---|
| 849 | n/a | return _do_ioctl_1_internal(self->fd, args, "get_recsrc", |
|---|
| 850 | n/a | SOUND_MIXER_READ_RECSRC); |
|---|
| 851 | n/a | } |
|---|
| 852 | n/a | |
|---|
| 853 | n/a | static PyObject * |
|---|
| 854 | n/a | oss_mixer_set_recsrc(oss_mixer_t *self, PyObject *args) |
|---|
| 855 | n/a | { |
|---|
| 856 | n/a | if (!_is_fd_valid(self->fd)) |
|---|
| 857 | n/a | return NULL; |
|---|
| 858 | n/a | |
|---|
| 859 | n/a | return _do_ioctl_1(self->fd, args, "set_recsrc", |
|---|
| 860 | n/a | SOUND_MIXER_WRITE_RECSRC); |
|---|
| 861 | n/a | } |
|---|
| 862 | n/a | |
|---|
| 863 | n/a | |
|---|
| 864 | n/a | /* ---------------------------------------------------------------------- |
|---|
| 865 | n/a | * Method tables and other bureaucracy |
|---|
| 866 | n/a | */ |
|---|
| 867 | n/a | |
|---|
| 868 | n/a | static PyMethodDef oss_methods[] = { |
|---|
| 869 | n/a | /* Regular file methods */ |
|---|
| 870 | n/a | { "read", (PyCFunction)oss_read, METH_VARARGS }, |
|---|
| 871 | n/a | { "write", (PyCFunction)oss_write, METH_VARARGS }, |
|---|
| 872 | n/a | { "writeall", (PyCFunction)oss_writeall, METH_VARARGS }, |
|---|
| 873 | n/a | { "close", (PyCFunction)oss_close, METH_NOARGS }, |
|---|
| 874 | n/a | { "fileno", (PyCFunction)oss_fileno, METH_NOARGS }, |
|---|
| 875 | n/a | |
|---|
| 876 | n/a | /* Simple ioctl wrappers */ |
|---|
| 877 | n/a | { "nonblock", (PyCFunction)oss_nonblock, METH_NOARGS }, |
|---|
| 878 | n/a | { "setfmt", (PyCFunction)oss_setfmt, METH_VARARGS }, |
|---|
| 879 | n/a | { "getfmts", (PyCFunction)oss_getfmts, METH_NOARGS }, |
|---|
| 880 | n/a | { "channels", (PyCFunction)oss_channels, METH_VARARGS }, |
|---|
| 881 | n/a | { "speed", (PyCFunction)oss_speed, METH_VARARGS }, |
|---|
| 882 | n/a | { "sync", (PyCFunction)oss_sync, METH_VARARGS }, |
|---|
| 883 | n/a | { "reset", (PyCFunction)oss_reset, METH_VARARGS }, |
|---|
| 884 | n/a | { "post", (PyCFunction)oss_post, METH_VARARGS }, |
|---|
| 885 | n/a | |
|---|
| 886 | n/a | /* Convenience methods -- wrap a couple of ioctls together */ |
|---|
| 887 | n/a | { "setparameters", (PyCFunction)oss_setparameters, METH_VARARGS }, |
|---|
| 888 | n/a | { "bufsize", (PyCFunction)oss_bufsize, METH_NOARGS }, |
|---|
| 889 | n/a | { "obufcount", (PyCFunction)oss_obufcount, METH_NOARGS }, |
|---|
| 890 | n/a | { "obuffree", (PyCFunction)oss_obuffree, METH_NOARGS }, |
|---|
| 891 | n/a | { "getptr", (PyCFunction)oss_getptr, METH_NOARGS }, |
|---|
| 892 | n/a | |
|---|
| 893 | n/a | /* Aliases for backwards compatibility */ |
|---|
| 894 | n/a | { "flush", (PyCFunction)oss_sync, METH_VARARGS }, |
|---|
| 895 | n/a | |
|---|
| 896 | n/a | /* Support for the context management protocol */ |
|---|
| 897 | n/a | { "__enter__", oss_self, METH_NOARGS }, |
|---|
| 898 | n/a | { "__exit__", oss_exit, METH_VARARGS }, |
|---|
| 899 | n/a | |
|---|
| 900 | n/a | { NULL, NULL} /* sentinel */ |
|---|
| 901 | n/a | }; |
|---|
| 902 | n/a | |
|---|
| 903 | n/a | static PyMethodDef oss_mixer_methods[] = { |
|---|
| 904 | n/a | /* Regular file method - OSS mixers are ioctl-only interface */ |
|---|
| 905 | n/a | { "close", (PyCFunction)oss_mixer_close, METH_NOARGS }, |
|---|
| 906 | n/a | { "fileno", (PyCFunction)oss_mixer_fileno, METH_NOARGS }, |
|---|
| 907 | n/a | |
|---|
| 908 | n/a | /* Support for the context management protocol */ |
|---|
| 909 | n/a | { "__enter__", oss_self, METH_NOARGS }, |
|---|
| 910 | n/a | { "__exit__", oss_exit, METH_VARARGS }, |
|---|
| 911 | n/a | |
|---|
| 912 | n/a | /* Simple ioctl wrappers */ |
|---|
| 913 | n/a | { "controls", (PyCFunction)oss_mixer_controls, METH_VARARGS }, |
|---|
| 914 | n/a | { "stereocontrols", (PyCFunction)oss_mixer_stereocontrols, METH_VARARGS}, |
|---|
| 915 | n/a | { "reccontrols", (PyCFunction)oss_mixer_reccontrols, METH_VARARGS}, |
|---|
| 916 | n/a | { "get", (PyCFunction)oss_mixer_get, METH_VARARGS }, |
|---|
| 917 | n/a | { "set", (PyCFunction)oss_mixer_set, METH_VARARGS }, |
|---|
| 918 | n/a | { "get_recsrc", (PyCFunction)oss_mixer_get_recsrc, METH_VARARGS }, |
|---|
| 919 | n/a | { "set_recsrc", (PyCFunction)oss_mixer_set_recsrc, METH_VARARGS }, |
|---|
| 920 | n/a | |
|---|
| 921 | n/a | { NULL, NULL} |
|---|
| 922 | n/a | }; |
|---|
| 923 | n/a | |
|---|
| 924 | n/a | static PyObject * |
|---|
| 925 | n/a | oss_getattro(oss_audio_t *self, PyObject *nameobj) |
|---|
| 926 | n/a | { |
|---|
| 927 | n/a | const char *name = ""; |
|---|
| 928 | n/a | PyObject * rval = NULL; |
|---|
| 929 | n/a | |
|---|
| 930 | n/a | if (PyUnicode_Check(nameobj)) { |
|---|
| 931 | n/a | name = PyUnicode_AsUTF8(nameobj); |
|---|
| 932 | n/a | if (name == NULL) |
|---|
| 933 | n/a | return NULL; |
|---|
| 934 | n/a | } |
|---|
| 935 | n/a | |
|---|
| 936 | n/a | if (strcmp(name, "closed") == 0) { |
|---|
| 937 | n/a | rval = (self->fd == -1) ? Py_True : Py_False; |
|---|
| 938 | n/a | Py_INCREF(rval); |
|---|
| 939 | n/a | } |
|---|
| 940 | n/a | else if (strcmp(name, "name") == 0) { |
|---|
| 941 | n/a | rval = PyUnicode_FromString(self->devicename); |
|---|
| 942 | n/a | } |
|---|
| 943 | n/a | else if (strcmp(name, "mode") == 0) { |
|---|
| 944 | n/a | /* No need for a "default" in this switch: from newossobject(), |
|---|
| 945 | n/a | self->mode can only be one of these three values. */ |
|---|
| 946 | n/a | switch(self->mode) { |
|---|
| 947 | n/a | case O_RDONLY: |
|---|
| 948 | n/a | rval = PyUnicode_FromString("r"); |
|---|
| 949 | n/a | break; |
|---|
| 950 | n/a | case O_RDWR: |
|---|
| 951 | n/a | rval = PyUnicode_FromString("rw"); |
|---|
| 952 | n/a | break; |
|---|
| 953 | n/a | case O_WRONLY: |
|---|
| 954 | n/a | rval = PyUnicode_FromString("w"); |
|---|
| 955 | n/a | break; |
|---|
| 956 | n/a | } |
|---|
| 957 | n/a | } |
|---|
| 958 | n/a | else { |
|---|
| 959 | n/a | rval = PyObject_GenericGetAttr((PyObject *)self, nameobj); |
|---|
| 960 | n/a | } |
|---|
| 961 | n/a | return rval; |
|---|
| 962 | n/a | } |
|---|
| 963 | n/a | |
|---|
| 964 | n/a | static PyTypeObject OSSAudioType = { |
|---|
| 965 | n/a | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|---|
| 966 | n/a | "ossaudiodev.oss_audio_device", /*tp_name*/ |
|---|
| 967 | n/a | sizeof(oss_audio_t), /*tp_size*/ |
|---|
| 968 | n/a | 0, /*tp_itemsize*/ |
|---|
| 969 | n/a | /* methods */ |
|---|
| 970 | n/a | (destructor)oss_dealloc, /*tp_dealloc*/ |
|---|
| 971 | n/a | 0, /*tp_print*/ |
|---|
| 972 | n/a | 0, /*tp_getattr*/ |
|---|
| 973 | n/a | 0, /*tp_setattr*/ |
|---|
| 974 | n/a | 0, /*tp_reserved*/ |
|---|
| 975 | n/a | 0, /*tp_repr*/ |
|---|
| 976 | n/a | 0, /*tp_as_number*/ |
|---|
| 977 | n/a | 0, /*tp_as_sequence*/ |
|---|
| 978 | n/a | 0, /*tp_as_mapping*/ |
|---|
| 979 | n/a | 0, /*tp_hash*/ |
|---|
| 980 | n/a | 0, /*tp_call*/ |
|---|
| 981 | n/a | 0, /*tp_str*/ |
|---|
| 982 | n/a | (getattrofunc)oss_getattro, /*tp_getattro*/ |
|---|
| 983 | n/a | 0, /*tp_setattro*/ |
|---|
| 984 | n/a | 0, /*tp_as_buffer*/ |
|---|
| 985 | n/a | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
|---|
| 986 | n/a | 0, /*tp_doc*/ |
|---|
| 987 | n/a | 0, /*tp_traverse*/ |
|---|
| 988 | n/a | 0, /*tp_clear*/ |
|---|
| 989 | n/a | 0, /*tp_richcompare*/ |
|---|
| 990 | n/a | 0, /*tp_weaklistoffset*/ |
|---|
| 991 | n/a | 0, /*tp_iter*/ |
|---|
| 992 | n/a | 0, /*tp_iternext*/ |
|---|
| 993 | n/a | oss_methods, /*tp_methods*/ |
|---|
| 994 | n/a | }; |
|---|
| 995 | n/a | |
|---|
| 996 | n/a | static PyTypeObject OSSMixerType = { |
|---|
| 997 | n/a | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|---|
| 998 | n/a | "ossaudiodev.oss_mixer_device", /*tp_name*/ |
|---|
| 999 | n/a | sizeof(oss_mixer_t), /*tp_size*/ |
|---|
| 1000 | n/a | 0, /*tp_itemsize*/ |
|---|
| 1001 | n/a | /* methods */ |
|---|
| 1002 | n/a | (destructor)oss_mixer_dealloc, /*tp_dealloc*/ |
|---|
| 1003 | n/a | 0, /*tp_print*/ |
|---|
| 1004 | n/a | 0, /*tp_getattr*/ |
|---|
| 1005 | n/a | 0, /*tp_setattr*/ |
|---|
| 1006 | n/a | 0, /*tp_reserved*/ |
|---|
| 1007 | n/a | 0, /*tp_repr*/ |
|---|
| 1008 | n/a | 0, /*tp_as_number*/ |
|---|
| 1009 | n/a | 0, /*tp_as_sequence*/ |
|---|
| 1010 | n/a | 0, /*tp_as_mapping*/ |
|---|
| 1011 | n/a | 0, /*tp_hash*/ |
|---|
| 1012 | n/a | 0, /*tp_call*/ |
|---|
| 1013 | n/a | 0, /*tp_str*/ |
|---|
| 1014 | n/a | 0, /*tp_getattro*/ |
|---|
| 1015 | n/a | 0, /*tp_setattro*/ |
|---|
| 1016 | n/a | 0, /*tp_as_buffer*/ |
|---|
| 1017 | n/a | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
|---|
| 1018 | n/a | 0, /*tp_doc*/ |
|---|
| 1019 | n/a | 0, /*tp_traverse*/ |
|---|
| 1020 | n/a | 0, /*tp_clear*/ |
|---|
| 1021 | n/a | 0, /*tp_richcompare*/ |
|---|
| 1022 | n/a | 0, /*tp_weaklistoffset*/ |
|---|
| 1023 | n/a | 0, /*tp_iter*/ |
|---|
| 1024 | n/a | 0, /*tp_iternext*/ |
|---|
| 1025 | n/a | oss_mixer_methods, /*tp_methods*/ |
|---|
| 1026 | n/a | }; |
|---|
| 1027 | n/a | |
|---|
| 1028 | n/a | |
|---|
| 1029 | n/a | static PyObject * |
|---|
| 1030 | n/a | ossopen(PyObject *self, PyObject *args) |
|---|
| 1031 | n/a | { |
|---|
| 1032 | n/a | return (PyObject *)newossobject(args); |
|---|
| 1033 | n/a | } |
|---|
| 1034 | n/a | |
|---|
| 1035 | n/a | static PyObject * |
|---|
| 1036 | n/a | ossopenmixer(PyObject *self, PyObject *args) |
|---|
| 1037 | n/a | { |
|---|
| 1038 | n/a | return (PyObject *)newossmixerobject(args); |
|---|
| 1039 | n/a | } |
|---|
| 1040 | n/a | |
|---|
| 1041 | n/a | static PyMethodDef ossaudiodev_methods[] = { |
|---|
| 1042 | n/a | { "open", ossopen, METH_VARARGS }, |
|---|
| 1043 | n/a | { "openmixer", ossopenmixer, METH_VARARGS }, |
|---|
| 1044 | n/a | { 0, 0 }, |
|---|
| 1045 | n/a | }; |
|---|
| 1046 | n/a | |
|---|
| 1047 | n/a | |
|---|
| 1048 | n/a | #define _EXPORT_INT(mod, name) \ |
|---|
| 1049 | n/a | if (PyModule_AddIntConstant(mod, #name, (long) (name)) == -1) return NULL; |
|---|
| 1050 | n/a | |
|---|
| 1051 | n/a | |
|---|
| 1052 | n/a | static char *control_labels[] = SOUND_DEVICE_LABELS; |
|---|
| 1053 | n/a | static char *control_names[] = SOUND_DEVICE_NAMES; |
|---|
| 1054 | n/a | |
|---|
| 1055 | n/a | |
|---|
| 1056 | n/a | static int |
|---|
| 1057 | n/a | build_namelists (PyObject *module) |
|---|
| 1058 | n/a | { |
|---|
| 1059 | n/a | PyObject *labels; |
|---|
| 1060 | n/a | PyObject *names; |
|---|
| 1061 | n/a | PyObject *s; |
|---|
| 1062 | n/a | int num_controls; |
|---|
| 1063 | n/a | int i; |
|---|
| 1064 | n/a | |
|---|
| 1065 | n/a | num_controls = Py_ARRAY_LENGTH(control_labels); |
|---|
| 1066 | n/a | assert(num_controls == Py_ARRAY_LENGTH(control_names)); |
|---|
| 1067 | n/a | |
|---|
| 1068 | n/a | labels = PyList_New(num_controls); |
|---|
| 1069 | n/a | names = PyList_New(num_controls); |
|---|
| 1070 | n/a | if (labels == NULL || names == NULL) |
|---|
| 1071 | n/a | goto error2; |
|---|
| 1072 | n/a | for (i = 0; i < num_controls; i++) { |
|---|
| 1073 | n/a | s = PyUnicode_FromString(control_labels[i]); |
|---|
| 1074 | n/a | if (s == NULL) |
|---|
| 1075 | n/a | goto error2; |
|---|
| 1076 | n/a | PyList_SET_ITEM(labels, i, s); |
|---|
| 1077 | n/a | |
|---|
| 1078 | n/a | s = PyUnicode_FromString(control_names[i]); |
|---|
| 1079 | n/a | if (s == NULL) |
|---|
| 1080 | n/a | goto error2; |
|---|
| 1081 | n/a | PyList_SET_ITEM(names, i, s); |
|---|
| 1082 | n/a | } |
|---|
| 1083 | n/a | |
|---|
| 1084 | n/a | if (PyModule_AddObject(module, "control_labels", labels) == -1) |
|---|
| 1085 | n/a | goto error2; |
|---|
| 1086 | n/a | if (PyModule_AddObject(module, "control_names", names) == -1) |
|---|
| 1087 | n/a | goto error1; |
|---|
| 1088 | n/a | |
|---|
| 1089 | n/a | return 0; |
|---|
| 1090 | n/a | |
|---|
| 1091 | n/a | error2: |
|---|
| 1092 | n/a | Py_XDECREF(labels); |
|---|
| 1093 | n/a | error1: |
|---|
| 1094 | n/a | Py_XDECREF(names); |
|---|
| 1095 | n/a | return -1; |
|---|
| 1096 | n/a | } |
|---|
| 1097 | n/a | |
|---|
| 1098 | n/a | |
|---|
| 1099 | n/a | static struct PyModuleDef ossaudiodevmodule = { |
|---|
| 1100 | n/a | PyModuleDef_HEAD_INIT, |
|---|
| 1101 | n/a | "ossaudiodev", |
|---|
| 1102 | n/a | NULL, |
|---|
| 1103 | n/a | -1, |
|---|
| 1104 | n/a | ossaudiodev_methods, |
|---|
| 1105 | n/a | NULL, |
|---|
| 1106 | n/a | NULL, |
|---|
| 1107 | n/a | NULL, |
|---|
| 1108 | n/a | NULL |
|---|
| 1109 | n/a | }; |
|---|
| 1110 | n/a | |
|---|
| 1111 | n/a | PyMODINIT_FUNC |
|---|
| 1112 | n/a | PyInit_ossaudiodev(void) |
|---|
| 1113 | n/a | { |
|---|
| 1114 | n/a | PyObject *m; |
|---|
| 1115 | n/a | |
|---|
| 1116 | n/a | if (PyType_Ready(&OSSAudioType) < 0) |
|---|
| 1117 | n/a | return NULL; |
|---|
| 1118 | n/a | |
|---|
| 1119 | n/a | if (PyType_Ready(&OSSMixerType) < 0) |
|---|
| 1120 | n/a | return NULL; |
|---|
| 1121 | n/a | |
|---|
| 1122 | n/a | m = PyModule_Create(&ossaudiodevmodule); |
|---|
| 1123 | n/a | if (m == NULL) |
|---|
| 1124 | n/a | return NULL; |
|---|
| 1125 | n/a | |
|---|
| 1126 | n/a | OSSAudioError = PyErr_NewException("ossaudiodev.OSSAudioError", |
|---|
| 1127 | n/a | NULL, NULL); |
|---|
| 1128 | n/a | if (OSSAudioError) { |
|---|
| 1129 | n/a | /* Each call to PyModule_AddObject decrefs it; compensate: */ |
|---|
| 1130 | n/a | Py_INCREF(OSSAudioError); |
|---|
| 1131 | n/a | Py_INCREF(OSSAudioError); |
|---|
| 1132 | n/a | PyModule_AddObject(m, "error", OSSAudioError); |
|---|
| 1133 | n/a | PyModule_AddObject(m, "OSSAudioError", OSSAudioError); |
|---|
| 1134 | n/a | } |
|---|
| 1135 | n/a | |
|---|
| 1136 | n/a | /* Build 'control_labels' and 'control_names' lists and add them |
|---|
| 1137 | n/a | to the module. */ |
|---|
| 1138 | n/a | if (build_namelists(m) == -1) /* XXX what to do here? */ |
|---|
| 1139 | n/a | return NULL; |
|---|
| 1140 | n/a | |
|---|
| 1141 | n/a | /* Expose the audio format numbers -- essential! */ |
|---|
| 1142 | n/a | _EXPORT_INT(m, AFMT_QUERY); |
|---|
| 1143 | n/a | _EXPORT_INT(m, AFMT_MU_LAW); |
|---|
| 1144 | n/a | _EXPORT_INT(m, AFMT_A_LAW); |
|---|
| 1145 | n/a | _EXPORT_INT(m, AFMT_IMA_ADPCM); |
|---|
| 1146 | n/a | _EXPORT_INT(m, AFMT_U8); |
|---|
| 1147 | n/a | _EXPORT_INT(m, AFMT_S16_LE); |
|---|
| 1148 | n/a | _EXPORT_INT(m, AFMT_S16_BE); |
|---|
| 1149 | n/a | _EXPORT_INT(m, AFMT_S8); |
|---|
| 1150 | n/a | _EXPORT_INT(m, AFMT_U16_LE); |
|---|
| 1151 | n/a | _EXPORT_INT(m, AFMT_U16_BE); |
|---|
| 1152 | n/a | _EXPORT_INT(m, AFMT_MPEG); |
|---|
| 1153 | n/a | #ifdef AFMT_AC3 |
|---|
| 1154 | n/a | _EXPORT_INT(m, AFMT_AC3); |
|---|
| 1155 | n/a | #endif |
|---|
| 1156 | n/a | #ifdef AFMT_S16_NE |
|---|
| 1157 | n/a | _EXPORT_INT(m, AFMT_S16_NE); |
|---|
| 1158 | n/a | #endif |
|---|
| 1159 | n/a | #ifdef AFMT_U16_NE |
|---|
| 1160 | n/a | _EXPORT_INT(m, AFMT_U16_NE); |
|---|
| 1161 | n/a | #endif |
|---|
| 1162 | n/a | #ifdef AFMT_S32_LE |
|---|
| 1163 | n/a | _EXPORT_INT(m, AFMT_S32_LE); |
|---|
| 1164 | n/a | #endif |
|---|
| 1165 | n/a | #ifdef AFMT_S32_BE |
|---|
| 1166 | n/a | _EXPORT_INT(m, AFMT_S32_BE); |
|---|
| 1167 | n/a | #endif |
|---|
| 1168 | n/a | #ifdef AFMT_MPEG |
|---|
| 1169 | n/a | _EXPORT_INT(m, AFMT_MPEG); |
|---|
| 1170 | n/a | #endif |
|---|
| 1171 | n/a | |
|---|
| 1172 | n/a | /* Expose the sound mixer device numbers. */ |
|---|
| 1173 | n/a | _EXPORT_INT(m, SOUND_MIXER_NRDEVICES); |
|---|
| 1174 | n/a | _EXPORT_INT(m, SOUND_MIXER_VOLUME); |
|---|
| 1175 | n/a | _EXPORT_INT(m, SOUND_MIXER_BASS); |
|---|
| 1176 | n/a | _EXPORT_INT(m, SOUND_MIXER_TREBLE); |
|---|
| 1177 | n/a | _EXPORT_INT(m, SOUND_MIXER_SYNTH); |
|---|
| 1178 | n/a | _EXPORT_INT(m, SOUND_MIXER_PCM); |
|---|
| 1179 | n/a | _EXPORT_INT(m, SOUND_MIXER_SPEAKER); |
|---|
| 1180 | n/a | _EXPORT_INT(m, SOUND_MIXER_LINE); |
|---|
| 1181 | n/a | _EXPORT_INT(m, SOUND_MIXER_MIC); |
|---|
| 1182 | n/a | _EXPORT_INT(m, SOUND_MIXER_CD); |
|---|
| 1183 | n/a | _EXPORT_INT(m, SOUND_MIXER_IMIX); |
|---|
| 1184 | n/a | _EXPORT_INT(m, SOUND_MIXER_ALTPCM); |
|---|
| 1185 | n/a | _EXPORT_INT(m, SOUND_MIXER_RECLEV); |
|---|
| 1186 | n/a | _EXPORT_INT(m, SOUND_MIXER_IGAIN); |
|---|
| 1187 | n/a | _EXPORT_INT(m, SOUND_MIXER_OGAIN); |
|---|
| 1188 | n/a | _EXPORT_INT(m, SOUND_MIXER_LINE1); |
|---|
| 1189 | n/a | _EXPORT_INT(m, SOUND_MIXER_LINE2); |
|---|
| 1190 | n/a | _EXPORT_INT(m, SOUND_MIXER_LINE3); |
|---|
| 1191 | n/a | #ifdef SOUND_MIXER_DIGITAL1 |
|---|
| 1192 | n/a | _EXPORT_INT(m, SOUND_MIXER_DIGITAL1); |
|---|
| 1193 | n/a | #endif |
|---|
| 1194 | n/a | #ifdef SOUND_MIXER_DIGITAL2 |
|---|
| 1195 | n/a | _EXPORT_INT(m, SOUND_MIXER_DIGITAL2); |
|---|
| 1196 | n/a | #endif |
|---|
| 1197 | n/a | #ifdef SOUND_MIXER_DIGITAL3 |
|---|
| 1198 | n/a | _EXPORT_INT(m, SOUND_MIXER_DIGITAL3); |
|---|
| 1199 | n/a | #endif |
|---|
| 1200 | n/a | #ifdef SOUND_MIXER_PHONEIN |
|---|
| 1201 | n/a | _EXPORT_INT(m, SOUND_MIXER_PHONEIN); |
|---|
| 1202 | n/a | #endif |
|---|
| 1203 | n/a | #ifdef SOUND_MIXER_PHONEOUT |
|---|
| 1204 | n/a | _EXPORT_INT(m, SOUND_MIXER_PHONEOUT); |
|---|
| 1205 | n/a | #endif |
|---|
| 1206 | n/a | #ifdef SOUND_MIXER_VIDEO |
|---|
| 1207 | n/a | _EXPORT_INT(m, SOUND_MIXER_VIDEO); |
|---|
| 1208 | n/a | #endif |
|---|
| 1209 | n/a | #ifdef SOUND_MIXER_RADIO |
|---|
| 1210 | n/a | _EXPORT_INT(m, SOUND_MIXER_RADIO); |
|---|
| 1211 | n/a | #endif |
|---|
| 1212 | n/a | #ifdef SOUND_MIXER_MONITOR |
|---|
| 1213 | n/a | _EXPORT_INT(m, SOUND_MIXER_MONITOR); |
|---|
| 1214 | n/a | #endif |
|---|
| 1215 | n/a | |
|---|
| 1216 | n/a | /* Expose all the ioctl numbers for masochists who like to do this |
|---|
| 1217 | n/a | stuff directly. */ |
|---|
| 1218 | n/a | _EXPORT_INT(m, SNDCTL_COPR_HALT); |
|---|
| 1219 | n/a | _EXPORT_INT(m, SNDCTL_COPR_LOAD); |
|---|
| 1220 | n/a | _EXPORT_INT(m, SNDCTL_COPR_RCODE); |
|---|
| 1221 | n/a | _EXPORT_INT(m, SNDCTL_COPR_RCVMSG); |
|---|
| 1222 | n/a | _EXPORT_INT(m, SNDCTL_COPR_RDATA); |
|---|
| 1223 | n/a | _EXPORT_INT(m, SNDCTL_COPR_RESET); |
|---|
| 1224 | n/a | _EXPORT_INT(m, SNDCTL_COPR_RUN); |
|---|
| 1225 | n/a | _EXPORT_INT(m, SNDCTL_COPR_SENDMSG); |
|---|
| 1226 | n/a | _EXPORT_INT(m, SNDCTL_COPR_WCODE); |
|---|
| 1227 | n/a | _EXPORT_INT(m, SNDCTL_COPR_WDATA); |
|---|
| 1228 | n/a | #ifdef SNDCTL_DSP_BIND_CHANNEL |
|---|
| 1229 | n/a | _EXPORT_INT(m, SNDCTL_DSP_BIND_CHANNEL); |
|---|
| 1230 | n/a | #endif |
|---|
| 1231 | n/a | _EXPORT_INT(m, SNDCTL_DSP_CHANNELS); |
|---|
| 1232 | n/a | _EXPORT_INT(m, SNDCTL_DSP_GETBLKSIZE); |
|---|
| 1233 | n/a | _EXPORT_INT(m, SNDCTL_DSP_GETCAPS); |
|---|
| 1234 | n/a | #ifdef SNDCTL_DSP_GETCHANNELMASK |
|---|
| 1235 | n/a | _EXPORT_INT(m, SNDCTL_DSP_GETCHANNELMASK); |
|---|
| 1236 | n/a | #endif |
|---|
| 1237 | n/a | _EXPORT_INT(m, SNDCTL_DSP_GETFMTS); |
|---|
| 1238 | n/a | _EXPORT_INT(m, SNDCTL_DSP_GETIPTR); |
|---|
| 1239 | n/a | _EXPORT_INT(m, SNDCTL_DSP_GETISPACE); |
|---|
| 1240 | n/a | #ifdef SNDCTL_DSP_GETODELAY |
|---|
| 1241 | n/a | _EXPORT_INT(m, SNDCTL_DSP_GETODELAY); |
|---|
| 1242 | n/a | #endif |
|---|
| 1243 | n/a | _EXPORT_INT(m, SNDCTL_DSP_GETOPTR); |
|---|
| 1244 | n/a | _EXPORT_INT(m, SNDCTL_DSP_GETOSPACE); |
|---|
| 1245 | n/a | #ifdef SNDCTL_DSP_GETSPDIF |
|---|
| 1246 | n/a | _EXPORT_INT(m, SNDCTL_DSP_GETSPDIF); |
|---|
| 1247 | n/a | #endif |
|---|
| 1248 | n/a | _EXPORT_INT(m, SNDCTL_DSP_GETTRIGGER); |
|---|
| 1249 | n/a | _EXPORT_INT(m, SNDCTL_DSP_MAPINBUF); |
|---|
| 1250 | n/a | _EXPORT_INT(m, SNDCTL_DSP_MAPOUTBUF); |
|---|
| 1251 | n/a | _EXPORT_INT(m, SNDCTL_DSP_NONBLOCK); |
|---|
| 1252 | n/a | _EXPORT_INT(m, SNDCTL_DSP_POST); |
|---|
| 1253 | n/a | #ifdef SNDCTL_DSP_PROFILE |
|---|
| 1254 | n/a | _EXPORT_INT(m, SNDCTL_DSP_PROFILE); |
|---|
| 1255 | n/a | #endif |
|---|
| 1256 | n/a | _EXPORT_INT(m, SNDCTL_DSP_RESET); |
|---|
| 1257 | n/a | _EXPORT_INT(m, SNDCTL_DSP_SAMPLESIZE); |
|---|
| 1258 | n/a | _EXPORT_INT(m, SNDCTL_DSP_SETDUPLEX); |
|---|
| 1259 | n/a | _EXPORT_INT(m, SNDCTL_DSP_SETFMT); |
|---|
| 1260 | n/a | _EXPORT_INT(m, SNDCTL_DSP_SETFRAGMENT); |
|---|
| 1261 | n/a | #ifdef SNDCTL_DSP_SETSPDIF |
|---|
| 1262 | n/a | _EXPORT_INT(m, SNDCTL_DSP_SETSPDIF); |
|---|
| 1263 | n/a | #endif |
|---|
| 1264 | n/a | _EXPORT_INT(m, SNDCTL_DSP_SETSYNCRO); |
|---|
| 1265 | n/a | _EXPORT_INT(m, SNDCTL_DSP_SETTRIGGER); |
|---|
| 1266 | n/a | _EXPORT_INT(m, SNDCTL_DSP_SPEED); |
|---|
| 1267 | n/a | _EXPORT_INT(m, SNDCTL_DSP_STEREO); |
|---|
| 1268 | n/a | _EXPORT_INT(m, SNDCTL_DSP_SUBDIVIDE); |
|---|
| 1269 | n/a | _EXPORT_INT(m, SNDCTL_DSP_SYNC); |
|---|
| 1270 | n/a | _EXPORT_INT(m, SNDCTL_FM_4OP_ENABLE); |
|---|
| 1271 | n/a | _EXPORT_INT(m, SNDCTL_FM_LOAD_INSTR); |
|---|
| 1272 | n/a | _EXPORT_INT(m, SNDCTL_MIDI_INFO); |
|---|
| 1273 | n/a | _EXPORT_INT(m, SNDCTL_MIDI_MPUCMD); |
|---|
| 1274 | n/a | _EXPORT_INT(m, SNDCTL_MIDI_MPUMODE); |
|---|
| 1275 | n/a | _EXPORT_INT(m, SNDCTL_MIDI_PRETIME); |
|---|
| 1276 | n/a | _EXPORT_INT(m, SNDCTL_SEQ_CTRLRATE); |
|---|
| 1277 | n/a | _EXPORT_INT(m, SNDCTL_SEQ_GETINCOUNT); |
|---|
| 1278 | n/a | _EXPORT_INT(m, SNDCTL_SEQ_GETOUTCOUNT); |
|---|
| 1279 | n/a | #ifdef SNDCTL_SEQ_GETTIME |
|---|
| 1280 | n/a | _EXPORT_INT(m, SNDCTL_SEQ_GETTIME); |
|---|
| 1281 | n/a | #endif |
|---|
| 1282 | n/a | _EXPORT_INT(m, SNDCTL_SEQ_NRMIDIS); |
|---|
| 1283 | n/a | _EXPORT_INT(m, SNDCTL_SEQ_NRSYNTHS); |
|---|
| 1284 | n/a | _EXPORT_INT(m, SNDCTL_SEQ_OUTOFBAND); |
|---|
| 1285 | n/a | _EXPORT_INT(m, SNDCTL_SEQ_PANIC); |
|---|
| 1286 | n/a | _EXPORT_INT(m, SNDCTL_SEQ_PERCMODE); |
|---|
| 1287 | n/a | _EXPORT_INT(m, SNDCTL_SEQ_RESET); |
|---|
| 1288 | n/a | _EXPORT_INT(m, SNDCTL_SEQ_RESETSAMPLES); |
|---|
| 1289 | n/a | _EXPORT_INT(m, SNDCTL_SEQ_SYNC); |
|---|
| 1290 | n/a | _EXPORT_INT(m, SNDCTL_SEQ_TESTMIDI); |
|---|
| 1291 | n/a | _EXPORT_INT(m, SNDCTL_SEQ_THRESHOLD); |
|---|
| 1292 | n/a | #ifdef SNDCTL_SYNTH_CONTROL |
|---|
| 1293 | n/a | _EXPORT_INT(m, SNDCTL_SYNTH_CONTROL); |
|---|
| 1294 | n/a | #endif |
|---|
| 1295 | n/a | #ifdef SNDCTL_SYNTH_ID |
|---|
| 1296 | n/a | _EXPORT_INT(m, SNDCTL_SYNTH_ID); |
|---|
| 1297 | n/a | #endif |
|---|
| 1298 | n/a | _EXPORT_INT(m, SNDCTL_SYNTH_INFO); |
|---|
| 1299 | n/a | _EXPORT_INT(m, SNDCTL_SYNTH_MEMAVL); |
|---|
| 1300 | n/a | #ifdef SNDCTL_SYNTH_REMOVESAMPLE |
|---|
| 1301 | n/a | _EXPORT_INT(m, SNDCTL_SYNTH_REMOVESAMPLE); |
|---|
| 1302 | n/a | #endif |
|---|
| 1303 | n/a | _EXPORT_INT(m, SNDCTL_TMR_CONTINUE); |
|---|
| 1304 | n/a | _EXPORT_INT(m, SNDCTL_TMR_METRONOME); |
|---|
| 1305 | n/a | _EXPORT_INT(m, SNDCTL_TMR_SELECT); |
|---|
| 1306 | n/a | _EXPORT_INT(m, SNDCTL_TMR_SOURCE); |
|---|
| 1307 | n/a | _EXPORT_INT(m, SNDCTL_TMR_START); |
|---|
| 1308 | n/a | _EXPORT_INT(m, SNDCTL_TMR_STOP); |
|---|
| 1309 | n/a | _EXPORT_INT(m, SNDCTL_TMR_TEMPO); |
|---|
| 1310 | n/a | _EXPORT_INT(m, SNDCTL_TMR_TIMEBASE); |
|---|
| 1311 | n/a | return m; |
|---|
| 1312 | n/a | } |
|---|