Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kernel vs user-space audio device driver on macOS

I'm in a need to develop an audio device driver for System Audio Capture(based on Soundflower).
But soon a problem appeared that it seems IOAudioFamily stack is being deprecated in OSX 10.10 and later.
Looking through the IOAudioDevice and IOAudioEngine header files it seems that apple recommends now using the <CoreAudio/AudioServerPlugIn.h> API which runs in user-space. But I can't find lots of information on this user-space device drivers topic. It seems that the only resource is the Apple provided sample devices from https://developer.apple.com/library/prerelease/content/samplecode/AudioDriverExamples/Introduction/Intro.html
Looking through the examples I find that its a lot harder and more work to develop a user-space driver instead of I/O Kit kernel based.
So the question arises what should motivate to develop a device driver in user-space instead of kernel space?

like image 677
lychee Avatar asked Aug 27 '16 20:08

lychee


People also ask

Do Macs need audio drivers?

Audio and MIDI devices (as well as printers & other external hardware) require drivers to connect with PCs & Macs. Without the driver, your computer may not be able to communicate properly with the device.

Are drivers in kernel space?

User space drivers run in user space. Kernel drivers run in kernel space.

Where are audio drivers on Mac?

Use macOS audio drivers In the Audio MIDI Setup app on your Mac, in the Audio Devices window, select the speakers for your Mac in the list of audio devices. At the bottom of the sidebar, click the Configure Selected Device pop-up menu , then choose “Use This Device for Sound Output.”


1 Answers

The "SimpleAudioDriver" example is somewhat misnamed. It demonstrates pretty much every feature of the API. This is handy as a reference if you actually need to use those features. It's also structured in a way that's maybe a little more complicated than necessary.

For a virtual device, the NullAudioDriver is probably a much better base, and much, much easier to understand (single source file, if I remember correctly). SimpleAudioDriver is more useful for dealing with issues such as hotplugging, multiple instances of identical devices, etc.

IOAudioEngine is deprecated as you say, and has been since OS X 10.10. Expect it to go away eventually, so if you build your driver with it, you'll probably need to rewrite it sooner than if you create a Core Audio Server Plugin based one.

Testing and debugging audio drivers is awkward either way (due to being so time sensitive), but I'd say userspace ones are slightly less frustrating to deal with. You'll still want to test on a different machine than your development Mac, because if coreaudiod crashes or hangs, apps usually start locking up too, so being able to just ssh in, delete your plugin and kill coreaudiod is handy. Certainly quicker turnaround than having to reboot.

(FWIW, I've shipped both kernel and userspace OS X audio drivers, and I spend a lot of time working on kexts.)

like image 178
pmdj Avatar answered Oct 18 '22 21:10

pmdj