Skip to content

Commit

Permalink
fix: fallback to X11 capturer if pipewire fails on Wayland (#37526)
Browse files Browse the repository at this point in the history
* fix: fallback to x11 desktop capturer on Wayland

Co-authored-by: VerteDinde <keeleymhammond@gmail.com>

* fix: sanitize window/screen capturer inputs

Co-authored-by: Keeley Hammond <vertedinde@electronjs.org>

* chore: clean up patch description

Co-authored-by: Keeley Hammond <vertedinde@electronjs.org>

* chore: update patches

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: VerteDinde <keeleymhammond@gmail.com>
Co-authored-by: Keeley Hammond <vertedinde@electronjs.org>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
  • Loading branch information
4 people committed Mar 8, 2023
1 parent c174ed7 commit 093a215
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 77 deletions.
4 changes: 3 additions & 1 deletion patches/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@

"src/electron/patches/Mantle": "src/third_party/squirrel.mac/vendor/Mantle",

"src/electron/patches/ReactiveObjC": "src/third_party/squirrel.mac/vendor/ReactiveObjC"
"src/electron/patches/ReactiveObjC": "src/third_party/squirrel.mac/vendor/ReactiveObjC",

"src/electron/patches/webrtc": "src/third_party/webrtc"
}
2 changes: 1 addition & 1 deletion patches/webrtc/.patches
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cherry-pick-e0efbd45ea74.patch
fix_fallback_to_x11_capturer_on_wayland.patch
57 changes: 0 additions & 57 deletions patches/webrtc/cherry-pick-e0efbd45ea74.patch

This file was deleted.

58 changes: 58 additions & 0 deletions patches/webrtc/fix_fallback_to_x11_capturer_on_wayland.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: VerteDinde <keeleymhammond@gmail.com>
Date: Sun, 5 Mar 2023 21:04:37 -0800
Subject: fix: fallback to X11 capturer on Wayland

CL: https://webrtc-review.googlesource.com/c/src/+/279163

Desktop Capturer behaves inconsistently on Wayland. PipeWire does not
always successfully start; if it does not, we return a nullptr rather
than falling back on the X11 capturer, crashing the application.

If the X11 capturer is enabled, we should at minimum try to fallback
to X11 for desktop capturer. This patch re-enables that fallback,
which was previously default behavior.

This patch can be removed when 1) this fix is upstreamed, or 2) the
stability of PipeWire initialization is improved upstream.

Patch_Filename: fix_fallback_to_x11_desktop_capturer_wayland.patch

diff --git a/modules/desktop_capture/screen_capturer_linux.cc b/modules/desktop_capture/screen_capturer_linux.cc
index 44993837e8bbd84a11ec9d187349a95f83258910..cd9f8b0be6a19d057fe9150382fb72bc4032b343 100644
--- a/modules/desktop_capture/screen_capturer_linux.cc
+++ b/modules/desktop_capture/screen_capturer_linux.cc
@@ -34,11 +34,10 @@ std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawScreenCapturer(
#endif // defined(WEBRTC_USE_PIPEWIRE)

#if defined(WEBRTC_USE_X11)
- if (!DesktopCapturer::IsRunningUnderWayland())
- return ScreenCapturerX11::CreateRawScreenCapturer(options);
-#endif // defined(WEBRTC_USE_X11)
-
+ return ScreenCapturerX11::CreateRawScreenCapturer(options);
+#else
return nullptr;
+#endif // defined(WEBRTC_USE_X11)
}

} // namespace webrtc
diff --git a/modules/desktop_capture/window_capturer_linux.cc b/modules/desktop_capture/window_capturer_linux.cc
index 4205bf9bc0eede48cdc39353c77ceb6e7529fd51..785dc01a1911fd027401b1461223668333e05558 100644
--- a/modules/desktop_capture/window_capturer_linux.cc
+++ b/modules/desktop_capture/window_capturer_linux.cc
@@ -34,11 +34,10 @@ std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawWindowCapturer(
#endif // defined(WEBRTC_USE_PIPEWIRE)

#if defined(WEBRTC_USE_X11)
- if (!DesktopCapturer::IsRunningUnderWayland())
- return WindowCapturerX11::CreateRawWindowCapturer(options);
-#endif // defined(WEBRTC_USE_X11)
-
+ return WindowCapturerX11::CreateRawWindowCapturer(options);
+#else
return nullptr;
+#endif // defined(WEBRTC_USE_X11)
}

} // namespace webrtc
40 changes: 22 additions & 18 deletions shell/browser/api/electron_api_desktop_capturer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,27 +207,31 @@ void DesktopCapturer::StartHandling(bool capture_window,
// Initialize the source list.
// Apply the new thumbnail size and restart capture.
if (capture_window) {
window_capturer_ = std::make_unique<NativeDesktopMediaList>(
DesktopMediaList::Type::kWindow,
content::desktop_capture::CreateWindowCapturer());
window_capturer_->SetThumbnailSize(thumbnail_size);
window_capturer_->Update(
base::BindOnce(&DesktopCapturer::UpdateSourcesList,
weak_ptr_factory_.GetWeakPtr(),
window_capturer_.get()),
/* refresh_thumbnails = */ true);
if (auto capturer = content::desktop_capture::CreateWindowCapturer();
capturer) {
window_capturer_ = std::make_unique<NativeDesktopMediaList>(
DesktopMediaList::Type::kWindow, std::move(capturer));
window_capturer_->SetThumbnailSize(thumbnail_size);
window_capturer_->Update(
base::BindOnce(&DesktopCapturer::UpdateSourcesList,
weak_ptr_factory_.GetWeakPtr(),
window_capturer_.get()),
/* refresh_thumbnails = */ true);
}
}

if (capture_screen) {
screen_capturer_ = std::make_unique<NativeDesktopMediaList>(
DesktopMediaList::Type::kScreen,
content::desktop_capture::CreateScreenCapturer());
screen_capturer_->SetThumbnailSize(thumbnail_size);
screen_capturer_->Update(
base::BindOnce(&DesktopCapturer::UpdateSourcesList,
weak_ptr_factory_.GetWeakPtr(),
screen_capturer_.get()),
/* refresh_thumbnails = */ true);
if (auto capturer = content::desktop_capture::CreateScreenCapturer();
capturer) {
screen_capturer_ = std::make_unique<NativeDesktopMediaList>(
DesktopMediaList::Type::kScreen, std::move(capturer));
screen_capturer_->SetThumbnailSize(thumbnail_size);
screen_capturer_->Update(
base::BindOnce(&DesktopCapturer::UpdateSourcesList,
weak_ptr_factory_.GetWeakPtr(),
screen_capturer_.get()),
/* refresh_thumbnails = */ true);
}
}
}
}
Expand Down

0 comments on commit 093a215

Please sign in to comment.