diff --git a/modules/desktop_capture/ohos/base_window_capturer.cc b/modules/desktop_capture/ohos/base_window_capturer.cc index e75caf9e642a5e7b4673c0a03b5755c2f7960fc2..9334d2dfda3dd745129a2c99d7381039de95c5a3 100644 --- a/modules/desktop_capture/ohos/base_window_capturer.cc +++ b/modules/desktop_capture/ohos/base_window_capturer.cc @@ -145,6 +145,12 @@ class OHOSScreenCaptureCallback base::BindOnce(&BaseWindowCapturer::HandleBuffer, capturer_)); } + void OnStateChange(OHOS::NWeb::ScreenCaptureStateCodeAdapter stateCode) override { + task_runner_->PostTask( + FROM_HERE, + base::BindOnce(&BaseWindowCapturer::SetScreenCaptureState, capturer_, stateCode)); + } + private: scoped_refptr task_runner_; base::WeakPtr capturer_; @@ -307,6 +313,13 @@ void BaseWindowCapturer::HandleBuffer() { screen_capture_adapter_->ReleaseVideoBuffer(); } +void BaseWindowCapturer::SetScreenCaptureState(const OHOS::NWeb::ScreenCaptureStateCodeAdapter& stateCode) { + { + webrtc::MutexLock lock(¤t_frame_lock_); + capture_state_code_ = stateCode; + } +} + void BaseWindowCapturer::Start(Callback* callback) { RTC_DCHECK(!callback_); RTC_DCHECK(callback); @@ -337,6 +350,11 @@ void BaseWindowCapturer::CaptureFrame() { std::unique_ptr current_frame; { 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; + } current_frame = std::move(current_frame_); } if (!current_frame) { diff --git a/modules/desktop_capture/ohos/base_window_capturer.h b/modules/desktop_capture/ohos/base_window_capturer.h index 298dbfcf8033bba3320b05c72aaacf7fac91d1e8..f851b57239206be6ddbfdc2da490ef2bf39cfaf8 100755 --- a/modules/desktop_capture/ohos/base_window_capturer.h +++ b/modules/desktop_capture/ohos/base_window_capturer.h @@ -59,11 +59,16 @@ class BaseWindowCapturer : public DesktopCapturer { void HandleBuffer(); + void SetScreenCaptureState(const OHOS::NWeb::ScreenCaptureStateCodeAdapter& stateCode); + private: webrtc::Mutex current_frame_lock_; std::unique_ptr current_frame_; + OHOS::NWeb::ScreenCaptureStateCodeAdapter capture_state_code_ = + OHOS::NWeb::ScreenCaptureStateCodeAdapter::SCREEN_CAPTURE_STATE_INVLID; + Callback* callback_ = nullptr; CaptureSourceType capture_source_type_ =