OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 return DxgiDuplicatorController::Instance()->IsSupported(); | 29 return DxgiDuplicatorController::Instance()->IsSupported(); |
30 } | 30 } |
31 | 31 |
32 // static | 32 // static |
33 bool ScreenCapturerWinDirectx::RetrieveD3dInfo(D3dInfo* info) { | 33 bool ScreenCapturerWinDirectx::RetrieveD3dInfo(D3dInfo* info) { |
34 // Forwards SupportedFeatureLevels() function call to | 34 // Forwards SupportedFeatureLevels() function call to |
35 // DxgiDuplicatorController. | 35 // DxgiDuplicatorController. |
36 return DxgiDuplicatorController::Instance()->RetrieveD3dInfo(info); | 36 return DxgiDuplicatorController::Instance()->RetrieveD3dInfo(info); |
37 } | 37 } |
38 | 38 |
39 ScreenCapturerWinDirectx::ScreenCapturerWinDirectx( | 39 ScreenCapturerWinDirectx::ScreenCapturerWinDirectx() |
40 const DesktopCaptureOptions& options) | 40 : controller_(DxgiDuplicatorController::GetReference()) {} |
41 : callback_(nullptr) {} | |
42 | 41 |
43 ScreenCapturerWinDirectx::~ScreenCapturerWinDirectx() {} | 42 ScreenCapturerWinDirectx::~ScreenCapturerWinDirectx() = default; |
| 43 |
| 44 bool ScreenCapturerWinDirectx::IsAvailable() const { |
| 45 return controller_->IsSupported(); |
| 46 } |
| 47 |
| 48 bool ScreenCapturerWinDirectx::GetD3dInfo(D3dInfo* info) const { |
| 49 return controller_->RetrieveD3dInfo(info); |
| 50 } |
44 | 51 |
45 void ScreenCapturerWinDirectx::Start(Callback* callback) { | 52 void ScreenCapturerWinDirectx::Start(Callback* callback) { |
46 RTC_DCHECK(!callback_); | 53 RTC_DCHECK(!callback_); |
47 RTC_DCHECK(callback); | 54 RTC_DCHECK(callback); |
48 | 55 |
49 callback_ = callback; | 56 callback_ = callback; |
50 } | 57 } |
51 | 58 |
52 void ScreenCapturerWinDirectx::SetSharedMemoryFactory( | 59 void ScreenCapturerWinDirectx::SetSharedMemoryFactory( |
53 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) { | 60 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) { |
54 shared_memory_factory_ = std::move(shared_memory_factory); | 61 shared_memory_factory_ = std::move(shared_memory_factory); |
55 } | 62 } |
56 | 63 |
57 void ScreenCapturerWinDirectx::CaptureFrame() { | 64 void ScreenCapturerWinDirectx::CaptureFrame() { |
58 RTC_DCHECK(callback_); | 65 RTC_DCHECK(callback_); |
59 | 66 |
60 int64_t capture_start_time_nanos = rtc::TimeNanos(); | 67 int64_t capture_start_time_nanos = rtc::TimeNanos(); |
61 | 68 |
62 frames_.MoveToNextFrame(); | 69 frames_.MoveToNextFrame(); |
63 if (!frames_.current_frame()) { | 70 if (!frames_.current_frame()) { |
64 frames_.ReplaceCurrentFrame( | 71 frames_.ReplaceCurrentFrame( |
65 rtc::MakeUnique<DxgiFrame>(shared_memory_factory_.get())); | 72 rtc::MakeUnique<DxgiFrame>(shared_memory_factory_.get())); |
66 } | 73 } |
67 | 74 |
68 DxgiDuplicatorController::Result result; | 75 DxgiDuplicatorController::Result result; |
69 if (current_screen_id_ == kFullDesktopScreenId) { | 76 if (current_screen_id_ == kFullDesktopScreenId) { |
70 result = DxgiDuplicatorController::Instance()->Duplicate( | 77 result = controller_->Duplicate(frames_.current_frame()); |
71 frames_.current_frame()); | |
72 } else { | 78 } else { |
73 result = DxgiDuplicatorController::Instance()->DuplicateMonitor( | 79 result = controller_->DuplicateMonitor( |
74 frames_.current_frame(), current_screen_id_); | 80 frames_.current_frame(), current_screen_id_); |
75 } | 81 } |
76 | 82 |
77 using DuplicateResult = DxgiDuplicatorController::Result; | 83 using DuplicateResult = DxgiDuplicatorController::Result; |
78 switch (result) { | 84 switch (result) { |
79 case DuplicateResult::FRAME_PREPARE_FAILED: { | 85 case DuplicateResult::FRAME_PREPARE_FAILED: { |
80 LOG(LS_ERROR) << "Failed to allocate a new DesktopFrame."; | 86 LOG(LS_ERROR) << "Failed to allocate a new DesktopFrame."; |
81 // This usually means we do not have enough memory or SharedMemoryFactory | 87 // This usually means we do not have enough memory or SharedMemoryFactory |
82 // cannot work correctly. | 88 // cannot work correctly. |
83 callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); | 89 callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); |
(...skipping 15 matching lines...) Expand all Loading... |
99 (rtc::TimeNanos() - capture_start_time_nanos) / | 105 (rtc::TimeNanos() - capture_start_time_nanos) / |
100 rtc::kNumNanosecsPerMillisec); | 106 rtc::kNumNanosecsPerMillisec); |
101 frame->set_capturer_id(DesktopCapturerId::kScreenCapturerWinDirectx); | 107 frame->set_capturer_id(DesktopCapturerId::kScreenCapturerWinDirectx); |
102 callback_->OnCaptureResult(Result::SUCCESS, std::move(frame)); | 108 callback_->OnCaptureResult(Result::SUCCESS, std::move(frame)); |
103 break; | 109 break; |
104 } | 110 } |
105 } | 111 } |
106 } | 112 } |
107 | 113 |
108 bool ScreenCapturerWinDirectx::GetSourceList(SourceList* sources) { | 114 bool ScreenCapturerWinDirectx::GetSourceList(SourceList* sources) { |
109 int screen_count = DxgiDuplicatorController::Instance()->ScreenCount(); | 115 int screen_count = controller_->ScreenCount(); |
110 for (int i = 0; i < screen_count; i++) { | 116 for (int i = 0; i < screen_count; i++) { |
111 sources->push_back({i}); | 117 sources->push_back({i}); |
112 } | 118 } |
113 return true; | 119 return true; |
114 } | 120 } |
115 | 121 |
116 bool ScreenCapturerWinDirectx::SelectSource(SourceId id) { | 122 bool ScreenCapturerWinDirectx::SelectSource(SourceId id) { |
117 if (id == current_screen_id_) { | 123 if (id == current_screen_id_) { |
118 return true; | 124 return true; |
119 } | 125 } |
120 | 126 |
121 if (id == kFullDesktopScreenId) { | 127 if (id == kFullDesktopScreenId) { |
122 current_screen_id_ = id; | 128 current_screen_id_ = id; |
123 return true; | 129 return true; |
124 } | 130 } |
125 | 131 |
126 int screen_count = DxgiDuplicatorController::Instance()->ScreenCount(); | 132 int screen_count = controller_->ScreenCount(); |
127 if (id >= 0 && id < screen_count) { | 133 if (id >= 0 && id < screen_count) { |
128 current_screen_id_ = id; | 134 current_screen_id_ = id; |
129 return true; | 135 return true; |
130 } | 136 } |
131 return false; | 137 return false; |
132 } | 138 } |
133 | 139 |
134 } // namespace webrtc | 140 } // namespace webrtc |
OLD | NEW |