blob: a8d40a72ef838ef59342249429fd10a2feb96449 [file] [log] [blame]
sergeyu@chromium.org6c82a7e2013-06-04 18:51:23 +00001/*
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.orga2c26542014-01-14 18:26:37 +000014#include <vector>
15
16#include "webrtc/modules/desktop_capture/desktop_capture_types.h"
sergeyu@chromium.org6c82a7e2013-06-04 18:51:23 +000017#include "webrtc/modules/desktop_capture/desktop_capturer.h"
18#include "webrtc/system_wrappers/interface/scoped_ptr.h"
19#include "webrtc/typedefs.h"
20
21namespace webrtc {
22
sergeyu@chromium.org91685dc2013-10-12 22:40:05 +000023class DesktopCaptureOptions;
sergeyu@chromium.org6c82a7e2013-06-04 18:51:23 +000024struct 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.
44class ScreenCapturer : public DesktopCapturer {
45 public:
jiayl@webrtc.orga2c26542014-01-14 18:26:37 +000046 // 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.org6c82a7e2013-06-04 18:51:23 +000053 // 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.org91685dc2013-10-12 22:40:05 +000071 //
72 // TODO(sergeyu): Remove all Create() methods except the first one.
73 // crbug.com/172183
74 static ScreenCapturer* Create(const DesktopCaptureOptions& options);
sergeyu@chromium.org6c82a7e2013-06-04 18:51:23 +000075 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.orga2c26542014-01-14 18:26:37 +000091
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.org6c82a7e2013-06-04 18:51:23 +0000100};
101
102} // namespace webrtc
103
104#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_H_