badaix / snapdroid

Snapcast client for Android
GNU General Public License v3.0
135 stars 26 forks source link

compile snapcast server #46

Open moritzkreemke opened 2 years ago

moritzkreemke commented 2 years ago

Hello,

thank you for this nice project. I would love, if it would be possible, to compile snapcast server for android.

Idea/Background: For University, I have to build an open source android project which uses Wifi-Direct/Bluetooth. My Idea:

Create an app, where you can connect multiple phones together (using Wifi Direct) and play music together.

How it works: Phone A receives audio via a TCP Stream and acting as a server. Phone A is at the same time a client and connect to itself. Phone B (connected via Wifi) should work fine with snapdroid as it is now.

Problem: When compiling snapdroid with BUILD_SERVER=ON. I get the Info: snapserver not yet supported for Android.

Question: Is snapserver not supported because this app current does not make use of them? Or does snapcast in general not supported/compile on android?

If snapcast can be compiled for android, build instructions would be great. In the snapcast build documentation, it's only linked to this project. Therefore, I hope it correct asking here.

Thank you for any help.

guerman5 commented 2 years ago

+1 I'm also interested. I dug the issues and found an old post from Sir Pohl (when snapcast was only v13) https://github.com/badaix/snapcast/issues/271#issuecomment-334124919

Then, I tried to cross compile v13 snapcast client/server for android on Arch, got the NDK, compiled the tools and the submodules (had to find myself). but i get stuck with the boost submodule, probably is not exactly as it was prepared for snapcast use. I downloaded boost_asio_1_10_8.zip from sourceforge and boost_1_63_0.zip from boost . org trying to get 2016 code, and tried to stitch all the hpp that compiler was asking. But get errors like: client ./clientConnection.h:34:7: error: use of undeclared identifier 'asio'; did you mean 'boost::asio'?

server controlSession.h:34:7: error: 'asio' has not been declared snapServer.cpp:65:51: error: expected primary-expression before '>' token /*auto portValue =*/ op.add<Value<size_t>>("p", "port", "Server port", settings.port, &settings.port);

among others errors and warnings, but i guess they originate from same mistake.

I'm doing something wrong, definitely obvious for the experienced eye, but I cant see it. Its because I'm learning how to compile with snapcast xD, never done this before.

I'm writing this to bring the topic into motion once more, and show that I'm trying as best as I can. Snapcast is v25 now, many things have changed, i assume the compilation method will be totally different.

Yes, that good is snapcast, and that bad I want to be able to run snapserver from android. I've taken the jump into compiling.

Thanks for reading.

badaix commented 2 years ago

The develop branch can compile the server for Android. To build the App, I recommend to use the latest Android Studio with the latest NDK and SDK and copy the required libraries to Snapcast/libs as described in readme.txt. To build the server, BUILD_SERVER must be set to ON in build.gradle. You can test the server in a root shell of your emulator:

johannes@Laptop:~/Develop/snapdroid$ ~/Develop/Android/Sdk/platform-tools/adb shell
generic_x86:/ $ su
generic_x86:/ # find /data -name "libsnapserver.so"
/data/app/~~eKwnv13JzR3hJVqyZWj3wQ==/de.badaix.snapcast-YFPjscovXwt_pmCMncsb6A==/lib/x86/libsnapserver.so
generic_x86:/ # /data/app/~~eKwnv13JzR3hJVqyZWj3wQ==/de.badaix.snapcast-YFPjscovXwt_pmCMncsb6A==/lib/x86/libsnapserver.so
2021-11-06 12-11-30.566 [Info] (Snapserver) Version 0.25.0
2021-11-06 12-11-30.579 [Error] (Snapserver) Exception: failed to create settings directory: "//.config/snapserver/": 30
terminating with uncaught exception of type SnapException: failed to create settings directory: "//.config/snapserver/": 30
/buildbot/src/android/ndk-release-r23/toolchain/llvm-project/libcxx/../../../toolchain/llvm-project/libcxxabi/src/abort_message.cpp:72: abort_message: assertion "terminating with uncaught exception of type SnapException: failed to create settings directory: "//.config/snapserver/": 30" failed
Aborted 
134|generic_x86:/ # 

As you can see, this server will fail to create a directory for it's settings and exit.

badaix commented 2 years ago

The settings directory is now configurable. You can start the server from the App in a similar way as the client is started and configure a data dir and a stream source like this: libsnapserver.so --server.datadir=getCacheDir().toString() --stream.source=tcp://127.0.0.1?name=android

guerman5 commented 2 years ago

Thanks a lot, I will work on it and update. Sweet!

guerman5 commented 2 years ago

The build was successful, apk installed ok. Configured settings and took off Im testing it now, very smooth

/data/app/de.badaix.snapcast-1/lib/arm64/./libsnapserver.so --server.datadir=/storage/emulated/0 --stream.source=pipe:///data/data/com.termux/files/usr/var/run/mpd.fifo?name=Radio&sampleformat=48000:16:2&codec=flac

What a great satisfaction it feels, its alive!

Muchas gracias Johannes

pvi-github commented 1 year ago

Hello there,

Do we still need to have the device rooted to run the Snapcast server on android ?

Kind regards,

pvi-github commented 1 year ago

And bonus question : wouldn't it be nice to have an APK published for Snapcast server ?