OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 <assert.h> | 11 #include <assert.h> |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 | 14 |
15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
16 #include "webrtc/base/constructormagic.h" | 16 #include "webrtc/base/constructormagic.h" |
17 #include "webrtc/base/win32.h" | 17 #include "webrtc/base/win32.h" |
18 #include "webrtc/modules/desktop_capture/desktop_capturer.h" | 18 #include "webrtc/modules/desktop_capture/desktop_capturer.h" |
19 #include "webrtc/modules/desktop_capture/desktop_frame_win.h" | 19 #include "webrtc/modules/desktop_capture/desktop_frame_win.h" |
20 #include "webrtc/modules/desktop_capture/win/window_capture_utils.h" | 20 #include "webrtc/modules/desktop_capture/win/window_capture_utils.h" |
21 #include "webrtc/system_wrappers/include/logging.h" | |
22 | 21 |
23 namespace webrtc { | 22 namespace webrtc { |
24 | 23 |
25 namespace { | 24 namespace { |
26 | 25 |
27 BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) { | 26 BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) { |
28 DesktopCapturer::SourceList* list = | 27 DesktopCapturer::SourceList* list = |
29 reinterpret_cast<DesktopCapturer::SourceList*>(param); | 28 reinterpret_cast<DesktopCapturer::SourceList*>(param); |
30 | 29 |
31 // Skip windows that are invisible, minimized, have no title, or are owned, | 30 // Skip windows that are invisible, minimized, have no title, or are owned, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 | 152 |
154 void WindowCapturerWin::Start(Callback* callback) { | 153 void WindowCapturerWin::Start(Callback* callback) { |
155 assert(!callback_); | 154 assert(!callback_); |
156 assert(callback); | 155 assert(callback); |
157 | 156 |
158 callback_ = callback; | 157 callback_ = callback; |
159 } | 158 } |
160 | 159 |
161 void WindowCapturerWin::CaptureFrame() { | 160 void WindowCapturerWin::CaptureFrame() { |
162 if (!window_) { | 161 if (!window_) { |
163 LOG(LS_ERROR) << "Window hasn't been selected: " << GetLastError(); | |
164 callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); | 162 callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); |
165 return; | 163 return; |
166 } | 164 } |
167 | 165 |
168 // Stop capturing if the window has been closed. | 166 // Stop capturing if the window has been closed. |
169 if (!IsWindow(window_)) { | 167 if (!IsWindow(window_)) { |
170 callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); | 168 callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); |
171 return; | 169 return; |
172 } | 170 } |
173 | 171 |
174 // Return a 1x1 black frame if the window is minimized or invisible, to match | 172 // Return a 1x1 black frame if the window is minimized or invisible, to match |
175 // behavior on mace. Window can be temporarily invisible during the | 173 // behavior on mace. Window can be temporarily invisible during the |
176 // transition of full screen mode on/off. | 174 // transition of full screen mode on/off. |
177 if (IsIconic(window_) || !IsWindowVisible(window_)) { | 175 if (IsIconic(window_) || !IsWindowVisible(window_)) { |
178 std::unique_ptr<DesktopFrame> frame( | 176 std::unique_ptr<DesktopFrame> frame( |
179 new BasicDesktopFrame(DesktopSize(1, 1))); | 177 new BasicDesktopFrame(DesktopSize(1, 1))); |
180 memset(frame->data(), 0, frame->stride() * frame->size().height()); | 178 memset(frame->data(), 0, frame->stride() * frame->size().height()); |
181 | 179 |
182 previous_size_ = frame->size(); | 180 previous_size_ = frame->size(); |
183 window_size_map_[window_] = previous_size_; | 181 window_size_map_[window_] = previous_size_; |
184 callback_->OnCaptureResult(Result::SUCCESS, std::move(frame)); | 182 callback_->OnCaptureResult(Result::SUCCESS, std::move(frame)); |
185 return; | 183 return; |
186 } | 184 } |
187 | 185 |
188 DesktopRect original_rect; | 186 DesktopRect original_rect; |
189 DesktopRect cropped_rect; | 187 DesktopRect cropped_rect; |
190 if (!GetCroppedWindowRect(window_, &cropped_rect, &original_rect)) { | 188 if (!GetCroppedWindowRect(window_, &cropped_rect, &original_rect)) { |
191 LOG(LS_WARNING) << "Failed to get window info: " << GetLastError(); | |
192 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); | 189 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); |
193 return; | 190 return; |
194 } | 191 } |
195 | 192 |
196 HDC window_dc = GetWindowDC(window_); | 193 HDC window_dc = GetWindowDC(window_); |
197 if (!window_dc) { | 194 if (!window_dc) { |
198 LOG(LS_WARNING) << "Failed to get window DC: " << GetLastError(); | |
199 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); | 195 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); |
200 return; | 196 return; |
201 } | 197 } |
202 | 198 |
203 std::unique_ptr<DesktopFrameWin> frame( | 199 std::unique_ptr<DesktopFrameWin> frame( |
204 DesktopFrameWin::Create(cropped_rect.size(), nullptr, window_dc)); | 200 DesktopFrameWin::Create(cropped_rect.size(), nullptr, window_dc)); |
205 if (!frame.get()) { | 201 if (!frame.get()) { |
206 ReleaseDC(window_, window_dc); | 202 ReleaseDC(window_, window_dc); |
207 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); | 203 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); |
208 return; | 204 return; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 DeleteDC(mem_dc); | 242 DeleteDC(mem_dc); |
247 ReleaseDC(window_, window_dc); | 243 ReleaseDC(window_, window_dc); |
248 | 244 |
249 previous_size_ = frame->size(); | 245 previous_size_ = frame->size(); |
250 window_size_map_[window_] = previous_size_; | 246 window_size_map_[window_] = previous_size_; |
251 | 247 |
252 frame->mutable_updated_region()->SetRect( | 248 frame->mutable_updated_region()->SetRect( |
253 DesktopRect::MakeSize(frame->size())); | 249 DesktopRect::MakeSize(frame->size())); |
254 | 250 |
255 if (!result) { | 251 if (!result) { |
256 LOG(LS_ERROR) << "Both PrintWindow() and BitBlt() failed."; | |
257 frame.reset(); | 252 frame.reset(); |
258 } | 253 } |
259 | 254 |
260 callback_->OnCaptureResult(Result::SUCCESS, std::move(frame)); | 255 callback_->OnCaptureResult(Result::SUCCESS, std::move(frame)); |
261 } | 256 } |
262 | 257 |
263 } // namespace | 258 } // namespace |
264 | 259 |
265 // static | 260 // static |
266 std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawWindowCapturer( | 261 std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawWindowCapturer( |
267 const DesktopCaptureOptions& options) { | 262 const DesktopCaptureOptions& options) { |
268 return std::unique_ptr<DesktopCapturer>(new WindowCapturerWin()); | 263 return std::unique_ptr<DesktopCapturer>(new WindowCapturerWin()); |
269 } | 264 } |
270 | 265 |
271 } // namespace webrtc | 266 } // namespace webrtc |
OLD | NEW |