diff --git a/client/Makefile b/client/Makefile index 41c2fee2..f5406a51 100644 --- a/client/Makefile +++ b/client/Makefile @@ -9,14 +9,21 @@ else TARGET_DIR ?= /usr endif +ifdef ANDROID CXX = /home/johannes/Develop/android-ndk-r10e-arm-21/bin/arm-linux-androideabi-g++ -#CXX = /usr/bin/g++ -CFLAGS = -std=c++0x -Wall -Wno-unused-function -fPIC -O3 -pthread -DASIO_STANDALONE -DVERSION=\"$(VERSION)\" -I.. -I../externals/asio/asio/include -I../externals/popl/include -I/home/johannes/Develop/build/arm/include +CFLAGS = -std=c++0x -Wall -Wno-unused-function -fPIC -O3 -pthread -DASIO_STANDALONE -DANDROID -DVERSION=\"$(VERSION)\" -I.. -I../externals/asio/asio/include -I../externals/popl/include -I/home/johannes/Develop/build/arm/include LDFLAGS = -L/home/johannes/Develop/build/arm/lib -pie -lFLAC -lOpenSLES +OBJ = snapClient.o stream.o clientConnection.o timeProvider.o player/player.o player/openslPlayer.o decoder/pcmDecoder.o decoder/flacDecoder.o controller.o ../message/pcmChunk.o ../common/log.o ../message/sampleFormat.o +else +CXX = /usr/bin/g++ +CFLAGS = -std=c++0x -Wall -Wno-unused-function -O3 -pthread -DASIO_STANDALONE -DVERSION=\"$(VERSION)\" -I.. -I../externals/asio/asio/include -I../externals/popl/include +LDFLAGS = -lrt -lasound -logg -lvorbis -lvorbisenc -lFLAC -lavahi-client -lavahi-common +OBJ = snapClient.o stream.o clientConnection.o timeProvider.o player/player.o player/alsaPlayer.o decoder/oggDecoder.o decoder/pcmDecoder.o decoder/flacDecoder.o controller.o browseAvahi.o ../message/pcmChunk.o ../common/log.o ../message/sampleFormat.o +endif -OBJ = snapClient.o stream.o clientConnection.o timeProvider.o player/player.o player/openslPlayer.o decoder/pcmDecoder.o decoder/flacDecoder.o controller.o ../message/pcmChunk.o ../common/log.o ../message/sampleFormat.o BIN = snapclient + all: $(TARGET) $(TARGET): $(OBJ) diff --git a/client/controller.cpp b/client/controller.cpp index ab286c4a..e12db7a1 100644 --- a/client/controller.cpp +++ b/client/controller.cpp @@ -20,7 +20,9 @@ #include #include #include -//#include "decoder/oggDecoder.h" +#ifndef ANDROID +#include "decoder/oggDecoder.h" +#endif #include "decoder/pcmDecoder.h" #include "decoder/flacDecoder.h" #include "timeProvider.h" @@ -38,7 +40,6 @@ using namespace std; Controller::Controller() : MessageReceiver(), active_(false), sampleFormat_(NULL), decoder_(NULL), player_(nullptr), asyncException_(false) { -logE << "Controller\n"; } @@ -113,15 +114,10 @@ bool Controller::sendTimeSyncMessage(long after) void Controller::start(const PcmDevice& pcmDevice, const std::string& host, size_t port, size_t latency) { -logE << "start 1\n"; pcmDevice_ = pcmDevice; -logE << "start 2\n"; latency_ = latency; -logE << "start 3\n"; clientConnection_ = new ClientConnection(this, host, port); -logE << "start 4\n"; controllerThread_ = new thread(&Controller::worker, this); -logE << "start 5\n"; } @@ -162,8 +158,10 @@ void Controller::worker() logO << "Codec: " << headerChunk->codec << "\n"; if (headerChunk->codec == "pcm") decoder_ = new PcmDecoder(); -// if (headerChunk->codec == "ogg") -// decoder_ = new OggDecoder(); +#ifndef ANDROID + if (headerChunk->codec == "ogg") + decoder_ = new OggDecoder(); +#endif else if (headerChunk->codec == "flac") decoder_ = new FlacDecoder(); decoder_->setHeader(headerChunk.get()); @@ -184,7 +182,11 @@ void Controller::worker() stream_ = new Stream(*sampleFormat_); stream_->setBufferLen(serverSettings->bufferMs - latency_); +#ifndef ANDROID + player_.reset(new AlsaPlayer(pcmDevice_, stream_)); +#else player_.reset(new OpenslPlayer(pcmDevice_, stream_)); +#endif player_->setVolume(serverSettings->volume / 100.); player_->start(); diff --git a/client/controller.h b/client/controller.h index 6d482473..69bee807 100644 --- a/client/controller.h +++ b/client/controller.h @@ -24,7 +24,11 @@ #include "decoder/decoder.h" #include "message/message.h" #include "player/pcmDevice.h" +#ifdef ANDROID #include "player/openslPlayer.h" +#else +#include "player/alsaPlayer.h" +#endif #include "clientConnection.h" #include "stream.h" diff --git a/client/snapClient.cpp b/client/snapClient.cpp index 007e7324..fd7b1023 100644 --- a/client/snapClient.cpp +++ b/client/snapClient.cpp @@ -21,9 +21,11 @@ #include "popl.hpp" #include "controller.h" -//#include "player/alsaPlayer.h" -//#include "browseAvahi.h" -//#include "common/daemon.h" +#ifndef ANDROID +#include "player/alsaPlayer.h" +#include "browseAvahi.h" +#include "common/daemon.h" +#endif #include "common/log.h" #include "common/signalHandler.h" @@ -35,7 +37,8 @@ bool g_terminated = false; PcmDevice getPcmDevice(const std::string& soundcard) { -/* vector pcmDevices = AlsaPlayer::pcm_list(); +#ifndef ANDROID + vector pcmDevices = AlsaPlayer::pcm_list(); int soundcardIdx = -1; try @@ -52,7 +55,7 @@ PcmDevice getPcmDevice(const std::string& soundcard) for (auto dev: pcmDevices) if (dev.name.find(soundcard) != string::npos) return dev; -*/ +#endif PcmDevice pcmDevice; return pcmDevice; } @@ -111,13 +114,15 @@ int main (int argc, char **argv) if (listSwitch.isSet()) { -/* vector pcmDevices = AlsaPlayer::pcm_list(); +#ifndef ANDROID + vector pcmDevices = AlsaPlayer::pcm_list(); for (auto dev: pcmDevices) { cout << dev.idx << ": " << dev.name << "\n" << dev.description << "\n\n"; } -*/ exit(EXIT_SUCCESS); +#endif + exit(EXIT_SUCCESS); } if (helpSwitch.isSet()) @@ -140,7 +145,8 @@ int main (int argc, char **argv) if (daemonOption.isSet()) { -/* daemonize("/var/run/snapclient.pid"); +#ifndef ANDROID + daemonize("/var/run/snapclient.pid"); if (processPriority < -20) processPriority = -20; else if (processPriority > 19) @@ -148,7 +154,8 @@ int main (int argc, char **argv) if (processPriority != 0) setpriority(PRIO_PROCESS, 0, processPriority); logS(kLogNotice) << "daemon started" << std::endl; -*/ } +#endif + } PcmDevice pcmDevice = getPcmDevice(soundcard); if (pcmDevice.idx == -1) @@ -159,7 +166,8 @@ int main (int argc, char **argv) if (host.empty()) { -/* BrowseAvahi browseAvahi; +#ifndef ANDROID + BrowseAvahi browseAvahi; AvahiResult avahiResult; while (!g_terminated) { @@ -179,9 +187,8 @@ int main (int argc, char **argv) } usleep(500*1000); } -*/ } - - logO << "host: " << host << "\n"; +#endif + } std::unique_ptr controller(new Controller()); if (!g_terminated) @@ -199,7 +206,9 @@ int main (int argc, char **argv) } logS(kLogNotice) << "daemon terminated." << endl; -// daemonShutdown(); +#ifndef ANDROID + daemonShutdown(); +#endif exit(EXIT_SUCCESS); }