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