1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/*
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MODULES_DESKTOP_CAPTURE_MAC_SCREEN_CAPTURER_MAC_H_
#define MODULES_DESKTOP_CAPTURE_MAC_SCREEN_CAPTURER_MAC_H_
#include <CoreGraphics/CoreGraphics.h>
#include <memory>
#include <vector>
#include "api/sequence_checker.h"
#include "modules/desktop_capture/desktop_capture_options.h"
#include "modules/desktop_capture/desktop_capturer.h"
#include "modules/desktop_capture/desktop_frame.h"
#include "modules/desktop_capture/desktop_geometry.h"
#include "modules/desktop_capture/desktop_region.h"
#include "modules/desktop_capture/mac/desktop_configuration.h"
#include "modules/desktop_capture/mac/desktop_configuration_monitor.h"
#include "modules/desktop_capture/mac/desktop_frame_provider.h"
#include "modules/desktop_capture/screen_capture_frame_queue.h"
#include "modules/desktop_capture/screen_capturer_helper.h"
#include "modules/desktop_capture/shared_desktop_frame.h"
namespace webrtc {
class DisplayStreamManager;
// A class to perform video frame capturing for mac.
class ScreenCapturerMac final : public DesktopCapturer {
public:
ScreenCapturerMac(rtc::scoped_refptr<DesktopConfigurationMonitor> desktop_config_monitor,
bool detect_updated_region,
bool allow_iosurface);
~ScreenCapturerMac() override;
ScreenCapturerMac(const ScreenCapturerMac&) = delete;
ScreenCapturerMac& operator=(const ScreenCapturerMac&) = delete;
// TODO(julien.isorce): Remove Init() or make it private.
bool Init();
// DesktopCapturer interface.
void Start(Callback* callback) override;
void CaptureFrame() override;
void SetExcludedWindow(WindowId window) override;
bool GetSourceList(SourceList* screens) override;
bool SelectSource(SourceId id) override;
private:
// Returns false if the selected screen is no longer valid.
bool CgBlit(const DesktopFrame& frame, const DesktopRegion& region);
// Called when the screen configuration is changed.
void ScreenConfigurationChanged();
bool RegisterRefreshAndMoveHandlers();
void UnregisterRefreshAndMoveHandlers();
void ScreenRefresh(CGDirectDisplayID display_id,
CGRectCount count,
const CGRect* rect_array,
DesktopVector display_origin,
IOSurfaceRef io_surface);
void ReleaseBuffers();
std::unique_ptr<DesktopFrame> CreateFrame();
const bool detect_updated_region_;
Callback* callback_ = nullptr;
// Queue of the frames buffers.
ScreenCaptureFrameQueue<SharedDesktopFrame> queue_;
// Current display configuration.
MacDesktopConfiguration desktop_config_;
// Currently selected display, or 0 if the full desktop is selected. On OS X
// 10.6 and before, this is always 0.
CGDirectDisplayID current_display_ = 0;
// The physical pixel bounds of the current screen.
DesktopRect screen_pixel_bounds_;
// The dip to physical pixel scale of the current screen.
float dip_to_pixel_scale_ = 1.0f;
// A thread-safe list of invalid rectangles, and the size of the most
// recently captured screen.
ScreenCapturerHelper helper_;
// Contains an invalid region from the previous capture.
DesktopRegion last_invalid_region_;
// Monitoring display reconfiguration.
rtc::scoped_refptr<DesktopConfigurationMonitor> desktop_config_monitor_;
CGWindowID excluded_window_ = 0;
// List of streams, one per screen.
std::vector<CGDisplayStreamRef> display_streams_;
// Container holding latest state of the snapshot per displays.
DesktopFrameProvider desktop_frame_provider_;
// Start, CaptureFrame and destructor have to called in the same thread.
SequenceChecker thread_checker_;
// Used to force CaptureFrame to update it's screen configuration
// and reregister event handlers. This ensure that this
// occurs on the ScreenCapture thread. Read and written from
// both the VideoCapture thread and ScreenCapture thread.
// Protected by desktop_config_monitor_.
bool update_screen_configuration_ = false;
};
} // namespace webrtc
#endif // MODULES_DESKTOP_CAPTURE_MAC_SCREEN_CAPTURER_MAC_H_
|