| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/media/video_capture_impl_manager.h" | 5 #include "content/renderer/media/video_capture_impl_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/renderer/media/rtc_encoding_video_capturer_factory.h" |
| 9 #include "content/renderer/media/video_capture_impl.h" | 10 #include "content/renderer/media/video_capture_impl.h" |
| 10 #include "content/renderer/media/video_capture_message_filter.h" | 11 #include "content/renderer/media/video_capture_message_filter.h" |
| 11 | 12 |
| 12 namespace content { | 13 namespace content { |
| 13 | 14 |
| 14 VideoCaptureImplManager::VideoCaptureImplManager() | 15 VideoCaptureImplManager::VideoCaptureImplManager() |
| 15 : thread_("VC manager") { | 16 : thread_("VC manager") { |
| 16 thread_.Start(); | 17 thread_.Start(); |
| 17 message_loop_proxy_ = thread_.message_loop_proxy(); | 18 message_loop_proxy_ = thread_.message_loop_proxy(); |
| 18 filter_ = new VideoCaptureMessageFilter(); | 19 filter_ = new VideoCaptureMessageFilter(); |
| 19 } | 20 } |
| 20 | 21 |
| 21 media::VideoCapture* VideoCaptureImplManager::AddDevice( | 22 media::VideoCapture* VideoCaptureImplManager::AddDevice( |
| 22 media::VideoCaptureSessionId id, | 23 media::VideoCaptureSessionId id, |
| 23 media::VideoCapture::EventHandler* handler) { | 24 media::VideoCapture::EventHandler* handler) { |
| 24 DCHECK(handler); | 25 DCHECK(handler); |
| 25 | 26 |
| 26 base::AutoLock auto_lock(lock_); | 27 base::AutoLock auto_lock(lock_); |
| 27 Devices::iterator it = devices_.find(id); | 28 Devices::iterator it = devices_.find(id); |
| 28 if (it == devices_.end()) { | 29 if (it == devices_.end()) { |
| 29 VideoCaptureImpl* vc = | 30 VideoCaptureImpl* vc = |
| 30 new VideoCaptureImpl(id, message_loop_proxy_.get(), filter_.get()); | 31 new VideoCaptureImpl(id, message_loop_proxy_.get(), filter_.get()); |
| 31 devices_[id] = new Device(vc, handler); | 32 devices_[id] = new Device(vc, handler); |
| 32 vc->Init(); | 33 vc->Init(); |
| 34 if (encoding_capturer_factory_) |
| 35 encoding_capturer_factory_->OnEncodedVideoSourceAdded(vc); |
| 33 return vc; | 36 return vc; |
| 34 } | 37 } |
| 35 | 38 |
| 36 devices_[id]->clients.push_front(handler); | 39 devices_[id]->clients.push_front(handler); |
| 37 return it->second->vc; | 40 return it->second->vc; |
| 38 } | 41 } |
| 39 | 42 |
| 40 void VideoCaptureImplManager::SuspendDevices(bool suspend) { | 43 void VideoCaptureImplManager::SuspendDevices(bool suspend) { |
| 41 base::AutoLock auto_lock(lock_); | 44 base::AutoLock auto_lock(lock_); |
| 42 for (Devices::iterator it = devices_.begin(); it != devices_.end(); ++it) | 45 for (Devices::iterator it = devices_.begin(); it != devices_.end(); ++it) |
| 43 it->second->vc->SuspendCapture(suspend); | 46 it->second->vc->SuspendCapture(suspend); |
| 44 } | 47 } |
| 45 | 48 |
| 46 void VideoCaptureImplManager::RemoveDevice( | 49 void VideoCaptureImplManager::RemoveDevice( |
| 47 media::VideoCaptureSessionId id, | 50 media::VideoCaptureSessionId id, |
| 48 media::VideoCapture::EventHandler* handler) { | 51 media::VideoCapture::EventHandler* handler) { |
| 49 DCHECK(handler); | 52 DCHECK(handler); |
| 50 | 53 |
| 51 base::AutoLock auto_lock(lock_); | 54 base::AutoLock auto_lock(lock_); |
| 52 Devices::iterator it = devices_.find(id); | 55 Devices::iterator it = devices_.find(id); |
| 53 if (it == devices_.end()) | 56 if (it == devices_.end()) |
| 54 return; | 57 return; |
| 55 | 58 |
| 56 size_t size = it->second->clients.size(); | 59 size_t size = it->second->clients.size(); |
| 57 it->second->clients.remove(handler); | 60 it->second->clients.remove(handler); |
| 58 | 61 |
| 59 if (size == it->second->clients.size() || size > 1) | 62 if (size == it->second->clients.size() || size > 1) |
| 60 return; | 63 return; |
| 61 | 64 |
| 65 if (encoding_capturer_factory_) |
| 66 encoding_capturer_factory_->OnEncodedVideoSourceRemoved(devices_[id]->vc); |
| 67 |
| 62 devices_[id]->vc->DeInit(base::Bind(&VideoCaptureImplManager::FreeDevice, | 68 devices_[id]->vc->DeInit(base::Bind(&VideoCaptureImplManager::FreeDevice, |
| 63 this, devices_[id]->vc)); | 69 this, devices_[id]->vc)); |
| 64 delete devices_[id]; | 70 delete devices_[id]; |
| 65 devices_.erase(id); | 71 devices_.erase(id); |
| 66 } | 72 } |
| 67 | 73 |
| 68 void VideoCaptureImplManager::FreeDevice(VideoCaptureImpl* vc) { | 74 void VideoCaptureImplManager::FreeDevice(VideoCaptureImpl* vc) { |
| 69 delete vc; | 75 delete vc; |
| 70 } | 76 } |
| 71 | 77 |
| 72 VideoCaptureImplManager::~VideoCaptureImplManager() { | 78 VideoCaptureImplManager::~VideoCaptureImplManager() { |
| 73 thread_.Stop(); | 79 thread_.Stop(); |
| 74 // TODO(wjia): uncomment the line below after collecting enough info for | 80 // TODO(wjia): uncomment the line below after collecting enough info for |
| 75 // crbug.com/152418. | 81 // crbug.com/152418. |
| 76 // STLDeleteContainerPairSecondPointers(devices_.begin(), devices_.end()); | 82 // STLDeleteContainerPairSecondPointers(devices_.begin(), devices_.end()); |
| 77 } | 83 } |
| 78 | 84 |
| 79 VideoCaptureImplManager::Device::Device( | 85 VideoCaptureImplManager::Device::Device( |
| 80 VideoCaptureImpl* device, | 86 VideoCaptureImpl* device, |
| 81 media::VideoCapture::EventHandler* handler) | 87 media::VideoCapture::EventHandler* handler) |
| 82 : vc(device) { | 88 : vc(device) { |
| 83 clients.push_front(handler); | 89 clients.push_front(handler); |
| 84 } | 90 } |
| 85 | 91 |
| 86 VideoCaptureImplManager::Device::~Device() {} | 92 VideoCaptureImplManager::Device::~Device() {} |
| 87 | 93 |
| 88 } // namespace content | 94 } // namespace content |
| OLD | NEW |