Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(776)

Side by Side Diff: content/renderer/media/video_capture_impl_manager.cc

Issue 2377163002: VideoCaptureImpl cleanup: merge ctor+Init() and DeInit()+dtor. (Closed)
Patch Set: miu@s comment on passing |io_task_runner| argument Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 render_main_task_runner_(base::ThreadTaskRunnerHandle::Get()), 64 render_main_task_runner_(base::ThreadTaskRunnerHandle::Get()),
65 is_suspending_all_(false), 65 is_suspending_all_(false),
66 weak_factory_(this) {} 66 weak_factory_(this) {}
67 67
68 VideoCaptureImplManager::~VideoCaptureImplManager() { 68 VideoCaptureImplManager::~VideoCaptureImplManager() {
69 DCHECK(render_main_task_runner_->BelongsToCurrentThread()); 69 DCHECK(render_main_task_runner_->BelongsToCurrentThread());
70 if (devices_.empty()) 70 if (devices_.empty())
71 return; 71 return;
72 // Forcibly release all video capture resources. 72 // Forcibly release all video capture resources.
73 for (auto& entry : devices_) { 73 for (auto& entry : devices_) {
74 ChildProcess::current()->io_task_runner()->PostTask( 74 ChildProcess::current()->io_task_runner()->DeleteSoon(FROM_HERE,
75 FROM_HERE, base::Bind(&VideoCaptureImpl::DeInit, 75 entry.impl.release());
76 base::Unretained(entry.impl.get())));
77 ChildProcess::current()->io_task_runner()->DeleteSoon(
78 FROM_HERE, entry.impl.release());
79 } 76 }
80 devices_.clear(); 77 devices_.clear();
81 } 78 }
82 79
83 base::Closure VideoCaptureImplManager::UseDevice( 80 base::Closure VideoCaptureImplManager::UseDevice(
84 media::VideoCaptureSessionId id) { 81 media::VideoCaptureSessionId id) {
85 DCHECK(render_main_task_runner_->BelongsToCurrentThread()); 82 DCHECK(render_main_task_runner_->BelongsToCurrentThread());
86 auto it = std::find_if( 83 auto it = std::find_if(
87 devices_.begin(), devices_.end(), 84 devices_.begin(), devices_.end(),
88 [id] (const DeviceEntry& entry) { return entry.session_id == id; }); 85 [id] (const DeviceEntry& entry) { return entry.session_id == id; });
89 if (it == devices_.end()) { 86 if (it == devices_.end()) {
90 devices_.push_back(DeviceEntry()); 87 devices_.push_back(DeviceEntry());
91 it = devices_.end() - 1; 88 it = devices_.end() - 1;
92 it->session_id = id; 89 it->session_id = id;
93 it->impl = CreateVideoCaptureImplForTesting(id, filter_.get()); 90 it->impl = CreateVideoCaptureImplForTesting(id, filter_.get());
94 if (!it->impl) 91 if (!it->impl) {
95 it->impl.reset(new VideoCaptureImpl(id, filter_.get())); 92 it->impl.reset(new VideoCaptureImpl(
96 ChildProcess::current()->io_task_runner()->PostTask( 93 id, filter_.get(), ChildProcess::current()->io_task_runner()));
97 FROM_HERE, base::Bind(&VideoCaptureImpl::Init, 94 }
98 base::Unretained(it->impl.get())));
99 } 95 }
100 ++it->client_count; 96 ++it->client_count;
101 97
102 // Design limit: When there are multiple clients, VideoCaptureImplManager 98 // Design limit: When there are multiple clients, VideoCaptureImplManager
103 // would have to individually track which ones requested suspending/resuming, 99 // would have to individually track which ones requested suspending/resuming,
104 // in order to determine whether the whole device should be suspended. 100 // in order to determine whether the whole device should be suspended.
105 // Instead, handle the non-common use case of multiple clients by just 101 // Instead, handle the non-common use case of multiple clients by just
106 // resuming the suspended device, and disable suspend functionality while 102 // resuming the suspended device, and disable suspend functionality while
107 // there are multiple clients. 103 // there are multiple clients.
108 if (it->is_individually_suspended) 104 if (it->is_individually_suspended)
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 media::VideoCaptureSessionId id) { 227 media::VideoCaptureSessionId id) {
232 DCHECK(render_main_task_runner_->BelongsToCurrentThread()); 228 DCHECK(render_main_task_runner_->BelongsToCurrentThread());
233 const auto it = std::find_if( 229 const auto it = std::find_if(
234 devices_.begin(), devices_.end(), 230 devices_.begin(), devices_.end(),
235 [id] (const DeviceEntry& entry) { return entry.session_id == id; }); 231 [id] (const DeviceEntry& entry) { return entry.session_id == id; });
236 DCHECK(it != devices_.end()); 232 DCHECK(it != devices_.end());
237 DCHECK_GT(it->client_count, 0); 233 DCHECK_GT(it->client_count, 0);
238 --it->client_count; 234 --it->client_count;
239 if (it->client_count > 0) 235 if (it->client_count > 0)
240 return; 236 return;
241 ChildProcess::current()->io_task_runner()->PostTask( 237 ChildProcess::current()->io_task_runner()->DeleteSoon(FROM_HERE,
242 FROM_HERE, base::Bind(&VideoCaptureImpl::DeInit, 238 it->impl.release());
243 base::Unretained(it->impl.get())));
244 ChildProcess::current()->io_task_runner()->DeleteSoon(
245 FROM_HERE, it->impl.release());
246 devices_.erase(it); 239 devices_.erase(it);
247 } 240 }
248 241
249 void VideoCaptureImplManager::SuspendDevices(bool suspend) { 242 void VideoCaptureImplManager::SuspendDevices(bool suspend) {
250 DCHECK(render_main_task_runner_->BelongsToCurrentThread()); 243 DCHECK(render_main_task_runner_->BelongsToCurrentThread());
251 if (is_suspending_all_ == suspend) 244 if (is_suspending_all_ == suspend)
252 return; 245 return;
253 is_suspending_all_ = suspend; 246 is_suspending_all_ = suspend;
254 for (auto& entry : devices_) { 247 for (auto& entry : devices_) {
255 if (entry.is_individually_suspended) 248 if (entry.is_individually_suspended)
256 continue; // Either: 1) Already suspended; or 2) Should not be resumed. 249 continue; // Either: 1) Already suspended; or 2) Should not be resumed.
257 ChildProcess::current()->io_task_runner()->PostTask( 250 ChildProcess::current()->io_task_runner()->PostTask(
258 FROM_HERE, base::Bind(&VideoCaptureImpl::SuspendCapture, 251 FROM_HERE, base::Bind(&VideoCaptureImpl::SuspendCapture,
259 base::Unretained(entry.impl.get()), suspend)); 252 base::Unretained(entry.impl.get()), suspend));
260 } 253 }
261 } 254 }
262 255
263 } // namespace content 256 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/video_capture_impl.cc ('k') | content/renderer/media/video_capture_impl_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698