ntroduction
Android provides two native layers that handle audio software:
- Audio Flinger: the audio software implementation that provides the minimum required audio functions (as illustrated in the diagram below).
- AudioHardwareInterface: the hardware abstraction layer that hides driver-specific audio implementations from the Android platform.
Solid elements represent Android blocks and dashed elements represent partner-specific proprietary blocks.
Porting Android to other Audio Stacks
Porting Android to other audio stacks (OSS, ALSA, proprietary user-space audio libraries, etc.) requires inheriting from and modifying AudioHardwareInterface
to support the driver-specific implementation.
AudioHardwareInterface Abstract Class
AudioHardwareInterface
(//device/servers/audio/flinger
) contains several pure virtual functions that the audio driver class being ported needs to implement.
Modifying AudioHardwareInterface
Once the audio driver that inherits AudioHardwareInterface
is ready, modify the static function AudioHardwareInterface::create()
in order to link/load the driver in Android.
Assume the manufacturer audio driver inherits from AudioHarddwareInterface
and that it is compiled into a native shared library (libaudio.so
). In this case, use dlopen
to load the library.
You can find an example of a similar implementation in//device/libs/media/mediaplayer.cpp
. (Note that the example below uses libpv.so
because this is a real code snippet from mediaplayer.cpp
. If your native shared library is calledlibaudio.so
, replace libpv.so
with your libaudio.so
.)
// load PV library and create PV player mLibHandle = dlopen("libpv.so", RTLD_NOW); if (!mLibHandle) { LOGE("dlopen failed on libpv.so/n"); return UNKNOWN_ERROR; } createPlayer_f createPlayer = reinterpret_cast(dlsym(mLibHandle, "createPlayer")); if (!createPlayer) { LOGE("dlsym failed on createPlayer in libpv.so/n"); return UNKNOWN_ERROR; }
Load the libraries with a call from AudioHardwareInterface::create()
, as illustrated below (full code found in //device/servers/audioflinger
).
if (property_get("ro.kernel.qemu", value, 0)) { LOGD("Running in emulation - using generic audio driver"); hw = new AudioHardwareGeneric(); } else { // Insert calling of dynamic loading of driver here... } if (hw->initCheck() != NO_ERROR) { LOGW("Using stubbed audio hardware. No sound will be produced."); delete hw; hw = new AudioHardwareStub(); }