From a8b5e934b8a79efd334e4e926866818eec9b1804 Mon Sep 17 00:00:00 2001 From: dijunkun Date: Thu, 29 May 2025 15:49:42 +0800 Subject: [PATCH] [feat] implementation for ScreenCapturerSck::Destroy() and ScreenCapturerSck::Stop() --- .../macosx/screen_capturer_sck.cpp | 21 ++++++++---- .../macosx/screen_capturer_sck_impl.mm | 33 +++++++++++++++++-- src/single_window/thumbnail.cpp | 2 +- thirdparty/projectx | 2 +- 4 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/screen_capturer/macosx/screen_capturer_sck.cpp b/src/screen_capturer/macosx/screen_capturer_sck.cpp index e79bd34..ec85e0c 100644 --- a/src/screen_capturer/macosx/screen_capturer_sck.cpp +++ b/src/screen_capturer/macosx/screen_capturer_sck.cpp @@ -19,15 +19,24 @@ int ScreenCapturerSck::Init(const int fps, cb_desktop_data cb) { return 0; } -int ScreenCapturerSck::Destroy() { return 0; } - -int ScreenCapturerSck::Start() { - screen_capturer_sck_impl_->Start(); - +int ScreenCapturerSck::Destroy() { + if (screen_capturer_sck_impl_) { + screen_capturer_sck_impl_->Destroy(); + } return 0; } -int ScreenCapturerSck::Stop() { return 0; } +int ScreenCapturerSck::Start() { + screen_capturer_sck_impl_->Start(); + return 0; +} + +int ScreenCapturerSck::Stop() { + if (screen_capturer_sck_impl_) { + screen_capturer_sck_impl_->Stop(); + } + return 0; +} int ScreenCapturerSck::Pause(int monitor_index) { if (screen_capturer_sck_impl_) { diff --git a/src/screen_capturer/macosx/screen_capturer_sck_impl.mm b/src/screen_capturer/macosx/screen_capturer_sck_impl.mm index a216221..d5948a9 100644 --- a/src/screen_capturer/macosx/screen_capturer_sck_impl.mm +++ b/src/screen_capturer/macosx/screen_capturer_sck_impl.mm @@ -58,9 +58,9 @@ class API_AVAILABLE(macos(14.0)) ScreenCapturerSckImpl : public ScreenCapturer { int SwitchTo(int monitor_index) override; - int Destroy() override { return 0; } + int Destroy() override; - int Stop() override { return 0; } + int Stop() override; int Pause(int monitor_index) override { return 0; } @@ -263,6 +263,35 @@ int ScreenCapturerSckImpl::SwitchTo(int monitor_index) { return 0; } +int ScreenCapturerSckImpl::Destroy() { + std::lock_guard lock(lock_); + if (stream_) { + LOG_INFO("Destroying stream"); + [stream_ stopCaptureWithCompletionHandler:nil]; + stream_ = nil; + } + current_display_ = 0; + permanent_error_ = false; + _on_data = nullptr; + [helper_ releaseCapturer]; + helper_ = nil; + + return 0; +} + +int ScreenCapturerSckImpl::Stop() { + [stream_ stopCaptureWithCompletionHandler:nil]; + std::lock_guard lock(lock_); + if (stream_) { + LOG_INFO("Stopping stream"); + [stream_ stopCaptureWithCompletionHandler:nil]; + stream_ = nil; + } + current_display_ = 0; + + return 0; +} + void ScreenCapturerSckImpl::OnShareableContentCreated(SCShareableContent *content) { if (!content) { LOG_ERROR("getShareableContent failed"); diff --git a/src/single_window/thumbnail.cpp b/src/single_window/thumbnail.cpp index 3b56a64..d323563 100644 --- a/src/single_window/thumbnail.cpp +++ b/src/single_window/thumbnail.cpp @@ -117,7 +117,7 @@ void ScaleNv12ToABGR(char* src, int src_w, int src_h, int dst_w, int dst_h, memset(dst_rgba, 0, dst_w * dst_h * 4); for (int i = 0; i < dst_w * dst_h; ++i) { - dst_rgba[i * 4 + 3] = 255; + dst_rgba[i * 4 + 3] = 0xFF; } for (int y = 0; y < fit_h; ++y) { diff --git a/thirdparty/projectx b/thirdparty/projectx index 9c5fc39..20c6ee1 160000 --- a/thirdparty/projectx +++ b/thirdparty/projectx @@ -1 +1 @@ -Subproject commit 9c5fc397de52c989c809500c4a7dbd7e0859ac41 +Subproject commit 20c6ee11f60a51249506ade144394dc11469c719