From 41db245efc85ce96442f5293fb0a6fb9f2c4ea54 Mon Sep 17 00:00:00 2001 From: badaix Date: Sat, 2 Apr 2016 23:20:45 +0200 Subject: [PATCH] server runs on OpenWrt --- Makefile.openwrt | 23 ++++++++++--------- server/Makefile | 3 ++- server/encoder/pcmEncoder.cpp | 43 +++++++++++++++++------------------ server/encoder/pcmEncoder.h | 7 ++++++ 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/Makefile.openwrt b/Makefile.openwrt index e27148c9..88f978a3 100755 --- a/Makefile.openwrt +++ b/Makefile.openwrt @@ -17,8 +17,8 @@ include $(INCLUDE_DIR)/package.mk define Package/snapcast/Default SECTION := sxx - CATEGORY := Sxx - TITLE := snapcast + CATEGORY := Sxx + TITLE := snapcast DEPENDS := +libstdcpp +libavahi-client +libatomic +libogg +libflac endef @@ -28,7 +28,7 @@ endef define Package/snapcast $(call Package/snapcast/Default) - TITLE += packages + TITLE += packages endef define Package/snapcast/description @@ -39,7 +39,8 @@ endef define Package/snapserver $(call Package/snapcast/Default) - TITLE += snapserver + TITLE += snapserver + DEPENDS += +libvorbis #+libvorbisenc HIDDEN := 1 endef @@ -61,19 +62,19 @@ define Package/snapclient/description endef define Package/snapcast/config - menu "Select snapcast Options" + menu "Select snapcast Options" depends on PACKAGE_snapcast comment "Choose server or client to compile" config PACKAGE_snapserver prompt "Compile snapserver" help - Compile multiroom server. + Compile multiroom server default n config PACKAGE_snapclient - prompt "Compile snapclient." + prompt "Compile snapclient" help - Compile multiroom client. + Compile multiroom client default n endmenu endef @@ -90,8 +91,8 @@ define Build/Prepare endef define Build/Compile -# $(if $(CONFIG_PACKAGE_snapserver), \ -# $(call Build/Compile/Default, -C server),) + $(if $(CONFIG_PACKAGE_snapserver), \ + $(call Build/Compile/Default, -C server TARGET=OPENWRT),) $(if $(CONFIG_PACKAGE_snapclient), \ $(call Build/Compile/Default, -C client TARGET=OPENWRT),) @@ -111,6 +112,6 @@ define Package/snapclient/install $(INSTALL_BIN) $(PKG_BUILD_DIR)/client/snapclient $(1)/usr/bin/ endef -#$(eval $(call BuildPackage,snapserver)) +$(eval $(call BuildPackage,snapserver)) $(eval $(call BuildPackage,snapclient)) $(eval $(call BuildPackage,snapcast)) diff --git a/server/Makefile b/server/Makefile index 0900bb87..eda44d52 100644 --- a/server/Makefile +++ b/server/Makefile @@ -10,18 +10,19 @@ else endif 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 +LDFLAGS = -lvorbis -lvorbisenc -logg -lFLAC -lavahi-client -lavahi-common -latomic else CXX = /usr/bin/g++ STRIP = strip CXXFLAGS += -static-libgcc -static-libstdc++ +LDFLAGS = -lrt -lvorbis -lvorbisenc -logg -lFLAC -lavahi-client -lavahi-common endif diff --git a/server/encoder/pcmEncoder.cpp b/server/encoder/pcmEncoder.cpp index 2831c08e..f91489d6 100644 --- a/server/encoder/pcmEncoder.cpp +++ b/server/encoder/pcmEncoder.cpp @@ -17,9 +17,16 @@ ***/ #include +#include "common/endian.h" #include "pcmEncoder.h" +#define ID_RIFF 0x46464952 +#define ID_WAVE 0x45564157 +#define ID_FMT 0x20746d66 +#define ID_DATA 0x61746164 + + PcmEncoder::PcmEncoder(const std::string& codecOptions) : Encoder(codecOptions) { headerChunk_.reset(new msg::Header("pcm")); @@ -35,30 +42,22 @@ void PcmEncoder::encode(const msg::PcmChunk* chunk) void PcmEncoder::initEncoder() { - //TODO: Endianess headerChunk_->payloadSize = 44; headerChunk_->payload = (char*)malloc(headerChunk_->payloadSize); - memcpy(headerChunk_->payload, "RIFF", 4); - uint32_t int32 = 36; - memcpy(headerChunk_->payload + 4, reinterpret_cast(&int32), sizeof(uint32_t)); - memcpy(headerChunk_->payload + 8, "WAVEfmt ", 8); - int32 = 16; - memcpy(headerChunk_->payload + 16, reinterpret_cast(&int32), sizeof(uint32_t)); - uint16_t int16 = 1; - memcpy(headerChunk_->payload + 20, reinterpret_cast(&int16), sizeof(uint16_t)); - int16 = sampleFormat_.channels; - memcpy(headerChunk_->payload + 22, reinterpret_cast(&int16), sizeof(uint16_t)); - int32 = sampleFormat_.rate; - memcpy(headerChunk_->payload + 24, reinterpret_cast(&int32), sizeof(uint32_t)); - int32 = sampleFormat_.rate * sampleFormat_.bits * sampleFormat_.channels / 8; - memcpy(headerChunk_->payload + 28, reinterpret_cast(&int32), sizeof(uint32_t)); - int16 = sampleFormat_.channels * ((sampleFormat_.bits + 7) / 8); - memcpy(headerChunk_->payload + 32, reinterpret_cast(&int16), sizeof(uint16_t)); - int16 = sampleFormat_.bits; - memcpy(headerChunk_->payload + 34, reinterpret_cast(&int16), sizeof(uint16_t)); - memcpy(headerChunk_->payload + 36, "data", 4); - int32 = 0; - memcpy(headerChunk_->payload + 40, reinterpret_cast(&int32), sizeof(uint32_t)); + char* payload = headerChunk_->payload; + assign(payload, SWAP_32(ID_RIFF)); + assign(payload + 4, SWAP_32(36)); + assign(payload + 8, SWAP_32(ID_WAVE)); + assign(payload + 12, SWAP_32(ID_FMT)); + assign(payload + 16, SWAP_32(16)); + assign(payload + 20, SWAP_16(1)); + assign(payload + 22, SWAP_16(sampleFormat_.channels)); + assign(payload + 24, SWAP_32(sampleFormat_.rate)); + assign(payload + 28, SWAP_32(sampleFormat_.rate * sampleFormat_.bits * sampleFormat_.channels / 8)); + assign(payload + 32, SWAP_16(sampleFormat_.channels * ((sampleFormat_.bits + 7) / 8))); + assign(payload + 34, SWAP_16(sampleFormat_.bits)); + assign(payload + 36, SWAP_32(ID_DATA)); + assign(payload + 40, SWAP_32(0)); } diff --git a/server/encoder/pcmEncoder.h b/server/encoder/pcmEncoder.h index 4b7b32f0..84629761 100644 --- a/server/encoder/pcmEncoder.h +++ b/server/encoder/pcmEncoder.h @@ -30,6 +30,13 @@ public: protected: virtual void initEncoder(); + + template + void assign(void* pointer, T val) + { + T* p = (T*)pointer; + *p = val; + } };