1*d9f75844SAndroid Build Coastguard Worker /* 2*d9f75844SAndroid Build Coastguard Worker * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3*d9f75844SAndroid Build Coastguard Worker * 4*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license 5*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source 6*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found 7*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may 8*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree. 9*d9f75844SAndroid Build Coastguard Worker */ 10*d9f75844SAndroid Build Coastguard Worker 11*d9f75844SAndroid Build Coastguard Worker #include "modules/desktop_capture/desktop_capturer.h" 12*d9f75844SAndroid Build Coastguard Worker 13*d9f75844SAndroid Build Coastguard Worker #include <stdlib.h> 14*d9f75844SAndroid Build Coastguard Worker #include <string.h> 15*d9f75844SAndroid Build Coastguard Worker 16*d9f75844SAndroid Build Coastguard Worker #include <cstring> 17*d9f75844SAndroid Build Coastguard Worker #include <utility> 18*d9f75844SAndroid Build Coastguard Worker 19*d9f75844SAndroid Build Coastguard Worker #include "modules/desktop_capture/cropping_window_capturer.h" 20*d9f75844SAndroid Build Coastguard Worker #include "modules/desktop_capture/desktop_capture_options.h" 21*d9f75844SAndroid Build Coastguard Worker #include "modules/desktop_capture/desktop_capturer_differ_wrapper.h" 22*d9f75844SAndroid Build Coastguard Worker 23*d9f75844SAndroid Build Coastguard Worker #if defined(RTC_ENABLE_WIN_WGC) 24*d9f75844SAndroid Build Coastguard Worker #include "modules/desktop_capture/win/wgc_capturer_win.h" 25*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/win/windows_version.h" 26*d9f75844SAndroid Build Coastguard Worker #endif // defined(RTC_ENABLE_WIN_WGC) 27*d9f75844SAndroid Build Coastguard Worker 28*d9f75844SAndroid Build Coastguard Worker namespace webrtc { 29*d9f75844SAndroid Build Coastguard Worker 30*d9f75844SAndroid Build Coastguard Worker DesktopCapturer::~DesktopCapturer() = default; 31*d9f75844SAndroid Build Coastguard Worker 32*d9f75844SAndroid Build Coastguard Worker DelegatedSourceListController* GetDelegatedSourceListController()33*d9f75844SAndroid Build Coastguard WorkerDesktopCapturer::GetDelegatedSourceListController() { 34*d9f75844SAndroid Build Coastguard Worker return nullptr; 35*d9f75844SAndroid Build Coastguard Worker } 36*d9f75844SAndroid Build Coastguard Worker SetSharedMemoryFactory(std::unique_ptr<SharedMemoryFactory> shared_memory_factory)37*d9f75844SAndroid Build Coastguard Workervoid DesktopCapturer::SetSharedMemoryFactory( 38*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SharedMemoryFactory> shared_memory_factory) {} 39*d9f75844SAndroid Build Coastguard Worker SetExcludedWindow(WindowId window)40*d9f75844SAndroid Build Coastguard Workervoid DesktopCapturer::SetExcludedWindow(WindowId window) {} 41*d9f75844SAndroid Build Coastguard Worker GetSourceList(SourceList * sources)42*d9f75844SAndroid Build Coastguard Workerbool DesktopCapturer::GetSourceList(SourceList* sources) { 43*d9f75844SAndroid Build Coastguard Worker return true; 44*d9f75844SAndroid Build Coastguard Worker } 45*d9f75844SAndroid Build Coastguard Worker SelectSource(SourceId id)46*d9f75844SAndroid Build Coastguard Workerbool DesktopCapturer::SelectSource(SourceId id) { 47*d9f75844SAndroid Build Coastguard Worker return false; 48*d9f75844SAndroid Build Coastguard Worker } 49*d9f75844SAndroid Build Coastguard Worker FocusOnSelectedSource()50*d9f75844SAndroid Build Coastguard Workerbool DesktopCapturer::FocusOnSelectedSource() { 51*d9f75844SAndroid Build Coastguard Worker return false; 52*d9f75844SAndroid Build Coastguard Worker } 53*d9f75844SAndroid Build Coastguard Worker IsOccluded(const DesktopVector & pos)54*d9f75844SAndroid Build Coastguard Workerbool DesktopCapturer::IsOccluded(const DesktopVector& pos) { 55*d9f75844SAndroid Build Coastguard Worker return false; 56*d9f75844SAndroid Build Coastguard Worker } 57*d9f75844SAndroid Build Coastguard Worker 58*d9f75844SAndroid Build Coastguard Worker // static CreateWindowCapturer(const DesktopCaptureOptions & options)59*d9f75844SAndroid Build Coastguard Workerstd::unique_ptr<DesktopCapturer> DesktopCapturer::CreateWindowCapturer( 60*d9f75844SAndroid Build Coastguard Worker const DesktopCaptureOptions& options) { 61*d9f75844SAndroid Build Coastguard Worker #if defined(RTC_ENABLE_WIN_WGC) 62*d9f75844SAndroid Build Coastguard Worker if (options.allow_wgc_capturer() && IsWgcSupported(CaptureType::kWindow)) { 63*d9f75844SAndroid Build Coastguard Worker return WgcCapturerWin::CreateRawWindowCapturer(options); 64*d9f75844SAndroid Build Coastguard Worker } 65*d9f75844SAndroid Build Coastguard Worker #endif // defined(RTC_ENABLE_WIN_WGC) 66*d9f75844SAndroid Build Coastguard Worker 67*d9f75844SAndroid Build Coastguard Worker #if defined(WEBRTC_WIN) 68*d9f75844SAndroid Build Coastguard Worker if (options.allow_cropping_window_capturer()) { 69*d9f75844SAndroid Build Coastguard Worker return CroppingWindowCapturer::CreateCapturer(options); 70*d9f75844SAndroid Build Coastguard Worker } 71*d9f75844SAndroid Build Coastguard Worker #endif // defined(WEBRTC_WIN) 72*d9f75844SAndroid Build Coastguard Worker 73*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<DesktopCapturer> capturer = CreateRawWindowCapturer(options); 74*d9f75844SAndroid Build Coastguard Worker if (capturer && options.detect_updated_region()) { 75*d9f75844SAndroid Build Coastguard Worker capturer.reset(new DesktopCapturerDifferWrapper(std::move(capturer))); 76*d9f75844SAndroid Build Coastguard Worker } 77*d9f75844SAndroid Build Coastguard Worker 78*d9f75844SAndroid Build Coastguard Worker return capturer; 79*d9f75844SAndroid Build Coastguard Worker } 80*d9f75844SAndroid Build Coastguard Worker 81*d9f75844SAndroid Build Coastguard Worker // static CreateScreenCapturer(const DesktopCaptureOptions & options)82*d9f75844SAndroid Build Coastguard Workerstd::unique_ptr<DesktopCapturer> DesktopCapturer::CreateScreenCapturer( 83*d9f75844SAndroid Build Coastguard Worker const DesktopCaptureOptions& options) { 84*d9f75844SAndroid Build Coastguard Worker #if defined(RTC_ENABLE_WIN_WGC) 85*d9f75844SAndroid Build Coastguard Worker if (options.allow_wgc_capturer() && IsWgcSupported(CaptureType::kScreen)) { 86*d9f75844SAndroid Build Coastguard Worker return WgcCapturerWin::CreateRawScreenCapturer(options); 87*d9f75844SAndroid Build Coastguard Worker } 88*d9f75844SAndroid Build Coastguard Worker #endif // defined(RTC_ENABLE_WIN_WGC) 89*d9f75844SAndroid Build Coastguard Worker 90*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<DesktopCapturer> capturer = CreateRawScreenCapturer(options); 91*d9f75844SAndroid Build Coastguard Worker if (capturer && options.detect_updated_region()) { 92*d9f75844SAndroid Build Coastguard Worker capturer.reset(new DesktopCapturerDifferWrapper(std::move(capturer))); 93*d9f75844SAndroid Build Coastguard Worker } 94*d9f75844SAndroid Build Coastguard Worker 95*d9f75844SAndroid Build Coastguard Worker return capturer; 96*d9f75844SAndroid Build Coastguard Worker } 97*d9f75844SAndroid Build Coastguard Worker 98*d9f75844SAndroid Build Coastguard Worker #if defined(WEBRTC_USE_PIPEWIRE) || defined(WEBRTC_USE_X11) IsRunningUnderWayland()99*d9f75844SAndroid Build Coastguard Workerbool DesktopCapturer::IsRunningUnderWayland() { 100*d9f75844SAndroid Build Coastguard Worker const char* xdg_session_type = getenv("XDG_SESSION_TYPE"); 101*d9f75844SAndroid Build Coastguard Worker if (!xdg_session_type || strncmp(xdg_session_type, "wayland", 7) != 0) 102*d9f75844SAndroid Build Coastguard Worker return false; 103*d9f75844SAndroid Build Coastguard Worker 104*d9f75844SAndroid Build Coastguard Worker if (!(getenv("WAYLAND_DISPLAY"))) 105*d9f75844SAndroid Build Coastguard Worker return false; 106*d9f75844SAndroid Build Coastguard Worker 107*d9f75844SAndroid Build Coastguard Worker return true; 108*d9f75844SAndroid Build Coastguard Worker } 109*d9f75844SAndroid Build Coastguard Worker #endif // defined(WEBRTC_USE_PIPEWIRE) || defined(WEBRTC_USE_X11) 110*d9f75844SAndroid Build Coastguard Worker 111*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc 112