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. | |
155 media::VideoCaptureCapabilities& formats = | |
perkj_chrome
2013/10/23 13:19:45
What happen after the camera has been stopped? The
| |
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 | 251 |
246 // Detach client from controller. | 252 // Detach client from controller. |
247 int session_id = controller->RemoveClient(client_id, client_handler); | 253 int session_id = controller->RemoveClient(client_id, client_handler); |
248 DVLOG(1) << "VideoCaptureManager::StopCaptureForClient, session_id = " | 254 DVLOG(1) << "VideoCaptureManager::StopCaptureForClient, session_id = " |
249 << session_id; | 255 << session_id; |
250 | 256 |
251 // If controller has no more clients, delete controller and device. | 257 // If controller has no more clients, delete controller and device. |
252 DestroyDeviceEntryIfNoClients(entry); | 258 DestroyDeviceEntryIfNoClients(entry); |
253 } | 259 } |
254 | 260 |
261 const media::VideoCaptureCapabilities* | |
262 VideoCaptureManager::EnumerateDeviceCapabilities( | |
263 const StreamDeviceInfo& device_info) { | |
264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
perkj_chrome
2013/10/23 13:19:45
What is the plan when it comes to multiple opening
perkj_chrome
2013/10/23 13:19:45
So this is done on the IO thread but you modify |v
| |
265 | |
266 // Find the device we are looking for and return its associated capabilities. | |
267 std::map<std::string, media::VideoCaptureCapabilities>::iterator it = | |
268 video_capture_capabilities_.find(device_info.device.id); | |
269 if ( it != video_capture_capabilities_.end()) | |
270 return &(it->second); | |
271 return NULL; | |
272 } | |
273 | |
255 void VideoCaptureManager::DoStopDeviceOnDeviceThread(DeviceEntry* entry) { | 274 void VideoCaptureManager::DoStopDeviceOnDeviceThread(DeviceEntry* entry) { |
256 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime"); | 275 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime"); |
257 DCHECK(IsOnDeviceThread()); | 276 DCHECK(IsOnDeviceThread()); |
258 if (entry->video_capture_device) { | 277 if (entry->video_capture_device) { |
259 entry->video_capture_device->StopAndDeAllocate(); | 278 entry->video_capture_device->StopAndDeAllocate(); |
260 } | 279 } |
261 entry->video_capture_device.reset(); | 280 entry->video_capture_device.reset(); |
262 } | 281 } |
263 | 282 |
264 void VideoCaptureManager::OnOpened(MediaStreamType stream_type, | 283 void VideoCaptureManager::OnOpened(MediaStreamType stream_type, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 DCHECK(IsOnDeviceThread()); | 333 DCHECK(IsOnDeviceThread()); |
315 media::VideoCaptureDevice::Names result; | 334 media::VideoCaptureDevice::Names result; |
316 | 335 |
317 switch (stream_type) { | 336 switch (stream_type) { |
318 case MEDIA_DEVICE_VIDEO_CAPTURE: | 337 case MEDIA_DEVICE_VIDEO_CAPTURE: |
319 // Cache the latest enumeration of video capture devices. | 338 // Cache the latest enumeration of video capture devices. |
320 // We'll refer to this list again in OnOpen to avoid having to | 339 // We'll refer to this list again in OnOpen to avoid having to |
321 // enumerate the devices again. | 340 // enumerate the devices again. |
322 if (!use_fake_device_) { | 341 if (!use_fake_device_) { |
323 media::VideoCaptureDevice::GetDeviceNames(&result); | 342 media::VideoCaptureDevice::GetDeviceNames(&result); |
343 // Add to the cache the devices' supported capture formats. | |
344 media::VideoCaptureDevice::Names::iterator name_it; | |
perkj_chrome
2013/10/23 13:19:45
See how GetAvailableDevicesOnDeviceThread is used
| |
345 for (name_it = result.begin(); name_it != result.end(); ++name_it) { | |
346 media::VideoCaptureDevice::GetDeviceSupportedFormats( | |
347 *name_it, &video_capture_capabilities_[name_it->id()] ); | |
348 } | |
324 } else { | 349 } else { |
325 media::FakeVideoCaptureDevice::GetDeviceNames(&result); | 350 media::FakeVideoCaptureDevice::GetDeviceNames(&result); |
351 // Add to the cache the devices' supported capture formats. | |
352 media::VideoCaptureDevice::Names::iterator name_it; | |
353 media::VideoCaptureCapabilities formats; | |
354 for (name_it = result.begin(); name_it != result.end(); ++name_it) { | |
355 media::FakeVideoCaptureDevice::GetDeviceSupportedFormats( | |
356 *name_it, &video_capture_capabilities_[name_it->id()] ); | |
357 } | |
326 } | 358 } |
327 | 359 |
328 // TODO(nick): The correctness of device start depends on this cache being | 360 // 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 | 361 // maintained, but it seems a little odd to keep a cache here. Can we |
330 // eliminate it? | 362 // eliminate it? |
331 video_capture_devices_ = result; | 363 video_capture_devices_ = result; |
332 break; | 364 break; |
333 | 365 |
334 case MEDIA_DESKTOP_VIDEO_CAPTURE: | 366 case MEDIA_DESKTOP_VIDEO_CAPTURE: |
335 // Do nothing. | 367 // Do nothing. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 scoped_ptr<VideoCaptureController> video_capture_controller( | 446 scoped_ptr<VideoCaptureController> video_capture_controller( |
415 new VideoCaptureController()); | 447 new VideoCaptureController()); |
416 DeviceEntry* new_device = new DeviceEntry(device_info.type, | 448 DeviceEntry* new_device = new DeviceEntry(device_info.type, |
417 device_info.id, | 449 device_info.id, |
418 video_capture_controller.Pass()); | 450 video_capture_controller.Pass()); |
419 devices_.insert(new_device); | 451 devices_.insert(new_device); |
420 return new_device; | 452 return new_device; |
421 } | 453 } |
422 | 454 |
423 } // namespace content | 455 } // namespace content |
OLD | NEW |