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/browser/renderer_host/media/video_capture_manager.h" | 5 #include "content/browser/renderer_host/media/video_capture_manager.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 VideoCaptureManager::DeviceEntry::DeviceEntry( | 32 VideoCaptureManager::DeviceEntry::DeviceEntry( |
33 MediaStreamType stream_type, | 33 MediaStreamType stream_type, |
34 const std::string& id, | 34 const std::string& id, |
35 scoped_ptr<VideoCaptureController> controller) | 35 scoped_ptr<VideoCaptureController> controller) |
36 : stream_type(stream_type), | 36 : stream_type(stream_type), |
37 id(id), | 37 id(id), |
38 video_capture_controller(controller.Pass()) {} | 38 video_capture_controller(controller.Pass()) {} |
39 | 39 |
40 VideoCaptureManager::DeviceEntry::~DeviceEntry() {} | 40 VideoCaptureManager::DeviceEntry::~DeviceEntry() {} |
41 | 41 |
42 VideoCaptureManager::DeviceInfo::DeviceInfo() {} | |
43 | |
44 VideoCaptureManager::DeviceInfo::DeviceInfo( | |
45 const media::VideoCaptureDevice::Name& name, | |
46 const media::VideoCaptureCapabilities& capabilities) | |
47 : capability_in_use_(), | |
48 name_(name), | |
49 capabilities_(capabilities) {} | |
50 | |
51 VideoCaptureManager::DeviceInfo::~DeviceInfo() {} | |
52 | |
42 VideoCaptureManager::VideoCaptureManager() | 53 VideoCaptureManager::VideoCaptureManager() |
43 : listener_(NULL), | 54 : listener_(NULL), |
44 new_capture_session_id_(1), | 55 new_capture_session_id_(1), |
45 use_fake_device_(false) { | 56 use_fake_device_(false) { |
46 } | 57 } |
47 | 58 |
48 VideoCaptureManager::~VideoCaptureManager() { | 59 VideoCaptureManager::~VideoCaptureManager() { |
49 DCHECK(devices_.empty()); | 60 DCHECK(devices_.empty()); |
50 } | 61 } |
51 | 62 |
52 void VideoCaptureManager::Register(MediaStreamProviderListener* listener, | 63 void VideoCaptureManager::Register(MediaStreamProviderListener* listener, |
53 base::MessageLoopProxy* device_thread_loop) { | 64 base::MessageLoopProxy* device_thread_loop) { |
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
55 DCHECK(!listener_); | 66 DCHECK(!listener_); |
56 DCHECK(!device_loop_.get()); | 67 DCHECK(!device_loop_.get()); |
57 listener_ = listener; | 68 listener_ = listener; |
58 device_loop_ = device_thread_loop; | 69 device_loop_ = device_thread_loop; |
59 } | 70 } |
60 | 71 |
61 void VideoCaptureManager::Unregister() { | 72 void VideoCaptureManager::Unregister() { |
62 DCHECK(listener_); | 73 DCHECK(listener_); |
63 listener_ = NULL; | 74 listener_ = NULL; |
64 } | 75 } |
65 | 76 |
66 void VideoCaptureManager::EnumerateDevices(MediaStreamType stream_type) { | 77 void VideoCaptureManager::EnumerateDevices(MediaStreamType stream_type) { |
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
68 DVLOG(1) << "VideoCaptureManager::EnumerateDevices, type " << stream_type; | 79 DVLOG(1) << "VideoCaptureManager::EnumerateDevices, type " << stream_type; |
69 DCHECK(listener_); | 80 DCHECK(listener_); |
70 base::PostTaskAndReplyWithResult( | 81 base::PostTaskAndReplyWithResult( |
71 device_loop_, FROM_HERE, | 82 device_loop_, |
72 base::Bind(&VideoCaptureManager::GetAvailableDevicesOnDeviceThread, this, | 83 FROM_HERE, |
84 base::Bind(&VideoCaptureManager::GetAvailableDevicesOnDeviceThread, | |
85 this, | |
73 stream_type), | 86 stream_type), |
74 base::Bind(&VideoCaptureManager::OnDevicesEnumerated, this, stream_type)); | 87 base::Bind( |
88 &VideoCaptureManager::OnDeviceNamesEnumerated, this, stream_type)); | |
75 } | 89 } |
76 | 90 |
77 int VideoCaptureManager::Open(const StreamDeviceInfo& device_info) { | 91 int VideoCaptureManager::Open(const StreamDeviceInfo& device_info) { |
78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
79 DCHECK(listener_); | 93 DCHECK(listener_); |
80 | 94 |
81 // Generate a new id for the session being opened. | 95 // Generate a new id for the session being opened. |
82 const int capture_session_id = new_capture_session_id_++; | 96 const int capture_session_id = new_capture_session_id_++; |
83 | 97 |
84 DCHECK(sessions_.find(capture_session_id) == sessions_.end()); | 98 DCHECK(sessions_.find(capture_session_id) == sessions_.end()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 capture_session_id)); | 140 capture_session_id)); |
127 sessions_.erase(session_it); | 141 sessions_.erase(session_it); |
128 } | 142 } |
129 | 143 |
130 void VideoCaptureManager::UseFakeDevice() { | 144 void VideoCaptureManager::UseFakeDevice() { |
131 use_fake_device_ = true; | 145 use_fake_device_ = true; |
132 } | 146 } |
133 | 147 |
134 void VideoCaptureManager::DoStartDeviceOnDeviceThread( | 148 void VideoCaptureManager::DoStartDeviceOnDeviceThread( |
135 DeviceEntry* entry, | 149 DeviceEntry* entry, |
150 const media::VideoCaptureDevice::Name* device_name, | |
ncarter (slow)
2013/11/09 01:49:11
The interface to this function gets kind of weird
mcasas
2013/11/11 17:39:59
Done.
| |
136 const media::VideoCaptureCapability& capture_params, | 151 const media::VideoCaptureCapability& capture_params, |
137 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { | 152 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { |
138 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); | 153 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); |
139 DCHECK(IsOnDeviceThread()); | 154 DCHECK(IsOnDeviceThread()); |
140 | 155 |
141 scoped_ptr<media::VideoCaptureDevice> video_capture_device; | 156 scoped_ptr<media::VideoCaptureDevice> video_capture_device; |
142 switch (entry->stream_type) { | 157 switch (entry->stream_type) { |
143 case MEDIA_DEVICE_VIDEO_CAPTURE: { | 158 case MEDIA_DEVICE_VIDEO_CAPTURE: { |
144 // We look up the device id from the renderer in our local enumeration | 159 // We look up the device id from the renderer in our local enumeration |
145 // since the renderer does not have all the information that might be | 160 // since the renderer does not have all the information that might be |
146 // held in the browser-side VideoCaptureDevice::Name structure. | 161 // held in the browser-side VideoCaptureDevice::Name structure. |
147 media::VideoCaptureDevice::Name* found = | 162 if (device_name) { |
148 video_capture_devices_.FindById(entry->id); | 163 video_capture_device.reset(use_fake_device_ |
149 if (found) { | 164 ? media::FakeVideoCaptureDevice::Create(*device_name) |
150 video_capture_device.reset(use_fake_device_ ? | 165 : media::VideoCaptureDevice::Create(*device_name)); |
151 media::FakeVideoCaptureDevice::Create(*found) : | |
152 media::VideoCaptureDevice::Create(*found)); | |
153 } | 166 } |
154 break; | 167 break; |
155 } | 168 } |
156 case MEDIA_TAB_VIDEO_CAPTURE: { | 169 case MEDIA_TAB_VIDEO_CAPTURE: { |
157 video_capture_device.reset( | 170 video_capture_device.reset( |
158 WebContentsVideoCaptureDevice::Create(entry->id)); | 171 WebContentsVideoCaptureDevice::Create(entry->id)); |
159 break; | 172 break; |
160 } | 173 } |
161 case MEDIA_DESKTOP_VIDEO_CAPTURE: { | 174 case MEDIA_DESKTOP_VIDEO_CAPTURE: { |
162 #if defined(ENABLE_SCREEN_CAPTURE) | 175 #if defined(ENABLE_SCREEN_CAPTURE) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 DVLOG(1) << "VideoCaptureManager starting device (type = " | 222 DVLOG(1) << "VideoCaptureManager starting device (type = " |
210 << entry->stream_type << ", id = " << entry->id << ")"; | 223 << entry->stream_type << ", id = " << entry->id << ")"; |
211 | 224 |
212 media::VideoCaptureCapability params_as_capability; | 225 media::VideoCaptureCapability params_as_capability; |
213 params_as_capability.width = params.requested_format.width; | 226 params_as_capability.width = params.requested_format.width; |
214 params_as_capability.height = params.requested_format.height; | 227 params_as_capability.height = params.requested_format.height; |
215 params_as_capability.frame_rate = params.requested_format.frame_rate; | 228 params_as_capability.frame_rate = params.requested_format.frame_rate; |
216 params_as_capability.frame_size_type = | 229 params_as_capability.frame_size_type = |
217 params.requested_format.frame_size_type; | 230 params.requested_format.frame_size_type; |
218 | 231 |
232 DeviceInfo* found = FindDeviceInfoById(entry->id); | |
ncarter (slow)
2013/11/09 01:49:11
Should we be doing this for only for MEDIA_DEVICE_
mcasas
2013/11/11 17:39:59
Done.
| |
233 if (found) { | |
234 found->capability_in_use_ = params_as_capability; | |
ncarter (slow)
2013/11/09 01:49:11
Because you're mirroring this state into the Devic
mcasas
2013/11/11 17:39:59
Done.
| |
235 } | |
219 device_loop_->PostTask(FROM_HERE, base::Bind( | 236 device_loop_->PostTask(FROM_HERE, base::Bind( |
220 &VideoCaptureManager::DoStartDeviceOnDeviceThread, this, | 237 &VideoCaptureManager::DoStartDeviceOnDeviceThread, this, |
221 entry, params_as_capability, | 238 entry, |
239 (found ? & found->name_ : NULL), | |
ncarter (slow)
2013/11/09 01:49:11
Isn't this use of found->name_ unsafe? What guaran
mcasas
2013/11/11 17:39:59
Done.
| |
240 params_as_capability, | |
222 base::Passed(entry->video_capture_controller->NewDeviceClient()))); | 241 base::Passed(entry->video_capture_controller->NewDeviceClient()))); |
223 } | 242 } |
224 // Run the callback first, as AddClient() may trigger OnFrameInfo(). | 243 // Run the callback first, as AddClient() may trigger OnFrameInfo(). |
225 done_cb.Run(entry->video_capture_controller->GetWeakPtr()); | 244 done_cb.Run(entry->video_capture_controller->GetWeakPtr()); |
226 entry->video_capture_controller->AddClient(client_id, | 245 entry->video_capture_controller->AddClient(client_id, |
227 client_handler, | 246 client_handler, |
228 client_render_process, | 247 client_render_process, |
229 params); | 248 params); |
230 } | 249 } |
231 | 250 |
(...skipping 13 matching lines...) Expand all Loading... | |
245 | 264 |
246 // Detach client from controller. | 265 // Detach client from controller. |
247 int session_id = controller->RemoveClient(client_id, client_handler); | 266 int session_id = controller->RemoveClient(client_id, client_handler); |
248 DVLOG(1) << "VideoCaptureManager::StopCaptureForClient, session_id = " | 267 DVLOG(1) << "VideoCaptureManager::StopCaptureForClient, session_id = " |
249 << session_id; | 268 << session_id; |
250 | 269 |
251 // If controller has no more clients, delete controller and device. | 270 // If controller has no more clients, delete controller and device. |
252 DestroyDeviceEntryIfNoClients(entry); | 271 DestroyDeviceEntryIfNoClients(entry); |
253 } | 272 } |
254 | 273 |
274 void VideoCaptureManager::GetDeviceCapabilities( | |
275 int capture_session_id, | |
276 media::VideoCaptureCapabilities* capabilities) { | |
277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
278 capabilities->clear(); | |
279 | |
280 std::map<int, MediaStreamDevice>::iterator it = | |
281 sessions_.find(capture_session_id); | |
282 DCHECK(it != sessions_.end()); | |
283 DVLOG(1) << "GetDeviceCapabilities for device: " << it->second.name; | |
284 | |
285 DeviceInfo* device = FindDeviceInfoById(it->second.id); | |
286 if (device) { | |
287 DeviceEntry* const existing_device = | |
288 GetDeviceEntryForMediaStreamDevice(it->second); | |
289 if (existing_device) | |
290 capabilities->push_back(device->capability_in_use_); | |
291 else | |
292 *capabilities = device->capabilities_; | |
293 } | |
294 } | |
295 | |
255 void VideoCaptureManager::DoStopDeviceOnDeviceThread(DeviceEntry* entry) { | 296 void VideoCaptureManager::DoStopDeviceOnDeviceThread(DeviceEntry* entry) { |
256 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime"); | 297 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime"); |
257 DCHECK(IsOnDeviceThread()); | 298 DCHECK(IsOnDeviceThread()); |
258 if (entry->video_capture_device) { | 299 if (entry->video_capture_device) { |
259 entry->video_capture_device->StopAndDeAllocate(); | 300 entry->video_capture_device->StopAndDeAllocate(); |
260 } | 301 } |
261 entry->video_capture_device.reset(); | 302 entry->video_capture_device.reset(); |
262 } | 303 } |
263 | 304 |
264 void VideoCaptureManager::OnOpened(MediaStreamType stream_type, | 305 void VideoCaptureManager::OnOpened(MediaStreamType stream_type, |
265 int capture_session_id) { | 306 int capture_session_id) { |
266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
267 if (!listener_) { | 308 if (!listener_) { |
268 // Listener has been removed. | 309 // Listener has been removed. |
269 return; | 310 return; |
270 } | 311 } |
271 listener_->Opened(stream_type, capture_session_id); | 312 listener_->Opened(stream_type, capture_session_id); |
272 } | 313 } |
273 | 314 |
274 void VideoCaptureManager::OnClosed(MediaStreamType stream_type, | 315 void VideoCaptureManager::OnClosed(MediaStreamType stream_type, |
275 int capture_session_id) { | 316 int capture_session_id) { |
276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 317 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
277 if (!listener_) { | 318 if (!listener_) { |
278 // Listener has been removed. | 319 // Listener has been removed. |
279 return; | 320 return; |
280 } | 321 } |
281 listener_->Closed(stream_type, capture_session_id); | 322 listener_->Closed(stream_type, capture_session_id); |
282 } | 323 } |
283 | 324 |
284 void VideoCaptureManager::OnDevicesEnumerated( | 325 void VideoCaptureManager::OnDeviceNamesEnumerated( |
285 MediaStreamType stream_type, | 326 MediaStreamType stream_type, |
286 const media::VideoCaptureDevice::Names& device_names) { | 327 const media::VideoCaptureDevice::Names& names_snapshot) { |
287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
288 | |
289 if (!listener_) { | 329 if (!listener_) { |
290 // Listener has been removed. | 330 // Listener has been removed. |
291 return; | 331 return; |
292 } | 332 } |
293 | 333 |
294 // Transform from VCD::Name to StreamDeviceInfo. | 334 // Eliminate from |devices_info_cache_| all devices not in the snapshot. |
295 StreamDeviceInfoArray devices; | 335 ScopedVector<DeviceInfo>::iterator it_device_info = |
296 for (media::VideoCaptureDevice::Names::const_iterator it = | 336 devices_info_cache_.begin(); |
297 device_names.begin(); it != device_names.end(); ++it) { | 337 while (it_device_info != devices_info_cache_.end()) { |
298 devices.push_back(StreamDeviceInfo( | 338 media::VideoCaptureDevice::Names::const_iterator it; |
299 stream_type, it->GetNameAndModel(), it->id())); | 339 for (it = names_snapshot.begin(); it != names_snapshot.end(); ++it) { |
340 if ((*it_device_info)->name_.id() == it->id()) | |
341 break; | |
342 } | |
343 if (it == names_snapshot.end()) | |
344 devices_info_cache_.erase(it_device_info++); | |
345 else | |
346 ++it_device_info; | |
300 } | 347 } |
301 | 348 |
302 listener_->DevicesEnumerated(stream_type, devices); | 349 // Truly new devices are put in |new_device_names|, and we need to retrieve |
350 // their capabilities. | |
351 media::VideoCaptureDevice::Names new_device_names; | |
352 for (media::VideoCaptureDevice::Names::const_iterator it = | |
353 names_snapshot.begin(); | |
354 it != names_snapshot.end(); | |
355 ++it) { | |
356 DeviceInfo* device_info = FindDeviceInfoById(it->id()); | |
357 if (!device_info) | |
358 new_device_names.push_back(*it); | |
359 } | |
360 base::PostTaskAndReplyWithResult( | |
361 device_loop_, | |
362 FROM_HERE, | |
363 base::Bind(&VideoCaptureManager::GetDevicesCapabilitiesOnDeviceThread, | |
364 this, | |
365 new_device_names), | |
366 base::Bind(&VideoCaptureManager::OnDeviceNameAndCapabilitiesEnumerated, | |
367 this, | |
368 stream_type)); | |
ncarter (slow)
2013/11/09 01:49:11
Could we make this enumeration work with only one
mcasas
2013/11/11 17:39:59
See global comments :) short answer: yes
| |
369 } | |
370 | |
371 void VideoCaptureManager::OnDeviceNameAndCapabilitiesEnumerated( | |
372 MediaStreamType stream_type, | |
373 ScopedVector<DeviceInfo> new_devices_info) { | |
374 DVLOG(1) << "OnDeviceNameAndCapabilitiesEnumerated, #new devices: " | |
375 << new_devices_info.size(); | |
376 | |
377 ScopedVector<DeviceInfo>::iterator it = new_devices_info.begin(); | |
378 while (it != new_devices_info.end()) { | |
379 devices_info_cache_.push_back(*it); | |
380 it = new_devices_info.weak_erase(it); | |
381 } | |
382 | |
383 // Walk the |devices_info_cache_| and transform from VCD::Name to | |
384 // StreamDeviceInfo for return purposes. | |
385 StreamDeviceInfoArray devices; | |
386 for (ScopedVector<DeviceInfo>::const_iterator it = | |
387 devices_info_cache_.begin(); | |
388 it != devices_info_cache_.end(); | |
389 ++it) { | |
390 devices.push_back(StreamDeviceInfo( | |
391 stream_type, (*it)->name_.GetNameAndModel(), (*it)->name_.id())); | |
392 } | |
393 // |listener_| might have disappeared while we were scanning the devices. | |
394 if (listener_) | |
395 listener_->DevicesEnumerated(stream_type, devices); | |
303 } | 396 } |
304 | 397 |
305 bool VideoCaptureManager::IsOnDeviceThread() const { | 398 bool VideoCaptureManager::IsOnDeviceThread() const { |
306 return device_loop_->BelongsToCurrentThread(); | 399 return device_loop_->BelongsToCurrentThread(); |
307 } | 400 } |
308 | 401 |
309 media::VideoCaptureDevice::Names | 402 media::VideoCaptureDevice::Names |
310 VideoCaptureManager::GetAvailableDevicesOnDeviceThread( | 403 VideoCaptureManager::GetAvailableDevicesOnDeviceThread( |
311 MediaStreamType stream_type) { | 404 MediaStreamType stream_type) { |
312 SCOPED_UMA_HISTOGRAM_TIMER( | 405 SCOPED_UMA_HISTOGRAM_TIMER( |
313 "Media.VideoCaptureManager.GetAvailableDevicesTime"); | 406 "Media.VideoCaptureManager.GetAvailableDevicesTime"); |
314 DCHECK(IsOnDeviceThread()); | 407 DCHECK(IsOnDeviceThread()); |
315 media::VideoCaptureDevice::Names result; | 408 media::VideoCaptureDevice::Names names; |
316 | 409 |
317 switch (stream_type) { | 410 switch (stream_type) { |
318 case MEDIA_DEVICE_VIDEO_CAPTURE: | 411 case MEDIA_DEVICE_VIDEO_CAPTURE: |
319 // Cache the latest enumeration of video capture devices. | 412 if (!use_fake_device_) |
320 // We'll refer to this list again in OnOpen to avoid having to | 413 media::VideoCaptureDevice::GetDeviceNames(&names); |
321 // enumerate the devices again. | 414 else |
322 if (!use_fake_device_) { | 415 media::FakeVideoCaptureDevice::GetDeviceNames(&names); |
323 media::VideoCaptureDevice::GetDeviceNames(&result); | |
324 } else { | |
325 media::FakeVideoCaptureDevice::GetDeviceNames(&result); | |
326 } | |
327 | |
328 // TODO(nick): The correctness of device start depends on this cache being | |
329 // maintained, but it seems a little odd to keep a cache here. Can we | |
330 // eliminate it? | |
331 video_capture_devices_ = result; | |
332 break; | 416 break; |
333 | 417 |
334 case MEDIA_DESKTOP_VIDEO_CAPTURE: | 418 case MEDIA_DESKTOP_VIDEO_CAPTURE: |
335 // Do nothing. | 419 // Do nothing. |
336 break; | 420 break; |
337 | 421 |
338 default: | 422 default: |
339 NOTREACHED(); | 423 NOTREACHED(); |
340 break; | 424 break; |
341 } | 425 } |
342 return result; | 426 return names; |
427 } | |
428 | |
429 ScopedVector<VideoCaptureManager::DeviceInfo> | |
430 VideoCaptureManager::GetDevicesCapabilitiesOnDeviceThread( | |
431 const media::VideoCaptureDevice::Names& device_names) { | |
432 DCHECK(IsOnDeviceThread()); | |
433 DVLOG(1) << "GetDevicesCapabilitiesOnDeviceThread"; | |
434 | |
435 ScopedVector<DeviceInfo> device_info_vector; | |
436 for (media::VideoCaptureDevice::Names::const_iterator it = | |
437 device_names.begin(); | |
438 it != device_names.end(); | |
439 ++it) { | |
440 media::VideoCaptureCapabilities capabilities; | |
441 DeviceInfo* device_info = | |
442 new DeviceInfo((*it), media::VideoCaptureCapabilities()); | |
443 if (!use_fake_device_) { | |
444 media::VideoCaptureDevice::GetDeviceSupportedFormats( | |
445 *it, &(device_info->capabilities_)); | |
446 } else { | |
447 media::FakeVideoCaptureDevice::GetDeviceSupportedFormats( | |
448 *it, &(device_info->capabilities_)); | |
449 } | |
450 device_info_vector.push_back(device_info); | |
451 } | |
452 return device_info_vector.Pass(); | |
343 } | 453 } |
344 | 454 |
345 VideoCaptureManager::DeviceEntry* | 455 VideoCaptureManager::DeviceEntry* |
346 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice( | 456 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice( |
347 const MediaStreamDevice& device_info) { | 457 const MediaStreamDevice& device_info) { |
348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
349 | 459 |
350 for (DeviceEntries::iterator it = devices_.begin(); | 460 for (DeviceEntries::iterator it = devices_.begin(); |
351 it != devices_.end(); ++it) { | 461 it != devices_.end(); ++it) { |
352 DeviceEntry* device = *it; | 462 DeviceEntry* device = *it; |
(...skipping 26 matching lines...) Expand all Loading... | |
379 << entry->stream_type << ", id = " << entry->id << ")"; | 489 << entry->stream_type << ", id = " << entry->id << ")"; |
380 | 490 |
381 // The DeviceEntry is removed from |devices_| immediately. The controller is | 491 // The DeviceEntry is removed from |devices_| immediately. The controller is |
382 // deleted immediately, and the device is freed asynchronously. After this | 492 // deleted immediately, and the device is freed asynchronously. After this |
383 // point, subsequent requests to open this same device ID will create a new | 493 // point, subsequent requests to open this same device ID will create a new |
384 // DeviceEntry, VideoCaptureController, and VideoCaptureDevice. | 494 // DeviceEntry, VideoCaptureController, and VideoCaptureDevice. |
385 devices_.erase(entry); | 495 devices_.erase(entry); |
386 entry->video_capture_controller.reset(); | 496 entry->video_capture_controller.reset(); |
387 device_loop_->PostTask( | 497 device_loop_->PostTask( |
388 FROM_HERE, | 498 FROM_HERE, |
389 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, | 499 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, |
500 this, | |
390 base::Owned(entry))); | 501 base::Owned(entry))); |
391 } | 502 } |
392 } | 503 } |
393 | 504 |
394 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry( | 505 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry( |
395 int capture_session_id) { | 506 int capture_session_id) { |
396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 507 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
397 | 508 |
398 std::map<int, MediaStreamDevice>::iterator session_it = | 509 std::map<int, MediaStreamDevice>::iterator session_it = |
399 sessions_.find(capture_session_id); | 510 sessions_.find(capture_session_id); |
(...skipping 13 matching lines...) Expand all Loading... | |
413 | 524 |
414 scoped_ptr<VideoCaptureController> video_capture_controller( | 525 scoped_ptr<VideoCaptureController> video_capture_controller( |
415 new VideoCaptureController()); | 526 new VideoCaptureController()); |
416 DeviceEntry* new_device = new DeviceEntry(device_info.type, | 527 DeviceEntry* new_device = new DeviceEntry(device_info.type, |
417 device_info.id, | 528 device_info.id, |
418 video_capture_controller.Pass()); | 529 video_capture_controller.Pass()); |
419 devices_.insert(new_device); | 530 devices_.insert(new_device); |
420 return new_device; | 531 return new_device; |
421 } | 532 } |
422 | 533 |
534 VideoCaptureManager::DeviceInfo* VideoCaptureManager::FindDeviceInfoById( | |
535 const std::string& id) { | |
536 for (ScopedVector<DeviceInfo>::iterator it = devices_info_cache_.begin(); | |
537 it != devices_info_cache_.end(); ++it) { | |
538 if ((*it)->name_.id() == id) | |
539 return *it; | |
540 } | |
541 return NULL; | |
542 } | |
543 | |
423 } // namespace content | 544 } // namespace content |
OLD | NEW |