mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-30 09:26:15 +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
|
||||
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)
|
||||
# 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
|
||||
|
@ -28,29 +24,38 @@ ifdef ANDROID
|
|||
# make ANDROID=1
|
||||
CXX = $(NDK_DIR)/bin/arm-linux-androideabi-g++
|
||||
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
|
||||
#-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16
|
||||
CXXFLAGS += -DANDROID -fPIC -DHAS_OPENSL -I/home/johannes/Develop/build/arm/include
|
||||
LDFLAGS = -L/home/johannes/Develop/build/arm/lib -pie -lFLAC -lOpenSLES
|
||||
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
|
||||
OBJ += player/openslPlayer.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
|
||||
|
||||
CXX = /usr/bin/g++
|
||||
STRIP = strip
|
||||
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
|
||||
CXXFLAGS += -static-libgcc -static-libstdc++ -DHAS_OGG -DHAS_ALSA -DHAS_AVAHI -DHAS_DAEMON
|
||||
LDFLAGS = -lrt -lasound -logg -lvorbis -lFLAC -lavahi-client -lavahi-common
|
||||
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
|
||||
OBJ += player/alsaPlayer.o decoder/oggDecoder.o browseAvahi.o
|
||||
|
||||
endif
|
||||
|
||||
|
||||
BIN = snapclient
|
||||
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
$(CXX) $(CFLAGS) -o $(BIN) $(OBJ) $(LDFLAGS)
|
||||
$(STRIP) $(BIN)
|
||||
$(CXX) $(CXXFLAGS) -o $(BIN) $(OBJ) $(LDFLAGS)
|
||||
# $(STRIP) $(BIN)
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) $(CFLAGS) -c $< -o $@
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
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 */
|
||||
char **ptr=vc.user_comments;
|
||||
while(*ptr)
|
||||
while (*ptr)
|
||||
{
|
||||
fprintf(stderr,"%s\n",*ptr);
|
||||
logO << "comment: " << *ptr << "\n";;
|
||||
++ptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
***/
|
||||
|
||||
#include "common/snapException.h"
|
||||
#include "common/endian.h"
|
||||
#include "common/log.h"
|
||||
#include "pcmDecoder.h"
|
||||
|
||||
|
@ -59,7 +60,19 @@ PcmDecoder::PcmDecoder() : Decoder()
|
|||
|
||||
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 chunk_header chunk_header;
|
||||
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);
|
||||
memcpy(&riff_wave_header, chunk->payload + 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");
|
||||
|
||||
bool moreChunks(true);
|
||||
|
@ -86,7 +101,7 @@ SampleFormat PcmDecoder::setHeader(msg::Header* chunk)
|
|||
throw SnapException("riff/wave header incomplete");
|
||||
memcpy(&chunk_header, chunk->payload + pos, sizeof(chunk_header));
|
||||
pos += sizeof(chunk_header);
|
||||
switch (chunk_header.id)
|
||||
switch (SWAP_32(chunk_header.id))
|
||||
{
|
||||
case ID_FMT:
|
||||
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));
|
||||
pos += sizeof(chunk_fmt);
|
||||
/// If the format header is larger, skip the rest
|
||||
if (chunk_header.sz > sizeof(chunk_fmt))
|
||||
pos += (chunk_header.sz - sizeof(chunk_fmt));
|
||||
if (SWAP_32(chunk_header.sz) > sizeof(chunk_fmt))
|
||||
pos += (SWAP_32(chunk_header.sz) - sizeof(chunk_fmt));
|
||||
break;
|
||||
case ID_DATA:
|
||||
/// Stop looking for chunks
|
||||
|
@ -103,19 +118,19 @@ SampleFormat PcmDecoder::setHeader(msg::Header* chunk)
|
|||
break;
|
||||
default:
|
||||
/// Unknown chunk, skip bytes
|
||||
pos += chunk_header.sz;
|
||||
pos += SWAP_32(chunk_header.sz);
|
||||
}
|
||||
}
|
||||
while (moreChunks);
|
||||
|
||||
|
||||
if (chunk_fmt.sample_rate == 0)
|
||||
if (SWAP_32(chunk_fmt.sample_rate) == 0)
|
||||
throw SnapException("Sample format not found");
|
||||
|
||||
SampleFormat sampleFormat(
|
||||
chunk_fmt.sample_rate,
|
||||
chunk_fmt.bits_per_sample,
|
||||
chunk_fmt.num_channels);
|
||||
SWAP_32(chunk_fmt.sample_rate),
|
||||
SWAP_16(chunk_fmt.bits_per_sample),
|
||||
SWAP_16(chunk_fmt.num_channels));
|
||||
|
||||
return sampleFormat;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include <vector>
|
||||
#include "../stream.h"
|
||||
#include "pcmDevice.h"
|
||||
#include "common/endian.h"
|
||||
#include "common/log.h"
|
||||
|
||||
|
||||
/// Audio Player
|
||||
|
@ -50,8 +52,9 @@ protected:
|
|||
void adjustVolume(char *buffer, size_t count, double volume)
|
||||
{
|
||||
T* bufferT = (T*)buffer;
|
||||
//TODO: SWAP_T
|
||||
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);
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#endif
|
||||
#include "common/log.h"
|
||||
#include "common/signalHandler.h"
|
||||
#include "common/compat.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
@ -46,7 +47,7 @@ PcmDevice getPcmDevice(const std::string& soundcard)
|
|||
|
||||
try
|
||||
{
|
||||
int soundcardIdx = std::stoi(soundcard);
|
||||
int soundcardIdx = cpt::stoi(soundcard);
|
||||
for (auto dev: pcmDevices)
|
||||
if (dev.idx == soundcardIdx)
|
||||
return dev;
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <sstream>
|
||||
#endif
|
||||
|
||||
#ifdef NO_STOUL
|
||||
#if defined(NO_STOUL) || defined(NO_STOI)
|
||||
#include <cstdlib>
|
||||
#endif
|
||||
|
||||
|
@ -39,6 +39,16 @@ namespace cpt
|
|||
return std::stoul(s);
|
||||
#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 <ctime>
|
||||
#include <sstream>
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
Log::Log(std::string ident, int facility)
|
||||
{
|
||||
|
|
|
@ -42,19 +42,13 @@ public:
|
|||
|
||||
virtual void read(std::istream& stream)
|
||||
{
|
||||
int16_t size;
|
||||
stream.read(reinterpret_cast<char *>(&size), sizeof(int16_t));
|
||||
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);
|
||||
readVal(stream, codec);
|
||||
readVal(stream, &payload, payloadSize);
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -64,11 +58,8 @@ public:
|
|||
protected:
|
||||
virtual void doserialize(std::ostream& stream) const
|
||||
{
|
||||
int16_t size(codec.size());
|
||||
stream.write(reinterpret_cast<const char *>(&size), sizeof(int16_t));
|
||||
stream.write(codec.c_str(), size);
|
||||
stream.write(reinterpret_cast<const char *>(&payloadSize), sizeof(uint32_t));
|
||||
stream.write(payload, payloadSize);
|
||||
writeVal(stream, codec);
|
||||
writeVal(stream, payload, payloadSize);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -44,21 +44,15 @@ public:
|
|||
{
|
||||
strMap.clear();
|
||||
uint16_t mapSize;
|
||||
stream.read(reinterpret_cast<char *>(&mapSize), sizeof(uint16_t));
|
||||
readVal(stream, mapSize);
|
||||
|
||||
for (size_t n=0; n<mapSize; ++n)
|
||||
{
|
||||
uint16_t size;
|
||||
std::string key;
|
||||
stream.read(reinterpret_cast<char *>(&size), sizeof(uint16_t));
|
||||
key.resize(size);
|
||||
stream.read(&key[0], size);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +61,7 @@ public:
|
|||
{
|
||||
uint32_t size = sizeof(uint16_t); /// count elements
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -113,15 +107,11 @@ protected:
|
|||
virtual void doserialize(std::ostream& stream) const
|
||||
{
|
||||
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)
|
||||
{
|
||||
size = iter->first.size();
|
||||
stream.write(reinterpret_cast<const char *>(&size), sizeof(uint16_t));
|
||||
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());
|
||||
writeVal(stream, iter->first);
|
||||
writeVal(stream, iter->second);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <streambuf>
|
||||
#include <vector>
|
||||
#include <sys/time.h>
|
||||
#include "common/endian.h"
|
||||
|
||||
|
||||
template<typename CharT, typename TraitsT = std::char_traits<CharT> >
|
||||
|
@ -126,14 +127,17 @@ struct BaseMessage
|
|||
|
||||
virtual void read(std::istream& stream)
|
||||
{
|
||||
stream.read(reinterpret_cast<char*>(&type), sizeof(uint16_t));
|
||||
stream.read(reinterpret_cast<char*>(&id), sizeof(uint16_t));
|
||||
stream.read(reinterpret_cast<char*>(&refersTo), sizeof(uint16_t));
|
||||
stream.read(reinterpret_cast<char*>(&sent.sec), sizeof(int32_t));
|
||||
stream.read(reinterpret_cast<char*>(&sent.usec), sizeof(int32_t));
|
||||
stream.read(reinterpret_cast<char*>(&received.sec), sizeof(int32_t));
|
||||
stream.read(reinterpret_cast<char*>(&received.usec), sizeof(int32_t));
|
||||
stream.read(reinterpret_cast<char*>(&size), sizeof(uint32_t));
|
||||
readVal(stream, type);
|
||||
readVal(stream, id);
|
||||
readVal(stream, refersTo);
|
||||
readVal(stream, sent.sec);
|
||||
readVal(stream, sent.usec);
|
||||
readVal(stream, received.sec);
|
||||
readVal(stream, received.usec);
|
||||
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)
|
||||
|
@ -158,24 +162,26 @@ struct BaseMessage
|
|||
|
||||
virtual void serialize(std::ostream& stream) const
|
||||
{
|
||||
stream.write(reinterpret_cast<const char*>(&type), sizeof(uint16_t));
|
||||
stream.write(reinterpret_cast<const char*>(&id), sizeof(uint16_t));
|
||||
stream.write(reinterpret_cast<const char*>(&refersTo), sizeof(uint16_t));
|
||||
stream.write(reinterpret_cast<const char *>(&sent.sec), sizeof(int32_t));
|
||||
stream.write(reinterpret_cast<const char *>(&sent.usec), sizeof(int32_t));
|
||||
stream.write(reinterpret_cast<const char *>(&received.sec), sizeof(int32_t));
|
||||
stream.write(reinterpret_cast<const char *>(&received.usec), sizeof(int32_t));
|
||||
writeVal(stream, type);
|
||||
writeVal(stream, id);
|
||||
writeVal(stream, refersTo);
|
||||
writeVal(stream, sent.sec);
|
||||
writeVal(stream, sent.usec);
|
||||
writeVal(stream, received.sec);
|
||||
writeVal(stream, received.usec);
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
uint16_t refersTo;
|
||||
tv received;
|
||||
|
@ -183,6 +189,119 @@ struct BaseMessage
|
|||
mutable uint32_t size;
|
||||
|
||||
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
|
||||
{
|
||||
};
|
||||
|
|
|
@ -45,7 +45,9 @@ public:
|
|||
|
||||
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
|
||||
|
@ -58,7 +60,8 @@ public:
|
|||
protected:
|
||||
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)
|
||||
{
|
||||
stream.read(reinterpret_cast<char*>(&bufferMs), sizeof(int32_t));
|
||||
stream.read(reinterpret_cast<char*>(&latency), sizeof(int32_t));
|
||||
stream.read(reinterpret_cast<char*>(&volume), sizeof(uint16_t));
|
||||
stream.read(reinterpret_cast<char*>(&muted), sizeof(bool));
|
||||
readVal(stream, bufferMs);
|
||||
readVal(stream, latency);
|
||||
readVal(stream, volume);
|
||||
readVal(stream, muted);
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -57,10 +57,10 @@ public:
|
|||
protected:
|
||||
virtual void doserialize(std::ostream& stream) const
|
||||
{
|
||||
stream.write(reinterpret_cast<const char*>(&bufferMs), sizeof(int32_t));
|
||||
stream.write(reinterpret_cast<const char*>(&latency), sizeof(int32_t));
|
||||
stream.write(reinterpret_cast<const char*>(&volume), sizeof(uint16_t));
|
||||
stream.write(reinterpret_cast<const char*>(&muted), sizeof(bool));
|
||||
writeVal(stream, bufferMs);
|
||||
writeVal(stream, latency);
|
||||
writeVal(stream, volume);
|
||||
writeVal(stream, muted);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -37,7 +37,8 @@ public:
|
|||
|
||||
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
|
||||
|
@ -50,7 +51,7 @@ public:
|
|||
protected:
|
||||
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)
|
||||
{
|
||||
stream.read(reinterpret_cast<char *>(×tamp.sec), sizeof(int32_t));
|
||||
stream.read(reinterpret_cast<char *>(×tamp.usec), sizeof(int32_t));
|
||||
stream.read(reinterpret_cast<char *>(&payloadSize), sizeof(uint32_t));
|
||||
payload = (char*)realloc(payload, payloadSize);
|
||||
stream.read(payload, payloadSize);
|
||||
readVal(stream, timestamp.sec);
|
||||
readVal(stream, timestamp.usec);
|
||||
readVal(stream, &payload, payloadSize);
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -81,10 +79,9 @@ public:
|
|||
protected:
|
||||
virtual void doserialize(std::ostream& stream) const
|
||||
{
|
||||
stream.write(reinterpret_cast<const char *>(×tamp.sec), sizeof(int32_t));
|
||||
stream.write(reinterpret_cast<const char *>(×tamp.usec), sizeof(int32_t));
|
||||
stream.write(reinterpret_cast<const char *>(&payloadSize), sizeof(uint32_t));
|
||||
stream.write(payload, payloadSize);
|
||||
writeVal(stream, timestamp.sec);
|
||||
writeVal(stream, timestamp.usec);
|
||||
writeVal(stream, payload, payloadSize);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ else
|
|||
endif
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
@ -19,11 +19,11 @@ BIN = snapserver
|
|||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
$(CXX) $(CFLAGS) -o $(BIN) $(OBJ) $(LDFLAGS)
|
||||
$(CXX) $(CXXFLAGS) -o $(BIN) $(OBJ) $(LDFLAGS)
|
||||
strip $(BIN)
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) $(CFLAGS) -c $< -o $@
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(BIN) $(OBJ) *~
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue