mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35: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;
|
||||
}
|
||||
|
||||
int ScreenCapturerX11::Destroy() { return 0; }
|
||||
int ScreenCapturerX11::Destroy() {
|
||||
running_ = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ScreenCapturerX11::Start() {
|
||||
capture_thread_.reset(new std::thread([this]() {
|
||||
while (1) {
|
||||
while (running_) {
|
||||
if (av_read_frame(pFormatCtx_, packet_) >= 0) {
|
||||
if (packet_->stream_index == videoindex_) {
|
||||
avcodec_send_packet(pCodecCtx_, packet_);
|
||||
@@ -133,7 +136,10 @@ int ScreenCapturerX11::Start() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ScreenCapturerX11::Stop() { return 0; }
|
||||
int ScreenCapturerX11::Stop() {
|
||||
running_ = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ScreenCapturerX11::Pause() { return 0; }
|
||||
|
||||
|
||||
@@ -78,6 +78,7 @@ class ScreenCapturerX11 : public ScreenCapturer {
|
||||
|
||||
// thread
|
||||
std::unique_ptr<std::thread> capture_thread_ = nullptr;
|
||||
std::atomic_bool running_;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -102,11 +102,19 @@ int ScreenCapturerAvf::Init(const RECORD_DESKTOP_RECT &rect, const int fps,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ScreenCapturerAvf::Destroy() { return 0; }
|
||||
int ScreenCapturerAvf::Destroy() {
|
||||
running_ = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ScreenCapturerAvf::Start() {
|
||||
if (_running) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
running_ = true;
|
||||
capture_thread_.reset(new std::thread([this]() {
|
||||
while (1) {
|
||||
while (running_) {
|
||||
if (av_read_frame(pFormatCtx_, packet_) >= 0) {
|
||||
if (packet_->stream_index == videoindex_) {
|
||||
avcodec_send_packet(pCodecCtx_, packet_);
|
||||
@@ -134,7 +142,10 @@ int ScreenCapturerAvf::Start() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ScreenCapturerAvf::Stop() { return 0; }
|
||||
int ScreenCapturerAvf::Stop() {
|
||||
running_ = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ScreenCapturerAvf::Pause() { return 0; }
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ class ScreenCapturerAvf : public ScreenCapturer {
|
||||
|
||||
// thread
|
||||
std::unique_ptr<std::thread> capture_thread_ = nullptr;
|
||||
std::atomic_bool running_;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user