xiph / libao

Portable audio output library
GNU General Public License v2.0
72 stars 32 forks source link

Building libao using Android standalone toolchain #7

Open lm8 opened 6 years ago

lm8 commented 6 years ago

Was experimenting to see if libao would build for Android using the standalone toolchain. I hit an issue with it not being able to find the soundcard.h include.

In configure.ac where the following appear: AC_CHECK_HEADERS(sys/soundcard.h, have_oss=yes) AC_CHECK_HEADERS(machine/soundcard.h, have_oss=yes) I ended up adding this after it: AC_CHECK_HEADERS(linux/soundcard.h, have_oss=yes)

I then patched ao_oss.c to use the HAVE_LINUX_SOUNDCARD_H define that the above check created: diff -Naurp src/libao-1.2.0/src/plugins/oss/ao_oss.c tmp/libao-1.2.0/src/plugins/oss/ao_oss.c --- src/libao-1.2.0/src/plugins/oss/ao_oss.c 2014-01-27 12:02:05 -0500 +++ tmp/libao-1.2.0/src/plugins/oss/ao_oss.c @@ -34,11 +34,15 @@

include

include

include

+#ifdef HAVE_LINUX_SOUNDCARD_H +#include <linux/soundcard.h> +#else

if defined(OpenBSD) || defined(NetBSD)

include

else

include <sys/soundcard.h>

endif

+#endif

include <sys/ioctl.h>

include "ao/ao.h"

After those changes, I was able to get libao to build with some sound support. Thought I'd mention the patches I needed in case anyone else was interested or might need them in the future.

Thank you.

nwrkbiz commented 5 years ago

Can you please post the full log, i guess this error occours due to a missing dependency for the platform you want to compile this library for. If you want to do cross compilation you need the dependencies (i.e. "alsa for android") on your host system.

I do not know if shared a library like that exists for android. If you do not need live output disable the plugin that is causing problems by passing "--disable-" to the configure script.

circinusX1 commented 3 years ago

Hi am trying to configure it for android I cannot pass the error. (fails sanity check)

checking how to run the C preprocessor... /sdaone/BOARDS/android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android28-clang++
configure: error: in `/sdaone/GIT_HUB/tcp_player/cli/android/libao-1.2.0':
configure: error: C preprocessor "/sdaone/BOARDS/android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/
x86_64-linux-android2#-clang++" fails sanity check
See `config.log' for more details
# linux-android2#-clang++  the # was 21 22 23...28 same error

The script

# omitted for clarity
export CC=$TOOLCHAIN/bin/$TARGET$API-clang
#export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
export CPP=$TOOLCHAIN/bin/$TARGET$API-clang++
#export CPP="$CC ${ANDROID_CFLAGS} -E"
# omitted for clarity
./configure --target=${TARGET} --host=${TARGET} --prefix=${SYSROOT}

where

CC=/sdaone/BOARDS/android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android28-clang
CPP=/sdaone/BOARDS/android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android28-clang++
CXX=
which clang: /sdaone/BOARDS/android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
which clang++: /sdaone/BOARDS/android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
TARGET=x86_64-linux-android
SYSROOT=/sdaone/BOARDS/android/android-ndk-r19c/sysroot/
TOOLCHAIN=/sdaone/BOARDS/android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64
PATH=/sdaone/BOARDS/android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin:/home/marius/usr/bin:/home/marius/bin:/home/marius/.local/bin:/opt/SEGGER/JLink/:/usr/local/gcc-arm-none-eabi-4_9-2015q3/bin:/home/marius/bin/node-v12.14.0-linux-x64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin/flutter:/usr/bin/dart:/home/marius/APPS/cling_2020-04-02_ubuntu18/bin:/usr/lib/jvm/java-8-openjdk-amd64/bin:/usr/lib/dart/bin:/usr/lib/jvm/java-8-openjdk-amd64/bin:/usr/lib/dart/bin
API=21

Thank you

circinusX1 commented 3 years ago

I Passed that error taking out from config the sanity check, but now on Android 9 I get

ao_default_driver_id() returning -1.

nwrkbiz commented 3 years ago

What driver plugins do you build? (most probably alsa?) You will need the driver plugin on your android device (which might not be trivial).

You can try to statically link the alsa plugin as described here: https://github.com/xiph/libao/issues/10

circinusX1 commented 3 years ago

Hi, Thank you. I figure that out. Now returns the index for oss driver whichever is 4 or 5 after default static are in the driver table, and goes fine in the oss functions table, but open on /dev/snd/pcm* 0,# fails with access denied errno. I also tried the tinyalsa and is same issue from NDK. Looks like some Java Audio manager has to be called before, but I am in NDK pure C++. I am looking into that.

nwrkbiz commented 3 years ago

Do you have a rooted phone? Did you try with su privileges? How did you link the plugins?

circinusX1 commented 3 years ago

Hi, No is not rooted. Rooted will work for sure. I am using now OpenES , though I did not want that, because I wanted to keep same code for linux/android and works fine for what I needed. Is not critical is just a fun project I mess with in my spare time. Thank you.

nwrkbiz commented 3 years ago

Hi, No is not rooted. Rooted will work for sure. I am using now OpenES , though I did not want that, because I wanted to keep same code for linux/android and works fine for what I needed. Is not critical is just a fun project I mess with in my spare time. Thank you.

I kind of got it to work on my android device using the example I attached to the other issue (#10). I built a completely statically linked binary using musl libc and alsa (wavplay.linux_aarch64_musl). The wav playback works only shortly after android itself performed a sound playback (i.e. beep after using the volume rocker). I guess some values need to be adjusted via amixer.

nwrkbiz commented 3 years ago

@circinusX1

I did some further digging. Seems like I miss the right alsa UCM configuration files for the sound hardware of my smartphone (may be the same issue for you). If I use an external USB soundcard via OTG everything works out of the box.

circinusX1 commented 3 years ago

@circinusX1

I did some further digging. Seems like I miss the right alsa UCM configuration files for the sound hardware of my smartphone (may be the same issue for you). If I use an external USB soundcard via OTG everything works out of the box.

Sounds interesting. I will try with the 2.0-sound card-usb. I'll have to solder a OTG, though I cannot find one in the cable box. Thank you. Ill play more definitely.