Commit 8a2cfaf3 authored by mflodman@chromium.org's avatar mflodman@chromium.org

Close video capture devices on the device thread.


Review URL: http://codereview.chromium.org/8589018

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110780 0039d316-1c4b-4281-b951-d872f2087c98
parent d9b46713
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "content/browser/renderer_host/media/video_capture_manager.h" #include "content/browser/renderer_host/media/video_capture_manager.h"
#include <set>
#include "base/bind.h" #include "base/bind.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "content/browser/renderer_host/media/video_capture_controller.h" #include "content/browser/renderer_host/media/video_capture_controller.h"
...@@ -45,19 +47,19 @@ VideoCaptureManager::VideoCaptureManager() ...@@ -45,19 +47,19 @@ VideoCaptureManager::VideoCaptureManager()
} }
VideoCaptureManager::~VideoCaptureManager() { VideoCaptureManager::~VideoCaptureManager() {
vc_device_thread_.Stop();
// TODO(mflodman) Remove this temporary solution when shut-down issue is // TODO(mflodman) Remove this temporary solution when shut-down issue is
// resolved, i.e. all code below this comment. // resolved, i.e. all code below this comment.
// Temporary solution: close all open devices and delete them, after the // Temporary solution: close all open devices and delete them, after the
// thread is stopped. // thread is stopped.
DLOG_IF(ERROR, !devices_.empty()) << "VideoCaptureManager: Open devices!"; DLOG_IF(ERROR, !devices_.empty()) << "VideoCaptureManager: Open devices!";
for (VideoCaptureDevices::iterator it = devices_.begin(); listener_ = NULL;
it != devices_.end(); // The devices must be stopped on the device thread to avoid threading issues
++it) { // in native device code.
it->second->DeAllocate(); vc_device_thread_.message_loop()->PostTask(
delete it->second; FROM_HERE,
} base::Bind(&VideoCaptureManager::TerminateOnDeviceThread,
STLDeleteValues(&controllers_); base::Unretained(this)));
vc_device_thread_.Stop();
} }
void VideoCaptureManager::Register(MediaStreamProviderListener* listener) { void VideoCaptureManager::Register(MediaStreamProviderListener* listener) {
...@@ -502,4 +504,17 @@ media::VideoCaptureDevice* VideoCaptureManager::GetDeviceInternal( ...@@ -502,4 +504,17 @@ media::VideoCaptureDevice* VideoCaptureManager::GetDeviceInternal(
return NULL; 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 } // namespace media_stream
...@@ -123,6 +123,7 @@ class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider { ...@@ -123,6 +123,7 @@ class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider {
const StreamDeviceInfo& device_info); const StreamDeviceInfo& device_info);
bool IsOnCaptureDeviceThread() const; bool IsOnCaptureDeviceThread() const;
media::VideoCaptureDevice* GetDeviceInternal(int capture_session_id); media::VideoCaptureDevice* GetDeviceInternal(int capture_session_id);
void TerminateOnDeviceThread();
// Thread for all calls to VideoCaptureDevice. // Thread for all calls to VideoCaptureDevice.
base::Thread vc_device_thread_; base::Thread vc_device_thread_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment