Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop using namespace std #1193

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ endif()

# Configure compiler options
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

include(${CMAKE_SOURCE_DIR}/cmake/TargetArch.cmake)
target_architecture(HOST_ARCH)
Expand Down
3 changes: 0 additions & 3 deletions client/browseZeroConf/browse_avahi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
#include "common/aixlog.hpp"
#include "common/snap_exception.hpp"
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>


Expand Down
12 changes: 5 additions & 7 deletions client/client_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@

// standard headers
#include <iostream>
#include <mutex>


using namespace std;

static constexpr auto LOG_TAG = "Connection";

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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";
}
Expand Down Expand Up @@ -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<PendingRequest> request) { return request.expired(); }),
pendingRequests_.end());
unique_ptr<msg::BaseMessage> response(nullptr);
std::unique_ptr<msg::BaseMessage> response(nullptr);
if (++reqId_ >= 10000)
reqId_ = 1;
message->id = reqId_;
auto request = make_shared<PendingRequest>(strand_, reqId_, handler);
auto request = std::make_shared<PendingRequest>(strand_, reqId_, handler);
pendingRequests_.push_back(request);
request->startTimer(timeout);
send(message,
Expand Down
25 changes: 12 additions & 13 deletions client/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
#include <memory>
#include <string>

using namespace std;
using namespace player;

static constexpr auto LOG_TAG = "Controller";
Expand All @@ -89,7 +88,7 @@ std::unique_ptr<Player> Controller::createPlayer(ClientSettings::Player& setting
if (settings.player_name.empty() || settings.player_name == player_name)
{
settings.player_name = player_name;
return make_unique<PlayerType>(io_context_, settings, stream_);
return std::make_unique<PlayerType>(io_context_, settings, stream_);
}
return nullptr;
}
Expand Down Expand Up @@ -173,28 +172,28 @@ void Controller::getNextMessage()
player_.reset(nullptr);

if (headerChunk_->codec == "pcm")
decoder_ = make_unique<decoder::PcmDecoder>();
decoder_ = std::make_unique<decoder::PcmDecoder>();
#if defined(HAS_OGG) && (defined(HAS_TREMOR) || defined(HAS_VORBIS))
else if (headerChunk_->codec == "ogg")
decoder_ = make_unique<decoder::OggDecoder>();
decoder_ = std::make_unique<decoder::OggDecoder>();
#endif
#if defined(HAS_FLAC)
else if (headerChunk_->codec == "flac")
decoder_ = make_unique<decoder::FlacDecoder>();
decoder_ = std::make_unique<decoder::FlacDecoder>();
#endif
#if defined(HAS_OPUS)
else if (headerChunk_->codec == "opus")
decoder_ = make_unique<decoder::OpusDecoder>();
decoder_ = std::make_unique<decoder::OpusDecoder>();
#endif
else if (headerChunk_->codec == "null")
decoder_ = make_unique<decoder::NullDecoder>();
decoder_ = std::make_unique<decoder::NullDecoder>();
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<Stream>(sampleFormat_, settings_.player.sample_format);
stream_ = std::make_shared<Stream>(sampleFormat_, settings_.player.sample_format);
stream_->setBufferLen(std::max(0, serverSettings_->getBufferMs() - serverSettings_->getLatency() - settings_.player.latency));

#ifdef HAS_ALSA
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<ClientConnection>(io_context_, settings_.server);
clientConnection_ = std::make_unique<ClientConnection>(io_context_, settings_.server);
worker();
}
});
}
else
{
clientConnection_ = make_unique<ClientConnection>(io_context_, settings_.server);
clientConnection_ = std::make_unique<ClientConnection>(io_context_, settings_.server);
worker();
}
}
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 1 addition & 4 deletions client/decoder/flac_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@
#include "common/aixlog.hpp"
#include "common/endian.hpp"
#include "common/snap_exception.hpp"
#include <cmath>
#include <cstring>
#include <iostream>


using namespace std;

static constexpr auto LOG_TAG = "FlacDecoder";

namespace decoder
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions client/decoder/ogg_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@
#include <cmath>
#include <cstdint>
#include <cstring>
#include <iostream>



using namespace std;

static constexpr auto LOG_TAG = "OggDecoder";

namespace decoder
Expand Down
1 change: 0 additions & 1 deletion client/decoder/opus_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "opus_decoder.hpp"
#include "common/aixlog.hpp"
#include "common/snap_exception.hpp"
#include "common/str_compat.hpp"

namespace decoder
{
Expand Down
1 change: 0 additions & 1 deletion client/decoder/pcm_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
***/

#include "pcm_decoder.hpp"
#include "common/aixlog.hpp"
#include "common/endian.hpp"
#include "common/snap_exception.hpp"

Expand Down
41 changes: 20 additions & 21 deletions client/player/alsa_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
// standard headers

using namespace std::chrono_literals;
using namespace std;

namespace player
{
Expand All @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -309,7 +308,7 @@ void AlsaPlayer::initAlsa()
snd_pcm_hw_params_t* params;
snd_pcm_hw_params_alloca(&params);
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)
Expand All @@ -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)
Expand Down Expand Up @@ -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<int>(SND_PCM_FORMAT_LAST); format++)
{
auto snd_pcm_format = static_cast<snd_pcm_format_t>(format);
Expand All @@ -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";

Expand Down Expand Up @@ -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);
Expand All @@ -416,15 +415,15 @@ 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)
// throw SnapException("Can't set periods: " + string(snd_strerror(err)));

// 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;
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
Expand All @@ -625,7 +624,7 @@ void AlsaPlayer::worker()
auto frame_time = std::chrono::microseconds(static_cast<int>(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;
}

Expand Down Expand Up @@ -673,11 +672,11 @@ void AlsaPlayer::worker()



vector<PcmDevice> AlsaPlayer::pcm_list()
std::vector<PcmDevice> AlsaPlayer::pcm_list()
{
void **hints, **n;
char *name, *descr, *io;
vector<PcmDevice> result;
std::vector<PcmDevice> result;
PcmDevice pcmDevice;

if (snd_device_name_hint(-1, "pcm", &hints) < 0)
Expand Down Expand Up @@ -716,4 +715,4 @@ vector<PcmDevice> AlsaPlayer::pcm_list()
return result;
}

} // namespace player
} // namespace player
Loading