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