server runs on OpenWrt

This commit is contained in:
badaix 2016-04-02 23:20:45 +02:00
parent 212c9c1c6b
commit 41db245efc
4 changed files with 42 additions and 34 deletions

View file

@ -40,6 +40,7 @@ endef
define Package/snapserver
$(call Package/snapcast/Default)
TITLE += snapserver
DEPENDS += +libvorbis #+libvorbisenc
HIDDEN := 1
endef
@ -67,13 +68,13 @@ define Package/snapcast/config
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))

View file

@ -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

View file

@ -17,9 +17,16 @@
***/
#include <memory>
#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<const char *>(&int32), sizeof(uint32_t));
memcpy(headerChunk_->payload + 8, "WAVEfmt ", 8);
int32 = 16;
memcpy(headerChunk_->payload + 16, reinterpret_cast<const char *>(&int32), sizeof(uint32_t));
uint16_t int16 = 1;
memcpy(headerChunk_->payload + 20, reinterpret_cast<const char *>(&int16), sizeof(uint16_t));
int16 = sampleFormat_.channels;
memcpy(headerChunk_->payload + 22, reinterpret_cast<const char *>(&int16), sizeof(uint16_t));
int32 = sampleFormat_.rate;
memcpy(headerChunk_->payload + 24, reinterpret_cast<const char *>(&int32), sizeof(uint32_t));
int32 = sampleFormat_.rate * sampleFormat_.bits * sampleFormat_.channels / 8;
memcpy(headerChunk_->payload + 28, reinterpret_cast<const char *>(&int32), sizeof(uint32_t));
int16 = sampleFormat_.channels * ((sampleFormat_.bits + 7) / 8);
memcpy(headerChunk_->payload + 32, reinterpret_cast<const char *>(&int16), sizeof(uint16_t));
int16 = sampleFormat_.bits;
memcpy(headerChunk_->payload + 34, reinterpret_cast<const char *>(&int16), sizeof(uint16_t));
memcpy(headerChunk_->payload + 36, "data", 4);
int32 = 0;
memcpy(headerChunk_->payload + 40, reinterpret_cast<const char *>(&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));
}

View file

@ -30,6 +30,13 @@ public:
protected:
virtual void initEncoder();
template<typename T>
void assign(void* pointer, T val)
{
T* p = (T*)pointer;
*p = val;
}
};