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_) |
no longer working on chromium
2013/11/12 16:48:00
nit, why ? changed here
mcasas
2013/11/12 18:10:16
clang-format would make something entirely differe
| |
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_); | |
no longer working on chromium
2013/11/12 16:48:00
nit, remove the local variable, just use if (FindD
mcasas
2013/11/12 18:10:16
? I used the |found| twice, one to check != NULL a
| |
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) { | |
no longer working on chromium
2013/11/12 16:48:00
early return
if (!device) {
// Add comment.
*c
mcasas
2013/11/12 18:10:16
Done.
| |
291 DeviceEntry* const existing_device = | |
292 GetDeviceEntryForMediaStreamDevice(it->second); | |
293 if (existing_device && device->device_in_use_) { | |
294 media::VideoCaptureParams params = | |
295 existing_device->video_capture_controller->GetVideoCaptureParams(); | |
296 media::VideoCaptureCapability current_format( | |
297 params.requested_format.width, | |
298 params.requested_format.height, | |
299 params.requested_format.frame_rate, | |
300 media::PIXEL_FORMAT_UNKNOWN, | |
301 params.requested_format.frame_size_type); | |
302 capabilities->push_back(current_format); | |
303 } else { | |
304 *capabilities = device->capabilities_; | |
305 } | |
306 } | |
307 } | |
308 | |
255 void VideoCaptureManager::DoStopDeviceOnDeviceThread(DeviceEntry* entry) { | 309 void VideoCaptureManager::DoStopDeviceOnDeviceThread(DeviceEntry* entry) { |
256 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime"); | 310 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime"); |
257 DCHECK(IsOnDeviceThread()); | 311 DCHECK(IsOnDeviceThread()); |
258 if (entry->video_capture_device) { | 312 if (entry->video_capture_device) { |
259 entry->video_capture_device->StopAndDeAllocate(); | 313 entry->video_capture_device->StopAndDeAllocate(); |
260 } | 314 } |
261 entry->video_capture_device.reset(); | 315 entry->video_capture_device.reset(); |
262 } | 316 } |
263 | 317 |
264 void VideoCaptureManager::OnOpened(MediaStreamType stream_type, | 318 void VideoCaptureManager::OnOpened(MediaStreamType stream_type, |
265 int capture_session_id) { | 319 int capture_session_id) { |
266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
267 if (!listener_) { | 321 if (!listener_) { |
268 // Listener has been removed. | 322 // Listener has been removed. |
269 return; | 323 return; |
270 } | 324 } |
271 listener_->Opened(stream_type, capture_session_id); | 325 listener_->Opened(stream_type, capture_session_id); |
272 } | 326 } |
273 | 327 |
274 void VideoCaptureManager::OnClosed(MediaStreamType stream_type, | 328 void VideoCaptureManager::OnClosed(MediaStreamType stream_type, |
275 int capture_session_id) { | 329 int capture_session_id) { |
276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
277 if (!listener_) { | 331 if (!listener_) { |
278 // Listener has been removed. | 332 // Listener has been removed. |
279 return; | 333 return; |
280 } | 334 } |
281 listener_->Closed(stream_type, capture_session_id); | 335 listener_->Closed(stream_type, capture_session_id); |
282 } | 336 } |
283 | 337 |
284 void VideoCaptureManager::OnDevicesEnumerated( | 338 void VideoCaptureManager::OnDeviceNamesAndCapabilitiesEnumerated( |
285 MediaStreamType stream_type, | 339 MediaStreamType stream_type, |
286 const media::VideoCaptureDevice::Names& device_names) { | 340 const DevicesInfo& new_devices_info_cache) { |
287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 341 DVLOG(1) << "OnDeviceNameAndCapabilitiesEnumerated, #new devices: " |
342 << new_devices_info_cache.size(); | |
288 | 343 |
289 if (!listener_) { | 344 devices_info_cache_ = new_devices_info_cache; |
290 // Listener has been removed. | 345 |
291 return; | 346 // Walk the |devices_info_cache_| and transform from VCD::Name to |
no longer working on chromium
2013/11/12 16:48:00
why do you change these, please added back the thr
mcasas
2013/11/12 18:10:16
Done.
| |
347 // StreamDeviceInfo for return purposes. | |
348 StreamDeviceInfoArray devices; | |
349 for (DevicesInfo::const_iterator it = devices_info_cache_.begin(); | |
350 it != devices_info_cache_.end(); | |
351 ++it) { | |
352 devices.push_back(StreamDeviceInfo( | |
353 stream_type, it->name_.GetNameAndModel(), it->name_.id())); | |
292 } | 354 } |
293 | 355 // |listener_| might have disappeared while we were scanning the devices. |
no longer working on chromium
2013/11/12 16:48:00
I think you should do nothing if the listener_ has
mcasas
2013/11/12 18:10:16
Done.
| |
294 // Transform from VCD::Name to StreamDeviceInfo. | 356 if (listener_) |
295 StreamDeviceInfoArray devices; | 357 listener_->DevicesEnumerated(stream_type, devices); |
296 for (media::VideoCaptureDevice::Names::const_iterator it = | |
297 device_names.begin(); it != device_names.end(); ++it) { | |
298 devices.push_back(StreamDeviceInfo( | |
299 stream_type, it->GetNameAndModel(), it->id())); | |
300 } | |
301 | |
302 listener_->DevicesEnumerated(stream_type, devices); | |
303 } | 358 } |
304 | 359 |
305 bool VideoCaptureManager::IsOnDeviceThread() const { | 360 bool VideoCaptureManager::IsOnDeviceThread() const { |
306 return device_loop_->BelongsToCurrentThread(); | 361 return device_loop_->BelongsToCurrentThread(); |
307 } | 362 } |
308 | 363 |
309 media::VideoCaptureDevice::Names | 364 VideoCaptureManager::DevicesInfo |
310 VideoCaptureManager::GetAvailableDevicesOnDeviceThread( | 365 VideoCaptureManager::GetAvailableDevicesAndCapabilitiesOnDeviceThread( |
311 MediaStreamType stream_type) { | 366 MediaStreamType stream_type, |
367 const DevicesInfo& old_device_info_cache) { | |
312 SCOPED_UMA_HISTOGRAM_TIMER( | 368 SCOPED_UMA_HISTOGRAM_TIMER( |
313 "Media.VideoCaptureManager.GetAvailableDevicesTime"); | 369 "Media.VideoCaptureManager." |
370 "GetAvailableDevicesAndCapabilitiesOnDeviceThreadTime"); | |
314 DCHECK(IsOnDeviceThread()); | 371 DCHECK(IsOnDeviceThread()); |
315 media::VideoCaptureDevice::Names result; | 372 media::VideoCaptureDevice::Names names_snapshot; |
316 | |
317 switch (stream_type) { | 373 switch (stream_type) { |
318 case MEDIA_DEVICE_VIDEO_CAPTURE: | 374 case MEDIA_DEVICE_VIDEO_CAPTURE: |
319 // Cache the latest enumeration of video capture devices. | 375 if (!use_fake_device_) |
320 // We'll refer to this list again in OnOpen to avoid having to | 376 media::VideoCaptureDevice::GetDeviceNames(&names_snapshot); |
321 // enumerate the devices again. | 377 else |
322 if (!use_fake_device_) { | 378 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; | 379 break; |
333 | |
334 case MEDIA_DESKTOP_VIDEO_CAPTURE: | 380 case MEDIA_DESKTOP_VIDEO_CAPTURE: |
335 // Do nothing. | 381 // Do nothing. |
336 break; | 382 break; |
337 | |
338 default: | 383 default: |
339 NOTREACHED(); | 384 NOTREACHED(); |
340 break; | 385 break; |
341 } | 386 } |
342 return result; | 387 |
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 break; | |
no longer working on chromium
2013/11/12 16:48:00
I think you can remove the if two lines below if y
mcasas
2013/11/12 18:10:16
Good catch! I think so too, so Done.
| |
400 } | |
401 if (it != names_snapshot.end()) { | |
402 new_devices_info_cache.push_back(*it_device_info); | |
403 names_snapshot.erase(it); | |
404 } | |
405 } | |
406 | |
407 // Need to get the capabilities for the truly new devices in |names_snapshot|. | |
408 for (media::VideoCaptureDevice::Names::const_iterator it = | |
409 names_snapshot.begin(); | |
410 it != names_snapshot.end(); | |
411 ++it) { | |
412 media::VideoCaptureCapabilities capabilities; | |
413 DeviceInfo device_info(*it, media::VideoCaptureCapabilities()); | |
414 if (!use_fake_device_) { | |
415 media::VideoCaptureDevice::GetDeviceSupportedFormats( | |
416 *it, &(device_info.capabilities_)); | |
417 } else { | |
418 media::FakeVideoCaptureDevice::GetDeviceSupportedFormats( | |
419 *it, &(device_info.capabilities_)); | |
420 } | |
421 new_devices_info_cache.push_back(device_info); | |
422 } | |
423 return new_devices_info_cache; | |
343 } | 424 } |
344 | 425 |
345 VideoCaptureManager::DeviceEntry* | 426 VideoCaptureManager::DeviceEntry* |
346 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice( | 427 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice( |
347 const MediaStreamDevice& device_info) { | 428 const MediaStreamDevice& device_info) { |
348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 429 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
349 | 430 |
350 for (DeviceEntries::iterator it = devices_.begin(); | 431 for (DeviceEntries::iterator it = devices_.begin(); |
351 it != devices_.end(); ++it) { | 432 it != devices_.end(); ++it) { |
352 DeviceEntry* device = *it; | 433 DeviceEntry* device = *it; |
(...skipping 26 matching lines...) Expand all Loading... | |
379 << entry->stream_type << ", id = " << entry->id << ")"; | 460 << entry->stream_type << ", id = " << entry->id << ")"; |
380 | 461 |
381 // The DeviceEntry is removed from |devices_| immediately. The controller is | 462 // The DeviceEntry is removed from |devices_| immediately. The controller is |
382 // deleted immediately, and the device is freed asynchronously. After this | 463 // deleted immediately, and the device is freed asynchronously. After this |
383 // point, subsequent requests to open this same device ID will create a new | 464 // point, subsequent requests to open this same device ID will create a new |
384 // DeviceEntry, VideoCaptureController, and VideoCaptureDevice. | 465 // DeviceEntry, VideoCaptureController, and VideoCaptureDevice. |
385 devices_.erase(entry); | 466 devices_.erase(entry); |
386 entry->video_capture_controller.reset(); | 467 entry->video_capture_controller.reset(); |
387 device_loop_->PostTask( | 468 device_loop_->PostTask( |
388 FROM_HERE, | 469 FROM_HERE, |
389 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, | 470 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, |
471 this, | |
390 base::Owned(entry))); | 472 base::Owned(entry))); |
473 DeviceInfo* device_info = | |
474 FindDeviceInfoById(entry->id, devices_info_cache_); | |
475 if (device_info) | |
476 device_info->device_in_use_ = false; | |
391 } | 477 } |
392 } | 478 } |
393 | 479 |
394 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry( | 480 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry( |
395 int capture_session_id) { | 481 int capture_session_id) { |
396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
397 | 483 |
398 std::map<int, MediaStreamDevice>::iterator session_it = | 484 std::map<int, MediaStreamDevice>::iterator session_it = |
399 sessions_.find(capture_session_id); | 485 sessions_.find(capture_session_id); |
400 if (session_it == sessions_.end()) { | 486 if (session_it == sessions_.end()) { |
(...skipping 12 matching lines...) Expand all Loading... | |
413 | 499 |
414 scoped_ptr<VideoCaptureController> video_capture_controller( | 500 scoped_ptr<VideoCaptureController> video_capture_controller( |
415 new VideoCaptureController()); | 501 new VideoCaptureController()); |
416 DeviceEntry* new_device = new DeviceEntry(device_info.type, | 502 DeviceEntry* new_device = new DeviceEntry(device_info.type, |
417 device_info.id, | 503 device_info.id, |
418 video_capture_controller.Pass()); | 504 video_capture_controller.Pass()); |
419 devices_.insert(new_device); | 505 devices_.insert(new_device); |
420 return new_device; | 506 return new_device; |
421 } | 507 } |
422 | 508 |
509 VideoCaptureManager::DeviceInfo* VideoCaptureManager::FindDeviceInfoById( | |
510 const std::string& id, | |
511 DevicesInfo& device_vector) { | |
512 for (DevicesInfo::iterator it = device_vector.begin(); | |
513 it != device_vector.end(); ++it) { | |
514 if (it->name_.id() == id) | |
515 return it.base(); | |
no longer working on chromium
2013/11/12 16:48:00
FYI, chrome rarely uses .base(), most of the case
mcasas
2013/11/12 18:10:16
Chromiumisms are my thing!
| |
516 } | |
517 return NULL; | |
518 } | |
519 | |
423 } // namespace content | 520 } // namespace content |
OLD | NEW |