I am writing a new Android Audio HAL, to let my App to feed audio to other apps, to allow my handheld remote microphone input to reach Google app. Essentially, a Virtual Aud
Found answers.
For out stream:
AUDIO_CHANNEL_OUT_STEREO
are not being opened by AndroidOutputs 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.