Skip to content

Commit cfdcb25

Browse files
committed
Bug 1871981 - Vendor libwebrtc from b0cc68e612
Upstream commit: https://webrtc.googlesource.com/src/+/b0cc68e61205fd11a7256a6e85307ec17ad95790 Reduces rate at which TryGetNextFrame returns NULL for WGC This CL is a follow-up of work done in https://webrtc-review.googlesource.com/c/src/+/323882 where the goal was to reduce the amount of FrameDropped error logs in WebRTC.DesktopCapture.Win.WgcCaptureSessionGetFrameResult. The previous work avoids FrameDropped logs for a minimized window being captured with WGC but we still se a large amount of these error (or rather warning) logs. See [1] which comes from Canary. This CL does two different things to improve the situation: 1) It adds kFramePoolEmpty to the existing GetFrameResult::kFrameDropped enum to point out that the warning comes from the frame pool not being able to return a valid new frame. It also makes it more clear that it does not cause an outer/final error as WgcCapturerResult::kFrameDropped. We still keep the inner GetFrameResult::kFrameDropped but it is only produced when the frame pool returns NULL and our external queue is empty. Hence, a real frame-drop error. Note that, it is still easy to provoke kFramePoolEmpty simply by asking for a high resolution at a high rate. The example in [2] comes from a 4K screen 30fps. Hence, we have not fixed anything yet. 2) It also increases the size of the internal frame pool from 1 to 2. This does lead to an almost zero rate of kFramePoolEmpt warnings at the expense of a slightly reduced max capture rate. BUT, with 1 as size, we can "see" a higher max capture rate but it is not a true rate since it comes with a high rate of kFramePoolEmpty errors. Hence, we "emulate" a high capture rate by simply feeding copies of the last frame that we had stored in the external queue. Using 2 leads to a more "true" rate of what we actually can capture in terms of *new* frames and also a substantially lower rate of kFramePoolEmpty. In addition, with 1 as size, if we ask at a too high rate and provide a copy of the last frame, our CPU adaptation will not reduce its rate since we think that things are OK when it is actually not. Also, the samples in [3] and [4] both use 2 as numberOfBuffers as well. Let me also mention that with this small change, I a have not been able to provoke any kFramePoolEmpty error messages. Finally, geDisplayMedia can be called called with constraints where min and max framerate is defined. The mechanism which maintains the min rate is implemented via the RequestRefreshFrame API and it can be sent to the source (DesktopCaptureDevice) back to back with a previous timer interrupt for a capture request. Without this change, these RRFs were also a source of a large amount of kFramePoolEmpty error logs. With 2 buffers instead; this is no longer the case. [1] https://screenshot.googleplex.com/7sfv6HdGXLwyxdj [2] https://paste.googleplex.com/4795680001359872 [3] https://github.com/robmikh/Win32CaptureSample/blob/master/Win32CaptureSample/SimpleCapture.cpp [4] https://learn.microsoft.com/en-us/windows/uwp/audio-video-camera/screen-capture#add-the-screen-capture-capability (cherry picked from commit 4be5927dc788b814dff2a6ca46175254dce59232) Bug: chromium:1314868 Change-Id: I73b823b31a993fd2cd6e007b212826dfe1a80012 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/325521 Commit-Queue: Alexander Cooper <alcooperchromium.org> Reviewed-by: Alexander Cooper <alcooperchromium.org> Cr-Original-Commit-Position: refs/heads/main{#41079} Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/326960 Commit-Queue: Henrik Andreassson <henrikawebrtc.org> Bot-Commit: rubber-stamperappspot.gserviceaccount.com <rubber-stamperappspot.gserviceaccount.com> Reviewed-by: Stefan Holmer <stefanwebrtc.org> Cr-Commit-Position: refs/branch-heads/6099{#1} Cr-Branched-From: 507f1cc3270d0577f79882acbd78e63e66008f3d-refs/heads/main{#41042} UltraBlame original commit: ea64d0bd5fc3e48d7ea9c11717f2a33521ec76b3
1 parent 7cc6582 commit cfdcb25

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

third_party/libwebrtc/README.moz-ff-commit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26850,3 +26850,6 @@ c3b7a50720
2685026850
# MOZ_LIBWEBRTC_SRC=/home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc MOZ_LIBWEBRTC_BRANCH=mozpatches bash dom/media/webrtc/third_party_build/fast-forward-libwebrtc.sh
2685126851
# base of lastest vendoring
2685226852
507f1cc327
26853+
# MOZ_LIBWEBRTC_SRC=/home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc MOZ_LIBWEBRTC_BRANCH=mozpatches bash dom/media/webrtc/third_party_build/fast-forward-libwebrtc.sh
26854+
# base of lastest vendoring
26855+
b0cc68e612

third_party/libwebrtc/README.mozilla

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17924,3 +17924,5 @@ libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc
1792417924
libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2024-01-03T18:59:14.475221.
1792517925
# ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc
1792617926
libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2024-01-03T19:00:15.797265.
17927+
# ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc
17928+
libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2024-01-03T19:01:15.317447.

third_party/libwebrtc/modules/desktop_capture/win/wgc_capture_session.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ enum class GetFrameResult {
7575
kGetContentSizeFailed = 9,
7676
kResizeMappedTextureFailed = 10,
7777
kRecreateFramePoolFailed = 11,
78-
kMaxValue = kRecreateFramePoolFailed
78+
kFramePoolEmpty = 12,
79+
kMaxValue = kFramePoolEmpty
7980
};
8081

8182
void RecordStartCaptureResult(StartCaptureResult error) {
@@ -338,10 +339,15 @@ HRESULT WgcCaptureSession::ProcessFrame() {
338339
}
339340

340341
if (!capture_frame) {
341-
342-
if (queue_.current_frame()) {
343-
RTC_DLOG(LS_WARNING) << "Frame pool was empty => kFrameDropped.";
342+
if (!queue_.current_frame()) {
343+
344+
RTC_DLOG(LS_ERROR) << "Frame pool was empty => kFrameDropped.";
344345
RecordGetFrameResult(GetFrameResult::kFrameDropped);
346+
} else {
347+
348+
349+
RTC_DLOG(LS_WARNING) << "Frame pool was empty => kFramePoolEmpty.";
350+
RecordGetFrameResult(GetFrameResult::kFramePoolEmpty);
345351
}
346352
return E_FAIL;
347353
}

third_party/libwebrtc/modules/desktop_capture/win/wgc_capture_session.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ class WgcCaptureSession final {
5555

5656

5757

58-
static constexpr int kNumBuffers = 1;
58+
59+
60+
static constexpr int kNumBuffers = 2;
5961

6062
private:
6163

third_party/libwebrtc/moz-patch-stack/0103.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ Mercurial Revision: https://hg.mozilla.org/mozilla-central/rev/0aac94794aad2ddb6
1111
1 file changed, 6 insertions(+)
1212

1313
diff --git a/modules/desktop_capture/win/wgc_capture_session.cc b/modules/desktop_capture/win/wgc_capture_session.cc
14-
index 2f7fac9f02..865cdb5acb 100644
14+
index 8c74c2bf24..86afc52411 100644
1515
--- a/modules/desktop_capture/win/wgc_capture_session.cc
1616
+++ b/modules/desktop_capture/win/wgc_capture_session.cc
17-
@@ -187,6 +187,11 @@ HRESULT WgcCaptureSession::StartCapture(const DesktopCaptureOptions& options) {
17+
@@ -188,6 +188,11 @@ HRESULT WgcCaptureSession::StartCapture(const DesktopCaptureOptions& options) {
1818
}
1919
}
2020

@@ -26,7 +26,7 @@ index 2f7fac9f02..865cdb5acb 100644
2626
// By default, the WGC capture API adds a yellow border around the captured
2727
// window or display to indicate that a capture is in progress. The section
2828
// below is an attempt to remove this yellow border to make the capture
29-
@@ -198,6 +203,7 @@ HRESULT WgcCaptureSession::StartCapture(const DesktopCaptureOptions& options) {
29+
@@ -199,6 +204,7 @@ HRESULT WgcCaptureSession::StartCapture(const DesktopCaptureOptions& options) {
3030
&session3))) {
3131
session3->put_IsBorderRequired(false);
3232
}

0 commit comments

Comments
 (0)