From 34b1150fe7ee9f19276fcd990aae4cb5e9696105 Mon Sep 17 00:00:00 2001 From: xiongjun_gitee Date: Tue, 28 May 2024 10:11:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3web=E5=BD=95=E5=B1=8Fbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiongjun_gitee --- .../ohos/base_window_capturer.cc | 29 +++++++++++++++---- .../ohos/base_window_capturer.h | 2 ++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/modules/desktop_capture/ohos/base_window_capturer.cc b/modules/desktop_capture/ohos/base_window_capturer.cc index 9334d2df..48524b65 100644 --- a/modules/desktop_capture/ohos/base_window_capturer.cc +++ b/modules/desktop_capture/ohos/base_window_capturer.cc @@ -341,6 +341,21 @@ void BaseWindowCapturer::Start(Callback* callback) { LOG(INFO) << "start capture success"; } +DesktopCapturer::Result BaseWindowCapturer::HandleCaptureStateCode(const OHOS::NWeb::ScreenCaptureStateCodeAdapter& code) { + switch (code) { + case OHOS::NWeb::ScreenCaptureStateCodeAdapter::SCREEN_CAPTURE_STATE_CANCELED: + case OHOS::NWeb::ScreenCaptureStateCodeAdapter::SCREEN_CAPTURE_STATE_STOPPED_BY_USER: + case OHOS::NWeb::ScreenCaptureStateCodeAdapter::SCREEN_CAPTURE_STATE_INTERRUPTED_BY_OTHER: + case OHOS::NWeb::ScreenCaptureStateCodeAdapter::SCREEN_CAPTURE_STATE_STOPPED_BY_CALL: + return DesktopCapturer::Result::ERROR_PERMANENT; + case OHOS::NWeb::ScreenCaptureStateCodeAdapter::SCREEN_CAPTURE_STATE_ENTER_PRIVATE_SCENE: + return DesktopCapturer::Result::ERROR_TEMPORARY; + default: + break; + } + return DesktopCapturer::Result::SUCCESS; +} + void BaseWindowCapturer::CaptureFrame() { if (portal_init_failed_) { callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); @@ -348,15 +363,19 @@ void BaseWindowCapturer::CaptureFrame() { } std::unique_ptr current_frame; + OHOS::NWeb::ScreenCaptureStateCodeAdapter capture_state_code; { webrtc::MutexLock lock(¤t_frame_lock_); - if (capture_state_code_ == OHOS::NWeb::ScreenCaptureStateCodeAdapter::SCREEN_CAPTURE_STATE_CANCELED) { - LOG(INFO) << "start capture SCREEN_CAPTURE_STATE_CANCELED"; - callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); - return; - } + capture_state_code = capture_state_code_; current_frame = std::move(current_frame_); } + DesktopCapturer::Result result = HandleCaptureStateCode(capture_state_code); + if (result != DesktopCapturer::Result::SUCCESS) { + LOG(INFO) << "start capture interrupted or stopped"; + callback_->OnCaptureResult(result, nullptr); + return; + } + if (!current_frame) { callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); return; diff --git a/modules/desktop_capture/ohos/base_window_capturer.h b/modules/desktop_capture/ohos/base_window_capturer.h index f851b572..03b32aae 100755 --- a/modules/desktop_capture/ohos/base_window_capturer.h +++ b/modules/desktop_capture/ohos/base_window_capturer.h @@ -62,6 +62,8 @@ class BaseWindowCapturer : public DesktopCapturer { void SetScreenCaptureState(const OHOS::NWeb::ScreenCaptureStateCodeAdapter& stateCode); private: + static DesktopCapturer::Result HandleCaptureStateCode(const OHOS::NWeb::ScreenCaptureStateCodeAdapter& code); + webrtc::Mutex current_frame_lock_; std::unique_ptr current_frame_; -- Gitee