Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/media/video_capture_manager.h" | 5 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "content/browser/renderer_host/media/video_capture_controller.h" | 9 #include "content/browser/renderer_host/media/video_capture_controller.h" |
| 10 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" | 10 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 | 38 |
| 39 VideoCaptureManager::VideoCaptureManager() | 39 VideoCaptureManager::VideoCaptureManager() |
| 40 : vc_device_thread_("VideoCaptureManagerThread"), | 40 : vc_device_thread_("VideoCaptureManagerThread"), |
| 41 listener_(NULL), | 41 listener_(NULL), |
| 42 new_capture_session_id_(kFirstSessionId), | 42 new_capture_session_id_(kFirstSessionId), |
| 43 use_fake_device_(false) { | 43 use_fake_device_(false) { |
| 44 vc_device_thread_.Start(); | 44 vc_device_thread_.Start(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 VideoCaptureManager::~VideoCaptureManager() { | 47 VideoCaptureManager::~VideoCaptureManager() { |
| 48 vc_device_thread_.Stop(); | |
| 49 // TODO(mflodman) Remove this temporary solution when shut-down issue is | 48 // TODO(mflodman) Remove this temporary solution when shut-down issue is |
| 50 // resolved, i.e. all code below this comment. | 49 // resolved, i.e. all code below this comment. |
| 51 // Temporary solution: close all open devices and delete them, after the | 50 // Temporary solution: close all open devices and delete them, after the |
| 52 // thread is stopped. | 51 // thread is stopped. |
| 53 DLOG_IF(ERROR, !devices_.empty()) << "VideoCaptureManager: Open devices!"; | 52 DLOG_IF(ERROR, !devices_.empty()) << "VideoCaptureManager: Open devices!"; |
| 54 for (VideoCaptureDevices::iterator it = devices_.begin(); | 53 listener_ = NULL; |
| 55 it != devices_.end(); | 54 // The devices must be stopped on the device thread to avoid threading issues |
| 56 ++it) { | 55 // in native device code. |
| 57 it->second->DeAllocate(); | 56 vc_device_thread_.message_loop()->PostTask( |
| 58 delete it->second; | 57 FROM_HERE, |
| 59 } | 58 base::Bind(&VideoCaptureManager::TerminateOnDeviceThread, |
| 60 STLDeleteValues(&controllers_); | 59 base::Unretained(this))); |
| 60 vc_device_thread_.message_loop()->PostTask(FROM_HERE, | |
| 61 new MessageLoop::QuitTask); | |
|
wjia(left Chromium)
2011/11/17 19:06:30
QuitTask is not needed. vc_device_thread_.Stop() w
mflodman_chromium_OOO
2011/11/18 08:22:45
Done.
| |
| 62 vc_device_thread_.Stop(); | |
| 61 } | 63 } |
| 62 | 64 |
| 63 void VideoCaptureManager::Register(MediaStreamProviderListener* listener) { | 65 void VideoCaptureManager::Register(MediaStreamProviderListener* listener) { |
| 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 65 DCHECK(!listener_); | 67 DCHECK(!listener_); |
| 66 listener_ = listener; | 68 listener_ = listener; |
| 67 } | 69 } |
| 68 | 70 |
| 69 void VideoCaptureManager::Unregister() { | 71 void VideoCaptureManager::Unregister() { |
| 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 OnOpen(capture_session_id, device); | 497 OnOpen(capture_session_id, device); |
| 496 | 498 |
| 497 VideoCaptureDevices::iterator dit = devices_.find(capture_session_id); | 499 VideoCaptureDevices::iterator dit = devices_.find(capture_session_id); |
| 498 if (dit != devices_.end()) { | 500 if (dit != devices_.end()) { |
| 499 return dit->second; | 501 return dit->second; |
| 500 } | 502 } |
| 501 } | 503 } |
| 502 return NULL; | 504 return NULL; |
| 503 } | 505 } |
| 504 | 506 |
| 507 void VideoCaptureManager::TerminateOnDeviceThread() { | |
| 508 DCHECK(IsOnCaptureDeviceThread()); | |
| 509 | |
| 510 for (VideoCaptureDevices::iterator it = devices_.begin(); | |
| 511 it != devices_.end(); ++it) { | |
| 512 it->second->DeAllocate(); | |
| 513 delete it->second; | |
|
wjia(left Chromium)
2011/11/17 19:06:30
There was a bug here since multiple capture_sessio
mflodman_chromium_OOO
2011/11/18 08:22:45
Done.
| |
| 514 } | |
| 515 STLDeleteValues(&controllers_); | |
| 516 } | |
| 517 | |
| 505 } // namespace media_stream | 518 } // namespace media_stream |
| OLD | NEW |