From 9396a78d7156e91a1fd08fbfb6d86c326dc3984a Mon Sep 17 00:00:00 2001 From: badaix Date: Fri, 20 Dec 2024 22:25:30 +0100 Subject: [PATCH] Fix compile error --- client/player/alsa_player.cpp | 18 +++++++++--------- client/player/alsa_player.hpp | 1 + client/player/player.cpp | 6 +++--- client/player/player.hpp | 2 +- client/player/pulse_player.cpp | 4 ++-- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/client/player/alsa_player.cpp b/client/player/alsa_player.cpp index 3c1c89f6..f9bbf773 100644 --- a/client/player/alsa_player.cpp +++ b/client/player/alsa_player.cpp @@ -50,7 +50,7 @@ static constexpr auto DEFAULT_MIXER = "PCM"; AlsaPlayer::AlsaPlayer(boost::asio::io_context& io_context, const ClientSettings::Player& settings, std::shared_ptr stream) - : Player(io_context, settings, stream), handle_(nullptr), ctl_(nullptr), mixer_(nullptr), elem_(nullptr), sd_(io_context), timer_(io_context) + : Player(io_context, settings, std::move(stream)), handle_(nullptr), ctl_(nullptr), mixer_(nullptr), elem_(nullptr), sd_(io_context), timer_(io_context) { if (settings_.mixer.mode == ClientSettings::Mixer::Mode::hardware) { @@ -93,7 +93,7 @@ AlsaPlayer::AlsaPlayer(boost::asio::io_context& io_context, const ClientSettings void AlsaPlayer::setHardwareVolume(const Volume& volume) { - std::lock_guard lock(mutex_); + std::lock_guard lock(rec_mutex_); if (elem_ == nullptr) return; @@ -140,7 +140,7 @@ bool AlsaPlayer::getHardwareVolume(Volume& volume) { try { - std::lock_guard lock(mutex_); + std::lock_guard lock(rec_mutex_); if (elem_ == nullptr) throw SnapException("Mixer not initialized"); @@ -201,7 +201,7 @@ void AlsaPlayer::waitForEvent() return; } - std::lock_guard lock(mutex_); + std::lock_guard lock(rec_mutex_); if (ctl_ == nullptr) return; @@ -250,7 +250,7 @@ void AlsaPlayer::initMixer() return; LOG(DEBUG, LOG_TAG) << "initMixer\n"; - std::lock_guard lock(mutex_); + std::lock_guard lock(rec_mutex_); int err; if ((err = snd_ctl_open(&ctl_, mixer_device_.c_str(), SND_CTL_READONLY)) < 0) throw SnapException("Can't open control for " + mixer_device_ + ", error: " + snd_strerror(err)); @@ -292,7 +292,7 @@ void AlsaPlayer::initMixer() void AlsaPlayer::initAlsa() { - std::lock_guard lock(mutex_); + std::lock_guard lock(rec_mutex_); const SampleFormat& format = stream_->getFormat(); uint32_t rate = format.rate(); @@ -461,7 +461,7 @@ void AlsaPlayer::initAlsa() void AlsaPlayer::uninitAlsa(bool uninit_mixer) { - std::lock_guard lock(mutex_); + std::lock_guard lock(rec_mutex_); if (uninit_mixer) uninitMixer(); @@ -480,7 +480,7 @@ void AlsaPlayer::uninitMixer() return; LOG(DEBUG, LOG_TAG) << "uninitMixer\n"; - std::lock_guard lock(mutex_); + std::lock_guard lock(rec_mutex_); if (sd_.is_open()) { boost::system::error_code ec; @@ -587,7 +587,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() << "\n"; chronos::sleep(100); } if (handle_ == nullptr) diff --git a/client/player/alsa_player.hpp b/client/player/alsa_player.hpp index fda6209a..c930eceb 100644 --- a/client/player/alsa_player.hpp +++ b/client/player/alsa_player.hpp @@ -86,6 +86,7 @@ private: snd_pcm_uframes_t frames_; boost::asio::posix::stream_descriptor sd_; std::chrono::time_point last_change_; + std::recursive_mutex rec_mutex_; boost::asio::steady_timer timer_; std::optional buffer_time_; diff --git a/client/player/player.cpp b/client/player/player.cpp index 16cb699f..f1d4ee10 100644 --- a/client/player/player.cpp +++ b/client/player/player.cpp @@ -48,7 +48,7 @@ namespace player 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), volCorrection_(1.0) + : io_context_(io_context), active_(false), stream_(std::move(stream)), settings_(settings), volCorrection_(1.0) { string sharing_mode; switch (settings_.sharing_mode) @@ -92,8 +92,8 @@ Player::Player(boost::asio::io_context& io_context, const ClientSettings::Player break; } LOG(INFO, LOG_TAG) << "Mixer mode: " << mixer << ", parameters: " << not_empty(settings_.mixer.parameter) << "\n"; - LOG(INFO, LOG_TAG) << "Sampleformat: " << (settings_.sample_format.isInitialized() ? settings_.sample_format.toString() : stream->getFormat().toString()) - << ", stream: " << stream->getFormat().toString() << "\n"; + LOG(INFO, LOG_TAG) << "Sampleformat: " << (settings_.sample_format.isInitialized() ? settings_.sample_format.toString() : stream_->getFormat().toString()) + << ", stream: " << stream_->getFormat().toString() << "\n"; } diff --git a/client/player/player.hpp b/client/player/player.hpp index f20dffd6..fbad0825 100644 --- a/client/player/player.hpp +++ b/client/player/player.hpp @@ -117,7 +117,7 @@ private: template void adjustVolume(char* buffer, size_t count, double volume) { - auto* bufferT = static_cast(buffer); + auto* bufferT = reinterpret_cast(buffer); for (size_t n = 0; n < count; ++n) bufferT[n] = endian::swap(static_cast(endian::swap(bufferT[n]) * volume)); } diff --git a/client/player/pulse_player.cpp b/client/player/pulse_player.cpp index 6c578457..05ec4d65 100644 --- a/client/player/pulse_player.cpp +++ b/client/player/pulse_player.cpp @@ -145,7 +145,7 @@ vector PulsePlayer::pcm_list(const std::string& parameter) PulsePlayer::PulsePlayer(boost::asio::io_context& io_context, const ClientSettings::Player& settings, std::shared_ptr stream) - : Player(io_context, settings, stream), latency_(BUFFER_TIME), last_chunk_tick_(0), pa_ml_(nullptr), pa_ctx_(nullptr), playstream_(nullptr), + : Player(io_context, settings, std::move(stream)), latency_(BUFFER_TIME), last_chunk_tick_(0), pa_ml_(nullptr), pa_ctx_(nullptr), playstream_(nullptr), proplist_(nullptr), server_(std::nullopt) { auto params = utils::string::split_pairs_to_container>(settings.parameter, ',', '='); @@ -210,7 +210,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() << "\n"; disconnect(); chronos::sleep(100); }