Skip to content

Implement AAudio output plugin - #1346

Merged
flyingmutant merged 2 commits into
cmus:masterfrom
pgaskin:aaudio
Sep 10, 2024
Merged

flyingmutant merged 2 commits into
cmus:masterfrom
pgaskin:aaudio

Conversation

@pgaskin

@pgaskin pgaskin commented Aug 5, 2024 •

Copy link
Copy Markdown
Member

Support native audio on Android 8.1 and later.

  • Better battery life.
  • Configurable latency.
  • Configurable capture policy.
  • Configurable sharing mode.
  • Configurable spatialization.
  • Full multi-channel audio support.
  • Supports pause_on_output_change.

To test this in Termux, compile and run cmus on the device. You can also compile just the plugin with $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -target aarch64-linux-android26 -shared -o aaudio.so -fPIC -D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__ -Werror=unguarded-availability -Wall -std=gnu11 op/aaudio.c -laaudio, and copy it to ~/../usr/lib/cmus/op.

Set the output plugin with :set output_plugin=aaudio.

This plugin has a higher priority than pulse, but will fallback on unsupported devices.

@pgaskin
pgaskin force-pushed the aaudio branch 11 times, most recently from 311e822 to f862051 Compare August 5, 2024 22:25
@pgaskin
pgaskin marked this pull request as draft August 5, 2024 22:43
@pgaskin
pgaskin force-pushed the aaudio branch 3 times, most recently from 011d003 to d9db94d Compare August 6, 2024 00:44
@pgaskin
pgaskin marked this pull request as ready for review August 6, 2024 00:45

@pgaskin pgaskin left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this on a Pixel 8 running Android 14, and a few emulators.

Has much lower CPU usage than pulse, and similar latency. Didn't crash or hang while testing various edge cases.

@pgaskin
pgaskin force-pushed the aaudio branch 5 times, most recently from 096ca05 to a876c0a Compare August 7, 2024 07:34

@pgaskin pgaskin left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now fully supports multi-channel audio, tested with various multi-channel audio files on Android 14.

@pgaskin
pgaskin force-pushed the aaudio branch 4 times, most recently from e8587fd to b54ab74 Compare August 7, 2024 10:20

@pgaskin pgaskin left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed an edge case where pause_on_output_change may cause cmus to hang due to cmus getting notified of the stream disconnect and attempting to pause it, and the pause getting stuck waiting for the stream state to change to paused (which never happens since the stream has already disconnected).

@pgaskin pgaskin left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed some issues with weak linking not working if the toolchain uses -Wl,--as-needed by default (e.g., Termux package build).

@pgaskin
pgaskin force-pushed the aaudio branch 2 times, most recently from 670fc3d to 29e6c04 Compare August 8, 2024 13:26

@pgaskin pgaskin left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a bit more refactoring; should be done now.

@pgaskin
pgaskin force-pushed the aaudio branch 3 times, most recently from 360425a to 870a7ea Compare August 8, 2024 14:06
TomJo2000 pushed a commit to pgaskin/termux-packages that referenced this pull request Aug 11, 2024
Support native audio on Android 8.1 and later.

- Better battery life.
- Configurable latency.
- Configurable capture policy.
- Configurable sharing mode.
- Configurable spatialization.
- Full multi-channel audio support.
- Supports `pause_on_output_change`.

Also includes fix for pause_on_output change with softvol enabled
since aaudio doesn't have volume control.

cmus/cmus#1346
cmus/cmus#1353
TomJo2000 pushed a commit to termux/termux-packages that referenced this pull request Aug 11, 2024
Cherry-pick in support native audio on Android 8.1 and later.
Upstream PRs: cmus/cmus#1346, cmus/cmus#1353
termux-pacman-bot added a commit to termux-pacman/termux-packages that referenced this pull request Aug 11, 2024
Cherry-pick in support native audio on Android 8.1 and later.
Upstream PRs: cmus/cmus#1346, cmus/cmus#1353
@pgaskin

pgaskin commented Aug 15, 2024

Copy link
Copy Markdown
Member Author

I think this is done, and I've been using it daily for the last week.

@pgaskin

pgaskin commented Sep 2, 2024

Copy link
Copy Markdown
Member Author

@flyingmutant

@gavtroy gavtroy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat lightweight review as it's completely over my head, but it looks okay. I briefly tested it out but only with boring files and a boring phone speaker :)

Comment thread op/aaudio.c Resolved
Comment thread op/aaudio.c Resolved
Comment thread op/aaudio.c Resolved
Comment thread op/aaudio.c Resolved
Comment thread op/aaudio.c Resolved
@flyingmutant

Copy link
Copy Markdown
Member

Wow, this is huge, great job! What is the main use case for uploading aaudio.so?

@pgaskin

pgaskin commented Sep 9, 2024 •

Copy link
Copy Markdown
Member Author

Huh? I didn't commit aaudio.so AFAICT.

If you mean in GitHub Actions, we ensure it builds with the latest NDK toolchain so we have as much coverage as possible, and we upload it since it'll work as-is for testing (it doesn't depend on any of the config vars).

BTW, can you rebase-merge this rather than squashing it?

@flyingmutant

Copy link
Copy Markdown
Member

Sure, I wouldn't squash it, but please rebase the branch, I think I don't have permissions to rebase myself.

Support native audio on Android 8.1 and later.

- Better battery life.
- Configurable latency.
- Configurable capture policy.
- Configurable sharing mode.
- Configurable spatialization.
- Full multi-channel audio support.
- Supports `pause_on_output_change`.
@flyingmutant

Copy link
Copy Markdown
Member

Done!

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