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 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
732 VideoCaptureController* controller, | 732 VideoCaptureController* controller, |
733 VideoCaptureControllerID client_id, | 733 VideoCaptureControllerID client_id, |
734 VideoCaptureControllerEventHandler* client_handler) { | 734 VideoCaptureControllerEventHandler* client_handler) { |
735 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 735 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
736 DCHECK(controller); | 736 DCHECK(controller); |
737 DCHECK(client_handler); | 737 DCHECK(client_handler); |
738 DeviceEntry* entry = GetDeviceEntryByController(controller); | 738 DeviceEntry* entry = GetDeviceEntryByController(controller); |
739 if (!entry) | 739 if (!entry) |
740 NOTREACHED() << "Got Null entry while pausing capture"; | 740 NOTREACHED() << "Got Null entry while pausing capture"; |
741 | 741 |
742 // Do not pause Content Video Capture devices, e.g. Tab or Screen capture. | 742 const bool had_active_client = controller->HasActiveClient(); |
743 if (entry->stream_type != MEDIA_DEVICE_VIDEO_CAPTURE) | |
744 return; | |
745 | |
746 controller->PauseClient(client_id, client_handler); | 743 controller->PauseClient(client_id, client_handler); |
744 if (had_active_client && !controller->HasActiveClient()) { | |
mcasas
2016/09/28 21:34:44
Early return?
if (!had_active_client || controll
miu
2016/09/28 22:35:15
Done.
| |
745 if (media::VideoCaptureDevice* device = entry->video_capture_device()) { | |
mcasas
2016/09/28 21:34:44
nit: I thought assignment-and-testing were discour
miu
2016/09/28 22:35:15
I've used it all over the place. Never had anyone
| |
746 device_task_runner_->PostTask( | |
747 FROM_HERE, | |
748 base::Bind(&VideoCaptureDevice::MaybeSuspend, | |
749 // Unretained is safe to use here because |device| would be | |
750 // null if it was scheduled for shutdown and destruction, | |
751 // and because this task is guaranteed to run before the | |
752 // task that destroys the |device|. | |
753 base::Unretained(device))); | |
754 } | |
755 } | |
747 } | 756 } |
748 | 757 |
749 void VideoCaptureManager::ResumeCaptureForClient( | 758 void VideoCaptureManager::ResumeCaptureForClient( |
750 media::VideoCaptureSessionId session_id, | 759 media::VideoCaptureSessionId session_id, |
751 const media::VideoCaptureParams& params, | 760 const media::VideoCaptureParams& params, |
752 VideoCaptureController* controller, | 761 VideoCaptureController* controller, |
753 VideoCaptureControllerID client_id, | 762 VideoCaptureControllerID client_id, |
754 VideoCaptureControllerEventHandler* client_handler) { | 763 VideoCaptureControllerEventHandler* client_handler) { |
755 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 764 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
756 DCHECK(controller); | 765 DCHECK(controller); |
757 DCHECK(client_handler); | 766 DCHECK(client_handler); |
758 | 767 |
759 DeviceEntry* entry = GetDeviceEntryByController(controller); | 768 DeviceEntry* entry = GetDeviceEntryByController(controller); |
760 if (!entry) | 769 if (!entry) |
761 NOTREACHED() << "Got Null entry while resuming capture"; | 770 NOTREACHED() << "Got Null entry while resuming capture"; |
762 | 771 |
763 // Do not resume Content Video Capture devices, e.g. Tab or Screen capture. | 772 const bool had_active_client = controller->HasActiveClient(); |
764 if (entry->stream_type != MEDIA_DEVICE_VIDEO_CAPTURE) | |
765 return; | |
766 | |
767 controller->ResumeClient(client_id, client_handler); | 773 controller->ResumeClient(client_id, client_handler); |
774 if (!had_active_client && controller->HasActiveClient()) { | |
775 if (media::VideoCaptureDevice* device = entry->video_capture_device()) { | |
776 device_task_runner_->PostTask( | |
777 FROM_HERE, | |
778 base::Bind(&VideoCaptureDevice::Resume, | |
779 // Unretained is safe to use here because |device| would be | |
780 // null if it was scheduled for shutdown and destruction, | |
781 // and because this task is guaranteed to run before the | |
782 // task that destroys the |device|. | |
783 base::Unretained(device))); | |
784 } | |
785 } | |
768 } | 786 } |
769 | 787 |
770 void VideoCaptureManager::RequestRefreshFrameForClient( | 788 void VideoCaptureManager::RequestRefreshFrameForClient( |
771 VideoCaptureController* controller) { | 789 VideoCaptureController* controller) { |
772 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 790 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
773 | 791 |
774 if (DeviceEntry* entry = GetDeviceEntryByController(controller)) { | 792 if (DeviceEntry* entry = GetDeviceEntryByController(controller)) { |
775 if (media::VideoCaptureDevice* device = entry->video_capture_device()) { | 793 if (media::VideoCaptureDevice* device = entry->video_capture_device()) { |
776 device_task_runner_->PostTask( | 794 device_task_runner_->PostTask( |
777 FROM_HERE, | 795 FROM_HERE, |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1264 if (!device_in_queue) { | 1282 if (!device_in_queue) { |
1265 // Session ID is only valid for Screen capture. So we can fake it to | 1283 // Session ID is only valid for Screen capture. So we can fake it to |
1266 // resume video capture devices here. | 1284 // resume video capture devices here. |
1267 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters); | 1285 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters); |
1268 } | 1286 } |
1269 } | 1287 } |
1270 } | 1288 } |
1271 #endif // defined(OS_ANDROID) | 1289 #endif // defined(OS_ANDROID) |
1272 | 1290 |
1273 } // namespace content | 1291 } // namespace content |
OLD | NEW |