fixed cspot crash when switching with LMS

This commit is contained in:
Philippe G
2021-12-25 23:05:53 -08:00
parent 1422003271
commit 676acbdbc2
5 changed files with 13 additions and 4 deletions

View File

@@ -45,8 +45,8 @@ void AudioChunkManager::close() {
}
void AudioChunkManager::runTask() {
this->isRunning = true;
std::scoped_lock lock(this->runningMutex);
this->isRunning = true;
while (isRunning) {
std::pair<std::vector<uint8_t>, bool> audioPair;
if (this->audioChunkDataQueue.wtpop(audioPair, 100)) {

View File

@@ -29,6 +29,8 @@ MercuryManager::MercuryManager(std::unique_ptr<Session> session): bell::Task("me
bool MercuryManager::timeoutHandler()
{
if (!isRunning) return true;
auto currentTimestamp = timeProvider->getSyncedTimestamp();
if (this->lastRequestTimestamp != -1 && currentTimestamp - this->lastRequestTimestamp > AUDIOCHUNK_TIMEOUT_MS)
@@ -161,7 +163,7 @@ void MercuryManager::runTask()
}
catch (const std::runtime_error& e)
{
if (!isRunning) break;
if (!isRunning) break;
// Reconnection required
this->reconnect();
this->reconnectedCallback();
@@ -189,10 +191,11 @@ void MercuryManager::runTask()
}
void MercuryManager::stop() {
std::scoped_lock stop(this->stopMutex);
CSPOT_LOG(debug, "Stopping mercury manager");
isRunning = false;
audioChunkManager->close();
std::scoped_lock lock(audioChunkManager->runningMutex, this->runningMutex);
std::scoped_lock lock(this->runningMutex);
CSPOT_LOG(debug, "mercury stopped");
}
@@ -274,6 +277,8 @@ void MercuryManager::handleQueue()
{
this->updateQueue();
}
std::scoped_lock lock(this->stopMutex);
}
uint64_t MercuryManager::execute(MercuryType method, std::string uri, mercuryCallback& callback, mercuryCallback& subscription, mercuryParts& payload)

View File

@@ -55,7 +55,8 @@ void SpircController::disconnect(void) {
player->cancelCurrentTrack();
state->setActive(false);
notify();
sendEvent(CSpotEventType::DISC);
// Send the event at the end at it might be a last gasp
sendEvent(CSpotEventType::DISC);
}
void SpircController::playToggle() {