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..c210aa88a0a77ba800955ed5e2f801a4be9a5319 |
--- /dev/null |
+++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h |
@@ -0,0 +1,100 @@ |
+/* |
+ * 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 <windows.h> |
+#include <wrl/client.h> |
+ |
+#include <memory> |
+#include <vector> |
+ |
+#include <D3DCommon.h> |
+#include <D3D11.h> |
+#include <DXGI1_2.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_geometry.h" |
+#include "webrtc/modules/desktop_capture/desktop_region.h" |
+#include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" |
+#include "webrtc/modules/desktop_capture/win/desktop_frame_win_dxgi.h" |
+ |
+namespace webrtc { |
+ |
+// ScreenCapturerWinDirectX captures 32bit RGBA using DirectX. |
+class ScreenCapturerWinDirectX : public ScreenCapturer { |
Sergey Ulanov
2016/04/08 21:22:26
please call it ScreenCapturerWinDirectx, with lowe
Hzj_jie
2016/04/11 22:19:16
Done.
|
+ 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 initialize_lock. |
+ 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. |
+ static const uint32_t kAcquireTimeout = 10; |
+ // Wait time between two DuplicateOutput operations, DuplicateOutput may fail |
+ // if display mode is changing. |
+ static const uint32_t kDuplicateOutputWait = 50; |
+ // How many times we attempt to DuplicateOutput before returning an error to |
+ // upstream components. |
+ static const int kDuplicateOutputAttempts = 10; |
+ |
+ static bool DoInitialize(); |
+ |
+ // Initializes dxgi_output_duplication. Returns false if it fails to execute |
+ // windows api. |
+ static bool DuplicateOutput(); |
+ |
+ // 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); |
+ |
+ // 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. |
+ bool ProcessFrame(const DXGI_OUTDUPL_FRAME_INFO& frame_info, |
+ IDXGIResource* resource); |
+ |
+ void EmitCurrentFrame(); |
+ |
+ // A shortcut to replace current frame to DesktopFrameWinDxgi if it is null. |
+ // Returns the created or original DesktopFrameWinDxgi instance. Never returns |
+ // nullptr. |
+ DesktopFrameWinDxgi* ReplaceCurrentFrameIfEmpty(); |
+ |
+ ScreenCaptureFrameQueue frames_; |
+ 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_ |