| 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 // Implementation notes about interactions with VideoCaptureImpl. | 5 // Implementation notes about interactions with VideoCaptureImpl. |
| 6 // | 6 // |
| 7 // How is VideoCaptureImpl used: | 7 // How is VideoCaptureImpl used: |
| 8 // | 8 // |
| 9 // VideoCaptureImpl is an IO thread object while VideoCaptureImplManager | 9 // VideoCaptureImpl is an IO thread object while VideoCaptureImplManager |
| 10 // lives only on the render thread. It is only possible to access an | 10 // lives only on the render thread. It is only possible to access an |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 render_main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 41 render_main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 42 weak_factory_(this) {} | 42 weak_factory_(this) {} |
| 43 | 43 |
| 44 VideoCaptureImplManager::~VideoCaptureImplManager() { | 44 VideoCaptureImplManager::~VideoCaptureImplManager() { |
| 45 DCHECK(render_main_task_runner_->BelongsToCurrentThread()); | 45 DCHECK(render_main_task_runner_->BelongsToCurrentThread()); |
| 46 if (devices_.empty()) | 46 if (devices_.empty()) |
| 47 return; | 47 return; |
| 48 // Forcibly release all video capture resources. | 48 // Forcibly release all video capture resources. |
| 49 for (const auto& device : devices_) { | 49 for (const auto& device : devices_) { |
| 50 VideoCaptureImpl* const impl = device.second.second; | 50 VideoCaptureImpl* const impl = device.second.second; |
| 51 ChildProcess::current()->io_task_runner()->PostTask( | |
| 52 FROM_HERE, | |
| 53 base::Bind(&VideoCaptureImpl::DeInit, base::Unretained(impl))); | |
| 54 ChildProcess::current()->io_task_runner()->DeleteSoon(FROM_HERE, impl); | 51 ChildProcess::current()->io_task_runner()->DeleteSoon(FROM_HERE, impl); |
| 55 } | 52 } |
| 56 devices_.clear(); | 53 devices_.clear(); |
| 57 } | 54 } |
| 58 | 55 |
| 59 base::Closure VideoCaptureImplManager::UseDevice( | 56 base::Closure VideoCaptureImplManager::UseDevice( |
| 60 media::VideoCaptureSessionId id) { | 57 media::VideoCaptureSessionId id) { |
| 61 DCHECK(render_main_task_runner_->BelongsToCurrentThread()); | 58 DCHECK(render_main_task_runner_->BelongsToCurrentThread()); |
| 62 VideoCaptureImpl* impl = NULL; | 59 VideoCaptureImpl* impl = NULL; |
| 63 const VideoCaptureDeviceMap::iterator it = devices_.find(id); | 60 const VideoCaptureDeviceMap::iterator it = devices_.find(id); |
| 64 if (it == devices_.end()) { | 61 if (it == devices_.end()) { |
| 65 impl = CreateVideoCaptureImplForTesting(id, filter_.get()); | 62 impl = CreateVideoCaptureImplForTesting(id, filter_.get()); |
| 66 if (!impl) | 63 if (!impl) { |
| 67 impl = new VideoCaptureImpl(id, filter_.get()); | 64 impl = new VideoCaptureImpl(id, filter_.get(), |
| 65 ChildProcess::current()->io_task_runner()); |
| 66 } |
| 68 devices_[id] = std::make_pair(1, impl); | 67 devices_[id] = std::make_pair(1, impl); |
| 69 ChildProcess::current()->io_task_runner()->PostTask( | |
| 70 FROM_HERE, base::Bind(&VideoCaptureImpl::Init, base::Unretained(impl))); | |
| 71 } else { | 68 } else { |
| 72 ++it->second.first; | 69 ++it->second.first; |
| 73 } | 70 } |
| 74 return base::Bind(&VideoCaptureImplManager::UnrefDevice, | 71 return base::Bind(&VideoCaptureImplManager::UnrefDevice, |
| 75 weak_factory_.GetWeakPtr(), id); | 72 weak_factory_.GetWeakPtr(), id); |
| 76 } | 73 } |
| 77 | 74 |
| 78 base::Closure VideoCaptureImplManager::StartCapture( | 75 base::Closure VideoCaptureImplManager::StartCapture( |
| 79 media::VideoCaptureSessionId id, | 76 media::VideoCaptureSessionId id, |
| 80 const media::VideoCaptureParams& params, | 77 const media::VideoCaptureParams& params, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 DCHECK(render_main_task_runner_->BelongsToCurrentThread()); | 152 DCHECK(render_main_task_runner_->BelongsToCurrentThread()); |
| 156 const VideoCaptureDeviceMap::iterator it = devices_.find(id); | 153 const VideoCaptureDeviceMap::iterator it = devices_.find(id); |
| 157 DCHECK(it != devices_.end()); | 154 DCHECK(it != devices_.end()); |
| 158 VideoCaptureImpl* const impl = it->second.second; | 155 VideoCaptureImpl* const impl = it->second.second; |
| 159 | 156 |
| 160 // Unref and destroy on the IO thread if there's no more client. | 157 // Unref and destroy on the IO thread if there's no more client. |
| 161 DCHECK(it->second.first); | 158 DCHECK(it->second.first); |
| 162 --it->second.first; | 159 --it->second.first; |
| 163 if (!it->second.first) { | 160 if (!it->second.first) { |
| 164 devices_.erase(id); | 161 devices_.erase(id); |
| 165 ChildProcess::current()->io_task_runner()->PostTask( | |
| 166 FROM_HERE, | |
| 167 base::Bind(&VideoCaptureImpl::DeInit, base::Unretained(impl))); | |
| 168 ChildProcess::current()->io_task_runner()->DeleteSoon(FROM_HERE, impl); | 162 ChildProcess::current()->io_task_runner()->DeleteSoon(FROM_HERE, impl); |
| 169 } | 163 } |
| 170 } | 164 } |
| 171 | 165 |
| 172 void VideoCaptureImplManager::SuspendDevices(bool suspend) { | 166 void VideoCaptureImplManager::SuspendDevices(bool suspend) { |
| 173 DCHECK(render_main_task_runner_->BelongsToCurrentThread()); | 167 DCHECK(render_main_task_runner_->BelongsToCurrentThread()); |
| 174 for (const auto& device : devices_) { | 168 for (const auto& device : devices_) { |
| 175 VideoCaptureImpl* const impl = device.second.second; | 169 VideoCaptureImpl* const impl = device.second.second; |
| 176 ChildProcess::current()->io_task_runner()->PostTask( | 170 ChildProcess::current()->io_task_runner()->PostTask( |
| 177 FROM_HERE, base::Bind(&VideoCaptureImpl::SuspendCapture, | 171 FROM_HERE, base::Bind(&VideoCaptureImpl::SuspendCapture, |
| 178 base::Unretained(impl), suspend)); | 172 base::Unretained(impl), suspend)); |
| 179 } | 173 } |
| 180 } | 174 } |
| 181 | 175 |
| 182 } // namespace content | 176 } // namespace content |
| OLD | NEW |