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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/task_runner_util.h" | |
15 #include "base/threading/sequenced_worker_pool.h" | 14 #include "base/threading/sequenced_worker_pool.h" |
16 #include "content/browser/renderer_host/media/video_capture_controller.h" | 15 #include "content/browser/renderer_host/media/video_capture_controller.h" |
17 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" | 16 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" |
18 #include "content/browser/renderer_host/media/web_contents_video_capture_device.
h" | 17 #include "content/browser/renderer_host/media/web_contents_video_capture_device.
h" |
19 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
21 #include "content/public/common/desktop_media_id.h" | 20 #include "content/public/common/desktop_media_id.h" |
22 #include "content/public/common/media_stream_request.h" | 21 #include "content/public/common/media_stream_request.h" |
23 #include "media/base/scoped_histogram_timer.h" | 22 #include "media/base/scoped_histogram_timer.h" |
24 #include "media/video/capture/fake_video_capture_device.h" | 23 #include "media/video/capture/fake_video_capture_device.h" |
25 #include "media/video/capture/video_capture_device.h" | 24 #include "media/video/capture/video_capture_device.h" |
26 | 25 |
27 #if defined(ENABLE_SCREEN_CAPTURE) | 26 #if defined(ENABLE_SCREEN_CAPTURE) |
28 #include "content/browser/renderer_host/media/desktop_capture_device.h" | 27 #include "content/browser/renderer_host/media/desktop_capture_device.h" |
29 #endif | 28 #endif |
30 | 29 |
31 namespace content { | 30 namespace content { |
32 | 31 |
33 VideoCaptureManager::DeviceEntry::DeviceEntry( | 32 VideoCaptureManager::DeviceEntry::DeviceEntry( |
34 MediaStreamType stream_type, | 33 MediaStreamType stream_type, |
35 const std::string& id, | 34 const std::string& id, |
36 scoped_ptr<VideoCaptureController> controller) | 35 scoped_ptr<VideoCaptureController> controller) |
37 : stream_type(stream_type), | 36 : stream_type(stream_type), |
38 id(id), | 37 id(id), |
39 video_capture_controller(controller.Pass()) {} | 38 video_capture_controller(controller.Pass()) {} |
40 | 39 |
41 VideoCaptureManager::DeviceEntry::~DeviceEntry() {} | 40 VideoCaptureManager::DeviceEntry::~DeviceEntry() {} |
42 | 41 |
43 VideoCaptureManager::DeviceInfo::DeviceInfo() {} | |
44 | |
45 VideoCaptureManager::DeviceInfo::DeviceInfo( | |
46 const media::VideoCaptureDevice::Name& name, | |
47 const media::VideoCaptureCapabilities& capabilities) | |
48 : name(name), | |
49 capabilities(capabilities) {} | |
50 | |
51 VideoCaptureManager::DeviceInfo::~DeviceInfo() {} | |
52 | |
53 VideoCaptureManager::VideoCaptureManager() | 42 VideoCaptureManager::VideoCaptureManager() |
54 : listener_(NULL), | 43 : listener_(NULL), |
55 new_capture_session_id_(1), | 44 new_capture_session_id_(1), |
56 use_fake_device_(false) { | 45 use_fake_device_(false) { |
57 } | 46 } |
58 | 47 |
59 VideoCaptureManager::~VideoCaptureManager() { | 48 VideoCaptureManager::~VideoCaptureManager() { |
60 DCHECK(devices_.empty()); | 49 DCHECK(devices_.empty()); |
61 } | 50 } |
62 | 51 |
63 void VideoCaptureManager::Register(MediaStreamProviderListener* listener, | 52 void VideoCaptureManager::Register(MediaStreamProviderListener* listener, |
64 base::MessageLoopProxy* device_thread_loop) { | 53 base::MessageLoopProxy* device_thread_loop) { |
65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
66 DCHECK(!listener_); | 55 DCHECK(!listener_); |
67 DCHECK(!device_loop_.get()); | 56 DCHECK(!device_loop_.get()); |
68 listener_ = listener; | 57 listener_ = listener; |
69 device_loop_ = device_thread_loop; | 58 device_loop_ = device_thread_loop; |
70 } | 59 } |
71 | 60 |
72 void VideoCaptureManager::Unregister() { | 61 void VideoCaptureManager::Unregister() { |
73 DCHECK(listener_); | 62 DCHECK(listener_); |
74 listener_ = NULL; | 63 listener_ = NULL; |
75 } | 64 } |
76 | 65 |
77 void VideoCaptureManager::EnumerateDevices(MediaStreamType stream_type) { | 66 void VideoCaptureManager::EnumerateDevices(MediaStreamType stream_type) { |
78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
79 DVLOG(1) << "VideoCaptureManager::EnumerateDevices, type " << stream_type; | 68 DVLOG(1) << "VideoCaptureManager::EnumerateDevices, type " << stream_type; |
80 DCHECK(listener_); | 69 DCHECK(listener_); |
81 | |
82 base::PostTaskAndReplyWithResult( | 70 base::PostTaskAndReplyWithResult( |
83 device_loop_, | 71 device_loop_, FROM_HERE, |
84 FROM_HERE, | 72 base::Bind(&VideoCaptureManager::GetAvailableDevicesOnDeviceThread, this, |
85 base::Bind(&VideoCaptureManager:: | 73 stream_type), |
86 GetAvailableDevicesAndCapabilitiesOnDeviceThread, | 74 base::Bind(&VideoCaptureManager::OnDevicesEnumerated, this, stream_type)); |
87 this, | |
88 stream_type, | |
89 devices_info_cache_), | |
90 base::Bind(&VideoCaptureManager::OnDeviceNamesAndCapabilitiesEnumerated, | |
91 this, | |
92 stream_type)); | |
93 } | 75 } |
94 | 76 |
95 int VideoCaptureManager::Open(const StreamDeviceInfo& device_info) { | 77 int VideoCaptureManager::Open(const StreamDeviceInfo& device_info) { |
96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
97 DCHECK(listener_); | 79 DCHECK(listener_); |
98 | 80 |
99 // Generate a new id for the session being opened. | 81 // Generate a new id for the session being opened. |
100 const int capture_session_id = new_capture_session_id_++; | 82 const int capture_session_id = new_capture_session_id_++; |
101 | 83 |
102 DCHECK(sessions_.find(capture_session_id) == sessions_.end()); | 84 DCHECK(sessions_.find(capture_session_id) == sessions_.end()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { | 137 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { |
156 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); | 138 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); |
157 DCHECK(IsOnDeviceThread()); | 139 DCHECK(IsOnDeviceThread()); |
158 | 140 |
159 scoped_ptr<media::VideoCaptureDevice> video_capture_device; | 141 scoped_ptr<media::VideoCaptureDevice> video_capture_device; |
160 switch (entry->stream_type) { | 142 switch (entry->stream_type) { |
161 case MEDIA_DEVICE_VIDEO_CAPTURE: { | 143 case MEDIA_DEVICE_VIDEO_CAPTURE: { |
162 // We look up the device id from the renderer in our local enumeration | 144 // We look up the device id from the renderer in our local enumeration |
163 // since the renderer does not have all the information that might be | 145 // since the renderer does not have all the information that might be |
164 // held in the browser-side VideoCaptureDevice::Name structure. | 146 // held in the browser-side VideoCaptureDevice::Name structure. |
165 DeviceInfo* found = FindDeviceInfoById(entry->id, devices_info_cache_); | 147 media::VideoCaptureDevice::Name* found = |
| 148 video_capture_devices_.FindById(entry->id); |
166 if (found) { | 149 if (found) { |
167 video_capture_device.reset(use_fake_device_ ? | 150 video_capture_device.reset(use_fake_device_ ? |
168 media::FakeVideoCaptureDevice::Create(found->name) : | 151 media::FakeVideoCaptureDevice::Create(*found) : |
169 media::VideoCaptureDevice::Create(found->name)); | 152 media::VideoCaptureDevice::Create(*found)); |
170 } | 153 } |
171 break; | 154 break; |
172 } | 155 } |
173 case MEDIA_TAB_VIDEO_CAPTURE: { | 156 case MEDIA_TAB_VIDEO_CAPTURE: { |
174 video_capture_device.reset( | 157 video_capture_device.reset( |
175 WebContentsVideoCaptureDevice::Create(entry->id)); | 158 WebContentsVideoCaptureDevice::Create(entry->id)); |
176 break; | 159 break; |
177 } | 160 } |
178 case MEDIA_DESKTOP_VIDEO_CAPTURE: { | 161 case MEDIA_DESKTOP_VIDEO_CAPTURE: { |
179 #if defined(ENABLE_SCREEN_CAPTURE) | 162 #if defined(ENABLE_SCREEN_CAPTURE) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 | 211 |
229 media::VideoCaptureCapability params_as_capability; | 212 media::VideoCaptureCapability params_as_capability; |
230 params_as_capability.width = params.requested_format.width; | 213 params_as_capability.width = params.requested_format.width; |
231 params_as_capability.height = params.requested_format.height; | 214 params_as_capability.height = params.requested_format.height; |
232 params_as_capability.frame_rate = params.requested_format.frame_rate; | 215 params_as_capability.frame_rate = params.requested_format.frame_rate; |
233 params_as_capability.frame_size_type = | 216 params_as_capability.frame_size_type = |
234 params.requested_format.frame_size_type; | 217 params.requested_format.frame_size_type; |
235 | 218 |
236 device_loop_->PostTask(FROM_HERE, base::Bind( | 219 device_loop_->PostTask(FROM_HERE, base::Bind( |
237 &VideoCaptureManager::DoStartDeviceOnDeviceThread, this, | 220 &VideoCaptureManager::DoStartDeviceOnDeviceThread, this, |
238 entry, | 221 entry, params_as_capability, |
239 params_as_capability, | |
240 base::Passed(entry->video_capture_controller->NewDeviceClient()))); | 222 base::Passed(entry->video_capture_controller->NewDeviceClient()))); |
241 } | 223 } |
242 // Run the callback first, as AddClient() may trigger OnFrameInfo(). | 224 // Run the callback first, as AddClient() may trigger OnFrameInfo(). |
243 done_cb.Run(entry->video_capture_controller->GetWeakPtr()); | 225 done_cb.Run(entry->video_capture_controller->GetWeakPtr()); |
244 entry->video_capture_controller->AddClient(client_id, | 226 entry->video_capture_controller->AddClient(client_id, |
245 client_handler, | 227 client_handler, |
246 client_render_process, | 228 client_render_process, |
247 params); | 229 params); |
248 } | 230 } |
249 | 231 |
(...skipping 13 matching lines...) Expand all Loading... |
263 | 245 |
264 // Detach client from controller. | 246 // Detach client from controller. |
265 int session_id = controller->RemoveClient(client_id, client_handler); | 247 int session_id = controller->RemoveClient(client_id, client_handler); |
266 DVLOG(1) << "VideoCaptureManager::StopCaptureForClient, session_id = " | 248 DVLOG(1) << "VideoCaptureManager::StopCaptureForClient, session_id = " |
267 << session_id; | 249 << session_id; |
268 | 250 |
269 // If controller has no more clients, delete controller and device. | 251 // If controller has no more clients, delete controller and device. |
270 DestroyDeviceEntryIfNoClients(entry); | 252 DestroyDeviceEntryIfNoClients(entry); |
271 } | 253 } |
272 | 254 |
273 void VideoCaptureManager::GetDeviceCapabilities( | |
274 int capture_session_id, | |
275 media::VideoCaptureCapabilities* capabilities) { | |
276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
277 capabilities->clear(); | |
278 | |
279 std::map<int, MediaStreamDevice>::iterator it = | |
280 sessions_.find(capture_session_id); | |
281 DCHECK(it != sessions_.end()); | |
282 DVLOG(1) << "GetDeviceCapabilities for device: " << it->second.name; | |
283 | |
284 DeviceInfo* device_in_use = | |
285 FindDeviceInfoById(it->second.id, devices_info_cache_); | |
286 DCHECK(device_in_use); | |
287 if (device_in_use) { | |
288 DeviceEntry* const existing_device = | |
289 GetDeviceEntryForMediaStreamDevice(it->second); | |
290 if (!existing_device) { | |
291 // If the device is not in use, just return all its cached capabilities. | |
292 *capabilities = device_in_use->capabilities; | |
293 return; | |
294 } | |
295 // Otherwise, get the video capture parameters in use from the controller | |
296 // associated to the device. | |
297 media::VideoCaptureFormat format = | |
298 existing_device->video_capture_controller->GetVideoCaptureFormat(); | |
299 media::VideoCaptureCapability current_format(format.width, | |
300 format.height, | |
301 format.frame_rate, | |
302 media::PIXEL_FORMAT_I420, | |
303 format.frame_size_type); | |
304 capabilities->push_back(current_format); | |
305 } | |
306 } | |
307 | |
308 void VideoCaptureManager::DoStopDeviceOnDeviceThread(DeviceEntry* entry) { | 255 void VideoCaptureManager::DoStopDeviceOnDeviceThread(DeviceEntry* entry) { |
309 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime"); | 256 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime"); |
310 DCHECK(IsOnDeviceThread()); | 257 DCHECK(IsOnDeviceThread()); |
311 if (entry->video_capture_device) { | 258 if (entry->video_capture_device) { |
312 entry->video_capture_device->StopAndDeAllocate(); | 259 entry->video_capture_device->StopAndDeAllocate(); |
313 } | 260 } |
314 entry->video_capture_device.reset(); | 261 entry->video_capture_device.reset(); |
315 } | 262 } |
316 | 263 |
317 void VideoCaptureManager::OnOpened(MediaStreamType stream_type, | 264 void VideoCaptureManager::OnOpened(MediaStreamType stream_type, |
318 int capture_session_id) { | 265 int capture_session_id) { |
319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
320 if (!listener_) { | 267 if (!listener_) { |
321 // Listener has been removed. | 268 // Listener has been removed. |
322 return; | 269 return; |
323 } | 270 } |
324 listener_->Opened(stream_type, capture_session_id); | 271 listener_->Opened(stream_type, capture_session_id); |
325 } | 272 } |
326 | 273 |
327 void VideoCaptureManager::OnClosed(MediaStreamType stream_type, | 274 void VideoCaptureManager::OnClosed(MediaStreamType stream_type, |
328 int capture_session_id) { | 275 int capture_session_id) { |
329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
330 if (!listener_) { | 277 if (!listener_) { |
331 // Listener has been removed. | 278 // Listener has been removed. |
332 return; | 279 return; |
333 } | 280 } |
334 listener_->Closed(stream_type, capture_session_id); | 281 listener_->Closed(stream_type, capture_session_id); |
335 } | 282 } |
336 | 283 |
337 void VideoCaptureManager::OnDeviceNamesAndCapabilitiesEnumerated( | 284 void VideoCaptureManager::OnDevicesEnumerated( |
338 MediaStreamType stream_type, | 285 MediaStreamType stream_type, |
339 const DevicesInfo& new_devices_info_cache) { | 286 const media::VideoCaptureDevice::Names& device_names) { |
340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
341 DVLOG(1) << "OnDeviceNameAndCapabilitiesEnumerated, #new devices: " | 288 |
342 << new_devices_info_cache.size(); | 289 if (!listener_) { |
343 if (!listener_) { // Listener has been removed. | 290 // Listener has been removed. |
344 return; | 291 return; |
345 } | 292 } |
346 devices_info_cache_ = new_devices_info_cache; | |
347 | 293 |
348 // Walk the |devices_info_cache_| and transform from VCD::Name to | 294 // Transform from VCD::Name to StreamDeviceInfo. |
349 // StreamDeviceInfo for return purposes. | |
350 StreamDeviceInfoArray devices; | 295 StreamDeviceInfoArray devices; |
351 for (DevicesInfo::const_iterator it = devices_info_cache_.begin(); | 296 for (media::VideoCaptureDevice::Names::const_iterator it = |
352 it != devices_info_cache_.end(); | 297 device_names.begin(); it != device_names.end(); ++it) { |
353 ++it) { | |
354 devices.push_back(StreamDeviceInfo( | 298 devices.push_back(StreamDeviceInfo( |
355 stream_type, it->name.GetNameAndModel(), it->name.id())); | 299 stream_type, it->GetNameAndModel(), it->id())); |
356 } | 300 } |
| 301 |
357 listener_->DevicesEnumerated(stream_type, devices); | 302 listener_->DevicesEnumerated(stream_type, devices); |
358 } | 303 } |
359 | 304 |
360 bool VideoCaptureManager::IsOnDeviceThread() const { | 305 bool VideoCaptureManager::IsOnDeviceThread() const { |
361 return device_loop_->BelongsToCurrentThread(); | 306 return device_loop_->BelongsToCurrentThread(); |
362 } | 307 } |
363 | 308 |
364 VideoCaptureManager::DevicesInfo | 309 media::VideoCaptureDevice::Names |
365 VideoCaptureManager::GetAvailableDevicesAndCapabilitiesOnDeviceThread( | 310 VideoCaptureManager::GetAvailableDevicesOnDeviceThread( |
366 MediaStreamType stream_type, | 311 MediaStreamType stream_type) { |
367 const DevicesInfo& old_device_info_cache) { | |
368 SCOPED_UMA_HISTOGRAM_TIMER( | 312 SCOPED_UMA_HISTOGRAM_TIMER( |
369 "Media.VideoCaptureManager." | 313 "Media.VideoCaptureManager.GetAvailableDevicesTime"); |
370 "GetAvailableDevicesAndCapabilitiesOnDeviceThreadTime"); | |
371 DCHECK(IsOnDeviceThread()); | 314 DCHECK(IsOnDeviceThread()); |
372 media::VideoCaptureDevice::Names names_snapshot; | 315 media::VideoCaptureDevice::Names result; |
| 316 |
373 switch (stream_type) { | 317 switch (stream_type) { |
374 case MEDIA_DEVICE_VIDEO_CAPTURE: | 318 case MEDIA_DEVICE_VIDEO_CAPTURE: |
375 if (!use_fake_device_) | 319 // Cache the latest enumeration of video capture devices. |
376 media::VideoCaptureDevice::GetDeviceNames(&names_snapshot); | 320 // We'll refer to this list again in OnOpen to avoid having to |
377 else | 321 // enumerate the devices again. |
378 media::FakeVideoCaptureDevice::GetDeviceNames(&names_snapshot); | 322 if (!use_fake_device_) { |
| 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; |
379 break; | 332 break; |
| 333 |
380 case MEDIA_DESKTOP_VIDEO_CAPTURE: | 334 case MEDIA_DESKTOP_VIDEO_CAPTURE: |
381 // Do nothing. | 335 // Do nothing. |
382 break; | 336 break; |
| 337 |
383 default: | 338 default: |
384 NOTREACHED(); | 339 NOTREACHED(); |
385 break; | 340 break; |
386 } | 341 } |
387 | 342 return result; |
388 // Construct |new_devices_info_cache| with the cached devices that are still | |
389 // present in the system, and remove their names from |names_snapshot|, so we | |
390 // keep there the truly new devices. | |
391 DevicesInfo new_devices_info_cache; | |
392 for (DevicesInfo::const_iterator it_device_info = | |
393 old_device_info_cache.begin(); | |
394 it_device_info != old_device_info_cache.end(); | |
395 ++it_device_info) { | |
396 media::VideoCaptureDevice::Names::iterator it; | |
397 for (it = names_snapshot.begin(); it != names_snapshot.end(); ++it) { | |
398 if (it_device_info->name.id() == it->id()) { | |
399 new_devices_info_cache.push_back(*it_device_info); | |
400 names_snapshot.erase(it); | |
401 break; | |
402 } | |
403 } | |
404 } | |
405 | |
406 // Need to get the capabilities for the truly new devices in |names_snapshot|. | |
407 for (media::VideoCaptureDevice::Names::const_iterator it = | |
408 names_snapshot.begin(); | |
409 it != names_snapshot.end(); | |
410 ++it) { | |
411 media::VideoCaptureCapabilities capabilities; | |
412 DeviceInfo device_info(*it, media::VideoCaptureCapabilities()); | |
413 if (!use_fake_device_) { | |
414 media::VideoCaptureDevice::GetDeviceSupportedFormats( | |
415 *it, &(device_info.capabilities)); | |
416 } else { | |
417 media::FakeVideoCaptureDevice::GetDeviceSupportedFormats( | |
418 *it, &(device_info.capabilities)); | |
419 } | |
420 new_devices_info_cache.push_back(device_info); | |
421 } | |
422 return new_devices_info_cache; | |
423 } | 343 } |
424 | 344 |
425 VideoCaptureManager::DeviceEntry* | 345 VideoCaptureManager::DeviceEntry* |
426 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice( | 346 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice( |
427 const MediaStreamDevice& device_info) { | 347 const MediaStreamDevice& device_info) { |
428 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
429 | 349 |
430 for (DeviceEntries::iterator it = devices_.begin(); | 350 for (DeviceEntries::iterator it = devices_.begin(); |
431 it != devices_.end(); ++it) { | 351 it != devices_.end(); ++it) { |
432 DeviceEntry* device = *it; | 352 DeviceEntry* device = *it; |
(...skipping 26 matching lines...) Expand all Loading... |
459 << entry->stream_type << ", id = " << entry->id << ")"; | 379 << entry->stream_type << ", id = " << entry->id << ")"; |
460 | 380 |
461 // The DeviceEntry is removed from |devices_| immediately. The controller is | 381 // The DeviceEntry is removed from |devices_| immediately. The controller is |
462 // deleted immediately, and the device is freed asynchronously. After this | 382 // deleted immediately, and the device is freed asynchronously. After this |
463 // point, subsequent requests to open this same device ID will create a new | 383 // point, subsequent requests to open this same device ID will create a new |
464 // DeviceEntry, VideoCaptureController, and VideoCaptureDevice. | 384 // DeviceEntry, VideoCaptureController, and VideoCaptureDevice. |
465 devices_.erase(entry); | 385 devices_.erase(entry); |
466 entry->video_capture_controller.reset(); | 386 entry->video_capture_controller.reset(); |
467 device_loop_->PostTask( | 387 device_loop_->PostTask( |
468 FROM_HERE, | 388 FROM_HERE, |
469 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, | 389 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, |
470 this, | |
471 base::Owned(entry))); | 390 base::Owned(entry))); |
472 } | 391 } |
473 } | 392 } |
474 | 393 |
475 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry( | 394 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry( |
476 int capture_session_id) { | 395 int capture_session_id) { |
477 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
478 | 397 |
479 std::map<int, MediaStreamDevice>::iterator session_it = | 398 std::map<int, MediaStreamDevice>::iterator session_it = |
480 sessions_.find(capture_session_id); | 399 sessions_.find(capture_session_id); |
(...skipping 13 matching lines...) Expand all Loading... |
494 | 413 |
495 scoped_ptr<VideoCaptureController> video_capture_controller( | 414 scoped_ptr<VideoCaptureController> video_capture_controller( |
496 new VideoCaptureController()); | 415 new VideoCaptureController()); |
497 DeviceEntry* new_device = new DeviceEntry(device_info.type, | 416 DeviceEntry* new_device = new DeviceEntry(device_info.type, |
498 device_info.id, | 417 device_info.id, |
499 video_capture_controller.Pass()); | 418 video_capture_controller.Pass()); |
500 devices_.insert(new_device); | 419 devices_.insert(new_device); |
501 return new_device; | 420 return new_device; |
502 } | 421 } |
503 | 422 |
504 VideoCaptureManager::DeviceInfo* VideoCaptureManager::FindDeviceInfoById( | |
505 const std::string& id, | |
506 DevicesInfo& device_vector) { | |
507 for (DevicesInfo::iterator it = device_vector.begin(); | |
508 it != device_vector.end(); ++it) { | |
509 if (it->name.id() == id) | |
510 return &(*it); | |
511 } | |
512 return NULL; | |
513 } | |
514 | |
515 } // namespace content | 423 } // namespace content |
OLD | NEW |