Chromium Code Reviews| Index: webrtc/modules/desktop_capture/fallback_desktop_capturer_wrapper.cc |
| diff --git a/webrtc/modules/desktop_capture/fallback_desktop_capturer_wrapper.cc b/webrtc/modules/desktop_capture/fallback_desktop_capturer_wrapper.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3f15f50bb487b336e912824f7ab4c04b730a2e30 |
| --- /dev/null |
| +++ b/webrtc/modules/desktop_capture/fallback_desktop_capturer_wrapper.cc |
| @@ -0,0 +1,101 @@ |
| +/* |
| + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#include "webrtc/modules/desktop_capture/fallback_desktop_capturer_wrapper.h" |
| + |
| +#include <utility> |
| + |
| +#include "webrtc/base/checks.h" |
| + |
| +namespace webrtc { |
| + |
| +FallbackDesktopCapturerWrapper::FallbackDesktopCapturerWrapper( |
| + std::unique_ptr<DesktopCapturer> main_capturer, |
| + std::unique_ptr<DesktopCapturer> secondary_capturer) |
| + : main_capturer_(std::move(main_capturer)), |
| + secondary_capturer_(std::move(secondary_capturer)) { |
| + RTC_DCHECK(main_capturer_); |
| + RTC_DCHECK(secondary_capturer_); |
| +} |
| + |
| +FallbackDesktopCapturerWrapper::~FallbackDesktopCapturerWrapper() = default; |
| + |
| +void FallbackDesktopCapturerWrapper::Start( |
| + DesktopCapturer::Callback* callback) { |
| + main_capturer_->Start(this); |
| + secondary_capturer_->Start(callback); |
|
Jamie
2017/02/15 18:43:48
Optional: Is Start ever an expensive operation? If
Hzj_jie
2017/02/15 21:20:36
No, Start() should be an extremely cheap operation
|
| + callback_ = callback; |
| +} |
| + |
| +void FallbackDesktopCapturerWrapper::SetSharedMemoryFactory( |
| + std::unique_ptr<SharedMemoryFactory> shared_memory_factory) { |
| + shared_memory_factory_ = std::move(shared_memory_factory); |
| + if (shared_memory_factory_) { |
| + main_capturer_->SetSharedMemoryFactory( |
| + SharedMemoryFactoryWrapper::Wrap(shared_memory_factory_)); |
| + secondary_capturer_->SetSharedMemoryFactory( |
| + SharedMemoryFactoryWrapper::Wrap(shared_memory_factory_)); |
| + } |
| +} |
| + |
| +void FallbackDesktopCapturerWrapper::CaptureFrame() { |
| + RTC_DCHECK(callback_); |
| + if (main_capturer_permanent_error_) { |
| + secondary_capturer_->CaptureFrame(); |
| + } else { |
| + main_capturer_->CaptureFrame(); |
| + } |
| +} |
| + |
| +void FallbackDesktopCapturerWrapper::SetExcludedWindow(WindowId window) { |
| + main_capturer_->SetExcludedWindow(window); |
| + secondary_capturer_->SetExcludedWindow(window); |
| +} |
| + |
| +bool FallbackDesktopCapturerWrapper::GetSourceList(SourceList* sources) { |
| + if (main_capturer_permanent_error_) { |
| + return secondary_capturer_->GetSourceList(sources); |
| + } else { |
| + return main_capturer_->GetSourceList(sources); |
| + } |
| +} |
| + |
| +bool FallbackDesktopCapturerWrapper::SelectSource(SourceId id) { |
| + if (main_capturer_permanent_error_) { |
| + return secondary_capturer_->SelectSource(id); |
| + } |
| + return main_capturer_->SelectSource(id) && |
| + secondary_capturer_->SelectSource(id); |
| +} |
| + |
| +bool FallbackDesktopCapturerWrapper::FocusOnSelectedSource() { |
| + if (main_capturer_permanent_error_) { |
| + return secondary_capturer_->FocusOnSelectedSource(); |
| + } |
| + return main_capturer_->FocusOnSelectedSource() && |
| + secondary_capturer_->FocusOnSelectedSource(); |
| +} |
| + |
| +void FallbackDesktopCapturerWrapper::OnCaptureResult( |
| + Result result, |
| + std::unique_ptr<DesktopFrame> frame) { |
| + RTC_DCHECK(callback_); |
| + if (result == Result::SUCCESS) { |
| + callback_->OnCaptureResult(result, std::move(frame)); |
| + return; |
| + } |
| + |
| + if (result == Result::ERROR_PERMANENT) { |
| + main_capturer_permanent_error_ = true; |
| + } |
| + secondary_capturer_->CaptureFrame(); |
| +} |
| + |
| +} // namespace webrtc |