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

Unified Diff: content/browser/renderer_host/media/video_capture_manager.cc

Issue 615043006: Release the camera when WebRTC is not visible in Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync Created 6 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/media/video_capture_manager.cc
diff --git a/content/browser/renderer_host/media/video_capture_manager.cc b/content/browser/renderer_host/media/video_capture_manager.cc
index 83b01a7fb1a2c30734bcc2c8dda5104ea9135a14..7a28856273673092a84a4d761b278ab9dec96c7e 100644
--- a/content/browser/renderer_host/media/video_capture_manager.cc
+++ b/content/browser/renderer_host/media/video_capture_manager.cc
@@ -308,7 +308,7 @@ void VideoCaptureManager::StartCaptureForClient(
LogVideoCaptureEvent(VIDEO_CAPTURE_EVENT_START_CAPTURE);
// First client starts the device.
- if (entry->video_capture_controller->GetClientCount() == 0) {
+ if (entry->video_capture_controller->GetActiveClientCount() == 0) {
DVLOG(1) << "VideoCaptureManager starting device (type = "
<< entry->stream_type << ", id = " << entry->id << ")";
@@ -367,6 +367,71 @@ void VideoCaptureManager::StopCaptureForClient(
DestroyDeviceEntryIfNoClients(entry);
}
+void VideoCaptureManager::PauseCaptureForClient(
+ VideoCaptureController* controller,
+ VideoCaptureControllerID client_id,
+ VideoCaptureControllerEventHandler* client_handler) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(controller);
+ DCHECK(client_handler);
+ DeviceEntry* entry = GetDeviceEntryForController(controller);
+ if (!entry) {
+ NOTREACHED();
+ return;
+ }
+
+ // We only pause the MEDIA_DEVICE_VIDEO_CAPTURE entry to release camera to
+ // system.
+ if (entry->stream_type != MEDIA_DEVICE_VIDEO_CAPTURE)
+ return;
+
+ controller->PauseOrResumeClient(client_id, client_handler, true);
+ if (controller->GetActiveClientCount() != 0)
+ return;
+
+ // There is no more client, release the camera.
+ device_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this,
+ base::Unretained(entry)));
+}
+
+void VideoCaptureManager::ResumeCaptureForClient(
+ media::VideoCaptureSessionId session_id,
+ const media::VideoCaptureParams& params,
+ VideoCaptureController* controller,
+ VideoCaptureControllerID client_id,
+ VideoCaptureControllerEventHandler* client_handler) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(controller);
+ DCHECK(client_handler);
+
+ DeviceEntry* entry = GetDeviceEntryForController(controller);
+ if (!entry) {
+ NOTREACHED();
+ return;
+ }
+
+ // We only pause/resume the MEDIA_DEVICE_VIDEO_CAPTURE entry.
+ if (entry->stream_type != MEDIA_DEVICE_VIDEO_CAPTURE)
+ return;
+
+ controller->PauseOrResumeClient(client_id, client_handler, false);
+ if (controller->GetActiveClientCount() != 1)
+ return;
+
+ // This is first active client, allocate the camera.
+ device_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &VideoCaptureManager::DoStartDeviceOnDeviceThread,
+ this,
+ session_id,
+ entry,
+ params,
+ base::Passed(entry->video_capture_controller->NewDeviceClient())));
+}
+
bool VideoCaptureManager::GetDeviceSupportedFormats(
media::VideoCaptureSessionId capture_session_id,
media::VideoCaptureFormats* supported_formats) {
« no previous file with comments | « content/browser/renderer_host/media/video_capture_manager.h ('k') | content/common/media/video_capture_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698