Allow building server and client without FLAC support

Allows building the server and the client without FLAC support:

```
readelf -d ./bin/snapserver | grep NEEDED
 0x00000001 (NEEDED)                     Shared library: [libjsonrpcpp.so]
 0x00000001 (NEEDED)                     Shared library: [libavahi-common.so.3]
 0x00000001 (NEEDED)                     Shared library: [libavahi-client.so.3]
 0x00000001 (NEEDED)                     Shared library: [libstdc++.so.6]
 0x00000001 (NEEDED)                     Shared library: [libgcc_s.so.1]
 0x00000001 (NEEDED)                     Shared library: [libc.so]
```

Note, that the current client and server Makefiles always enable FLAC
support.
This commit is contained in:
Jörg Krause 2017-03-15 13:11:23 +01:00 committed by badaix
parent a5ffa356fe
commit 9abeac8365
3 changed files with 13 additions and 5 deletions

View file

@ -51,20 +51,20 @@ ifeq ($(TARGET), ANDROID)
CXX = $(NDK_DIR)/bin/arm-linux-androideabi-g++ CXX = $(NDK_DIR)/bin/arm-linux-androideabi-g++
STRIP = $(NDK_DIR)/bin/arm-linux-androideabi-strip STRIP = $(NDK_DIR)/bin/arm-linux-androideabi-strip
CXXFLAGS += -pthread -DANDROID -DNO_CPP11_STRING -fPIC -DHAS_OGG -DHAS_TREMOR -DHAS_OPENSL -I$(NDK_DIR)/include CXXFLAGS += -pthread -DANDROID -DNO_CPP11_STRING -fPIC -DHAS_OGG -DHAS_TREMOR -DHAS_FLAC -DHAS_OPENSL -I$(NDK_DIR)/include
LDFLAGS = -L$(NDK_DIR)/lib -pie -lvorbisidec -logg -lFLAC -lOpenSLES LDFLAGS = -L$(NDK_DIR)/lib -pie -lvorbisidec -logg -lFLAC -lOpenSLES
OBJ += player/openslPlayer.o OBJ += player/openslPlayer.o
else ifeq ($(TARGET), OPENWRT) else ifeq ($(TARGET), OPENWRT)
STRIP = echo STRIP = echo
CXXFLAGS += -pthread -DNO_CPP11_STRING -DHAS_OGG -DHAS_TREMOR -DHAS_ALSA -DHAS_AVAHI -DHAS_DAEMON CXXFLAGS += -pthread -DNO_CPP11_STRING -DHAS_OGG -DHAS_TREMOR -DHAS_FLAC -DHAS_ALSA -DHAS_AVAHI -DHAS_DAEMON
LDFLAGS = -lasound -lvorbisidec -logg -lFLAC -lavahi-client -lavahi-common -latomic LDFLAGS = -lasound -lvorbisidec -logg -lFLAC -lavahi-client -lavahi-common -latomic
OBJ += player/alsaPlayer.o browseZeroConf/browseAvahi.o OBJ += player/alsaPlayer.o browseZeroConf/browseAvahi.o
else ifeq ($(TARGET), BUILDROOT) else ifeq ($(TARGET), BUILDROOT)
CXXFLAGS += -pthread -DNO_CPP11_STRING -DHAS_OGG -DHAS_TREMOR -DHAS_ALSA -DHAS_AVAHI -DHAS_DAEMON CXXFLAGS += -pthread -DNO_CPP11_STRING -DHAS_OGG -DHAS_TREMOR -DHAS_FLAC -DHAS_ALSA -DHAS_AVAHI -DHAS_DAEMON
LDFLAGS += -lasound -lvorbisidec -logg -lFLAC -lavahi-client -lavahi-common -latomic LDFLAGS += -lasound -lvorbisidec -logg -lFLAC -lavahi-client -lavahi-common -latomic
OBJ += player/alsaPlayer.o browseZeroConf/browseAvahi.o OBJ += player/alsaPlayer.o browseZeroConf/browseAvahi.o
@ -73,6 +73,7 @@ else ifeq ($(TARGET), MACOS)
CXX = g++ CXX = g++
STRIP = strip STRIP = strip
CXXFLAGS += -DHAS_OGG -DHAS_VORBIS -DHAS_COREAUDIO -DFREEBSD -DMACOS -DHAS_BONJOUR -DHAS_DAEMON -I/usr/local/include -Wno-unused-local-typedef -Wno-deprecated CXXFLAGS += -DHAS_OGG -DHAS_VORBIS -DHAS_COREAUDIO -DFREEBSD -DMACOS -DHAS_BONJOUR -DHAS_DAEMON -I/usr/local/include -Wno-unused-local-typedef -Wno-deprecated
CXXFLAGS += -DHAS_OGG -DHAS_VORBIS -DHAS_FLAC -DHAS_COREAUDIO -DFREEBSD -DMACOS -DHAS_BONJOUR -DHAS_DAEMON -I/usr/local/include -Wno-unused-local-typedef -Wno-deprecated
LDFLAGS = -logg -lvorbis -lFLAC -L/usr/local/lib -framework AudioToolbox -framework CoreFoundation LDFLAGS = -logg -lvorbis -lFLAC -L/usr/local/lib -framework AudioToolbox -framework CoreFoundation
OBJ += player/coreAudioPlayer.o browseZeroConf/browseBonjour.o OBJ += player/coreAudioPlayer.o browseZeroConf/browseBonjour.o
@ -80,7 +81,7 @@ else
CXX = g++ CXX = g++
STRIP = strip STRIP = strip
CXXFLAGS += -pthread -DHAS_OGG -DHAS_VORBIS -DHAS_ALSA -DHAS_AVAHI -DHAS_DAEMON CXXFLAGS += -pthread -DHAS_OGG -DHAS_VORBIS -DHAS_FLAC -DHAS_ALSA -DHAS_AVAHI -DHAS_DAEMON
LDFLAGS = -lrt -lasound -logg -lvorbis -lFLAC -lavahi-client -lavahi-common -static-libgcc -static-libstdc++ LDFLAGS = -lrt -lasound -logg -lvorbis -lFLAC -lavahi-client -lavahi-common -static-libgcc -static-libstdc++
OBJ += player/alsaPlayer.o browseZeroConf/browseAvahi.o OBJ += player/alsaPlayer.o browseZeroConf/browseAvahi.o

View file

@ -20,11 +20,13 @@
#include <string> #include <string>
#include <memory> #include <memory>
#include "controller.h" #include "controller.h"
#include "decoder/pcmDecoder.h"
#if defined(HAS_OGG) && (defined(HAS_TREMOR) || defined(HAS_VORBIS)) #if defined(HAS_OGG) && (defined(HAS_TREMOR) || defined(HAS_VORBIS))
#include "decoder/oggDecoder.h" #include "decoder/oggDecoder.h"
#endif #endif
#include "decoder/pcmDecoder.h" #if defined(HAS_FLAC)
#include "decoder/flacDecoder.h" #include "decoder/flacDecoder.h"
#endif
#include "timeProvider.h" #include "timeProvider.h"
#include "message/time.h" #include "message/time.h"
#include "message/hello.h" #include "message/hello.h"
@ -110,8 +112,10 @@ void Controller::onMessageReceived(ClientConnection* connection, const msg::Base
else if (headerChunk_->codec == "ogg") else if (headerChunk_->codec == "ogg")
decoder_.reset(new OggDecoder()); decoder_.reset(new OggDecoder());
#endif #endif
#if defined(HAS_FLAC)
else if (headerChunk_->codec == "flac") else if (headerChunk_->codec == "flac")
decoder_.reset(new FlacDecoder()); decoder_.reset(new FlacDecoder());
#endif
else else
throw SnapException("codec not supported: \"" + headerChunk_->codec + "\""); throw SnapException("codec not supported: \"" + headerChunk_->codec + "\"");

View file

@ -21,6 +21,7 @@
#if defined(HAS_OGG) && defined(HAS_VORBIS) && defined(HAS_VORBIS_ENC) #if defined(HAS_OGG) && defined(HAS_VORBIS) && defined(HAS_VORBIS_ENC)
#include "oggEncoder.h" #include "oggEncoder.h"
#endif #endif
#if defined(HAS_FLAC)
#include "flacEncoder.h" #include "flacEncoder.h"
#include "common/utils/string_utils.h" #include "common/utils/string_utils.h"
#include "common/snapException.h" #include "common/snapException.h"
@ -46,8 +47,10 @@ Encoder* EncoderFactory::createEncoder(const std::string& codecSettings) const
else if (codec == "ogg") else if (codec == "ogg")
encoder = new OggEncoder(codecOptions); encoder = new OggEncoder(codecOptions);
#endif #endif
#if defined(HAS_FLAC)
else if (codec == "flac") else if (codec == "flac")
encoder = new FlacEncoder(codecOptions); encoder = new FlacEncoder(codecOptions);
#endif
else else
{ {
throw SnapException("unknown codec: " + codec); throw SnapException("unknown codec: " + codec);