fix_use_delegated_generic_capturer_when_available.patch 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Athul Iddya <[email protected]>
  3. Date: Fri, 14 Jul 2023 08:03:37 -0700
  4. Subject: fix: use delegated generic capturer when available
  5. When the generic capturer is used to fetch capture sources, the returned
  6. ID will be arbitrarily prefixed with "screen" or "window" regardless of
  7. the source type. If the window capturer is used to stream video when the
  8. source was a screen or vice-versa, the stream fails to restart in
  9. delegated capturers like PipeWire.
  10. To fix this, use the generic capturer to fetch the media stream if it's
  11. delegated and available. This does not cause any issues if the original
  12. capturer was window or screen-specific, as the IDs remain valid for
  13. generic capturer as well.
  14. diff --git a/content/browser/media/capture/desktop_capture_device.cc b/content/browser/media/capture/desktop_capture_device.cc
  15. index fba9bdf62541ddd7f81eb32cfc5fb8565a5b325f..43b17972602a14e7db0de229958448a6badc75a4 100644
  16. --- a/content/browser/media/capture/desktop_capture_device.cc
  17. +++ b/content/browser/media/capture/desktop_capture_device.cc
  18. @@ -812,8 +812,14 @@ std::unique_ptr<media::VideoCaptureDevice> DesktopCaptureDevice::Create(
  19. switch (source.type) {
  20. case DesktopMediaID::TYPE_SCREEN: {
  21. - std::unique_ptr<webrtc::DesktopCapturer> screen_capturer(
  22. - webrtc::DesktopCapturer::CreateScreenCapturer(options));
  23. + std::unique_ptr<webrtc::DesktopCapturer> screen_capturer;
  24. + if (auto generic_capturer =
  25. + webrtc::DesktopCapturer::CreateGenericCapturer(options);
  26. + generic_capturer && generic_capturer->GetDelegatedSourceListController()) {
  27. + screen_capturer = std::move(generic_capturer);
  28. + } else {
  29. + screen_capturer = webrtc::DesktopCapturer::CreateScreenCapturer(options);
  30. + }
  31. if (screen_capturer && screen_capturer->SelectSource(source.id)) {
  32. capturer = std::make_unique<webrtc::DesktopAndCursorComposer>(
  33. std::move(screen_capturer), options);
  34. @@ -826,8 +832,14 @@ std::unique_ptr<media::VideoCaptureDevice> DesktopCaptureDevice::Create(
  35. }
  36. case DesktopMediaID::TYPE_WINDOW: {
  37. - std::unique_ptr<webrtc::DesktopCapturer> window_capturer =
  38. - webrtc::DesktopCapturer::CreateWindowCapturer(options);
  39. + std::unique_ptr<webrtc::DesktopCapturer> window_capturer;
  40. + if (auto generic_capturer =
  41. + webrtc::DesktopCapturer::CreateGenericCapturer(options);
  42. + generic_capturer && generic_capturer->GetDelegatedSourceListController()) {
  43. + window_capturer = std::move(generic_capturer);
  44. + } else {
  45. + window_capturer = webrtc::DesktopCapturer::CreateWindowCapturer(options);
  46. + }
  47. if (window_capturer && window_capturer->SelectSource(source.id)) {
  48. capturer = std::make_unique<webrtc::DesktopAndCursorComposer>(
  49. std::move(window_capturer), options);