blob: 998b720d904afd2e3a283a525406e0f4a5f1481c [file] [log] [blame]
Roman Gaiub58835352019-10-07 18:57:011/*
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>
Byoungchan Lee604fd2f2022-01-21 00:49:3915
Roman Gaiub58835352019-10-07 18:57:0116#include "api/function_view.h"
17#include "api/ref_counted_base.h"
18#include "api/scoped_refptr.h"
19#include "modules/desktop_capture/desktop_capturer.h"
20#include "modules/desktop_capture/full_screen_application_handler.h"
Roman Gaiub58835352019-10-07 18:57:0121
22namespace 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
Tommi86ee89f2021-04-20 14:58:0135class FullScreenWindowDetector
36 : public rtc::RefCountedNonVirtual<FullScreenWindowDetector> {
Roman Gaiub58835352019-10-07 18:57:0137 public:
38 using ApplicationHandlerFactory =
39 std::function<std::unique_ptr<FullScreenApplicationHandler>(
40 DesktopCapturer::SourceId sourceId)>;
41
42 FullScreenWindowDetector(
43 ApplicationHandlerFactory application_handler_factory);
44
Byoungchan Lee604fd2f2022-01-21 00:49:3945 FullScreenWindowDetector(const FullScreenWindowDetector&) = delete;
46 FullScreenWindowDetector& operator=(const FullScreenWindowDetector&) = delete;
47
Roman Gaiub58835352019-10-07 18:57:0148 // Returns the full-screen window in place of the original window if all the
49 // criteria provided by FullScreenApplicationHandler are met, or 0 if no such
50 // window found.
51 DesktopCapturer::SourceId FindFullScreenWindow(
52 DesktopCapturer::SourceId original_source_id);
53
54 // The caller should call this function periodically, implementation will
55 // update internal state no often than twice per second
56 void UpdateWindowListIfNeeded(
57 DesktopCapturer::SourceId original_source_id,
58 rtc::FunctionView<bool(DesktopCapturer::SourceList*)> get_sources);
59
60 static rtc::scoped_refptr<FullScreenWindowDetector>
61 CreateFullScreenWindowDetector();
62
63 protected:
64 std::unique_ptr<FullScreenApplicationHandler> app_handler_;
65
66 private:
67 void CreateApplicationHandlerIfNeeded(DesktopCapturer::SourceId source_id);
68
69 ApplicationHandlerFactory application_handler_factory_;
70
71 int64_t last_update_time_ms_;
72 DesktopCapturer::SourceId previous_source_id_;
73
74 // Save the source id when we fail to create an instance of
75 // CreateApplicationHandlerIfNeeded to avoid redundant attempt to do it again.
76 DesktopCapturer::SourceId no_handler_source_id_;
77
78 DesktopCapturer::SourceList window_list_;
Roman Gaiub58835352019-10-07 18:57:0179};
80
81} // namespace webrtc
82
83#endif // MODULES_DESKTOP_CAPTURE_FULL_SCREEN_WINDOW_DETECTOR_H_