Fix dead-lock when play/stopAll immidiately

This commit is contained in:
halx99 2020-07-30 17:26:54 +08:00
parent dda5628876
commit e250fe3707
4 changed files with 10 additions and 5 deletions

View File

@ -276,11 +276,13 @@ void AudioCache::readDataTask(unsigned int selfId)
}
}
// Set before invokingPlayCallbacks, otherwise, may cause dead-lock
_isLoadingFinished = true;
//FIXME: Why to invoke play callback first? Should it be after 'load' callback?
invokingPlayCallbacks();
invokingLoadCallbacks();
_isLoadingFinished = true;
_readDataTaskMutex.unlock();
ALOGVV("readDataTask end, cache id=%u", selfId);
}

View File

@ -495,8 +495,9 @@ void AudioEngineImpl::_updateLocked(float dt)
finishCallback(audioID, filePath); //FIXME: callback will delay 50ms
});
#endif
player->setCache(nullptr); // it's safe for player didn't free audio cache
}
// clear cache when audio player finsihed properly
player->setCache(nullptr);
delete player;
_alSourceUsed[alSource] = false;
}

View File

@ -306,11 +306,13 @@ void AudioCache::readDataTask(unsigned int selfId)
decoder->close();
AudioDecoderManager::destroyDecoder(decoder);
// Set before invokingPlayCallbacks, otherwise, may cause dead-lock
_isLoadingFinished = true;
//FIXME: Why to invoke play callback first? Should it be after 'load' callback?
invokingPlayCallbacks();
invokingLoadCallbacks();
_isLoadingFinished = true;
if (_state != State::READY)
{
_state = State::FAILED;

View File

@ -751,9 +751,9 @@ void AudioEngineImpl::_updateLocked(float dt)
_finishCallbacks.push_back([finishCallback = std::move(player->_finishCallbak), audioID, filePath = std::move(filePath)](){
finishCallback(audioID, filePath); // FIXME: callback will delay 50ms
});
player->setCache(nullptr); // it's safe for player didn't free audio cache
}
// clear cache when audio player finsihed properly
player->setCache(nullptr);
delete player;
_unusedSourcesPool.push_back(alSource);
}