Index: webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h |
diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h b/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8ed41bafa4891f057b36f9e0d7a969fb9409cb3e |
--- /dev/null |
+++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h |
@@ -0,0 +1,121 @@ |
+/* |
+ * Copyright (c) 2016 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 WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURER_WIN_DIRECTX_H_ |
+#define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURER_WIN_DIRECTX_H_ |
+ |
+#include "webrtc/modules/desktop_capture/screen_capturer.h" |
+ |
+#include <memory> |
+#include <vector> |
+ |
+#include <D3DCommon.h> |
+#include <D3D11.h> |
+#include <DXGI1_2.h> |
+#include <windows.h> |
+#include <wrl/client.h> |
+ |
+#include "webrtc/base/scoped_ptr.h" |
+#include "webrtc/base/thread_annotations.h" |
+#include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
+#include "webrtc/modules/desktop_capture/desktop_frame.h" |
+#include "webrtc/modules/desktop_capture/desktop_geometry.h" |
+#include "webrtc/modules/desktop_capture/desktop_region.h" |
+#include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
+ |
+namespace webrtc { |
+ |
+class Differ; |
+ |
+// ScreenCapturerWinDirectX captures 32bit RGB using DirectX. |
+class ScreenCapturerWinDirectX : public ScreenCapturer { |
+ public: |
+ // Initializes DirectX related components. Returns false if any error |
+ // happened, any instance of this class won't be able to work in such status. |
+ // Thread safe, guarded by kInitializeLock. |
+ static bool Initialize(); |
+ |
+ explicit ScreenCapturerWinDirectX(const DesktopCaptureOptions& options); |
+ virtual ~ScreenCapturerWinDirectX(); |
+ |
+ void Start(Callback* callback) override; |
+ void SetSharedMemoryFactory( |
+ rtc::scoped_ptr<SharedMemoryFactory> shared_memory_factory) override; |
+ void Capture(const DesktopRegion& region) override; |
+ bool GetScreenList(ScreenList* screens) override; |
+ bool SelectScreen(ScreenId id) override; |
+ |
+ private: |
+ // In milliseconds, consistent with windows api. |
+ const static uint32_t kAcquireTimeout = 10; |
+ |
+ static bool DoInitialize(); |
+ |
+ // Initializes kDXGIOutputDuplication. Returns false if it fails to execute |
+ // windows api. |
+ static bool DuplicateOutput(); |
+ |
+ // Initializes kStage and kSurface from a CPU inaccessible IDXGIResource. |
+ // Returns false if it fails to execute windows api. |
+ static bool CreateTexture(ID3D11Texture2D* texture); |
+ |
+ // Detect update regions in last frame, if anything wrong, returns false. |
+ // ProcessFrame will insert a whole desktop size as updated region instead. |
+ static bool DetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info, |
+ DesktopFrame* frame); |
+ |
+ // Windows accepts only one DirectX duplication per application, so most of |
Sergey Ulanov
2016/03/31 18:41:17
Ouch, is it documented anywhere?
This is an issue,
Hzj_jie
2016/04/05 23:15:18
Yes, http://shortn/_geEQFIizM3. We are fine with m
|
+ // these com instances are static. |
+ static bool kInitialized GUARDED_BY(kInitializeLock); |
+ static bool kInitializeResult GUARDED_BY(kInitializeLock); |
+ static ID3D11Device* kD3D11Device GUARDED_BY(kInitializeLock); |
+ static ID3D11DeviceContext* kD3D11Context GUARDED_BY(kInitializeLock); |
+ static IDXGIOutput1* kDXGIOutput1 GUARDED_BY(kInitializeLock); |
+ static Microsoft::WRL::ComPtr<IDXGIOutputDuplication> kDXGIOutputDuplication |
+ GUARDED_BY(kDuplicationLock); |
+ // Update with kDXGIOutputDuplication |
+ static DesktopSize kDesktopSize GUARDED_BY(kAcquireLock); |
+ // Update during ProcessFrame or DuplicateOutput (CreateTexture), they are |
+ // always pointing to the same object (thread unsafely). |
+ static Microsoft::WRL::ComPtr<ID3D11Texture2D> kStage |
+ GUARDED_BY(kAcquireLock); |
+ static Microsoft::WRL::ComPtr<IDXGISurface> kSurface GUARDED_BY(kAcquireLock); |
+ // Update during ProcessFrame (DetectUpdatedRegion). |
+ static std::vector<BYTE> kMetaDataBuffer GUARDED_BY(kAcquireLock); |
+ |
+ // Lock in Initialize function. |
+ static CriticalSectionWrapper kInitializeLock; |
+ // Lock when kDXGIOutputDuplication needs to be updated. |
+ static CriticalSectionWrapper kDuplicationLock; |
+ // Lock when kDXGIOutputDuplication is acquiring a frame or is being updated. |
+ static CriticalSectionWrapper kAcquireLock; |
+ |
+ // Process one frame received from AcquireNextFrame function, returns false if |
+ // anything wrong, and Capture function will call |
+ // callback_->OnCaptureCompleted(nullptr), otherwise |
+ // callback_->OnCaptureCompleted(frame) will be called. |
+ static bool ProcessFrame(const DXGI_OUTDUPL_FRAME_INFO& frame_info, |
+ IDXGIResource* resource, |
+ DesktopFrame** frame); |
+ |
+ void CallbackUnchanged(); |
+ void CallbackError(); |
+ |
+ // std::unique_ptr<SharedMemoryFactory> shared_memory_factory_; |
+ Callback* callback_; |
+ |
+ bool set_thread_execution_state_failed_; |
+ |
+ RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerWinDirectX); |
+}; |
+ |
+} // namespace webrtc |
+ |
+#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURER_WIN_DIRECTX_H_ |