Index: webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h |
diff --git a/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h b/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h |
index c9838ad7a1e5d63c918da9b22fcde0c0276d0dac..67c58aa24354506e9b67402dcbc01715e96a0999 100644 |
--- a/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h |
+++ b/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h |
@@ -13,6 +13,7 @@ |
#include <D3DCommon.h> |
+#include <atomic> |
#include <memory> |
#include <vector> |
@@ -39,8 +40,15 @@ namespace webrtc { |
// changing. Consumers should retry after a while. (Typically 50 milliseconds, |
// but according to hardware performance, this time may vary.) |
class DxgiDuplicatorController { |
+ private: |
+ struct ReferenceReleaser final { |
+ void operator()(DxgiDuplicatorController* instance) const; |
+ }; |
+ |
public: |
using Context = DxgiFrameContext; |
+ using Reference = |
+ std::unique_ptr<DxgiDuplicatorController, ReferenceReleaser>; |
Do not use (sergeyu)
2017/06/15 19:25:19
Do we really need this instead of scoped_refptr<>?
Hzj_jie
2017/06/15 20:32:02
I can imagine three solutions by using scoped_refp
Sergey Ulanov
2017/06/16 05:59:58
I was thinking about (3), but I think (1) may work
|
// A collection of D3d information we are interested on, which may impact |
// capturer performance or reliability. |
@@ -65,14 +73,11 @@ class DxgiDuplicatorController { |
INVALID_MONITOR_ID, |
}; |
+ // Deprecated: use "GetRefence()" instead. |
// Returns the singleton instance of DxgiDuplicatorController. |
static DxgiDuplicatorController* Instance(); |
- // Destructs current instance. We need to make sure COM components and their |
- // containers are destructed in correct order. This function calls |
- // Deinitialize() to do the real work. |
- ~DxgiDuplicatorController(); |
- |
+ static Reference GetReference(); |
// All the following public functions implicitly call Initialize() function. |
// Detects whether the system supports DXGI based capturer. |
@@ -108,15 +113,23 @@ class DxgiDuplicatorController { |
friend DxgiFrameContext::~DxgiFrameContext(); |
// A private constructor to ensure consumers to use |
- // DxgiDuplicatorController::Instance(). |
+ // DxgiDuplicatorController::GetReference(). |
DxgiDuplicatorController(); |
+ // Not implemented: The singleton DxgiDuplicatorController instance should not |
+ // be deleted. |
+ ~DxgiDuplicatorController(); |
+ |
// Does the real duplication work. Setting |monitor_id| < 0 to capture entire |
// screen. This function calls Initialize(). And if the duplication failed, |
// this function calls Deinitialize() to ensure the Dxgi components can be |
// reinitialized next time. |
Result DoDuplicate(DxgiFrame* frame, int monitor_id); |
+ // Unload all the DXGI components and releases the resources. This function |
+ // wraps Deinitialize() with |lock_|. |
+ void Unload(); |
+ |
// Unregisters Context from this instance and all DxgiAdapterDuplicator(s) |
// it owns. |
void Unregister(const Context* const context); |
@@ -185,6 +198,9 @@ class DxgiDuplicatorController { |
// DxgiAdapterDuplicator and DxgiOutputDuplicator instances are initialized. |
void TranslateRect(); |
+ // The count of references which are now "living". |
+ static std::atomic_int refcount_; |
+ |
// This lock must be locked whenever accessing any of the following objects. |
rtc::CriticalSection lock_; |