mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
[fix] fix program cannot exit when click close button due to screen capture thread is running
This commit is contained in:
@@ -101,11 +101,14 @@ int ScreenCapturerX11::Init(const RECORD_DESKTOP_RECT &rect, const int fps,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScreenCapturerX11::Destroy() { return 0; }
|
int ScreenCapturerX11::Destroy() {
|
||||||
|
running_ = false;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int ScreenCapturerX11::Start() {
|
int ScreenCapturerX11::Start() {
|
||||||
capture_thread_.reset(new std::thread([this]() {
|
capture_thread_.reset(new std::thread([this]() {
|
||||||
while (1) {
|
while (running_) {
|
||||||
if (av_read_frame(pFormatCtx_, packet_) >= 0) {
|
if (av_read_frame(pFormatCtx_, packet_) >= 0) {
|
||||||
if (packet_->stream_index == videoindex_) {
|
if (packet_->stream_index == videoindex_) {
|
||||||
avcodec_send_packet(pCodecCtx_, packet_);
|
avcodec_send_packet(pCodecCtx_, packet_);
|
||||||
@@ -133,7 +136,10 @@ int ScreenCapturerX11::Start() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScreenCapturerX11::Stop() { return 0; }
|
int ScreenCapturerX11::Stop() {
|
||||||
|
running_ = false;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int ScreenCapturerX11::Pause() { return 0; }
|
int ScreenCapturerX11::Pause() { return 0; }
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ class ScreenCapturerX11 : public ScreenCapturer {
|
|||||||
|
|
||||||
// thread
|
// thread
|
||||||
std::unique_ptr<std::thread> capture_thread_ = nullptr;
|
std::unique_ptr<std::thread> capture_thread_ = nullptr;
|
||||||
|
std::atomic_bool running_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -102,11 +102,19 @@ int ScreenCapturerAvf::Init(const RECORD_DESKTOP_RECT &rect, const int fps,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScreenCapturerAvf::Destroy() { return 0; }
|
int ScreenCapturerAvf::Destroy() {
|
||||||
|
running_ = false;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int ScreenCapturerAvf::Start() {
|
int ScreenCapturerAvf::Start() {
|
||||||
|
if (_running) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
running_ = true;
|
||||||
capture_thread_.reset(new std::thread([this]() {
|
capture_thread_.reset(new std::thread([this]() {
|
||||||
while (1) {
|
while (running_) {
|
||||||
if (av_read_frame(pFormatCtx_, packet_) >= 0) {
|
if (av_read_frame(pFormatCtx_, packet_) >= 0) {
|
||||||
if (packet_->stream_index == videoindex_) {
|
if (packet_->stream_index == videoindex_) {
|
||||||
avcodec_send_packet(pCodecCtx_, packet_);
|
avcodec_send_packet(pCodecCtx_, packet_);
|
||||||
@@ -134,7 +142,10 @@ int ScreenCapturerAvf::Start() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScreenCapturerAvf::Stop() { return 0; }
|
int ScreenCapturerAvf::Stop() {
|
||||||
|
running_ = false;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int ScreenCapturerAvf::Pause() { return 0; }
|
int ScreenCapturerAvf::Pause() { return 0; }
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ class ScreenCapturerAvf : public ScreenCapturer {
|
|||||||
|
|
||||||
// thread
|
// thread
|
||||||
std::unique_ptr<std::thread> capture_thread_ = nullptr;
|
std::unique_ptr<std::thread> capture_thread_ = nullptr;
|
||||||
|
std::atomic_bool running_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -143,7 +143,8 @@ int Render::StartScreenCapture() {
|
|||||||
|
|
||||||
int Render::StopScreenCapture() {
|
int Render::StopScreenCapture() {
|
||||||
if (screen_capturer_) {
|
if (screen_capturer_) {
|
||||||
LOG_INFO("Destroy screen capturer")
|
LOG_INFO("Stop screen capturer")
|
||||||
|
screen_capturer_->Stop();
|
||||||
screen_capturer_->Destroy();
|
screen_capturer_->Destroy();
|
||||||
delete screen_capturer_;
|
delete screen_capturer_;
|
||||||
screen_capturer_ = nullptr;
|
screen_capturer_ = nullptr;
|
||||||
@@ -483,7 +484,7 @@ int Render::Run() {
|
|||||||
if (streaming_) {
|
if (streaming_) {
|
||||||
LOG_INFO("Return to main interface");
|
LOG_INFO("Return to main interface");
|
||||||
streaming_ = false;
|
streaming_ = false;
|
||||||
LeaveConnection(peer_reserved_);
|
LeaveConnection(peer_reserved_ ? peer_reserved_ : peer_);
|
||||||
rejoin_ = false;
|
rejoin_ = false;
|
||||||
memset(audio_buffer_, 0, 960);
|
memset(audio_buffer_, 0, 960);
|
||||||
connection_established_ = false;
|
connection_established_ = false;
|
||||||
@@ -506,10 +507,9 @@ int Render::Run() {
|
|||||||
|
|
||||||
if (video_width * 9 < video_height * 16) {
|
if (video_width * 9 < video_height * 16) {
|
||||||
stream_render_rect_.x = 0;
|
stream_render_rect_.x = 0;
|
||||||
stream_render_rect_.y = abs(video_height - video_width * 9 / 16) / 2 +
|
stream_render_rect_.y =
|
||||||
fullscreen_button_pressed_
|
abs(video_height - video_width * 9 / 16) / 2 +
|
||||||
? 0
|
(fullscreen_button_pressed_ ? 0 : title_bar_height_);
|
||||||
: title_bar_height_;
|
|
||||||
stream_render_rect_.w = video_width;
|
stream_render_rect_.w = video_width;
|
||||||
stream_render_rect_.h = video_width * 9 / 16;
|
stream_render_rect_.h = video_width * 9 / 16;
|
||||||
} else if (video_width * 9 > video_height * 16) {
|
} else if (video_width * 9 > video_height * 16) {
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ void Render::OnReceiveVideoBufferCb(const char *data, size_t size,
|
|||||||
event.type = REFRESH_EVENT;
|
event.type = REFRESH_EVENT;
|
||||||
SDL_PushEvent(&event);
|
SDL_PushEvent(&event);
|
||||||
render->received_frame_ = true;
|
render->received_frame_ = true;
|
||||||
|
render->streaming_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,7 +181,6 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, void *user_data) {
|
|||||||
} else if (ConnectionStatus::Connected == status) {
|
} else if (ConnectionStatus::Connected == status) {
|
||||||
render->connection_status_str_ = "Connected";
|
render->connection_status_str_ = "Connected";
|
||||||
render->connection_established_ = true;
|
render->connection_established_ = true;
|
||||||
render->streaming_ = true;
|
|
||||||
|
|
||||||
if (render->peer_reserved_ || !render->is_client_mode_) {
|
if (render->peer_reserved_ || !render->is_client_mode_) {
|
||||||
render->start_screen_capture_ = true;
|
render->start_screen_capture_ = true;
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ class SpeakerCapturerFactory {
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return new SpeakerCapturerWasapi();
|
return new SpeakerCapturerWasapi();
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
|
return new SpeakerCapturerLinux();
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
|
return new SpeakerCapturerMacosx();
|
||||||
#else
|
#else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user