diff --git a/src/device_controller/mouse/linux/mouse_controller.cpp b/src/device_controller/mouse/linux/mouse_controller.cpp index b0f801a..732260e 100644 --- a/src/device_controller/mouse/linux/mouse_controller.cpp +++ b/src/device_controller/mouse/linux/mouse_controller.cpp @@ -4,7 +4,12 @@ MouseController::MouseController() {} -MouseController::~MouseController() {} +MouseController::~MouseController() { + if (uinput_fd_) { + ioctl(uinput_fd_, UI_DEV_DESTROY); + close(uinput_fd_); + } +} int MouseController::Init(int screen_width, int screen_height) { screen_width_ = screen_width; @@ -41,13 +46,7 @@ int MouseController::Init(int screen_width, int screen_height) { return 0; } -int MouseController::Destroy() { - if (uinput_fd_) { - ioctl(uinput_fd_, UI_DEV_DESTROY); - close(uinput_fd_); - } - return 0; -} +int MouseController::Destroy() { return 0; } int MouseController::SendCommand(RemoteAction remote_action) { int mouse_pos_x = remote_action.m.x * screen_width_ / 1280; diff --git a/src/screen_capturer/linux/screen_capturer_x11.cpp b/src/screen_capturer/linux/screen_capturer_x11.cpp index fb390db..58d962e 100644 --- a/src/screen_capturer/linux/screen_capturer_x11.cpp +++ b/src/screen_capturer/linux/screen_capturer_x11.cpp @@ -9,7 +9,12 @@ unsigned char nv12_buffer_[NV12_BUFFER_SIZE]; ScreenCapturerX11::ScreenCapturerX11() {} -ScreenCapturerX11::~ScreenCapturerX11() {} +ScreenCapturerX11::~ScreenCapturerX11() { + if (inited_ && capture_thread_->joinable()) { + capture_thread_->join(); + inited_ = false; + } +} int ScreenCapturerX11::Init(const RECORD_DESKTOP_RECT &rect, const int fps, cb_desktop_data cb) { @@ -96,14 +101,7 @@ int ScreenCapturerX11::Init(const RECORD_DESKTOP_RECT &rect, const int fps, return 0; } -int ScreenCapturerX11::Destroy() { - if (inited_ && capture_thread_->joinable()) { - capture_thread_->join(); - inited_ = false; - } - - return 0; -} +int ScreenCapturerX11::Destroy() { return 0; } int ScreenCapturerX11::Start() { capture_thread_.reset(new std::thread([this]() { diff --git a/src/screen_capturer/macosx/screen_capturer_avf.cpp b/src/screen_capturer/macosx/screen_capturer_avf.cpp index d6c4648..d758308 100644 --- a/src/screen_capturer/macosx/screen_capturer_avf.cpp +++ b/src/screen_capturer/macosx/screen_capturer_avf.cpp @@ -9,7 +9,12 @@ unsigned char nv12_buffer_[NV12_BUFFER_SIZE]; ScreenCapturerAvf::ScreenCapturerAvf() {} -ScreenCapturerAvf::~ScreenCapturerAvf() {} +ScreenCapturerAvf::~ScreenCapturerAvf() { + if (inited_ && capture_thread_->joinable()) { + capture_thread_->join(); + inited_ = false; + } +} int ScreenCapturerAvf::Init(const RECORD_DESKTOP_RECT &rect, const int fps, cb_desktop_data cb) { @@ -97,14 +102,7 @@ int ScreenCapturerAvf::Init(const RECORD_DESKTOP_RECT &rect, const int fps, return 0; } -int ScreenCapturerAvf::Destroy() { - if (inited_ && capture_thread_->joinable()) { - capture_thread_->join(); - inited_ = false; - } - - return 0; -} +int ScreenCapturerAvf::Destroy() { return 0; } int ScreenCapturerAvf::Start() { capture_thread_.reset(new std::thread([this]() { diff --git a/src/screen_capturer/windows/screen_capturer_wgc.cpp b/src/screen_capturer/windows/screen_capturer_wgc.cpp index a79a04b..a84e7b7 100644 --- a/src/screen_capturer/windows/screen_capturer_wgc.cpp +++ b/src/screen_capturer/windows/screen_capturer_wgc.cpp @@ -35,7 +35,20 @@ HMONITOR GetPrimaryMonitor() { ScreenCapturerWgc::ScreenCapturerWgc() {} -ScreenCapturerWgc::~ScreenCapturerWgc() {} +ScreenCapturerWgc::~ScreenCapturerWgc() { + Stop(); + CleanUp(); + + if (nv12_frame_) { + delete nv12_frame_; + nv12_frame_ = nullptr; + } + + if (nv12_frame_scaled_) { + delete nv12_frame_scaled_; + nv12_frame_scaled_ = nullptr; + } +} bool ScreenCapturerWgc::IsWgcSupported() { try { @@ -91,22 +104,7 @@ int ScreenCapturerWgc::Init(const RECORD_DESKTOP_RECT &rect, const int fps, return error; } -int ScreenCapturerWgc::Destroy() { - if (nv12_frame_) { - delete nv12_frame_; - nv12_frame_ = nullptr; - } - - if (nv12_frame_scaled_) { - delete nv12_frame_scaled_; - nv12_frame_scaled_ = nullptr; - } - - Stop(); - CleanUp(); - - return 0; -} +int ScreenCapturerWgc::Destroy() { return 0; } int ScreenCapturerWgc::Start() { if (_running == true) {