Fix crash caused by screen capturer or mouse controller init failed on Linux and MacOS

This commit is contained in:
dijunkun
2024-05-23 15:48:10 +08:00
parent 70be1d8afc
commit 8807636372
7 changed files with 49 additions and 15 deletions

View File

@@ -91,12 +91,15 @@ int ScreenCapturerX11::Init(const RECORD_DESKTOP_RECT &rect, const int fps,
pFrame_->width, pFrame_->height, pCodecCtx_->pix_fmt, pFrameNv12_->width,
pFrameNv12_->height, AV_PIX_FMT_NV12, SWS_BICUBIC, NULL, NULL, NULL);
inited_ = true;
return 0;
}
int ScreenCapturerX11::Destroy() {
if (capture_thread_->joinable()) {
if (inited_ && capture_thread_->joinable()) {
capture_thread_->join();
inited_ = false;
}
return 0;

View File

@@ -61,6 +61,8 @@ class ScreenCapturerX11 : public ScreenCapturer {
int videoindex_ = 0;
int got_picture_ = 0;
int fps_ = 0;
bool inited_ = false;
// ffmpeg
AVFormatContext *pFormatCtx_ = nullptr;
AVCodecContext *pCodecCtx_ = nullptr;

View File

@@ -92,12 +92,15 @@ int ScreenCapturerAvf::Init(const RECORD_DESKTOP_RECT &rect, const int fps,
pFrame_->width, pFrame_->height, pCodecCtx_->pix_fmt, pFrameNv12_->width,
pFrameNv12_->height, AV_PIX_FMT_NV12, SWS_BICUBIC, NULL, NULL, NULL);
inited_ = true;
return 0;
}
int ScreenCapturerAvf::Destroy() {
if (capture_thread_->joinable()) {
if (inited_ && capture_thread_->joinable()) {
capture_thread_->join();
inited_ = false;
}
return 0;

View File

@@ -66,6 +66,8 @@ class ScreenCapturerAvf : public ScreenCapturer {
int i_ = 0;
int videoindex_ = 0;
int got_picture_ = 0;
bool inited_ = false;
// ffmpeg
AVFormatContext *pFormatCtx_ = nullptr;
AVCodecContext *pCodecCtx_ = nullptr;