sergeyu@chromium.org | 6c82a7e | 2013-06-04 18:51:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_H_ |
| 12 | #define WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_H_ |
| 13 | |
jiayl@webrtc.org | a2c2654 | 2014-01-14 18:26:37 +0000 | [diff] [blame] | 14 | #include <vector> |
| 15 | |
| 16 | #include "webrtc/modules/desktop_capture/desktop_capture_types.h" |
sergeyu@chromium.org | 6c82a7e | 2013-06-04 18:51:23 +0000 | [diff] [blame] | 17 | #include "webrtc/modules/desktop_capture/desktop_capturer.h" |
| 18 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
| 19 | #include "webrtc/typedefs.h" |
| 20 | |
| 21 | namespace webrtc { |
| 22 | |
sergeyu@chromium.org | 91685dc | 2013-10-12 22:40:05 +0000 | [diff] [blame] | 23 | class DesktopCaptureOptions; |
sergeyu@chromium.org | 6c82a7e | 2013-06-04 18:51:23 +0000 | [diff] [blame] | 24 | struct MouseCursorShape; |
| 25 | |
| 26 | // Class used to capture video frames asynchronously. |
| 27 | // |
| 28 | // The full capture sequence is as follows: |
| 29 | // |
| 30 | // (1) Start |
| 31 | // This is when pre-capture steps are executed, such as flagging the |
| 32 | // display to prevent it from sleeping during a session. |
| 33 | // |
| 34 | // (2) CaptureFrame |
| 35 | // This is where the bits for the invalid rects are packaged up and sent |
| 36 | // to the encoder. |
| 37 | // A screen capture is performed if needed. For example, Windows requires |
| 38 | // a capture to calculate the diff from the previous screen, whereas the |
| 39 | // Mac version does not. |
| 40 | // |
| 41 | // Implementation has to ensure the following guarantees: |
| 42 | // 1. Double buffering |
| 43 | // Since data can be read while another capture action is happening. |
| 44 | class ScreenCapturer : public DesktopCapturer { |
| 45 | public: |
jiayl@webrtc.org | a2c2654 | 2014-01-14 18:26:37 +0000 | [diff] [blame] | 46 | // Use a struct to represent a screen although it has only an id for now, |
| 47 | // because we may want to add more fields (e.g. description) in the future. |
| 48 | struct Screen { |
| 49 | ScreenId id; |
| 50 | }; |
| 51 | typedef std::vector<Screen> ScreenList; |
| 52 | |
sergeyu@chromium.org | 6c82a7e | 2013-06-04 18:51:23 +0000 | [diff] [blame] | 53 | // Provides callbacks used by the capturer to pass captured video frames and |
| 54 | // mouse cursor shapes to the processing pipeline. |
| 55 | // |
| 56 | // TODO(sergeyu): Move cursor shape capturing to a separate class because it's |
| 57 | // unrelated. |
| 58 | class MouseShapeObserver { |
| 59 | public: |
| 60 | // Called when the cursor shape has changed. Must take ownership of |
| 61 | // |cursor_shape|. |
| 62 | virtual void OnCursorShapeChanged(MouseCursorShape* cursor_shape) = 0; |
| 63 | |
| 64 | protected: |
| 65 | virtual ~MouseShapeObserver() {} |
| 66 | }; |
| 67 | |
| 68 | virtual ~ScreenCapturer() {} |
| 69 | |
| 70 | // Creates platform-specific capturer. |
sergeyu@chromium.org | 91685dc | 2013-10-12 22:40:05 +0000 | [diff] [blame] | 71 | // |
| 72 | // TODO(sergeyu): Remove all Create() methods except the first one. |
| 73 | // crbug.com/172183 |
| 74 | static ScreenCapturer* Create(const DesktopCaptureOptions& options); |
sergeyu@chromium.org | 6c82a7e | 2013-06-04 18:51:23 +0000 | [diff] [blame] | 75 | static ScreenCapturer* Create(); |
| 76 | |
| 77 | #if defined(WEBRTC_LINUX) |
| 78 | // Creates platform-specific capturer and instructs it whether it should use |
| 79 | // X DAMAGE support. |
| 80 | static ScreenCapturer* CreateWithXDamage(bool use_x_damage); |
| 81 | #elif defined(WEBRTC_WIN) |
| 82 | // Creates Windows-specific capturer and instructs it whether or not to |
| 83 | // disable desktop compositing. |
| 84 | static ScreenCapturer* CreateWithDisableAero(bool disable_aero); |
| 85 | #endif // defined(WEBRTC_WIN) |
| 86 | |
| 87 | // Called at the beginning of a capturing session. |mouse_shape_observer| must |
| 88 | // remain valid until the capturer is destroyed. |
| 89 | virtual void SetMouseShapeObserver( |
| 90 | MouseShapeObserver* mouse_shape_observer) = 0; |
jiayl@webrtc.org | a2c2654 | 2014-01-14 18:26:37 +0000 | [diff] [blame] | 91 | |
| 92 | // Get the list of screens (not containing kFullDesktopScreenId). Returns |
| 93 | // false in case of a failure. |
| 94 | virtual bool GetScreenList(ScreenList* screens) = 0; |
| 95 | |
| 96 | // Select the screen to be captured. Returns false in case of a failure (e.g. |
| 97 | // if there is no screen with the specified id). If this is never called, the |
| 98 | // full desktop is captured. |
| 99 | virtual bool SelectScreen(ScreenId id) = 0; |
sergeyu@chromium.org | 6c82a7e | 2013-06-04 18:51:23 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | } // namespace webrtc |
| 103 | |
| 104 | #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_H_ |