From 212c9c1c6bd5fddad3c87c84c8e74d3bf7aa5072 Mon Sep 17 00:00:00 2001 From: badaix Date: Sat, 2 Apr 2016 19:12:38 +0200 Subject: [PATCH] server compiles under OpenWrt --- common/compat.h | 27 +++++++++++++++++++++++++++ server/Makefile | 19 ++++++++++++++++--- server/config.cpp | 1 + server/encoder/flacEncoder.cpp | 5 +++-- server/encoder/oggEncoder.cpp | 5 +++-- server/json/json.hpp | 16 +++++++++------- server/publishAvahi.cpp | 2 ++ server/streamreader/pipeStream.cpp | 1 + server/streamreader/streamManager.cpp | 5 +++-- 9 files changed, 65 insertions(+), 16 deletions(-) diff --git a/common/compat.h b/common/compat.h index e23e2a0b..6962cbaa 100644 --- a/common/compat.h +++ b/common/compat.h @@ -41,6 +41,33 @@ namespace cpt return std::stoi(str); #endif } + + static double stod(const std::string& str) + { + #ifdef NO_CPP11_STRING + return strtod(str.c_str(), NULL); + #else + return std::stod(str.c_str()); + #endif + } + + static long double strtold(const char* str, char** endptr) + { + #ifdef NO_CPP11_STRING + return strtod(str, endptr); + #else + return std::strtold(str, endptr); + #endif + } + + static float strtof(const char* str, char** endptr) + { + #ifdef NO_CPP11_STRING + return (float)strtod(str, endptr); + #else + return std::strtof(str, endptr); + #endif + } } diff --git a/server/Makefile b/server/Makefile index 48251d4c..0900bb87 100644 --- a/server/Makefile +++ b/server/Makefile @@ -9,10 +9,23 @@ else TARGET_DIR ?= /usr endif -CXX = /usr/bin/g++ -CXXFLAGS = -std=c++0x -static-libgcc -static-libstdc++ -Wall -Wno-unused-function -O3 -pthread -DASIO_STANDALONE -DVERSION=\"$(VERSION)\" -I.. -I../externals/asio/asio/include -I../externals/popl/include +CXXFLAGS += -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 -lvorbis -lvorbisenc -logg -lFLAC -lavahi-client -lavahi-common +ifeq ($(TARGET), OPENWRT) + +STRIP = echo +CXXFLAGS += -DIS_BIG_ENDIAN -DNO_CPP11_STRING + +else + +CXX = /usr/bin/g++ +STRIP = strip +CXXFLAGS += -static-libgcc -static-libstdc++ + +endif + + OBJ = snapServer.o config.o controlServer.o controlSession.o streamServer.o streamSession.o json/jsonrpc.o streamreader/streamUri.o streamreader/streamManager.o streamreader/pcmStream.o streamreader/pipeStream.o streamreader/fileStream.o encoder/encoderFactory.o encoder/flacEncoder.o encoder/pcmEncoder.o encoder/oggEncoder.o publishAvahi.o ../common/log.o ../message/pcmChunk.o ../message/sampleFormat.o BIN = snapserver @@ -20,7 +33,7 @@ all: $(TARGET) $(TARGET): $(OBJ) $(CXX) $(CXXFLAGS) -o $(BIN) $(OBJ) $(LDFLAGS) - strip $(BIN) + $(STRIP) $(BIN) %.o: %.cpp $(CXX) $(CXXFLAGS) -c $< -o $@ diff --git a/server/config.cpp b/server/config.cpp index 41443def..cae6d9ce 100644 --- a/server/config.cpp +++ b/server/config.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "common/snapException.h" #include "common/compat.h" #include "common/log.h" diff --git a/server/encoder/flacEncoder.cpp b/server/encoder/flacEncoder.cpp index 9ef3d98b..9e6d5310 100644 --- a/server/encoder/flacEncoder.cpp +++ b/server/encoder/flacEncoder.cpp @@ -19,8 +19,9 @@ #include #include "flacEncoder.h" -#include "common/log.h" +#include "common/compat.h" #include "common/snapException.h" +#include "common/log.h" using namespace std; @@ -138,7 +139,7 @@ void FlacEncoder::initEncoder() int quality(2); try { - quality = std::stoi(codecOptions_); + quality = cpt::stoi(codecOptions_); } catch(...) { diff --git a/server/encoder/oggEncoder.cpp b/server/encoder/oggEncoder.cpp index 7eca822f..38ad5b75 100644 --- a/server/encoder/oggEncoder.cpp +++ b/server/encoder/oggEncoder.cpp @@ -21,6 +21,7 @@ #include "oggEncoder.h" #include "common/snapException.h" +#include "common/compat.h" #include "common/utils.h" #include "common/log.h" @@ -136,7 +137,7 @@ void OggEncoder::initEncoder() double quality = 1.0; try { - quality = std::stod(qual); + quality = cpt::stod(qual); } catch(...) { @@ -201,7 +202,7 @@ void OggEncoder::initEncoder() /* pick a random serial number; that way we can more likely build chained streams just by concatenation */ srand(time(NULL)); - ogg_stream_init(&os,rand()); + ogg_stream_init(&os, rand()); /* Vorbis streams begin with three headers; the initial header (with most of the codec setup parameters) which is mandated by the Ogg diff --git a/server/json/json.hpp b/server/json/json.hpp index db733367..62628541 100644 --- a/server/json/json.hpp +++ b/server/json/json.hpp @@ -61,6 +61,8 @@ Class @ref nlohmann::basic_json is a good entry point for the documentation. #include #include +#include "common/compat.h" + // enable ssize_t on MinGW #ifdef __GNUC__ #ifdef __MINGW32__ @@ -2739,7 +2741,7 @@ class basic_json catch (std::out_of_range&) { // create better exception explanation - throw std::out_of_range("array index " + std::to_string(idx) + " is out of range"); + throw std::out_of_range("array index " + cpt::to_string(idx) + " is out of range"); } } else @@ -2783,7 +2785,7 @@ class basic_json catch (std::out_of_range&) { // create better exception explanation - throw std::out_of_range("array index " + std::to_string(idx) + " is out of range"); + throw std::out_of_range("array index " + cpt::to_string(idx) + " is out of range"); } } else @@ -5789,7 +5791,7 @@ class basic_json // use integer array index as key case value_t::array: { - return std::to_string(array_index); + return cpt::to_string(array_index); } // use key from the object @@ -7781,7 +7783,7 @@ basic_json_parser_64: This function (and its overloads) serves to select the most approprate standard floating point number parsing function (i.e., `std::strtof`, - `std::strtod`, or `std::strtold`) based on the type supplied via the + `std::strtod`, or `cpt::strtold`) based on the type supplied via the first parameter. Set this to @a static_cast(nullptr). @param[in] type the @ref number_float_t in use @@ -7791,14 +7793,14 @@ basic_json_parser_64: @return the floating point number - @bug This function uses `std::strtof`, `std::strtod`, or `std::strtold` + @bug This function uses `std::strtof`, `std::strtod`, or `cpt::strtold` which use the current C locale to determine which character is used as decimal point character. This may yield to parse errors if the locale does not used `.`. */ long double str_to_float_t(long double* /* type */, char** endptr) const { - return std::strtold(reinterpret_cast(m_start), endptr); + return cpt::strtold(reinterpret_cast(m_start), endptr); } /// @copydoc str_to_float_t @@ -7810,7 +7812,7 @@ basic_json_parser_64: /// @copydoc str_to_float_t float str_to_float_t(float*, char** endptr) const { - return std::strtof(reinterpret_cast(m_start), endptr); + return cpt::strtof(reinterpret_cast(m_start), endptr); } /*! diff --git a/server/publishAvahi.cpp b/server/publishAvahi.cpp index ef09202d..26f9ac75 100644 --- a/server/publishAvahi.cpp +++ b/server/publishAvahi.cpp @@ -17,6 +17,8 @@ USA. ***/ +#include +#include #include "publishAvahi.h" #include "common/log.h" diff --git a/server/streamreader/pipeStream.cpp b/server/streamreader/pipeStream.cpp index 249ed1c3..13c3fd77 100644 --- a/server/streamreader/pipeStream.cpp +++ b/server/streamreader/pipeStream.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "pipeStream.h" #include "../encoder/encoderFactory.h" diff --git a/server/streamreader/streamManager.cpp b/server/streamreader/streamManager.cpp index 7f38ae64..82a05cb0 100644 --- a/server/streamreader/streamManager.cpp +++ b/server/streamreader/streamManager.cpp @@ -16,10 +16,11 @@ along with this program. If not, see . ***/ -#include "common/utils.h" #include "streamManager.h" #include "pipeStream.h" #include "fileStream.h" +#include "common/utils.h" +#include "common/compat.h" #include "common/log.h" #include "common/snapException.h" @@ -43,7 +44,7 @@ PcmStream* StreamManager::addStream(const std::string& uri) streamUri.query["codec"] = codec_; if (streamUri.query.find("buffer_ms") == streamUri.query.end()) - streamUri.query["buffer_ms"] = to_string(readBufferMs_); + streamUri.query["buffer_ms"] = cpt::to_string(readBufferMs_); // logD << "\nURI: " << streamUri.uri << "\nscheme: " << streamUri.scheme << "\nhost: " // << streamUri.host << "\npath: " << streamUri.path << "\nfragment: " << streamUri.fragment << "\n";