From 71b9a581b48a33b98d84a1e40642b638e30b7ed4 Mon Sep 17 00:00:00 2001 From: henrika Date: Mon, 25 Mar 2024 10:23:57 +0100 Subject: [PATCH] WGC capturer now fails with error when source is closed When refactoring the WGC capture path, the check of a closed source had been placed at a level where the notification of a closed source was left without being detected since the error message was never provided to the main WgcCapturerWin::CaptureFrame() which sends the error message up to the client. This trivial change ensures that WgcCapturerWin::CaptureFrame() returns with DesktopCapturer::Result::ERROR_PERMANENT as soon as WgcCaptureSession::OnItemClosed() has been triggered and it will ensure that the WGC capture session stops and that any attached MediaStreamTrack will signal its onended event as expected. Bug: chromium:330863510 Change-Id: I57e44df417c33efa0595fc277cac5429cf539b26 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/344420 Reviewed-by: Alexander Cooper Commit-Queue: Henrik Andreassson Cr-Commit-Position: refs/heads/main@{#41963} --- modules/desktop_capture/win/wgc_capture_session.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/desktop_capture/win/wgc_capture_session.cc b/modules/desktop_capture/win/wgc_capture_session.cc index 8c74c2bf24..1c86f8ed1b 100644 --- a/modules/desktop_capture/win/wgc_capture_session.cc +++ b/modules/desktop_capture/win/wgc_capture_session.cc @@ -261,6 +261,12 @@ bool WgcCaptureSession::GetFrame(std::unique_ptr* output_frame, bool source_should_be_capturable) { RTC_DCHECK_RUN_ON(&sequence_checker_); + if (item_closed_) { + RTC_LOG(LS_ERROR) << "The target source has been closed."; + RecordGetFrameResult(GetFrameResult::kItemClosed); + return false; + } + // Try to process the captured frame and wait some if needed. Avoid trying // if we know that the source will not be capturable. This can happen e.g. // when captured window is minimized and if EnsureFrame() was called in this @@ -316,12 +322,6 @@ HRESULT WgcCaptureSession::CreateMappedTexture( HRESULT WgcCaptureSession::ProcessFrame() { RTC_DCHECK_RUN_ON(&sequence_checker_); - if (item_closed_) { - RTC_LOG(LS_ERROR) << "The target source has been closed."; - RecordGetFrameResult(GetFrameResult::kItemClosed); - return E_ABORT; - } - RTC_DCHECK(is_capture_started_); ComPtr capture_frame;