mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-17 19:16:14 +02:00
Clean up mutexes
This commit is contained in:
parent
12aeb5859c
commit
2efd00d8ef
8 changed files with 19 additions and 18 deletions
|
@ -576,7 +576,7 @@ class MPDWrapper(object):
|
|||
logger.debug(
|
||||
f'key: {key}, value: {value}, mapped key: {tag_mapping[key][0]}, mapped value: {snapmeta[tag_mapping[key][0]]}')
|
||||
except KeyError:
|
||||
logger.warning(f'tag "{key}" not supported')
|
||||
logger.debug(f'tag "{key}" not supported')
|
||||
except (ValueError, TypeError):
|
||||
logger.warning(
|
||||
f"Can't cast value {value} to {tag_mapping[key][1]}")
|
||||
|
@ -602,7 +602,6 @@ class MPDWrapper(object):
|
|||
if art_url is not None:
|
||||
logger.info(f'album art cache hit: "{art_url}"')
|
||||
snapmeta['artUrl'] = art_url
|
||||
|
||||
return snapmeta
|
||||
|
||||
def __diff_map(self, old_map, new_map):
|
||||
|
@ -647,12 +646,12 @@ class MPDWrapper(object):
|
|||
|
||||
new_song = self.client.currentsong()
|
||||
if not new_song:
|
||||
logger.debug("_update_properties: failed to get current song")
|
||||
logger.warning("_update_properties: failed to get current song")
|
||||
new_song = {}
|
||||
|
||||
new_status = self.client.status()
|
||||
if not new_status:
|
||||
logger.debug("_update_properties: failed to get new status")
|
||||
logger.warning("_update_properties: failed to get new status")
|
||||
new_status = {}
|
||||
|
||||
changed_status = self.__diff_map(self._status, new_status)
|
||||
|
|
|
@ -153,7 +153,7 @@ void Server::processRequest(const jsonrpcpp::request_ptr request, const OnRespon
|
|||
// Notification: {"jsonrpc":"2.0","method":"Client.OnVolumeChanged","params":{"id":"00:21:6a:7d:74:fc","volume":{"muted":false,"percent":74}}}
|
||||
// clang-format on
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lock(clientMutex_);
|
||||
// std::lock_guard<std::recursive_mutex> lock(clientMutex_);
|
||||
clientInfo->config.volume.fromJson(request->params().get("volume"));
|
||||
result["volume"] = clientInfo->config.volume.toJson();
|
||||
notification = std::make_shared<jsonrpcpp::Notification>(
|
||||
|
@ -825,6 +825,8 @@ void Server::onMessageReceived(StreamSession* streamSession, const msg::BaseMess
|
|||
|
||||
void Server::saveConfig(const std::chrono::milliseconds& deferred)
|
||||
{
|
||||
static std::mutex mutex;
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
config_timer_.cancel();
|
||||
config_timer_.expires_after(deferred);
|
||||
config_timer_.async_wait([](const boost::system::error_code& ec) {
|
||||
|
|
|
@ -90,8 +90,8 @@ private:
|
|||
/// @param deferred the delay after the last call to saveConfig
|
||||
void saveConfig(const std::chrono::milliseconds& deferred = std::chrono::seconds(2));
|
||||
|
||||
mutable std::recursive_mutex sessionsMutex_;
|
||||
mutable std::recursive_mutex clientMutex_;
|
||||
// mutable std::recursive_mutex controlMutex_;
|
||||
// mutable std::recursive_mutex clientMutex_;
|
||||
boost::asio::io_context& io_context_;
|
||||
boost::asio::steady_timer config_timer_;
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ void StreamServer::onChunkEncoded(const PcmStream* pcmStream, bool isDefaultStre
|
|||
{
|
||||
if (!settings_.stream.sendAudioToMutedClients)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(clientMutex_);
|
||||
// std::lock_guard<std::recursive_mutex> lock(clientMutex_);
|
||||
GroupPtr group = Config::instance().getGroupFromClient(session->clientId);
|
||||
if (group)
|
||||
{
|
||||
|
|
|
@ -38,14 +38,14 @@ StreamSession::StreamSession(const net::any_io_executor& executor, StreamMessage
|
|||
|
||||
void StreamSession::setPcmStream(PcmStreamPtr pcmStream)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
// std::lock_guard<std::mutex> lock(mutex_);
|
||||
pcmStream_ = pcmStream;
|
||||
}
|
||||
|
||||
|
||||
const PcmStreamPtr StreamSession::pcmStream() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
// std::lock_guard<std::mutex> lock(mutex_);
|
||||
return pcmStream_;
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ void MetaStream::stop()
|
|||
void MetaStream::onPropertiesChanged(const PcmStream* pcmStream, const Properties& properties)
|
||||
{
|
||||
LOG(DEBUG, LOG_TAG) << "onPropertiesChanged: " << pcmStream->getName() << "\n";
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
// std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (pcmStream != active_stream_.get())
|
||||
return;
|
||||
setProperties(properties);
|
||||
|
@ -97,7 +97,7 @@ void MetaStream::onPropertiesChanged(const PcmStream* pcmStream, const Propertie
|
|||
void MetaStream::onStateChanged(const PcmStream* pcmStream, ReaderState state)
|
||||
{
|
||||
LOG(DEBUG, LOG_TAG) << "onStateChanged: " << pcmStream->getName() << ", state: " << state << "\n";
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
// std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
|
||||
if (active_stream_->getProperties().playback_status == PlaybackStatus::kPaused)
|
||||
return;
|
||||
|
@ -137,7 +137,7 @@ void MetaStream::onStateChanged(const PcmStream* pcmStream, ReaderState state)
|
|||
void MetaStream::onChunkRead(const PcmStream* pcmStream, const msg::PcmChunk& chunk)
|
||||
{
|
||||
// LOG(TRACE, LOG_TAG) << "onChunkRead: " << pcmStream->getName() << ", duration: " << chunk.durationMs() << "\n";
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
// std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (pcmStream != active_stream_.get())
|
||||
return;
|
||||
// active_stream_->sampleFormat_
|
||||
|
@ -195,7 +195,7 @@ void MetaStream::onChunkEncoded(const PcmStream* pcmStream, std::shared_ptr<msg:
|
|||
void MetaStream::onResync(const PcmStream* pcmStream, double ms)
|
||||
{
|
||||
LOG(DEBUG, LOG_TAG) << "onResync: " << pcmStream->getName() << ", duration: " << ms << " ms\n";
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
// std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (pcmStream != active_stream_.get())
|
||||
return;
|
||||
resync(std::chrono::nanoseconds(static_cast<int64_t>(ms * 1000000)));
|
||||
|
|
|
@ -71,7 +71,7 @@ protected:
|
|||
protected:
|
||||
std::vector<std::shared_ptr<PcmStream>> streams_;
|
||||
std::shared_ptr<PcmStream> active_stream_;
|
||||
std::recursive_mutex mutex_;
|
||||
// std::recursive_mutex mutex_;
|
||||
std::unique_ptr<Resampler> resampler_;
|
||||
bool first_read_;
|
||||
std::chrono::time_point<std::chrono::steady_clock> next_tick_;
|
||||
|
|
|
@ -288,6 +288,7 @@ void PcmStream::resync(const std::chrono::nanoseconds& duration)
|
|||
|
||||
json PcmStream::toJson() const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
json j = {
|
||||
{"uri", uri_.toJson()},
|
||||
{"id", getId()},
|
||||
|
@ -316,7 +317,7 @@ const Metatags& PcmStream::getMetadata() const
|
|||
|
||||
const Properties& PcmStream::getProperties() const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
// std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
return properties_;
|
||||
}
|
||||
|
||||
|
@ -447,8 +448,7 @@ void PcmStream::play(ResultHandler handler)
|
|||
|
||||
void PcmStream::setProperties(const Properties& properties)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
|
||||
// std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
Properties props = properties;
|
||||
// Missing metadata means the data didn't change, so
|
||||
// enrich the new properites with old metadata
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue