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