The ioctl() system call
All OSS system calls follow the familiar Posix/Unix semantics. Please look at the standard manual page (man ioctl
) for more informtion. This section will only explain some OSS related details. The error codes returned by OSS as well as their meaning will be described in the Possible error codes (errno) returned by OSS calls section.
The available ioctl call set depends on the device and the calls will be described in the chapters for each device type. All ioctl calls are non-blocking ones except few exceptions that are used to wait until the device has played all of the data written to it.
Some of the ioctl calls have no parameters at all. However most of them have one parameter that is a pointer to an integer variavle or to some structure. The function return of the ioctl() system call has no defined meaning. However return value of -1 means that an error has occurred. In that case the errno system variable will contain the exact error code (see above).
Even if the ioctl call didn't return error it's necessary to check the argument value to see if the device accepted the requested value. Many ioctl calls will use the nearest possible value of the one requested by the application was not supported. For example if an application requests sampling rate of 44000 Hz the device may change it to 44100 Hz. It's responsibility of the application to check if the returned value is suitable for it's purposes.
Most ioctl calls will return only when the application did something seriously wrong. Another reason to an error is that the device is not working properly. If a minor error occurred the ioctl call will just silently modify the argument to the value being actually used.
With OSS the return value of ioctl() is used only for error reporting. The return value has no defined meaning when the call was successful (and it will be 0 in most cases). Applications that use the ioctl return value are likely to fail under different OSS implementations.
Ioctl calls available on audio devices
Source | Explanation |
SNDCTL_DSP_BIND_CHANNEL | Route stereo output to the specified channels (obsolete) |
SNDCTL_DSP_CHANNELS | Set the number of audio channels |
SNDCTL_DSP_COOKEDMODE | Disable/enable the "on fly" format conversions made by the OSS software |
SNDCTL_DSP_CURRENT_IPTR | Returns the current recording position |
SNDCTL_DSP_CURRENT_OPTR | Returns the current playback position |