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

Unified Diff: content/browser/renderer_host/media/video_capture_manager.cc

Issue 8589018: Close video capture devices on the device thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes based on review by wjia. Created 9 years, 1 month 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
« no previous file with comments | « content/browser/renderer_host/media/video_capture_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/media/video_capture_manager.cc
diff --git a/content/browser/renderer_host/media/video_capture_manager.cc b/content/browser/renderer_host/media/video_capture_manager.cc
index ce686e60e4dcd3113d870d11cc68f1625e54394b..e65eb9d2c12c78c5e4603454fbd5f10478c3e070 100644
--- a/content/browser/renderer_host/media/video_capture_manager.cc
+++ b/content/browser/renderer_host/media/video_capture_manager.cc
@@ -4,6 +4,8 @@
#include "content/browser/renderer_host/media/video_capture_manager.h"
+#include <set>
+
#include "base/bind.h"
#include "base/stl_util.h"
#include "content/browser/renderer_host/media/video_capture_controller.h"
@@ -45,19 +47,19 @@ VideoCaptureManager::VideoCaptureManager()
}
VideoCaptureManager::~VideoCaptureManager() {
- vc_device_thread_.Stop();
// TODO(mflodman) Remove this temporary solution when shut-down issue is
// resolved, i.e. all code below this comment.
// Temporary solution: close all open devices and delete them, after the
// thread is stopped.
DLOG_IF(ERROR, !devices_.empty()) << "VideoCaptureManager: Open devices!";
- for (VideoCaptureDevices::iterator it = devices_.begin();
- it != devices_.end();
- ++it) {
- it->second->DeAllocate();
- delete it->second;
- }
- STLDeleteValues(&controllers_);
+ listener_ = NULL;
+ // The devices must be stopped on the device thread to avoid threading issues
+ // in native device code.
+ vc_device_thread_.message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&VideoCaptureManager::TerminateOnDeviceThread,
+ base::Unretained(this)));
+ vc_device_thread_.Stop();
}
void VideoCaptureManager::Register(MediaStreamProviderListener* listener) {
@@ -502,4 +504,17 @@ media::VideoCaptureDevice* VideoCaptureManager::GetDeviceInternal(
return NULL;
}
+void VideoCaptureManager::TerminateOnDeviceThread() {
+ DCHECK(IsOnCaptureDeviceThread());
+
+ std::set<media::VideoCaptureDevice*> devices_to_delete;
+ for (VideoCaptureDevices::iterator it = devices_.begin();
+ it != devices_.end(); ++it) {
+ it->second->DeAllocate();
+ devices_to_delete.insert(it->second);
+ }
+ STLDeleteElements(&devices_to_delete);
+ STLDeleteValues(&controllers_);
+}
+
} // namespace media_stream
« no previous file with comments | « content/browser/renderer_host/media/video_capture_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698