Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: webrtc/modules/desktop_capture/fallback_desktop_capturer_wrapper.cc

Issue 2697453002: [DesktopCapturer] FallbackDesktopCapturerWrapper and its tests (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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);
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
34 callback_ = callback;
35 }
36
37 void FallbackDesktopCapturerWrapper::SetSharedMemoryFactory(
38 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) {
39 shared_memory_factory_ = std::move(shared_memory_factory);
40 if (shared_memory_factory_) {
41 main_capturer_->SetSharedMemoryFactory(
42 SharedMemoryFactoryWrapper::Wrap(shared_memory_factory_));
43 secondary_capturer_->SetSharedMemoryFactory(
44 SharedMemoryFactoryWrapper::Wrap(shared_memory_factory_));
45 }
46 }
47
48 void FallbackDesktopCapturerWrapper::CaptureFrame() {
49 RTC_DCHECK(callback_);
50 if (main_capturer_permanent_error_) {
51 secondary_capturer_->CaptureFrame();
52 } else {
53 main_capturer_->CaptureFrame();
54 }
55 }
56
57 void FallbackDesktopCapturerWrapper::SetExcludedWindow(WindowId window) {
58 main_capturer_->SetExcludedWindow(window);
59 secondary_capturer_->SetExcludedWindow(window);
60 }
61
62 bool FallbackDesktopCapturerWrapper::GetSourceList(SourceList* sources) {
63 if (main_capturer_permanent_error_) {
64 return secondary_capturer_->GetSourceList(sources);
65 } else {
66 return main_capturer_->GetSourceList(sources);
67 }
68 }
69
70 bool FallbackDesktopCapturerWrapper::SelectSource(SourceId id) {
71 if (main_capturer_permanent_error_) {
72 return secondary_capturer_->SelectSource(id);
73 }
74 return main_capturer_->SelectSource(id) &&
75 secondary_capturer_->SelectSource(id);
76 }
77
78 bool FallbackDesktopCapturerWrapper::FocusOnSelectedSource() {
79 if (main_capturer_permanent_error_) {
80 return secondary_capturer_->FocusOnSelectedSource();
81 }
82 return main_capturer_->FocusOnSelectedSource() &&
83 secondary_capturer_->FocusOnSelectedSource();
84 }
85
86 void FallbackDesktopCapturerWrapper::OnCaptureResult(
87 Result result,
88 std::unique_ptr<DesktopFrame> frame) {
89 RTC_DCHECK(callback_);
90 if (result == Result::SUCCESS) {
91 callback_->OnCaptureResult(result, std::move(frame));
92 return;
93 }
94
95 if (result == Result::ERROR_PERMANENT) {
96 main_capturer_permanent_error_ = true;
97 }
98 secondary_capturer_->CaptureFrame();
99 }
100
101 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698