server compiles under OpenWrt

This commit is contained in:
badaix 2016-04-02 19:12:38 +02:00
parent b75bb77fd4
commit 212c9c1c6b
9 changed files with 65 additions and 16 deletions

View file

@ -41,6 +41,33 @@ namespace cpt
return std::stoi(str); return std::stoi(str);
#endif #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
}
} }

View file

@ -9,10 +9,23 @@ else
TARGET_DIR ?= /usr TARGET_DIR ?= /usr
endif endif
CXX = /usr/bin/g++ CXXFLAGS += -std=c++0x -Wall -Wno-unused-function -O3 -pthread -DASIO_STANDALONE -DVERSION=\"$(VERSION)\" -I.. -I../externals/asio/asio/include -I../externals/popl/include
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
LDFLAGS = -lrt -lvorbis -lvorbisenc -logg -lFLAC -lavahi-client -lavahi-common 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 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 BIN = snapserver
@ -20,7 +33,7 @@ all: $(TARGET)
$(TARGET): $(OBJ) $(TARGET): $(OBJ)
$(CXX) $(CXXFLAGS) -o $(BIN) $(OBJ) $(LDFLAGS) $(CXX) $(CXXFLAGS) -o $(BIN) $(OBJ) $(LDFLAGS)
strip $(BIN) $(STRIP) $(BIN)
%.o: %.cpp %.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@ $(CXX) $(CXXFLAGS) -c $< -o $@

View file

@ -20,6 +20,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fstream> #include <fstream>
#include <cerrno>
#include "common/snapException.h" #include "common/snapException.h"
#include "common/compat.h" #include "common/compat.h"
#include "common/log.h" #include "common/log.h"

View file

@ -19,8 +19,9 @@
#include <iostream> #include <iostream>
#include "flacEncoder.h" #include "flacEncoder.h"
#include "common/log.h" #include "common/compat.h"
#include "common/snapException.h" #include "common/snapException.h"
#include "common/log.h"
using namespace std; using namespace std;
@ -138,7 +139,7 @@ void FlacEncoder::initEncoder()
int quality(2); int quality(2);
try try
{ {
quality = std::stoi(codecOptions_); quality = cpt::stoi(codecOptions_);
} }
catch(...) catch(...)
{ {

View file

@ -21,6 +21,7 @@
#include "oggEncoder.h" #include "oggEncoder.h"
#include "common/snapException.h" #include "common/snapException.h"
#include "common/compat.h"
#include "common/utils.h" #include "common/utils.h"
#include "common/log.h" #include "common/log.h"
@ -136,7 +137,7 @@ void OggEncoder::initEncoder()
double quality = 1.0; double quality = 1.0;
try try
{ {
quality = std::stod(qual); quality = cpt::stod(qual);
} }
catch(...) catch(...)
{ {

View file

@ -61,6 +61,8 @@ Class @ref nlohmann::basic_json is a good entry point for the documentation.
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "common/compat.h"
// enable ssize_t on MinGW // enable ssize_t on MinGW
#ifdef __GNUC__ #ifdef __GNUC__
#ifdef __MINGW32__ #ifdef __MINGW32__
@ -2739,7 +2741,7 @@ class basic_json
catch (std::out_of_range&) catch (std::out_of_range&)
{ {
// create better exception explanation // 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 else
@ -2783,7 +2785,7 @@ class basic_json
catch (std::out_of_range&) catch (std::out_of_range&)
{ {
// create better exception explanation // 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 else
@ -5789,7 +5791,7 @@ class basic_json
// use integer array index as key // use integer array index as key
case value_t::array: case value_t::array:
{ {
return std::to_string(array_index); return cpt::to_string(array_index);
} }
// use key from the object // use key from the object
@ -7781,7 +7783,7 @@ basic_json_parser_64:
This function (and its overloads) serves to select the most approprate This function (and its overloads) serves to select the most approprate
standard floating point number parsing function (i.e., `std::strtof`, 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<number_float_t>(nullptr). first parameter. Set this to @a static_cast<number_float_t>(nullptr).
@param[in] type the @ref number_float_t in use @param[in] type the @ref number_float_t in use
@ -7791,14 +7793,14 @@ basic_json_parser_64:
@return the floating point number @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 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 decimal point character. This may yield to parse errors if the locale
does not used `.`. does not used `.`.
*/ */
long double str_to_float_t(long double* /* type */, char** endptr) const long double str_to_float_t(long double* /* type */, char** endptr) const
{ {
return std::strtold(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr); return cpt::strtold(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
} }
/// @copydoc str_to_float_t /// @copydoc str_to_float_t
@ -7810,7 +7812,7 @@ basic_json_parser_64:
/// @copydoc str_to_float_t /// @copydoc str_to_float_t
float str_to_float_t(float*, char** endptr) const float str_to_float_t(float*, char** endptr) const
{ {
return std::strtof(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr); return cpt::strtof(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
} }
/*! /*!

View file

@ -17,6 +17,8 @@
USA. USA.
***/ ***/
#include <cstdio>
#include <cstdlib>
#include "publishAvahi.h" #include "publishAvahi.h"
#include "common/log.h" #include "common/log.h"

View file

@ -20,6 +20,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <cerrno>
#include "pipeStream.h" #include "pipeStream.h"
#include "../encoder/encoderFactory.h" #include "../encoder/encoderFactory.h"

View file

@ -16,10 +16,11 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
***/ ***/
#include "common/utils.h"
#include "streamManager.h" #include "streamManager.h"
#include "pipeStream.h" #include "pipeStream.h"
#include "fileStream.h" #include "fileStream.h"
#include "common/utils.h"
#include "common/compat.h"
#include "common/log.h" #include "common/log.h"
#include "common/snapException.h" #include "common/snapException.h"
@ -43,7 +44,7 @@ PcmStream* StreamManager::addStream(const std::string& uri)
streamUri.query["codec"] = codec_; streamUri.query["codec"] = codec_;
if (streamUri.query.find("buffer_ms") == streamUri.query.end()) 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: " // logD << "\nURI: " << streamUri.uri << "\nscheme: " << streamUri.scheme << "\nhost: "
// << streamUri.host << "\npath: " << streamUri.path << "\nfragment: " << streamUri.fragment << "\n"; // << streamUri.host << "\npath: " << streamUri.path << "\nfragment: " << streamUri.fragment << "\n";