modernize with clang-tidy

This commit is contained in:
badaix 2019-09-25 19:02:33 +02:00
parent e0d25d02ab
commit 8b231c7cc6
54 changed files with 182 additions and 196 deletions

View file

@ -27,10 +27,10 @@
#include <time.h> #include <time.h>
static AvahiSimplePoll* simple_poll = NULL; static AvahiSimplePoll* simple_poll = nullptr;
BrowseAvahi::BrowseAvahi() : client_(NULL), sb_(NULL) BrowseAvahi::BrowseAvahi() : client_(nullptr), sb_(nullptr)
{ {
} }
@ -45,15 +45,15 @@ void BrowseAvahi::cleanUp()
{ {
if (sb_) if (sb_)
avahi_service_browser_free(sb_); avahi_service_browser_free(sb_);
sb_ = NULL; sb_ = nullptr;
if (client_) if (client_)
avahi_client_free(client_); avahi_client_free(client_);
client_ = NULL; client_ = nullptr;
if (simple_poll) if (simple_poll)
avahi_simple_poll_free(simple_poll); avahi_simple_poll_free(simple_poll);
simple_poll = NULL; simple_poll = nullptr;
} }
@ -180,7 +180,7 @@ bool BrowseAvahi::browse(const std::string& serviceName, mDNSResult& result, int
/* Create the service browser */ /* Create the service browser */
if (!(sb_ = if (!(sb_ =
avahi_service_browser_new(client_, AVAHI_IF_UNSPEC, AVAHI_PROTO_INET, serviceName.c_str(), NULL, (AvahiLookupFlags)0, browse_callback, this))) avahi_service_browser_new(client_, AVAHI_IF_UNSPEC, AVAHI_PROTO_INET, serviceName.c_str(), nullptr, (AvahiLookupFlags)0, browse_callback, this)))
throw SnapException("BrowseAvahi - Failed to create service browser: " + std::string(avahi_strerror(avahi_client_errno(client_)))); throw SnapException("BrowseAvahi - Failed to create service browser: " + std::string(avahi_strerror(avahi_client_errno(client_))));
result_.valid = false; result_.valid = false;

View file

@ -29,7 +29,7 @@ using namespace std;
ClientConnection::ClientConnection(MessageReceiver* receiver, const std::string& host, size_t port) ClientConnection::ClientConnection(MessageReceiver* receiver, const std::string& host, size_t port)
: socket_(nullptr), active_(false), connected_(false), messageReceiver_(receiver), reqId_(1), host_(host), port_(port), readerThread_(NULL), : socket_(nullptr), active_(false), connected_(false), messageReceiver_(receiver), reqId_(1), host_(host), port_(port), readerThread_(nullptr),
sumTimeout_(chronos::msec(0)) sumTimeout_(chronos::msec(0))
{ {
} }
@ -116,7 +116,7 @@ void ClientConnection::stop()
catch (...) catch (...)
{ {
} }
readerThread_ = NULL; readerThread_ = nullptr;
socket_.reset(); socket_.reset();
LOG(DEBUG) << "readerThread terminated\n"; LOG(DEBUG) << "readerThread terminated\n";
} }
@ -142,7 +142,7 @@ bool ClientConnection::send(const msg::BaseMessage* message) const
shared_ptr<msg::SerializedMessage> ClientConnection::sendRequest(const msg::BaseMessage* message, const chronos::msec& timeout) shared_ptr<msg::SerializedMessage> ClientConnection::sendRequest(const msg::BaseMessage* message, const chronos::msec& timeout)
{ {
shared_ptr<msg::SerializedMessage> response(NULL); shared_ptr<msg::SerializedMessage> response(nullptr);
if (++reqId_ >= 10000) if (++reqId_ >= 10000)
reqId_ = 1; reqId_ = 1;
message->id = reqId_; message->id = reqId_;
@ -209,7 +209,7 @@ void ClientConnection::getNextMessage()
} }
} }
if (messageReceiver_ != NULL) if (messageReceiver_ != nullptr)
messageReceiver_->onMessageReceived(this, baseMessage, &buffer[0]); messageReceiver_->onMessageReceived(this, baseMessage, &buffer[0]);
} }
@ -226,7 +226,7 @@ void ClientConnection::reader()
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
if (messageReceiver_ != NULL) if (messageReceiver_ != nullptr)
messageReceiver_->onException(this, make_shared<SnapException>(e.what())); messageReceiver_->onException(this, make_shared<SnapException>(e.what()));
} }
catch (...) catch (...)

View file

@ -40,7 +40,7 @@ class ClientConnection;
/// Used to synchronize server requests (wait for server response) /// Used to synchronize server requests (wait for server response)
struct PendingRequest struct PendingRequest
{ {
PendingRequest(uint16_t reqId) : id(reqId), response(NULL){}; PendingRequest(uint16_t reqId) : id(reqId), response(nullptr){};
uint16_t id; uint16_t id;
std::shared_ptr<msg::SerializedMessage> response; std::shared_ptr<msg::SerializedMessage> response;
@ -87,7 +87,7 @@ public:
{ {
std::shared_ptr<msg::SerializedMessage> reply = sendRequest(message, timeout); std::shared_ptr<msg::SerializedMessage> reply = sendRequest(message, timeout);
if (!reply) if (!reply)
return NULL; return nullptr;
std::shared_ptr<T> msg(new T); std::shared_ptr<T> msg(new T);
msg->deserialize(reply->message, reply->buffer); msg->deserialize(reply->message, reply->buffer);
return msg; return msg;

View file

@ -57,7 +57,7 @@ void Controller::onMessageReceived(ClientConnection* connection, const msg::Base
{ {
if (stream_ && decoder_) if (stream_ && decoder_)
{ {
msg::PcmChunk* pcmChunk = new msg::PcmChunk(sampleFormat_, 0); auto* pcmChunk = new msg::PcmChunk(sampleFormat_, 0);
pcmChunk->deserialize(baseMessage, buffer); pcmChunk->deserialize(baseMessage, buffer);
// LOG(DEBUG) << "chunk: " << pcmChunk->payloadSize << ", sampleFormat: " << sampleFormat_.rate << "\n"; // LOG(DEBUG) << "chunk: " << pcmChunk->payloadSize << ", sampleFormat: " << sampleFormat_.rate << "\n";
if (decoder_->decode(pcmChunk)) if (decoder_->decode(pcmChunk))

View file

@ -54,11 +54,11 @@ public:
/// Implementation of MessageReceiver. /// Implementation of MessageReceiver.
/// ClientConnection passes messages from the server through these callbacks /// ClientConnection passes messages from the server through these callbacks
virtual void onMessageReceived(ClientConnection* connection, const msg::BaseMessage& baseMessage, char* buffer); void onMessageReceived(ClientConnection* connection, const msg::BaseMessage& baseMessage, char* buffer) override;
/// Implementation of MessageReceiver. /// Implementation of MessageReceiver.
/// Used for async exception reporting /// Used for async exception reporting
virtual void onException(ClientConnection* connection, shared_exception_ptr exception); void onException(ClientConnection* connection, shared_exception_ptr exception) override;
private: private:
void worker(); void worker();

View file

@ -28,7 +28,7 @@ class Decoder
{ {
public: public:
Decoder(){}; Decoder(){};
virtual ~Decoder(){}; virtual ~Decoder()= default;;
virtual bool decode(msg::PcmChunk* chunk) = 0; virtual bool decode(msg::PcmChunk* chunk) = 0;
virtual SampleFormat setHeader(msg::CodecHeader* chunk) = 0; virtual SampleFormat setHeader(msg::CodecHeader* chunk) = 0;

View file

@ -35,11 +35,11 @@ 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 void error_callback(const FLAC__StreamDecoder* decoder, FLAC__StreamDecoderErrorStatus status, void* client_data);
static msg::CodecHeader* flacHeader = NULL; static msg::CodecHeader* flacHeader = nullptr;
static msg::PcmChunk* flacChunk = NULL; static msg::PcmChunk* flacChunk = nullptr;
static msg::PcmChunk* pcmChunk = NULL; static msg::PcmChunk* pcmChunk = nullptr;
static SampleFormat sampleFormat; static SampleFormat sampleFormat;
static FLAC__StreamDecoder* decoder = NULL; static FLAC__StreamDecoder* decoder = nullptr;
@ -101,11 +101,11 @@ SampleFormat FlacDecoder::setHeader(msg::CodecHeader* chunk)
flacHeader = chunk; flacHeader = chunk;
FLAC__StreamDecoderInitStatus init_status; FLAC__StreamDecoderInitStatus init_status;
if ((decoder = FLAC__stream_decoder_new()) == NULL) if ((decoder = FLAC__stream_decoder_new()) == nullptr)
throw SnapException("ERROR: allocating decoder"); throw SnapException("ERROR: allocating decoder");
// (void)FLAC__stream_decoder_set_md5_checking(decoder, true); // (void)FLAC__stream_decoder_set_md5_checking(decoder, true);
init_status = FLAC__stream_decoder_init_stream(decoder, read_callback, NULL, NULL, NULL, NULL, write_callback, metadata_callback, error_callback, this); init_status = FLAC__stream_decoder_init_stream(decoder, read_callback, nullptr, nullptr, nullptr, nullptr, write_callback, metadata_callback, error_callback, this);
if (init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK) if (init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK)
throw SnapException("ERROR: initializing decoder: " + string(FLAC__StreamDecoderInitStatusString[init_status])); throw SnapException("ERROR: initializing decoder: " + string(FLAC__StreamDecoderInitStatusString[init_status]));
@ -120,13 +120,13 @@ SampleFormat FlacDecoder::setHeader(msg::CodecHeader* chunk)
FLAC__StreamDecoderReadStatus read_callback(const FLAC__StreamDecoder* decoder, FLAC__byte buffer[], size_t* bytes, void* client_data) FLAC__StreamDecoderReadStatus read_callback(const FLAC__StreamDecoder* decoder, FLAC__byte buffer[], size_t* bytes, void* client_data)
{ {
if (flacHeader != NULL) if (flacHeader != nullptr)
{ {
*bytes = flacHeader->payloadSize; *bytes = flacHeader->payloadSize;
memcpy(buffer, flacHeader->payload, *bytes); memcpy(buffer, flacHeader->payload, *bytes);
flacHeader = NULL; flacHeader = nullptr;
} }
else if (flacChunk != NULL) else if (flacChunk != nullptr)
{ {
// cerr << "read_callback: " << *bytes << ", avail: " << flacChunk->payloadSize << "\n"; // cerr << "read_callback: " << *bytes << ", avail: " << flacChunk->payloadSize << "\n";
static_cast<FlacDecoder*>(client_data)->cacheInfo_.isCachedChunk_ = false; static_cast<FlacDecoder*>(client_data)->cacheInfo_.isCachedChunk_ = false;
@ -150,7 +150,7 @@ FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder* decoder
{ {
(void)decoder; (void)decoder;
if (pcmChunk != NULL) if (pcmChunk != nullptr)
{ {
size_t bytes = frame->header.blocksize * sampleFormat.frameSize; size_t bytes = frame->header.blocksize * sampleFormat.frameSize;
@ -162,7 +162,7 @@ FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder* decoder
for (size_t channel = 0; channel < sampleFormat.channels; ++channel) for (size_t channel = 0; channel < sampleFormat.channels; ++channel)
{ {
if (buffer[channel] == NULL) if (buffer[channel] == nullptr)
{ {
SLOG(ERROR) << "ERROR: buffer[" << channel << "] is NULL\n"; SLOG(ERROR) << "ERROR: buffer[" << channel << "] is NULL\n";
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;

View file

@ -50,9 +50,9 @@ class FlacDecoder : public Decoder
{ {
public: public:
FlacDecoder(); FlacDecoder();
virtual ~FlacDecoder(); ~FlacDecoder() override;
virtual bool decode(msg::PcmChunk* chunk); bool decode(msg::PcmChunk* chunk) override;
virtual SampleFormat setHeader(msg::CodecHeader* chunk); SampleFormat setHeader(msg::CodecHeader* chunk) override;
CacheInfo cacheInfo_; CacheInfo cacheInfo_;
std::unique_ptr<FLAC__StreamDecoderErrorStatus> lastError_; std::unique_ptr<FLAC__StreamDecoderErrorStatus> lastError_;

View file

@ -30,9 +30,9 @@ class OggDecoder : public Decoder
{ {
public: public:
OggDecoder(); OggDecoder();
virtual ~OggDecoder(); ~OggDecoder() override;
virtual bool decode(msg::PcmChunk* chunk); bool decode(msg::PcmChunk* chunk) override;
virtual SampleFormat setHeader(msg::CodecHeader* chunk); SampleFormat setHeader(msg::CodecHeader* chunk) override;
private: private:
bool decodePayload(msg::PcmChunk* chunk); bool decodePayload(msg::PcmChunk* chunk);

View file

@ -25,8 +25,8 @@ class PcmDecoder : public Decoder
{ {
public: public:
PcmDecoder(); PcmDecoder();
virtual bool decode(msg::PcmChunk* chunk); bool decode(msg::PcmChunk* chunk) override;
virtual SampleFormat setHeader(msg::CodecHeader* chunk); SampleFormat setHeader(msg::CodecHeader* chunk) override;
}; };

View file

@ -93,7 +93,7 @@ class MetaStderrAdapter : public MetadataAdapter
public: public:
using MetadataAdapter::push; using MetadataAdapter::push;
int push() int push() override
{ {
std::cerr << serialize() << "\n"; std::cerr << serialize() << "\n";
return 0; return 0;

View file

@ -26,7 +26,7 @@
using namespace std; using namespace std;
AlsaPlayer::AlsaPlayer(const PcmDevice& pcmDevice, std::shared_ptr<Stream> stream) : Player(pcmDevice, stream), handle_(NULL), buff_(NULL) AlsaPlayer::AlsaPlayer(const PcmDevice& pcmDevice, std::shared_ptr<Stream> stream) : Player(pcmDevice, stream), handle_(nullptr), buff_(nullptr)
{ {
} }
@ -105,18 +105,18 @@ void AlsaPlayer::initAlsa()
if ((pcm = snd_pcm_hw_params_set_channels(handle_, params, channels)) < 0) if ((pcm = snd_pcm_hw_params_set_channels(handle_, params, channels)) < 0)
throw SnapException("Can't set channels number: " + string(snd_strerror(pcm))); throw SnapException("Can't set channels number: " + string(snd_strerror(pcm)));
if ((pcm = snd_pcm_hw_params_set_rate_near(handle_, params, &rate, 0)) < 0) if ((pcm = snd_pcm_hw_params_set_rate_near(handle_, params, &rate, nullptr)) < 0)
throw SnapException("Can't set rate: " + string(snd_strerror(pcm))); throw SnapException("Can't set rate: " + string(snd_strerror(pcm)));
unsigned int period_time; unsigned int period_time;
snd_pcm_hw_params_get_period_time_max(params, &period_time, 0); snd_pcm_hw_params_get_period_time_max(params, &period_time, nullptr);
if (period_time > PERIOD_TIME) if (period_time > PERIOD_TIME)
period_time = PERIOD_TIME; period_time = PERIOD_TIME;
unsigned int buffer_time = 4 * period_time; unsigned int buffer_time = 4 * period_time;
snd_pcm_hw_params_set_period_time_near(handle_, params, &period_time, 0); snd_pcm_hw_params_set_period_time_near(handle_, params, &period_time, nullptr);
snd_pcm_hw_params_set_buffer_time_near(handle_, params, &buffer_time, 0); snd_pcm_hw_params_set_buffer_time_near(handle_, params, &buffer_time, nullptr);
// long unsigned int periodsize = stream_->format.msRate() * 50;//2*rate/50; // long unsigned int periodsize = stream_->format.msRate() * 50;//2*rate/50;
// if ((pcm = snd_pcm_hw_params_set_buffer_size_near(pcm_handle, params, &periodsize)) < 0) // if ((pcm = snd_pcm_hw_params_set_buffer_size_near(pcm_handle, params, &periodsize)) < 0)
@ -132,17 +132,17 @@ void AlsaPlayer::initAlsa()
snd_pcm_hw_params_get_channels(params, &tmp); snd_pcm_hw_params_get_channels(params, &tmp);
LOG(DEBUG) << "channels: " << tmp << "\n"; LOG(DEBUG) << "channels: " << tmp << "\n";
snd_pcm_hw_params_get_rate(params, &tmp, 0); snd_pcm_hw_params_get_rate(params, &tmp, nullptr);
LOG(DEBUG) << "rate: " << tmp << " bps\n"; LOG(DEBUG) << "rate: " << tmp << " bps\n";
/* Allocate buffer to hold single period */ /* Allocate buffer to hold single period */
snd_pcm_hw_params_get_period_size(params, &frames_, 0); snd_pcm_hw_params_get_period_size(params, &frames_, nullptr);
LOG(INFO) << "frames: " << frames_ << "\n"; LOG(INFO) << "frames: " << frames_ << "\n";
buff_size = frames_ * format.frameSize; // channels * 2 /* 2 -> sample size */; buff_size = frames_ * format.frameSize; // channels * 2 /* 2 -> sample size */;
buff_ = (char*)malloc(buff_size); buff_ = (char*)malloc(buff_size);
snd_pcm_hw_params_get_period_time(params, &tmp, NULL); snd_pcm_hw_params_get_period_time(params, &tmp, nullptr);
LOG(DEBUG) << "period time: " << tmp << "\n"; LOG(DEBUG) << "period time: " << tmp << "\n";
snd_pcm_sw_params_t* swparams; snd_pcm_sw_params_t* swparams;
@ -158,17 +158,17 @@ void AlsaPlayer::initAlsa()
void AlsaPlayer::uninitAlsa() void AlsaPlayer::uninitAlsa()
{ {
if (handle_ != NULL) if (handle_ != nullptr)
{ {
snd_pcm_drain(handle_); snd_pcm_drain(handle_);
snd_pcm_close(handle_); snd_pcm_close(handle_);
handle_ = NULL; handle_ = nullptr;
} }
if (buff_ != NULL) if (buff_ != nullptr)
{ {
free(buff_); free(buff_);
buff_ = NULL; buff_ = nullptr;
} }
} }
@ -201,7 +201,7 @@ void AlsaPlayer::worker()
while (active_) while (active_)
{ {
if (handle_ == NULL) if (handle_ == nullptr)
{ {
try try
{ {
@ -240,7 +240,7 @@ void AlsaPlayer::worker()
while (active_ && !stream_->waitForChunk(100)) while (active_ && !stream_->waitForChunk(100))
{ {
LOG(DEBUG) << "Waiting for chunk\n"; LOG(DEBUG) << "Waiting for chunk\n";
if ((handle_ != NULL) && (chronos::getTickCount() - lastChunkTick > 5000)) if ((handle_ != nullptr) && (chronos::getTickCount() - lastChunkTick > 5000))
{ {
LOG(NOTICE) << "No chunk received for 5000ms. Closing ALSA.\n"; LOG(NOTICE) << "No chunk received for 5000ms. Closing ALSA.\n";
uninitAlsa(); uninitAlsa();
@ -253,7 +253,7 @@ void AlsaPlayer::worker()
vector<PcmDevice> AlsaPlayer::pcm_list(void) vector<PcmDevice> AlsaPlayer::pcm_list()
{ {
void **hints, **n; void **hints, **n;
char *name, *descr, *io; char *name, *descr, *io;
@ -264,15 +264,15 @@ vector<PcmDevice> AlsaPlayer::pcm_list(void)
return result; return result;
n = hints; n = hints;
size_t idx(0); size_t idx(0);
while (*n != NULL) while (*n != nullptr)
{ {
name = snd_device_name_get_hint(*n, "NAME"); name = snd_device_name_get_hint(*n, "NAME");
descr = snd_device_name_get_hint(*n, "DESC"); descr = snd_device_name_get_hint(*n, "DESC");
io = snd_device_name_get_hint(*n, "IOID"); io = snd_device_name_get_hint(*n, "IOID");
if (io != NULL && strcmp(io, "Output") != 0) if (io != nullptr && strcmp(io, "Output") != 0)
goto __end; goto __end;
pcmDevice.name = name; pcmDevice.name = name;
if (descr == NULL) if (descr == nullptr)
{ {
pcmDevice.description = ""; pcmDevice.description = "";
} }
@ -284,11 +284,11 @@ vector<PcmDevice> AlsaPlayer::pcm_list(void)
result.push_back(pcmDevice); result.push_back(pcmDevice);
__end: __end:
if (name != NULL) if (name != nullptr)
free(name); free(name);
if (descr != NULL) if (descr != nullptr)
free(descr); free(descr);
if (io != NULL) if (io != nullptr)
free(io); free(io);
n++; n++;
} }

View file

@ -31,17 +31,17 @@ class AlsaPlayer : public Player
{ {
public: public:
AlsaPlayer(const PcmDevice& pcmDevice, std::shared_ptr<Stream> stream); AlsaPlayer(const PcmDevice& pcmDevice, std::shared_ptr<Stream> stream);
virtual ~AlsaPlayer(); ~AlsaPlayer() override;
/// Set audio volume in range [0..1] /// Set audio volume in range [0..1]
virtual void start(); void start() override;
virtual void stop(); void stop() override;
/// List the system's audio output devices /// List the system's audio output devices
static std::vector<PcmDevice> pcm_list(void); static std::vector<PcmDevice> pcm_list(void);
protected: protected:
virtual void worker(); void worker() override;
private: private:
void initAlsa(); void initAlsa();

View file

@ -262,7 +262,7 @@ bool Stream::getPlayerChunk(void* outputBuffer, const cs::usec& outputBufferDacT
if (!chunks_.try_pop(chunk_, outputBufferDacTime)) if (!chunks_.try_pop(chunk_, outputBufferDacTime))
{ {
LOG(INFO) << "no chunks available\n"; LOG(INFO) << "no chunks available\n";
chunk_ = NULL; chunk_ = nullptr;
sleep_ = cs::usec(0); sleep_ = cs::usec(0);
return false; return false;
} }
@ -362,7 +362,7 @@ else if (miniBuffer_.full() && (cs::usec(abs(miniBuffer_.median())) > cs::msec(5
updateBuffers(age.count()); updateBuffers(age.count());
// print sync stats // print sync stats
time_t now = time(NULL); time_t now = time(nullptr);
if (now != lastUpdate_) if (now != lastUpdate_)
{ {
lastUpdate_ = now; lastUpdate_ = now;

View file

@ -35,18 +35,18 @@ public:
payload = (char*)malloc(size); payload = (char*)malloc(size);
} }
virtual ~CodecHeader() ~CodecHeader() override
{ {
free(payload); free(payload);
} }
virtual void read(std::istream& stream) void read(std::istream& stream) override
{ {
readVal(stream, codec); readVal(stream, codec);
readVal(stream, &payload, payloadSize); readVal(stream, &payload, payloadSize);
} }
virtual uint32_t getSize() const uint32_t getSize() const override
{ {
return sizeof(uint32_t) + codec.size() + sizeof(uint32_t) + payloadSize; return sizeof(uint32_t) + codec.size() + sizeof(uint32_t) + payloadSize;
} }
@ -56,7 +56,7 @@ public:
std::string codec; std::string codec;
protected: protected:
virtual void doserialize(std::ostream& stream) const void doserialize(std::ostream& stream) const override
{ {
writeVal(stream, codec); writeVal(stream, codec);
writeVal(stream, payload, payloadSize); writeVal(stream, payload, payloadSize);

View file

@ -48,9 +48,8 @@ public:
msg["SnapStreamProtocolVersion"] = 2; msg["SnapStreamProtocolVersion"] = 2;
} }
virtual ~Hello() ~Hello() override
{ = default;
}
std::string getMacAddress() const std::string getMacAddress() const
{ {

View file

@ -36,18 +36,17 @@ public:
{ {
} }
virtual ~JsonMessage() ~JsonMessage() override
{ = default;
}
virtual void read(std::istream& stream) void read(std::istream& stream) override
{ {
std::string s; std::string s;
readVal(stream, s); readVal(stream, s);
msg = json::parse(s); msg = json::parse(s);
} }
virtual uint32_t getSize() const uint32_t getSize() const override
{ {
return sizeof(uint32_t) + msg.dump().size(); return sizeof(uint32_t) + msg.dump().size();
} }
@ -56,7 +55,7 @@ public:
protected: protected:
virtual void doserialize(std::ostream& stream) const void doserialize(std::ostream& stream) const override
{ {
writeVal(stream, msg.dump()); writeVal(stream, msg.dump());
} }

View file

@ -127,8 +127,7 @@ struct BaseMessage
} }
virtual ~BaseMessage() virtual ~BaseMessage()
{ = default;
}
virtual void read(std::istream& stream) virtual void read(std::istream& stream)
{ {

View file

@ -48,9 +48,8 @@ public:
{ {
} }
virtual ~PcmChunk() ~PcmChunk() override
{ = default;
}
int readFrames(void* outputBuffer, size_t frameCount) int readFrames(void* outputBuffer, size_t frameCount)
{ {
@ -60,7 +59,7 @@ public:
result = (payloadSize / format.frameSize) - idx_; result = (payloadSize / format.frameSize) - idx_;
// logd << ", from: " << format.frameSize*idx << ", to: " << format.frameSize*idx + format.frameSize*result; // logd << ", from: " << format.frameSize*idx << ", to: " << format.frameSize*idx + format.frameSize*result;
if (outputBuffer != NULL) if (outputBuffer != nullptr)
memcpy((char*)outputBuffer, (char*)(payload) + format.frameSize * idx_, format.frameSize * result); memcpy((char*)outputBuffer, (char*)(payload) + format.frameSize * idx_, format.frameSize * result);
idx_ += result; idx_ += result;
@ -82,7 +81,7 @@ public:
} }
virtual chronos::time_point_clk start() const chronos::time_point_clk start() const override
{ {
return chronos::time_point_clk(chronos::sec(timestamp.sec) + chronos::usec(timestamp.usec) + return chronos::time_point_clk(chronos::sec(timestamp.sec) + chronos::usec(timestamp.usec) +
chronos::usec((chronos::usec::rep)(1000000. * ((double)idx_ / (double)format.rate)))); chronos::usec((chronos::usec::rep)(1000000. * ((double)idx_ / (double)format.rate))));

View file

@ -36,9 +36,8 @@ public:
setMuted(false); setMuted(false);
} }
virtual ~ServerSettings() ~ServerSettings() override
{ = default;
}
int32_t getBufferMs() int32_t getBufferMs()
{ {

View file

@ -65,9 +65,8 @@ public:
{ {
} }
virtual ~StreamTags() ~StreamTags() override
{ = default;
}
}; };
} }

View file

@ -31,17 +31,16 @@ public:
{ {
} }
virtual ~Time() ~Time() override
{ = default;
}
virtual void read(std::istream& stream) void read(std::istream& stream) override
{ {
readVal(stream, latency.sec); readVal(stream, latency.sec);
readVal(stream, latency.usec); readVal(stream, latency.usec);
} }
virtual uint32_t getSize() const uint32_t getSize() const override
{ {
return sizeof(tv); return sizeof(tv);
} }
@ -49,7 +48,7 @@ public:
tv latency; tv latency;
protected: protected:
virtual void doserialize(std::ostream& stream) const void doserialize(std::ostream& stream) const override
{ {
writeVal(stream, latency.sec); writeVal(stream, latency.sec);
writeVal(stream, latency.usec); writeVal(stream, latency.usec);

View file

@ -50,19 +50,19 @@ public:
memcpy(payload, wireChunk.payload, payloadSize); memcpy(payload, wireChunk.payload, payloadSize);
} }
virtual ~WireChunk() ~WireChunk() override
{ {
free(payload); free(payload);
} }
virtual void read(std::istream& stream) void read(std::istream& stream) override
{ {
readVal(stream, timestamp.sec); readVal(stream, timestamp.sec);
readVal(stream, timestamp.usec); readVal(stream, timestamp.usec);
readVal(stream, &payload, payloadSize); readVal(stream, &payload, payloadSize);
} }
virtual uint32_t getSize() const uint32_t getSize() const override
{ {
return sizeof(tv) + sizeof(int32_t) + payloadSize; return sizeof(tv) + sizeof(int32_t) + payloadSize;
} }
@ -77,7 +77,7 @@ public:
char* payload; char* payload;
protected: protected:
virtual void doserialize(std::ostream& stream) const void doserialize(std::ostream& stream) const override
{ {
writeVal(stream, timestamp.sec); writeVal(stream, timestamp.sec);
writeVal(stream, timestamp.usec); writeVal(stream, timestamp.usec);

View file

@ -31,8 +31,7 @@ using namespace std;
SampleFormat::SampleFormat() SampleFormat::SampleFormat()
{ = default;
}
SampleFormat::SampleFormat(const std::string& format) SampleFormat::SampleFormat(const std::string& format)

View file

@ -43,12 +43,12 @@ public:
{ {
} }
virtual ~SnapException() throw() ~SnapException() throw() override
{ {
delete[] text_; delete[] text_;
} }
virtual const char* what() const noexcept const char* what() const noexcept override
{ {
return text_; return text_;
} }
@ -72,9 +72,8 @@ public:
} }
virtual ~AsyncSnapException() throw() ~AsyncSnapException() throw() override
{ = default;
}
}; };

View file

@ -47,7 +47,7 @@ inline static void timeofday(struct timeval* tv)
inline static void systemtimeofday(struct timeval* tv) inline static void systemtimeofday(struct timeval* tv)
{ {
gettimeofday(tv, NULL); gettimeofday(tv, nullptr);
// timeofday<std::chrono::system_clock>(tv); // timeofday<std::chrono::system_clock>(tv);
} }

View file

@ -69,7 +69,7 @@ static std::string execGetOutput(const std::string& cmd)
std::string result = ""; std::string result = "";
while (!feof(pipe.get())) while (!feof(pipe.get()))
{ {
if (fgets(buffer, 1024, pipe.get()) != NULL) if (fgets(buffer, 1024, pipe.get()) != nullptr)
result += buffer; result += buffer;
} }
return strutils::trim(result); return strutils::trim(result);
@ -182,7 +182,7 @@ static std::string generateUUID()
static bool initialized(false); static bool initialized(false);
if (!initialized) if (!initialized)
{ {
std::srand(std::time(0)); std::srand(std::time(nullptr));
initialized = true; initialized = true;
} }
std::stringstream ss; std::stringstream ss;

View file

@ -54,7 +54,7 @@ static void do_chown(const std::string& file_path, const std::string& user_name,
if (!user_name.empty()) if (!user_name.empty())
{ {
struct passwd* pwd = getpwnam(user_name.c_str()); struct passwd* pwd = getpwnam(user_name.c_str());
if (pwd == NULL) if (pwd == nullptr)
throw std::runtime_error("Failed to get uid"); throw std::runtime_error("Failed to get uid");
uid = pwd->pw_uid; uid = pwd->pw_uid;
} }
@ -62,7 +62,7 @@ static void do_chown(const std::string& file_path, const std::string& user_name,
if (!group_name.empty()) if (!group_name.empty())
{ {
struct group* grp = getgrnam(group_name.c_str()); struct group* grp = getgrnam(group_name.c_str());
if (grp == NULL) if (grp == nullptr)
throw std::runtime_error("Failed to get gid"); throw std::runtime_error("Failed to get gid");
gid = grp->gr_gid; gid = grp->gr_gid;
} }

View file

@ -46,7 +46,7 @@ void Config::init(const std::string& root_directory, const std::string& user, co
string dir; string dir;
if (!root_directory.empty()) if (!root_directory.empty())
dir = root_directory; dir = root_directory;
else if (getenv("HOME") == NULL) else if (getenv("HOME") == nullptr)
dir = "/var/lib/snapserver/"; dir = "/var/lib/snapserver/";
else else
dir = getenv("HOME"); dir = getenv("HOME");
@ -97,10 +97,10 @@ void Config::init(const std::string& root_directory, const std::string& user, co
if (j.count("ConfigVersion")) if (j.count("ConfigVersion"))
{ {
json jGroups = j["Groups"]; json jGroups = j["Groups"];
for (auto it = jGroups.begin(); it != jGroups.end(); ++it) for (auto & jGroup : jGroups)
{ {
GroupPtr group = make_shared<Group>(); GroupPtr group = make_shared<Group>();
group->fromJson(*it); group->fromJson(jGroup);
// if (client->id.empty() || getClientInfo(client->id)) // if (client->id.empty() || getClientInfo(client->id))
// continue; // continue;
groups.push_back(group); groups.push_back(group);

View file

@ -161,8 +161,7 @@ struct Snapcast
} }
virtual ~Snapcast() virtual ~Snapcast()
{ = default;
}
virtual void fromJson(const json& j) virtual void fromJson(const json& j)
{ {
@ -200,13 +199,13 @@ struct Snapserver : public Snapcast
{ {
} }
virtual void fromJson(const json& j) void fromJson(const json& j) override
{ {
Snapcast::fromJson(j); Snapcast::fromJson(j);
controlProtocolVersion = jGet<int>(j, "controlProtocolVersion", 1); controlProtocolVersion = jGet<int>(j, "controlProtocolVersion", 1);
} }
virtual json toJson() json toJson() override
{ {
json j = Snapcast::toJson(); json j = Snapcast::toJson();
j["controlProtocolVersion"] = controlProtocolVersion; j["controlProtocolVersion"] = controlProtocolVersion;

View file

@ -94,7 +94,7 @@ void ControlServer::onMessageReceived(ControlSession* connection, const std::str
} }
else else
{ {
if (controlMessageReceiver_ != NULL) if (controlMessageReceiver_ != nullptr)
controlMessageReceiver_->onMessageReceived(connection, message); controlMessageReceiver_->onMessageReceived(connection, message);
} }
} }

View file

@ -46,17 +46,17 @@ typedef std::shared_ptr<tcp::socket> socket_ptr;
class ControlServer : public ControlMessageReceiver class ControlServer : public ControlMessageReceiver
{ {
public: public:
ControlServer(asio::io_service* io_service, size_t port, ControlMessageReceiver* controlMessageReceiver = NULL); ControlServer(asio::io_service* io_service, size_t port, ControlMessageReceiver* controlMessageReceiver = nullptr);
virtual ~ControlServer(); virtual ~ControlServer();
void start(); void start();
void stop(); void stop();
/// Send a message to all connceted clients /// Send a message to all connceted clients
void send(const std::string& message, const ControlSession* excludeSession = NULL); void send(const std::string& message, const ControlSession* excludeSession = nullptr);
/// Clients call this when they receive a message. Implementation of MessageReceiver::onMessageReceived /// Clients call this when they receive a message. Implementation of MessageReceiver::onMessageReceived
virtual void onMessageReceived(ControlSession* connection, const std::string& message); void onMessageReceived(ControlSession* connection, const std::string& message) override;
private: private:
void startAccept(); void startAccept();

View file

@ -82,7 +82,7 @@ void ControlSession::stop()
catch (...) catch (...)
{ {
} }
socket_ = NULL; socket_ = nullptr;
LOG(DEBUG) << "ControlSession ControlSession stopped\n"; LOG(DEBUG) << "ControlSession ControlSession stopped\n";
} }
@ -137,7 +137,7 @@ void ControlSession::reader()
if ((len >= 2) && line[len - 2] == '\r') if ((len >= 2) && line[len - 2] == '\r')
--len; --len;
line.resize(len); line.resize(len);
if ((messageReceiver_ != NULL) && !line.empty()) if ((messageReceiver_ != nullptr) && !line.empty())
messageReceiver_->onMessageReceived(this, line); messageReceiver_->onMessageReceived(this, line);
} }
message.str(""); message.str("");

View file

@ -50,13 +50,12 @@ class Encoder
{ {
public: public:
/// ctor. Codec options (E.g. compression level) are passed as string and are codec dependend /// ctor. Codec options (E.g. compression level) are passed as string and are codec dependend
Encoder(const std::string& codecOptions = "") : headerChunk_(NULL), codecOptions_(codecOptions) Encoder(const std::string& codecOptions = "") : headerChunk_(nullptr), codecOptions_(codecOptions)
{ {
} }
virtual ~Encoder() virtual ~Encoder()
{ = default;
}
/// The listener will receive the encoded stream /// The listener will receive the encoded stream
virtual void init(EncoderListener* listener, const SampleFormat& format) virtual void init(EncoderListener* listener, const SampleFormat& format)

View file

@ -26,7 +26,7 @@
using namespace std; using namespace std;
FlacEncoder::FlacEncoder(const std::string& codecOptions) : Encoder(codecOptions), encoder_(NULL), pcmBufferSize_(0), encodedSamples_(0) FlacEncoder::FlacEncoder(const std::string& codecOptions) : Encoder(codecOptions), encoder_(nullptr), pcmBufferSize_(0), encodedSamples_(0)
{ {
flacChunk_ = new msg::PcmChunk(); flacChunk_ = new msg::PcmChunk();
headerChunk_.reset(new msg::CodecHeader("flac")); headerChunk_.reset(new msg::CodecHeader("flac"));
@ -36,7 +36,7 @@ FlacEncoder::FlacEncoder(const std::string& codecOptions) : Encoder(codecOptions
FlacEncoder::~FlacEncoder() FlacEncoder::~FlacEncoder()
{ {
if (encoder_ != NULL) if (encoder_ != nullptr)
{ {
FLAC__stream_encoder_finish(encoder_); FLAC__stream_encoder_finish(encoder_);
FLAC__metadata_object_delete(metadata_[0]); FLAC__metadata_object_delete(metadata_[0]);
@ -163,7 +163,7 @@ void FlacEncoder::initEncoder()
FLAC__StreamMetadata_VorbisComment_Entry entry; FLAC__StreamMetadata_VorbisComment_Entry entry;
// allocate the encoder // allocate the encoder
if ((encoder_ = FLAC__stream_encoder_new()) == NULL) if ((encoder_ = FLAC__stream_encoder_new()) == nullptr)
throw SnapException("error allocating encoder"); throw SnapException("error allocating encoder");
ok &= FLAC__stream_encoder_set_verify(encoder_, true); ok &= FLAC__stream_encoder_set_verify(encoder_, true);
@ -181,8 +181,8 @@ void FlacEncoder::initEncoder()
throw SnapException("error setting up encoder"); throw SnapException("error setting up encoder");
// now add some metadata; we'll add some tags and a padding block // now add some metadata; we'll add some tags and a padding block
if ((metadata_[0] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT)) == NULL || if ((metadata_[0] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT)) == nullptr ||
(metadata_[1] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING)) == NULL || (metadata_[1] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING)) == nullptr ||
// there are many tag (vorbiscomment) functions but these are convenient for this particular use: // there are many tag (vorbiscomment) functions but these are convenient for this particular use:
!FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(&entry, "TITLE", "SnapStream") || !FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(&entry, "TITLE", "SnapStream") ||
!FLAC__metadata_object_vorbiscomment_append_comment(metadata_[0], entry, false) || !FLAC__metadata_object_vorbiscomment_append_comment(metadata_[0], entry, false) ||
@ -196,7 +196,7 @@ void FlacEncoder::initEncoder()
throw SnapException("error setting meta data"); throw SnapException("error setting meta data");
// initialize encoder // initialize encoder
init_status = FLAC__stream_encoder_init_stream(encoder_, ::write_callback, NULL, NULL, NULL, this); init_status = FLAC__stream_encoder_init_stream(encoder_, ::write_callback, nullptr, nullptr, nullptr, this);
if (init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) if (init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
throw SnapException("ERROR: initializing encoder: " + string(FLAC__StreamEncoderInitStatusString[init_status])); throw SnapException("ERROR: initializing encoder: " + string(FLAC__StreamEncoderInitStatusString[init_status]));
} }

View file

@ -31,17 +31,17 @@ class FlacEncoder : public Encoder
{ {
public: public:
FlacEncoder(const std::string& codecOptions = ""); FlacEncoder(const std::string& codecOptions = "");
~FlacEncoder(); ~FlacEncoder() override;
virtual void encode(const msg::PcmChunk* chunk); void encode(const msg::PcmChunk* chunk) override;
virtual std::string getAvailableOptions() const; std::string getAvailableOptions() const override;
virtual std::string getDefaultOptions() const; std::string getDefaultOptions() const override;
virtual std::string name() const; std::string name() const override;
FLAC__StreamEncoderWriteStatus write_callback(const FLAC__StreamEncoder* encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__StreamEncoderWriteStatus write_callback(const FLAC__StreamEncoder* encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples,
unsigned current_frame); unsigned current_frame);
protected: protected:
virtual void initEncoder(); void initEncoder() override;
FLAC__StreamEncoder* encoder_; FLAC__StreamEncoder* encoder_;
FLAC__StreamMetadata* metadata_[2]; FLAC__StreamMetadata* metadata_[2];

View file

@ -86,7 +86,7 @@ void OggEncoder::encode(const msg::PcmChunk* chunk)
/* tell the library how much we actually submitted */ /* tell the library how much we actually submitted */
vorbis_analysis_wrote(&vd_, frames); vorbis_analysis_wrote(&vd_, frames);
msg::PcmChunk* oggChunk = new msg::PcmChunk(chunk->format, 0); auto* oggChunk = new msg::PcmChunk(chunk->format, 0);
/* vorbis does some data preanalysis, then divvies up blocks for /* vorbis does some data preanalysis, then divvies up blocks for
more involved (potentially parallel) processing. Get a single more involved (potentially parallel) processing. Get a single
@ -95,7 +95,7 @@ void OggEncoder::encode(const msg::PcmChunk* chunk)
while (vorbis_analysis_blockout(&vd_, &vb_) == 1) while (vorbis_analysis_blockout(&vd_, &vb_) == 1)
{ {
/* analysis, assume we want to use bitrate management */ /* analysis, assume we want to use bitrate management */
vorbis_analysis(&vb_, NULL); vorbis_analysis(&vb_, nullptr);
vorbis_bitrate_addblock(&vb_); vorbis_bitrate_addblock(&vb_);
while (vorbis_bitrate_flushpacket(&vd_, &op_)) while (vorbis_bitrate_flushpacket(&vd_, &op_))
@ -219,7 +219,7 @@ void OggEncoder::initEncoder()
/* set up our packet->stream encoder */ /* set up our packet->stream encoder */
/* pick a random serial number; that way we can more likely build /* pick a random serial number; that way we can more likely build
chained streams just by concatenation */ chained streams just by concatenation */
srand(time(NULL)); srand(time(nullptr));
ogg_stream_init(&os_, rand()); ogg_stream_init(&os_, rand());
/* Vorbis streams begin with three headers; the initial header (with /* Vorbis streams begin with three headers; the initial header (with

View file

@ -26,13 +26,13 @@ class OggEncoder : public Encoder
{ {
public: public:
OggEncoder(const std::string& codecOptions = ""); OggEncoder(const std::string& codecOptions = "");
virtual void encode(const msg::PcmChunk* chunk); void encode(const msg::PcmChunk* chunk) override;
virtual std::string getAvailableOptions() const; std::string getAvailableOptions() const override;
virtual std::string getDefaultOptions() const; std::string getDefaultOptions() const override;
virtual std::string name() const; std::string name() const override;
protected: protected:
virtual void initEncoder(); void initEncoder() override;
private: private:
ogg_stream_state os_; /// take physical pages, weld into a logical stream of packets ogg_stream_state os_; /// take physical pages, weld into a logical stream of packets

View file

@ -35,7 +35,7 @@ PcmEncoder::PcmEncoder(const std::string& codecOptions) : Encoder(codecOptions)
void PcmEncoder::encode(const msg::PcmChunk* chunk) void PcmEncoder::encode(const msg::PcmChunk* chunk)
{ {
msg::PcmChunk* pcmChunk = new msg::PcmChunk(*chunk); auto* pcmChunk = new msg::PcmChunk(*chunk);
listener_->onChunkEncoded(this, pcmChunk, pcmChunk->duration<chronos::msec>().count()); listener_->onChunkEncoded(this, pcmChunk, pcmChunk->duration<chronos::msec>().count());
} }

View file

@ -25,11 +25,11 @@ class PcmEncoder : public Encoder
{ {
public: public:
PcmEncoder(const std::string& codecOptions = ""); PcmEncoder(const std::string& codecOptions = "");
virtual void encode(const msg::PcmChunk* chunk); void encode(const msg::PcmChunk* chunk) override;
virtual std::string name() const; std::string name() const override;
protected: protected:
virtual void initEncoder(); void initEncoder() override;
template <typename T> template <typename T>
void assign(void* pointer, T val) void assign(void* pointer, T val)

View file

@ -27,10 +27,10 @@ static AvahiEntryGroup* group;
static AvahiSimplePoll* simple_poll; static AvahiSimplePoll* simple_poll;
static char* name; static char* name;
PublishAvahi::PublishAvahi(const std::string& serviceName) : PublishmDNS(serviceName), client_(NULL), active_(false) PublishAvahi::PublishAvahi(const std::string& serviceName) : PublishmDNS(serviceName), client_(nullptr), active_(false)
{ {
group = NULL; group = nullptr;
simple_poll = NULL; simple_poll = nullptr;
name = avahi_strdup(serviceName_.c_str()); name = avahi_strdup(serviceName_.c_str());
} }
@ -85,7 +85,7 @@ PublishAvahi::~PublishAvahi()
void PublishAvahi::entry_group_callback(AvahiEntryGroup* g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void* userdata) void PublishAvahi::entry_group_callback(AvahiEntryGroup* g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void* userdata)
{ {
assert(g == group || group == NULL); assert(g == group || group == nullptr);
group = g; group = g;
/// Called whenever the entry group state changes /// Called whenever the entry group state changes
@ -149,7 +149,7 @@ void PublishAvahi::create_services(AvahiClient* c)
/// We will now add two services and one subtype to the entry group /// We will now add two services and one subtype to the entry group
for (const auto& service : services_) for (const auto& service : services_)
{ {
if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AvahiPublishFlags(0), name, service.name_.c_str(), NULL, NULL, if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AvahiPublishFlags(0), name, service.name_.c_str(), nullptr, nullptr,
service.port_, NULL)) < 0) service.port_, NULL)) < 0)
{ {
if (ret == AVAHI_ERR_COLLISION) if (ret == AVAHI_ERR_COLLISION)

View file

@ -41,8 +41,8 @@ class PublishAvahi : public PublishmDNS
{ {
public: public:
PublishAvahi(const std::string& serviceName); PublishAvahi(const std::string& serviceName);
virtual ~PublishAvahi(); ~PublishAvahi() override;
virtual void publish(const std::vector<mDNSService>& services); void publish(const std::vector<mDNSService>& services) override;
private: private:
static void entry_group_callback(AvahiEntryGroup* g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void* userdata); static void entry_group_callback(AvahiEntryGroup* g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void* userdata);

View file

@ -24,8 +24,7 @@ public:
} }
virtual ~PublishmDNS() virtual ~PublishmDNS()
{ = default;
}
virtual void publish(const std::vector<mDNSService>& services) = 0; virtual void publish(const std::vector<mDNSService>& services) = 0;

View file

@ -36,8 +36,7 @@ StreamServer::StreamServer(asio::io_service* io_service, const StreamServerSetti
StreamServer::~StreamServer() StreamServer::~StreamServer()
{ = default;
}
void StreamServer::onMetaChanged(const PcmStream* pcmStream) void StreamServer::onMetaChanged(const PcmStream* pcmStream)
@ -57,7 +56,7 @@ void StreamServer::onMetaChanged(const PcmStream* pcmStream)
LOG(INFO) << "onMetaChanged (" << pcmStream->getName() << ")\n"; LOG(INFO) << "onMetaChanged (" << pcmStream->getName() << ")\n";
json notification = jsonrpcpp::Notification("Stream.OnMetadata", jsonrpcpp::Parameter("id", pcmStream->getId(), "meta", meta->msg)).to_json(); json notification = jsonrpcpp::Notification("Stream.OnMetadata", jsonrpcpp::Parameter("id", pcmStream->getId(), "meta", meta->msg)).to_json();
controlServer_->send(notification.dump(), NULL); controlServer_->send(notification.dump(), nullptr);
////cout << "Notification: " << notification.dump() << "\n"; ////cout << "Notification: " << notification.dump() << "\n";
} }
@ -69,7 +68,7 @@ void StreamServer::onStateChanged(const PcmStream* pcmStream, const ReaderState&
LOG(INFO) << "onStateChanged (" << pcmStream->getName() << "): " << state << "\n"; LOG(INFO) << "onStateChanged (" << pcmStream->getName() << "): " << state << "\n";
// LOG(INFO) << pcmStream->toJson().dump(4); // LOG(INFO) << pcmStream->toJson().dump(4);
json notification = jsonrpcpp::Notification("Stream.OnUpdate", jsonrpcpp::Parameter("id", pcmStream->getId(), "stream", pcmStream->toJson())).to_json(); json notification = jsonrpcpp::Notification("Stream.OnUpdate", jsonrpcpp::Parameter("id", pcmStream->getId(), "stream", pcmStream->toJson())).to_json();
controlServer_->send(notification.dump(), NULL); controlServer_->send(notification.dump(), nullptr);
////cout << "Notification: " << notification.dump() << "\n"; ////cout << "Notification: " << notification.dump() << "\n";
} }

View file

@ -79,17 +79,17 @@ public:
// void send(const msg::BaseMessage* message); // void send(const msg::BaseMessage* message);
/// Clients call this when they receive a message. Implementation of MessageReceiver::onMessageReceived /// Clients call this when they receive a message. Implementation of MessageReceiver::onMessageReceived
virtual void onMessageReceived(StreamSession* connection, const msg::BaseMessage& baseMessage, char* buffer); void onMessageReceived(StreamSession* connection, const msg::BaseMessage& baseMessage, char* buffer) override;
virtual void onDisconnect(StreamSession* connection); void onDisconnect(StreamSession* connection) override;
/// Implementation of ControllMessageReceiver::onMessageReceived, called by ControlServer::onMessageReceived /// Implementation of ControllMessageReceiver::onMessageReceived, called by ControlServer::onMessageReceived
virtual void onMessageReceived(ControlSession* connection, const std::string& message); void onMessageReceived(ControlSession* connection, const std::string& message) override;
/// Implementation of PcmListener /// Implementation of PcmListener
virtual void onMetaChanged(const PcmStream* pcmStream); void onMetaChanged(const PcmStream* pcmStream) override;
virtual void onStateChanged(const PcmStream* pcmStream, const ReaderState& state); void onStateChanged(const PcmStream* pcmStream, const ReaderState& state) override;
virtual void onChunkRead(const PcmStream* pcmStream, msg::PcmChunk* chunk, double duration); void onChunkRead(const PcmStream* pcmStream, msg::PcmChunk* chunk, double duration) override;
virtual void onResync(const PcmStream* pcmStream, double ms); void onResync(const PcmStream* pcmStream, double ms) override;
private: private:
void startAccept(); void startAccept();

View file

@ -200,7 +200,7 @@ void StreamSession::getNextMessage()
tv t; tv t;
baseMessage.received = t; baseMessage.received = t;
if (active_ && (messageReceiver_ != NULL)) if (active_ && (messageReceiver_ != nullptr))
messageReceiver_->onMessageReceived(this, baseMessage, &buffer[0]); messageReceiver_->onMessageReceived(this, baseMessage, &buffer[0]);
} }
@ -219,7 +219,7 @@ void StreamSession::reader()
SLOG(ERROR) << "Exception in StreamSession::reader(): " << e.what() << endl; SLOG(ERROR) << "Exception in StreamSession::reader(): " << e.what() << endl;
} }
if (active_ && (messageReceiver_ != NULL)) if (active_ && (messageReceiver_ != nullptr))
messageReceiver_->onDisconnect(this); messageReceiver_->onDisconnect(this);
} }
@ -238,7 +238,7 @@ void StreamSession::writer()
if (bufferMs_ > 0) if (bufferMs_ > 0)
{ {
const msg::WireChunk* wireChunk = dynamic_cast<const msg::WireChunk*>(message.get()); const msg::WireChunk* wireChunk = dynamic_cast<const msg::WireChunk*>(message.get());
if (wireChunk != NULL) if (wireChunk != nullptr)
{ {
chronos::time_point_clk now = chronos::clk::now(); chronos::time_point_clk now = chronos::clk::now();
size_t age = 0; size_t age = 0;
@ -258,6 +258,6 @@ void StreamSession::writer()
SLOG(ERROR) << "Exception in StreamSession::writer(): " << e.what() << endl; SLOG(ERROR) << "Exception in StreamSession::writer(): " << e.what() << endl;
} }
if (active_ && (messageReceiver_ != NULL)) if (active_ && (messageReceiver_ != nullptr))
messageReceiver_->onDisconnect(this); messageReceiver_->onDisconnect(this);
} }

View file

@ -28,7 +28,7 @@ using namespace std;
static string hex2str(string input) static string hex2str(string input)
{ {
typedef unsigned char byte; typedef unsigned char byte;
unsigned long x = strtoul(input.c_str(), 0, 16); unsigned long x = strtoul(input.c_str(), nullptr, 16);
byte a[] = {byte(x >> 24), byte(x >> 16), byte(x >> 8), byte(x), 0}; byte a[] = {byte(x >> 24), byte(x >> 16), byte(x >> 8), byte(x), 0};
return string((char*)a); return string((char*)a);
} }

View file

@ -57,7 +57,7 @@ class AirplayStream : public ProcessStream
public: public:
/// ctor. Encoded PCM data is passed to the PipeListener /// ctor. Encoded PCM data is passed to the PipeListener
AirplayStream(PcmListener* pcmListener, const StreamUri& uri); AirplayStream(PcmListener* pcmListener, const StreamUri& uri);
virtual ~AirplayStream(); ~AirplayStream() override;
protected: protected:
#ifdef HAS_EXPAT #ifdef HAS_EXPAT
@ -74,8 +74,8 @@ protected:
void push(); void push();
#endif #endif
virtual void onStderrMsg(const char* buffer, size_t n); void onStderrMsg(const char* buffer, size_t n) override;
virtual void initExeAndPath(const std::string& filename); void initExeAndPath(const std::string& filename) override;
size_t port_; size_t port_;
std::string pipePath_; std::string pipePath_;
std::string params_wo_port_; std::string params_wo_port_;

View file

@ -34,10 +34,10 @@ class FileStream : public PcmStream
public: public:
/// ctor. Encoded PCM data is passed to the PipeListener /// ctor. Encoded PCM data is passed to the PipeListener
FileStream(PcmListener* pcmListener, const StreamUri& uri); FileStream(PcmListener* pcmListener, const StreamUri& uri);
virtual ~FileStream(); ~FileStream() override;
protected: protected:
virtual void worker(); void worker() override;
std::ifstream ifs; std::ifstream ifs;
}; };

View file

@ -75,7 +75,7 @@ public:
virtual void stop(); virtual void stop();
/// Implementation of EncoderListener::onChunkEncoded /// Implementation of EncoderListener::onChunkEncoded
virtual void onChunkEncoded(const Encoder* encoder, msg::PcmChunk* chunk, double duration); void onChunkEncoded(const Encoder* encoder, msg::PcmChunk* chunk, double duration) override;
virtual std::shared_ptr<msg::CodecHeader> getHeader(); virtual std::shared_ptr<msg::CodecHeader> getHeader();
virtual const StreamUri& getUri() const; virtual const StreamUri& getUri() const;

View file

@ -34,10 +34,10 @@ class PipeStream : public PcmStream
public: public:
/// ctor. Encoded PCM data is passed to the PipeListener /// ctor. Encoded PCM data is passed to the PipeListener
PipeStream(PcmListener* pcmListener, const StreamUri& uri); PipeStream(PcmListener* pcmListener, const StreamUri& uri);
virtual ~PipeStream(); ~PipeStream() override;
protected: protected:
virtual void worker(); void worker() override;
int fd_; int fd_;
}; };

View file

@ -37,10 +37,10 @@ class ProcessStream : public PcmStream
public: public:
/// ctor. Encoded PCM data is passed to the PipeListener /// ctor. Encoded PCM data is passed to the PipeListener
ProcessStream(PcmListener* pcmListener, const StreamUri& uri); ProcessStream(PcmListener* pcmListener, const StreamUri& uri);
virtual ~ProcessStream(); ~ProcessStream() override;
virtual void start(); void start() override;
virtual void stop(); void stop() override;
protected: protected:
std::string exe_; std::string exe_;
@ -50,7 +50,7 @@ protected:
std::thread stderrReaderThread_; std::thread stderrReaderThread_;
bool logStderr_; bool logStderr_;
virtual void worker(); void worker() override;
virtual void stderrReader(); virtual void stderrReader();
virtual void onStderrMsg(const char* buffer, size_t n); virtual void onStderrMsg(const char* buffer, size_t n);
virtual void initExeAndPath(const std::string& filename); virtual void initExeAndPath(const std::string& filename);

View file

@ -64,8 +64,7 @@ SpotifyStream::SpotifyStream(PcmListener* pcmListener, const StreamUri& uri) : P
SpotifyStream::~SpotifyStream() SpotifyStream::~SpotifyStream()
{ = default;
}
void SpotifyStream::initExeAndPath(const std::string& filename) void SpotifyStream::initExeAndPath(const std::string& filename)

View file

@ -36,16 +36,16 @@ class SpotifyStream : public ProcessStream, WatchdogListener
public: public:
/// ctor. Encoded PCM data is passed to the PipeListener /// ctor. Encoded PCM data is passed to the PipeListener
SpotifyStream(PcmListener* pcmListener, const StreamUri& uri); SpotifyStream(PcmListener* pcmListener, const StreamUri& uri);
virtual ~SpotifyStream(); ~SpotifyStream() override;
protected: protected:
std::unique_ptr<Watchdog> watchdog_; std::unique_ptr<Watchdog> watchdog_;
virtual void stderrReader(); void stderrReader() override;
virtual void onStderrMsg(const char* buffer, size_t n); void onStderrMsg(const char* buffer, size_t n) override;
virtual void initExeAndPath(const std::string& filename); void initExeAndPath(const std::string& filename) override;
virtual void onTimeout(const Watchdog* watchdog, size_t ms); void onTimeout(const Watchdog* watchdog, size_t ms) override;
}; };