• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 namespace webrtc {
24 
25 DesktopCapturer::~DesktopCapturer() = default;
26 
SetSharedMemoryFactory(std::unique_ptr<SharedMemoryFactory> shared_memory_factory)27 void DesktopCapturer::SetSharedMemoryFactory(
28     std::unique_ptr<SharedMemoryFactory> shared_memory_factory) {}
29 
SetExcludedWindow(WindowId window)30 void DesktopCapturer::SetExcludedWindow(WindowId window) {}
31 
GetSourceList(SourceList * sources)32 bool DesktopCapturer::GetSourceList(SourceList* sources) {
33   return true;
34 }
35 
SelectSource(SourceId id)36 bool DesktopCapturer::SelectSource(SourceId id) {
37   return false;
38 }
39 
FocusOnSelectedSource()40 bool DesktopCapturer::FocusOnSelectedSource() {
41   return false;
42 }
43 
IsOccluded(const DesktopVector & pos)44 bool DesktopCapturer::IsOccluded(const DesktopVector& pos) {
45   return false;
46 }
47 
48 // static
CreateWindowCapturer(const DesktopCaptureOptions & options)49 std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateWindowCapturer(
50     const DesktopCaptureOptions& options) {
51 #if defined(WEBRTC_WIN)
52   if (options.allow_cropping_window_capturer()) {
53     return CroppingWindowCapturer::CreateCapturer(options);
54   }
55 #endif  // defined(WEBRTC_WIN)
56 
57   std::unique_ptr<DesktopCapturer> capturer = CreateRawWindowCapturer(options);
58   if (capturer && options.detect_updated_region()) {
59     capturer.reset(new DesktopCapturerDifferWrapper(std::move(capturer)));
60   }
61 
62   return capturer;
63 }
64 
65 // static
CreateScreenCapturer(const DesktopCaptureOptions & options)66 std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateScreenCapturer(
67     const DesktopCaptureOptions& options) {
68   std::unique_ptr<DesktopCapturer> capturer = CreateRawScreenCapturer(options);
69   if (capturer && options.detect_updated_region()) {
70     capturer.reset(new DesktopCapturerDifferWrapper(std::move(capturer)));
71   }
72 
73   return capturer;
74 }
75 
76 #if defined(WEBRTC_USE_PIPEWIRE) || defined(WEBRTC_USE_X11)
IsRunningUnderWayland()77 bool DesktopCapturer::IsRunningUnderWayland() {
78   const char* xdg_session_type = getenv("XDG_SESSION_TYPE");
79   if (!xdg_session_type || strncmp(xdg_session_type, "wayland", 7) != 0)
80     return false;
81 
82   if (!(getenv("WAYLAND_DISPLAY")))
83     return false;
84 
85   return true;
86 }
87 #endif  // defined(WEBRTC_USE_PIPEWIRE) || defined(WEBRTC_USE_X11)
88 
89 }  // namespace webrtc
90