From e7e6380adc927aa83a486ae2a40fedf1d9ca1120 Mon Sep 17 00:00:00 2001 From: dijunkun Date: Mon, 3 Jun 2024 23:48:53 +0800 Subject: [PATCH] Start capturing screen when connection established --- src/main_window/main_window.cpp | 5 ++--- src/main_window/main_window_callback_func.cpp | 2 ++ src/screen_capturer/linux/screen_capturer_x11.cpp | 4 ++-- src/screen_capturer/linux/screen_capturer_x11.h | 3 ++- src/screen_capturer/macosx/screen_capturer_avf.cpp | 4 ++-- src/screen_capturer/macosx/screen_capturer_avf.h | 3 ++- src/screen_capturer/screen_capturer.h | 2 ++ src/screen_capturer/windows/screen_capturer_wgc.h | 2 +- 8 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main_window/main_window.cpp b/src/main_window/main_window.cpp index aa3fbc1..01deebe 100644 --- a/src/main_window/main_window.cpp +++ b/src/main_window/main_window.cpp @@ -225,11 +225,10 @@ int MainWindow::Run() { } }); - if (0 == screen_capturer_init_ret) { - screen_capturer_->Start(); - } else { + if (0 != screen_capturer_init_ret) { screen_capturer_->Destroy(); screen_capturer_ = nullptr; + LOG_ERROR("Create screen capturer failed"); } // Mouse control diff --git a/src/main_window/main_window_callback_func.cpp b/src/main_window/main_window_callback_func.cpp index b58cfcc..5c6748f 100644 --- a/src/main_window/main_window_callback_func.cpp +++ b/src/main_window/main_window_callback_func.cpp @@ -153,12 +153,14 @@ void MainWindow::OnConnectionStatusCb(ConnectionStatus status, } else if (ConnectionStatus::Connected == status) { main_window->connection_status_str_ = "Connected"; main_window->connection_established_ = true; + main_window->screen_capturer_->Start(); } else if (ConnectionStatus::Disconnected == status) { main_window->connection_status_str_ = "Disconnected"; } else if (ConnectionStatus::Failed == status) { main_window->connection_status_str_ = "Failed"; } else if (ConnectionStatus::Closed == status) { main_window->connection_status_str_ = "Closed"; + main_window->screen_capturer_->Stop(); } else if (ConnectionStatus::IncorrectPassword == status) { main_window->connection_status_str_ = "Incorrect password"; if (main_window->connect_button_pressed_) { diff --git a/src/screen_capturer/linux/screen_capturer_x11.cpp b/src/screen_capturer/linux/screen_capturer_x11.cpp index 58d962e..69deb5e 100644 --- a/src/screen_capturer/linux/screen_capturer_x11.cpp +++ b/src/screen_capturer/linux/screen_capturer_x11.cpp @@ -133,12 +133,12 @@ int ScreenCapturerX11::Start() { return 0; } +int ScreenCapturerX11::Stop() { return 0; } + int ScreenCapturerX11::Pause() { return 0; } int ScreenCapturerX11::Resume() { return 0; } -int ScreenCapturerX11::Stop() { return 0; } - void ScreenCapturerX11::OnFrame() {} void ScreenCapturerX11::CleanUp() {} diff --git a/src/screen_capturer/linux/screen_capturer_x11.h b/src/screen_capturer/linux/screen_capturer_x11.h index d984e8f..0be5a23 100644 --- a/src/screen_capturer/linux/screen_capturer_x11.h +++ b/src/screen_capturer/linux/screen_capturer_x11.h @@ -32,9 +32,10 @@ class ScreenCapturerX11 : public ScreenCapturer { virtual int Start(); + virtual int Stop(); + int Pause(); int Resume(); - int Stop(); void OnFrame(); diff --git a/src/screen_capturer/macosx/screen_capturer_avf.cpp b/src/screen_capturer/macosx/screen_capturer_avf.cpp index d758308..e46f8e0 100644 --- a/src/screen_capturer/macosx/screen_capturer_avf.cpp +++ b/src/screen_capturer/macosx/screen_capturer_avf.cpp @@ -134,12 +134,12 @@ int ScreenCapturerAvf::Start() { return 0; } +int ScreenCapturerAvf::Stop() { return 0; } + int ScreenCapturerAvf::Pause() { return 0; } int ScreenCapturerAvf::Resume() { return 0; } -int ScreenCapturerAvf::Stop() { return 0; } - void ScreenCapturerAvf::OnFrame() {} void ScreenCapturerAvf::CleanUp() {} diff --git a/src/screen_capturer/macosx/screen_capturer_avf.h b/src/screen_capturer/macosx/screen_capturer_avf.h index 4ecc206..eacd418 100644 --- a/src/screen_capturer/macosx/screen_capturer_avf.h +++ b/src/screen_capturer/macosx/screen_capturer_avf.h @@ -38,9 +38,10 @@ class ScreenCapturerAvf : public ScreenCapturer { virtual int Start(); + virtual int Stop(); + int Pause(); int Resume(); - int Stop(); void OnFrame(); diff --git a/src/screen_capturer/screen_capturer.h b/src/screen_capturer/screen_capturer.h index 731159d..8d029aa 100644 --- a/src/screen_capturer/screen_capturer.h +++ b/src/screen_capturer/screen_capturer.h @@ -28,6 +28,8 @@ class ScreenCapturer { virtual int Destroy() = 0; virtual int Start() = 0; + + virtual int Stop() = 0; }; #endif \ No newline at end of file diff --git a/src/screen_capturer/windows/screen_capturer_wgc.h b/src/screen_capturer/windows/screen_capturer_wgc.h index c6e7f45..b004a98 100644 --- a/src/screen_capturer/windows/screen_capturer_wgc.h +++ b/src/screen_capturer/windows/screen_capturer_wgc.h @@ -27,7 +27,7 @@ class ScreenCapturerWgc : public ScreenCapturer, int Pause(); int Resume(); - int Stop(); + virtual int Stop(); void OnFrame(const WgcSession::wgc_session_frame &frame);