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" | |
12 | |
13 #include <string.h> | 11 #include <string.h> |
14 | 12 |
15 #include <memory> | 13 #include <memory> |
16 #include <set> | 14 #include <set> |
17 #include <utility> | 15 #include <utility> |
18 | 16 |
19 #include <X11/extensions/Xdamage.h> | 17 #include <X11/extensions/Xdamage.h> |
20 #include <X11/extensions/Xfixes.h> | 18 #include <X11/extensions/Xfixes.h> |
21 #include <X11/Xlib.h> | 19 #include <X11/Xlib.h> |
22 #include <X11/Xutil.h> | 20 #include <X11/Xutil.h> |
23 | 21 |
24 #include "webrtc/base/checks.h" | 22 #include "webrtc/base/checks.h" |
25 #include "webrtc/base/constructormagic.h" | 23 #include "webrtc/base/constructormagic.h" |
26 #include "webrtc/base/timeutils.h" | 24 #include "webrtc/base/timeutils.h" |
| 25 #include "webrtc/modules/desktop_capture/desktop_capturer.h" |
27 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" | 26 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
28 #include "webrtc/modules/desktop_capture/desktop_frame.h" | 27 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
29 #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" | 28 #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" |
30 #include "webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.h" | |
31 #include "webrtc/modules/desktop_capture/screen_capturer_helper.h" | 29 #include "webrtc/modules/desktop_capture/screen_capturer_helper.h" |
32 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" | 30 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" |
33 #include "webrtc/modules/desktop_capture/x11/x_server_pixel_buffer.h" | 31 #include "webrtc/modules/desktop_capture/x11/x_server_pixel_buffer.h" |
34 #include "webrtc/system_wrappers/include/logging.h" | 32 #include "webrtc/system_wrappers/include/logging.h" |
35 | 33 |
36 namespace webrtc { | 34 namespace webrtc { |
37 namespace { | 35 namespace { |
38 | 36 |
39 // A class to perform video frame capturing for Linux. | 37 // A class to perform video frame capturing for Linux. |
40 // | 38 // |
41 // If XDamage is used, this class sets DesktopFrame::updated_region() according | 39 // If XDamage is used, this class sets DesktopFrame::updated_region() according |
42 // to the areas reported by XDamage. Otherwise this class does not detect | 40 // to the areas reported by XDamage. Otherwise this class does not detect |
43 // DesktopFrame::updated_region(), the field is always set to the entire frame | 41 // DesktopFrame::updated_region(), the field is always set to the entire frame |
44 // rectangle. ScreenCapturerDifferWrapper should be used if that functionality | 42 // rectangle. ScreenCapturerDifferWrapper should be used if that functionality |
45 // is necessary. | 43 // is necessary. |
46 class ScreenCapturerLinux : public ScreenCapturer, | 44 class ScreenCapturerLinux : public DesktopCapturer, |
47 public SharedXDisplay::XEventHandler { | 45 public SharedXDisplay::XEventHandler { |
48 public: | 46 public: |
49 ScreenCapturerLinux(); | 47 ScreenCapturerLinux(); |
50 ~ScreenCapturerLinux() override; | 48 ~ScreenCapturerLinux() override; |
51 | 49 |
52 // TODO(ajwong): Do we really want this to be synchronous? | 50 // TODO(ajwong): Do we really want this to be synchronous? |
53 bool Init(const DesktopCaptureOptions& options); | 51 bool Init(const DesktopCaptureOptions& options); |
54 | 52 |
55 // DesktopCapturer interface. | 53 // DesktopCapturer interface. |
56 void Start(Callback* delegate) override; | 54 void Start(Callback* delegate) override; |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 if (damage_region_) { | 395 if (damage_region_) { |
398 XFixesDestroyRegion(display(), damage_region_); | 396 XFixesDestroyRegion(display(), damage_region_); |
399 damage_region_ = 0; | 397 damage_region_ = 0; |
400 } | 398 } |
401 } | 399 } |
402 } | 400 } |
403 | 401 |
404 } // namespace | 402 } // namespace |
405 | 403 |
406 // static | 404 // static |
407 ScreenCapturer* ScreenCapturer::Create(const DesktopCaptureOptions& options) { | |
408 if (!options.x_display()) | |
409 return nullptr; | |
410 | |
411 std::unique_ptr<ScreenCapturer> capturer(new ScreenCapturerLinux()); | |
412 if (!static_cast<ScreenCapturerLinux*>(capturer.get())->Init(options)) { | |
413 return nullptr; | |
414 } | |
415 | |
416 if (options.detect_updated_region()) { | |
417 capturer.reset(new ScreenCapturerDifferWrapper(std::move(capturer))); | |
418 } | |
419 | |
420 return capturer.release(); | |
421 } | |
422 | |
423 // static | |
424 std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawScreenCapturer( | 405 std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawScreenCapturer( |
425 const DesktopCaptureOptions& options) { | 406 const DesktopCaptureOptions& options) { |
426 if (!options.x_display()) | 407 if (!options.x_display()) |
427 return nullptr; | 408 return nullptr; |
428 | 409 |
429 std::unique_ptr<ScreenCapturer> capturer(new ScreenCapturerLinux()); | 410 std::unique_ptr<ScreenCapturerLinux> capturer(new ScreenCapturerLinux()); |
430 if (!static_cast<ScreenCapturerLinux*>(capturer.get())->Init(options)) { | 411 if (!capturer.get()->Init(options)) { |
431 return nullptr; | 412 return nullptr; |
432 } | 413 } |
433 | 414 |
434 return capturer; | 415 return capturer; |
435 } | 416 } |
436 | 417 |
437 } // namespace webrtc | 418 } // namespace webrtc |
OLD | NEW |