diff --git a/client/Makefile b/client/Makefile index 9ce8d5e2..43da5564 100644 --- a/client/Makefile +++ b/client/Makefile @@ -11,7 +11,7 @@ endif CXXFLAGS += $(ADD_CFLAGS) -std=c++0x -Wall -Wno-unused-function -O3 -pthread -DASIO_STANDALONE -DVERSION=\"$(VERSION)\" -I. -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 +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 ../common/sampleFormat.o ifeq ($(TARGET), ANDROID) # Android NDK setup: (http://developer.android.com/ndk/guides/standalone_toolchain.html) diff --git a/client/controller.cpp b/client/controller.cpp index 51926a5f..04e67c92 100644 --- a/client/controller.cpp +++ b/client/controller.cpp @@ -78,17 +78,17 @@ void Controller::onMessageReceived(ClientConnection* connection, const msg::Base { serverSettings_.reset(new msg::ServerSettings()); serverSettings_->deserialize(baseMessage, buffer); - logO << "ServerSettings - buffer: " << serverSettings_->bufferMs << ", latency: " << serverSettings_->latency << ", volume: " << serverSettings_->volume << ", muted: " << serverSettings_->muted << "\n"; + logO << "ServerSettings - buffer: " << serverSettings_->getBufferMs() << ", latency: " << serverSettings_->getLatency() << ", volume: " << serverSettings_->getVolume() << ", muted: " << serverSettings_->isMuted() << "\n"; if (stream_ && player_) { - player_->setVolume(serverSettings_->volume / 100.); - player_->setMute(serverSettings_->muted); - stream_->setBufferLen(serverSettings_->bufferMs - serverSettings_->latency); + player_->setVolume(serverSettings_->getVolume() / 100.); + player_->setMute(serverSettings_->isMuted()); + stream_->setBufferLen(serverSettings_->getBufferMs() - serverSettings_->getLatency()); } } - else if (baseMessage.type == message_type::kHeader) + else if (baseMessage.type == message_type::kCodecHeader) { - headerChunk_.reset(new msg::Header()); + headerChunk_.reset(new msg::CodecHeader()); headerChunk_->deserialize(baseMessage, buffer); logO << "Codec: " << headerChunk_->codec << "\n"; @@ -111,7 +111,7 @@ void Controller::onMessageReceived(ClientConnection* connection, const msg::Base logState << "sampleformat: " << sampleFormat_.rate << ":" << sampleFormat_.bits << ":" << sampleFormat_.channels << "\n"; stream_.reset(new Stream(sampleFormat_)); - stream_->setBufferLen(serverSettings_->bufferMs - latency_); + stream_->setBufferLen(serverSettings_->getBufferMs() - latency_); #ifdef HAS_ALSA player_.reset(new AlsaPlayer(pcmDevice_, stream_.get())); @@ -120,8 +120,8 @@ void Controller::onMessageReceived(ClientConnection* connection, const msg::Base #else throw SnapException("No ALSA or OPENSL support"); #endif - player_->setVolume(serverSettings_->volume / 100.); - player_->setMute(serverSettings_->muted); + player_->setVolume(serverSettings_->getVolume() / 100.); + player_->setMute(serverSettings_->isMuted()); player_->start(); } diff --git a/client/controller.h b/client/controller.h index d2afe3c6..039e529f 100644 --- a/client/controller.h +++ b/client/controller.h @@ -68,7 +68,7 @@ private: std::unique_ptr decoder_; std::unique_ptr player_; std::shared_ptr serverSettings_; - std::shared_ptr headerChunk_; + std::shared_ptr headerChunk_; std::mutex receiveMutex_; std::string exception_; diff --git a/client/decoder/decoder.h b/client/decoder/decoder.h index 4a045950..17df8981 100644 --- a/client/decoder/decoder.h +++ b/client/decoder/decoder.h @@ -20,8 +20,8 @@ #define DECODER_H #include #include "message/pcmChunk.h" -#include "message/header.h" -#include "message/sampleFormat.h" +#include "message/codecHeader.h" +#include "common/sampleFormat.h" class Decoder @@ -30,7 +30,7 @@ public: Decoder() {}; virtual ~Decoder() {}; virtual bool decode(msg::PcmChunk* chunk) = 0; - virtual SampleFormat setHeader(msg::Header* chunk) = 0; + virtual SampleFormat setHeader(msg::CodecHeader* chunk) = 0; protected: std::mutex mutex_; diff --git a/client/decoder/flacDecoder.cpp b/client/decoder/flacDecoder.cpp index df2ec296..0aa191cc 100644 --- a/client/decoder/flacDecoder.cpp +++ b/client/decoder/flacDecoder.cpp @@ -35,7 +35,7 @@ static void metadata_callback(const FLAC__StreamDecoder *decoder, const FLAC__St static void error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); -static msg::Header* flacHeader = NULL; +static msg::CodecHeader* flacHeader = NULL; static msg::PcmChunk* flacChunk = NULL; static msg::PcmChunk* pcmChunk = NULL; static SampleFormat sampleFormat; @@ -84,7 +84,7 @@ bool FlacDecoder::decode(msg::PcmChunk* chunk) } -SampleFormat FlacDecoder::setHeader(msg::Header* chunk) +SampleFormat FlacDecoder::setHeader(msg::CodecHeader* chunk) { flacHeader = chunk; FLAC__StreamDecoderInitStatus init_status; diff --git a/client/decoder/flacDecoder.h b/client/decoder/flacDecoder.h index 41a7d30f..4106ebb4 100644 --- a/client/decoder/flacDecoder.h +++ b/client/decoder/flacDecoder.h @@ -47,7 +47,7 @@ public: FlacDecoder(); virtual ~FlacDecoder(); virtual bool decode(msg::PcmChunk* chunk); - virtual SampleFormat setHeader(msg::Header* chunk); + virtual SampleFormat setHeader(msg::CodecHeader* chunk); CacheInfo cacheInfo_; }; diff --git a/client/decoder/oggDecoder.cpp b/client/decoder/oggDecoder.cpp index 9deae30b..a600ad7e 100644 --- a/client/decoder/oggDecoder.cpp +++ b/client/decoder/oggDecoder.cpp @@ -145,7 +145,7 @@ bool OggDecoder::decode(msg::PcmChunk* chunk) } -SampleFormat OggDecoder::setHeader(msg::Header* chunk) +SampleFormat OggDecoder::setHeader(msg::CodecHeader* chunk) { bytes = chunk->payloadSize; buffer=ogg_sync_buffer(&oy, bytes); diff --git a/client/decoder/oggDecoder.h b/client/decoder/oggDecoder.h index 5c1ca44a..2cfa7231 100644 --- a/client/decoder/oggDecoder.h +++ b/client/decoder/oggDecoder.h @@ -28,7 +28,7 @@ public: OggDecoder(); virtual ~OggDecoder(); virtual bool decode(msg::PcmChunk* chunk); - virtual SampleFormat setHeader(msg::Header* chunk); + virtual SampleFormat setHeader(msg::CodecHeader* chunk); private: bool decodePayload(msg::PcmChunk* chunk); diff --git a/client/decoder/pcmDecoder.cpp b/client/decoder/pcmDecoder.cpp index 9cb5f85f..a48278c4 100644 --- a/client/decoder/pcmDecoder.cpp +++ b/client/decoder/pcmDecoder.cpp @@ -76,7 +76,7 @@ bool PcmDecoder::decode(msg::PcmChunk* chunk) } -SampleFormat PcmDecoder::setHeader(msg::Header* chunk) +SampleFormat PcmDecoder::setHeader(msg::CodecHeader* chunk) { if (chunk->payloadSize < 44) throw SnapException("PCM header too small"); diff --git a/client/decoder/pcmDecoder.h b/client/decoder/pcmDecoder.h index 09ad1f55..6750835d 100644 --- a/client/decoder/pcmDecoder.h +++ b/client/decoder/pcmDecoder.h @@ -26,7 +26,7 @@ class PcmDecoder : public Decoder public: PcmDecoder(); virtual bool decode(msg::PcmChunk* chunk); - virtual SampleFormat setHeader(msg::Header* chunk); + virtual SampleFormat setHeader(msg::CodecHeader* chunk); }; diff --git a/client/stream.h b/client/stream.h index 95b9272b..efe41a22 100644 --- a/client/stream.h +++ b/client/stream.h @@ -30,7 +30,7 @@ #include "doubleBuffer.h" #include "message/message.h" #include "message/pcmChunk.h" -#include "message/sampleFormat.h" +#include "common/sampleFormat.h" #include "common/queue.h" diff --git a/message/sampleFormat.cpp b/common/sampleFormat.cpp similarity index 100% rename from message/sampleFormat.cpp rename to common/sampleFormat.cpp diff --git a/message/sampleFormat.h b/common/sampleFormat.h similarity index 100% rename from message/sampleFormat.h rename to common/sampleFormat.h diff --git a/message/header.h b/message/codecHeader.h similarity index 83% rename from message/header.h rename to message/codecHeader.h index af82accc..62da2ac3 100644 --- a/message/header.h +++ b/message/codecHeader.h @@ -16,8 +16,8 @@ along with this program. If not, see . ***/ -#ifndef HEADER_MESSAGE_H -#define HEADER_MESSAGE_H +#ifndef CODEC_HEADER_MESSAGE_H +#define CODEC_HEADER_MESSAGE_H #include "message.h" @@ -27,15 +27,15 @@ namespace msg /** * Codec dependend header of encoded data stream */ -class Header : public BaseMessage +class CodecHeader : public BaseMessage { public: - Header(const std::string& codecName = "", size_t size = 0) : BaseMessage(message_type::kHeader), payloadSize(size), codec(codecName) + CodecHeader(const std::string& codecName = "", size_t size = 0) : BaseMessage(message_type::kCodecHeader), payloadSize(size), codec(codecName) { payload = (char*)malloc(size); } - virtual ~Header() + virtual ~CodecHeader() { free(payload); } diff --git a/message/hello.h b/message/hello.h index 5cf934c6..2e9f6903 100644 --- a/message/hello.h +++ b/message/hello.h @@ -19,7 +19,7 @@ #ifndef HELLO_MSG_H #define HELLO_MSG_H -#include "mapMessage.h" +#include "jsonMessage.h" #include "common/utils.h" #include @@ -27,22 +27,22 @@ namespace msg { -class Hello : public MapMessage +class Hello : public JsonMessage { public: - Hello() : MapMessage(message_type::kHello) + Hello() : JsonMessage(message_type::kHello) { } - Hello(const std::string& macAddress) : MapMessage(message_type::kHello) + Hello(const std::string& macAddress) : JsonMessage(message_type::kHello) { - add("MAC", macAddress); - add("HostName", ::getHostName()); - add("Version", VERSION); - add("ClientName", "Snapclient"); - add("OS", ::getOS()); - add("Arch", ::getArch()); - add("SnapStreamProtocolVersion", "1"); + msg["MAC"] = macAddress; + msg["HostName"] = ::getHostName(); + msg["Version"] = VERSION; + msg["ClientName"] = "Snapclient"; + msg["OS"] = ::getOS(); + msg["Arch"] = ::getArch(); + msg["SnapStreamProtocolVersion"] = 1; } virtual ~Hello() @@ -51,32 +51,32 @@ public: std::string getMacAddress() { - return get("MAC"); + return msg["MAC"]; } std::string getHostName() { - return get("HostName"); + return msg["HostName"]; } std::string getVersion() { - return get("Version"); + return msg["Version"]; } std::string getClientName() { - return get("ClientName"); + return msg["ClientName"]; } std::string getOS() { - return get("OS"); + return msg["OS"]; } std::string getArch() { - return get("Arch"); + return msg["Arch"]; } int getProtocolVersion() diff --git a/message/jsonMessage.h b/message/jsonMessage.h new file mode 100644 index 00000000..2c1d2c98 --- /dev/null +++ b/message/jsonMessage.h @@ -0,0 +1,83 @@ +/*** + This file is part of snapcast + Copyright (C) 2014-2016 Johannes Pohl + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +***/ + +#ifndef JSON_MESSAGE_H +#define JSON_MESSAGE_H + +#include "message.h" +#include "externals/json.hpp" + + +using json = nlohmann::json; + + +namespace msg +{ + +class JsonMessage : public BaseMessage +{ +public: + JsonMessage(message_type msgType) : BaseMessage(msgType) + { + } + + virtual ~JsonMessage() + { + } + + virtual void read(std::istream& stream) + { + std::string s; + readVal(stream, s); + msg = json::parse(s); + } + + virtual uint32_t getSize() const + { + return sizeof(uint32_t) + msg.dump().size(); + } + + json msg; + + +protected: + virtual void doserialize(std::ostream& stream) const + { + writeVal(stream, msg.dump()); + } + + template + T get(const std::string& what, const T& def) + { + try + { + return msg[what].get(); + } + catch(...) + { + return def; + } + } +}; + +} + + +#endif + + diff --git a/message/mapMessage.h b/message/mapMessage.h deleted file mode 100644 index 13b20780..00000000 --- a/message/mapMessage.h +++ /dev/null @@ -1,124 +0,0 @@ -/*** - This file is part of snapcast - Copyright (C) 2014-2016 Johannes Pohl - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -***/ - -#ifndef MAP_MESSAGE_H -#define MAP_MESSAGE_H - -#include "message.h" -#include -#include -#include -#include "common/log.h" - - -namespace msg -{ - -class MapMessage : public BaseMessage -{ -public: - MapMessage(message_type msgType) : BaseMessage(msgType) - { - } - - virtual ~MapMessage() - { - } - - virtual void read(std::istream& stream) - { - strMap.clear(); - uint16_t mapSize; - readVal(stream, mapSize); - - for (size_t n=0; nfirst.size()) + (sizeof(uint32_t) + iter->second.size()); - return size; - } - - std::map strMap; - - - MapMessage& add(const std::string& key, const std::string& value) - { - strMap[key] = value; - return *this; - } - - std::string get(const std::string& key, const std::string& def = "") - { - if (strMap.find(key) == strMap.end()) - return def; - - return strMap[key]; - } - - - template - T get(const std::string& key, const T& def) - { - T result; - std::stringstream defaultValue; - defaultValue << def; - std::string value = get(key, defaultValue.str()); - - std::istringstream is(value); - while (is.good()) - { - if (is.peek() != EOF) - is >> result; - else - break; - } - return result; - } - - -protected: - virtual void doserialize(std::ostream& stream) const - { - uint16_t size = strMap.size(); - writeVal(stream, size); - for (auto iter = strMap.begin(); iter != strMap.end(); ++iter) - { - writeVal(stream, iter->first); - writeVal(stream, iter->second); - } - } -}; - -} - - -#endif - - diff --git a/message/message.h b/message/message.h index 0a0acbe5..b83b9695 100644 --- a/message/message.h +++ b/message/message.h @@ -51,17 +51,12 @@ struct membuf : public std::basic_streambuf enum message_type { kBase = 0, - kHeader = 1, + kCodecHeader = 1, kWireChunk = 2, -// kSampleFormat = 3, - kServerSettings = 4, - kTime = 5, - kRequest = 6, -// kAck = 7, -// kCommand = 8, - kHello = 9, - kMap = 10 -// kString = 11 + kServerSettings = 3, + kTime = 4, + kRequest = 5, + kHello = 6 }; @@ -135,9 +130,6 @@ struct BaseMessage 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) @@ -171,17 +163,15 @@ struct BaseMessage writeVal(stream, received.usec); size = getSize(); 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 2*sizeof(uint16_t) + 2*sizeof(tv) + 2*sizeof(uint32_t); + return 3*sizeof(uint16_t) + 2*sizeof(tv) + sizeof(uint32_t); }; - uint32_t type; + uint16_t type; mutable uint16_t id; uint16_t refersTo; tv received; @@ -224,12 +214,6 @@ protected: stream.write(reinterpret_cast(&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(&v), sizeof(int64_t)); - } - void writeVal(std::ostream& stream, const char* payload, const uint32_t& size) const { writeVal(stream, size); @@ -280,12 +264,6 @@ protected: val = SWAP_32(val); } - void readVal(std::istream& stream, double& val) const - { - stream.read(reinterpret_cast(&val), sizeof(int64_t)); - val = SWAP_64(val); - } - void readVal(std::istream& stream, char** payload, uint32_t& size) const { readVal(stream, size); diff --git a/message/pcmChunk.h b/message/pcmChunk.h index 3d8694d3..ed0db951 100644 --- a/message/pcmChunk.h +++ b/message/pcmChunk.h @@ -22,7 +22,7 @@ #include #include "message.h" #include "wireChunk.h" -#include "sampleFormat.h" +#include "common/sampleFormat.h" namespace msg diff --git a/message/serverSettings.h b/message/serverSettings.h index 71fb9de6..76bb1ffe 100644 --- a/message/serverSettings.h +++ b/message/serverSettings.h @@ -19,48 +19,67 @@ #ifndef SERVER_SETTINGS_H #define SERVER_SETTINGS_H -#include "message/message.h" +#include "jsonMessage.h" namespace msg { -class ServerSettings : public BaseMessage +class ServerSettings : public JsonMessage { public: - ServerSettings() : BaseMessage(message_type::kServerSettings), bufferMs(0), latency(0), volume(100), muted(false) + ServerSettings() : JsonMessage(message_type::kServerSettings) { + setBufferMs(0); + setLatency(0); + setVolume(100); + setMuted(false); } virtual ~ServerSettings() { } - virtual void read(std::istream& stream) + int32_t getBufferMs() { - readVal(stream, bufferMs); - readVal(stream, latency); - readVal(stream, volume); - readVal(stream, muted); + return get("bufferMs", 0); } - virtual uint32_t getSize() const + int32_t getLatency() { - return sizeof(int32_t) + sizeof(int32_t) + sizeof(uint16_t) + sizeof(unsigned char); + return get("latency", 0); } - int32_t bufferMs; - int32_t latency; - uint16_t volume; - bool muted; - -protected: - virtual void doserialize(std::ostream& stream) const + uint16_t getVolume() { - writeVal(stream, bufferMs); - writeVal(stream, latency); - writeVal(stream, volume); - writeVal(stream, muted); + return get("volume", 100); + } + + bool isMuted() + { + return get("muted", false); + } + + + + void setBufferMs(int32_t bufferMs) + { + msg["bufferMs"] = bufferMs; + } + + void setLatency(int32_t latency) + { + msg["latency"] = latency; + } + + void setVolume(uint16_t volume) + { + msg["volume"] = volume; + } + + void setMuted(bool muted) + { + msg["muted"] = muted; } }; diff --git a/server/Makefile b/server/Makefile index a8c01c68..849a73cf 100644 --- a/server/Makefile +++ b/server/Makefile @@ -27,7 +27,7 @@ LDFLAGS = -lrt -lvorbis -lvorbisenc -logg -lFLAC -lavahi-client -lavahi-common 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 ../common/sampleFormat.o ../message/pcmChunk.o BIN = snapserver all: $(TARGET) diff --git a/server/controlServer.h b/server/controlServer.h index 804406a8..c052f60d 100644 --- a/server/controlServer.h +++ b/server/controlServer.h @@ -29,9 +29,9 @@ #include "controlSession.h" #include "common/queue.h" +#include "common/sampleFormat.h" #include "message/message.h" -#include "message/header.h" -#include "message/sampleFormat.h" +#include "message/codecHeader.h" #include "message/serverSettings.h" diff --git a/server/encoder/encoder.h b/server/encoder/encoder.h index 52faf21b..526f33d8 100644 --- a/server/encoder/encoder.h +++ b/server/encoder/encoder.h @@ -23,8 +23,8 @@ #include #include "message/pcmChunk.h" -#include "message/header.h" -#include "message/sampleFormat.h" +#include "message/codecHeader.h" +#include "common/sampleFormat.h" class Encoder; @@ -84,7 +84,7 @@ public: } /// Header information needed to decode the data - virtual std::shared_ptr getHeader() const + virtual std::shared_ptr getHeader() const { return headerChunk_; } @@ -93,7 +93,7 @@ protected: virtual void initEncoder() = 0; SampleFormat sampleFormat_; - std::shared_ptr headerChunk_; + std::shared_ptr headerChunk_; EncoderListener* listener_; std::string codecOptions_; }; diff --git a/server/encoder/flacEncoder.cpp b/server/encoder/flacEncoder.cpp index 9e6d5310..780bdee5 100644 --- a/server/encoder/flacEncoder.cpp +++ b/server/encoder/flacEncoder.cpp @@ -29,7 +29,7 @@ using namespace std; FlacEncoder::FlacEncoder(const std::string& codecOptions) : Encoder(codecOptions), encoder_(NULL), pcmBufferSize_(0), encodedSamples_(0) { flacChunk_ = new msg::PcmChunk(); - headerChunk_.reset(new msg::Header("flac")); + headerChunk_.reset(new msg::CodecHeader("flac")); pcmBuffer_ = (FLAC__int32*)malloc(pcmBufferSize_ * sizeof(FLAC__int32)); } diff --git a/server/encoder/oggEncoder.cpp b/server/encoder/oggEncoder.cpp index 38ad5b75..bcaa87f0 100644 --- a/server/encoder/oggEncoder.cpp +++ b/server/encoder/oggEncoder.cpp @@ -224,7 +224,7 @@ void OggEncoder::initEncoder() * audio data will start on a new page, as per spec */ size_t pos(0); - headerChunk_.reset(new msg::Header("ogg")); + headerChunk_.reset(new msg::CodecHeader("ogg")); while (true) { int result = ogg_stream_flush(&os,&og); diff --git a/server/encoder/pcmEncoder.cpp b/server/encoder/pcmEncoder.cpp index f91489d6..a1adb6a1 100644 --- a/server/encoder/pcmEncoder.cpp +++ b/server/encoder/pcmEncoder.cpp @@ -29,7 +29,7 @@ PcmEncoder::PcmEncoder(const std::string& codecOptions) : Encoder(codecOptions) { - headerChunk_.reset(new msg::Header("pcm")); + headerChunk_.reset(new msg::CodecHeader("pcm")); } diff --git a/server/snapServer.cpp b/server/snapServer.cpp index 336e55f5..dd63dce3 100644 --- a/server/snapServer.cpp +++ b/server/snapServer.cpp @@ -25,7 +25,7 @@ #include "common/timeDefs.h" #include "common/signalHandler.h" #include "common/snapException.h" -#include "message/sampleFormat.h" +#include "common/sampleFormat.h" #include "message/message.h" #include "encoder/encoderFactory.h" #include "streamServer.h" diff --git a/server/streamServer.cpp b/server/streamServer.cpp index a703c273..f3fe7f55 100644 --- a/server/streamServer.cpp +++ b/server/streamServer.cpp @@ -123,7 +123,7 @@ void StreamServer::onMessageReceived(ControlSession* controlSession, const std:: json response; ClientInfoPtr clientInfo = nullptr; msg::ServerSettings serverSettings; - serverSettings.bufferMs = settings_.bufferMs; + serverSettings.setBufferMs(settings_.bufferMs); if (request.method.find("Client.Set") == 0) { @@ -211,9 +211,9 @@ void StreamServer::onMessageReceived(ControlSession* controlSession, const std:: if (clientInfo != nullptr) { - serverSettings.volume = clientInfo->config.volume.percent; - serverSettings.muted = clientInfo->config.volume.muted; - serverSettings.latency = clientInfo->config.latency; + serverSettings.setVolume(clientInfo->config.volume.percent); + serverSettings.setMuted(clientInfo->config.volume.muted); + serverSettings.setLatency(clientInfo->config.latency); StreamSession* session = getStreamSession(request.getParam("client").get()); if (session != NULL) @@ -283,11 +283,11 @@ void StreamServer::onMessageReceived(StreamSession* connection, const msg::BaseM { logD << "request kServerSettings\n"; msg::ServerSettings serverSettings; - serverSettings.volume = clientInfo->config.volume.percent; - serverSettings.muted = clientInfo->config.volume.muted; - serverSettings.latency = clientInfo->config.latency; + serverSettings.setVolume(clientInfo->config.volume.percent); + serverSettings.setMuted(clientInfo->config.volume.muted); + serverSettings.setLatency(clientInfo->config.latency); + serverSettings.setBufferMs(settings_.bufferMs); serverSettings.refersTo = helloMsg.id; - serverSettings.bufferMs = settings_.bufferMs; connection->send(&serverSettings); } diff --git a/server/streamServer.h b/server/streamServer.h index 35f81c8f..f307e0df 100644 --- a/server/streamServer.h +++ b/server/streamServer.h @@ -30,9 +30,9 @@ #include "streamSession.h" #include "streamreader/streamManager.h" #include "common/queue.h" +#include "common/sampleFormat.h" #include "message/message.h" -#include "message/header.h" -#include "message/sampleFormat.h" +#include "message/codecHeader.h" #include "message/serverSettings.h" #include "controlServer.h" diff --git a/server/streamreader/pcmStream.cpp b/server/streamreader/pcmStream.cpp index 58256d33..f0d7e5bf 100644 --- a/server/streamreader/pcmStream.cpp +++ b/server/streamreader/pcmStream.cpp @@ -59,7 +59,7 @@ PcmStream::~PcmStream() } -std::shared_ptr PcmStream::getHeader() +std::shared_ptr PcmStream::getHeader() { return encoder_->getHeader(); } diff --git a/server/streamreader/pcmStream.h b/server/streamreader/pcmStream.h index b2459f8a..55171321 100644 --- a/server/streamreader/pcmStream.h +++ b/server/streamreader/pcmStream.h @@ -26,8 +26,8 @@ #include "streamUri.h" #include "encoder/encoder.h" #include "externals/json.hpp" -#include "message/sampleFormat.h" -#include "message/header.h" +#include "common/sampleFormat.h" +#include "message/codecHeader.h" class PcmStream; @@ -72,7 +72,7 @@ public: /// Implementation of EncoderListener::onChunkEncoded virtual void onChunkEncoded(const Encoder* encoder, msg::PcmChunk* chunk, double duration); - virtual std::shared_ptr getHeader(); + virtual std::shared_ptr getHeader(); virtual const StreamUri& getUri() const; virtual const std::string& getName() const;