Audio Subsystem

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();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值