Tidy up code

This commit is contained in:
badaix 2021-02-11 08:33:36 +01:00
parent f5d4fcaf43
commit 7597f15d24
22 changed files with 74 additions and 85 deletions

View file

@ -1,6 +1,6 @@
/*** /***
This file is part of snapcast This file is part of snapcast
Copyright (C) 2014-2020 Johannes Pohl Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -24,10 +24,10 @@
namespace decoder namespace decoder
{ {
#define ID_RIFF 0x46464952 static constexpr auto ID_RIFF = 0x46464952;
#define ID_WAVE 0x45564157 static constexpr auto ID_WAVE = 0x45564157;
#define ID_FMT 0x20746d66 static constexpr auto ID_FMT = 0x20746d66;
#define ID_DATA 0x61746164 static constexpr auto ID_DATA = 0x61746164;
struct riff_wave_header struct riff_wave_header
{ {

View file

@ -261,7 +261,7 @@ void AlsaPlayer::initMixer()
throw SnapException(std::string("Failed to open mixer, error: ") + snd_strerror(err)); throw SnapException(std::string("Failed to open mixer, error: ") + snd_strerror(err));
if ((err = snd_mixer_attach(mixer_, mixer_device_.c_str())) < 0) if ((err = snd_mixer_attach(mixer_, mixer_device_.c_str())) < 0)
throw SnapException("Failed to attach mixer to " + mixer_device_ + ", error: " + snd_strerror(err)); throw SnapException("Failed to attach mixer to " + mixer_device_ + ", error: " + snd_strerror(err));
if ((err = snd_mixer_selem_register(mixer_, NULL, NULL)) < 0) if ((err = snd_mixer_selem_register(mixer_, nullptr, nullptr)) < 0)
throw SnapException(std::string("Failed to register selem, error: ") + snd_strerror(err)); throw SnapException(std::string("Failed to register selem, error: ") + snd_strerror(err));
if ((err = snd_mixer_load(mixer_)) < 0) if ((err = snd_mixer_load(mixer_)) < 0)
throw SnapException(std::string("Failed to load mixer, error: ") + snd_strerror(err)); throw SnapException(std::string("Failed to load mixer, error: ") + snd_strerror(err));
@ -402,7 +402,7 @@ void AlsaPlayer::initAlsa()
buffer_time = period_time * periods; buffer_time = period_time * periods;
} }
if ((err = snd_pcm_hw_params_set_buffer_time_near(handle_, params, &buffer_time, 0)) < 0) if ((err = snd_pcm_hw_params_set_buffer_time_near(handle_, params, &buffer_time, nullptr)) < 0)
throw SnapException("Can't set buffer time to " + cpt::to_string(buffer_time) + " us : " + string(snd_strerror(err))); throw SnapException("Can't set buffer time to " + cpt::to_string(buffer_time) + " us : " + string(snd_strerror(err)));
// unsigned int periods = periods_; // unsigned int periods = periods_;

View file

@ -1,6 +1,6 @@
/*** /***
This file is part of snapcast This file is part of snapcast
Copyright (C) 2014-2020 Johannes Pohl Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -53,8 +53,8 @@ static void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void* context)
OpenslPlayer::OpenslPlayer(boost::asio::io_context& io_context, const ClientSettings::Player& settings, std::shared_ptr<Stream> stream) OpenslPlayer::OpenslPlayer(boost::asio::io_context& io_context, const ClientSettings::Player& settings, std::shared_ptr<Stream> stream)
: Player(io_context, settings, stream), engineObject(NULL), engineEngine(NULL), outputMixObject(NULL), bqPlayerObject(NULL), bqPlayerPlay(NULL), : Player(io_context, settings, stream), engineObject(nullptr), engineEngine(nullptr), outputMixObject(nullptr), bqPlayerObject(nullptr),
bqPlayerBufferQueue(NULL), bqPlayerVolume(NULL), curBuffer(0), ms_(50), buff_size(0), pubStream_(stream) bqPlayerPlay(nullptr), bqPlayerBufferQueue(nullptr), bqPlayerVolume(nullptr), curBuffer(0), ms_(50), buff_size(0), pubStream_(stream)
{ {
initOpensl(); initOpensl();
} }
@ -178,7 +178,7 @@ void OpenslPlayer::initOpensl()
SLresult result; SLresult result;
// create engine // create engine
SLEngineOption engineOption[] = {{(SLuint32)SL_ENGINEOPTION_THREADSAFE, (SLuint32)SL_BOOLEAN_TRUE}}; SLEngineOption engineOption[] = {{(SLuint32)SL_ENGINEOPTION_THREADSAFE, (SLuint32)SL_BOOLEAN_TRUE}};
result = slCreateEngine(&engineObject, 1, engineOption, 0, NULL, NULL); result = slCreateEngine(&engineObject, 1, engineOption, 0, nullptr, nullptr);
throwUnsuccess(kPhaseInit, "slCreateEngine", result); throwUnsuccess(kPhaseInit, "slCreateEngine", result);
result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE);
throwUnsuccess(kPhaseInit, "EngineObject::Realize", result); throwUnsuccess(kPhaseInit, "EngineObject::Realize", result);
@ -266,7 +266,7 @@ void OpenslPlayer::initOpensl()
// configure audio sink // configure audio sink
SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject}; SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject};
SLDataSink audioSnk = {&loc_outmix, NULL}; SLDataSink audioSnk = {&loc_outmix, nullptr};
// create audio player // create audio player
const SLInterfaceID ids[3] = {SL_IID_ANDROIDCONFIGURATION, SL_IID_PLAY, SL_IID_BUFFERQUEUE}; //, SL_IID_VOLUME}; const SLInterfaceID ids[3] = {SL_IID_ANDROIDCONFIGURATION, SL_IID_PLAY, SL_IID_BUFFERQUEUE}; //, SL_IID_VOLUME};
@ -321,7 +321,7 @@ void OpenslPlayer::uninitOpensl()
LOG(INFO, LOG_TAG) << "uninitOpensl\n"; LOG(INFO, LOG_TAG) << "uninitOpensl\n";
SLresult result; SLresult result;
LOG(INFO, LOG_TAG) << "OpenSLWrap_Shutdown - stopping playback\n"; LOG(INFO, LOG_TAG) << "OpenSLWrap_Shutdown - stopping playback\n";
if (bqPlayerPlay != NULL) if (bqPlayerPlay != nullptr)
{ {
result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_STOPPED); result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_STOPPED);
if (SL_RESULT_SUCCESS != result) if (SL_RESULT_SUCCESS != result)
@ -330,37 +330,37 @@ void OpenslPlayer::uninitOpensl()
LOG(INFO, LOG_TAG) << "OpenSLWrap_Shutdown - deleting player object\n"; LOG(INFO, LOG_TAG) << "OpenSLWrap_Shutdown - deleting player object\n";
if (bqPlayerObject != NULL) if (bqPlayerObject != nullptr)
{ {
(*bqPlayerObject)->Destroy(bqPlayerObject); (*bqPlayerObject)->Destroy(bqPlayerObject);
bqPlayerObject = NULL; bqPlayerObject = nullptr;
bqPlayerPlay = NULL; bqPlayerPlay = nullptr;
bqPlayerBufferQueue = NULL; bqPlayerBufferQueue = nullptr;
bqPlayerVolume = NULL; bqPlayerVolume = nullptr;
} }
LOG(INFO, LOG_TAG) << "OpenSLWrap_Shutdown - deleting mix object\n"; LOG(INFO, LOG_TAG) << "OpenSLWrap_Shutdown - deleting mix object\n";
if (outputMixObject != NULL) if (outputMixObject != nullptr)
{ {
(*outputMixObject)->Destroy(outputMixObject); (*outputMixObject)->Destroy(outputMixObject);
outputMixObject = NULL; outputMixObject = nullptr;
} }
LOG(INFO, LOG_TAG) << "OpenSLWrap_Shutdown - deleting engine object\n"; LOG(INFO, LOG_TAG) << "OpenSLWrap_Shutdown - deleting engine object\n";
if (engineObject != NULL) if (engineObject != nullptr)
{ {
(*engineObject)->Destroy(engineObject); (*engineObject)->Destroy(engineObject);
engineObject = NULL; engineObject = nullptr;
engineEngine = NULL; engineEngine = nullptr;
} }
delete[] buffer[0]; delete[] buffer[0];
buffer[0] = NULL; buffer[0] = nullptr;
delete[] buffer[1]; delete[] buffer[1];
buffer[1] = NULL; buffer[1] = nullptr;
LOG(INFO, LOG_TAG) << "OpenSLWrap_Shutdown - finished\n"; LOG(INFO, LOG_TAG) << "OpenSLWrap_Shutdown - finished\n";
active_ = false; active_ = false;

View file

@ -122,7 +122,7 @@ int main(int argc, char** argv)
int exitcode = EXIT_SUCCESS; int exitcode = EXIT_SUCCESS;
try try
{ {
string meta_script(""); string meta_script;
ClientSettings settings; ClientSettings settings;
string pcm_device(player::DEFAULT_DEVICE); string pcm_device(player::DEFAULT_DEVICE);
@ -309,8 +309,8 @@ int main(int argc, char** argv)
string pidFile = "/var/run/snapclient/pid"; string pidFile = "/var/run/snapclient/pid";
if (settings.instance != 1) if (settings.instance != 1)
pidFile += "." + cpt::to_string(settings.instance); pidFile += "." + cpt::to_string(settings.instance);
string user = ""; string user;
string group = ""; string group;
if (userValue->is_set()) if (userValue->is_set())
{ {

View file

@ -67,11 +67,6 @@ Stream::Stream(const SampleFormat& in_format, const SampleFormat& out_format)
} }
Stream::~Stream()
{
}
void Stream::setRealSampleRate(double sampleRate) void Stream::setRealSampleRate(double sampleRate)
{ {
if (sampleRate == format_.rate()) if (sampleRate == format_.rate())
@ -95,7 +90,7 @@ void Stream::setBufferLen(size_t bufferLenMs)
void Stream::clearChunks() void Stream::clearChunks()
{ {
std::lock_guard<std::mutex> lock(mutex_); std::lock_guard<std::mutex> lock(mutex_);
while (chunks_.size() > 0) while (!chunks_.empty())
chunks_.pop(); chunks_.pop();
resetBuffers(); resetBuffers();
} }

View file

@ -1,6 +1,6 @@
/*** /***
This file is part of snapcast This file is part of snapcast
Copyright (C) 2014-2020 Johannes Pohl Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -40,7 +40,7 @@ class Stream
{ {
public: public:
Stream(const SampleFormat& in_format, const SampleFormat& out_format); Stream(const SampleFormat& in_format, const SampleFormat& out_format);
virtual ~Stream(); virtual ~Stream() = default;
/// Adds PCM data to the queue /// Adds PCM data to the queue
void addChunk(std::unique_ptr<msg::PcmChunk> chunk); void addChunk(std::unique_ptr<msg::PcmChunk> chunk);

View file

@ -44,8 +44,8 @@ Resampler::Resampler(const SampleFormat& in_format, const SampleFormat& out_form
soxr_io_spec_t iospec = soxr_io_spec(in_type, out_type); soxr_io_spec_t iospec = soxr_io_spec(in_type, out_type);
// HQ should be fine: http://sox.sourceforge.net/Docs/FAQ // HQ should be fine: http://sox.sourceforge.net/Docs/FAQ
soxr_quality_spec_t q_spec = soxr_quality_spec(SOXR_HQ, 0); soxr_quality_spec_t q_spec = soxr_quality_spec(SOXR_HQ, 0);
soxr_ = soxr_ = soxr_create(static_cast<double>(in_format_.rate()), static_cast<double>(out_format_.rate()), in_format_.channels(), &error, &iospec, &q_spec,
soxr_create(static_cast<double>(in_format_.rate()), static_cast<double>(out_format_.rate()), in_format_.channels(), &error, &iospec, &q_spec, NULL); nullptr);
if (error != nullptr) if (error != nullptr)
{ {
LOG(ERROR, LOG_TAG) << "Error soxr_create: " << error << "\n"; LOG(ERROR, LOG_TAG) << "Error soxr_create: " << error << "\n";

View file

@ -1,6 +1,6 @@
/*** /***
This file is part of snapcast This file is part of snapcast
Copyright (C) 2014-2020 Johannes Pohl Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -43,9 +43,9 @@ SampleFormat::SampleFormat(const std::string& format)
} }
SampleFormat::SampleFormat(uint32_t sampleRate, uint16_t bitsPerSample, uint16_t channelCount) SampleFormat::SampleFormat(uint32_t sampleRate, uint16_t bitsPerSample, uint16_t channels)
{ {
setFormat(sampleRate, bitsPerSample, channelCount); setFormat(sampleRate, bitsPerSample, channels);
} }

View file

@ -30,10 +30,6 @@
using namespace std; using namespace std;
Config::Config()
{
}
Config::~Config() Config::~Config()
{ {

View file

@ -1,6 +1,6 @@
/*** /***
This file is part of snapcast This file is part of snapcast
Copyright (C) 2014-2020 Johannes Pohl Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -16,8 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
***/ ***/
#ifndef CONFIG_H #ifndef CONFIG_HPP
#define CONFIG_H #define CONFIG_HPP
#include <memory> #include <memory>
#include <string> #include <string>
@ -395,7 +395,7 @@ public:
std::vector<GroupPtr> groups; std::vector<GroupPtr> groups;
private: private:
Config(); Config() = default;
~Config(); ~Config();
std::string filename_; std::string filename_;
}; };

View file

@ -1,6 +1,6 @@
/*** /***
This file is part of snapcast This file is part of snapcast
Copyright (C) 2014-2020 Johannes Pohl Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -363,8 +363,10 @@ void ControlSessionHttp::on_read(beast::error_code ec, std::size_t bytes_transfe
} }
void ControlSessionHttp::on_write(beast::error_code ec, std::size_t, bool close) void ControlSessionHttp::on_write(beast::error_code ec, std::size_t bytes, bool close)
{ {
std::ignore = bytes;
// Handle the error, if any // Handle the error, if any
if (ec) if (ec)
{ {

View file

@ -1,6 +1,6 @@
/*** /***
This file is part of snapcast This file is part of snapcast
Copyright (C) 2014-2020 Johannes Pohl Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -58,7 +58,7 @@ public:
protected: protected:
// HTTP methods // HTTP methods
void on_read(beast::error_code ec, std::size_t bytes_transferred); void on_read(beast::error_code ec, std::size_t bytes_transferred);
void on_write(beast::error_code ec, std::size_t, bool close); void on_write(beast::error_code ec, std::size_t bytes, bool close);
template <class Body, class Allocator, class Send> template <class Body, class Allocator, class Send>
void handle_request(http::request<Body, http::basic_fields<Allocator>>&& req, Send&& send); void handle_request(http::request<Body, http::basic_fields<Allocator>>&& req, Send&& send);

View file

@ -24,10 +24,10 @@
namespace encoder namespace encoder
{ {
#define ID_RIFF 0x46464952 static constexpr auto ID_RIFF = 0x46464952;
#define ID_WAVE 0x45564157 static constexpr auto ID_WAVE = 0x45564157;
#define ID_FMT 0x20746d66 static constexpr auto ID_FMT = 0x20746d66;
#define ID_DATA 0x61746164 static constexpr auto ID_DATA = 0x61746164;
namespace namespace

View file

@ -152,7 +152,7 @@ void PublishAvahi::create_services(AvahiClient* c)
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(), nullptr, 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_, static_cast<char*>(NULL))) < 0) nullptr, service.port_, static_cast<char*>(nullptr))) < 0)
{ {
if (ret == AVAHI_ERR_COLLISION) if (ret == AVAHI_ERR_COLLISION)
goto collision; goto collision;

View file

@ -1,6 +1,6 @@
/*** /***
This file is part of snapcast This file is part of snapcast
Copyright (C) 2014-2020 Johannes Pohl Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -63,11 +63,11 @@ public:
private: private:
/// Implementation of StreamMessageReceiver /// Implementation of StreamMessageReceiver
void onMessageReceived(StreamSession* connection, const msg::BaseMessage& baseMessage, char* buffer) override; void onMessageReceived(StreamSession* streamSession, const msg::BaseMessage& baseMessage, char* buffer) override;
void onDisconnect(StreamSession* connection) override; void onDisconnect(StreamSession* streamSession) override;
/// Implementation of ControllMessageReceiver /// Implementation of ControllMessageReceiver
std::string onMessageReceived(ControlSession* connection, const std::string& message) override; std::string onMessageReceived(ControlSession* controlSession, const std::string& message) override;
void onNewSession(const std::shared_ptr<ControlSession>& session) override void onNewSession(const std::shared_ptr<ControlSession>& session) override
{ {
std::ignore = session; std::ignore = session;

View file

@ -242,7 +242,7 @@ int main(int argc, char* argv[])
if (daemonOption->is_set()) if (daemonOption->is_set())
{ {
if (settings.server.user.empty()) if (settings.server.user.empty())
std::invalid_argument("user must not be empty"); throw std::invalid_argument("user must not be empty");
if (settings.server.data_dir.empty()) if (settings.server.data_dir.empty())
settings.server.data_dir = "/var/lib/snapserver"; settings.server.data_dir = "/var/lib/snapserver";

View file

@ -1,6 +1,6 @@
/*** /***
This file is part of snapcast This file is part of snapcast
Copyright (C) 2014-2020 Johannes Pohl Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -67,7 +67,7 @@ public:
void onMetaChanged(const PcmStream* pcmStream, std::shared_ptr<msg::StreamTags> meta); void onMetaChanged(const PcmStream* pcmStream, std::shared_ptr<msg::StreamTags> meta);
void onChunkEncoded(const PcmStream* pcmStream, bool isDefaultStream, std::shared_ptr<msg::PcmChunk> chunk, double duration); void onChunkEncoded(const PcmStream* pcmStream, bool isDefaultStream, std::shared_ptr<msg::PcmChunk> chunk, double duration);
session_ptr getStreamSession(const std::string& mac) const; session_ptr getStreamSession(const std::string& clientId) const;
session_ptr getStreamSession(StreamSession* session) const; session_ptr getStreamSession(StreamSession* session) const;
private: private:
@ -76,8 +76,8 @@ private:
void cleanup(); void cleanup();
/// Implementation of StreamMessageReceiver /// Implementation of StreamMessageReceiver
void onMessageReceived(StreamSession* connection, const msg::BaseMessage& baseMessage, char* buffer) override; void onMessageReceived(StreamSession* streamSession, const msg::BaseMessage& baseMessage, char* buffer) override;
void onDisconnect(StreamSession* connection) override; void onDisconnect(StreamSession* streamSession) override;
mutable std::recursive_mutex sessionsMutex_; mutable std::recursive_mutex sessionsMutex_;
mutable std::recursive_mutex clientMutex_; mutable std::recursive_mutex clientMutex_;

View file

@ -33,7 +33,7 @@ static constexpr auto LOG_TAG = "AirplayStream";
namespace namespace
{ {
string hex2str(string input) string hex2str(const string& input)
{ {
using byte = unsigned char; using byte = unsigned char;
unsigned long x = strtoul(input.c_str(), nullptr, 16); unsigned long x = strtoul(input.c_str(), nullptr, 16);
@ -88,7 +88,7 @@ AirplayStream::~AirplayStream()
} }
#ifdef HAS_EXPAT #ifdef HAS_EXPAT
int AirplayStream::parse(string line) int AirplayStream::parse(const string& line)
{ {
enum XML_Status result; enum XML_Status result;
@ -345,7 +345,7 @@ void XMLCALL AirplayStream::element_end(void* userdata, const char* element_name
self->entry_->type.assign(hex2str(self->buf_)); self->entry_->type.assign(hex2str(self->buf_));
else if (name == "length") else if (name == "length")
self->entry_->length = strtoul(self->buf_.c_str(), 0, 10); self->entry_->length = strtoul(self->buf_.c_str(), nullptr, 10);
else if (name == "data") else if (name == "data")
self->entry_->data = self->buf_; self->entry_->data = self->buf_;

View file

@ -1,6 +1,6 @@
/*** /***
This file is part of snapcast This file is part of snapcast
Copyright (C) 2014-2020 Johannes Pohl Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -74,7 +74,7 @@ protected:
void pipeReadLine(); void pipeReadLine();
#ifdef HAS_EXPAT #ifdef HAS_EXPAT
int parse(std::string line); int parse(const std::string& line);
void createParser(); void createParser();
void push(); void push();
void setMetaData(const std::string& key, const std::string& newValue); void setMetaData(const std::string& key, const std::string& newValue);

View file

@ -134,17 +134,13 @@ void AlsaStream::initAlsa()
if ((err = snd_pcm_hw_params_set_format(handle_, hw_params, snd_pcm_format)) < 0) if ((err = snd_pcm_hw_params_set_format(handle_, hw_params, snd_pcm_format)) < 0)
throw SnapException("Can't set sample format: " + string(snd_strerror(err))); throw SnapException("Can't set sample format: " + string(snd_strerror(err)));
if ((err = snd_pcm_hw_params_set_rate_near(handle_, hw_params, &rate, 0)) < 0) if ((err = snd_pcm_hw_params_set_rate_near(handle_, hw_params, &rate, nullptr)) < 0)
{
throw SnapException("Can't set rate: " + string(snd_strerror(err))); throw SnapException("Can't set rate: " + string(snd_strerror(err)));
}
else if (rate != sampleFormat_.rate())
{ {
if (rate != sampleFormat_.rate()) LOG(WARNING, LOG_TAG) << "Rate is not accurate (requested: " << sampleFormat_.rate() << ", got: " << rate << "), using: " << rate << "\n";
{ sampleFormat_.setFormat(rate, sampleFormat_.bits(), sampleFormat_.channels());
LOG(WARNING, LOG_TAG) << "Rate is not accurate (requested: " << sampleFormat_.rate() << ", got: " << rate << "), using: " << rate << "\n";
sampleFormat_.setFormat(rate, sampleFormat_.bits(), sampleFormat_.channels());
}
} }
if ((err = snd_pcm_hw_params_set_channels(handle_, hw_params, sampleFormat_.channels())) < 0) if ((err = snd_pcm_hw_params_set_channels(handle_, hw_params, sampleFormat_.channels())) < 0)

View file

@ -1,6 +1,6 @@
/*** /***
This file is part of snapcast This file is part of snapcast
Copyright (C) 2014-2020 Johannes Pohl Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -32,7 +32,7 @@ static constexpr auto LOG_TAG = "MetaStream";
// static constexpr auto kResyncTolerance = 50ms; // static constexpr auto kResyncTolerance = 50ms;
MetaStream::MetaStream(PcmListener* pcmListener, std::vector<std::shared_ptr<PcmStream>> streams, boost::asio::io_context& ioc, const StreamUri& uri) MetaStream::MetaStream(PcmListener* pcmListener, const std::vector<std::shared_ptr<PcmStream>>& streams, boost::asio::io_context& ioc, const StreamUri& uri)
: PcmStream(pcmListener, ioc, uri), first_read_(true) : PcmStream(pcmListener, ioc, uri), first_read_(true)
{ {
auto path_components = utils::string::split(uri.path, '/'); auto path_components = utils::string::split(uri.path, '/');

View file

@ -1,6 +1,6 @@
/*** /***
This file is part of snapcast This file is part of snapcast
Copyright (C) 2014-2020 Johannes Pohl Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -37,7 +37,7 @@ class MetaStream : public PcmStream, public PcmListener
{ {
public: public:
/// ctor. Encoded PCM data is passed to the PcmListener /// ctor. Encoded PCM data is passed to the PcmListener
MetaStream(PcmListener* pcmListener, std::vector<std::shared_ptr<PcmStream>> streams, boost::asio::io_context& ioc, const StreamUri& uri); MetaStream(PcmListener* pcmListener, const std::vector<std::shared_ptr<PcmStream>>& streams, boost::asio::io_context& ioc, const StreamUri& uri);
virtual ~MetaStream(); virtual ~MetaStream();
void start() override; void start() override;