Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: content/browser/renderer_host/media/video_capture_manager.cc

Issue 29423003: Added video capture capabilities retrieval and caching to VideoCaptureManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ncarter@: Removed double visit to Device thread. Removed ScopedVector<> use. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
mcasas 2013/11/11 17:40:00 For PostTaskAndReplyWithResult()
mcasas 2013/11/12 12:21:53 Done.
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,
perkj_chrome 2013/11/12 11:10:58 4 step indentation
mcasas 2013/11/12 12:21:53 This is what clang-format makes of it :S
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
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
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
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 DeviceEntry* const existing_device =
perkj_chrome 2013/11/12 11:10:58 please rename existing_device to something else. d
mcasas 2013/11/12 12:21:53 See next reply.
292 GetDeviceEntryForMediaStreamDevice(it->second);
293 if (existing_device) {
294 media::VideoCaptureParams params =
295 existing_device->video_capture_controller->getVideoCaptureParams();
perkj_chrome 2013/11/12 11:10:58 This seems wrong to me. How do you know that the d
mcasas 2013/11/12 12:21:53 It is partially wrong, I should have tested here f
296 media::VideoCaptureCapability current_format(
mcasas 2013/11/11 17:40:00 This is a silly copy but a consequence of our divi
mcasas 2013/11/12 12:21:53 Done.
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 DevicesInfo& new_devices_info_cache) {
perkj_chrome 2013/11/12 11:10:58 const ref?
mcasas 2013/11/12 12:21:53 Done.
287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 341 DVLOG(1) << "OnDeviceNameAndCapabilitiesEnumerated, #new devices: "
342 << new_devices_info_cache.size();
perkj_chrome 2013/11/12 11:10:58 indentation
mcasas 2013/11/12 12:21:53 Done.
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
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.
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& devices_info_cache_copy) {
perkj_chrome 2013/11/12 11:10:58 No need to say that this is a copy. Maybe call thi
mcasas 2013/11/12 12:21:53 Done.
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 DevicesInfo new_devices_info_cache;
389 // Construct |new_devices_info_cache| with the cached devices that are still
390 // present in the system, and remove their names from |names_snapshot|, so we
391 // keep there the truly new devices.
392 DevicesInfo::const_iterator it_device_info = devices_info_cache_copy.begin();
393 while (it_device_info != devices_info_cache_copy.end()) {
perkj_chrome 2013/11/12 11:10:58 nit: Looks like this can be a for loop.
mcasas 2013/11/12 12:21:53 Done.
394 media::VideoCaptureDevice::Names::iterator it;
395 for (it = names_snapshot.begin(); it != names_snapshot.end(); ++it) {
396 if (it_device_info->name_.id() == it->id())
397 break;
398 }
399 if (it != names_snapshot.end()) {
400 new_devices_info_cache.push_back(*it_device_info);
401 names_snapshot.erase(it);
402 }
403 ++it_device_info;
404 }
405
406 // Need to get the capabilities for the truly new devices in |names_snapshot|.
407 for (media::VideoCaptureDevice::Names::const_iterator it =
408 names_snapshot.begin();
409 it != names_snapshot.end();
410 ++it) {
411 media::VideoCaptureCapabilities capabilities;
412 DeviceInfo device_info(*it, media::VideoCaptureCapabilities());
413 if (!use_fake_device_) {
414 media::VideoCaptureDevice::GetDeviceSupportedFormats(
415 *it, &(device_info.capabilities_));
416 } else {
417 media::FakeVideoCaptureDevice::GetDeviceSupportedFormats(
418 *it, &(device_info.capabilities_));
419 }
420 new_devices_info_cache.push_back(device_info);
421 }
422 return new_devices_info_cache;
343 } 423 }
344 424
345 VideoCaptureManager::DeviceEntry* 425 VideoCaptureManager::DeviceEntry*
346 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice( 426 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice(
347 const MediaStreamDevice& device_info) { 427 const MediaStreamDevice& device_info) {
348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 428 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
349 429
350 for (DeviceEntries::iterator it = devices_.begin(); 430 for (DeviceEntries::iterator it = devices_.begin();
351 it != devices_.end(); ++it) { 431 it != devices_.end(); ++it) {
352 DeviceEntry* device = *it; 432 DeviceEntry* device = *it;
(...skipping 26 matching lines...) Expand all
379 << entry->stream_type << ", id = " << entry->id << ")"; 459 << entry->stream_type << ", id = " << entry->id << ")";
380 460
381 // The DeviceEntry is removed from |devices_| immediately. The controller is 461 // The DeviceEntry is removed from |devices_| immediately. The controller is
382 // deleted immediately, and the device is freed asynchronously. After this 462 // deleted immediately, and the device is freed asynchronously. After this
383 // point, subsequent requests to open this same device ID will create a new 463 // point, subsequent requests to open this same device ID will create a new
384 // DeviceEntry, VideoCaptureController, and VideoCaptureDevice. 464 // DeviceEntry, VideoCaptureController, and VideoCaptureDevice.
385 devices_.erase(entry); 465 devices_.erase(entry);
386 entry->video_capture_controller.reset(); 466 entry->video_capture_controller.reset();
387 device_loop_->PostTask( 467 device_loop_->PostTask(
388 FROM_HERE, 468 FROM_HERE,
389 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, 469 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread,
470 this,
390 base::Owned(entry))); 471 base::Owned(entry)));
472 DeviceInfo* device_info =
473 FindDeviceInfoById(entry->id, devices_info_cache_);
474 if (device_info)
475 device_info->device_in_use_ = false;
perkj_chrome 2013/11/12 11:10:58 Where to you use this info now?
mcasas 2013/11/12 12:21:53 See comment on line 295, basically I forgot to add
391 } 476 }
392 } 477 }
393 478
394 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry( 479 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry(
395 int capture_session_id) { 480 int capture_session_id) {
396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 481 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
397 482
398 std::map<int, MediaStreamDevice>::iterator session_it = 483 std::map<int, MediaStreamDevice>::iterator session_it =
399 sessions_.find(capture_session_id); 484 sessions_.find(capture_session_id);
400 if (session_it == sessions_.end()) { 485 if (session_it == sessions_.end()) {
(...skipping 12 matching lines...) Expand all
413 498
414 scoped_ptr<VideoCaptureController> video_capture_controller( 499 scoped_ptr<VideoCaptureController> video_capture_controller(
415 new VideoCaptureController()); 500 new VideoCaptureController());
416 DeviceEntry* new_device = new DeviceEntry(device_info.type, 501 DeviceEntry* new_device = new DeviceEntry(device_info.type,
417 device_info.id, 502 device_info.id,
418 video_capture_controller.Pass()); 503 video_capture_controller.Pass());
419 devices_.insert(new_device); 504 devices_.insert(new_device);
420 return new_device; 505 return new_device;
421 } 506 }
422 507
508 VideoCaptureManager::DeviceInfo* VideoCaptureManager::FindDeviceInfoById(
509 const std::string& id,
510 DevicesInfo& device_vector) {
511 for (DevicesInfo::iterator it = device_vector.begin();
512 it != device_vector.end(); ++it) {
513 if (it->name_.id() == id)
514 return it.base();
515 }
516 return NULL;
517 }
518
423 } // namespace content 519 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698