zijiehe | b68d655 | 2016-10-29 00:35:11 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #include "modules/desktop_capture/desktop_capturer.h" |
zijiehe | b68d655 | 2016-10-29 00:35:11 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 13 | #include <stdlib.h> |
| 14 | #include <string.h> |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 15 | |
| 16 | #include <cstring> |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 17 | #include <utility> |
| 18 | |
Bryan Ferguson | 366ac4d | 2019-07-26 17:45:01 | [diff] [blame] | 19 | #include "modules/desktop_capture/cropping_window_capturer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 20 | #include "modules/desktop_capture/desktop_capture_options.h" |
| 21 | #include "modules/desktop_capture/desktop_capturer_differ_wrapper.h" |
Johannes Kron | b311f6a | 2023-02-03 11:01:52 | [diff] [blame] | 22 | #include "system_wrappers/include/metrics.h" |
zijiehe | b68d655 | 2016-10-29 00:35:11 | [diff] [blame] | 23 | |
Austin Orion | 25b0dee | 2020-10-01 20:47:54 | [diff] [blame] | 24 | #if defined(RTC_ENABLE_WIN_WGC) |
Austin Orion | 2aad812 | 2021-01-07 22:34:31 | [diff] [blame] | 25 | #include "modules/desktop_capture/win/wgc_capturer_win.h" |
Austin Orion | 25b0dee | 2020-10-01 20:47:54 | [diff] [blame] | 26 | #include "rtc_base/win/windows_version.h" |
Austin Orion | 25b0dee | 2020-10-01 20:47:54 | [diff] [blame] | 27 | #endif // defined(RTC_ENABLE_WIN_WGC) |
| 28 | |
Jan Grulich | 0e9556a | 2023-07-12 11:15:40 | [diff] [blame] | 29 | #if defined(WEBRTC_USE_PIPEWIRE) |
| 30 | #include "modules/desktop_capture/linux/wayland/base_capturer_pipewire.h" |
| 31 | #endif |
| 32 | |
zijiehe | b68d655 | 2016-10-29 00:35:11 | [diff] [blame] | 33 | namespace webrtc { |
| 34 | |
Johannes Kron | b311f6a | 2023-02-03 11:01:52 | [diff] [blame] | 35 | void LogDesktopCapturerFullscreenDetectorUsage() { |
Johannes Kron | fd29662 | 2023-02-03 19:23:39 | [diff] [blame] | 36 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Screenshare.DesktopCapturerFullscreenDetector", |
| 37 | true); |
Johannes Kron | b311f6a | 2023-02-03 11:01:52 | [diff] [blame] | 38 | } |
| 39 | |
zijiehe | b68d655 | 2016-10-29 00:35:11 | [diff] [blame] | 40 | DesktopCapturer::~DesktopCapturer() = default; |
| 41 | |
Alex Cooper | 86015a6 | 2022-08-31 17:31:11 | [diff] [blame] | 42 | DelegatedSourceListController* |
| 43 | DesktopCapturer::GetDelegatedSourceListController() { |
| 44 | return nullptr; |
| 45 | } |
| 46 | |
zijiehe | b68d655 | 2016-10-29 00:35:11 | [diff] [blame] | 47 | void DesktopCapturer::SetSharedMemoryFactory( |
| 48 | std::unique_ptr<SharedMemoryFactory> shared_memory_factory) {} |
| 49 | |
| 50 | void DesktopCapturer::SetExcludedWindow(WindowId window) {} |
| 51 | |
| 52 | bool DesktopCapturer::GetSourceList(SourceList* sources) { |
| 53 | return true; |
| 54 | } |
| 55 | |
| 56 | bool DesktopCapturer::SelectSource(SourceId id) { |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | bool DesktopCapturer::FocusOnSelectedSource() { |
| 61 | return false; |
| 62 | } |
| 63 | |
Zijie He | 1282711 | 2017-08-29 18:19:13 | [diff] [blame] | 64 | bool DesktopCapturer::IsOccluded(const DesktopVector& pos) { |
| 65 | return false; |
| 66 | } |
| 67 | |
zijiehe | 54fd579 | 2016-11-02 21:49:35 | [diff] [blame] | 68 | // static |
| 69 | std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateWindowCapturer( |
| 70 | const DesktopCaptureOptions& options) { |
Austin Orion | 25b0dee | 2020-10-01 20:47:54 | [diff] [blame] | 71 | #if defined(RTC_ENABLE_WIN_WGC) |
henrika | 58e97b8 | 2023-06-22 12:53:52 | [diff] [blame] | 72 | if (options.allow_wgc_window_capturer() && |
henrika | c3a7402 | 2023-06-21 15:07:55 | [diff] [blame] | 73 | IsWgcSupported(CaptureType::kWindow)) { |
Austin Orion | 2aad812 | 2021-01-07 22:34:31 | [diff] [blame] | 74 | return WgcCapturerWin::CreateRawWindowCapturer(options); |
Austin Orion | 25b0dee | 2020-10-01 20:47:54 | [diff] [blame] | 75 | } |
| 76 | #endif // defined(RTC_ENABLE_WIN_WGC) |
| 77 | |
Bryan Ferguson | 366ac4d | 2019-07-26 17:45:01 | [diff] [blame] | 78 | #if defined(WEBRTC_WIN) |
| 79 | if (options.allow_cropping_window_capturer()) { |
| 80 | return CroppingWindowCapturer::CreateCapturer(options); |
| 81 | } |
| 82 | #endif // defined(WEBRTC_WIN) |
| 83 | |
zijiehe | 54fd579 | 2016-11-02 21:49:35 | [diff] [blame] | 84 | std::unique_ptr<DesktopCapturer> capturer = CreateRawWindowCapturer(options); |
sergeyu | 3eba2d8 | 2017-03-17 22:33:27 | [diff] [blame] | 85 | if (capturer && options.detect_updated_region()) { |
zijiehe | 54fd579 | 2016-11-02 21:49:35 | [diff] [blame] | 86 | capturer.reset(new DesktopCapturerDifferWrapper(std::move(capturer))); |
| 87 | } |
| 88 | |
| 89 | return capturer; |
| 90 | } |
| 91 | |
| 92 | // static |
| 93 | std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateScreenCapturer( |
| 94 | const DesktopCaptureOptions& options) { |
Austin Orion | 2aad812 | 2021-01-07 22:34:31 | [diff] [blame] | 95 | #if defined(RTC_ENABLE_WIN_WGC) |
henrika | 58e97b8 | 2023-06-22 12:53:52 | [diff] [blame] | 96 | if (options.allow_wgc_screen_capturer() && |
henrika | c3a7402 | 2023-06-21 15:07:55 | [diff] [blame] | 97 | IsWgcSupported(CaptureType::kScreen)) { |
Austin Orion | 2aad812 | 2021-01-07 22:34:31 | [diff] [blame] | 98 | return WgcCapturerWin::CreateRawScreenCapturer(options); |
| 99 | } |
| 100 | #endif // defined(RTC_ENABLE_WIN_WGC) |
| 101 | |
zijiehe | 54fd579 | 2016-11-02 21:49:35 | [diff] [blame] | 102 | std::unique_ptr<DesktopCapturer> capturer = CreateRawScreenCapturer(options); |
sergeyu | 3eba2d8 | 2017-03-17 22:33:27 | [diff] [blame] | 103 | if (capturer && options.detect_updated_region()) { |
zijiehe | 54fd579 | 2016-11-02 21:49:35 | [diff] [blame] | 104 | capturer.reset(new DesktopCapturerDifferWrapper(std::move(capturer))); |
| 105 | } |
| 106 | |
| 107 | return capturer; |
| 108 | } |
zijiehe | 54fd579 | 2016-11-02 21:49:35 | [diff] [blame] | 109 | |
Jan Grulich | 0e9556a | 2023-07-12 11:15:40 | [diff] [blame] | 110 | // static |
| 111 | std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateGenericCapturer( |
| 112 | const DesktopCaptureOptions& options) { |
| 113 | std::unique_ptr<DesktopCapturer> capturer; |
| 114 | |
| 115 | #if defined(WEBRTC_USE_PIPEWIRE) |
| 116 | if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) { |
| 117 | capturer = std::make_unique<BaseCapturerPipeWire>( |
| 118 | options, CaptureType::kAnyScreenContent); |
| 119 | } |
| 120 | |
| 121 | if (capturer && options.detect_updated_region()) { |
| 122 | capturer.reset(new DesktopCapturerDifferWrapper(std::move(capturer))); |
| 123 | } |
| 124 | #endif // defined(WEBRTC_USE_PIPEWIRE) |
| 125 | |
| 126 | return capturer; |
| 127 | } |
| 128 | |
Patrik Höglund | 0808a8c | 2019-12-12 10:20:07 | [diff] [blame] | 129 | #if defined(WEBRTC_USE_PIPEWIRE) || defined(WEBRTC_USE_X11) |
Tomas Popela | 318da51 | 2018-11-13 05:32:23 | [diff] [blame] | 130 | bool DesktopCapturer::IsRunningUnderWayland() { |
| 131 | const char* xdg_session_type = getenv("XDG_SESSION_TYPE"); |
| 132 | if (!xdg_session_type || strncmp(xdg_session_type, "wayland", 7) != 0) |
| 133 | return false; |
| 134 | |
| 135 | if (!(getenv("WAYLAND_DISPLAY"))) |
| 136 | return false; |
| 137 | |
| 138 | return true; |
| 139 | } |
Patrik Höglund | 0808a8c | 2019-12-12 10:20:07 | [diff] [blame] | 140 | #endif // defined(WEBRTC_USE_PIPEWIRE) || defined(WEBRTC_USE_X11) |
Tomas Popela | 318da51 | 2018-11-13 05:32:23 | [diff] [blame] | 141 | |
zijiehe | b68d655 | 2016-10-29 00:35:11 | [diff] [blame] | 142 | } // namespace webrtc |