What is required to make Android use a new Audio HAL

天大地大妈咪最大 提交于 2019-11-29 09:34:05

Found answers.

For out stream:

  1. Outputs that don't support AUDIO_CHANNEL_OUT_STEREO are not being opened by Android
  2. Outputs that mention flag AUDIO_OUTPUT_FLAG_DIRECT are not opened by Android automatically. This is evident in following code in AudioPolicyManager.cpp

        if ((outProfile->mFlags & AUDIO_OUTPUT_FLAG_DIRECT) != 0) {
            continue;
        }
    

    from here

There may be a way to open them in programatically, but I have not found answer to that.

These two, once fixed were sufficient for Android to start using my out stream.

For in stream:

In stream was already a part of results of AudioManager.getDevices()

So it was possible to read from vloop in stream after AudioTrack.setPreferredDevice().

To ensure that other apps will read mic input from vloop, I had to declare it to implement AUDIO_DEVICE_IN_BUILTIN_MIC. For this to work, I also removed AUDIO_DEVICE_IN_BUILTIN_MIC from primary HAL in audio_policy.conf.

Additionally, I made in stream stereo only to maintain compatibility with out stream buffer format.

After these changes, I see that there are continuous read and write calls coming to vloop.

UPDATE:

I later found that above mentioned behavior is dependent on Audio Policy Manager implementation. Most of them behave same way, (e.g. most open INBUILT_MIC for VOICE_RECOGNITION input) but some may not (Nexus Player) For these outliers, either implemnent what their APMs open, or modify APMs to open what your HAL implements.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!