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::FallbackDesktopCapturerWrapper( | |
| 20 std::unique_ptr<DesktopCapturer> main_capturer, | |
| 21 std::unique_ptr<DesktopCapturer> secondary_capturer) | |
| 22 : main_capturer_(std::move(main_capturer)), | |
| 23 secondary_capturer_(std::move(secondary_capturer)) { | |
| 24 RTC_DCHECK(main_capturer_); | |
| 25 RTC_DCHECK(secondary_capturer_); | |
| 26 } | |
| 27 | |
| 28 FallbackDesktopCapturerWrapper::~FallbackDesktopCapturerWrapper() = default; | |
| 29 | |
| 30 void FallbackDesktopCapturerWrapper::Start( | |
| 31 DesktopCapturer::Callback* callback) { | |
| 32 main_capturer_->Start(this); | |
| 33 secondary_capturer_->Start(callback); | |
| 34 callback_ = callback; | |
| 35 } | |
| 36 | |
| 37 void FallbackDesktopCapturerWrapper::SetSharedMemoryFactory( | |
| 38 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) { | |
| 39 if (shared_memory_factory) { | |
| 40 shared_memory_factory_.reset(new SharedMemoryFactoryWrapper( | |
| 41 std::move(shared_memory_factory))); | |
| 42 main_capturer_->SetSharedMemoryFactory(shared_memory_factory_->Wrap()); | |
| 43 secondary_capturer_->SetSharedMemoryFactory(shared_memory_factory_->Wrap()); | |
|
Sergey Ulanov
2017/02/15 23:08:43
There is a potential threading issue that comes wi
Hzj_jie
2017/02/16 01:57:07
Done.
| |
| 44 } else { | |
| 45 shared_memory_factory_.reset(); | |
| 46 main_capturer_->SetSharedMemoryFactory( | |
| 47 std::unique_ptr<SharedMemoryFactory>()); | |
| 48 secondary_capturer_->SetSharedMemoryFactory( | |
| 49 std::unique_ptr<SharedMemoryFactory>()); | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 void FallbackDesktopCapturerWrapper::CaptureFrame() { | |
| 54 RTC_DCHECK(callback_); | |
| 55 if (main_capturer_permanent_error_) { | |
| 56 secondary_capturer_->CaptureFrame(); | |
| 57 } else { | |
| 58 main_capturer_->CaptureFrame(); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 void FallbackDesktopCapturerWrapper::SetExcludedWindow(WindowId window) { | |
| 63 main_capturer_->SetExcludedWindow(window); | |
| 64 secondary_capturer_->SetExcludedWindow(window); | |
| 65 } | |
| 66 | |
| 67 bool FallbackDesktopCapturerWrapper::GetSourceList(SourceList* sources) { | |
| 68 if (main_capturer_permanent_error_) { | |
| 69 return secondary_capturer_->GetSourceList(sources); | |
| 70 } else { | |
|
Sergey Ulanov
2017/02/15 23:08:43
no else after return please.
Hzj_jie
2017/02/16 01:57:07
Done.
| |
| 71 return main_capturer_->GetSourceList(sources); | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 bool FallbackDesktopCapturerWrapper::SelectSource(SourceId id) { | |
| 76 if (main_capturer_permanent_error_) { | |
| 77 return secondary_capturer_->SelectSource(id); | |
| 78 } | |
| 79 return main_capturer_->SelectSource(id) && | |
| 80 secondary_capturer_->SelectSource(id); | |
| 81 } | |
| 82 | |
| 83 bool FallbackDesktopCapturerWrapper::FocusOnSelectedSource() { | |
| 84 if (main_capturer_permanent_error_) { | |
| 85 return secondary_capturer_->FocusOnSelectedSource(); | |
| 86 } | |
| 87 return main_capturer_->FocusOnSelectedSource() && | |
| 88 secondary_capturer_->FocusOnSelectedSource(); | |
|
Sergey Ulanov
2017/02/15 23:08:43
Do we need to call both capturers here?
Hzj_jie
2017/02/16 01:57:07
I think it should be simpler to always forward the
Sergey Ulanov
2017/02/16 19:14:17
This makes sense fro SelectSource(), but not for F
Hzj_jie
2017/02/16 21:31:28
Oh, got you. I almost forgot the functionality of
Sergey Ulanov
2017/02/17 20:16:23
I don't think it needs to be const. E.g. an X11 ca
Hzj_jie
2017/02/17 21:55:17
Done.
| |
| 89 } | |
| 90 | |
| 91 void FallbackDesktopCapturerWrapper::OnCaptureResult( | |
| 92 Result result, | |
| 93 std::unique_ptr<DesktopFrame> frame) { | |
| 94 RTC_DCHECK(callback_); | |
| 95 if (result == Result::SUCCESS) { | |
| 96 callback_->OnCaptureResult(result, std::move(frame)); | |
| 97 return; | |
| 98 } | |
| 99 | |
| 100 if (result == Result::ERROR_PERMANENT) { | |
|
Sergey Ulanov
2017/02/15 23:08:43
it's possible that OnCaptureResult() was called by
Hzj_jie
2017/02/16 01:57:07
No, this class does not handle the OnCaptureResult
| |
| 101 main_capturer_permanent_error_ = true; | |
| 102 } | |
| 103 secondary_capturer_->CaptureFrame(); | |
|
Sergey Ulanov
2017/02/15 23:08:43
this may loop indefinitely if secondary_capturer_
Hzj_jie
2017/02/16 01:57:07
Same as the reason above.
| |
| 104 } | |
| 105 | |
| 106 } // namespace webrtc | |
| OLD | NEW |