Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement AIDL IEffect ViPER library #25

Draft
wants to merge 1 commit into
base: foss
Choose a base branch
from

Conversation

anonymix007
Copy link

@anonymix007 anonymix007 commented Sep 27, 2024

Only compile-tested.

Should fix AndroidAudioMods/ViPER4Android#101 for Pixel 9

@iscle
Copy link
Collaborator

iscle commented Sep 27, 2024

Hey!

Thanks for the PR, looks good :)

Do you have any idea on how to compile it? I guess this is mostly used with the AOSP build system, but what about standalone?

@anonymix007
Copy link
Author

I believe there's no easy way. Too much libraries and headers from AOSP are needed (i.e. AIDL interfaces headers, aidl2legacy library and so on).
Though one may probably generate CMakeLists for all the relevant projects and/or import them into the repo. Alternatively, aospless may be used.

@iscle
Copy link
Collaborator

iscle commented Sep 27, 2024

Thanks, will check it later.

However, even if this builds, I'm bot sure how'd we get Android to detect it and use it as an audio effects library. It has to be registered somewhere with the appropiate UUID and lib name...

@anonymix007
Copy link
Author

It has to be registered somewhere with the appropiate UUID and lib name...

Yes

@iscle
Copy link
Collaborator

iscle commented Sep 27, 2024

It has to be registered somewhere with the appropiate UUID and lib name...

Yes

I think this file does not get used anymore in Pixel 9... :( Although the issue maybe was that it was not an AIDL lib, but I did not see anything in the logs.

On Pixel 9, Google registers the effects using a custom library in vendor (IIRC): https://dumps.tadiphone.dev/dumps/google/komodo/-/blob/komodo-user-14-AD1A.240530.047-12143574-release-keys/vendor/lib64/vendor.google.whitechapel.audio.hal.services.so

@anonymix007
Copy link
Author

anonymix007 commented Sep 27, 2024

Actually, the effects themselves are probably in this library: https://dumps.tadiphone.dev/dumps/google/komodo/-/blob/komodo-user-14-AD1A.240530.047-12143574-release-keys/vendor/lib64/vendor.google.whitechapel.audio.hal.effect.so
And the vendor.google.whitechapel.audio.hal.services.so appears to be the effect factory.

That xml file is present in newer builds though: https://dumps.tadiphone.dev/dumps/google/komodo/-/blob/komodo_beta-user-15-AP41.240726.010-12266677-release-keys/system/system/etc/audio_effects.xml

@anonymix007
Copy link
Author

Okay, it seems that Google hardcoded a few builtin effects and we just can't easily add more of them without dirty tricks.
We can build custom effects HAL, change the instance from default to i.e. viper4a and also patch the [email protected] to use that instance instead.
It'll break Google offloaded audio effects, but who uses them anyway?
Or we may patch android.hardware.audio.service-aidl.aoc to load libv4aidl_re.so instead of one of the predefined libs (libvisualizeraidl.so, libdynamicsprocessingaidl.so, libreverbaidl.so, libdownmixaidl.so, libloudnessenhanceraidl.so, libhapticgeneratoraidl.so).

The ideal solution would be to file a bug to Google so that they implement audio_effects_config.xml parsing in their audio hal.

Do you have a Pixel 9 or any other means of testing this?

@Martmists-GH
Copy link
Member

I'd say wait and see what AudModLib does, since it'll be the main component adding support for multiple, possibly conflicting effects.

@anonymix007
Copy link
Author

anonymix007 commented Sep 27, 2024

AudModLib

It looks abandoned since last update was more than a year ago. Or am I looking at the wrong repo?

As of now, this (hardcoded list of effects) is exclusively a Pixel problem. All current Qualcomm devices still have HIDL audio HAL. Though maybe 8g4 will switch to AIDL, we'll know it in a few months. Hopefully it will just have audio_effects_config.xml so this won't be an issue, but even if it will be an issue, Qualcomm's HALs are usually open source unlike Google's.

Multiple effects can be added via the first (custom effects HAL) method.

@iscle
Copy link
Collaborator

iscle commented Sep 27, 2024

I'd say wait and see what AudModLib does, since it'll be the main component adding support for multiple, possibly conflicting effects.

AudioModificationLibrary is officially dead, Zack stopped all public development on his projects. I'm working on a method to inject the libs, I plan on updating the AML module myself if it ends up working (he gave me access to the repo 😋)

@iscle
Copy link
Collaborator

iscle commented Sep 27, 2024

We can build custom effects HAL

I did look into this a few weeks ago, and I did not see it as a nice universal / viable solution.

Do you have a Pixel 9 or any other means of testing this?

Sadly, no, but I have some people willing to test things out. Not ideal, of course.

--

My plan is to hook into some effect functions by loading a custom library with LD_PRELOAD before launching the audioserver executable. Then injecting our own effects after the device default ones are loaded by the system. It looks doable, audioserver is started by an init.rc file, which has the ability to also set env variables (setenv) before running execve on it. However, I did not have time to test it out yet. Since the audioserver structure has not changed, it should be a universal fix for all android versions and we can just forget about xml files and other stuff.

@anonymix007
Copy link
Author

I did look into this a few weeks ago, and I did not see it as a nice universal / viable solution.

Are there any problems other than the lack of stock effects with this approach? We probably can try to implement whatever effects Pixels have by default as well since there's a separate library with them (vendor.google.whitechapel.audio.hal.effect.so). The good thing at it would be possible to patch system libraries with a simple sed call, so no need to recompile them after each Android release.

My plan is to hook into some effect functions by loading a custom library with LD_PRELOAD before launching the audioserver executable.

I had some success with using LSPosed for replacing system libraries (Bluetooth stack, to be precise), though just replacing .so files with the patched ones should do. Do you really have to use LD_PRELOAD?
[email protected] (EffectsFactoryHalAidl::createEffect and a few other functions) and the HIDL libaudiohal@?.?.so (EffectsFactoryHalHidl::createEffect and a few others) look like a good candidates to inject code to. The question is, will the data processing function be called if another effect will be added there?

But this will heavily rely on having the same system libraries, so probably won't be very universal, i.e. if AIDL version was incremented in QPR or in a major release, these libraries will fail to load due to missing dependencies unless the module will include all of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants