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 11 #include "modules/desktop_capture/desktop_capturer.h" 12 13 #include <stdlib.h> 14 #include <string.h> 15 16 #include <cstring> 17 #include <utility> 18 19 #include "modules/desktop_capture/cropping_window_capturer.h" 20 #include "modules/desktop_capture/desktop_capture_options.h" 21 #include "modules/desktop_capture/desktop_capturer_differ_wrapper.h" 22 23 #if defined(RTC_ENABLE_WIN_WGC) 24 #include "modules/desktop_capture/win/wgc_capturer_win.h" 25 #include "rtc_base/win/windows_version.h" 26 #endif // defined(RTC_ENABLE_WIN_WGC) 27 28 namespace webrtc { 29 30 DesktopCapturer::~DesktopCapturer() = default; 31 32 DelegatedSourceListController* GetDelegatedSourceListController()33DesktopCapturer::GetDelegatedSourceListController() { 34 return nullptr; 35 } 36 SetSharedMemoryFactory(std::unique_ptr<SharedMemoryFactory> shared_memory_factory)37void DesktopCapturer::SetSharedMemoryFactory( 38 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) {} 39 SetExcludedWindow(WindowId window)40void DesktopCapturer::SetExcludedWindow(WindowId window) {} 41 GetSourceList(SourceList * sources)42bool DesktopCapturer::GetSourceList(SourceList* sources) { 43 return true; 44 } 45 SelectSource(SourceId id)46bool DesktopCapturer::SelectSource(SourceId id) { 47 return false; 48 } 49 FocusOnSelectedSource()50bool DesktopCapturer::FocusOnSelectedSource() { 51 return false; 52 } 53 IsOccluded(const DesktopVector & pos)54bool DesktopCapturer::IsOccluded(const DesktopVector& pos) { 55 return false; 56 } 57 58 // static CreateWindowCapturer(const DesktopCaptureOptions & options)59std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateWindowCapturer( 60 const DesktopCaptureOptions& options) { 61 #if defined(RTC_ENABLE_WIN_WGC) 62 if (options.allow_wgc_capturer() && IsWgcSupported(CaptureType::kWindow)) { 63 return WgcCapturerWin::CreateRawWindowCapturer(options); 64 } 65 #endif // defined(RTC_ENABLE_WIN_WGC) 66 67 #if defined(WEBRTC_WIN) 68 if (options.allow_cropping_window_capturer()) { 69 return CroppingWindowCapturer::CreateCapturer(options); 70 } 71 #endif // defined(WEBRTC_WIN) 72 73 std::unique_ptr<DesktopCapturer> capturer = CreateRawWindowCapturer(options); 74 if (capturer && options.detect_updated_region()) { 75 capturer.reset(new DesktopCapturerDifferWrapper(std::move(capturer))); 76 } 77 78 return capturer; 79 } 80 81 // static CreateScreenCapturer(const DesktopCaptureOptions & options)82std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateScreenCapturer( 83 const DesktopCaptureOptions& options) { 84 #if defined(RTC_ENABLE_WIN_WGC) 85 if (options.allow_wgc_capturer() && IsWgcSupported(CaptureType::kScreen)) { 86 return WgcCapturerWin::CreateRawScreenCapturer(options); 87 } 88 #endif // defined(RTC_ENABLE_WIN_WGC) 89 90 std::unique_ptr<DesktopCapturer> capturer = CreateRawScreenCapturer(options); 91 if (capturer && options.detect_updated_region()) { 92 capturer.reset(new DesktopCapturerDifferWrapper(std::move(capturer))); 93 } 94 95 return capturer; 96 } 97 98 #if defined(WEBRTC_USE_PIPEWIRE) || defined(WEBRTC_USE_X11) IsRunningUnderWayland()99bool DesktopCapturer::IsRunningUnderWayland() { 100 const char* xdg_session_type = getenv("XDG_SESSION_TYPE"); 101 if (!xdg_session_type || strncmp(xdg_session_type, "wayland", 7) != 0) 102 return false; 103 104 if (!(getenv("WAYLAND_DISPLAY"))) 105 return false; 106 107 return true; 108 } 109 #endif // defined(WEBRTC_USE_PIPEWIRE) || defined(WEBRTC_USE_X11) 110 111 } // namespace webrtc 112