From e2e053a2853ded5f5f47f4f1d7e78f172f1245c5 Mon Sep 17 00:00:00 2001 From: dijunkun Date: Tue, 13 Aug 2024 16:29:37 +0800 Subject: [PATCH] [fix] release NvCodec DLL only when loaded success --- src/pc/peer_connection.cpp | 14 +++----------- src/pc/peer_connection.h | 1 + 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/pc/peer_connection.cpp b/src/pc/peer_connection.cpp index ca551c9..67ae9d2 100644 --- a/src/pc/peer_connection.cpp +++ b/src/pc/peer_connection.cpp @@ -20,6 +20,7 @@ PeerConnection::~PeerConnection() { video_codec_inited_ = false; audio_codec_inited_ = false; + load_nvcodec_dll_success = false; } int PeerConnection::Init(PeerConnectionParams params, @@ -201,16 +202,6 @@ int PeerConnection::Init(PeerConnectionParams params, LOG_INFO("[{}] Init finish", user_id); - // if (0 != CreateVideoCodec(hardware_acceleration_)) { - // LOG_ERROR("Create video codec failed"); - // return -1; - // } - - // if (0 != CreateAudioCodec()) { - // LOG_ERROR("Create audio codec failed"); - // return -1; - // } - inited_ = true; return 0; } @@ -237,6 +228,7 @@ int PeerConnection::CreateVideoCodec(bool hardware_acceleration) { } else { if (hardware_acceleration_) { if (0 == LoadNvCodecDll()) { + load_nvcodec_dll_success = true; video_encoder_ = VideoEncoderFactory::CreateVideoEncoder(true, false); video_decoder_ = VideoDecoderFactory::CreateVideoDecoder(true, false); } else { @@ -614,7 +606,7 @@ int PeerConnection::Destroy() { nv12_data_ = nullptr; } - if (hardware_acceleration_) { + if (hardware_acceleration_ && load_nvcodec_dll_success) { ReleaseNvCodecDll(); } return 0; diff --git a/src/pc/peer_connection.h b/src/pc/peer_connection.h index 5100eee..7710f58 100644 --- a/src/pc/peer_connection.h +++ b/src/pc/peer_connection.h @@ -150,6 +150,7 @@ class PeerConnection { bool hardware_accelerated_decode_ = false; bool b_force_i_frame_ = false; bool video_codec_inited_ = false; + bool load_nvcodec_dll_success = false; private: std::unique_ptr audio_encoder_ = nullptr;