| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 } | 513 } |
| 514 base::PostTaskAndReplyWithResult( | 514 base::PostTaskAndReplyWithResult( |
| 515 device_task_runner_.get(), FROM_HERE, start_capture_function, | 515 device_task_runner_.get(), FROM_HERE, start_capture_function, |
| 516 base::Bind(&VideoCaptureManager::OnDeviceStarted, this, | 516 base::Bind(&VideoCaptureManager::OnDeviceStarted, this, |
| 517 request->serial_id())); | 517 request->serial_id())); |
| 518 } | 518 } |
| 519 | 519 |
| 520 void VideoCaptureManager::OnDeviceStarted( | 520 void VideoCaptureManager::OnDeviceStarted( |
| 521 int serial_id, | 521 int serial_id, |
| 522 std::unique_ptr<VideoCaptureDevice> device) { | 522 std::unique_ptr<VideoCaptureDevice> device) { |
| 523 DVLOG(3) << __func__; |
| 523 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 524 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 524 DCHECK_EQ(serial_id, device_start_queue_.begin()->serial_id()); | 525 DCHECK_EQ(serial_id, device_start_queue_.begin()->serial_id()); |
| 525 DVLOG(3) << __func__; | |
| 526 if (device_start_queue_.front().abort_start()) { | 526 if (device_start_queue_.front().abort_start()) { |
| 527 // |device| can be null if creation failed in | 527 // |device| can be null if creation failed in |
| 528 // DoStartDeviceCaptureOnDeviceThread. | 528 // DoStartDeviceCaptureOnDeviceThread. |
| 529 // The device is no longer wanted. Stop the device again. | 529 // The device is no longer wanted. Stop the device again. |
| 530 DVLOG(3) << "OnDeviceStarted but start request have been aborted."; | 530 DVLOG(3) << "OnDeviceStarted but start request have been aborted."; |
| 531 media::VideoCaptureDevice* device_ptr = device.get(); | 531 media::VideoCaptureDevice* device_ptr = device.get(); |
| 532 base::Closure closure = | 532 base::Closure closure = |
| 533 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, | 533 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, |
| 534 base::Passed(&device)); | 534 base::Passed(&device)); |
| 535 if (device_ptr && !device_task_runner_->PostTask(FROM_HERE, closure)) { | 535 if (device_ptr && !device_task_runner_->PostTask(FROM_HERE, closure)) { |
| 536 // PostTask failed. The device must be stopped anyway. | 536 // PostTask failed. The device must be stopped anyway. |
| 537 device_ptr->StopAndDeAllocate(); | 537 device_ptr->StopAndDeAllocate(); |
| 538 } | 538 } |
| 539 } else { | 539 } else { |
| 540 DeviceEntry* const entry = GetDeviceEntryBySerialId(serial_id); | 540 DeviceEntry* const entry = GetDeviceEntryBySerialId(serial_id); |
| 541 DCHECK(entry); | 541 DCHECK(entry); |
| 542 DCHECK(!entry->video_capture_device()); | 542 DCHECK(!entry->video_capture_device()); |
| 543 entry->SetVideoCaptureDevice(std::move(device)); | 543 entry->SetVideoCaptureDevice(std::move(device)); |
| 544 | 544 |
| 545 if (entry->stream_type == MEDIA_DESKTOP_VIDEO_CAPTURE) { | 545 if (entry->stream_type == MEDIA_DESKTOP_VIDEO_CAPTURE) { |
| 546 const media::VideoCaptureSessionId session_id = | 546 const media::VideoCaptureSessionId session_id = |
| 547 device_start_queue_.front().session_id(); | 547 device_start_queue_.front().session_id(); |
| 548 DCHECK(session_id != kFakeSessionId); | 548 DCHECK(session_id != kFakeSessionId); |
| 549 MaybePostDesktopCaptureWindowId(session_id); | 549 MaybePostDesktopCaptureWindowId(session_id); |
| 550 } | 550 } |
| 551 | 551 |
| 552 auto request = photo_request_queue_.begin(); | 552 auto it = photo_request_queue_.begin(); |
| 553 while(request != photo_request_queue_.end()) { | 553 while (it != photo_request_queue_.end()) { |
| 554 auto request = it++; |
| 554 DeviceEntry* maybe_entry = GetDeviceEntryBySessionId(request->first); | 555 DeviceEntry* maybe_entry = GetDeviceEntryBySessionId(request->first); |
| 555 if (maybe_entry && maybe_entry->video_capture_device()) { | 556 if (maybe_entry && maybe_entry->video_capture_device()) { |
| 556 request->second.Run(maybe_entry->video_capture_device()); | 557 request->second.Run(maybe_entry->video_capture_device()); |
| 557 photo_request_queue_.erase(request); | 558 photo_request_queue_.erase(request); |
| 558 } | 559 } |
| 559 ++request; | |
| 560 } | 560 } |
| 561 } | 561 } |
| 562 | 562 |
| 563 device_start_queue_.pop_front(); | 563 device_start_queue_.pop_front(); |
| 564 HandleQueuedStartRequest(); | 564 HandleQueuedStartRequest(); |
| 565 } | 565 } |
| 566 | 566 |
| 567 std::unique_ptr<media::VideoCaptureDevice> | 567 std::unique_ptr<media::VideoCaptureDevice> |
| 568 VideoCaptureManager::DoStartDeviceCaptureOnDeviceThread( | 568 VideoCaptureManager::DoStartDeviceCaptureOnDeviceThread( |
| 569 const VideoCaptureDeviceDescriptor& descriptor, | 569 const VideoCaptureDeviceDescriptor& descriptor, |
| (...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 if (!device_in_queue) { | 1285 if (!device_in_queue) { |
| 1286 // Session ID is only valid for Screen capture. So we can fake it to | 1286 // Session ID is only valid for Screen capture. So we can fake it to |
| 1287 // resume video capture devices here. | 1287 // resume video capture devices here. |
| 1288 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters); | 1288 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters); |
| 1289 } | 1289 } |
| 1290 } | 1290 } |
| 1291 } | 1291 } |
| 1292 #endif // defined(OS_ANDROID) | 1292 #endif // defined(OS_ANDROID) |
| 1293 | 1293 |
| 1294 } // namespace content | 1294 } // namespace content |
| OLD | NEW |