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

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

Issue 801363002: Queue commands to the Os to start a video device. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed more comments. Created 6 years 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/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 VideoCaptureManager::VideoCaptureManager( 112 VideoCaptureManager::VideoCaptureManager(
113 scoped_ptr<media::VideoCaptureDeviceFactory> factory) 113 scoped_ptr<media::VideoCaptureDeviceFactory> factory)
114 : listener_(NULL), 114 : listener_(NULL),
115 new_capture_session_id_(1), 115 new_capture_session_id_(1),
116 video_capture_device_factory_(factory.Pass()) { 116 video_capture_device_factory_(factory.Pass()) {
117 } 117 }
118 118
119 VideoCaptureManager::~VideoCaptureManager() { 119 VideoCaptureManager::~VideoCaptureManager() {
120 DCHECK(devices_.empty()); 120 DCHECK(devices_.empty());
121 DCHECK(device_start_queue_.empty());
121 } 122 }
122 123
123 void VideoCaptureManager::Register( 124 void VideoCaptureManager::Register(
124 MediaStreamProviderListener* listener, 125 MediaStreamProviderListener* listener,
125 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner) { 126 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner) {
126 DCHECK_CURRENTLY_ON(BrowserThread::IO); 127 DCHECK_CURRENTLY_ON(BrowserThread::IO);
127 DCHECK(!listener_); 128 DCHECK(!listener_);
128 DCHECK(!device_task_runner_.get()); 129 DCHECK(!device_task_runner_.get());
129 listener_ = listener; 130 listener_ = listener;
130 device_task_runner_ = device_task_runner; 131 device_task_runner_ = device_task_runner;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 DestroyDeviceEntryIfNoClients(existing_device); 210 DestroyDeviceEntryIfNoClients(existing_device);
210 } 211 }
211 212
212 // Notify listeners asynchronously, and forget the session. 213 // Notify listeners asynchronously, and forget the session.
213 base::MessageLoop::current()->PostTask(FROM_HERE, 214 base::MessageLoop::current()->PostTask(FROM_HERE,
214 base::Bind(&VideoCaptureManager::OnClosed, this, session_it->second.type, 215 base::Bind(&VideoCaptureManager::OnClosed, this, session_it->second.type,
215 capture_session_id)); 216 capture_session_id));
216 sessions_.erase(session_it); 217 sessions_.erase(session_it);
217 } 218 }
218 219
219 void VideoCaptureManager::DoStartDeviceOnDeviceThread( 220 VideoCaptureManager::CaptureDeviceStartRequest::CaptureDeviceStartRequest(
221 DeviceEntry* entry,
222 media::VideoCaptureSessionId session_id,
223 const media::VideoCaptureParams& params)
224 : entry(entry),
225 session_id(session_id),
226 params(params),
227 abort_start(false) {
228 }
229
230 void VideoCaptureManager::QueueStartDevice(
220 media::VideoCaptureSessionId session_id, 231 media::VideoCaptureSessionId session_id,
221 DeviceEntry* entry, 232 DeviceEntry* entry,
233 const media::VideoCaptureParams& params) {
234 DCHECK_CURRENTLY_ON(BrowserThread::IO);
235 device_start_queue_.push_back(
236 CaptureDeviceStartRequest(entry, session_id, params));
237 if (device_start_queue_.size() == 1)
238 HandleQueuedStartRequest();
239 }
240
241 void VideoCaptureManager::DoStopDevice(DeviceEntry* entry) {
242 DCHECK_CURRENTLY_ON(BrowserThread::IO);
243 DCHECK(std::find(devices_.begin(), devices_.end(), entry) != devices_.end());
244
245 // Reverse iterate to find the last start request. This also avoids a problem
246 // where |entry| might get the same pointer value if it is deleted
247 // and recreated while we are waiting for the device to be started.
248 for (DeviceStartQueue::reverse_iterator request =
249 device_start_queue_.rbegin();
250 request != device_start_queue_.rend(); ++request) {
251 if (request->entry == entry) {
252 request->abort_start = true;
253 DVLOG(3) << "DoStopDevice, aborting start request for device "
254 << entry->id << ".";
255 return;
256 }
257 }
258
259 DVLOG(3) << "DoStopDevice. Send stop request for device " << entry->id << ".";
260 if (entry->video_capture_device.get()) {
261 // |entry->video_capture_device| can be null if creating the device fails.
262 device_task_runner_->PostTask(
263 FROM_HERE,
264 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this,
265 base::Passed(&entry->video_capture_device)));
266 }
267 }
268
269 void VideoCaptureManager::HandleQueuedStartRequest() {
270 // Remove all start requests that have been aborted.
271 while(device_start_queue_.begin() != device_start_queue_.end() &&
272 device_start_queue_.begin()->abort_start) {
273 device_start_queue_.pop_front();
274 }
275 DeviceStartQueue::iterator request = device_start_queue_.begin();
276 if (request == device_start_queue_.end())
277 return;
278
279 DeviceEntry* entry = request->entry;
280 DCHECK(std::find(devices_.begin(), devices_.end(), request->entry) !=
281 devices_.end());
282
283 DVLOG(3) << "HandleQueuedStartRequest, Post start to device thread, device = "
284 << entry->id;
285 base::PostTaskAndReplyWithResult(
286 device_task_runner_.get(),
287 FROM_HERE,
288 base::Bind(
289 &VideoCaptureManager::DoStartDeviceOnDeviceThread,
290 this,
291 request->session_id,
292 entry->id,
293 entry->stream_type,
294 request->params,
295 base::Passed(entry->video_capture_controller->NewDeviceClient())),
296 base::Bind(&VideoCaptureManager::OnDeviceStarted, this, entry));
297 }
298
299 void VideoCaptureManager::OnDeviceStarted(
300 DeviceEntry* device_entry,
301 scoped_ptr<media::VideoCaptureDevice> device) {
302 DCHECK_CURRENTLY_ON(BrowserThread::IO);
303 DCHECK(device_entry == device_start_queue_.begin()->entry);
304 DVLOG(3) << "OnDeviceStarted";
305 if (device_start_queue_.front().abort_start) {
306 // |device| can be null if creation failed in DoStartDeviceOnDeviceThread.
307 // The device is no longer wanted. Stop the device again.
308 DVLOG(3) << "OnDeviceStarted but start request have been aborted.";
309 media::VideoCaptureDevice* device_ptr = device.get();
310 base::Closure closure =
311 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this,
312 base::Passed(&device));
313 if (device_ptr && !device_task_runner_->PostTask(FROM_HERE, closure)) {
314 // PostTask failed. The device must be stopped anyway.
315 device_ptr->StopAndDeAllocate();
316 }
317 } else {
318 DCHECK(std::find(devices_.begin(), devices_.end(), device_entry) !=
319 devices_.end());
320 DCHECK(!device_entry->video_capture_device);
tommi (sloooow) - chröme 2014/12/17 14:46:12 missing .get() or is this now supported in scoped_
perkj_chrome 2014/12/18 12:15:32 Seems to compile. Which operator would that be?
321 device_entry->video_capture_device.swap(device);
322 }
323
324 device_start_queue_.pop_front();
325 HandleQueuedStartRequest();
326 }
327
328 scoped_ptr<media::VideoCaptureDevice>
329 VideoCaptureManager::DoStartDeviceOnDeviceThread(
330 media::VideoCaptureSessionId session_id,
331 const std::string& id,
332 MediaStreamType stream_type,
222 const media::VideoCaptureParams& params, 333 const media::VideoCaptureParams& params,
223 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { 334 scoped_ptr<media::VideoCaptureDevice::Client> device_client) {
224 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); 335 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime");
225 DCHECK(IsOnDeviceThread()); 336 DCHECK(IsOnDeviceThread());
226 337
227 scoped_ptr<media::VideoCaptureDevice> video_capture_device; 338 scoped_ptr<media::VideoCaptureDevice> video_capture_device;
228 switch (entry->stream_type) { 339 switch (stream_type) {
229 case MEDIA_DEVICE_VIDEO_CAPTURE: { 340 case MEDIA_DEVICE_VIDEO_CAPTURE: {
230 // We look up the device id from the renderer in our local enumeration 341 // We look up the device id from the renderer in our local enumeration
231 // since the renderer does not have all the information that might be 342 // since the renderer does not have all the information that might be
232 // held in the browser-side VideoCaptureDevice::Name structure. 343 // held in the browser-side VideoCaptureDevice::Name structure.
233 media::VideoCaptureDeviceInfo* found = 344 media::VideoCaptureDeviceInfo* found =
234 FindDeviceInfoById(entry->id, devices_info_cache_); 345 FindDeviceInfoById(id, devices_info_cache_);
235 if (found) { 346 if (found) {
236 video_capture_device = 347 video_capture_device =
237 video_capture_device_factory_->Create(found->name); 348 video_capture_device_factory_->Create(found->name);
238 } 349 }
239 break; 350 break;
240 } 351 }
241 case MEDIA_TAB_VIDEO_CAPTURE: { 352 case MEDIA_TAB_VIDEO_CAPTURE: {
242 video_capture_device.reset( 353 video_capture_device.reset(
243 WebContentsVideoCaptureDevice::Create(entry->id)); 354 WebContentsVideoCaptureDevice::Create(id));
244 break; 355 break;
245 } 356 }
246 case MEDIA_DESKTOP_VIDEO_CAPTURE: { 357 case MEDIA_DESKTOP_VIDEO_CAPTURE: {
247 #if defined(ENABLE_SCREEN_CAPTURE) 358 #if defined(ENABLE_SCREEN_CAPTURE)
248 DesktopMediaID id = DesktopMediaID::Parse(entry->id); 359 DesktopMediaID desktop_id = DesktopMediaID::Parse(id);
249 #if defined(USE_AURA) 360 #if defined(USE_AURA)
250 if (id.type == DesktopMediaID::TYPE_AURA_WINDOW) { 361 if (desktop_id.type == DesktopMediaID::TYPE_AURA_WINDOW) {
251 video_capture_device.reset(DesktopCaptureDeviceAura::Create(id)); 362 video_capture_device.reset(
363 DesktopCaptureDeviceAura::Create(desktop_id));
252 } else 364 } else
253 #endif 365 #endif
254 if (id.type != DesktopMediaID::TYPE_NONE && 366 if (desktop_id.type != DesktopMediaID::TYPE_NONE &&
255 id.type != DesktopMediaID::TYPE_AURA_WINDOW) { 367 desktop_id.type != DesktopMediaID::TYPE_AURA_WINDOW) {
256 video_capture_device = DesktopCaptureDevice::Create(id); 368 video_capture_device = DesktopCaptureDevice::Create(desktop_id);
257 if (notification_window_ids_.find(session_id) != 369 if (notification_window_ids_.find(session_id) !=
258 notification_window_ids_.end()) { 370 notification_window_ids_.end()) {
259 static_cast<DesktopCaptureDevice*>(video_capture_device.get()) 371 static_cast<DesktopCaptureDevice*>(video_capture_device.get())
260 ->SetNotificationWindowId(notification_window_ids_[session_id]); 372 ->SetNotificationWindowId(notification_window_ids_[session_id]);
261 VLOG(2) << "Screen capture notification window passed for session " 373 VLOG(2) << "Screen capture notification window passed for session "
262 << session_id; 374 << session_id;
263 } 375 }
264 } 376 }
265 #endif // defined(ENABLE_SCREEN_CAPTURE) 377 #endif // defined(ENABLE_SCREEN_CAPTURE)
266 break; 378 break;
267 } 379 }
268 default: { 380 default: {
269 NOTIMPLEMENTED(); 381 NOTIMPLEMENTED();
270 break; 382 break;
271 } 383 }
272 } 384 }
273 385
274 if (!video_capture_device) { 386 if (!video_capture_device) {
275 device_client->OnError("Could not create capture device"); 387 device_client->OnError("Could not create capture device");
276 return; 388 return nullptr;
277 } 389 }
278 390
279 video_capture_device->AllocateAndStart(params, device_client.Pass()); 391 video_capture_device->AllocateAndStart(params, device_client.Pass());
280 entry->video_capture_device = video_capture_device.Pass(); 392 return video_capture_device.Pass();
281 } 393 }
282 394
283 void VideoCaptureManager::StartCaptureForClient( 395 void VideoCaptureManager::StartCaptureForClient(
284 media::VideoCaptureSessionId session_id, 396 media::VideoCaptureSessionId session_id,
285 const media::VideoCaptureParams& params, 397 const media::VideoCaptureParams& params,
286 base::ProcessHandle client_render_process, 398 base::ProcessHandle client_render_process,
287 VideoCaptureControllerID client_id, 399 VideoCaptureControllerID client_id,
288 VideoCaptureControllerEventHandler* client_handler, 400 VideoCaptureControllerEventHandler* client_handler,
289 const DoneCB& done_cb) { 401 const DoneCB& done_cb) {
290 DCHECK_CURRENTLY_ON(BrowserThread::IO); 402 DCHECK_CURRENTLY_ON(BrowserThread::IO);
291 DVLOG(1) << "VideoCaptureManager::StartCaptureForClient, " 403 DVLOG(1) << "VideoCaptureManager::StartCaptureForClient, "
292 << params.requested_format.frame_size.ToString() << ", " 404 << params.requested_format.frame_size.ToString() << ", "
293 << params.requested_format.frame_rate << ", #" << session_id << ")"; 405 << params.requested_format.frame_rate << ", #" << session_id << ")";
294 406
295 DeviceEntry* entry = GetOrCreateDeviceEntry(session_id); 407 DeviceEntry* entry = GetOrCreateDeviceEntry(session_id);
296 if (!entry) { 408 if (!entry) {
297 done_cb.Run(base::WeakPtr<VideoCaptureController>()); 409 done_cb.Run(base::WeakPtr<VideoCaptureController>());
298 return; 410 return;
299 } 411 }
300 412
301 DCHECK(entry->video_capture_controller); 413 DCHECK(entry->video_capture_controller);
302 414
303 LogVideoCaptureEvent(VIDEO_CAPTURE_START_CAPTURE); 415 LogVideoCaptureEvent(VIDEO_CAPTURE_START_CAPTURE);
304 416
305 // First client starts the device. 417 // First client starts the device.
306 if (entry->video_capture_controller->GetActiveClientCount() == 0) { 418 if (entry->video_capture_controller->GetActiveClientCount() == 0) {
307 DVLOG(1) << "VideoCaptureManager starting device (type = " 419 DVLOG(1) << "VideoCaptureManager starting device (type = "
308 << entry->stream_type << ", id = " << entry->id << ")"; 420 << entry->stream_type << ", id = " << entry->id << ")";
309 421 QueueStartDevice(session_id, entry, params);
310 device_task_runner_->PostTask(
311 FROM_HERE,
312 base::Bind(
313 &VideoCaptureManager::DoStartDeviceOnDeviceThread,
314 this,
315 session_id,
316 entry,
317 params,
318 base::Passed(entry->video_capture_controller->NewDeviceClient())));
319 } 422 }
320 // Run the callback first, as AddClient() may trigger OnFrameInfo(). 423 // Run the callback first, as AddClient() may trigger OnFrameInfo().
321 done_cb.Run(entry->video_capture_controller->GetWeakPtr()); 424 done_cb.Run(entry->video_capture_controller->GetWeakPtr());
322 entry->video_capture_controller->AddClient( 425 entry->video_capture_controller->AddClient(
323 client_id, client_handler, client_render_process, session_id, params); 426 client_id, client_handler, client_render_process, session_id, params);
324 } 427 }
325 428
326 void VideoCaptureManager::StopCaptureForClient( 429 void VideoCaptureManager::StopCaptureForClient(
327 VideoCaptureController* controller, 430 VideoCaptureController* controller,
328 VideoCaptureControllerID client_id, 431 VideoCaptureControllerID client_id,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 // We only pause the MEDIA_DEVICE_VIDEO_CAPTURE entry to release camera to 488 // We only pause the MEDIA_DEVICE_VIDEO_CAPTURE entry to release camera to
386 // system. 489 // system.
387 if (entry->stream_type != MEDIA_DEVICE_VIDEO_CAPTURE) 490 if (entry->stream_type != MEDIA_DEVICE_VIDEO_CAPTURE)
388 return; 491 return;
389 492
390 controller->PauseOrResumeClient(client_id, client_handler, true); 493 controller->PauseOrResumeClient(client_id, client_handler, true);
391 if (controller->GetActiveClientCount() != 0) 494 if (controller->GetActiveClientCount() != 0)
392 return; 495 return;
393 496
394 // There is no more client, release the camera. 497 // There is no more client, release the camera.
395 device_task_runner_->PostTask( 498 DoStopDevice(entry);
396 FROM_HERE,
397 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this,
398 base::Unretained(entry)));
399 } 499 }
400 500
401 void VideoCaptureManager::ResumeCaptureForClient( 501 void VideoCaptureManager::ResumeCaptureForClient(
402 media::VideoCaptureSessionId session_id, 502 media::VideoCaptureSessionId session_id,
403 const media::VideoCaptureParams& params, 503 const media::VideoCaptureParams& params,
404 VideoCaptureController* controller, 504 VideoCaptureController* controller,
405 VideoCaptureControllerID client_id, 505 VideoCaptureControllerID client_id,
406 VideoCaptureControllerEventHandler* client_handler) { 506 VideoCaptureControllerEventHandler* client_handler) {
407 DCHECK_CURRENTLY_ON(BrowserThread::IO); 507 DCHECK_CURRENTLY_ON(BrowserThread::IO);
408 DCHECK(controller); 508 DCHECK(controller);
409 DCHECK(client_handler); 509 DCHECK(client_handler);
410 510
411 DeviceEntry* entry = GetDeviceEntryForController(controller); 511 DeviceEntry* entry = GetDeviceEntryForController(controller);
412 if (!entry) { 512 if (!entry) {
413 NOTREACHED(); 513 NOTREACHED();
414 return; 514 return;
415 } 515 }
416 516
417 // We only pause/resume the MEDIA_DEVICE_VIDEO_CAPTURE entry. 517 // We only pause/resume the MEDIA_DEVICE_VIDEO_CAPTURE entry.
418 if (entry->stream_type != MEDIA_DEVICE_VIDEO_CAPTURE) 518 if (entry->stream_type != MEDIA_DEVICE_VIDEO_CAPTURE)
419 return; 519 return;
420 520
421 controller->PauseOrResumeClient(client_id, client_handler, false); 521 controller->PauseOrResumeClient(client_id, client_handler, false);
422 if (controller->GetActiveClientCount() != 1) 522 if (controller->GetActiveClientCount() != 1)
423 return; 523 return;
424 524
425 // This is first active client, allocate the camera. 525 // This is first active client, allocate the camera.
426 device_task_runner_->PostTask( 526 QueueStartDevice(session_id, entry, params);
427 FROM_HERE,
428 base::Bind(
429 &VideoCaptureManager::DoStartDeviceOnDeviceThread,
430 this,
431 session_id,
432 entry,
433 params,
434 base::Passed(entry->video_capture_controller->NewDeviceClient())));
435 } 527 }
436 528
437 bool VideoCaptureManager::GetDeviceSupportedFormats( 529 bool VideoCaptureManager::GetDeviceSupportedFormats(
438 media::VideoCaptureSessionId capture_session_id, 530 media::VideoCaptureSessionId capture_session_id,
439 media::VideoCaptureFormats* supported_formats) { 531 media::VideoCaptureFormats* supported_formats) {
440 DCHECK_CURRENTLY_ON(BrowserThread::IO); 532 DCHECK_CURRENTLY_ON(BrowserThread::IO);
441 DCHECK(supported_formats->empty()); 533 DCHECK(supported_formats->empty());
442 534
443 SessionMap::iterator it = sessions_.find(capture_session_id); 535 SessionMap::iterator it = sessions_.find(capture_session_id);
444 if (it == sessions_.end()) 536 if (it == sessions_.end())
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 } 602 }
511 603
512 device_task_runner_->PostTask( 604 device_task_runner_->PostTask(
513 FROM_HERE, 605 FROM_HERE,
514 base::Bind(&VideoCaptureManager::SetDesktopCaptureWindowIdOnDeviceThread, 606 base::Bind(&VideoCaptureManager::SetDesktopCaptureWindowIdOnDeviceThread,
515 this, 607 this,
516 existing_device, 608 existing_device,
517 window_id)); 609 window_id));
518 } 610 }
519 611
520 void VideoCaptureManager::DoStopDeviceOnDeviceThread(DeviceEntry* entry) { 612 void VideoCaptureManager::DoStopDeviceOnDeviceThread(
613 scoped_ptr<media::VideoCaptureDevice> device) {
521 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime"); 614 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime");
522 DCHECK(IsOnDeviceThread()); 615 DCHECK(IsOnDeviceThread());
523 if (entry->video_capture_device) { 616 device->StopAndDeAllocate();
524 entry->video_capture_device->StopAndDeAllocate(); 617 DVLOG(3) << "DoStopDeviceOnDeviceThread";
525 }
526 entry->video_capture_device.reset();
527 } 618 }
528 619
529 void VideoCaptureManager::OnOpened( 620 void VideoCaptureManager::OnOpened(
530 MediaStreamType stream_type, 621 MediaStreamType stream_type,
531 media::VideoCaptureSessionId capture_session_id) { 622 media::VideoCaptureSessionId capture_session_id) {
532 DCHECK_CURRENTLY_ON(BrowserThread::IO); 623 DCHECK_CURRENTLY_ON(BrowserThread::IO);
533 if (!listener_) { 624 if (!listener_) {
534 // Listener has been removed. 625 // Listener has been removed.
535 return; 626 return;
536 } 627 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 DCHECK_CURRENTLY_ON(BrowserThread::IO); 737 DCHECK_CURRENTLY_ON(BrowserThread::IO);
647 // Removal of the last client stops the device. 738 // Removal of the last client stops the device.
648 if (entry->video_capture_controller->GetClientCount() == 0) { 739 if (entry->video_capture_controller->GetClientCount() == 0) {
649 DVLOG(1) << "VideoCaptureManager stopping device (type = " 740 DVLOG(1) << "VideoCaptureManager stopping device (type = "
650 << entry->stream_type << ", id = " << entry->id << ")"; 741 << entry->stream_type << ", id = " << entry->id << ")";
651 742
652 // The DeviceEntry is removed from |devices_| immediately. The controller is 743 // The DeviceEntry is removed from |devices_| immediately. The controller is
653 // deleted immediately, and the device is freed asynchronously. After this 744 // deleted immediately, and the device is freed asynchronously. After this
654 // point, subsequent requests to open this same device ID will create a new 745 // point, subsequent requests to open this same device ID will create a new
655 // DeviceEntry, VideoCaptureController, and VideoCaptureDevice. 746 // DeviceEntry, VideoCaptureController, and VideoCaptureDevice.
656 devices_.erase(entry); 747 DoStopDevice(entry);
657 entry->video_capture_controller.reset(); 748 DeviceEntries::iterator device_it = std::find(devices_.begin(),
658 device_task_runner_->PostTask( 749 devices_.end(),
659 FROM_HERE, 750 entry);
660 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, 751 devices_.erase(device_it);
661 base::Owned(entry)));
662 } 752 }
663 } 753 }
664 754
665 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry( 755 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry(
666 media::VideoCaptureSessionId capture_session_id) { 756 media::VideoCaptureSessionId capture_session_id) {
667 DCHECK_CURRENTLY_ON(BrowserThread::IO); 757 DCHECK_CURRENTLY_ON(BrowserThread::IO);
668 758
669 SessionMap::iterator session_it = sessions_.find(capture_session_id); 759 SessionMap::iterator session_it = sessions_.find(capture_session_id);
670 if (session_it == sessions_.end()) { 760 if (session_it == sessions_.end()) {
671 return NULL; 761 return NULL;
672 } 762 }
673 const MediaStreamDevice& device_info = session_it->second; 763 const MediaStreamDevice& device_info = session_it->second;
674 764
675 // Check if another session has already opened this device. If so, just 765 // Check if another session has already opened this device. If so, just
676 // use that opened device. 766 // use that opened device.
677 DeviceEntry* const existing_device = 767 DeviceEntry* const existing_device =
678 GetDeviceEntryForMediaStreamDevice(device_info); 768 GetDeviceEntryForMediaStreamDevice(device_info);
679 if (existing_device) { 769 if (existing_device) {
680 DCHECK_EQ(device_info.type, existing_device->stream_type); 770 DCHECK_EQ(device_info.type, existing_device->stream_type);
681 return existing_device; 771 return existing_device;
682 } 772 }
683 773
684 const int max_buffers = device_info.type == MEDIA_TAB_VIDEO_CAPTURE ? 774 const int max_buffers = device_info.type == MEDIA_TAB_VIDEO_CAPTURE ?
685 kMaxNumberOfBuffersForTabCapture : kMaxNumberOfBuffers; 775 kMaxNumberOfBuffersForTabCapture : kMaxNumberOfBuffers;
686 scoped_ptr<VideoCaptureController> video_capture_controller( 776 scoped_ptr<VideoCaptureController> video_capture_controller(
687 new VideoCaptureController(max_buffers)); 777 new VideoCaptureController(max_buffers));
688 DeviceEntry* new_device = new DeviceEntry(device_info.type, 778 DeviceEntry* new_device = new DeviceEntry(device_info.type,
689 device_info.id, 779 device_info.id,
690 video_capture_controller.Pass()); 780 video_capture_controller.Pass());
691 devices_.insert(new_device); 781 devices_.push_back(new_device);
692 return new_device; 782 return new_device;
693 } 783 }
694 784
695 media::VideoCaptureDeviceInfo* VideoCaptureManager::FindDeviceInfoById( 785 media::VideoCaptureDeviceInfo* VideoCaptureManager::FindDeviceInfoById(
696 const std::string& id, 786 const std::string& id,
697 media::VideoCaptureDeviceInfos& device_vector) { 787 media::VideoCaptureDeviceInfos& device_vector) {
698 for (auto& it : device_vector) { 788 for (auto& it : device_vector) {
699 if (it.name.id() == id) 789 if (it.name.id() == id)
700 return &(it); 790 return &(it);
701 } 791 }
(...skipping 18 matching lines...) Expand all
720 gfx::NativeViewId window_id) { 810 gfx::NativeViewId window_id) {
721 DCHECK(IsOnDeviceThread()); 811 DCHECK(IsOnDeviceThread());
722 DCHECK(notification_window_ids_.find(session_id) == 812 DCHECK(notification_window_ids_.find(session_id) ==
723 notification_window_ids_.end()); 813 notification_window_ids_.end());
724 notification_window_ids_[session_id] = window_id; 814 notification_window_ids_[session_id] = window_id;
725 VLOG(2) << "Screen capture notification window saved for session " 815 VLOG(2) << "Screen capture notification window saved for session "
726 << session_id << " on device thread."; 816 << session_id << " on device thread.";
727 } 817 }
728 818
729 } // namespace content 819 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698