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 "webrtc/modules/desktop_capture/screen_capturer.h" | 11 #include "webrtc/modules/desktop_capture/screen_capturer.h" |
12 | 12 |
13 #include <string.h> | 13 #include <string.h> |
14 | 14 |
15 #include <memory> | 15 #include <memory> |
16 #include <set> | 16 #include <set> |
17 | 17 |
18 #include <X11/extensions/Xdamage.h> | 18 #include <X11/extensions/Xdamage.h> |
19 #include <X11/extensions/Xfixes.h> | 19 #include <X11/extensions/Xfixes.h> |
20 #include <X11/Xlib.h> | 20 #include <X11/Xlib.h> |
21 #include <X11/Xutil.h> | 21 #include <X11/Xutil.h> |
22 | 22 |
23 #include "webrtc/base/checks.h" | 23 #include "webrtc/base/checks.h" |
24 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" | 24 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
25 #include "webrtc/modules/desktop_capture/desktop_frame.h" | 25 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
26 #include "webrtc/modules/desktop_capture/differ.h" | 26 #include "webrtc/modules/desktop_capture/differ.h" |
27 #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" | 27 #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" |
28 #include "webrtc/modules/desktop_capture/screen_capturer_helper.h" | 28 #include "webrtc/modules/desktop_capture/screen_capturer_helper.h" |
| 29 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" |
29 #include "webrtc/modules/desktop_capture/x11/x_server_pixel_buffer.h" | 30 #include "webrtc/modules/desktop_capture/x11/x_server_pixel_buffer.h" |
30 #include "webrtc/system_wrappers/include/logging.h" | 31 #include "webrtc/system_wrappers/include/logging.h" |
31 #include "webrtc/system_wrappers/include/tick_util.h" | 32 #include "webrtc/system_wrappers/include/tick_util.h" |
32 | 33 |
33 namespace webrtc { | 34 namespace webrtc { |
34 namespace { | 35 namespace { |
35 | 36 |
36 // A class to perform video frame capturing for Linux. | 37 // A class to perform video frame capturing for Linux. |
37 class ScreenCapturerLinux : public ScreenCapturer, | 38 class ScreenCapturerLinux : public ScreenCapturer, |
38 public SharedXDisplay::XEventHandler { | 39 public SharedXDisplay::XEventHandler { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 XserverRegion damage_region_; | 100 XserverRegion damage_region_; |
100 | 101 |
101 // Access to the X Server's pixel buffer. | 102 // Access to the X Server's pixel buffer. |
102 XServerPixelBuffer x_server_pixel_buffer_; | 103 XServerPixelBuffer x_server_pixel_buffer_; |
103 | 104 |
104 // A thread-safe list of invalid rectangles, and the size of the most | 105 // A thread-safe list of invalid rectangles, and the size of the most |
105 // recently captured screen. | 106 // recently captured screen. |
106 ScreenCapturerHelper helper_; | 107 ScreenCapturerHelper helper_; |
107 | 108 |
108 // Queue of the frames buffers. | 109 // Queue of the frames buffers. |
109 ScreenCaptureFrameQueue queue_; | 110 ScreenCaptureFrameQueue<SharedDesktopFrame> queue_; |
110 | 111 |
111 // Invalid region from the previous capture. This is used to synchronize the | 112 // Invalid region from the previous capture. This is used to synchronize the |
112 // current with the last buffer used. | 113 // current with the last buffer used. |
113 DesktopRegion last_invalid_region_; | 114 DesktopRegion last_invalid_region_; |
114 | 115 |
115 // |Differ| for use when polling for changes. | 116 // |Differ| for use when polling for changes. |
116 std::unique_ptr<Differ> differ_; | 117 std::unique_ptr<Differ> differ_; |
117 | 118 |
118 RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerLinux); | 119 RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerLinux); |
119 }; | 120 }; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 RTC_DCHECK(!callback_); | 231 RTC_DCHECK(!callback_); |
231 RTC_DCHECK(callback); | 232 RTC_DCHECK(callback); |
232 | 233 |
233 callback_ = callback; | 234 callback_ = callback; |
234 } | 235 } |
235 | 236 |
236 void ScreenCapturerLinux::Capture(const DesktopRegion& region) { | 237 void ScreenCapturerLinux::Capture(const DesktopRegion& region) { |
237 TickTime capture_start_time = TickTime::Now(); | 238 TickTime capture_start_time = TickTime::Now(); |
238 | 239 |
239 queue_.MoveToNextFrame(); | 240 queue_.MoveToNextFrame(); |
| 241 RTC_DCHECK(!queue_.current_frame() || !queue_.current_frame()->IsShared()); |
240 | 242 |
241 // Process XEvents for XDamage and cursor shape tracking. | 243 // Process XEvents for XDamage and cursor shape tracking. |
242 options_.x_display()->ProcessPendingXEvents(); | 244 options_.x_display()->ProcessPendingXEvents(); |
243 | 245 |
244 // ProcessPendingXEvents() may call ScreenConfigurationChanged() which | 246 // ProcessPendingXEvents() may call ScreenConfigurationChanged() which |
245 // reinitializes |x_server_pixel_buffer_|. Check if the pixel buffer is still | 247 // reinitializes |x_server_pixel_buffer_|. Check if the pixel buffer is still |
246 // in a good shape. | 248 // in a good shape. |
247 if (!x_server_pixel_buffer_.is_initialized()) { | 249 if (!x_server_pixel_buffer_.is_initialized()) { |
248 // We failed to initialize pixel buffer. | 250 // We failed to initialize pixel buffer. |
249 callback_->OnCaptureCompleted(NULL); | 251 callback_->OnCaptureCompleted(NULL); |
250 return; | 252 return; |
251 } | 253 } |
252 | 254 |
253 // If the current frame is from an older generation then allocate a new one. | 255 // If the current frame is from an older generation then allocate a new one. |
254 // Note that we can't reallocate other buffers at this point, since the caller | 256 // Note that we can't reallocate other buffers at this point, since the caller |
255 // may still be reading from them. | 257 // may still be reading from them. |
256 if (!queue_.current_frame()) { | 258 if (!queue_.current_frame()) { |
257 std::unique_ptr<DesktopFrame> frame( | 259 std::unique_ptr<DesktopFrame> frame( |
258 new BasicDesktopFrame(x_server_pixel_buffer_.window_size())); | 260 new BasicDesktopFrame(x_server_pixel_buffer_.window_size())); |
259 queue_.ReplaceCurrentFrame(frame.release()); | 261 queue_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(frame.release())); |
260 } | 262 } |
261 | 263 |
262 // Refresh the Differ helper used by CaptureFrame(), if needed. | 264 // Refresh the Differ helper used by CaptureFrame(), if needed. |
263 DesktopFrame* frame = queue_.current_frame(); | 265 DesktopFrame* frame = queue_.current_frame(); |
264 if (!use_damage_ && ( | 266 if (!use_damage_ && ( |
265 !differ_.get() || | 267 !differ_.get() || |
266 (differ_->width() != frame->size().width()) || | 268 (differ_->width() != frame->size().width()) || |
267 (differ_->height() != frame->size().height()) || | 269 (differ_->height() != frame->size().height()) || |
268 (differ_->bytes_per_row() != frame->stride()))) { | 270 (differ_->bytes_per_row() != frame->stride()))) { |
269 differ_.reset(new Differ(frame->size().width(), frame->size().height(), | 271 differ_.reset(new Differ(frame->size().width(), frame->size().height(), |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 if (!options.x_display()) | 438 if (!options.x_display()) |
437 return NULL; | 439 return NULL; |
438 | 440 |
439 std::unique_ptr<ScreenCapturerLinux> capturer(new ScreenCapturerLinux()); | 441 std::unique_ptr<ScreenCapturerLinux> capturer(new ScreenCapturerLinux()); |
440 if (!capturer->Init(options)) | 442 if (!capturer->Init(options)) |
441 capturer.reset(); | 443 capturer.reset(); |
442 return capturer.release(); | 444 return capturer.release(); |
443 } | 445 } |
444 | 446 |
445 } // namespace webrtc | 447 } // namespace webrtc |
OLD | NEW |