Skip to content

Commit

Permalink
Fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
badaix committed Feb 13, 2025
1 parent 329ca05 commit e42a290
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- name: evaluate
run: |
WARNINGS=$(cat build/analysis.log | sort | uniq | grep -e ": warning: " | wc -l)
MAX_ALLOWED=431
MAX_ALLOWED=41
echo "Analysis finished with $WARNINGS warnings, max allowed: $MAX_ALLOWED"
if [ "$WARNINGS" -gt "$MAX_ALLOWED" ]; then exit $WARNINGS; else exit 0; fi;
Expand Down
54 changes: 27 additions & 27 deletions client/player/alsa_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,25 @@ void AlsaPlayer::setHardwareVolume(const Volume& volume)
LOG(ERROR, LOG_TAG) << "Failed to mute, error: " << snd_strerror(err) << "\n";

long minv, maxv;
if ((err = snd_mixer_selem_get_playback_dB_range(elem_, &minv, &maxv)) == 0)
if (err = snd_mixer_selem_get_playback_dB_range(elem_, &minv, &maxv); err == 0)
{
double min_norm = exp10((minv - maxv) / 6000.0);
double vol = volume.volume * (1 - min_norm) + min_norm;
double mixer_volume = 6000.0 * log10(vol) + maxv;

LOG(DEBUG, LOG_TAG) << "Mixer playback dB range [" << minv << ", " << maxv << "], volume: " << vol << ", mixer volume: " << mixer_volume << "\n";
if ((err = snd_mixer_selem_set_playback_dB_all(elem_, mixer_volume, 0)) < 0)
if (err = snd_mixer_selem_set_playback_dB_all(elem_, mixer_volume, 0); err < 0)
throw SnapException(std::string("Failed to set playback volume, error: ") + snd_strerror(err));
}
else
{
if ((err = snd_mixer_selem_get_playback_volume_range(elem_, &minv, &maxv)) < 0)
if (err = snd_mixer_selem_get_playback_volume_range(elem_, &minv, &maxv); err < 0)
throw SnapException(std::string("Failed to get playback volume range, error: ") + snd_strerror(err));

auto mixer_volume = volume.volume * (maxv - minv) + minv;
LOG(DEBUG, LOG_TAG) << "Mixer playback volume range [" << minv << ", " << maxv << "], volume: " << volume.volume
<< ", mixer volume: " << mixer_volume << "\n";
if ((err = snd_mixer_selem_set_playback_volume_all(elem_, mixer_volume)) < 0)
if (err = snd_mixer_selem_set_playback_volume_all(elem_, mixer_volume); err < 0)
throw SnapException(std::string("Failed to set playback volume, error: ") + snd_strerror(err));
}
}
Expand All @@ -149,9 +149,9 @@ bool AlsaPlayer::getHardwareVolume(Volume& volume)
while (snd_mixer_handle_events(mixer_) > 0)
this_thread::sleep_for(1us);
long minv, maxv;
if ((err = snd_mixer_selem_get_playback_dB_range(elem_, &minv, &maxv)) == 0)
if (err = snd_mixer_selem_get_playback_dB_range(elem_, &minv, &maxv); err == 0)
{
if ((err = snd_mixer_selem_get_playback_dB(elem_, SND_MIXER_SCHN_MONO, &vol)) < 0)
if (err = snd_mixer_selem_get_playback_dB(elem_, SND_MIXER_SCHN_MONO, &vol); err < 0)
throw SnapException(std::string("Failed to get playback volume, error: ") + snd_strerror(err));

volume.volume = pow(10, (vol - maxv) / 6000.0);
Expand All @@ -163,17 +163,17 @@ bool AlsaPlayer::getHardwareVolume(Volume& volume)
}
else
{
if ((err = snd_mixer_selem_get_playback_volume_range(elem_, &minv, &maxv)) < 0)
if (err = snd_mixer_selem_get_playback_volume_range(elem_, &minv, &maxv); err < 0)
throw SnapException(std::string("Failed to get playback volume range, error: ") + snd_strerror(err));
if ((err = snd_mixer_selem_get_playback_volume(elem_, SND_MIXER_SCHN_MONO, &vol)) < 0)
if (err = snd_mixer_selem_get_playback_volume(elem_, SND_MIXER_SCHN_MONO, &vol); err < 0)
throw SnapException(std::string("Failed to get playback volume, error: ") + snd_strerror(err));

vol -= minv;
maxv = maxv - minv;
volume.volume = static_cast<double>(vol) / static_cast<double>(maxv);
}
int val;
if ((err = snd_mixer_selem_get_playback_switch(elem_, SND_MIXER_SCHN_MONO, &val)) < 0)
if (err = snd_mixer_selem_get_playback_switch(elem_, SND_MIXER_SCHN_MONO, &val); err < 0)
throw SnapException(std::string("Failed to get mute state, error: ") + snd_strerror(err));
volume.mute = (val == 0);
LOG(DEBUG, LOG_TAG) << "Get volume, mixer volume range [" << minv << ", " << maxv << "], volume: " << volume.volume << ", muted: " << volume.mute
Expand Down Expand Up @@ -250,9 +250,9 @@ void AlsaPlayer::initMixer()
LOG(DEBUG, LOG_TAG) << "initMixer\n";
std::lock_guard<std::recursive_mutex> lock(rec_mutex_);
int err;
if ((err = snd_ctl_open(&ctl_, mixer_device_.c_str(), SND_CTL_READONLY)) < 0)
if (err = snd_ctl_open(&ctl_, mixer_device_.c_str(), SND_CTL_READONLY); err < 0)
throw SnapException("Can't open control for " + mixer_device_ + ", error: " + snd_strerror(err));
if ((err = snd_ctl_subscribe_events(ctl_, 1)) < 0)
if (err = snd_ctl_subscribe_events(ctl_, 1); err < 0)
throw SnapException("Can't subscribe for events for " + mixer_device_ + ", error: " + snd_strerror(err));
fd_ = std::unique_ptr<pollfd, std::function<void(pollfd*)>>(new pollfd(), [](pollfd* p)
{
Expand All @@ -270,13 +270,13 @@ void AlsaPlayer::initMixer()
snd_mixer_selem_id_set_index(sid, mix_index);
snd_mixer_selem_id_set_name(sid, mixer_name_.c_str());

if ((err = snd_mixer_open(&mixer_, 0)) < 0)
if (err = snd_mixer_open(&mixer_, 0); err < 0)
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()); err < 0)
throw SnapException("Failed to attach mixer to " + mixer_device_ + ", error: " + snd_strerror(err));
if ((err = snd_mixer_selem_register(mixer_, nullptr, nullptr)) < 0)
if (err = snd_mixer_selem_register(mixer_, nullptr, nullptr); err < 0)
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_); err < 0)
throw SnapException(std::string("Failed to load mixer, error: ") + snd_strerror(err));
elem_ = snd_mixer_find_selem(mixer_, sid);
if (elem_ == nullptr)
Expand All @@ -297,7 +297,7 @@ void AlsaPlayer::initAlsa()
int err;

// Open the PCM device in playback mode
if ((err = snd_pcm_open(&handle_, settings_.pcm_device.name.c_str(), SND_PCM_STREAM_PLAYBACK, 0)) < 0)
if (err = snd_pcm_open(&handle_, settings_.pcm_device.name.c_str(), SND_PCM_STREAM_PLAYBACK, 0); err < 0)
throw SnapException("Can't open " + settings_.pcm_device.name + ", error: " + snd_strerror(err), err);

// struct snd_pcm_playback_info_t pinfo;
Expand All @@ -308,7 +308,7 @@ void AlsaPlayer::initAlsa()
// Allocate parameters object and fill it with default values
snd_pcm_hw_params_t* params;
snd_pcm_hw_params_alloca(&params);
if ((err = snd_pcm_hw_params_any(handle_, params)) < 0)
if (err = snd_pcm_hw_params_any(handle_, params); err < 0)
throw SnapException("Can't fill params: " + string(snd_strerror(err)));

snd_output_t* output;
Expand All @@ -324,7 +324,7 @@ void AlsaPlayer::initAlsa()
}

// Set parameters
if ((err = snd_pcm_hw_params_set_access(handle_, params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
if (err = snd_pcm_hw_params_set_access(handle_, params, SND_PCM_ACCESS_RW_INTERLEAVED); err < 0)
throw SnapException("Can't set interleaved mode: " + string(snd_strerror(err)));

snd_pcm_format_t snd_pcm_format;
Expand Down Expand Up @@ -367,17 +367,17 @@ void AlsaPlayer::initAlsa()
throw SnapException(ss.str());
}

if ((err = snd_pcm_hw_params_set_channels(handle_, params, channels)) < 0)
if (err = snd_pcm_hw_params_set_channels(handle_, params, channels); err < 0)
throw SnapException("Can't set channel count: " + string(snd_strerror(err)));

if ((err = snd_pcm_hw_params_set_rate_near(handle_, params, &rate, nullptr)) < 0)
if (err = snd_pcm_hw_params_set_rate_near(handle_, params, &rate, nullptr); err < 0)
throw SnapException("Can't set rate: " + 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";

uint32_t period_time = buffer_time_.value_or(BUFFER_TIME).count() / periods_.value_or(PERIODS);
uint32_t max_period_time = period_time;
if ((err = snd_pcm_hw_params_get_period_time_max(params, &max_period_time, nullptr)) < 0)
if (err = snd_pcm_hw_params_get_period_time_max(params, &max_period_time, nullptr); err < 0)
{
LOG(ERROR, LOG_TAG) << "Can't get max period time: " << snd_strerror(err) << "\n";
}
Expand All @@ -390,7 +390,7 @@ void AlsaPlayer::initAlsa()
}
}
uint32_t min_period_time = period_time;
if ((err = snd_pcm_hw_params_get_period_time_min(params, &min_period_time, nullptr)) < 0)
if (err = snd_pcm_hw_params_get_period_time_min(params, &min_period_time, nullptr); err < 0)
{
LOG(ERROR, LOG_TAG) << "Can't get min period time: " << snd_strerror(err) << "\n";
}
Expand All @@ -403,7 +403,7 @@ void AlsaPlayer::initAlsa()
}
}

if ((err = snd_pcm_hw_params_set_period_time_near(handle_, params, &period_time, nullptr)) < 0)
if (err = snd_pcm_hw_params_set_period_time_near(handle_, params, &period_time, nullptr); err < 0)
throw SnapException("Can't set period time: " + string(snd_strerror(err)));

uint32_t buffer_time = buffer_time_.value_or(BUFFER_TIME).count();
Expand All @@ -415,15 +415,15 @@ void AlsaPlayer::initAlsa()
buffer_time = period_time * periods;
}

if ((err = snd_pcm_hw_params_set_buffer_time_near(handle_, params, &buffer_time, nullptr)) < 0)
if (err = snd_pcm_hw_params_set_buffer_time_near(handle_, params, &buffer_time, nullptr); err < 0)
throw SnapException("Can't set buffer time to " + cpt::to_string(buffer_time) + " us : " + string(snd_strerror(err)));

// unsigned int periods = periods_;
// if ((err = snd_pcm_hw_params_set_periods_near(handle_, params, &periods, 0)) < 0)
// if (err = snd_pcm_hw_params_set_periods_near(handle_, params, &periods, 0); err < 0)
// throw SnapException("Can't set periods: " + string(snd_strerror(err)));

// Write parameters
if ((err = snd_pcm_hw_params(handle_, params)) < 0)
if (err = snd_pcm_hw_params(handle_, params); err < 0)
throw SnapException("Can't set hardware parameters: " + string(snd_strerror(err)));

// Resume information
Expand All @@ -447,7 +447,7 @@ void AlsaPlayer::initAlsa()

if (snd_pcm_state(handle_) == SND_PCM_STATE_PREPARED)
{
if ((err = snd_pcm_start(handle_)) < 0)
if (err = snd_pcm_start(handle_); err < 0)
LOG(DEBUG, LOG_TAG) << "Failed to start PCM: " << snd_strerror(err) << "\n";
}

Expand Down
2 changes: 2 additions & 0 deletions client/player/pulse_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ void PulsePlayer::connect()
if (settings_.pcm_device.name != DEFAULT_DEVICE)
device = settings_.pcm_device.name.c_str();

// NOLINTBEGIN
int result = pa_stream_connect_playback(
playstream_, device, &bufattr_, static_cast<pa_stream_flags>(PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_ADJUST_LATENCY | PA_STREAM_AUTO_TIMING_UPDATE),
nullptr, nullptr);
Expand All @@ -500,6 +501,7 @@ void PulsePlayer::connect()
result = pa_stream_connect_playback(playstream_, device, &bufattr_,
static_cast<pa_stream_flags>(PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE), nullptr, nullptr);
}
// NOLINTEND
if (result < 0)
throw SnapException("Failed to connect PulseAudio playback stream");

Expand Down
14 changes: 7 additions & 7 deletions common/daemon.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***
This file is part of snapcast
Copyright (C) 2014-2024 Johannes Pohl
Copyright (C) 2014-2025 Johannes Pohl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -25,8 +25,8 @@
#include "common/utils/file_utils.hpp"

// standard headers
#include <array>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <grp.h>
#include <pwd.h>
Expand All @@ -36,8 +36,8 @@
#include <unistd.h>


Daemon::Daemon(const std::string& user, const std::string& group, const std::string& pidfile)
: pidFilehandle_(-1), user_(user), group_(group), pidfile_(pidfile)
Daemon::Daemon(std::string user, std::string group, std::string pidfile)
: pidFilehandle_(-1), user_(std::move(user)), group_(std::move(group)), pidfile_(std::move(pidfile))
{
if (pidfile.empty() || pidfile.find('/') == std::string::npos)
throw SnapException("invalid pid file \"" + pidfile + "\"");
Expand Down Expand Up @@ -152,12 +152,12 @@ void Daemon::daemonize()
if (lockf(pidFilehandle_, F_TLOCK, 0) == -1)
throw SnapException("Could not lock PID lock file \"" + pidfile_ + "\". Is the daemon already running?");

char str[10];
std::array<char, 10> str;
/// Get and format PID
sprintf(str, "%d\n", getpid());
sprintf(str.data(), "%d\n", getpid());

/// write pid to lockfile
if (write(pidFilehandle_, str, strlen(str)) != static_cast<int>(strlen(str)))
if (write(pidFilehandle_, str.data(), str.size()) != static_cast<int>(str.size()))
throw SnapException("Could not write PID to lock file \"" + pidfile_ + "\"");

/// Close out the standard file descriptors
Expand Down
9 changes: 6 additions & 3 deletions common/daemon.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***
This file is part of snapcast
Copyright (C) 2014-2024 Johannes Pohl
Copyright (C) 2014-2025 Johannes Pohl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -22,13 +22,16 @@
// standard headers
#include <string>


/// Daemonize a process: run a fork as specified user/group
class Daemon
{
public:
Daemon(const std::string& user, const std::string& group, const std::string& pidfile);
/// c'tor
Daemon(std::string user, std::string group, std::string pidfile);
/// d'tor
virtual ~Daemon();

/// daemonize the process
void daemonize();

private:
Expand Down
5 changes: 3 additions & 2 deletions server/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ Config::~Config()
void Config::init(const std::string& root_directory, const std::string& user, const std::string& group)
{
string dir;
auto home = getenv("HOME");
if (!root_directory.empty())
dir = root_directory;
else if (getenv("HOME") == nullptr)
else if (home == nullptr)
dir = "/var/lib/snapserver/";
else
dir = string(getenv("HOME")) + "/.config/snapserver/";
dir = string{home} + "/.config/snapserver/";

if (!dir.empty() && (dir.back() != '/'))
dir += "/";
Expand Down
3 changes: 2 additions & 1 deletion server/encoder/flac_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

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


using namespace std;
Expand All @@ -41,7 +42,7 @@ static constexpr auto LOG_TAG = "FlacEnc";

FlacEncoder::FlacEncoder(const std::string& codecOptions) : Encoder(codecOptions), encoder_(nullptr), pcmBufferSize_(0), encodedSamples_(0), flacChunk_(nullptr)
{
headerChunk_.reset(new msg::CodecHeader("flac"));
headerChunk_ = std::make_shared<msg::CodecHeader>("flac");
pcmBuffer_ = static_cast<FLAC__int32*>(malloc(pcmBufferSize_ * sizeof(FLAC__int32)));
metadata_[0] = nullptr;
metadata_[1] = nullptr;
Expand Down
7 changes: 5 additions & 2 deletions server/encoder/null_encoder.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***
This file is part of snapcast
Copyright (C) 2014-2024 Johannes Pohl
Copyright (C) 2014-2025 Johannes Pohl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -22,6 +22,9 @@
// local headers
#include "common/aixlog.hpp"

// standard headers
#include <memory>


namespace encoder
{
Expand All @@ -30,7 +33,7 @@ static constexpr auto LOG_TAG = "NullEnc";

NullEncoder::NullEncoder(const std::string& codecOptions) : Encoder(codecOptions)
{
headerChunk_.reset(new msg::CodecHeader("null"));
headerChunk_ = std::make_shared<msg::CodecHeader>("null");
}


Expand Down
9 changes: 5 additions & 4 deletions server/encoder/ogg_encoder.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***
This file is part of snapcast
Copyright (C) 2014-2024 Johannes Pohl
Copyright (C) 2014-2025 Johannes Pohl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -28,6 +28,7 @@
// standard headers
#include <cstring>
#include <iostream>
#include <memory>


using namespace std;
Expand Down Expand Up @@ -238,8 +239,8 @@ void OggEncoder::initEncoder()
/* set up our packet->stream encoder */
/* pick a random serial number; that way we can more likely build
chained streams just by concatenation */
srand(time(nullptr));
ogg_stream_init(&os_, rand());
srand(time(nullptr)); // NOLINT
ogg_stream_init(&os_, rand()); // NOLINT

/* Vorbis streams begin with three headers; the initial header (with
most of the codec setup parameters) which is mandated by the Ogg
Expand All @@ -261,7 +262,7 @@ void OggEncoder::initEncoder()
* audio data will start on a new page, as per spec
*/
size_t pos(0);
headerChunk_.reset(new msg::CodecHeader("ogg"));
headerChunk_ = std::make_shared<msg::CodecHeader>("ogg");
while (true)
{
int result = ogg_stream_flush(&os_, &og_);
Expand Down
4 changes: 2 additions & 2 deletions server/encoder/pcm_encoder.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***
This file is part of snapcast
Copyright (C) 2014-2024 Johannes Pohl
Copyright (C) 2014-2025 Johannes Pohl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -50,7 +50,7 @@ void assign(void* pointer, T val)

PcmEncoder::PcmEncoder(const std::string& codecOptions) : Encoder(codecOptions)
{
headerChunk_.reset(new msg::CodecHeader("pcm"));
headerChunk_ = std::make_shared<msg::CodecHeader>("pcm");
}


Expand Down
Loading

0 comments on commit e42a290

Please sign in to comment.