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

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

Issue 2468753002: Add CreateWindowCapturer() and CreateScreenCapturer() in DesktopCapturer (Closed)
Patch Set: Build break without X11 Created 4 years, 1 month 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
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
11 #include "webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.h" 11 #include "webrtc/modules/desktop_capture/desktop_capturer_differ_wrapper.h"
12 12
13 #include <string.h> 13 #include <string.h>
14 14
15 #include <algorithm> 15 #include <algorithm>
16 #include <utility> 16 #include <utility>
17 17
18 #include "webrtc/base/checks.h" 18 #include "webrtc/base/checks.h"
19 #include "webrtc/base/timeutils.h" 19 #include "webrtc/base/timeutils.h"
20 #include "webrtc/modules/desktop_capture/desktop_geometry.h" 20 #include "webrtc/modules/desktop_capture/desktop_geometry.h"
21 #include "webrtc/modules/desktop_capture/differ_block.h" 21 #include "webrtc/modules/desktop_capture/differ_block.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // it separatedly. 70 // it separatedly.
71 for (int x = 0; x < block_count; x++) { 71 for (int x = 0; x < block_count; x++) {
72 if (BlockDifference(old_buffer, new_buffer, height, stride)) { 72 if (BlockDifference(old_buffer, new_buffer, height, stride)) {
73 if (first_dirty_x_block == -1) { 73 if (first_dirty_x_block == -1) {
74 // This is the first dirty block in a continuous dirty area. 74 // This is the first dirty block in a continuous dirty area.
75 first_dirty_x_block = x; 75 first_dirty_x_block = x;
76 } 76 }
77 } else if (first_dirty_x_block != -1) { 77 } else if (first_dirty_x_block != -1) {
78 // The block on the left is the last dirty block in a continuous 78 // The block on the left is the last dirty block in a continuous
79 // dirty area. 79 // dirty area.
80 output->AddRect(DesktopRect::MakeLTRB( 80 output->AddRect(
81 first_dirty_x_block * kBlockSize + left, top, 81 DesktopRect::MakeLTRB(first_dirty_x_block * kBlockSize + left, top,
82 x * kBlockSize + left, bottom)); 82 x * kBlockSize + left, bottom));
83 first_dirty_x_block = -1; 83 first_dirty_x_block = -1;
84 } 84 }
85 old_buffer += block_x_offset; 85 old_buffer += block_x_offset;
86 new_buffer += block_x_offset; 86 new_buffer += block_x_offset;
87 } 87 }
88 88
89 bool last_block_diff; 89 bool last_block_diff;
90 if (last_block_width < kBlockSize) { 90 if (last_block_width < kBlockSize) {
91 // The last one is a partial vector. 91 // The last one is a partial vector.
92 last_block_diff = PartialBlockDifference( 92 last_block_diff = PartialBlockDifference(old_buffer, new_buffer,
93 old_buffer, new_buffer, last_block_width, height, stride); 93 last_block_width, height, stride);
94 } else { 94 } else {
95 last_block_diff = 95 last_block_diff = BlockDifference(old_buffer, new_buffer, height, stride);
96 BlockDifference(old_buffer, new_buffer, height, stride);
97 } 96 }
98 if (last_block_diff) { 97 if (last_block_diff) {
99 if (first_dirty_x_block == -1) { 98 if (first_dirty_x_block == -1) {
100 first_dirty_x_block = block_count; 99 first_dirty_x_block = block_count;
101 } 100 }
101 output->AddRect(DesktopRect::MakeLTRB(
102 first_dirty_x_block * kBlockSize + left, top, right, bottom));
103 } else if (first_dirty_x_block != -1) {
102 output->AddRect( 104 output->AddRect(
103 DesktopRect::MakeLTRB(first_dirty_x_block * kBlockSize + left, 105 DesktopRect::MakeLTRB(first_dirty_x_block * kBlockSize + left, top,
104 top, right, bottom)); 106 block_count * kBlockSize + left, bottom));
105 } else if (first_dirty_x_block != -1) {
106 output->AddRect(DesktopRect::MakeLTRB(
107 first_dirty_x_block * kBlockSize + left, top,
108 block_count * kBlockSize + left, bottom));
109 } 107 }
110 } 108 }
111 109
112 // Compares |rect| area in |old_frame| and |new_frame|, and outputs dirty 110 // Compares |rect| area in |old_frame| and |new_frame|, and outputs dirty
113 // regions into |output|. 111 // regions into |output|.
114 void CompareFrames(const DesktopFrame& old_frame, 112 void CompareFrames(const DesktopFrame& old_frame,
115 const DesktopFrame& new_frame, 113 const DesktopFrame& new_frame,
116 DesktopRect rect, 114 DesktopRect rect,
117 DesktopRegion* const output) { 115 DesktopRegion* const output) {
118 RTC_DCHECK(old_frame.size().equals(new_frame.size())); 116 RTC_DCHECK(old_frame.size().equals(new_frame.size()));
119 RTC_DCHECK_EQ(old_frame.stride(), new_frame.stride()); 117 RTC_DCHECK_EQ(old_frame.stride(), new_frame.stride());
120 rect.IntersectWith(DesktopRect::MakeSize(old_frame.size())); 118 rect.IntersectWith(DesktopRect::MakeSize(old_frame.size()));
121 119
122 const int y_block_count = (rect.height() - 1) / kBlockSize; 120 const int y_block_count = (rect.height() - 1) / kBlockSize;
123 const int last_y_block_height = rect.height() - y_block_count * kBlockSize; 121 const int last_y_block_height = rect.height() - y_block_count * kBlockSize;
124 // Offset from the start of one block-row to the next. 122 // Offset from the start of one block-row to the next.
125 const int block_y_stride = old_frame.stride() * kBlockSize; 123 const int block_y_stride = old_frame.stride() * kBlockSize;
126 const uint8_t* prev_block_row_start = 124 const uint8_t* prev_block_row_start =
127 old_frame.GetFrameDataAtPos(rect.top_left()); 125 old_frame.GetFrameDataAtPos(rect.top_left());
128 const uint8_t* curr_block_row_start = 126 const uint8_t* curr_block_row_start =
129 new_frame.GetFrameDataAtPos(rect.top_left()); 127 new_frame.GetFrameDataAtPos(rect.top_left());
130 128
131 int top = rect.top(); 129 int top = rect.top();
132 // The last row may have a different height, so we handle it separately. 130 // The last row may have a different height, so we handle it separately.
133 for (int y = 0; y < y_block_count; y++) { 131 for (int y = 0; y < y_block_count; y++) {
134 CompareRow(prev_block_row_start, curr_block_row_start, rect.left(), 132 CompareRow(prev_block_row_start, curr_block_row_start, rect.left(),
135 rect.right(), top, top + kBlockSize, 133 rect.right(), top, top + kBlockSize, old_frame.stride(), output);
136 old_frame.stride(), output);
137 top += kBlockSize; 134 top += kBlockSize;
138 prev_block_row_start += block_y_stride; 135 prev_block_row_start += block_y_stride;
139 curr_block_row_start += block_y_stride; 136 curr_block_row_start += block_y_stride;
140 } 137 }
141 CompareRow(prev_block_row_start, curr_block_row_start, rect.left(), 138 CompareRow(prev_block_row_start, curr_block_row_start, rect.left(),
142 rect.right(), top, top + last_y_block_height, 139 rect.right(), top, top + last_y_block_height, old_frame.stride(),
143 old_frame.stride(), output); 140 output);
144 } 141 }
145 142
146 } // namespace 143 } // namespace
147 144
148 ScreenCapturerDifferWrapper::ScreenCapturerDifferWrapper( 145 DesktopCapturerDifferWrapper::DesktopCapturerDifferWrapper(
149 std::unique_ptr<ScreenCapturer> base_capturer) 146 std::unique_ptr<DesktopCapturer> base_capturer)
150 : base_capturer_(std::move(base_capturer)) { 147 : base_capturer_(std::move(base_capturer)) {
151 RTC_DCHECK(base_capturer_); 148 RTC_DCHECK(base_capturer_);
152 } 149 }
153 150
154 ScreenCapturerDifferWrapper::~ScreenCapturerDifferWrapper() {} 151 DesktopCapturerDifferWrapper::~DesktopCapturerDifferWrapper() {}
155 152
156 void ScreenCapturerDifferWrapper::Start(DesktopCapturer::Callback* callback) { 153 void DesktopCapturerDifferWrapper::Start(DesktopCapturer::Callback* callback) {
157 callback_ = callback; 154 callback_ = callback;
158 base_capturer_->Start(this); 155 base_capturer_->Start(this);
159 } 156 }
160 157
161 void ScreenCapturerDifferWrapper::SetSharedMemoryFactory( 158 void DesktopCapturerDifferWrapper::SetSharedMemoryFactory(
162 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) { 159 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) {
163 base_capturer_->SetSharedMemoryFactory(std::move(shared_memory_factory)); 160 base_capturer_->SetSharedMemoryFactory(std::move(shared_memory_factory));
164 } 161 }
165 162
166 void ScreenCapturerDifferWrapper::CaptureFrame() { 163 void DesktopCapturerDifferWrapper::CaptureFrame() {
167 base_capturer_->CaptureFrame(); 164 base_capturer_->CaptureFrame();
168 } 165 }
169 166
170 bool ScreenCapturerDifferWrapper::GetScreenList(ScreenList* screens) { 167 void DesktopCapturerDifferWrapper::SetExcludedWindow(WindowId window) {
171 return base_capturer_->GetScreenList(screens); 168 base_capturer_->SetExcludedWindow(window);
172 } 169 }
173 170
174 bool ScreenCapturerDifferWrapper::SelectScreen(ScreenId id) { 171 bool DesktopCapturerDifferWrapper::GetSourceList(SourceList* sources) {
175 return base_capturer_->SelectScreen(id); 172 return base_capturer_->GetSourceList(sources);
176 } 173 }
177 174
178 void ScreenCapturerDifferWrapper::OnCaptureResult( 175 bool DesktopCapturerDifferWrapper::SelectSource(SourceId id) {
176 return base_capturer_->SelectSource(id);
177 }
178
179 bool DesktopCapturerDifferWrapper::FocusOnSelectedSource() {
180 return base_capturer_->FocusOnSelectedSource();
181 }
182
183 void DesktopCapturerDifferWrapper::OnCaptureResult(
179 Result result, 184 Result result,
180 std::unique_ptr<DesktopFrame> input_frame) { 185 std::unique_ptr<DesktopFrame> input_frame) {
181 int64_t start_time_nanos = rtc::TimeNanos(); 186 int64_t start_time_nanos = rtc::TimeNanos();
182 if (!input_frame) { 187 if (!input_frame) {
183 callback_->OnCaptureResult(result, nullptr); 188 callback_->OnCaptureResult(result, nullptr);
184 return; 189 return;
185 } 190 }
186 RTC_DCHECK(result == Result::SUCCESS); 191 RTC_DCHECK(result == Result::SUCCESS);
187 192
188 std::unique_ptr<SharedDesktopFrame> frame = 193 std::unique_ptr<SharedDesktopFrame> frame =
189 SharedDesktopFrame::Wrap(std::move(input_frame)); 194 SharedDesktopFrame::Wrap(std::move(input_frame));
190 if (last_frame_ && 195 if (last_frame_ && (last_frame_->size().width() != frame->size().width() ||
191 (last_frame_->size().width() != frame->size().width() || 196 last_frame_->size().height() != frame->size().height() ||
192 last_frame_->size().height() != frame->size().height() || 197 last_frame_->stride() != frame->stride())) {
193 last_frame_->stride() != frame->stride())) {
194 last_frame_.reset(); 198 last_frame_.reset();
195 } 199 }
196 200
197 if (last_frame_) { 201 if (last_frame_) {
198 DesktopRegion hints; 202 DesktopRegion hints;
199 hints.Swap(frame->GetUnderlyingFrame()->mutable_updated_region()); 203 hints.Swap(frame->GetUnderlyingFrame()->mutable_updated_region());
200 for (DesktopRegion::Iterator it(hints); !it.IsAtEnd(); it.Advance()) { 204 for (DesktopRegion::Iterator it(hints); !it.IsAtEnd(); it.Advance()) {
201 CompareFrames(*last_frame_, *frame, it.rect(), 205 CompareFrames(*last_frame_, *frame, it.rect(),
202 frame->mutable_updated_region()); 206 frame->mutable_updated_region());
203 } 207 }
204 } else { 208 } else {
205 frame->mutable_updated_region()->SetRect( 209 frame->mutable_updated_region()->SetRect(
206 DesktopRect::MakeSize(frame->size())); 210 DesktopRect::MakeSize(frame->size()));
207 } 211 }
208 last_frame_ = frame->Share(); 212 last_frame_ = frame->Share();
209 213
210 frame->set_capture_time_ms(frame->GetUnderlyingFrame()->capture_time_ms() + 214 frame->set_capture_time_ms(frame->GetUnderlyingFrame()->capture_time_ms() +
211 (rtc::TimeNanos() - start_time_nanos) / 215 (rtc::TimeNanos() - start_time_nanos) /
212 rtc::kNumNanosecsPerMillisec); 216 rtc::kNumNanosecsPerMillisec);
213 callback_->OnCaptureResult(result, std::move(frame)); 217 callback_->OnCaptureResult(result, std::move(frame));
214 } 218 }
215 219
216 } // namespace webrtc 220 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698