From 74e29f25bf96864eb616faf881ebcd7ea066c7e2 Mon Sep 17 00:00:00 2001 From: dijunkun Date: Mon, 2 Sep 2024 16:33:01 +0800 Subject: [PATCH] [fix] do not use smart pointer to manage std::thread objects --- .../linux/screen_capturer_x11.cpp | 8 ++++---- src/screen_capturer/linux/screen_capturer_x11.h | 2 +- .../macosx/screen_capturer_avf.cpp | 8 ++++---- src/screen_capturer/macosx/screen_capturer_avf.h | 2 +- src/single_window/render.cpp | 16 +--------------- src/single_window/render_callback_func.cpp | 3 --- .../linux/speaker_capturer_linux.h | 2 +- .../macosx/speaker_capturer_macosx.h | 2 +- thirdparty/projectx | 2 +- 9 files changed, 14 insertions(+), 31 deletions(-) diff --git a/src/screen_capturer/linux/screen_capturer_x11.cpp b/src/screen_capturer/linux/screen_capturer_x11.cpp index 5a256b2..d3a298e 100644 --- a/src/screen_capturer/linux/screen_capturer_x11.cpp +++ b/src/screen_capturer/linux/screen_capturer_x11.cpp @@ -10,8 +10,8 @@ unsigned char nv12_buffer_[NV12_BUFFER_SIZE]; ScreenCapturerX11::ScreenCapturerX11() {} ScreenCapturerX11::~ScreenCapturerX11() { - if (inited_ && capture_thread_->joinable()) { - capture_thread_->join(); + if (inited_ && capture_thread_.joinable()) { + capture_thread_.join(); inited_ = false; } } @@ -107,7 +107,7 @@ int ScreenCapturerX11::Destroy() { } int ScreenCapturerX11::Start() { - capture_thread_.reset(new std::thread([this]() { + capture_thread_ = std::thread([this]() { while (running_) { if (av_read_frame(pFormatCtx_, packet_) >= 0) { if (packet_->stream_index == videoindex_) { @@ -131,7 +131,7 @@ int ScreenCapturerX11::Start() { } } } - })); + }); return 0; } diff --git a/src/screen_capturer/linux/screen_capturer_x11.h b/src/screen_capturer/linux/screen_capturer_x11.h index 27e2d7c..401d702 100644 --- a/src/screen_capturer/linux/screen_capturer_x11.h +++ b/src/screen_capturer/linux/screen_capturer_x11.h @@ -77,7 +77,7 @@ class ScreenCapturerX11 : public ScreenCapturer { struct SwsContext *img_convert_ctx_ = nullptr; // thread - std::unique_ptr capture_thread_ = nullptr; + std::thread capture_thread_; std::atomic_bool running_; }; diff --git a/src/screen_capturer/macosx/screen_capturer_avf.cpp b/src/screen_capturer/macosx/screen_capturer_avf.cpp index f9833bf..df53bca 100644 --- a/src/screen_capturer/macosx/screen_capturer_avf.cpp +++ b/src/screen_capturer/macosx/screen_capturer_avf.cpp @@ -10,8 +10,8 @@ unsigned char nv12_buffer_[NV12_BUFFER_SIZE]; ScreenCapturerAvf::ScreenCapturerAvf() {} ScreenCapturerAvf::~ScreenCapturerAvf() { - if (inited_ && capture_thread_->joinable()) { - capture_thread_->join(); + if (inited_ && capture_thread_.joinable()) { + capture_thread_.join(); inited_ = false; } } @@ -113,7 +113,7 @@ int ScreenCapturerAvf::Start() { } running_ = true; - capture_thread_.reset(new std::thread([this]() { + capture_thread_ = std::thread([this]() { while (running_) { if (av_read_frame(pFormatCtx_, packet_) >= 0) { if (packet_->stream_index == videoindex_) { @@ -137,7 +137,7 @@ int ScreenCapturerAvf::Start() { } } } - })); + }); return 0; } diff --git a/src/screen_capturer/macosx/screen_capturer_avf.h b/src/screen_capturer/macosx/screen_capturer_avf.h index df0f407..8c4381c 100644 --- a/src/screen_capturer/macosx/screen_capturer_avf.h +++ b/src/screen_capturer/macosx/screen_capturer_avf.h @@ -82,7 +82,7 @@ class ScreenCapturerAvf : public ScreenCapturer { struct SwsContext *img_convert_ctx_ = nullptr; // thread - std::unique_ptr capture_thread_ = nullptr; + std::thread capture_thread_; std::atomic_bool running_; }; diff --git a/src/single_window/render.cpp b/src/single_window/render.cpp index 8b6df2f..310c3d4 100644 --- a/src/single_window/render.cpp +++ b/src/single_window/render.cpp @@ -275,7 +275,7 @@ int Render::CreateConnectionPeer() { ConfigCenter::VIDEO_ENCODE_FORMAT::AV1 ? true : false; - params_.enable_turn = true; + params_.enable_turn = false; params_.on_receive_video_buffer = OnReceiveVideoBufferCb; params_.on_receive_audio_buffer = OnReceiveAudioBufferCb; params_.on_receive_data_buffer = OnReceiveDataBufferCb; @@ -446,20 +446,6 @@ int Render::Run() { : true; } - if (!is_create_connection_ && rejoin_ && - "Failed" == connection_status_str_) { - LeaveConnection(peer_, client_id_); - DestroyPeer(&peer_); - peer_ = CreatePeer(¶ms_); - if (peer_) { - LOG_INFO("[{}] Create peer instance successful", client_id_); - Init(peer_, client_id_); - LOG_INFO("[{}] Peer init finish", client_id_); - } else { - LOG_INFO("Create peer instance failed"); - } - } - if (!inited_ || localization_language_index_last_ != localization_language_index_) { connect_button_label_ = diff --git a/src/single_window/render_callback_func.cpp b/src/single_window/render_callback_func.cpp index 4cb355b..10f7531 100644 --- a/src/single_window/render_callback_func.cpp +++ b/src/single_window/render_callback_func.cpp @@ -198,9 +198,6 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, void *user_data) { } else if (ConnectionStatus::Failed == status) { render->connection_status_str_ = "Failed"; render->password_validating_time_ = 0; - render->is_create_connection_ = false; - render->params_.enable_turn = true; - render->rejoin_ = true; } else if (ConnectionStatus::Closed == status) { render->connection_status_str_ = "Closed"; render->password_validating_time_ = 0; diff --git a/src/speaker_capturer/linux/speaker_capturer_linux.h b/src/speaker_capturer/linux/speaker_capturer_linux.h index 9840da0..dfa532e 100644 --- a/src/speaker_capturer/linux/speaker_capturer_linux.h +++ b/src/speaker_capturer/linux/speaker_capturer_linux.h @@ -32,7 +32,7 @@ class SpeakerCapturerLinux : public SpeakerCapturer { private: bool inited_ = false; // thread - std::unique_ptr capture_thread_ = nullptr; + std::thread capture_thread_; }; #endif \ No newline at end of file diff --git a/src/speaker_capturer/macosx/speaker_capturer_macosx.h b/src/speaker_capturer/macosx/speaker_capturer_macosx.h index 749f5dd..2ffe2aa 100644 --- a/src/speaker_capturer/macosx/speaker_capturer_macosx.h +++ b/src/speaker_capturer/macosx/speaker_capturer_macosx.h @@ -32,7 +32,7 @@ class SpeakerCapturerMacosx : public SpeakerCapturer { private: bool inited_ = false; // thread - std::unique_ptr capture_thread_ = nullptr; + std::thread capture_thread_; }; #endif \ No newline at end of file diff --git a/thirdparty/projectx b/thirdparty/projectx index 0b11646..98bd477 160000 --- a/thirdparty/projectx +++ b/thirdparty/projectx @@ -1 +1 @@ -Subproject commit 0b11646619fb88c5a802b583551d9c63d3ae8215 +Subproject commit 98bd477af5c212b385ae55651c6c203065de9083