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

libpulseaudio: add module-aaudio-sink #2734

Merged
merged 3 commits into from
Aug 16, 2018
Merged

libpulseaudio: add module-aaudio-sink #2734

merged 3 commits into from
Aug 16, 2018

Conversation

tomty89
Copy link
Contributor

@tomty89 tomty89 commented Aug 14, 2018

Add a sink module that makes use of the AAudio API, which is
available in Oreo or later.

The sink will have its sample rate and latency configured based on
the info we got with the API. They will also be updated accordingly
when the output device is changed.

@its-pointless
Copy link
Contributor

Fails because libaaudio.so isn't available for android 5 toolchain. Easily fixed by copying over aaudio lib at tool chain creation.

Do you take requests?
Microphone support would be nice

@tomty89
Copy link
Contributor Author

tomty89 commented Aug 14, 2018

@its-pointless Might take a look in the future. But to be honest I am not particularly interested in implementing audio capturing, so most likely I would leave it to someone else. It would be a separate module anyway.

mkdir $TERMUX_PKG_SRCDIR/src/modules/aaudio
cp $TERMUX_PKG_BUILDER_DIR/module-aaudio-sink.c $TERMUX_PKG_SRCDIR/src/modules/aaudio
sed -i "s/define __ANDROID_API__ $TERMUX_PKG_API_LEVEL/define __ANDROID_API__ 21/" \
$TERMUX_STANDALONE_TOOLCHAIN/sysroot/usr/include/android/api-level.h
Copy link
Member

Choose a reason for hiding this comment

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

I think something like

CFLAGS+=" -D__ANDROID_API__=21"

should be enough instead of the sed command, to avoid modifying the toolchain files.


#include <aaudio/AAudio.h>

PA_MODULE_AUTHOR("Lennart Poettering, Nathan Martynov, Tom Yan");
Copy link
Member

Choose a reason for hiding this comment

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

Should this be updated?

Copy link
Member

Choose a reason for hiding this comment

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

I think my name (char *name = "Nathan Martynov";) should be listed in SLES backend source...

Copy link
Member

Choose a reason for hiding this comment

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

Sorry what do you mean? So should I add Nathan Martynov back in module-sles-sink? (Aren't you Twaik Yont btw?)

Nathan Martynov is real name, Twaik Yont is pseudoname. :)

Add a sink module that makes use of the AAudio API, which is
available in Oreo or later.

The sink will have its sample rate and latency configured based on
the info we got with the API. They will also be updated accordingly
when the output device is changed.
s32le output is also now allowed
@fornwall fornwall merged commit 60d5038 into termux:master Aug 16, 2018
@fornwall
Copy link
Member

Thanks! The updated package is now available for installation.

@tomty89 tomty89 deleted the libpulseaudio_aaudio branch August 22, 2018 08:54
@edward-p
Copy link
Contributor

@tomty89

buffer underrun issue with libao

...
I: [pulseaudio] sink-input.c: Created input 0 "libao[pianobar] playback stream" on AAudio_sink with sample spec s16le 2ch 44100Hz and channel map front-left,front-right
I: [pulseaudio] sink-input.c:     media.name = "libao[pianobar] playback stream"
I: [pulseaudio] sink-input.c:     application.name = "libao[pianobar]"
I: [pulseaudio] sink-input.c:     native-protocol.peer = "UNIX socket client"
I: [pulseaudio] sink-input.c:     native-protocol.version = "32"
I: [pulseaudio] sink-input.c:     application.process.id = "2352"
I: [pulseaudio] sink-input.c:     application.process.user = "u0_a114"
I: [pulseaudio] sink-input.c:     application.process.host = "localhost"
I: [pulseaudio] sink-input.c:     application.process.binary = "pianobar"
I: [pulseaudio] sink-input.c:     application.process.machine_id = "localhost"
I: [pulseaudio] sink-input.c:     module-stream-restore.id = "sink-input-by-application-name:libao[pianobar]"
I: [pulseaudio] protocol-native.c: Requested tlength=50.00 ms, minreq=12.49 ms
D: [pulseaudio] protocol-native.c: Adjust latency mode enabled, configuring sink latency to half of overall latency.
D: [pulseaudio] protocol-native.c: Requested latency=12.51 ms, Received latency=30.48 ms
D: [pulseaudio] memblockq.c: memblockq requested: maxlength=4194304, tlength=9784, base=4, prebuf=7584, minreq=2204 maxrewind=0
D: [pulseaudio] memblockq.c: memblockq sanitized: maxlength=4194304, tlength=9784, base=4, prebuf=7584, minreq=2204 maxrewind=0
I: [pulseaudio] protocol-native.c: Final latency 85.94 ms = 30.48 ms + 2*12.49 ms + 30.48 ms
D: [pulseaudio] sink.c: AAudio_sink: state: IDLE -> RUNNING
D: [pulseaudio] core-subscribe.c: Dropped redundant event due to change event.
D: [aaudio-sink] protocol-native.c: Requesting rewind due to end of underrun.
D: [AudioTrack] protocol-native.c: Implicit underrun of 'libao[pianobar] playback stream'
D: [aaudio-sink] protocol-native.c: Requesting rewind due to end of underrun.
D: [AudioTrack] protocol-native.c: Implicit underrun of 'libao[pianobar] playback stream'
D: [aaudio-sink] protocol-native.c: Requesting rewind due to end of underrun.
...

Seems there is something wrong with latency again?

However, since applyed the patch xiph/libao#8 libao works fine with module-seles-sink

@tomty89
Copy link
Contributor Author

tomty89 commented Sep 16, 2018

I don't have libao built here at the moment, but no apparent problem here with mpv. Set pulse-buffer (i.e. tlength) to 25, tested with both the optimal and a non-optimal rate with the rate module argument, both appears to work fine.

Note that by default the AAudio sink module configure the latency based on buffer size info reported by the system/device, while the SLES sink module configure that to a fixed default value, but both modules has the module argument latency for you to set it to a desired fixed value.

@edward-p
Copy link
Contributor

OK, this can be fixed manually by set buffer_time=280 to libao.conf

@tomty89
Copy link
Contributor Author

tomty89 commented Sep 16, 2018

I assume you are using Bluetooth audio?

I've seen device/ROM reports fast flag and a low buffer size for Bluetooth audio, and I doubt that they are valid.

@edward-p
Copy link
Contributor

Yeah,but I just find my buffer size for none Bluetooth audio is also very low.

I: [pulseaudio] sink-input.c:     module-stream-restore.id = "sink-input-by-application-name:libao[pianobar]"
I: [pulseaudio] protocol-native.c: Requested tlength=50.00 ms, minreq=12.49 ms
D: [pulseaudio] protocol-native.c: Adjust latency mode enabled, configuring sink latency to half of overall latency.
D: [pulseaudio] protocol-native.c: Requested latency=12.51 ms, Received latency=16.00 ms
D: [pulseaudio] memblockq.c: memblockq requested: maxlength=4194304, tlength=7232, base=4, prebuf=5032, minreq=2204 maxrewind=0
D: [pulseaudio] memblockq.c: memblockq sanitized: maxlength=4194304, tlength=7232, base=4, prebuf=5032, minreq=2204 maxrewind=0
I: [pulseaudio] protocol-native.c: Final latency 57.00 ms = 16.01 ms + 2*12.49 ms + 16.00 ms
D: [pulseaudio] sink.c: AAudio_sink: state: IDLE -> RUNNING
D: [pulseaudio] core-subscribe.c: Dropped redundant event due to change event.
D: [aaudio-sink] protocol-native.c: Requesting rewind due to end of underrun.
D: [AudioTrack] protocol-native.c: Implicit underrun of 'libao[pianobar] playback stream'
D: [aaudio-sink] protocol-native.c: Requesting rewind due to end of underrun.
D: [AudioTrack] protocol-native.c: Implicit underrun of 'libao[pianobar] playback stream'
D: [aaudio-sink] protocol-native.c: Requesting rewind due to end of underrun.
D: [AudioTrack] protocol-native.c: Implicit underrun of 'libao[pianobar] playback stream'
D: [aaudio-sink] protocol-native.c: Requesting rewind due to end of underrun.
E: [AudioTrack] memblockq.c: Assertion 'bq->n_blocks >= 1' failed at /home/builder/.termux-build/libpulseaudio/src/src/pulsecore/memblockq.c:183, function void drop_block(pa_memblockq *, struct list_item *)(). Aborting.
[1]    7761 abort      pulseaudio -vvv --daemonize=no

I will test it on my other devices later.

@tomty89
Copy link
Contributor Author

tomty89 commented Sep 16, 2018

It is normal to get low latency and fast flag with wired audio (including USB). Not sure if it's a problem of your device or libao/pianobar.

@tomty89
Copy link
Contributor Author

tomty89 commented Sep 16, 2018

Btw the assertion failure is probably a separate issue. I've seen it occur with both modules. It's pretty random and I don't know what exactly triggers it. Could be some upstream bug as well.

@edward-p
Copy link
Contributor

Both wired audio and Bluetooth audio works fine on my old device without set latency manually. I think it's a problem of my new device. It should be an issue of the ROM. However, I assume that the manufacturer can achieve low latency on some high-end Bluetooth headphones which I don't have :(

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.

5 participants