1 /*
2  *  Copyright (c) 2014 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 #ifndef MODULES_DESKTOP_CAPTURE_FULL_SCREEN_WINDOW_DETECTOR_H_
12 #define MODULES_DESKTOP_CAPTURE_FULL_SCREEN_WINDOW_DETECTOR_H_
13 
14 #include <memory>
15 #include "api/function_view.h"
16 #include "api/ref_counted_base.h"
17 #include "api/scoped_refptr.h"
18 #include "modules/desktop_capture/desktop_capturer.h"
19 #include "modules/desktop_capture/full_screen_application_handler.h"
20 #include "rtc_base/constructor_magic.h"
21 
22 namespace webrtc {
23 
24 // This is a way to handle switch to full-screen mode for application in some
25 // specific cases:
26 // - Chrome on MacOS creates a new window in full-screen mode to
27 //   show a tab full-screen and minimizes the old window.
28 // - PowerPoint creates new windows in full-screen mode when user goes to
29 //   presentation mode (Slide Show Window, Presentation Window).
30 //
31 // To continue capturing in these cases, we try to find the new full-screen
32 // window using criteria provided by application specific
33 // FullScreenApplicationHandler.
34 
35 class FullScreenWindowDetector : public rtc::RefCountedBase {
36  public:
37   using ApplicationHandlerFactory =
38       std::function<std::unique_ptr<FullScreenApplicationHandler>(
39           DesktopCapturer::SourceId sourceId)>;
40 
41   FullScreenWindowDetector(
42       ApplicationHandlerFactory application_handler_factory);
43 
44   // Returns the full-screen window in place of the original window if all the
45   // criteria provided by FullScreenApplicationHandler are met, or 0 if no such
46   // window found.
47   DesktopCapturer::SourceId FindFullScreenWindow(
48       DesktopCapturer::SourceId original_source_id);
49 
50   // The caller should call this function periodically, implementation will
51   // update internal state no often than twice per second
52   void UpdateWindowListIfNeeded(
53       DesktopCapturer::SourceId original_source_id,
54       rtc::FunctionView<bool(DesktopCapturer::SourceList*)> get_sources);
55 
56   static rtc::scoped_refptr<FullScreenWindowDetector>
57   CreateFullScreenWindowDetector();
58 
59  protected:
60   std::unique_ptr<FullScreenApplicationHandler> app_handler_;
61 
62  private:
63   void CreateApplicationHandlerIfNeeded(DesktopCapturer::SourceId source_id);
64 
65   ApplicationHandlerFactory application_handler_factory_;
66 
67   int64_t last_update_time_ms_;
68   DesktopCapturer::SourceId previous_source_id_;
69 
70   // Save the source id when we fail to create an instance of
71   // CreateApplicationHandlerIfNeeded to avoid redundant attempt to do it again.
72   DesktopCapturer::SourceId no_handler_source_id_;
73 
74   DesktopCapturer::SourceList window_list_;
75   RTC_DISALLOW_COPY_AND_ASSIGN(FullScreenWindowDetector);
76 };
77 
78 }  // namespace webrtc
79 
80 #endif  // MODULES_DESKTOP_CAPTURE_FULL_SCREEN_WINDOW_DETECTOR_H_
81