Pulseaudio on Mac OS X

Pulseaudio on Mac OS X

PulseAudio on Mac OS X Daniel Mack [email protected] Abstract • IOAudioEngines are required to report PulseAudio is becoming the standard audio envi- their sample rate by delivering exact times- ronment on many Linux dektops nowadays. As it tamps whenever their internal ring buffer offers network transparency as well as other inter- rolls over. The more precise, the better, esting features OS X won't offer its users natively, as its userspace counterpart (the HAL, see it's time to have a closer look on possibilities on how below) can do better estimation of the de- to port this piece of software over to yet another vice's speed and approximate closer to the platform. actual hardware sample pointer positions, In the recent months, I put some effort into at- resulting in smaller latencies. tempts to port PulseAudio to Mac OS X, aiming for cross-platform interoperability between hetero- 1.2 HAL gen audio host networks and enabling other features PulseAudio offers such as uPnP/AV streaming. The HAL is part of the CoreAudio framework This paper will first give a short overview about and is automatically instanciated within the how CoreAudio, the native audio system on Mac OS process image of each CoreAudio client appli- X, is structured, the various ways that can be used cation. During its startup, it scans for plugins to plug into this system, and then focus on the steps in /Library/Audio/Plugins/HAL and this way it takes to port PulseAudio to Mac OS X. offers the possibility of loading userspace imple- Keywords mentations of audio drivers. The HAL is also in charge of interfacing to the IOAudio based PulseAudio, Mac OS X, network audio, virtual audio kernel drivers and hence acts as their bridge to driver, portability userspace clients. 1 CoreAudio essentials 1.3 AudioHardwarePlugins for HAL 1.1 IOAudio Kernel extensions Automatically loaded by the HAL code upon • The Darwin kernel is in charge of handling creation of an audio client, AudioHardwarePlu- hardware drivers, abstracted via the IOKit gins are instanciated via the standard CFBundle API framework. load mechanisms. An interface must be im- plemented to provide the hooks needed by the • The kernel's representation of an audio de- HAL, and a full-fledged infrastructure of APIs vice is an object derived from the IOAu- for adding audio devices, streams and controls dioDevice base class, which holds a refer- are available. Unlike kernel drivers, virtual ence of an IOAudioEngine (or a derived drivers implemented as HAL plugin are working type thereof). on a per-client base, so their implementations • The kernel's way of adding audio streams must care for mixing and inter-client operabil- to a device is attaching objects of type ity themselves. IOAudioStream to an IOAudioEngine. 1.4 System Sound Server • The kernel's API is only one way to provide This daemon is in charge for handling system- an audio device to the system; the other is internal sound requests such as interface and a plugin for the HAL (see above). alert sounds. • Sample material is organized in ring buffers 1.5 coreaudiod which are usually shared with the hard- coreaudiod is a system-wide daemon that ware. gives home to the System Sound Server and provides the AudioHardwareServices API for re-route audio differentely. An example of this querying parameters of available audio drivers. approach is the closed-source shareware utility The daemon also handles the default sound in- AudioHijack2. More research is needed in or- terface configuration on a per-user level1. der to find out whether this approach is also feasable for PulseAudio sound re-routing. At 1.6 AudioUnits the time of writing, this option is not being in- AudioUnits are Mac OS X typical CFBundles vestigated on. which can be installed user-wide or system-wide to fixed locations in the file system and which 3 PulseAudio on OS X can be accessed by arbitrary applications with In order to bring PulseAudio to Mac OS X, an standarized API for audio processing. They some tweaks are needed to the core system, can also offer a graphical representation for pa- and some parts have to be re-developed from rameter control and visualization. The two sup- scratch. ported types of AudioUnit plugins are effect processors and virtual instruments. 3.1 pulseaudiod Porting the daemon is of course the main part 2 Possible audio hooks of the work as it is the heart of the whole sys- The purpose of this project is to be able to hook tem other pieces connect to. Since a couple of into the transport channels of all audio applica- versions, pulseaudiod, along with a selection of tions - including system sounds, if desired - and its essential modules, builds fine on OS X. Some re-route audio through an either local or remote adoptions were neccessary to make this happen. PulseAudio server connection. Mac OS X officially offers a number of ways • poll() is broken since Mac OS X 10.3, dis- to access the audio material: respecting the timeout argument and re- turning immediately if no file descriptor • A virtual sound card interface implemented has any pending event. This was circum- as kernel driver which can either be con- vented by using the select() syscall, just like figured as standard sound interface for all PulseAudio does for Windows. appliactions and/or system sounds. Appli- cations may let the user decide which sound • recv() with MSG PEEK does in fact eat up card to use for input and output sound data from the given file descriptor. The rendering, but for those which don't (like workaround was to use a different ioctl() iTunes, QuicktimePlayer, iChat, ...), set- for this purpose. ting the system-wide default is the only op- • OS X lacks a proper implementation of tion. POSIX locks but implements its own thing • A virtual sound card interface implemented as defined in Multiprocessing.h. A ver- as AudioHardwarePlugin for the HAL. The sion which uses them internally for the same rules as for the kernel versions apply: PulseAudio daemon was needed. if an application doesn't allow its user to • clock functions work differently than on choose the device for audio output, the sys- Linux, so a specialized version for the clock tem falls back to the configured default. wrapper functions in PulseAudio was also • An AudioUnit which is loaded by more ad- neccessary. vanced applications such as Logic. For ap- • Mac OS X offers a powerful API to give plication which don't use this plugin inter- userland tasks high priority. This is es- face, this is no option. sential for real-time applications just like PulseAudio, so an implementation using Another possible way of interaction is unof- this API was added to the daemon. ficial, somewhat hackish and based on the idea of library pre-loading for selected applications. • Some library PulseAudio uses are not suit- Binaries are relaunched with their CoreAudio li- able for OS X. Work on the build system braries temporarily replaced by versions which was done to build some parts of the suite conditionally. 1http://lists.apple.com/archives/coreaudio- api/2007/Nov/msg00068.html 2http://rogueamoeba.com/audiohijackpro/ 3.2 CoreAudio device detection module dependencies for others are copied to the frame- In order to make use of audio input and work bundle and the tool install name tool output devices CoreAudio knows about, a which ships with XCode is called to remap the new pulseaudiod module was written which path locations recursively. uses the CoreAudio specific callback mecha- 3.6 PulseConsole nisms to detect hotplugged devices. For each PulseConsole is a Cocoa based GUI applica- detected device, a new module instance of tion written in Objective-C that aims to be a module-coreaudio-device is loaded, and un- comfortable configuration tool for PulseAudio loaded on device removal, accordingly. servers, both local and remote instances. It of- This module is part of the offcial PulseAu- fers a way to inspect and possibly modify details dio sources since some months and is called and parameters and a nice GUI for per-stream module-coreaudio-detect. mixer controls and routing settings. 3.3 CoreAudio source/sink module The plan is to make this tool as convenient as possible, also with GUIs for mixer controls, Loaded and unloaded by the house-keeping detailed server inspection and all the like. This module module-coreaudio-detect, this mod- will need some time to finish, but is actively ule accesses the actual CoreAudio device, developed already. queries its properties and acts as translation layer between CoreAudio and PulseAudio. An 3.7 AudioHardwarePlugin for HAL important implementation detail is that code in CoreAudio allows to add software plugins to this module has to cope with the fact that audio register virtual sound interfaces. Such a plugin is exchanged between different threads. was developed for PulseAudio, with the follow- This module is part of the offcial PulseAu- ing key features. dio sources since many months and is called module-coreaudio-device. • Allows audio routing to both the local and any remote server instances. 3.4 Bonjour/ZeroConf service • Multiple plugin instances communicate discovery module with each other over a distributed notifi- Porting the dependency chain for Avahi (dbus, cation center. This is essential for sharing ...) wasn't an easy and straight-forward task to stream volume information. do, and given the fact that Mac OS X features a convenient API for the same task, a new module • Each plugin instance announces itself to a for mDNS service notification was written. The system-wide message bus and can receive code for this module purely uses Apple's own setup controls.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    5 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us