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

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: Style tweaks, per mcasas's comments. 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 721 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) 743 controller->PauseClient(client_id, client_handler);
744 if (!had_active_client || controller->HasActiveClient())
744 return; 745 return;
745 746 if (media::VideoCaptureDevice* device = entry->video_capture_device()) {
746 controller->PauseClient(client_id, client_handler); 747 device_task_runner_->PostTask(
748 FROM_HERE,
749 base::Bind(&VideoCaptureDevice::MaybeSuspend,
750 // Unretained is safe to use here because |device| would be
751 // null if it was scheduled for shutdown and destruction, and
752 // because this task is guaranteed to run before the task
753 // that destroys the |device|.
754 base::Unretained(device)));
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) 773 controller->ResumeClient(client_id, client_handler);
774 if (had_active_client || !controller->HasActiveClient())
765 return; 775 return;
766 776 if (media::VideoCaptureDevice* device = entry->video_capture_device()) {
767 controller->ResumeClient(client_id, client_handler); 777 device_task_runner_->PostTask(
778 FROM_HERE,
779 base::Bind(&VideoCaptureDevice::Resume,
780 // Unretained is safe to use here because |device| would be
781 // null if it was scheduled for shutdown and destruction, and
782 // because this task is guaranteed to run before the task
783 // that destroys the |device|.
784 base::Unretained(device)));
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698