Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(806)

Unified Diff: webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc

Issue 2933893003: Add reference counter of DxgiDuplicatorController to unload DXGI components (Closed)
Patch Set: Add reference counter for DxgiDuplicatorController Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..e1a9febb77aba879484c112dc26db2d31d1ab8a6 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);
+
+// 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,13 +36,28 @@ DxgiDuplicatorController* DxgiDuplicatorController::Instance() {
return instance;
}
-DxgiDuplicatorController::DxgiDuplicatorController() = default;
+// static
+DxgiDuplicatorController::Reference DxgiDuplicatorController::GetReference() {
+ Reference result(Instance());
+ int refcount = (++refcount_);
+ RTC_DCHECK(refcount > 0);
+ return result;
+}
-DxgiDuplicatorController::~DxgiDuplicatorController() {
- rtc::CritScope lock(&lock_);
- Deinitialize();
+// static
+void DxgiDuplicatorController::ReferenceReleaser::operator()(
+ DxgiDuplicatorController* instance) const {
+ int refcount = (--refcount_);
+ RTC_DCHECK(refcount >= 0);
+ if (refcount == 0) {
+ LOG(LS_WARNING) << "Count of references reaches zero, "
+ "DxgiDuplicatorController will be unloaded.";
+ instance->Unload();
+ }
}
+DxgiDuplicatorController::DxgiDuplicatorController() = default;
+
bool DxgiDuplicatorController::IsSupported() {
rtc::CritScope lock(&lock_);
return Initialize();
@@ -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)) {

Powered by Google App Engine
This is Rietveld 408576698