Fix compile error

This commit is contained in:
badaix 2024-12-20 22:25:30 +01:00
parent 17efc6799c
commit 9396a78d71
5 changed files with 16 additions and 15 deletions

View file

@ -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> stream) AlsaPlayer::AlsaPlayer(boost::asio::io_context& io_context, const ClientSettings::Player& settings, std::shared_ptr<Stream> 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) 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) void AlsaPlayer::setHardwareVolume(const Volume& volume)
{ {
std::lock_guard<std::recursive_mutex> lock(mutex_); std::lock_guard<std::recursive_mutex> lock(rec_mutex_);
if (elem_ == nullptr) if (elem_ == nullptr)
return; return;
@ -140,7 +140,7 @@ bool AlsaPlayer::getHardwareVolume(Volume& volume)
{ {
try try
{ {
std::lock_guard<std::recursive_mutex> lock(mutex_); std::lock_guard<std::recursive_mutex> lock(rec_mutex_);
if (elem_ == nullptr) if (elem_ == nullptr)
throw SnapException("Mixer not initialized"); throw SnapException("Mixer not initialized");
@ -201,7 +201,7 @@ void AlsaPlayer::waitForEvent()
return; return;
} }
std::lock_guard<std::recursive_mutex> lock(mutex_); std::lock_guard<std::recursive_mutex> lock(rec_mutex_);
if (ctl_ == nullptr) if (ctl_ == nullptr)
return; return;
@ -250,7 +250,7 @@ void AlsaPlayer::initMixer()
return; return;
LOG(DEBUG, LOG_TAG) << "initMixer\n"; LOG(DEBUG, LOG_TAG) << "initMixer\n";
std::lock_guard<std::recursive_mutex> lock(mutex_); std::lock_guard<std::recursive_mutex> lock(rec_mutex_);
int err; 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)) < 0)
throw SnapException("Can't open control for " + mixer_device_ + ", error: " + snd_strerror(err)); throw SnapException("Can't open control for " + mixer_device_ + ", error: " + snd_strerror(err));
@ -292,7 +292,7 @@ void AlsaPlayer::initMixer()
void AlsaPlayer::initAlsa() void AlsaPlayer::initAlsa()
{ {
std::lock_guard<std::recursive_mutex> lock(mutex_); std::lock_guard<std::recursive_mutex> lock(rec_mutex_);
const SampleFormat& format = stream_->getFormat(); const SampleFormat& format = stream_->getFormat();
uint32_t rate = format.rate(); uint32_t rate = format.rate();
@ -461,7 +461,7 @@ void AlsaPlayer::initAlsa()
void AlsaPlayer::uninitAlsa(bool uninit_mixer) void AlsaPlayer::uninitAlsa(bool uninit_mixer)
{ {
std::lock_guard<std::recursive_mutex> lock(mutex_); std::lock_guard<std::recursive_mutex> lock(rec_mutex_);
if (uninit_mixer) if (uninit_mixer)
uninitMixer(); uninitMixer();
@ -480,7 +480,7 @@ void AlsaPlayer::uninitMixer()
return; return;
LOG(DEBUG, LOG_TAG) << "uninitMixer\n"; LOG(DEBUG, LOG_TAG) << "uninitMixer\n";
std::lock_guard<std::recursive_mutex> lock(mutex_); std::lock_guard<std::recursive_mutex> lock(rec_mutex_);
if (sd_.is_open()) if (sd_.is_open())
{ {
boost::system::error_code ec; boost::system::error_code ec;
@ -587,7 +587,7 @@ void AlsaPlayer::worker()
} }
catch (const std::exception& e) 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); chronos::sleep(100);
} }
if (handle_ == nullptr) if (handle_ == nullptr)

View file

@ -86,6 +86,7 @@ private:
snd_pcm_uframes_t frames_; snd_pcm_uframes_t frames_;
boost::asio::posix::stream_descriptor sd_; boost::asio::posix::stream_descriptor sd_;
std::chrono::time_point<std::chrono::steady_clock> last_change_; std::chrono::time_point<std::chrono::steady_clock> last_change_;
std::recursive_mutex rec_mutex_;
boost::asio::steady_timer timer_; boost::asio::steady_timer timer_;
std::optional<std::chrono::microseconds> buffer_time_; std::optional<std::chrono::microseconds> buffer_time_;

View file

@ -48,7 +48,7 @@ namespace player
static constexpr auto LOG_TAG = "Player"; static constexpr auto LOG_TAG = "Player";
Player::Player(boost::asio::io_context& io_context, const ClientSettings::Player& settings, std::shared_ptr<Stream> stream) Player::Player(boost::asio::io_context& io_context, const ClientSettings::Player& settings, std::shared_ptr<Stream> 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; string sharing_mode;
switch (settings_.sharing_mode) switch (settings_.sharing_mode)
@ -92,8 +92,8 @@ Player::Player(boost::asio::io_context& io_context, const ClientSettings::Player
break; break;
} }
LOG(INFO, LOG_TAG) << "Mixer mode: " << mixer << ", parameters: " << not_empty(settings_.mixer.parameter) << "\n"; 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()) LOG(INFO, LOG_TAG) << "Sampleformat: " << (settings_.sample_format.isInitialized() ? settings_.sample_format.toString() : stream_->getFormat().toString())
<< ", stream: " << stream->getFormat().toString() << "\n"; << ", stream: " << stream_->getFormat().toString() << "\n";
} }

View file

@ -117,7 +117,7 @@ private:
template <typename T> template <typename T>
void adjustVolume(char* buffer, size_t count, double volume) void adjustVolume(char* buffer, size_t count, double volume)
{ {
auto* bufferT = static_cast<T*>(buffer); auto* bufferT = reinterpret_cast<T*>(buffer);
for (size_t n = 0; n < count; ++n) for (size_t n = 0; n < count; ++n)
bufferT[n] = endian::swap<T>(static_cast<T>(endian::swap<T>(bufferT[n]) * volume)); bufferT[n] = endian::swap<T>(static_cast<T>(endian::swap<T>(bufferT[n]) * volume));
} }

View file

@ -145,7 +145,7 @@ vector<PcmDevice> PulsePlayer::pcm_list(const std::string& parameter)
PulsePlayer::PulsePlayer(boost::asio::io_context& io_context, const ClientSettings::Player& settings, std::shared_ptr<Stream> stream) PulsePlayer::PulsePlayer(boost::asio::io_context& io_context, const ClientSettings::Player& settings, std::shared_ptr<Stream> 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) proplist_(nullptr), server_(std::nullopt)
{ {
auto params = utils::string::split_pairs_to_container<std::vector<std::string>>(settings.parameter, ',', '='); auto params = utils::string::split_pairs_to_container<std::vector<std::string>>(settings.parameter, ',', '=');
@ -210,7 +210,7 @@ void PulsePlayer::worker()
} }
catch (const std::exception& e) 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(); disconnect();
chronos::sleep(100); chronos::sleep(100);
} }