| Index: webrtc/media/base/capturemanager.cc
|
| diff --git a/webrtc/media/base/capturemanager.cc b/webrtc/media/base/capturemanager.cc
|
| index 0e724773c7d3ca883688cf9ba5bf1322c3858adb..3628fb306d8663a0f18f5b30224a9bc4751777df 100644
|
| --- a/webrtc/media/base/capturemanager.cc
|
| +++ b/webrtc/media/base/capturemanager.cc
|
| @@ -194,6 +194,62 @@
|
| if (capture_state->DecCaptureStartRef() == 0) {
|
| // Unregistering cannot fail as capture_state is not NULL.
|
| UnregisterVideoCapturer(capture_state);
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +bool CaptureManager::RestartVideoCapture(
|
| + VideoCapturer* video_capturer,
|
| + const VideoFormat& previous_format,
|
| + const VideoFormat& desired_format,
|
| + CaptureManager::RestartOptions options) {
|
| + RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
| + if (!IsCapturerRegistered(video_capturer)) {
|
| + LOG(LS_ERROR) << "RestartVideoCapture: video_capturer is not registered.";
|
| + return false;
|
| + }
|
| + // Start the new format first. This keeps the capturer running.
|
| + if (!StartVideoCapture(video_capturer, desired_format)) {
|
| + LOG(LS_ERROR) << "RestartVideoCapture: unable to start video capture with "
|
| + "desired_format=" << desired_format.ToString();
|
| + return false;
|
| + }
|
| + // Stop the old format.
|
| + if (!StopVideoCapture(video_capturer, previous_format)) {
|
| + LOG(LS_ERROR) << "RestartVideoCapture: unable to stop video capture with "
|
| + "previous_format=" << previous_format.ToString();
|
| + // Undo the start request we just performed.
|
| + StopVideoCapture(video_capturer, desired_format);
|
| + return false;
|
| + }
|
| +
|
| + switch (options) {
|
| + case kForceRestart: {
|
| + VideoCapturerState* capture_state = GetCaptureState(video_capturer);
|
| + ASSERT(capture_state && capture_state->start_count() > 0);
|
| + // Try a restart using the new best resolution.
|
| + VideoFormat highest_asked_format =
|
| + capture_state->GetHighestFormat(video_capturer);
|
| + VideoFormat capture_format;
|
| + if (video_capturer->GetBestCaptureFormat(highest_asked_format,
|
| + &capture_format)) {
|
| + if (!video_capturer->Restart(capture_format)) {
|
| + LOG(LS_ERROR) << "RestartVideoCapture: Restart failed.";
|
| + }
|
| + } else {
|
| + LOG(LS_WARNING)
|
| + << "RestartVideoCapture: Couldn't find a best capture format for "
|
| + << highest_asked_format.ToString();
|
| + }
|
| + break;
|
| + }
|
| + case kRequestRestart:
|
| + // TODO(ryanpetrie): Support restart requests. Should this
|
| + // to-be-implemented logic be used for {Start,Stop}VideoCapture as well?
|
| + break;
|
| + default:
|
| + LOG(LS_ERROR) << "Unknown/unimplemented RestartOption";
|
| + break;
|
| }
|
| return true;
|
| }
|
|
|