OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTROLLER_H_ | 11 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTROLLER_H_ |
12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTROLLER_H_ | 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTROLLER_H_ |
13 | 13 |
| 14 #include <memory> |
14 #include <vector> | 15 #include <vector> |
15 | 16 |
16 #include "webrtc/base/criticalsection.h" | 17 #include "webrtc/base/criticalsection.h" |
17 #include "webrtc/modules/desktop_capture/desktop_frame.h" | |
18 #include "webrtc/modules/desktop_capture/desktop_geometry.h" | 18 #include "webrtc/modules/desktop_capture/desktop_geometry.h" |
19 #include "webrtc/modules/desktop_capture/desktop_region.h" | 19 #include "webrtc/modules/desktop_capture/desktop_region.h" |
| 20 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" |
20 #include "webrtc/modules/desktop_capture/win/d3d_device.h" | 21 #include "webrtc/modules/desktop_capture/win/d3d_device.h" |
21 #include "webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.h" | 22 #include "webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.h" |
22 | 23 |
23 namespace webrtc { | 24 namespace webrtc { |
24 | 25 |
25 // A controller for all the objects we need to call Windows DirectX capture APIs | 26 // A controller for all the objects we need to call Windows DirectX capture APIs |
26 // It's a singleton because, only one IDXGIOutputDuplication instance per | 27 // It's a singleton because, only one IDXGIOutputDuplication instance per |
27 // monitor is allowed per application. | 28 // monitor is allowed per application. |
28 // | 29 // |
29 // Consumers should create a DxgiDuplicatorController::Context and keep it | 30 // Consumers should create a DxgiDuplicatorController::Context and keep it |
30 // throughout their lifetime, and pass it when calling Duplicate(). Consumers | 31 // throughout their lifetime, and pass it when calling Duplicate(). Consumers |
31 // can also call IsSupported() to determine whether the system supports DXGI | 32 // can also call IsSupported() to determine whether the system supports DXGI |
32 // duplicator or not. If a previous IsSupported() function call returns true, | 33 // duplicator or not. If a previous IsSupported() function call returns true, |
33 // but a later Duplicate() returns false, this usually means the display mode is | 34 // but a later Duplicate() returns false, this usually means the display mode is |
34 // changing. Consumers should retry after a while. (Typically 50 milliseconds, | 35 // changing. Consumers should retry after a while. (Typically 50 milliseconds, |
35 // but according to hardware performance, this time may vary.) | 36 // but according to hardware performance, this time may vary.) |
36 // | |
37 // This class is normally used with double buffering, e.g. as in | |
38 // ScreenCapturerWinDirectx, but it should work with consumers with one buffer, | |
39 // i.e. consumers can always send nullptr for |last_frame|. Some minor changes | |
40 // in DxgiOutputDuplicator class are nice to have to reduce size of data to copy | |
41 // (Commented in dxgi_output_duplicator.cc). But this class won't work | |
42 // with three or more buffers, the updated region merging logic will be broken | |
43 // in such scenarios. If a consumer does have this requirement, one can always | |
44 // send a new Context instance to Duplicate() function to force duplicator to | |
45 // treat it as a new consumer. | |
46 class DxgiDuplicatorController { | 37 class DxgiDuplicatorController { |
47 public: | 38 public: |
48 // A context to store the status of a single consumer of | 39 // A context to store the status of a single consumer of |
49 // DxgiDuplicatorController. | 40 // DxgiDuplicatorController. |
50 class Context { | 41 class Context { |
51 public: | 42 public: |
52 // Unregister this Context instance from all Dxgi duplicators during | 43 // Unregister this Context instance from all Dxgi duplicators during |
53 // destructing. | 44 // destructing. |
54 ~Context(); | 45 ~Context(); |
55 | 46 |
(...skipping 19 matching lines...) Expand all Loading... |
75 // Detects whether the system supports DXGI based capturer. | 66 // Detects whether the system supports DXGI based capturer. |
76 bool IsSupported(); | 67 bool IsSupported(); |
77 | 68 |
78 // Captures current screen and writes into target. Since we are using double | 69 // Captures current screen and writes into target. Since we are using double |
79 // buffering, |last_frame|.updated_region() is used to represent the not | 70 // buffering, |last_frame|.updated_region() is used to represent the not |
80 // updated regions in current |target| frame, which should also be copied this | 71 // updated regions in current |target| frame, which should also be copied this |
81 // time. | 72 // time. |
82 // TODO(zijiehe): Windows cannot guarantee the frames returned by each | 73 // TODO(zijiehe): Windows cannot guarantee the frames returned by each |
83 // IDXGIOutputDuplication are synchronized. But we are using a totally | 74 // IDXGIOutputDuplication are synchronized. But we are using a totally |
84 // different threading model than the way Windows suggested, it's hard to | 75 // different threading model than the way Windows suggested, it's hard to |
85 // synchronize them manually. But we should find a way to do it. | 76 // synchronize them manually. We should find a way to do it. |
86 bool Duplicate(Context* context, | 77 bool Duplicate(Context* context, SharedDesktopFrame* target); |
87 const DesktopFrame* last_frame, | |
88 DesktopFrame* target); | |
89 | 78 |
90 // Captures one monitor and writes into target. |monitor_id| should >= 0. If | 79 // Captures one monitor and writes into target. |monitor_id| should >= 0. If |
91 // |monitor_id| is greater than the total screen count of all the Duplicators, | 80 // |monitor_id| is greater than the total screen count of all the Duplicators, |
92 // this function returns false. | 81 // this function returns false. |
93 bool DuplicateMonitor(Context* context, | 82 bool DuplicateMonitor(Context* context, |
94 int monitor_id, | 83 int monitor_id, |
95 const DesktopFrame* last_frame, | 84 SharedDesktopFrame* target); |
96 DesktopFrame* target); | |
97 | 85 |
98 // Returns dpi of current system. Returns an empty DesktopVector if system | 86 // Returns dpi of current system. Returns an empty DesktopVector if system |
99 // does not support DXGI based capturer. | 87 // does not support DXGI based capturer. |
100 DesktopVector dpi(); | 88 DesktopVector dpi(); |
101 | 89 |
102 // Returns entire desktop size. Returns an empty DesktopRect if system does | 90 // Returns entire desktop size. Returns an empty DesktopRect if system does |
103 // not support DXGI based capturer. | 91 // not support DXGI based capturer. |
104 DesktopRect desktop_rect(); | 92 DesktopRect desktop_rect(); |
105 | 93 |
106 // Returns a DesktopSize to cover entire desktop_rect. This may be different | 94 // Returns a DesktopSize to cover entire desktop_rect. This may be different |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 134 |
147 // A helper function to check whether a Context has been expired. | 135 // A helper function to check whether a Context has been expired. |
148 bool ContextExpired(const Context* const context) const; | 136 bool ContextExpired(const Context* const context) const; |
149 | 137 |
150 // Updates Context if needed. | 138 // Updates Context if needed. |
151 void Setup(Context* context); | 139 void Setup(Context* context); |
152 | 140 |
153 // Do the real duplication work. |monitor_id < 0| to capture entire screen. | 141 // Do the real duplication work. |monitor_id < 0| to capture entire screen. |
154 bool DoDuplicate(Context* context, | 142 bool DoDuplicate(Context* context, |
155 int monitor_id, | 143 int monitor_id, |
156 const DesktopFrame* last_frame, | 144 SharedDesktopFrame* target); |
157 DesktopFrame* target); | |
158 | 145 |
159 // This lock must be locked whenever accessing any of the following objects. | 146 // This lock must be locked whenever accessing any of the following objects. |
160 rtc::CriticalSection lock_; | 147 rtc::CriticalSection lock_; |
161 | 148 |
162 // A self-incremented integer to compare with the one in Context, to | 149 // A self-incremented integer to compare with the one in Context, to |
163 // ensure a Context has been initialized after DxgiDuplicatorController. | 150 // ensure a Context has been initialized after DxgiDuplicatorController. |
164 int identity_ = 0; | 151 int identity_ = 0; |
165 DesktopRect desktop_rect_; | 152 DesktopRect desktop_rect_; |
166 DesktopVector dpi_; | 153 DesktopVector dpi_; |
167 std::vector<DxgiAdapterDuplicator> duplicators_; | 154 std::vector<DxgiAdapterDuplicator> duplicators_; |
168 }; | 155 }; |
169 | 156 |
170 } // namespace webrtc | 157 } // namespace webrtc |
171 | 158 |
172 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTROLLER_H_ | 159 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTROLLER_H_ |
OLD | NEW |