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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 case MEDIA_DEVICE_VIDEO_CAPTURE: { | 143 case MEDIA_DEVICE_VIDEO_CAPTURE: { |
144 // 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 |
145 // 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 |
146 // held in the browser-side VideoCaptureDevice::Name structure. | 146 // held in the browser-side VideoCaptureDevice::Name structure. |
147 media::VideoCaptureDevice::Name* found = | 147 media::VideoCaptureDevice::Name* found = |
148 video_capture_devices_.FindById(entry->id); | 148 video_capture_devices_.FindById(entry->id); |
149 if (found) { | 149 if (found) { |
150 video_capture_device.reset(use_fake_device_ ? | 150 video_capture_device.reset(use_fake_device_ ? |
151 media::FakeVideoCaptureDevice::Create(*found) : | 151 media::FakeVideoCaptureDevice::Create(*found) : |
152 media::VideoCaptureDevice::Create(*found)); | 152 media::VideoCaptureDevice::Create(*found)); |
153 | |
154 // Filter capture capabilities: remove all except the current one. | |
tommi (sloooow) - chröme
2013/10/25 14:15:34
why? (usually that's more important to document th
mcasas
2013/10/28 12:50:08
Done.
| |
155 media::VideoCaptureCapabilities& formats = | |
156 video_capture_capabilities_[entry->id]; | |
157 formats.clear(); | |
158 formats.push_back(capture_params); | |
153 } | 159 } |
154 break; | 160 break; |
155 } | 161 } |
156 case MEDIA_TAB_VIDEO_CAPTURE: { | 162 case MEDIA_TAB_VIDEO_CAPTURE: { |
157 video_capture_device.reset( | 163 video_capture_device.reset( |
158 WebContentsVideoCaptureDevice::Create(entry->id)); | 164 WebContentsVideoCaptureDevice::Create(entry->id)); |
159 break; | 165 break; |
160 } | 166 } |
161 case MEDIA_DESKTOP_VIDEO_CAPTURE: { | 167 case MEDIA_DESKTOP_VIDEO_CAPTURE: { |
162 #if defined(ENABLE_SCREEN_CAPTURE) | 168 #if defined(ENABLE_SCREEN_CAPTURE) |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 | 252 |
247 // Detach client from controller. | 253 // Detach client from controller. |
248 int session_id = controller->RemoveClient(client_id, client_handler); | 254 int session_id = controller->RemoveClient(client_id, client_handler); |
249 DVLOG(1) << "VideoCaptureManager::StopCaptureForClient, session_id = " | 255 DVLOG(1) << "VideoCaptureManager::StopCaptureForClient, session_id = " |
250 << session_id; | 256 << session_id; |
251 | 257 |
252 // If controller has no more clients, delete controller and device. | 258 // If controller has no more clients, delete controller and device. |
253 DestroyDeviceEntryIfNoClients(entry); | 259 DestroyDeviceEntryIfNoClients(entry); |
254 } | 260 } |
255 | 261 |
262 void VideoCaptureManager::EnumerateDeviceCapabilities( | |
263 const StreamDeviceInfo& device_info) { | |
264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
265 DVLOG(1) << "VideoCaptureManager::EnumerateDeviceCapabilites for device: " | |
266 << device_info.device.name; | |
267 DCHECK(listener_); | |
268 base::PostTaskAndReplyWithResult( | |
269 device_loop_, | |
270 FROM_HERE, | |
271 base::Bind(&VideoCaptureManager::GetDeviceCapabilitiesOnDeviceThread, | |
272 this, | |
273 device_info), | |
274 base::Bind(&VideoCaptureManager::OnDeviceCapabilitiesEnumerated, | |
275 this, | |
276 device_info)); | |
277 } | |
278 | |
256 void VideoCaptureManager::DoStopDeviceOnDeviceThread(DeviceEntry* entry) { | 279 void VideoCaptureManager::DoStopDeviceOnDeviceThread(DeviceEntry* entry) { |
257 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime"); | 280 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime"); |
258 DCHECK(IsOnDeviceThread()); | 281 DCHECK(IsOnDeviceThread()); |
259 if (entry->video_capture_device) { | 282 if (entry->video_capture_device) { |
260 entry->video_capture_device->StopAndDeAllocate(); | 283 entry->video_capture_device->StopAndDeAllocate(); |
261 } | 284 } |
262 entry->video_capture_device.reset(); | 285 entry->video_capture_device.reset(); |
263 } | 286 } |
264 | 287 |
265 void VideoCaptureManager::OnOpened(MediaStreamType stream_type, | 288 void VideoCaptureManager::OnOpened(MediaStreamType stream_type, |
(...skipping 18 matching lines...) Expand all Loading... | |
284 | 307 |
285 void VideoCaptureManager::OnDevicesEnumerated( | 308 void VideoCaptureManager::OnDevicesEnumerated( |
286 MediaStreamType stream_type, | 309 MediaStreamType stream_type, |
287 const media::VideoCaptureDevice::Names& device_names) { | 310 const media::VideoCaptureDevice::Names& device_names) { |
288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
289 | 312 |
290 if (!listener_) { | 313 if (!listener_) { |
291 // Listener has been removed. | 314 // Listener has been removed. |
292 return; | 315 return; |
293 } | 316 } |
317 DVLOG(1) << "OnDevicesEnumerated"; | |
tommi (sloooow) - chröme
2013/10/25 14:15:34
nit: above the listener check
mcasas
2013/10/28 12:50:08
Done.
| |
294 | 318 |
295 // Transform from VCD::Name to StreamDeviceInfo. | 319 // Transform from VCD::Name to StreamDeviceInfo. |
296 StreamDeviceInfoArray devices; | 320 StreamDeviceInfoArray devices; |
297 for (media::VideoCaptureDevice::Names::const_iterator it = | 321 for (media::VideoCaptureDevice::Names::const_iterator it = |
298 device_names.begin(); it != device_names.end(); ++it) { | 322 device_names.begin(); it != device_names.end(); ++it) { |
299 devices.push_back(StreamDeviceInfo( | 323 devices.push_back(StreamDeviceInfo( |
300 stream_type, it->GetNameAndModel(), it->id())); | 324 stream_type, it->GetNameAndModel(), it->id())); |
301 } | 325 } |
302 | 326 |
303 listener_->DevicesEnumerated(stream_type, devices); | 327 listener_->DevicesEnumerated(stream_type, devices); |
304 } | 328 } |
305 | 329 |
330 void VideoCaptureManager::OnDeviceCapabilitiesEnumerated( | |
331 const StreamDeviceInfo& device_info, | |
332 const media::VideoCaptureCapabilities& capabilities) { | |
333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
334 | |
335 if (!listener_) { | |
336 // Listener has been removed. | |
337 return; | |
338 } | |
339 DVLOG(1) << "OnDeviceCapabilitiesEnumerated device: " | |
tommi (sloooow) - chröme
2013/10/25 14:15:34
nit: move this DLOG above the listener_ check so t
mcasas
2013/10/28 12:50:08
Done.
| |
340 << device_info.device.id; | |
341 listener_->DeviceCapabilitiesEnumerated(device_info, capabilities); | |
342 } | |
343 | |
306 bool VideoCaptureManager::IsOnDeviceThread() const { | 344 bool VideoCaptureManager::IsOnDeviceThread() const { |
307 return device_loop_->BelongsToCurrentThread(); | 345 return device_loop_->BelongsToCurrentThread(); |
308 } | 346 } |
309 | 347 |
310 media::VideoCaptureDevice::Names | 348 media::VideoCaptureDevice::Names |
311 VideoCaptureManager::GetAvailableDevicesOnDeviceThread( | 349 VideoCaptureManager::GetAvailableDevicesOnDeviceThread( |
312 MediaStreamType stream_type) { | 350 MediaStreamType stream_type) { |
313 SCOPED_UMA_HISTOGRAM_TIMER( | 351 SCOPED_UMA_HISTOGRAM_TIMER( |
314 "Media.VideoCaptureManager.GetAvailableDevicesTime"); | 352 "Media.VideoCaptureManager.GetAvailableDevicesTime"); |
315 DCHECK(IsOnDeviceThread()); | 353 DCHECK(IsOnDeviceThread()); |
316 media::VideoCaptureDevice::Names result; | 354 media::VideoCaptureDevice::Names result; |
317 | 355 |
318 switch (stream_type) { | 356 switch (stream_type) { |
319 case MEDIA_DEVICE_VIDEO_CAPTURE: | 357 case MEDIA_DEVICE_VIDEO_CAPTURE: |
320 // Cache the latest enumeration of video capture devices. | 358 // Cache the latest enumeration of video capture devices. |
321 // We'll refer to this list again in OnOpen to avoid having to | 359 // We'll refer to this list again in OnOpen to avoid having to |
322 // enumerate the devices again. | 360 // enumerate the devices again. |
323 if (!use_fake_device_) { | 361 if (!use_fake_device_) { |
324 media::VideoCaptureDevice::GetDeviceNames(&result); | 362 media::VideoCaptureDevice::GetDeviceNames(&result); |
363 // Add to the cache the devices' supported capture formats. | |
tommi (sloooow) - chröme
2013/10/25 14:15:34
nit: sentence structure - it feels more natural to
mcasas
2013/10/28 12:50:08
Done.
| |
364 media::VideoCaptureDevice::Names::iterator name_it; | |
365 for (name_it = result.begin(); name_it != result.end(); ++name_it) { | |
366 media::VideoCaptureDevice::GetDeviceSupportedFormats( | |
367 *name_it, &video_capture_capabilities_[name_it->id()] ); | |
tommi (sloooow) - chröme
2013/10/25 14:15:34
before sending a pointer to the entry in the map,
mcasas
2013/10/28 12:50:08
I guess this doesn't apply since the map is gone.
| |
368 } | |
325 } else { | 369 } else { |
326 media::FakeVideoCaptureDevice::GetDeviceNames(&result); | 370 media::FakeVideoCaptureDevice::GetDeviceNames(&result); |
371 // Add to the cache the devices' supported capture formats. | |
372 media::VideoCaptureDevice::Names::iterator name_it; | |
373 media::VideoCaptureCapabilities formats; | |
374 for (name_it = result.begin(); name_it != result.end(); ++name_it) { | |
375 media::FakeVideoCaptureDevice::GetDeviceSupportedFormats( | |
376 *name_it, &video_capture_capabilities_[name_it->id()] ); | |
tommi (sloooow) - chröme
2013/10/25 14:15:34
same here
mcasas
2013/10/28 12:50:08
dixit.
| |
377 } | |
327 } | 378 } |
328 | 379 |
329 // TODO(nick): The correctness of device start depends on this cache being | 380 // TODO(nick): The correctness of device start depends on this cache being |
330 // maintained, but it seems a little odd to keep a cache here. Can we | 381 // maintained, but it seems a little odd to keep a cache here. Can we |
331 // eliminate it? | 382 // eliminate it? |
332 video_capture_devices_ = result; | 383 video_capture_devices_ = result; |
333 break; | 384 break; |
334 | 385 |
335 case MEDIA_DESKTOP_VIDEO_CAPTURE: | 386 case MEDIA_DESKTOP_VIDEO_CAPTURE: |
336 // Do nothing. | 387 // Do nothing. |
337 break; | 388 break; |
338 | 389 |
339 default: | 390 default: |
340 NOTREACHED(); | 391 NOTREACHED(); |
341 break; | 392 break; |
342 } | 393 } |
343 return result; | 394 return result; |
344 } | 395 } |
345 | 396 |
397 media::VideoCaptureCapabilities | |
398 VideoCaptureManager::GetDeviceCapabilitiesOnDeviceThread( | |
399 const StreamDeviceInfo& device_info) const { | |
400 DCHECK(IsOnDeviceThread()); | |
401 | |
402 // Find the device we are looking for and return its associated capabilities. | |
403 std::map<std::string, media::VideoCaptureCapabilities>::const_iterator it = | |
404 video_capture_capabilities_.find(device_info.device.id); | |
405 if ( it != video_capture_capabilities_.end()) | |
tommi (sloooow) - chröme
2013/10/25 14:15:34
fix spaces
mcasas
2013/10/28 12:50:08
Done.
| |
406 return it->second; | |
407 return media::VideoCaptureCapabilities(); | |
408 } | |
409 | |
346 VideoCaptureManager::DeviceEntry* | 410 VideoCaptureManager::DeviceEntry* |
347 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice( | 411 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice( |
348 const MediaStreamDevice& device_info) { | 412 const MediaStreamDevice& device_info) { |
349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
350 | 414 |
351 for (DeviceEntries::iterator it = devices_.begin(); | 415 for (DeviceEntries::iterator it = devices_.begin(); |
352 it != devices_.end(); ++it) { | 416 it != devices_.end(); ++it) { |
353 DeviceEntry* device = *it; | 417 DeviceEntry* device = *it; |
354 if (device_info.type == device->stream_type && | 418 if (device_info.type == device->stream_type && |
355 device_info.id == device->id) { | 419 device_info.id == device->id) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
415 scoped_ptr<VideoCaptureController> video_capture_controller( | 479 scoped_ptr<VideoCaptureController> video_capture_controller( |
416 new VideoCaptureController()); | 480 new VideoCaptureController()); |
417 DeviceEntry* new_device = new DeviceEntry(device_info.type, | 481 DeviceEntry* new_device = new DeviceEntry(device_info.type, |
418 device_info.id, | 482 device_info.id, |
419 video_capture_controller.Pass()); | 483 video_capture_controller.Pass()); |
420 devices_.insert(new_device); | 484 devices_.insert(new_device); |
421 return new_device; | 485 return new_device; |
422 } | 486 } |
423 | 487 |
424 } // namespace content | 488 } // namespace content |
OLD | NEW |