[fix] do not recreate screen capturer when reload configuration file

This commit is contained in:
dijunkun
2025-05-28 19:15:02 +08:00
parent 7ea26854af
commit 818dab764f
4 changed files with 24 additions and 8 deletions

View File

@@ -232,6 +232,7 @@ int Render::LoadSettingsFromCacheFile() {
config_center_.SetHardwareVideoCodec(enable_hardware_video_codec_); config_center_.SetHardwareVideoCodec(enable_hardware_video_codec_);
config_center_.SetTurn(enable_turn_); config_center_.SetTurn(enable_turn_);
thumbnail_.reset();
thumbnail_ = std::make_unique<Thumbnail>(); thumbnail_ = std::make_unique<Thumbnail>();
thumbnail_->GetKeyAndIv(aes128_key_, aes128_iv_); thumbnail_->GetKeyAndIv(aes128_key_, aes128_iv_);
thumbnail_->DeleteAllFilesInDirectory(); thumbnail_->DeleteAllFilesInDirectory();
@@ -255,6 +256,7 @@ int Render::LoadSettingsFromCacheFile() {
memcpy(aes128_key_, cd_cache_.key, sizeof(cd_cache_.key)); memcpy(aes128_key_, cd_cache_.key, sizeof(cd_cache_.key));
memcpy(aes128_iv_, cd_cache_.iv, sizeof(cd_cache_.iv)); memcpy(aes128_iv_, cd_cache_.iv, sizeof(cd_cache_.iv));
thumbnail_.reset();
thumbnail_ = std::make_unique<Thumbnail>(aes128_key_, aes128_iv_); thumbnail_ = std::make_unique<Thumbnail>(aes128_key_, aes128_iv_);
language_button_value_ = cd_cache_.language; language_button_value_ = cd_cache_.language;
@@ -283,6 +285,11 @@ int Render::LoadSettingsFromCacheFile() {
} }
int Render::ScreenCapturerInit() { int Render::ScreenCapturerInit() {
if (screen_capturer_) {
LOG_INFO("Screen capturer already initialized");
return 0;
}
screen_capturer_ = (ScreenCapturer*)screen_capturer_factory_->Create(); screen_capturer_ = (ScreenCapturer*)screen_capturer_factory_->Create();
last_frame_time_ = std::chrono::duration_cast<std::chrono::milliseconds>( last_frame_time_ = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now().time_since_epoch()) std::chrono::steady_clock::now().time_since_epoch())
@@ -870,7 +877,6 @@ int Render::Run() {
const int scaled_video_width_ = 160; const int scaled_video_width_ = 160;
const int scaled_video_height_ = 90; const int scaled_video_height_ = 90;
argb_buffer_ = new char[scaled_video_width_ * scaled_video_height_ * 40];
MainLoop(); MainLoop();
@@ -1041,8 +1047,6 @@ void Render::HandleStreamWindow() {
} }
void Render::Cleanup() { void Render::Cleanup() {
delete[] argb_buffer_;
if (screen_capturer_) { if (screen_capturer_) {
screen_capturer_->Destroy(); screen_capturer_->Destroy();
delete screen_capturer_; delete screen_capturer_;
@@ -1119,6 +1123,19 @@ void Render::CleanupPeers() {
client_properties_.clear(); client_properties_.clear();
} }
void Render::CleanSubStreamWindowProperties(
std::shared_ptr<SubStreamWindowProperties> props) {
if (props->stream_texture_) {
SDL_DestroyTexture(props->stream_texture_);
props->stream_texture_ = nullptr;
}
if (props->dst_buffer_) {
delete[] props->dst_buffer_;
props->dst_buffer_ = nullptr;
}
}
void Render::UpdateRenderRect() { void Render::UpdateRenderRect() {
for (auto& [_, props] : client_properties_) { for (auto& [_, props] : client_properties_) {
if (!props->reset_control_bar_pos_) { if (!props->reset_control_bar_pos_) {
@@ -1220,8 +1237,6 @@ void Render::ProcessSdlEvent() {
memset(&props->net_traffic_stats_, 0, memset(&props->net_traffic_stats_, 0,
sizeof(props->net_traffic_stats_)); sizeof(props->net_traffic_stats_));
SDL_SetWindowFullscreen(main_window_, SDL_FALSE); SDL_SetWindowFullscreen(main_window_, SDL_FALSE);
SDL_DestroyTexture(props->stream_texture_);
props->stream_texture_ = nullptr;
SDL_FlushEvents(STREAM_FRASH, STREAM_FRASH); SDL_FlushEvents(STREAM_FRASH, STREAM_FRASH);
memset(audio_buffer_, 0, 720); memset(audio_buffer_, 0, 720);
} }

View File

@@ -130,6 +130,8 @@ class Render {
void CleanupFactories(); void CleanupFactories();
void CleanupPeer(std::shared_ptr<SubStreamWindowProperties> props); void CleanupPeer(std::shared_ptr<SubStreamWindowProperties> props);
void CleanupPeers(); void CleanupPeers();
void CleanSubStreamWindowProperties(
std::shared_ptr<SubStreamWindowProperties> props);
void UpdateRenderRect(); void UpdateRenderRect();
void ProcessSdlEvent(); void ProcessSdlEvent();
@@ -276,7 +278,6 @@ class Render {
SDL_Renderer *main_renderer_ = nullptr; SDL_Renderer *main_renderer_ = nullptr;
ImGuiContext *main_ctx_ = nullptr; ImGuiContext *main_ctx_ = nullptr;
bool exit_ = false; bool exit_ = false;
char *argb_buffer_ = nullptr;
// main window properties // main window properties
bool start_mouse_controller_ = false; bool start_mouse_controller_ = false;
@@ -337,7 +338,6 @@ class Render {
// stream window render // stream window render
SDL_Window *stream_window_ = nullptr; SDL_Window *stream_window_ = nullptr;
SDL_Renderer *stream_renderer_ = nullptr; SDL_Renderer *stream_renderer_ = nullptr;
SDL_Texture *stream_texture_ = nullptr;
ImGuiContext *stream_ctx_ = nullptr; ImGuiContext *stream_ctx_ = nullptr;
// stream window properties // stream window properties

View File

@@ -432,6 +432,7 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, const char *user_id,
SDL_UpdateTexture(props->stream_texture_, NULL, props->dst_buffer_, SDL_UpdateTexture(props->stream_texture_, NULL, props->dst_buffer_,
props->texture_width_); props->texture_width_);
} }
render->CleanSubStreamWindowProperties(props);
break; break;
case ConnectionStatus::IncorrectPassword: case ConnectionStatus::IncorrectPassword:
render->password_validating_ = false; render->password_validating_ = false;