Chromium Code Reviews| 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); |
|
Mike West
2014/10/02 11:24:39
Nit: The bool at the end makes this is pretty hard
michaelbai
2014/10/02 18:55:39
Yes, it is a little bit hard to read, but there ar
|
| + if (controller->GetActiveClientCount() != 1) |
| + return; |
| + |
| + // This is first active client, allocate the camera. |
|
Mike West
2014/10/02 11:24:39
Since resuming capture assumes that the user has a
|
| + 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) { |