mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-28 08:26:16 +02:00
compiles under OpenWrt
This commit is contained in:
parent
365cb85d0f
commit
9ec9256ac4
16 changed files with 268 additions and 115 deletions
|
@ -9,15 +9,11 @@ else
|
||||||
TARGET_DIR ?= /usr
|
TARGET_DIR ?= /usr
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# MIPS
|
|
||||||
# export STAGING_DIR=/home/johannes/Develop/openwrt/staging_dir
|
|
||||||
# TOOLCHAIN_DIR=$(STAGING_DIR)/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2
|
|
||||||
# LDCFLAGS=$(TOOLCHAIN_DIR)/usr/lib
|
|
||||||
# LD_LIBRARY_PATH=$(TOOLCHAIN_DIR)/usr/lib
|
|
||||||
# PATH=$(TOOLCHAIN_DIR)/bin:$PATH
|
|
||||||
# CXX = $(TOOLCHAIN_DIR)/bin/mips-openwrt-linux-g++
|
|
||||||
|
|
||||||
ifdef ANDROID
|
CXXFLAGS += $(ADD_CFLAGS) -std=c++0x -Wall -Wno-unused-function -O3 -pthread -DASIO_STANDALONE -DVERSION=\"$(VERSION)\" -I.. -I../externals/asio/asio/include -I../externals/popl/include
|
||||||
|
OBJ = snapClient.o stream.o clientConnection.o timeProvider.o player/player.o decoder/pcmDecoder.o decoder/flacDecoder.o controller.o ../message/pcmChunk.o ../common/log.o ../message/sampleFormat.o
|
||||||
|
|
||||||
|
ifeq ($(TARGET), ANDROID)
|
||||||
# Android NDK setup: (http://developer.android.com/ndk/guides/standalone_toolchain.html)
|
# Android NDK setup: (http://developer.android.com/ndk/guides/standalone_toolchain.html)
|
||||||
# 1. Download NDK: http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86_64.bin
|
# 1. Download NDK: http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86_64.bin
|
||||||
# 2. Extract to: /home/johannes/Develop/android-ndk-r10e
|
# 2. Extract to: /home/johannes/Develop/android-ndk-r10e
|
||||||
|
@ -26,31 +22,40 @@ ifdef ANDROID
|
||||||
# ii. ./make-standalone-toolchain.sh --arch=arm --platform=android-14 --install-dir=/home/johannes/Develop/android-toolchain-arm-14 --ndk-dir=/home/johannes/Develop/android-ndk-r10e --system=linux-x86_64
|
# ii. ./make-standalone-toolchain.sh --arch=arm --platform=android-14 --install-dir=/home/johannes/Develop/android-toolchain-arm-14 --ndk-dir=/home/johannes/Develop/android-ndk-r10e --system=linux-x86_64
|
||||||
# build with:
|
# build with:
|
||||||
# make ANDROID=1
|
# make ANDROID=1
|
||||||
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
|
||||||
CFLAGS = $(ADD_CFLAGS) -std=c++0x -Wall -Wno-unused-function -fPIC -O3 -pthread -DASIO_STANDALONE -DANDROID -DHAS_OPENSL -DVERSION=\"$(VERSION)\" -I.. -I../externals/asio/asio/include -I../externals/popl/include -I/home/johannes/Develop/build/arm/include
|
CXXFLAGS += -DANDROID -fPIC -DHAS_OPENSL -I/home/johannes/Develop/build/arm/include
|
||||||
#-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16
|
LDFLAGS = -L/home/johannes/Develop/build/arm/lib -pie -lFLAC -lOpenSLES
|
||||||
LDFLAGS = -L/home/johannes/Develop/build/arm/lib -pie -lFLAC -lOpenSLES
|
OBJ += player/openslPlayer.o
|
||||||
OBJ = snapClient.o stream.o clientConnection.o timeProvider.o player/player.o player/openslPlayer.o decoder/pcmDecoder.o decoder/flacDecoder.o controller.o ../message/pcmChunk.o ../common/log.o ../message/sampleFormat.o
|
|
||||||
|
else ifeq ($(TARGET), OPENWRT)
|
||||||
|
|
||||||
|
CXXFLAGS += -DIS_BIG_ENDIAN -DNO_TO_STRING -DNO_STOUL -DNO_STOI -DHAS_OGG -DHAS_ALSA -DHAS_AVAHI -DHAS_DAEMON
|
||||||
|
LDFLAGS = -lasound -logg -lvorbis -lFLAC -lavahi-client -lavahi-common -latomic
|
||||||
|
OBJ += player/alsaPlayer.o decoder/oggDecoder.o browseAvahi.o
|
||||||
|
|
||||||
else
|
else
|
||||||
CXX = /usr/bin/g++
|
|
||||||
STRIP = strip
|
CXX = /usr/bin/g++
|
||||||
CFLAGS = -std=c++0x -static-libgcc -static-libstdc++ -Wall -Wno-unused-function -O3 -pthread -DASIO_STANDALONE -DHAS_OGG -DHAS_ALSA -DHAS_AVAHI -DHAS_DAEMON -DVERSION=\"$(VERSION)\" -I.. -I../externals/asio/asio/include -I../externals/popl/include
|
STRIP = strip
|
||||||
LDFLAGS = -lrt -lasound -logg -lvorbis -lFLAC -lavahi-client -lavahi-common
|
CXXFLAGS += -static-libgcc -static-libstdc++ -DHAS_OGG -DHAS_ALSA -DHAS_AVAHI -DHAS_DAEMON
|
||||||
OBJ = snapClient.o stream.o clientConnection.o timeProvider.o player/player.o player/alsaPlayer.o decoder/oggDecoder.o decoder/pcmDecoder.o decoder/flacDecoder.o controller.o browseAvahi.o ../message/pcmChunk.o ../common/log.o ../message/sampleFormat.o
|
LDFLAGS = -lrt -lasound -logg -lvorbis -lFLAC -lavahi-client -lavahi-common
|
||||||
|
OBJ += player/alsaPlayer.o decoder/oggDecoder.o browseAvahi.o
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
BIN = snapclient
|
BIN = snapclient
|
||||||
|
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
$(TARGET): $(OBJ)
|
$(TARGET): $(OBJ)
|
||||||
$(CXX) $(CFLAGS) -o $(BIN) $(OBJ) $(LDFLAGS)
|
$(CXX) $(CXXFLAGS) -o $(BIN) $(OBJ) $(LDFLAGS)
|
||||||
$(STRIP) $(BIN)
|
# $(STRIP) $(BIN)
|
||||||
|
|
||||||
%.o: %.cpp
|
%.o: %.cpp
|
||||||
$(CXX) $(CFLAGS) -c $< -o $@
|
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(BIN) $(OBJ) *~
|
rm -rf $(BIN) $(OBJ) *~
|
||||||
|
|
|
@ -202,9 +202,9 @@ SampleFormat OggDecoder::setHeader(msg::Header* chunk)
|
||||||
|
|
||||||
/* Throw the comments plus a few lines about the bitstream we're decoding */
|
/* Throw the comments plus a few lines about the bitstream we're decoding */
|
||||||
char **ptr=vc.user_comments;
|
char **ptr=vc.user_comments;
|
||||||
while(*ptr)
|
while (*ptr)
|
||||||
{
|
{
|
||||||
fprintf(stderr,"%s\n",*ptr);
|
logO << "comment: " << *ptr << "\n";;
|
||||||
++ptr;
|
++ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
***/
|
***/
|
||||||
|
|
||||||
#include "common/snapException.h"
|
#include "common/snapException.h"
|
||||||
|
#include "common/endian.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "pcmDecoder.h"
|
#include "pcmDecoder.h"
|
||||||
|
|
||||||
|
@ -59,7 +60,19 @@ PcmDecoder::PcmDecoder() : Decoder()
|
||||||
|
|
||||||
bool PcmDecoder::decode(msg::PcmChunk* chunk)
|
bool PcmDecoder::decode(msg::PcmChunk* chunk)
|
||||||
{
|
{
|
||||||
return true;
|
/* int16_t* bufferT = (int16_t*)chunk->payload;
|
||||||
|
for (size_t n=0; n<chunk->getSampleCount(); ++n)
|
||||||
|
{
|
||||||
|
bufferT[n] = SWAP_16(bufferT[n]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sampleFormat.bits == 8)
|
||||||
|
adjustVolume<int8_t>(buffer, frames*sampleFormat.channels, volume);
|
||||||
|
else if (sampleFormat.bits == 16)
|
||||||
|
adjustVolume<int16_t>(buffer, frames*sampleFormat.channels, volume);
|
||||||
|
else if (sampleFormat.bits == 32)
|
||||||
|
adjustVolume<int32_t>(buffer, frames*sampleFormat.channels, volume);
|
||||||
|
*/ return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,12 +84,14 @@ SampleFormat PcmDecoder::setHeader(msg::Header* chunk)
|
||||||
struct riff_wave_header riff_wave_header;
|
struct riff_wave_header riff_wave_header;
|
||||||
struct chunk_header chunk_header;
|
struct chunk_header chunk_header;
|
||||||
struct chunk_fmt chunk_fmt;
|
struct chunk_fmt chunk_fmt;
|
||||||
chunk_fmt.sample_rate = 0;
|
chunk_fmt.sample_rate = SWAP_32(0);
|
||||||
|
chunk_fmt.bits_per_sample = SWAP_16(0);
|
||||||
|
chunk_fmt.num_channels = SWAP_16(0);
|
||||||
|
|
||||||
size_t pos(0);
|
size_t pos(0);
|
||||||
memcpy(&riff_wave_header, chunk->payload + pos, sizeof(riff_wave_header));
|
memcpy(&riff_wave_header, chunk->payload + pos, sizeof(riff_wave_header));
|
||||||
pos += sizeof(riff_wave_header);
|
pos += sizeof(riff_wave_header);
|
||||||
if ((riff_wave_header.riff_id != ID_RIFF) || (riff_wave_header.wave_id != ID_WAVE))
|
if ((SWAP_32(riff_wave_header.riff_id) != ID_RIFF) || (SWAP_32(riff_wave_header.wave_id) != ID_WAVE))
|
||||||
throw SnapException("Not a riff/wave header");
|
throw SnapException("Not a riff/wave header");
|
||||||
|
|
||||||
bool moreChunks(true);
|
bool moreChunks(true);
|
||||||
|
@ -86,7 +101,7 @@ SampleFormat PcmDecoder::setHeader(msg::Header* chunk)
|
||||||
throw SnapException("riff/wave header incomplete");
|
throw SnapException("riff/wave header incomplete");
|
||||||
memcpy(&chunk_header, chunk->payload + pos, sizeof(chunk_header));
|
memcpy(&chunk_header, chunk->payload + pos, sizeof(chunk_header));
|
||||||
pos += sizeof(chunk_header);
|
pos += sizeof(chunk_header);
|
||||||
switch (chunk_header.id)
|
switch (SWAP_32(chunk_header.id))
|
||||||
{
|
{
|
||||||
case ID_FMT:
|
case ID_FMT:
|
||||||
if (pos + sizeof(chunk_fmt) > chunk->payloadSize)
|
if (pos + sizeof(chunk_fmt) > chunk->payloadSize)
|
||||||
|
@ -94,8 +109,8 @@ SampleFormat PcmDecoder::setHeader(msg::Header* chunk)
|
||||||
memcpy(&chunk_fmt, chunk->payload + pos, sizeof(chunk_fmt));
|
memcpy(&chunk_fmt, chunk->payload + pos, sizeof(chunk_fmt));
|
||||||
pos += sizeof(chunk_fmt);
|
pos += sizeof(chunk_fmt);
|
||||||
/// If the format header is larger, skip the rest
|
/// If the format header is larger, skip the rest
|
||||||
if (chunk_header.sz > sizeof(chunk_fmt))
|
if (SWAP_32(chunk_header.sz) > sizeof(chunk_fmt))
|
||||||
pos += (chunk_header.sz - sizeof(chunk_fmt));
|
pos += (SWAP_32(chunk_header.sz) - sizeof(chunk_fmt));
|
||||||
break;
|
break;
|
||||||
case ID_DATA:
|
case ID_DATA:
|
||||||
/// Stop looking for chunks
|
/// Stop looking for chunks
|
||||||
|
@ -103,19 +118,19 @@ SampleFormat PcmDecoder::setHeader(msg::Header* chunk)
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/// Unknown chunk, skip bytes
|
/// Unknown chunk, skip bytes
|
||||||
pos += chunk_header.sz;
|
pos += SWAP_32(chunk_header.sz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (moreChunks);
|
while (moreChunks);
|
||||||
|
|
||||||
|
|
||||||
if (chunk_fmt.sample_rate == 0)
|
if (SWAP_32(chunk_fmt.sample_rate) == 0)
|
||||||
throw SnapException("Sample format not found");
|
throw SnapException("Sample format not found");
|
||||||
|
|
||||||
SampleFormat sampleFormat(
|
SampleFormat sampleFormat(
|
||||||
chunk_fmt.sample_rate,
|
SWAP_32(chunk_fmt.sample_rate),
|
||||||
chunk_fmt.bits_per_sample,
|
SWAP_16(chunk_fmt.bits_per_sample),
|
||||||
chunk_fmt.num_channels);
|
SWAP_16(chunk_fmt.num_channels));
|
||||||
|
|
||||||
return sampleFormat;
|
return sampleFormat;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "../stream.h"
|
#include "../stream.h"
|
||||||
#include "pcmDevice.h"
|
#include "pcmDevice.h"
|
||||||
|
#include "common/endian.h"
|
||||||
|
#include "common/log.h"
|
||||||
|
|
||||||
|
|
||||||
/// Audio Player
|
/// Audio Player
|
||||||
|
@ -50,8 +52,9 @@ protected:
|
||||||
void adjustVolume(char *buffer, size_t count, double volume)
|
void adjustVolume(char *buffer, size_t count, double volume)
|
||||||
{
|
{
|
||||||
T* bufferT = (T*)buffer;
|
T* bufferT = (T*)buffer;
|
||||||
|
//TODO: SWAP_T
|
||||||
for (size_t n=0; n<count; ++n)
|
for (size_t n=0; n<count; ++n)
|
||||||
bufferT[n] *= volume;
|
bufferT[n] = (T)(SWAP_16(((T)SWAP_16(bufferT[n])) * volume));
|
||||||
}
|
}
|
||||||
|
|
||||||
void adjustVolume(char* buffer, size_t frames);
|
void adjustVolume(char* buffer, size_t frames);
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#endif
|
#endif
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/signalHandler.h"
|
#include "common/signalHandler.h"
|
||||||
|
#include "common/compat.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -46,7 +47,7 @@ PcmDevice getPcmDevice(const std::string& soundcard)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int soundcardIdx = std::stoi(soundcard);
|
int soundcardIdx = cpt::stoi(soundcard);
|
||||||
for (auto dev: pcmDevices)
|
for (auto dev: pcmDevices)
|
||||||
if (dev.idx == soundcardIdx)
|
if (dev.idx == soundcardIdx)
|
||||||
return dev;
|
return dev;
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NO_STOUL
|
#if defined(NO_STOUL) || defined(NO_STOI)
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -39,6 +39,16 @@ namespace cpt
|
||||||
return std::stoul(s);
|
return std::stoul(s);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int stoi(const std::string& str)
|
||||||
|
{
|
||||||
|
#ifdef NO_STOI
|
||||||
|
return strtol(str.c_str(), 0, 10);
|
||||||
|
#else
|
||||||
|
return std::stoi(str);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
16
common/endian.h
Normal file
16
common/endian.h
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef ENDIAN_H
|
||||||
|
#define ENDIAN_H
|
||||||
|
|
||||||
|
#ifdef IS_BIG_ENDIAN
|
||||||
|
# define SWAP_16(x) (__builtin_bswap16(x))
|
||||||
|
# define SWAP_32(x) (__builtin_bswap32(x))
|
||||||
|
# define SWAP_64(x) (__builtin_bswap64(x))
|
||||||
|
#else
|
||||||
|
# define SWAP_16(x) x
|
||||||
|
# define SWAP_32(x) x
|
||||||
|
# define SWAP_64(x) x
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
|
||||||
Log::Log(std::string ident, int facility)
|
Log::Log(std::string ident, int facility)
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,19 +42,13 @@ public:
|
||||||
|
|
||||||
virtual void read(std::istream& stream)
|
virtual void read(std::istream& stream)
|
||||||
{
|
{
|
||||||
int16_t size;
|
readVal(stream, codec);
|
||||||
stream.read(reinterpret_cast<char *>(&size), sizeof(int16_t));
|
readVal(stream, &payload, payloadSize);
|
||||||
codec.resize(size);
|
|
||||||
stream.read(&codec[0], size);
|
|
||||||
|
|
||||||
stream.read(reinterpret_cast<char *>(&payloadSize), sizeof(uint32_t));
|
|
||||||
payload = (char*)realloc(payload, payloadSize);
|
|
||||||
stream.read(payload, payloadSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual uint32_t getSize() const
|
virtual uint32_t getSize() const
|
||||||
{
|
{
|
||||||
return sizeof(int16_t) + codec.size() + sizeof(uint32_t) + payloadSize;
|
return sizeof(uint32_t) + codec.size() + sizeof(uint32_t) + payloadSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t payloadSize;
|
uint32_t payloadSize;
|
||||||
|
@ -64,11 +58,8 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual void doserialize(std::ostream& stream) const
|
virtual void doserialize(std::ostream& stream) const
|
||||||
{
|
{
|
||||||
int16_t size(codec.size());
|
writeVal(stream, codec);
|
||||||
stream.write(reinterpret_cast<const char *>(&size), sizeof(int16_t));
|
writeVal(stream, payload, payloadSize);
|
||||||
stream.write(codec.c_str(), size);
|
|
||||||
stream.write(reinterpret_cast<const char *>(&payloadSize), sizeof(uint32_t));
|
|
||||||
stream.write(payload, payloadSize);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -44,21 +44,15 @@ public:
|
||||||
{
|
{
|
||||||
strMap.clear();
|
strMap.clear();
|
||||||
uint16_t mapSize;
|
uint16_t mapSize;
|
||||||
stream.read(reinterpret_cast<char *>(&mapSize), sizeof(uint16_t));
|
readVal(stream, mapSize);
|
||||||
|
|
||||||
for (size_t n=0; n<mapSize; ++n)
|
for (size_t n=0; n<mapSize; ++n)
|
||||||
{
|
{
|
||||||
uint16_t size;
|
|
||||||
std::string key;
|
std::string key;
|
||||||
stream.read(reinterpret_cast<char *>(&size), sizeof(uint16_t));
|
|
||||||
key.resize(size);
|
|
||||||
stream.read(&key[0], size);
|
|
||||||
|
|
||||||
std::string value;
|
std::string value;
|
||||||
stream.read(reinterpret_cast<char *>(&size), sizeof(uint16_t));
|
|
||||||
value.resize(size);
|
|
||||||
stream.read(&value[0], size);
|
|
||||||
|
|
||||||
|
readVal(stream, key);
|
||||||
|
readVal(stream, value);
|
||||||
strMap[key] = value;
|
strMap[key] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,7 +61,7 @@ public:
|
||||||
{
|
{
|
||||||
uint32_t size = sizeof(uint16_t); /// count elements
|
uint32_t size = sizeof(uint16_t); /// count elements
|
||||||
for (auto iter = strMap.begin(); iter != strMap.end(); ++iter)
|
for (auto iter = strMap.begin(); iter != strMap.end(); ++iter)
|
||||||
size += (sizeof(uint16_t) + iter->first.size()) + (sizeof(uint16_t) + iter->second.size());
|
size += (sizeof(uint32_t) + iter->first.size()) + (sizeof(uint32_t) + iter->second.size());
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,15 +107,11 @@ protected:
|
||||||
virtual void doserialize(std::ostream& stream) const
|
virtual void doserialize(std::ostream& stream) const
|
||||||
{
|
{
|
||||||
uint16_t size = strMap.size();
|
uint16_t size = strMap.size();
|
||||||
stream.write(reinterpret_cast<const char *>(&size), sizeof(uint16_t));
|
writeVal(stream, size);
|
||||||
for (auto iter = strMap.begin(); iter != strMap.end(); ++iter)
|
for (auto iter = strMap.begin(); iter != strMap.end(); ++iter)
|
||||||
{
|
{
|
||||||
size = iter->first.size();
|
writeVal(stream, iter->first);
|
||||||
stream.write(reinterpret_cast<const char *>(&size), sizeof(uint16_t));
|
writeVal(stream, iter->second);
|
||||||
stream.write(iter->first.c_str(), iter->first.size());
|
|
||||||
size = iter->second.size();
|
|
||||||
stream.write(reinterpret_cast<const char *>(&size), sizeof(uint16_t));
|
|
||||||
stream.write(iter->second.c_str(), iter->second.size());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <streambuf>
|
#include <streambuf>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include "common/endian.h"
|
||||||
|
|
||||||
|
|
||||||
template<typename CharT, typename TraitsT = std::char_traits<CharT> >
|
template<typename CharT, typename TraitsT = std::char_traits<CharT> >
|
||||||
|
@ -126,14 +127,17 @@ struct BaseMessage
|
||||||
|
|
||||||
virtual void read(std::istream& stream)
|
virtual void read(std::istream& stream)
|
||||||
{
|
{
|
||||||
stream.read(reinterpret_cast<char*>(&type), sizeof(uint16_t));
|
readVal(stream, type);
|
||||||
stream.read(reinterpret_cast<char*>(&id), sizeof(uint16_t));
|
readVal(stream, id);
|
||||||
stream.read(reinterpret_cast<char*>(&refersTo), sizeof(uint16_t));
|
readVal(stream, refersTo);
|
||||||
stream.read(reinterpret_cast<char*>(&sent.sec), sizeof(int32_t));
|
readVal(stream, sent.sec);
|
||||||
stream.read(reinterpret_cast<char*>(&sent.usec), sizeof(int32_t));
|
readVal(stream, sent.usec);
|
||||||
stream.read(reinterpret_cast<char*>(&received.sec), sizeof(int32_t));
|
readVal(stream, received.sec);
|
||||||
stream.read(reinterpret_cast<char*>(&received.usec), sizeof(int32_t));
|
readVal(stream, received.usec);
|
||||||
stream.read(reinterpret_cast<char*>(&size), sizeof(uint32_t));
|
readVal(stream, size);
|
||||||
|
//std::cout << type << ", " << id << ", " << refersTo << ", " << sent.sec << ":" << sent.usec << ", " << received.sec << ":" << received.usec << ", " << size << "\n";
|
||||||
|
//std::cout << __builtin_bswap32(type) << ", " << __builtin_bswap16(id) << ", " << __builtin_bswap16(refersTo) << ", " << __builtin_bswap32(sent.sec) << ":" << __builtin_bswap32(sent.usec) << ", " << __builtin_bswap32(received.sec) << ":" << __builtin_bswap32(received.usec) << ", " << __builtin_bswap32(size) << "\n";
|
||||||
|
//std::cout << SWAP_32(type) << ", " << SWAP_16(id) << ", " << SWAP_16(refersTo) << ", " << SWAP_32(sent.sec) << ":" << SWAP_32(sent.usec) << ", " << SWAP_32(received.sec) << ":" << SWAP_32(received.usec) << ", " << SWAP_32(size) << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void deserialize(char* payload)
|
void deserialize(char* payload)
|
||||||
|
@ -158,24 +162,26 @@ struct BaseMessage
|
||||||
|
|
||||||
virtual void serialize(std::ostream& stream) const
|
virtual void serialize(std::ostream& stream) const
|
||||||
{
|
{
|
||||||
stream.write(reinterpret_cast<const char*>(&type), sizeof(uint16_t));
|
writeVal(stream, type);
|
||||||
stream.write(reinterpret_cast<const char*>(&id), sizeof(uint16_t));
|
writeVal(stream, id);
|
||||||
stream.write(reinterpret_cast<const char*>(&refersTo), sizeof(uint16_t));
|
writeVal(stream, refersTo);
|
||||||
stream.write(reinterpret_cast<const char *>(&sent.sec), sizeof(int32_t));
|
writeVal(stream, sent.sec);
|
||||||
stream.write(reinterpret_cast<const char *>(&sent.usec), sizeof(int32_t));
|
writeVal(stream, sent.usec);
|
||||||
stream.write(reinterpret_cast<const char *>(&received.sec), sizeof(int32_t));
|
writeVal(stream, received.sec);
|
||||||
stream.write(reinterpret_cast<const char *>(&received.usec), sizeof(int32_t));
|
writeVal(stream, received.usec);
|
||||||
size = getSize();
|
size = getSize();
|
||||||
stream.write(reinterpret_cast<const char*>(&size), sizeof(uint32_t));
|
writeVal(stream, size);
|
||||||
|
//std::cout << type << ", " << id << ", " << refersTo << ", " << sent.sec << ":" << sent.usec << ", " << received.sec << ":" << received.usec << ", " << size << "\n";
|
||||||
|
//std::cout << SWAP_32(type) << ", " << SWAP_16(id) << ", " << SWAP_16(refersTo) << ", " << SWAP_32(sent.sec) << ":" << SWAP_32(sent.usec) << ", " << SWAP_32(received.sec) << ":" << SWAP_32(received.usec) << ", " << SWAP_32(size) << "\n";
|
||||||
doserialize(stream);
|
doserialize(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual uint32_t getSize() const
|
virtual uint32_t getSize() const
|
||||||
{
|
{
|
||||||
return 3*sizeof(uint16_t) + 2*sizeof(tv) + sizeof(uint32_t);
|
return 2*sizeof(uint16_t) + 2*sizeof(tv) + 2*sizeof(uint32_t);
|
||||||
};
|
};
|
||||||
|
|
||||||
uint16_t type;
|
uint32_t type;
|
||||||
mutable uint16_t id;
|
mutable uint16_t id;
|
||||||
uint16_t refersTo;
|
uint16_t refersTo;
|
||||||
tv received;
|
tv received;
|
||||||
|
@ -183,6 +189,119 @@ struct BaseMessage
|
||||||
mutable uint32_t size;
|
mutable uint32_t size;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void writeVal(std::ostream& stream, const bool& val) const
|
||||||
|
{
|
||||||
|
char c = val?1:0;
|
||||||
|
writeVal(stream, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeVal(std::ostream& stream, const char& val) const
|
||||||
|
{
|
||||||
|
stream.write(reinterpret_cast<const char*>(&val), sizeof(char));
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeVal(std::ostream& stream, const uint16_t& val) const
|
||||||
|
{
|
||||||
|
uint16_t v = SWAP_16(val);
|
||||||
|
stream.write(reinterpret_cast<const char*>(&v), sizeof(uint16_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeVal(std::ostream& stream, const int16_t& val) const
|
||||||
|
{
|
||||||
|
uint16_t v = SWAP_16(val);
|
||||||
|
stream.write(reinterpret_cast<const char*>(&v), sizeof(int16_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeVal(std::ostream& stream, const uint32_t& val) const
|
||||||
|
{
|
||||||
|
uint32_t v = SWAP_32(val);
|
||||||
|
stream.write(reinterpret_cast<const char*>(&v), sizeof(uint32_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeVal(std::ostream& stream, const int32_t& val) const
|
||||||
|
{
|
||||||
|
uint32_t v = SWAP_32(val);
|
||||||
|
stream.write(reinterpret_cast<const char*>(&v), sizeof(int32_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeVal(std::ostream& stream, const double& val) const
|
||||||
|
{
|
||||||
|
uint64_t v = SWAP_64(*(int64_t*)&val);
|
||||||
|
stream.write(reinterpret_cast<const char*>(&v), sizeof(int64_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeVal(std::ostream& stream, const char* payload, const uint32_t& size) const
|
||||||
|
{
|
||||||
|
writeVal(stream, size);
|
||||||
|
stream.write(payload, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeVal(std::ostream& stream, const std::string& val) const
|
||||||
|
{
|
||||||
|
uint32_t size = val.size();
|
||||||
|
writeVal(stream, val.c_str(), size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void readVal(std::istream& stream, bool& val) const
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
readVal(stream, c);
|
||||||
|
val = (c != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void readVal(std::istream& stream, char& val) const
|
||||||
|
{
|
||||||
|
stream.read(reinterpret_cast<char*>(&val), sizeof(char));
|
||||||
|
}
|
||||||
|
|
||||||
|
void readVal(std::istream& stream, uint16_t& val) const
|
||||||
|
{
|
||||||
|
stream.read(reinterpret_cast<char*>(&val), sizeof(uint16_t));
|
||||||
|
val = SWAP_16(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
void readVal(std::istream& stream, int16_t& val) const
|
||||||
|
{
|
||||||
|
stream.read(reinterpret_cast<char*>(&val), sizeof(int16_t));
|
||||||
|
val = SWAP_16(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
void readVal(std::istream& stream, uint32_t& val) const
|
||||||
|
{
|
||||||
|
stream.read(reinterpret_cast<char*>(&val), sizeof(uint32_t));
|
||||||
|
val = SWAP_32(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
void readVal(std::istream& stream, int32_t& val) const
|
||||||
|
{
|
||||||
|
stream.read(reinterpret_cast<char*>(&val), sizeof(int32_t));
|
||||||
|
val = SWAP_32(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
void readVal(std::istream& stream, double& val) const
|
||||||
|
{
|
||||||
|
stream.read(reinterpret_cast<char*>(&val), sizeof(int64_t));
|
||||||
|
val = SWAP_64(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
void readVal(std::istream& stream, char** payload, uint32_t& size) const
|
||||||
|
{
|
||||||
|
readVal(stream, size);
|
||||||
|
*payload = (char*)realloc(*payload, size);
|
||||||
|
stream.read(*payload, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void readVal(std::istream& stream, std::string& val) const
|
||||||
|
{
|
||||||
|
uint32_t size;
|
||||||
|
readVal(stream, size);
|
||||||
|
val.resize(size);
|
||||||
|
stream.read(&val[0], size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual void doserialize(std::ostream& stream) const
|
virtual void doserialize(std::ostream& stream) const
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
|
@ -45,7 +45,9 @@ public:
|
||||||
|
|
||||||
virtual void read(std::istream& stream)
|
virtual void read(std::istream& stream)
|
||||||
{
|
{
|
||||||
stream.read(reinterpret_cast<char *>(&request), sizeof(int16_t));
|
uint16_t i;
|
||||||
|
readVal(stream, i);
|
||||||
|
request = (message_type)i;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual uint32_t getSize() const
|
virtual uint32_t getSize() const
|
||||||
|
@ -58,7 +60,8 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual void doserialize(std::ostream& stream) const
|
virtual void doserialize(std::ostream& stream) const
|
||||||
{
|
{
|
||||||
stream.write(reinterpret_cast<const char *>(&request), sizeof(int16_t));
|
uint16_t i = request;
|
||||||
|
writeVal(stream, i);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -38,15 +38,15 @@ public:
|
||||||
|
|
||||||
virtual void read(std::istream& stream)
|
virtual void read(std::istream& stream)
|
||||||
{
|
{
|
||||||
stream.read(reinterpret_cast<char*>(&bufferMs), sizeof(int32_t));
|
readVal(stream, bufferMs);
|
||||||
stream.read(reinterpret_cast<char*>(&latency), sizeof(int32_t));
|
readVal(stream, latency);
|
||||||
stream.read(reinterpret_cast<char*>(&volume), sizeof(uint16_t));
|
readVal(stream, volume);
|
||||||
stream.read(reinterpret_cast<char*>(&muted), sizeof(bool));
|
readVal(stream, muted);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual uint32_t getSize() const
|
virtual uint32_t getSize() const
|
||||||
{
|
{
|
||||||
return sizeof(int32_t) + sizeof(int32_t) + sizeof(uint16_t) + sizeof(bool);
|
return sizeof(int32_t) + sizeof(int32_t) + sizeof(uint16_t) + sizeof(unsigned char);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t bufferMs;
|
int32_t bufferMs;
|
||||||
|
@ -57,10 +57,10 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual void doserialize(std::ostream& stream) const
|
virtual void doserialize(std::ostream& stream) const
|
||||||
{
|
{
|
||||||
stream.write(reinterpret_cast<const char*>(&bufferMs), sizeof(int32_t));
|
writeVal(stream, bufferMs);
|
||||||
stream.write(reinterpret_cast<const char*>(&latency), sizeof(int32_t));
|
writeVal(stream, latency);
|
||||||
stream.write(reinterpret_cast<const char*>(&volume), sizeof(uint16_t));
|
writeVal(stream, volume);
|
||||||
stream.write(reinterpret_cast<const char*>(&muted), sizeof(bool));
|
writeVal(stream, muted);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,8 @@ public:
|
||||||
|
|
||||||
virtual void read(std::istream& stream)
|
virtual void read(std::istream& stream)
|
||||||
{
|
{
|
||||||
stream.read(reinterpret_cast<char *>(&latency), sizeof(double));
|
readVal(stream, latency);
|
||||||
|
// stream.read(reinterpret_cast<char *>(&latency), sizeof(double));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual uint32_t getSize() const
|
virtual uint32_t getSize() const
|
||||||
|
@ -50,7 +51,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual void doserialize(std::ostream& stream) const
|
virtual void doserialize(std::ostream& stream) const
|
||||||
{
|
{
|
||||||
stream.write(reinterpret_cast<const char *>(&latency), sizeof(double));
|
writeVal(stream, latency);//reinterpret_cast<const char *>(&latency), sizeof(double));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -57,16 +57,14 @@ public:
|
||||||
|
|
||||||
virtual void read(std::istream& stream)
|
virtual void read(std::istream& stream)
|
||||||
{
|
{
|
||||||
stream.read(reinterpret_cast<char *>(×tamp.sec), sizeof(int32_t));
|
readVal(stream, timestamp.sec);
|
||||||
stream.read(reinterpret_cast<char *>(×tamp.usec), sizeof(int32_t));
|
readVal(stream, timestamp.usec);
|
||||||
stream.read(reinterpret_cast<char *>(&payloadSize), sizeof(uint32_t));
|
readVal(stream, &payload, payloadSize);
|
||||||
payload = (char*)realloc(payload, payloadSize);
|
|
||||||
stream.read(payload, payloadSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual uint32_t getSize() const
|
virtual uint32_t getSize() const
|
||||||
{
|
{
|
||||||
return sizeof(int32_t) + sizeof(int32_t) + sizeof(uint32_t) + payloadSize;
|
return sizeof(tv) + sizeof(int32_t) + payloadSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual chronos::time_point_hrc start() const
|
virtual chronos::time_point_hrc start() const
|
||||||
|
@ -81,10 +79,9 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual void doserialize(std::ostream& stream) const
|
virtual void doserialize(std::ostream& stream) const
|
||||||
{
|
{
|
||||||
stream.write(reinterpret_cast<const char *>(×tamp.sec), sizeof(int32_t));
|
writeVal(stream, timestamp.sec);
|
||||||
stream.write(reinterpret_cast<const char *>(×tamp.usec), sizeof(int32_t));
|
writeVal(stream, timestamp.usec);
|
||||||
stream.write(reinterpret_cast<const char *>(&payloadSize), sizeof(uint32_t));
|
writeVal(stream, payload, payloadSize);
|
||||||
stream.write(payload, payloadSize);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,9 @@ else
|
||||||
TARGET_DIR ?= /usr
|
TARGET_DIR ?= /usr
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CXX = /usr/bin/g++
|
CXX = /usr/bin/g++
|
||||||
CFLAGS = -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 -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
|
||||||
|
|
||||||
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
|
||||||
|
@ -19,11 +19,11 @@ BIN = snapserver
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
$(TARGET): $(OBJ)
|
$(TARGET): $(OBJ)
|
||||||
$(CXX) $(CFLAGS) -o $(BIN) $(OBJ) $(LDFLAGS)
|
$(CXX) $(CXXFLAGS) -o $(BIN) $(OBJ) $(LDFLAGS)
|
||||||
strip $(BIN)
|
strip $(BIN)
|
||||||
|
|
||||||
%.o: %.cpp
|
%.o: %.cpp
|
||||||
$(CXX) $(CFLAGS) -c $< -o $@
|
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(BIN) $(OBJ) *~
|
rm -rf $(BIN) $(OBJ) *~
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue