Skip to content

Commit

Permalink
Bug 1871981 - Vendor libwebrtc from b0cc68e612
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marco-c committed Jan 25, 2024
1 parent 7cc6582 commit cfdcb25
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
3 changes: 3 additions & 0 deletions third_party/libwebrtc/README.moz-ff-commit
Original file line number Diff line number Diff line change
Expand Up @@ -26850,3 +26850,6 @@ c3b7a50720
# 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
# base of lastest vendoring
507f1cc327
# 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
# base of lastest vendoring
b0cc68e612
2 changes: 2 additions & 0 deletions third_party/libwebrtc/README.mozilla
Original file line number Diff line number Diff line change
Expand Up @@ -17924,3 +17924,5 @@ libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc
libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2024-01-03T18:59:14.475221.
# ./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
libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2024-01-03T19:00:15.797265.
# ./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
libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2024-01-03T19:01:15.317447.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ enum class GetFrameResult {
kGetContentSizeFailed = 9,
kResizeMappedTextureFailed = 10,
kRecreateFramePoolFailed = 11,
kMaxValue = kRecreateFramePoolFailed
kFramePoolEmpty = 12,
kMaxValue = kFramePoolEmpty
};

void RecordStartCaptureResult(StartCaptureResult error) {
Expand Down Expand Up @@ -338,10 +339,15 @@ HRESULT WgcCaptureSession::ProcessFrame() {
}

if (!capture_frame) {

if (queue_.current_frame()) {
RTC_DLOG(LS_WARNING) << "Frame pool was empty => kFrameDropped.";
if (!queue_.current_frame()) {
RTC_DLOG(LS_ERROR) << "Frame pool was empty => kFrameDropped.";
RecordGetFrameResult(GetFrameResult::kFrameDropped);
} else {


RTC_DLOG(LS_WARNING) << "Frame pool was empty => kFramePoolEmpty.";
RecordGetFrameResult(GetFrameResult::kFramePoolEmpty);
}
return E_FAIL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ class WgcCaptureSession final {



static constexpr int kNumBuffers = 1;


static constexpr int kNumBuffers = 2;

private:

Expand Down
6 changes: 3 additions & 3 deletions third_party/libwebrtc/moz-patch-stack/0103.patch
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ Mercurial Revision: https://hg.mozilla.org/mozilla-central/rev/0aac94794aad2ddb6
1 file changed, 6 insertions(+)

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

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

0 comments on commit cfdcb25

Please sign in to comment.