Index: webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc |
diff --git a/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc b/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc |
index c17bd1481c7fffa9e09939e3fbcb75f70deaee87..e6a51ee57b89c46d32d8136f519d50b90393a310 100644 |
--- a/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc |
+++ b/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc |
@@ -16,6 +16,7 @@ |
#include <string> |
#include "webrtc/base/checks.h" |
+#include "webrtc/base/logging.h" |
#include "webrtc/base/timeutils.h" |
#include "webrtc/modules/desktop_capture/desktop_capture_types.h" |
#include "webrtc/modules/desktop_capture/win/dxgi_frame.h" |
@@ -25,6 +26,9 @@ |
namespace webrtc { |
// static |
+std::atomic_int DxgiDuplicatorController::refcount_(0); |
Sergey Ulanov
2017/06/19 18:52:43
Does this value need to be static?
Hzj_jie
2017/06/19 20:19:46
Since we have only one DxgiDuplicatorController in
|
+ |
+// static |
DxgiDuplicatorController* DxgiDuplicatorController::Instance() { |
// The static instance won't be deleted to ensure it can be used by other |
// threads even during program exiting. |
@@ -32,11 +36,26 @@ DxgiDuplicatorController* DxgiDuplicatorController::Instance() { |
return instance; |
} |
+// static |
+DxgiDuplicatorController::Reference DxgiDuplicatorController::GetReference() { |
+ return Reference(Instance()); |
+} |
+ |
DxgiDuplicatorController::DxgiDuplicatorController() = default; |
-DxgiDuplicatorController::~DxgiDuplicatorController() { |
- rtc::CritScope lock(&lock_); |
- Deinitialize(); |
+void DxgiDuplicatorController::AddRef() const { |
+ int refcount = (++refcount_); |
+ RTC_DCHECK(refcount > 0); |
+} |
+ |
+void DxgiDuplicatorController::Release() { |
+ int refcount = (--refcount_); |
+ RTC_DCHECK(refcount >= 0); |
+ if (refcount == 0) { |
+ LOG(LS_WARNING) << "Count of references reaches zero, " |
+ "DxgiDuplicatorController will be unloaded."; |
+ Unload(); |
+ } |
} |
bool DxgiDuplicatorController::IsSupported() { |
@@ -129,6 +148,11 @@ DxgiDuplicatorController::DoDuplicate(DxgiFrame* frame, int monitor_id) { |
return Result::DUPLICATION_FAILED; |
} |
+void DxgiDuplicatorController::Unload() { |
+ rtc::CritScope lock(&lock_); |
+ Deinitialize(); |
+} |
+ |
void DxgiDuplicatorController::Unregister(const Context* const context) { |
rtc::CritScope lock(&lock_); |
if (ContextExpired(context)) { |