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

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

Issue 2365223002: Video Capture: Allow suspension of individual devices. (Closed)
Patch Set: Created 4 years, 2 months 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 <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 VideoCaptureController* controller, 727 VideoCaptureController* controller,
728 VideoCaptureControllerID client_id, 728 VideoCaptureControllerID client_id,
729 VideoCaptureControllerEventHandler* client_handler) { 729 VideoCaptureControllerEventHandler* client_handler) {
730 DCHECK_CURRENTLY_ON(BrowserThread::IO); 730 DCHECK_CURRENTLY_ON(BrowserThread::IO);
731 DCHECK(controller); 731 DCHECK(controller);
732 DCHECK(client_handler); 732 DCHECK(client_handler);
733 DeviceEntry* entry = GetDeviceEntryByController(controller); 733 DeviceEntry* entry = GetDeviceEntryByController(controller);
734 if (!entry) 734 if (!entry)
735 NOTREACHED() << "Got Null entry while pausing capture"; 735 NOTREACHED() << "Got Null entry while pausing capture";
736 736
737 // Do not pause Content Video Capture devices, e.g. Tab or Screen capture. 737 const bool had_active_client = controller->HasActiveClient();
738 if (entry->stream_type != MEDIA_DEVICE_VIDEO_CAPTURE)
739 return;
740
741 controller->PauseClient(client_id, client_handler); 738 controller->PauseClient(client_id, client_handler);
739 if (had_active_client && !controller->HasActiveClient()) {
740 if (media::VideoCaptureDevice* device = entry->video_capture_device()) {
741 device_task_runner_->PostTask(
742 FROM_HERE,
743 base::Bind(&VideoCaptureDevice::MaybeSuspend,
744 // Unretained is safe to use here because |device| would be
745 // null if it was scheduled for shutdown and destruction,
746 // and because this task is guaranteed to run before the
747 // task that destroys the |device|.
748 base::Unretained(device)));
749 }
750 }
chfremer 2016/09/27 00:54:59 We are changing the behavior of VideoCaptureManage
miu 2016/09/27 23:42:22 Seems so. I added some extra testing around this t
742 } 751 }
743 752
744 void VideoCaptureManager::ResumeCaptureForClient( 753 void VideoCaptureManager::ResumeCaptureForClient(
745 media::VideoCaptureSessionId session_id, 754 media::VideoCaptureSessionId session_id,
746 const media::VideoCaptureParams& params, 755 const media::VideoCaptureParams& params,
747 VideoCaptureController* controller, 756 VideoCaptureController* controller,
748 VideoCaptureControllerID client_id, 757 VideoCaptureControllerID client_id,
749 VideoCaptureControllerEventHandler* client_handler) { 758 VideoCaptureControllerEventHandler* client_handler) {
750 DCHECK_CURRENTLY_ON(BrowserThread::IO); 759 DCHECK_CURRENTLY_ON(BrowserThread::IO);
751 DCHECK(controller); 760 DCHECK(controller);
752 DCHECK(client_handler); 761 DCHECK(client_handler);
753 762
754 DeviceEntry* entry = GetDeviceEntryByController(controller); 763 DeviceEntry* entry = GetDeviceEntryByController(controller);
755 if (!entry) 764 if (!entry)
756 NOTREACHED() << "Got Null entry while resuming capture"; 765 NOTREACHED() << "Got Null entry while resuming capture";
757 766
758 // Do not resume Content Video Capture devices, e.g. Tab or Screen capture. 767 const bool had_active_client = controller->HasActiveClient();
759 if (entry->stream_type != MEDIA_DEVICE_VIDEO_CAPTURE)
760 return;
761
762 controller->ResumeClient(client_id, client_handler); 768 controller->ResumeClient(client_id, client_handler);
769 if (!had_active_client && controller->HasActiveClient()) {
770 if (media::VideoCaptureDevice* device = entry->video_capture_device()) {
771 device_task_runner_->PostTask(
772 FROM_HERE,
773 base::Bind(&VideoCaptureDevice::Resume,
774 // Unretained is safe to use here because |device| would be
775 // null if it was scheduled for shutdown and destruction,
776 // and because this task is guaranteed to run before the
777 // task that destroys the |device|.
778 base::Unretained(device)));
779 }
780 }
763 } 781 }
764 782
765 void VideoCaptureManager::RequestRefreshFrameForClient( 783 void VideoCaptureManager::RequestRefreshFrameForClient(
766 VideoCaptureController* controller) { 784 VideoCaptureController* controller) {
767 DCHECK_CURRENTLY_ON(BrowserThread::IO); 785 DCHECK_CURRENTLY_ON(BrowserThread::IO);
768 786
769 if (DeviceEntry* entry = GetDeviceEntryByController(controller)) { 787 if (DeviceEntry* entry = GetDeviceEntryByController(controller)) {
770 if (media::VideoCaptureDevice* device = entry->video_capture_device()) { 788 if (media::VideoCaptureDevice* device = entry->video_capture_device()) {
771 device_task_runner_->PostTask( 789 device_task_runner_->PostTask(
772 FROM_HERE, 790 FROM_HERE,
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 if (!device_in_queue) { 1277 if (!device_in_queue) {
1260 // Session ID is only valid for Screen capture. So we can fake it to 1278 // Session ID is only valid for Screen capture. So we can fake it to
1261 // resume video capture devices here. 1279 // resume video capture devices here.
1262 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters); 1280 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters);
1263 } 1281 }
1264 } 1282 }
1265 } 1283 }
1266 #endif // defined(OS_ANDROID) 1284 #endif // defined(OS_ANDROID)
1267 1285
1268 } // namespace content 1286 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698