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 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURER_H_ | 11 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURER_H_ |
12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURER_H_ | 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURER_H_ |
13 | 13 |
14 #include <stddef.h> | 14 #include <stddef.h> |
15 #include <stdint.h> | |
15 | 16 |
16 #include <memory> | 17 #include <memory> |
18 #include <string> | |
19 #include <vector> | |
17 | 20 |
18 #include "webrtc/modules/desktop_capture/desktop_frame.h" | 21 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
19 #include "webrtc/modules/desktop_capture/desktop_capture_types.h" | 22 #include "webrtc/modules/desktop_capture/desktop_capture_types.h" |
20 #include "webrtc/modules/desktop_capture/shared_memory.h" | 23 #include "webrtc/modules/desktop_capture/shared_memory.h" |
21 | 24 |
22 namespace webrtc { | 25 namespace webrtc { |
23 | 26 |
27 class DesktopCaptureOptions; | |
24 class DesktopFrame; | 28 class DesktopFrame; |
25 | 29 |
26 // Abstract interface for screen and window capturers. | 30 // Abstract interface for screen and window capturers. |
27 class DesktopCapturer { | 31 class DesktopCapturer { |
28 public: | 32 public: |
29 enum class Result { | 33 enum class Result { |
30 // The frame was captured successfully. | 34 // The frame was captured successfully. |
31 SUCCESS, | 35 SUCCESS, |
32 | 36 |
33 // There was a temporary error. The caller should continue calling | 37 // There was a temporary error. The caller should continue calling |
(...skipping 12 matching lines...) Expand all Loading... | |
46 public: | 50 public: |
47 // Called after a frame has been captured. |frame| is not nullptr if and | 51 // Called after a frame has been captured. |frame| is not nullptr if and |
48 // only if |result| is SUCCESS. | 52 // only if |result| is SUCCESS. |
49 virtual void OnCaptureResult(Result result, | 53 virtual void OnCaptureResult(Result result, |
50 std::unique_ptr<DesktopFrame> frame) = 0; | 54 std::unique_ptr<DesktopFrame> frame) = 0; |
51 | 55 |
52 protected: | 56 protected: |
53 virtual ~Callback() {} | 57 virtual ~Callback() {} |
54 }; | 58 }; |
55 | 59 |
56 virtual ~DesktopCapturer() {} | 60 enum class SourceType { |
61 // The source represents a window. | |
62 WINDOW, | |
63 // The source represents a screen. | |
64 SCREEN, | |
65 }; | |
66 | |
67 typedef webrtc::ScreenId ScreenId; | |
68 typedef webrtc::WindowId WindowId; | |
69 typedef intptr_t SourceId; | |
70 | |
71 struct Source { | |
72 // Whether this source represents a window or a screen. | |
73 SourceType type; | |
Sergey Ulanov
2016/10/28 15:53:21
I don't think we need this field here or SourceTyp
Hzj_jie
2016/10/28 22:03:53
I reconsidered this design, and, yes, the SourceId
| |
74 // |type| + |id| can identity a unique source in the system. | |
75 SourceId id; | |
76 // Title of the window or screen in UTF-8 encoding, maybe empty. This field | |
77 // should not be used to identify a source. | |
78 std::string title; | |
79 | |
80 // The WindowId, if type is SourceType::WINDOW, otherwise undefined. | |
81 WindowId window_id() const; | |
82 // The ScreenId, if type is SourceType::SCREEN, otherwise undefined. | |
83 ScreenId screen_id() const; | |
Sergey Ulanov
2016/10/28 15:53:22
I don't see a case when these fields can be useful
Hzj_jie
2016/10/28 22:03:53
Done.
| |
84 | |
85 bool operator<(const Source& other) const; | |
86 bool operator>(const Source& other) const; | |
87 bool operator==(const Source& other) const; | |
88 bool operator!=(const Source& other) const; | |
Sergey Ulanov
2016/10/28 15:53:22
Why do we need these operators? Their behavior is
Hzj_jie
2016/10/28 22:03:53
These operators are for comparing one Source to an
| |
89 | |
90 static Source NewWindow(WindowId id, const std::string& title); | |
91 static Source NewScreen(ScreenId id); | |
92 }; | |
93 | |
94 typedef std::vector<Source> SourceList; | |
95 | |
96 virtual ~DesktopCapturer(); | |
57 | 97 |
58 // Called at the beginning of a capturing session. |callback| must remain | 98 // Called at the beginning of a capturing session. |callback| must remain |
59 // valid until capturer is destroyed. | 99 // valid until capturer is destroyed. |
60 virtual void Start(Callback* callback) = 0; | 100 virtual void Start(Callback* callback) = 0; |
61 | 101 |
62 // Sets SharedMemoryFactory that will be used to create buffers for the | 102 // Sets SharedMemoryFactory that will be used to create buffers for the |
63 // captured frames. The factory can be invoked on a thread other than the one | 103 // captured frames. The factory can be invoked on a thread other than the one |
64 // where CaptureFrame() is called. It will be destroyed on the same thread. | 104 // where CaptureFrame() is called. It will be destroyed on the same thread. |
65 // Shared memory is currently supported only by some DesktopCapturer | 105 // Shared memory is currently supported only by some DesktopCapturer |
66 // implementations. | 106 // implementations. |
67 virtual void SetSharedMemoryFactory( | 107 virtual void SetSharedMemoryFactory( |
68 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) {} | 108 std::unique_ptr<SharedMemoryFactory> shared_memory_factory); |
69 | 109 |
70 // Captures next frame, and involve callback provided by Start() function. | 110 // Captures next frame, and involve callback provided by Start() function. |
71 // Pending capture requests are canceled when DesktopCapturer is deleted. | 111 // Pending capture requests are canceled when DesktopCapturer is deleted. |
72 virtual void CaptureFrame() = 0; | 112 virtual void CaptureFrame() = 0; |
73 | 113 |
74 // Sets the window to be excluded from the captured image in the future | 114 // Sets the window to be excluded from the captured image in the future |
75 // Capture calls. Used to exclude the screenshare notification window for | 115 // Capture calls. Used to exclude the screenshare notification window for |
76 // screen capturing. | 116 // screen capturing. |
77 virtual void SetExcludedWindow(WindowId window) {} | 117 virtual void SetExcludedWindow(WindowId window); |
118 | |
119 // TODO(zijiehe): Following functions should be pure virtual. The default | |
120 // implementations are for backward compatibility only. Remove default | |
121 // implementations once all DesktopCapturer implementations in Chromium have | |
122 // implemented these functions. | |
123 | |
124 // Gets a list of sources current capturer supports. Returns false in case of | |
125 // a failure. | |
126 virtual bool GetSourceList(SourceList* sources); | |
127 | |
128 // Selects a source to be captured. Returns false in case of a failure (e.g. | |
129 // if there is no source with the specified type and id.) | |
130 virtual bool SelectSource(const Source& source); | |
131 | |
132 // Brings the selected source to the front and sets the input focus on it. | |
133 // Returns false in case of a failure or no source has been selected or the | |
134 // implementation does not support this functionality. | |
135 virtual bool FocusOnSelectedSource(); | |
78 }; | 136 }; |
79 | 137 |
80 } // namespace webrtc | 138 } // namespace webrtc |
81 | 139 |
82 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURER_H_ | 140 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURER_H_ |
83 | 141 |
OLD | NEW |