Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include "webrtc/modules/desktop_capture/fallback_desktop_capturer_wrapper.h" | |
| 12 | |
| 13 #include <utility> | |
| 14 | |
| 15 #include "webrtc/base/checks.h" | |
| 16 | |
| 17 namespace webrtc { | |
| 18 | |
| 19 FallbackDesktopCapturerWrapper::SharedMemoryFactoryWrapper:: | |
| 20 SharedMemoryFactoryWrapper(std::unique_ptr<SharedMemoryFactory> factory) { | |
| 21 RTC_DCHECK(factory); | |
| 22 owned_factory_ = std::move(factory); | |
| 23 shared_factory_ = owned_factory_.get(); | |
| 24 } | |
| 25 | |
| 26 FallbackDesktopCapturerWrapper::SharedMemoryFactoryWrapper:: | |
| 27 SharedMemoryFactoryWrapper(SharedMemoryFactory* factory) { | |
| 28 RTC_DCHECK(factory); | |
| 29 shared_factory_ = factory; | |
| 30 } | |
| 31 | |
| 32 FallbackDesktopCapturerWrapper::SharedMemoryFactoryWrapper:: | |
| 33 ~SharedMemoryFactoryWrapper() = default; | |
| 34 | |
| 35 std::unique_ptr<SharedMemoryFactory> | |
| 36 FallbackDesktopCapturerWrapper::SharedMemoryFactoryWrapper::Wrap() const { | |
| 37 return std::unique_ptr<SharedMemoryFactory>( | |
| 38 new SharedMemoryFactoryWrapper(owned_factory_.get())); | |
| 39 } | |
| 40 | |
| 41 std::unique_ptr<SharedMemory> | |
| 42 FallbackDesktopCapturerWrapper::SharedMemoryFactoryWrapper::CreateSharedMemory( | |
| 43 size_t size) { | |
| 44 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 45 return shared_factory_->CreateSharedMemory(size); | |
| 46 } | |
| 47 | |
| 48 FallbackDesktopCapturerWrapper::FallbackDesktopCapturerWrapper( | |
| 49 std::unique_ptr<DesktopCapturer> main_capturer, | |
| 50 std::unique_ptr<DesktopCapturer> secondary_capturer) | |
| 51 : main_capturer_(std::move(main_capturer)), | |
| 52 secondary_capturer_(std::move(secondary_capturer)) { | |
| 53 RTC_DCHECK(main_capturer_); | |
| 54 RTC_DCHECK(secondary_capturer_); | |
| 55 } | |
| 56 | |
| 57 FallbackDesktopCapturerWrapper::~FallbackDesktopCapturerWrapper() = default; | |
| 58 | |
| 59 void FallbackDesktopCapturerWrapper::Start( | |
| 60 DesktopCapturer::Callback* callback) { | |
| 61 main_capturer_->Start(this); | |
| 62 secondary_capturer_->Start(callback); | |
|
Sergey Ulanov
2017/02/16 19:14:17
Add a comment there to explain how the callbacks a
Hzj_jie
2017/02/16 21:31:28
Done.
| |
| 63 callback_ = callback; | |
| 64 } | |
| 65 | |
| 66 void FallbackDesktopCapturerWrapper::SetSharedMemoryFactory( | |
| 67 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) { | |
| 68 if (shared_memory_factory) { | |
| 69 shared_memory_factory_.reset( | |
| 70 new SharedMemoryFactoryWrapper(std::move(shared_memory_factory))); | |
| 71 main_capturer_->SetSharedMemoryFactory(shared_memory_factory_->Wrap()); | |
| 72 secondary_capturer_->SetSharedMemoryFactory(shared_memory_factory_->Wrap()); | |
| 73 } else { | |
| 74 shared_memory_factory_.reset(); | |
| 75 main_capturer_->SetSharedMemoryFactory( | |
| 76 std::unique_ptr<SharedMemoryFactory>()); | |
| 77 secondary_capturer_->SetSharedMemoryFactory( | |
| 78 std::unique_ptr<SharedMemoryFactory>()); | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 void FallbackDesktopCapturerWrapper::CaptureFrame() { | |
| 83 RTC_DCHECK(callback_); | |
| 84 if (main_capturer_permanent_error_) { | |
| 85 secondary_capturer_->CaptureFrame(); | |
| 86 } else { | |
| 87 main_capturer_->CaptureFrame(); | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 void FallbackDesktopCapturerWrapper::SetExcludedWindow(WindowId window) { | |
| 92 main_capturer_->SetExcludedWindow(window); | |
| 93 secondary_capturer_->SetExcludedWindow(window); | |
| 94 } | |
| 95 | |
| 96 bool FallbackDesktopCapturerWrapper::GetSourceList(SourceList* sources) { | |
| 97 if (main_capturer_permanent_error_) { | |
| 98 return secondary_capturer_->GetSourceList(sources); | |
| 99 } | |
| 100 return main_capturer_->GetSourceList(sources); | |
| 101 } | |
| 102 | |
| 103 bool FallbackDesktopCapturerWrapper::SelectSource(SourceId id) { | |
| 104 if (main_capturer_permanent_error_) { | |
| 105 return secondary_capturer_->SelectSource(id); | |
| 106 } | |
| 107 return main_capturer_->SelectSource(id) && | |
| 108 secondary_capturer_->SelectSource(id); | |
| 109 } | |
| 110 | |
| 111 bool FallbackDesktopCapturerWrapper::FocusOnSelectedSource() { | |
| 112 if (main_capturer_permanent_error_) { | |
| 113 return secondary_capturer_->FocusOnSelectedSource(); | |
| 114 } | |
| 115 return main_capturer_->FocusOnSelectedSource() && | |
| 116 secondary_capturer_->FocusOnSelectedSource(); | |
| 117 } | |
| 118 | |
| 119 void FallbackDesktopCapturerWrapper::OnCaptureResult( | |
| 120 Result result, | |
| 121 std::unique_ptr<DesktopFrame> frame) { | |
| 122 RTC_DCHECK(callback_); | |
| 123 if (result == Result::SUCCESS) { | |
| 124 callback_->OnCaptureResult(result, std::move(frame)); | |
| 125 return; | |
| 126 } | |
| 127 | |
| 128 if (result == Result::ERROR_PERMANENT) { | |
| 129 main_capturer_permanent_error_ = true; | |
| 130 } | |
| 131 secondary_capturer_->CaptureFrame(); | |
| 132 } | |
| 133 | |
| 134 } // namespace webrtc | |
| OLD | NEW |