Fix NV12 crash issue when recreate camera object
This commit is contained in:
@@ -46,13 +46,22 @@ namespace ANSCENTER {
|
||||
Destroy();
|
||||
}
|
||||
void ANSFLVClient::Destroy() {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
if (_playerClient) {
|
||||
if (_isPlaying) {
|
||||
_playerClient->stop();
|
||||
_isPlaying = false;
|
||||
// Move player out of lock scope — close() does CUDA cleanup
|
||||
// (cuArrayDestroy/cuMemFree) which must not run under _mutex
|
||||
// to avoid deadlocking with nvcuda64 SRW lock held by inference.
|
||||
decltype(_playerClient) clientToClose;
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
if (_playerClient) {
|
||||
if (_isPlaying) {
|
||||
_playerClient->stop();
|
||||
_isPlaying = false;
|
||||
}
|
||||
}
|
||||
_playerClient->close();
|
||||
clientToClose = std::move(_playerClient);
|
||||
}
|
||||
if (clientToClose) {
|
||||
clientToClose->close();
|
||||
}
|
||||
}
|
||||
static void VerifyGlobalANSFLVLicense(const std::string& licenseKey) {
|
||||
@@ -129,8 +138,12 @@ namespace ANSCENTER {
|
||||
}
|
||||
}
|
||||
bool ANSFLVClient::Reconnect() {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
_isPlaying = false;
|
||||
}
|
||||
_playerClient->close();
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
Setup();
|
||||
_isPlaying = _playerClient->play();
|
||||
return _isPlaying;
|
||||
@@ -143,10 +156,16 @@ namespace ANSCENTER {
|
||||
return _isPlaying;
|
||||
}
|
||||
bool ANSFLVClient::Stop() {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
if (_isPlaying) {
|
||||
_playerClient->stop();
|
||||
_isPlaying = false;
|
||||
decltype(_playerClient.get()) player = nullptr;
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
if (_isPlaying) {
|
||||
_isPlaying = false;
|
||||
player = _playerClient.get();
|
||||
}
|
||||
}
|
||||
if (player) {
|
||||
player->stop();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user