From a7a4a91def549c0786200add639d702c9a66ade8 Mon Sep 17 00:00:00 2001 From: Mathis Logemann Date: Sun, 7 Jan 2024 21:02:10 +0100 Subject: [PATCH 1/2] drop using namespace std to not get in conflict with boost declarations --- client/browseZeroConf/browse_avahi.cpp | 3 - client/client_connection.cpp | 12 +-- client/controller.cpp | 25 +++-- client/decoder/flac_decoder.cpp | 5 +- client/decoder/ogg_decoder.cpp | 4 - client/decoder/opus_decoder.cpp | 1 - client/decoder/pcm_decoder.cpp | 1 - client/player/alsa_player.cpp | 41 ++++---- client/player/file_player.cpp | 8 +- client/player/player.cpp | 13 ++- client/player/pulse_player.cpp | 12 +-- client/snapclient.cpp | 110 ++++++++++----------- client/stream.cpp | 5 +- common/daemon.cpp | 2 - common/resampler.cpp | 6 +- common/sample_format.cpp | 8 +- server/config.cpp | 15 ++- server/control_server.cpp | 17 ++-- server/control_session_http.cpp | 7 +- server/control_session_tcp.cpp | 1 - server/control_session_ws.cpp | 2 - server/encoder/encoder_factory.cpp | 2 - server/encoder/flac_encoder.cpp | 7 +- server/encoder/ogg_encoder.cpp | 12 +-- server/encoder/opus_encoder.cpp | 7 +- server/publishZeroConf/publish_bonjour.cpp | 26 ++--- server/server.cpp | 51 +++++----- server/snapserver.cpp | 66 ++++++------- server/stream_server.cpp | 11 +-- server/stream_session.cpp | 2 +- server/stream_session_tcp.cpp | 1 - server/stream_session_ws.cpp | 1 - server/streamreader/airplay_stream.cpp | 41 ++++---- server/streamreader/alsa_stream.cpp | 21 ++-- server/streamreader/file_stream.cpp | 4 +- server/streamreader/librespot_stream.cpp | 29 +++--- server/streamreader/meta_stream.cpp | 11 +-- server/streamreader/pcm_stream.cpp | 14 +-- server/streamreader/pipe_stream.cpp | 6 +- server/streamreader/posix_stream.cpp | 1 - server/streamreader/process_stream.cpp | 16 ++- server/streamreader/stream_control.cpp | 14 ++- server/streamreader/stream_manager.cpp | 18 ++-- server/streamreader/stream_uri.cpp | 29 +++--- server/streamreader/tcp_stream.cpp | 10 +- server/streamreader/watchdog.cpp | 2 - 46 files changed, 317 insertions(+), 383 deletions(-) diff --git a/client/browseZeroConf/browse_avahi.cpp b/client/browseZeroConf/browse_avahi.cpp index a2c1be67..9bd52b4f 100644 --- a/client/browseZeroConf/browse_avahi.cpp +++ b/client/browseZeroConf/browse_avahi.cpp @@ -20,9 +20,6 @@ #include "common/aixlog.hpp" #include "common/snap_exception.hpp" #include -#include -#include -#include #include diff --git a/client/client_connection.cpp b/client/client_connection.cpp index 74d89c0f..8509aa1f 100644 --- a/client/client_connection.cpp +++ b/client/client_connection.cpp @@ -32,10 +32,8 @@ // standard headers #include -#include -using namespace std; static constexpr auto LOG_TAG = "Connection"; @@ -146,7 +144,7 @@ void ClientConnection::connect(const ResultHandler& handler) handler(ec); return; } - LOG(NOTICE, LOG_TAG) << "Connected to " << socket_.remote_endpoint().address().to_string() << endl; + LOG(NOTICE, LOG_TAG) << "Connected to " << socket_.remote_endpoint().address().to_string() << std::endl; handler(ec); #if 0 @@ -187,10 +185,10 @@ void ClientConnection::disconnect() boost::system::error_code ec; socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec); if (ec) - LOG(ERROR, LOG_TAG) << "Error in socket shutdown: " << ec.message() << endl; + LOG(ERROR, LOG_TAG) << "Error in socket shutdown: " << ec.message() << std::endl; socket_.close(ec); if (ec) - LOG(ERROR, LOG_TAG) << "Error in socket close: " << ec.message() << endl; + LOG(ERROR, LOG_TAG) << "Error in socket close: " << ec.message() << std::endl; boost::asio::post(strand_, [this]() { pendingRequests_.clear(); }); LOG(DEBUG, LOG_TAG) << "Disconnected\n"; } @@ -248,11 +246,11 @@ void ClientConnection::sendRequest(const msg::message_ptr& message, const chrono pendingRequests_.erase( std::remove_if(pendingRequests_.begin(), pendingRequests_.end(), [](std::weak_ptr request) { return request.expired(); }), pendingRequests_.end()); - unique_ptr response(nullptr); + std::unique_ptr response(nullptr); if (++reqId_ >= 10000) reqId_ = 1; message->id = reqId_; - auto request = make_shared(strand_, reqId_, handler); + auto request = std::make_shared(strand_, reqId_, handler); pendingRequests_.push_back(request); request->startTimer(timeout); send(message, diff --git a/client/controller.cpp b/client/controller.cpp index ca913a92..d33b6199 100644 --- a/client/controller.cpp +++ b/client/controller.cpp @@ -70,7 +70,6 @@ #include #include -using namespace std; using namespace player; static constexpr auto LOG_TAG = "Controller"; @@ -89,7 +88,7 @@ std::unique_ptr Controller::createPlayer(ClientSettings::Player& setting if (settings.player_name.empty() || settings.player_name == player_name) { settings.player_name = player_name; - return make_unique(io_context_, settings, stream_); + return std::make_unique(io_context_, settings, stream_); } return nullptr; } @@ -173,28 +172,28 @@ void Controller::getNextMessage() player_.reset(nullptr); if (headerChunk_->codec == "pcm") - decoder_ = make_unique(); + decoder_ = std::make_unique(); #if defined(HAS_OGG) && (defined(HAS_TREMOR) || defined(HAS_VORBIS)) else if (headerChunk_->codec == "ogg") - decoder_ = make_unique(); + decoder_ = std::make_unique(); #endif #if defined(HAS_FLAC) else if (headerChunk_->codec == "flac") - decoder_ = make_unique(); + decoder_ = std::make_unique(); #endif #if defined(HAS_OPUS) else if (headerChunk_->codec == "opus") - decoder_ = make_unique(); + decoder_ = std::make_unique(); #endif else if (headerChunk_->codec == "null") - decoder_ = make_unique(); + decoder_ = std::make_unique(); else throw SnapException("codec not supported: \"" + headerChunk_->codec + "\""); sampleFormat_ = decoder_->setHeader(headerChunk_.get()); LOG(INFO, LOG_TAG) << "Codec: " << headerChunk_->codec << ", sampleformat: " << sampleFormat_.toString() << "\n"; - stream_ = make_shared(sampleFormat_, settings_.player.sample_format); + stream_ = std::make_shared(sampleFormat_, settings_.player.sample_format); stream_->setBufferLen(std::max(0, serverSettings_->getBufferMs() - serverSettings_->getLatency() - settings_.player.latency)); #ifdef HAS_ALSA @@ -314,8 +313,8 @@ void Controller::browseMdns(const MdnsHandler& handler) mDNSResult avahiResult; if (browser.browse("_snapcast._tcp", avahiResult, 1000)) { - string host = avahiResult.ip; - uint16_t port = avahiResult.port; + std::string host = avahiResult.ip; + const uint16_t port = avahiResult.port; if (avahiResult.ip_version == IPVersion::IPv6) host += "%" + cpt::to_string(avahiResult.iface_idx); handler({}, host, port); @@ -361,14 +360,14 @@ void Controller::start() settings_.server.host = host; settings_.server.port = port; LOG(INFO, LOG_TAG) << "Found server " << settings_.server.host << ":" << settings_.server.port << "\n"; - clientConnection_ = make_unique(io_context_, settings_.server); + clientConnection_ = std::make_unique(io_context_, settings_.server); worker(); } }); } else { - clientConnection_ = make_unique(io_context_, settings_.server); + clientConnection_ = std::make_unique(io_context_, settings_.server); worker(); } } @@ -406,7 +405,7 @@ void Controller::worker() if (!ec) { // LOG(INFO, LOG_TAG) << "Connected!\n"; - string macAddress = clientConnection_->getMacAddress(); + const std::string macAddress = clientConnection_->getMacAddress(); if (settings_.host_id.empty()) settings_.host_id = ::getHostId(macAddress); diff --git a/client/decoder/flac_decoder.cpp b/client/decoder/flac_decoder.cpp index 967585a6..96b67a9e 100644 --- a/client/decoder/flac_decoder.cpp +++ b/client/decoder/flac_decoder.cpp @@ -20,13 +20,10 @@ #include "common/aixlog.hpp" #include "common/endian.hpp" #include "common/snap_exception.hpp" -#include #include #include -using namespace std; - static constexpr auto LOG_TAG = "FlacDecoder"; namespace decoder @@ -115,7 +112,7 @@ SampleFormat FlacDecoder::setHeader(msg::CodecHeader* chunk) init_status = FLAC__stream_decoder_init_stream(decoder, callback::read_callback, nullptr, nullptr, nullptr, nullptr, callback::write_callback, callback::metadata_callback, callback::error_callback, this); if (init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK) - throw SnapException("ERROR: initializing decoder: " + string(FLAC__StreamDecoderInitStatusString[init_status])); + throw SnapException("ERROR: initializing decoder: " + std::string(FLAC__StreamDecoderInitStatusString[init_status])); FLAC__stream_decoder_process_until_end_of_metadata(decoder); if (sampleFormat.rate() == 0) diff --git a/client/decoder/ogg_decoder.cpp b/client/decoder/ogg_decoder.cpp index 8540fcbe..38128ab0 100644 --- a/client/decoder/ogg_decoder.cpp +++ b/client/decoder/ogg_decoder.cpp @@ -31,12 +31,8 @@ #include #include #include -#include - -using namespace std; - static constexpr auto LOG_TAG = "OggDecoder"; namespace decoder diff --git a/client/decoder/opus_decoder.cpp b/client/decoder/opus_decoder.cpp index 41303ae0..5b8e5e3f 100644 --- a/client/decoder/opus_decoder.cpp +++ b/client/decoder/opus_decoder.cpp @@ -20,7 +20,6 @@ #include "opus_decoder.hpp" #include "common/aixlog.hpp" #include "common/snap_exception.hpp" -#include "common/str_compat.hpp" namespace decoder { diff --git a/client/decoder/pcm_decoder.cpp b/client/decoder/pcm_decoder.cpp index 4451a9a4..97517fa8 100644 --- a/client/decoder/pcm_decoder.cpp +++ b/client/decoder/pcm_decoder.cpp @@ -17,7 +17,6 @@ ***/ #include "pcm_decoder.hpp" -#include "common/aixlog.hpp" #include "common/endian.hpp" #include "common/snap_exception.hpp" diff --git a/client/player/alsa_player.cpp b/client/player/alsa_player.cpp index ca08ab3a..cef86dc2 100644 --- a/client/player/alsa_player.cpp +++ b/client/player/alsa_player.cpp @@ -31,7 +31,6 @@ // standard headers using namespace std::chrono_literals; -using namespace std; namespace player { @@ -52,19 +51,19 @@ AlsaPlayer::AlsaPlayer(boost::asio::io_context& io_context, const ClientSettings { if (settings_.mixer.mode == ClientSettings::Mixer::Mode::hardware) { - string tmp; + std::string tmp; if (settings_.mixer.parameter.empty()) mixer_name_ = DEFAULT_MIXER; else mixer_name_ = utils::string::split_left(settings_.mixer.parameter, ':', tmp); - string card; + std::string card; // default:CARD=ALSA[,DEV=x] => default mixer_device_ = utils::string::split_left(settings_.pcm_device.name, ':', card); if (!card.empty()) { auto pos = card.find("CARD="); - if (pos != string::npos) + if (pos != std::string::npos) { card = card.substr(pos + 5); card = utils::string::split_left(card, ',', tmp); @@ -145,7 +144,7 @@ bool AlsaPlayer::getHardwareVolume(double& volume, bool& muted) long vol; int err = 0; while (snd_mixer_handle_events(mixer_) > 0) - this_thread::sleep_for(1us); + std::this_thread::sleep_for(1us); long minv, maxv; if ((err = snd_mixer_selem_get_playback_dB_range(elem_, &minv, &maxv)) == 0) { @@ -309,7 +308,7 @@ void AlsaPlayer::initAlsa() snd_pcm_hw_params_t* params; snd_pcm_hw_params_alloca(¶ms); if ((err = snd_pcm_hw_params_any(handle_, params)) < 0) - throw SnapException("Can't fill params: " + string(snd_strerror(err))); + throw SnapException("Can't fill params: " + std::string(snd_strerror(err))); snd_output_t* output; if (snd_output_buffer_open(&output) == 0) @@ -325,7 +324,7 @@ void AlsaPlayer::initAlsa() // Set parameters if ((err = snd_pcm_hw_params_set_access(handle_, params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) - throw SnapException("Can't set interleaved mode: " + string(snd_strerror(err))); + throw SnapException("Can't set interleaved mode: " + std::string(snd_strerror(err))); snd_pcm_format_t snd_pcm_format; if (format.bits() == 8) @@ -356,8 +355,8 @@ void AlsaPlayer::initAlsa() err = snd_pcm_hw_params_set_format(handle_, params, snd_pcm_format); if (err < 0) { - stringstream ss; - ss << "Can't set format: " << string(snd_strerror(err)) << ", supported: "; + std::stringstream ss; + ss << "Can't set format: " << std::string(snd_strerror(err)) << ", supported: "; for (int format = 0; format <= static_cast(SND_PCM_FORMAT_LAST); format++) { auto snd_pcm_format = static_cast(format); @@ -368,10 +367,10 @@ void AlsaPlayer::initAlsa() } if ((err = snd_pcm_hw_params_set_channels(handle_, params, channels)) < 0) - throw SnapException("Can't set channel count: " + string(snd_strerror(err))); + throw SnapException("Can't set channel count: " + std::string(snd_strerror(err))); if ((err = snd_pcm_hw_params_set_rate_near(handle_, params, &rate, nullptr)) < 0) - throw SnapException("Can't set rate: " + string(snd_strerror(err))); + throw SnapException("Can't set rate: " + std::string(snd_strerror(err))); if (rate != format.rate()) LOG(WARNING, LOG_TAG) << "Could not set sample rate to " << format.rate() << " Hz, using: " << rate << " Hz\n"; @@ -404,7 +403,7 @@ void AlsaPlayer::initAlsa() } if ((err = snd_pcm_hw_params_set_period_time_near(handle_, params, &period_time, nullptr)) < 0) - throw SnapException("Can't set period time: " + string(snd_strerror(err))); + throw SnapException("Can't set period time: " + std::string(snd_strerror(err))); uint32_t buffer_time = buffer_time_.value_or(BUFFER_TIME).count(); uint32_t periods = periods_.value_or(MIN_PERIODS); @@ -416,7 +415,7 @@ void AlsaPlayer::initAlsa() } 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 : " + std::string(snd_strerror(err))); // unsigned int periods = periods_; // if ((err = snd_pcm_hw_params_set_periods_near(handle_, params, &periods, 0)) < 0) @@ -424,7 +423,7 @@ void AlsaPlayer::initAlsa() // Write parameters if ((err = snd_pcm_hw_params(handle_, params)) < 0) - throw SnapException("Can't set hardware parameters: " + string(snd_strerror(err))); + throw SnapException("Can't set hardware parameters: " + std::string(snd_strerror(err))); // Resume information // uint32_t periods; @@ -542,7 +541,7 @@ bool AlsaPlayer::getAvailDelay(snd_pcm_sframes_t& avail, snd_pcm_sframes_t& dela { LOG(WARNING, LOG_TAG) << "snd_pcm_avail_delay failed: " << snd_strerror(result) << " (" << result << "), avail: " << avail << ", delay: " << delay << ", using snd_pcm_avail amd snd_pcm_delay.\n"; - this_thread::sleep_for(1ms); + std::this_thread::sleep_for(1ms); avail = snd_pcm_avail(handle_); result = snd_pcm_delay(handle_, &delay); if ((result < 0) || (delay < 0)) @@ -584,7 +583,7 @@ void AlsaPlayer::worker() } catch (const std::exception& e) { - LOG(ERROR, LOG_TAG) << "Exception in initAlsa: " << e.what() << endl; + LOG(ERROR, LOG_TAG) << "Exception in initAlsa: " << e.what() << std::endl; chronos::sleep(100); } if (handle_ == nullptr) @@ -610,7 +609,7 @@ void AlsaPlayer::worker() if (!getAvailDelay(framesAvail, framesDelay)) { - this_thread::sleep_for(10ms); + std::this_thread::sleep_for(10ms); snd_pcm_prepare(handle_); continue; } @@ -625,7 +624,7 @@ void AlsaPlayer::worker() auto frame_time = std::chrono::microseconds(static_cast(frames_ / format.usRate())); std::chrono::microseconds wait = std::min(frame_time / 2, std::chrono::microseconds(10ms)); LOG(DEBUG, LOG_TAG) << "No frames available, waiting for " << wait.count() << " us\n"; - this_thread::sleep_for(wait); + std::this_thread::sleep_for(wait); continue; } @@ -673,11 +672,11 @@ void AlsaPlayer::worker() -vector AlsaPlayer::pcm_list() +std::vector AlsaPlayer::pcm_list() { void **hints, **n; char *name, *descr, *io; - vector result; + std::vector result; PcmDevice pcmDevice; if (snd_device_name_hint(-1, "pcm", &hints) < 0) @@ -716,4 +715,4 @@ vector AlsaPlayer::pcm_list() return result; } -} // namespace player \ No newline at end of file +} // namespace player diff --git a/client/player/file_player.cpp b/client/player/file_player.cpp index e916e8a2..460a31fa 100644 --- a/client/player/file_player.cpp +++ b/client/player/file_player.cpp @@ -28,10 +28,8 @@ // 3rd party headers // standard headers -#include -#include -using namespace std; +using namespace std::chrono_literals; namespace player { @@ -44,7 +42,7 @@ static constexpr auto kDescription = "Raw PCM file output"; std::vector FilePlayer::pcm_list(const std::string& parameter) { auto params = utils::string::split_pairs(parameter, ',', '='); - string filename; + std::string filename; if (params.find("filename") != params.end()) filename = params["filename"]; if (filename.empty()) @@ -57,7 +55,7 @@ FilePlayer::FilePlayer(boost::asio::io_context& io_context, const ClientSettings : Player(io_context, settings, stream), timer_(io_context), file_(nullptr) { auto params = utils::string::split_pairs(settings.parameter, ',', '='); - string filename; + std::string filename; if (params.find("filename") != params.end()) filename = params["filename"]; diff --git a/client/player/player.cpp b/client/player/player.cpp index f2b8eb73..af774d5a 100644 --- a/client/player/player.cpp +++ b/client/player/player.cpp @@ -47,7 +47,6 @@ #include -using namespace std; namespace player { @@ -57,7 +56,7 @@ static constexpr auto LOG_TAG = "Player"; Player::Player(boost::asio::io_context& io_context, const ClientSettings::Player& settings, std::shared_ptr stream) : io_context_(io_context), active_(false), stream_(stream), settings_(settings), volume_(1.0), muted_(false), volCorrection_(1.0) { - string sharing_mode; + std::string sharing_mode; switch (settings_.sharing_mode) { case ClientSettings::SharingMode::unspecified: @@ -82,7 +81,7 @@ Player::Player(boost::asio::io_context& io_context, const ClientSettings::Player << ", description: " << not_empty(settings_.pcm_device.description) << ", idx: " << settings_.pcm_device.idx << ", sharing mode: " << sharing_mode << ", parameters: " << not_empty(settings.parameter) << "\n"; - string mixer; + std::string mixer; switch (settings_.mixer.mode) { case ClientSettings::Mixer::Mode::hardware: @@ -114,7 +113,7 @@ void Player::start() { active_ = true; if (needsThread()) - playerThread_ = thread(&Player::worker, this); + playerThread_ = std::thread(&Player::worker, this); // If hardware mixer is used, send the initial volume to the server, because this is // the volume that is configured by the user on his local device, so we shouldn't change it @@ -218,8 +217,8 @@ void Player::setVolume(double volume, bool mute) } else if (settings_.mixer.mode == ClientSettings::Mixer::Mode::software) { - string param; - string mode = utils::string::split_left(settings_.mixer.parameter, ':', param); + std::string param; + std::string mode = utils::string::split_left(settings_.mixer.parameter, ':', param); double dparam = -1.; if (!param.empty()) { @@ -231,7 +230,7 @@ void Player::setVolume(double volume, bool mute) } catch (const std::exception& e) { - throw SnapException("Invalid mixer param: " + param + ", error: " + string(e.what())); + throw SnapException("Invalid mixer param: " + param + ", error: " + std::string(e.what())); } } if (mode == "poly") diff --git a/client/player/pulse_player.cpp b/client/player/pulse_player.cpp index 1405e59c..17d560dd 100644 --- a/client/player/pulse_player.cpp +++ b/client/player/pulse_player.cpp @@ -30,12 +30,10 @@ #include // standard headers -#include #include using namespace std::chrono_literals; -using namespace std; namespace player { @@ -50,7 +48,7 @@ static constexpr auto LOG_TAG = "PulsePlayer"; // https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/Developer/Clients/Samples/AsyncPlayback/ -vector PulsePlayer::pcm_list(const std::string& parameter) +std::vector PulsePlayer::pcm_list(const std::string& parameter) { auto pa_ml = std::shared_ptr(pa_mainloop_new(), [](pa_mainloop* pa_ml) { pa_mainloop_free(pa_ml); }); pa_mainloop_api* pa_mlapi = pa_mainloop_get_api(pa_ml.get()); @@ -101,7 +99,7 @@ vector PulsePlayer::pcm_list(const std::string& parameter) throw SnapException("Timeout while waiting for PulseAudio to become ready"); if (pa_mainloop_iterate(pa_ml.get(), 1, nullptr) < 0) throw SnapException("Error while waiting for PulseAudio to become ready, error: " + std::string(pa_strerror(pa_context_errno(pa_ctx.get())))); - this_thread::sleep_for(1ms); + std::this_thread::sleep_for(1ms); } if (pa_ready == 2) @@ -211,7 +209,7 @@ void PulsePlayer::worker() } catch (const std::exception& e) { - LOG(ERROR, LOG_TAG) << "Exception while connecting to pulse: " << e.what() << endl; + LOG(ERROR, LOG_TAG) << "Exception while connecting to pulse: " << e.what() << std::endl; disconnect(); chronos::sleep(100); } @@ -312,7 +310,7 @@ void PulsePlayer::underflowCallback(pa_stream* stream) void PulsePlayer::stateCallback(pa_context* ctx) { pa_context_state_t state = pa_context_get_state(ctx); - string str_state = "unknown"; + std::string str_state{"unknown"}; pa_ready_ = 0; switch (state) { @@ -454,7 +452,7 @@ void PulsePlayer::connect() throw SnapException("Timeout while waiting for PulseAudio to become ready"); if (pa_mainloop_iterate(pa_ml_, 1, nullptr) < 0) throw SnapException("Error while waiting for PulseAudio to become ready, error: " + std::string(pa_strerror(pa_context_errno(pa_ctx_)))); - this_thread::sleep_for(1ms); + std::this_thread::sleep_for(1ms); } if (pa_ready_ == 2) diff --git a/client/snapclient.cpp b/client/snapclient.cpp index ebbf7f82..c0f6b49f 100644 --- a/client/snapclient.cpp +++ b/client/snapclient.cpp @@ -53,7 +53,6 @@ #endif -using namespace std; using namespace popl; using namespace player; @@ -67,7 +66,7 @@ PcmDevice getPcmDevice(const std::string& player, const std::string& parameter, LOG(DEBUG, LOG_TAG) << "Trying to get PCM device for player: " << player << ", parameter: " << ", card: " << soundcard << "\n"; #if defined(HAS_ALSA) || defined(HAS_PULSE) || defined(HAS_WASAPI) - vector pcm_devices; + std::vector pcm_devices; #if defined(HAS_ALSA) if (player == player::ALSA) pcm_devices = AlsaPlayer::pcm_list(); @@ -94,7 +93,7 @@ PcmDevice getPcmDevice(const std::string& player, const std::string& parameter, } for (auto dev : pcm_devices) - if (dev.name.find(soundcard) != string::npos) + if (dev.name.find(soundcard) != std::string::npos) return dev; #endif std::ignore = player; @@ -134,32 +133,32 @@ int main(int argc, char** argv) try { ClientSettings settings; - string pcm_device(player::DEFAULT_DEVICE); + std::string pcm_device(player::DEFAULT_DEVICE); OptionParser op("Allowed options"); auto helpSwitch = op.add("", "help", "produce help message"); auto groffSwitch = op.add("", "groff", "produce groff message"); auto versionSwitch = op.add("v", "version", "show version number"); - op.add>("h", "host", "server hostname or ip address", "", &settings.server.host); + op.add>("h", "host", "server hostname or ip address", "", &settings.server.host); op.add>("p", "port", "server port", 1704, &settings.server.port); op.add>("i", "instance", "instance id when running multiple instances on the same host", 1, &settings.instance); - op.add>("", "hostID", "unique host id, default is MAC address", "", &settings.host_id); + op.add>("", "hostID", "unique host id, default is MAC address", "", &settings.host_id); // PCM device specific #if defined(HAS_ALSA) || defined(HAS_PULSE) || defined(HAS_WASAPI) auto listSwitch = op.add("l", "list", "list PCM devices"); - /*auto soundcardValue =*/op.add>("s", "soundcard", "index or name of the pcm device", pcm_device, &pcm_device); + /*auto soundcardValue =*/op.add>("s", "soundcard", "index or name of the pcm device", pcm_device, &pcm_device); #endif /*auto latencyValue =*/op.add>("", "latency", "latency of the PCM device", 0, &settings.player.latency); #ifdef HAS_SOXR - auto sample_format = op.add>("", "sampleformat", "resample audio stream to ::", ""); + auto sample_format = op.add>("", "sampleformat", "resample audio stream to ::", ""); #endif auto supported_players = Controller::getSupportedPlayerNames(); - string supported_players_str; + std::string supported_players_str; for (const auto& supported_player : supported_players) supported_players_str += (!supported_players_str.empty() ? "|" : "") + supported_player; - op.add>("", "player", supported_players_str + "[:|?]", supported_players.front(), &settings.player.player_name); + op.add>("", "player", supported_players_str + "[:|?]", supported_players.front(), &settings.player.player_name); // sharing mode #if defined(HAS_OBOE) || defined(HAS_WASAPI) @@ -173,20 +172,20 @@ int main(int argc, char** argv) #endif std::shared_ptr> mixer_mode; if (hw_mixer_supported) - mixer_mode = op.add>("", "mixer", "software|hardware|script|none|?[:]", "software"); + mixer_mode = op.add>("", "mixer", "software|hardware|script|none|?[:]", "software"); else - mixer_mode = op.add>("", "mixer", "software|script|none|?[:]", "software"); + mixer_mode = op.add>("", "mixer", "software|script|none|?[:]", "software"); // daemon settings #ifdef HAS_DAEMON int processPriority(-3); auto daemonOption = op.add>("d", "daemon", "daemonize, optional process priority [-20..19]", processPriority, &processPriority); - auto userValue = op.add>("", "user", "the user[:group] to run snapclient as when daemonized"); + auto userValue = op.add>("", "user", "the user[:group] to run snapclient as when daemonized"); #endif // logging - op.add>("", "logsink", "log sink [null,system,stdout,stderr,file:]", settings.logging.sink, &settings.logging.sink); - auto logfilterOption = op.add>( + op.add>("", "logsink", "log sink [null,system,stdout,stderr,file:]", settings.logging.sink, &settings.logging.sink); + auto logfilterOption = op.add>( "", "logfilter", "log filter :[,:]* with tag = * or and level = [trace,debug,info,notice,warning,error,fatal]", settings.logging.filter); @@ -196,19 +195,19 @@ int main(int argc, char** argv) } catch (const std::invalid_argument& e) { - cerr << "Exception: " << e.what() << std::endl; - cout << "\n" << op << "\n"; + std::cerr << "Exception: " << e.what() << std::endl; + std::cout << "\n" << op << "\n"; exit(EXIT_FAILURE); } if (versionSwitch->is_set()) { - cout << "snapclient v" << version::code << (!version::rev().empty() ? (" (rev " + version::rev(8) + ")") : ("")) << "\n" - << "Copyright (C) 2014-2022 BadAix (snapcast@badaix.de).\n" - << "License GPLv3+: GNU GPL version 3 or later .\n" - << "This is free software: you are free to change and redistribute it.\n" - << "There is NO WARRANTY, to the extent permitted by law.\n\n" - << "Written by Johannes M. Pohl and contributors .\n\n"; + std::cout << "snapclient v" << version::code << (!version::rev().empty() ? (" (rev " + version::rev(8) + ")") : ("")) << "\n" + << "Copyright (C) 2014-2022 BadAix (snapcast@badaix.de).\n" + << "License GPLv3+: GNU GPL version 3 or later .\n" + << "This is free software: you are free to change and redistribute it.\n" + << "There is NO WARRANTY, to the extent permitted by law.\n\n" + << "Written by Johannes M. Pohl and contributors .\n\n"; exit(EXIT_SUCCESS); } @@ -219,7 +218,7 @@ int main(int argc, char** argv) { try { - vector pcm_devices; + std::vector pcm_devices; #if defined(HAS_ALSA) if (settings.player.player_name == player::ALSA) pcm_devices = AlsaPlayer::pcm_list(); @@ -239,14 +238,14 @@ int main(int argc, char** argv) setvbuf(stdout, nullptr, _IOFBF, 1000); #endif for (const auto& dev : pcm_devices) - cout << dev.idx << ": " << dev.name << "\n" << dev.description << "\n\n"; + std::cout << dev.idx << ": " << dev.name << "\n" << dev.description << "\n\n"; if (pcm_devices.empty()) - cout << "No PCM device available for audio backend \"" << settings.player.player_name << "\"\n"; + std::cout << "No PCM device available for audio backend \"" << settings.player.player_name << "\"\n"; } catch (const std::exception& e) { - cout << "Failed to get device list: " << e.what() << "\n"; + std::cout << "Failed to get device list: " << e.what() << "\n"; } exit(EXIT_SUCCESS); } @@ -254,14 +253,14 @@ int main(int argc, char** argv) if (helpSwitch->is_set()) { - cout << op << "\n"; + std::cout << op << "\n"; exit(EXIT_SUCCESS); } if (groffSwitch->is_set()) { GroffOptionPrinter option_printer(&op); - cout << option_printer.print(); + std::cout << option_printer.print(); exit(EXIT_SUCCESS); } @@ -285,10 +284,10 @@ int main(int argc, char** argv) for (const auto& filter : filters) logfilter.add_filter(filter); - string logformat = "%Y-%m-%d %H-%M-%S.#ms [#severity] (#tag_func)"; - if (settings.logging.sink.find("file:") != string::npos) + std::string logformat = "%Y-%m-%d %H-%M-%S.#ms [#severity] (#tag_func)"; + if (settings.logging.sink.find("file:") != std::string::npos) { - string logfile = settings.logging.sink.substr(settings.logging.sink.find(':') + 1); + std::string logfile = settings.logging.sink.substr(settings.logging.sink.find(':') + 1); AixLog::Log::init(logfilter, logfile, logformat); } else if (settings.logging.sink == "stdout") @@ -312,18 +311,18 @@ int main(int argc, char** argv) std::unique_ptr daemon; if (daemonOption->is_set()) { - string pidFile = "/var/run/snapclient/pid"; + std::string pidFile = "/var/run/snapclient/pid"; if (settings.instance != 1) pidFile += "." + cpt::to_string(settings.instance); - string user; - string group; + std::string user; + std::string group; if (userValue->is_set()) { if (userValue->value().empty()) throw std::invalid_argument("user must not be empty"); - vector user_group = utils::string::split(userValue->value(), ':'); + std::vector user_group = utils::string::split(userValue->value(), ':'); user = user_group[0]; if (user_group.size() > 1) group = user_group[1]; @@ -358,30 +357,30 @@ int main(int argc, char** argv) { if (settings.player.player_name == player::FILE) { - cout << "Options are a comma separated list of:\n" - << " \"filename=\" - with = \"stdout\", \"stderr\", \"null\" or a filename\n" - << " \"mode=[w|a]\" - w: write (discarding the content), a: append (keeping the content)\n"; + std::cout << "Options are a comma separated list of:\n" + << " \"filename=\" - with = \"stdout\", \"stderr\", \"null\" or a filename\n" + << " \"mode=[w|a]\" - w: write (discarding the content), a: append (keeping the content)\n"; } #ifdef HAS_PULSE else if (settings.player.player_name == player::PULSE) { - cout << "Options are a comma separated list of:\n" - << " \"buffer_time=\" - default 100, min 10\n" - << " \"server=\" - default not-set: use the default server\n" - << " \"property==\" - can be set multiple times, default 'media.role=music'\n"; + std::cout << "Options are a comma separated list of:\n" + << " \"buffer_time=\" - default 100, min 10\n" + << " \"server=\" - default not-set: use the default server\n" + << " \"property==\" - can be set multiple times, default 'media.role=music'\n"; } #endif #ifdef HAS_ALSA else if (settings.player.player_name == player::ALSA) { - cout << "Options are a comma separated list of:\n" - << " \"buffer_time=\" - default 80, min 10\n" - << " \"fragments=\" - default 4, min 2\n"; + std::cout << "Options are a comma separated list of:\n" + << " \"buffer_time=\" - default 80, min 10\n" + << " \"fragments=\" - default 4, min 2\n"; } #endif else { - cout << "No options available for \"" << settings.player.player_name << "\n"; + std::cout << "No options available for \"" << settings.player.player_name << "\n"; } exit(EXIT_SUCCESS); } @@ -395,7 +394,7 @@ int main(int argc, char** argv) } #endif - string mode = utils::string::split_left(mixer_mode->value(), ':', settings.player.mixer.parameter); + std::string mode = utils::string::split_left(mixer_mode->value(), ':', settings.player.mixer.parameter); if (mode == "software") settings.player.mixer.mode = ClientSettings::Mixer::Mode::software; else if ((mode == "hardware") && hw_mixer_supported) @@ -406,10 +405,10 @@ int main(int argc, char** argv) settings.player.mixer.mode = ClientSettings::Mixer::Mode::none; else if ((mode == "?") || (mode == "help")) { - cout << "mixer can be one of 'software', " << (hw_mixer_supported ? "'hardware', " : "") << "'script', 'none'\n" - << "followed by optional parameters:\n" - << " * software[:poly[:]|exp[:]]\n" - << (hw_mixer_supported ? " * hardware[:]\n" : "") << " * script[: