Fix crash during termination on windows

This commit is contained in:
dijunkun
2024-05-24 15:48:37 +08:00
parent f291ad189a
commit 5f1cf89649
4 changed files with 36 additions and 43 deletions

View File

@@ -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;

View File

@@ -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]() {

View File

@@ -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]() {

View File

@@ -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) {