diff --git a/modules/desktop_capture/ohos/base_window_capturer.cc b/modules/desktop_capture/ohos/base_window_capturer.cc index 9334d2dfda3dd745129a2c99d7381039de95c5a3..48524b6534cbed477def7e5c82f71da18cf840cc 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 f851b57239206be6ddbfdc2da490ef2bf39cfaf8..03b32aaead717d72ec102e6e27c33ae241949cf3 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_;