Fix dead-lock when play/stopAll immidiately

This commit is contained in:
halx99 2020-07-30 17:26:54 +08:00
parent a2800e0144
commit 72dcc33747
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? //FIXME: Why to invoke play callback first? Should it be after 'load' callback?
invokingPlayCallbacks(); invokingPlayCallbacks();
invokingLoadCallbacks(); invokingLoadCallbacks();
_isLoadingFinished = true;
_readDataTaskMutex.unlock(); _readDataTaskMutex.unlock();
ALOGVV("readDataTask end, cache id=%u", selfId); 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 finishCallback(audioID, filePath); //FIXME: callback will delay 50ms
}); });
#endif #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; delete player;
_alSourceUsed[alSource] = false; _alSourceUsed[alSource] = false;
} }

View File

@ -306,11 +306,13 @@ void AudioCache::readDataTask(unsigned int selfId)
decoder->close(); decoder->close();
AudioDecoderManager::destroyDecoder(decoder); 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? //FIXME: Why to invoke play callback first? Should it be after 'load' callback?
invokingPlayCallbacks(); invokingPlayCallbacks();
invokingLoadCallbacks(); invokingLoadCallbacks();
_isLoadingFinished = true;
if (_state != State::READY) if (_state != State::READY)
{ {
_state = State::FAILED; _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)](){ _finishCallbacks.push_back([finishCallback = std::move(player->_finishCallbak), audioID, filePath = std::move(filePath)](){
finishCallback(audioID, filePath); // FIXME: callback will delay 50ms 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; delete player;
_unusedSourcesPool.push_back(alSource); _unusedSourcesPool.push_back(alSource);
} }