Agora C++ API Reference for All Platforms

NGIAgoraExtensionScreenSource.h
1 //
2 // Agora SDK
3 //
4 // Copyright (c) 2021 Agora.io. All rights reserved.
5 //
6
7 #pragma once // NOLINT(build/header_guard)
8
9 #include "AgoraBase.h"
10 #include "IAgoraLog.h"
11 #include "AgoraRefPtr.h"
12 #include "NGIAgoraVideoFrame.h"
13 #include "AgoraMediaBase.h"
14 #if defined(WEBRTC_IOS)
15 #include <coreVideo/CVPixelBuffer.h>
16 #endif
17 namespace agora {
18 namespace rtc {
19
20 struct ScreenCaptureProfilingStatistics {
21 int capture_type;
22 uint32_t captured_frame_width;
23 uint32_t captured_frame_height;
24 uint32_t total_captured_frames;
25 uint64_t per_frame_cap_time_ms;
26 uint64_t per_capture_cpu_cycles;
27 bool capture_mouse_cursor;
28 uint32_t target_fps;
29 uint32_t real_capture_fps;
30 uint32_t capture_out_fps;
31 uint32_t drop_fps;
32
33 ScreenCaptureProfilingStatistics()
34 : capture_type(-1), captured_frame_width(0), captured_frame_height(0),
35 total_captured_frames(0), per_frame_cap_time_ms(0),
36 per_capture_cpu_cycles(0), capture_mouse_cursor(true),
37 target_fps(0), real_capture_fps(0),
38 capture_out_fps(0), drop_fps(0) {}
39 };
40
41 class IScreenCaptureSource : public RefCountInterface {
42 public:
43 class Control : public RefCountInterface {
44 public:
45 virtual int postEvent(const char* key, const char* value) = 0;
46 virtual void printLog(commons::LOG_LEVEL level, const char* format, ...) = 0;
47 virtual void printLog(commons::LOG_LEVEL level, const char* fromat, va_list) = 0;
48 virtual int pushAudioFrame(const media::IAudioFrameObserver::AudioFrame& captured_frame) = 0;
49 virtual bool timeToPushVideo() = 0;
50 virtual int pushVideoFrame(const agora::agora_refptr<IVideoFrame>& captured_frame) = 0;
51 virtual agora::agora_refptr<IVideoFrameMemoryPool> getMemoryPool() = 0;
52 #if defined(WEBRTC_IOS)
53 virtual int pushVideoFrame(CVPixelBufferRef pixelBuffer, int64_t timestamp_ms, uint32_t rotation) = 0;
54 #endif
55 #if defined(WEBRTC_WIN)
56 virtual void recycleVideoCache() = 0;
57 #endif
58 };
59
60 struct AudioCaptureConfig {
61 uint32_t volume;
62 int sample_rate_hz;
63 int num_channels;
64 AudioCaptureConfig() : volume(0), sample_rate_hz(0), num_channels(0) {}
65 };
66
67 #if defined (__ANDROID__) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
68 struct VideoCaptureConfig {
69 agora::rtc::VideoDimensions dimensions;
70 int frameRate;
71 VideoCaptureConfig()
72 : dimensions(640, 360), frameRate(15) {}
73 };
74 #else
75 struct VideoCaptureConfig {
76 enum CaptureType {
77 CaptureWindow,
78 CaptureScreen,
79 };
80 CaptureType type;
81 Rectangle screen_rect;
82 Rectangle region_offset;
83 int64_t display_id;
84 view_t window_id;
85
86 bool window_focused;
87
88 // Mac only
89 bool disable_avf;
90
91 VideoCaptureConfig()
92 : type(CaptureScreen), screen_rect(), region_offset(), display_id(0), window_id(NULL), window_focused(false), disable_avf(false) { }
93 };
94 #endif
95
96 struct ScreenSourceListOption {
97 int thumb_width;
98 int thumb_height;
99 int icon_width;
100 int icon_height;
101 bool include_screen;
102 bool unfiltered;
103 bool unskip_system_window;
104 bool ignore_unresponsive;
105 };
106
107 enum CaptureMode {
108 kPull, // SDK needs to poll the captured frame actively
109 kPush // Capture source pushes the captured frame to sdk
110 };
111
112
113 virtual ~IScreenCaptureSource() {}
114
115 virtual int initializeCapture(const agora_refptr<Control>& control) = 0;
116
117 virtual int initVideo(const VideoCaptureConfig& config) = 0;
118 // Start video capture interface for desktop capturing
119 virtual int startVideoCapture(const VideoCaptureConfig& config) = 0;
120 virtual int stopVideoCapture() = 0;
121 virtual int stopVideoCaptureAsync() = 0;
122
123 virtual CaptureMode getVideoCaptureMode() = 0;
124
125 // Implementation of the following interfaces are not mandatory
126 virtual int startAudioCapture(const AudioCaptureConfig& config) {
127 return -ERR_NOT_SUPPORTED;
128 }
129 virtual int stopAudioCapture() {
130 return -ERR_NOT_SUPPORTED;
131 }
132 virtual int setAudioVolume(uint32_t volume) {
133 return -ERR_NOT_SUPPORTED;
134 }
135 virtual int setFrameRate(int fps) {
136 return -ERR_NOT_SUPPORTED;
137 }
138
139 virtual int setScreenCaptureDimensions(const agora::rtc::VideoDimensions& dimensions) {
140 return -ERR_NOT_SUPPORTED;
141 }
142 virtual int updateCaptureRegion(const agora::rtc::Rectangle& captureRegion) {
143 return -ERR_NOT_SUPPORTED;
144 }
145 virtual int setExcludeWindowList(void* const * handles, int count) {
146 return -ERR_NOT_SUPPORTED;
147 }
148 virtual int captureMouseCursor(bool capture) {
149 return -ERR_NOT_SUPPORTED;
150 }
151 virtual int capture(agora::agora_refptr<IVideoFrame>& frame) {
152 return -ERR_NOT_SUPPORTED;
153 }
154 virtual int getProfilingStats(ScreenCaptureProfilingStatistics& stats) {
155 return -ERR_NOT_SUPPORTED;
156 }
157 virtual int getScreenDimensions(int& width, int& height) {
158 return ERR_NOT_SUPPORTED;
159 }
160 virtual int setProperty(const char* key, const char* json_value) {
161 return -ERR_NOT_SUPPORTED;
162 }
163 virtual int setCustomContext(const char* key, const void* context) {
164 return -ERR_NOT_SUPPORTED;
165 }
166 virtual int getProperty(const char* key, char* json_value, int& length) {
167 return -ERR_NOT_SUPPORTED;
168 }
169 virtual int setHighLight(bool isHighLight, unsigned int color, int width) {
170 return -ERR_NOT_SUPPORTED;
171 }
172 virtual int setContentType(int contentType) {
173 return -ERR_NOT_SUPPORTED;
174 }
175 virtual void* getCustomContext(const char* key) {
176 return NULL;
177 }
178 virtual void* getScreenCaptureSources(const ScreenSourceListOption& option) {
179 return NULL;
180 }
181 virtual void setFrameCopy(bool frameCopy) {};
182 #if defined(WEBRTC_ANDROID) && !defined(RTC_EXCLUDE_JAVA)
183 virtual void setSmoothCapture(bool smoothCapture) {};
184 virtual void setResetVitualDisplay(bool reset) {};
185 #endif
186 #if defined(WEBRTC_ANDROID)
187 virtual int setExternalMediaProjection(void* mediaProjection) {
188 return -ERR_NOT_SUPPORTED;
189 }
190 #endif
191 };
192
193 } // namespace rtc
194 } // namespace agora
agora::rtc::ScreenCaptureProfilingStatistics::ScreenCaptureProfilingStatistics
ScreenCaptureProfilingStatistics()
Definition: NGIAgoraExtensionScreenSource.h:33
agora::rtc::IScreenCaptureSource::VideoCaptureConfig::CaptureScreen
@ CaptureScreen
Definition: NGIAgoraExtensionScreenSource.h:78
agora::rtc::IScreenCaptureSource::Control::pushAudioFrame
virtual int pushAudioFrame(const media::IAudioFrameObserver::AudioFrame &captured_frame)=0
agora::rtc::ScreenCaptureProfilingStatistics
Definition: NGIAgoraExtensionScreenSource.h:20
agora::rtc::IScreenCaptureSource::Control::timeToPushVideo
virtual bool timeToPushVideo()=0
agora::agora_refptr
Definition: AgoraRefPtr.h:44
agora::rtc::ScreenCaptureProfilingStatistics::captured_frame_height
uint32_t captured_frame_height
Definition: NGIAgoraExtensionScreenSource.h:23
agora::rtc::IScreenCaptureSource::initVideo
virtual int initVideo(const VideoCaptureConfig &config)=0
agora::rtc::IScreenCaptureSource::Control::postEvent
virtual int postEvent(const char *key, const char *value)=0
agora::rtc::IScreenCaptureSource::Control::pushVideoFrame
virtual int pushVideoFrame(CVPixelBufferRef pixelBuffer, int64_t timestamp_ms, uint32_t rotation)=0
agora::rtc::IScreenCaptureSource::stopVideoCaptureAsync
virtual int stopVideoCaptureAsync()=0
agora::rtc::Rectangle
Definition: AgoraBase.h:2224
agora::view_t
void * view_t
Definition: AgoraBase.h:818
agora::rtc::ScreenCaptureProfilingStatistics::drop_fps
uint32_t drop_fps
Definition: NGIAgoraExtensionScreenSource.h:31
agora::media::IAudioFrameObserverBase::AudioFrame
Definition: AgoraMediaBase.h:1270
agora::rtc::IScreenCaptureSource::getProfilingStats
virtual int getProfilingStats(ScreenCaptureProfilingStatistics &stats)
Definition: NGIAgoraExtensionScreenSource.h:154
agora::rtc::IScreenCaptureSource::VideoCaptureConfig::CaptureWindow
@ CaptureWindow
Definition: NGIAgoraExtensionScreenSource.h:77
agora::rtc::IScreenCaptureSource::setAudioVolume
virtual int setAudioVolume(uint32_t volume)
Definition: NGIAgoraExtensionScreenSource.h:132
agora::rtc::IScreenCaptureSource::ScreenSourceListOption::unfiltered
bool unfiltered
Definition: NGIAgoraExtensionScreenSource.h:102
agora::rtc::ScreenCaptureProfilingStatistics::real_capture_fps
uint32_t real_capture_fps
Definition: NGIAgoraExtensionScreenSource.h:29
agora::rtc::IScreenCaptureSource::kPush
@ kPush
Definition: NGIAgoraExtensionScreenSource.h:109
agora::rtc::IScreenCaptureSource::VideoCaptureConfig::display_id
int64_t display_id
Definition: NGIAgoraExtensionScreenSource.h:83
agora::rtc::IScreenCaptureSource::capture
virtual int capture(agora::agora_refptr< IVideoFrame > &frame)
Definition: NGIAgoraExtensionScreenSource.h:151
agora::rtc::IScreenCaptureSource::setHighLight
virtual int setHighLight(bool isHighLight, unsigned int color, int width)
Definition: NGIAgoraExtensionScreenSource.h:169
agora::rtc::IScreenCaptureSource::VideoCaptureConfig::region_offset
Rectangle region_offset
Definition: NGIAgoraExtensionScreenSource.h:82
agora::rtc::IScreenCaptureSource::AudioCaptureConfig::AudioCaptureConfig
AudioCaptureConfig()
Definition: NGIAgoraExtensionScreenSource.h:64
agora::rtc::ScreenCaptureProfilingStatistics::total_captured_frames
uint32_t total_captured_frames
Definition: NGIAgoraExtensionScreenSource.h:24
agora
Definition: AgoraAtomicOps.h:21
agora::rtc::IScreenCaptureSource::ScreenSourceListOption
Definition: NGIAgoraExtensionScreenSource.h:96
agora::rtc::ScreenCaptureProfilingStatistics::captured_frame_width
uint32_t captured_frame_width
Definition: NGIAgoraExtensionScreenSource.h:22
agora::rtc::IScreenCaptureSource::AudioCaptureConfig
Definition: NGIAgoraExtensionScreenSource.h:60
agora::rtc::IScreenCaptureSource::ScreenSourceListOption::thumb_width
int thumb_width
Definition: NGIAgoraExtensionScreenSource.h:97
agora::rtc::IScreenCaptureSource::stopAudioCapture
virtual int stopAudioCapture()
Definition: NGIAgoraExtensionScreenSource.h:129
agora::rtc::IScreenCaptureSource::captureMouseCursor
virtual int captureMouseCursor(bool capture)
Definition: NGIAgoraExtensionScreenSource.h:148
agora::rtc::IScreenCaptureSource::setResetVitualDisplay
virtual void setResetVitualDisplay(bool reset)
Definition: NGIAgoraExtensionScreenSource.h:184
agora::rtc::IScreenCaptureSource::setSmoothCapture
virtual void setSmoothCapture(bool smoothCapture)
Definition: NGIAgoraExtensionScreenSource.h:183
agora::rtc::IScreenCaptureSource::VideoCaptureConfig::disable_avf
bool disable_avf
Definition: NGIAgoraExtensionScreenSource.h:89
agora::rtc::IScreenCaptureSource::ScreenSourceListOption::ignore_unresponsive
bool ignore_unresponsive
Definition: NGIAgoraExtensionScreenSource.h:104
agora::rtc::IScreenCaptureSource::getProperty
virtual int getProperty(const char *key, char *json_value, int &length)
Definition: NGIAgoraExtensionScreenSource.h:166
agora::rtc::IScreenCaptureSource::Control::printLog
virtual void printLog(commons::LOG_LEVEL level, const char *format,...)=0
agora::rtc::IScreenCaptureSource::Control::recycleVideoCache
virtual void recycleVideoCache()=0
agora::rtc::IScreenCaptureSource::VideoCaptureConfig::window_focused
bool window_focused
Definition: NGIAgoraExtensionScreenSource.h:86
agora::rtc::IScreenCaptureSource::setProperty
virtual int setProperty(const char *key, const char *json_value)
Definition: NGIAgoraExtensionScreenSource.h:160
agora::rtc::IScreenCaptureSource::Control::getMemoryPool
virtual agora::agora_refptr< IVideoFrameMemoryPool > getMemoryPool()=0
agora::commons::LOG_LEVEL
OPTIONAL_ENUM_CLASS LOG_LEVEL
Definition: IAgoraLog.h:33
agora::rtc::IScreenCaptureSource::VideoCaptureConfig::dimensions
agora::rtc::VideoDimensions dimensions
Definition: NGIAgoraExtensionScreenSource.h:69
agora::rtc::ScreenCaptureProfilingStatistics::capture_out_fps
uint32_t capture_out_fps
Definition: NGIAgoraExtensionScreenSource.h:30
agora::rtc::IScreenCaptureSource::AudioCaptureConfig::num_channels
int num_channels
Definition: NGIAgoraExtensionScreenSource.h:63
agora::rtc::IScreenCaptureSource::Control
Definition: NGIAgoraExtensionScreenSource.h:43
agora::rtc::IScreenCaptureSource::CaptureMode
CaptureMode
Definition: NGIAgoraExtensionScreenSource.h:107
agora::rtc::IScreenCaptureSource::ScreenSourceListOption::include_screen
bool include_screen
Definition: NGIAgoraExtensionScreenSource.h:101
agora::rtc::IScreenCaptureSource::initializeCapture
virtual int initializeCapture(const agora_refptr< Control > &control)=0
agora::rtc::IScreenCaptureSource::Control::printLog
virtual void printLog(commons::LOG_LEVEL level, const char *fromat, va_list)=0
agora::rtc::ScreenCaptureProfilingStatistics::per_frame_cap_time_ms
uint64_t per_frame_cap_time_ms
Definition: NGIAgoraExtensionScreenSource.h:25
agora::rtc::IScreenCaptureSource::ScreenSourceListOption::icon_height
int icon_height
Definition: NGIAgoraExtensionScreenSource.h:100
agora::rtc::ScreenCaptureProfilingStatistics::target_fps
uint32_t target_fps
Definition: NGIAgoraExtensionScreenSource.h:28
agora::rtc::ScreenCaptureProfilingStatistics::capture_mouse_cursor
bool capture_mouse_cursor
Definition: NGIAgoraExtensionScreenSource.h:27
agora::rtc::IScreenCaptureSource::setFrameRate
virtual int setFrameRate(int fps)
Definition: NGIAgoraExtensionScreenSource.h:135
agora::rtc::IScreenCaptureSource::Control::pushVideoFrame
virtual int pushVideoFrame(const agora::agora_refptr< IVideoFrame > &captured_frame)=0
agora::rtc::ScreenCaptureProfilingStatistics::capture_type
int capture_type
Definition: NGIAgoraExtensionScreenSource.h:21
agora::rtc::IScreenCaptureSource::updateCaptureRegion
virtual int updateCaptureRegion(const agora::rtc::Rectangle &captureRegion)
Definition: NGIAgoraExtensionScreenSource.h:142
agora::rtc::IScreenCaptureSource::startAudioCapture
virtual int startAudioCapture(const AudioCaptureConfig &config)
Definition: NGIAgoraExtensionScreenSource.h:126
agora::rtc::IScreenCaptureSource::AudioCaptureConfig::volume
uint32_t volume
Definition: NGIAgoraExtensionScreenSource.h:61
agora::ERR_NOT_SUPPORTED
@ ERR_NOT_SUPPORTED
Definition: AgoraBase.h:485
agora::rtc::IScreenCaptureSource::getVideoCaptureMode
virtual CaptureMode getVideoCaptureMode()=0
agora::rtc::IScreenCaptureSource
Definition: NGIAgoraExtensionScreenSource.h:41
agora::rtc::IScreenCaptureSource::VideoCaptureConfig::type
CaptureType type
Definition: NGIAgoraExtensionScreenSource.h:80
agora::rtc::IScreenCaptureSource::stopVideoCapture
virtual int stopVideoCapture()=0
agora::RefCountInterface
Definition: AgoraRefPtr.h:31
agora::rtc::IScreenCaptureSource::ScreenSourceListOption::icon_width
int icon_width
Definition: NGIAgoraExtensionScreenSource.h:99
agora::rtc::IScreenCaptureSource::startVideoCapture
virtual int startVideoCapture(const VideoCaptureConfig &config)=0
agora::rtc::IScreenCaptureSource::VideoCaptureConfig::window_id
view_t window_id
Definition: NGIAgoraExtensionScreenSource.h:84
agora::rtc::VideoDimensions
Definition: AgoraBase.h:1103
agora::rtc::IScreenCaptureSource::VideoCaptureConfig::CaptureType
CaptureType
Definition: NGIAgoraExtensionScreenSource.h:76
agora::rtc::IScreenCaptureSource::getCustomContext
virtual void * getCustomContext(const char *key)
Definition: NGIAgoraExtensionScreenSource.h:175
agora::rtc::IScreenCaptureSource::ScreenSourceListOption::unskip_system_window
bool unskip_system_window
Definition: NGIAgoraExtensionScreenSource.h:103
agora::rtc::IScreenCaptureSource::setCustomContext
virtual int setCustomContext(const char *key, const void *context)
Definition: NGIAgoraExtensionScreenSource.h:163
agora::rtc::IScreenCaptureSource::ScreenSourceListOption::thumb_height
int thumb_height
Definition: NGIAgoraExtensionScreenSource.h:98
agora::rtc::IScreenCaptureSource::setScreenCaptureDimensions
virtual int setScreenCaptureDimensions(const agora::rtc::VideoDimensions &dimensions)
Definition: NGIAgoraExtensionScreenSource.h:139
agora::rtc::IScreenCaptureSource::getScreenCaptureSources
virtual void * getScreenCaptureSources(const ScreenSourceListOption &option)
Definition: NGIAgoraExtensionScreenSource.h:178
agora::rtc::IScreenCaptureSource::kPull
@ kPull
Definition: NGIAgoraExtensionScreenSource.h:108
agora::rtc::IScreenCaptureSource::~IScreenCaptureSource
virtual ~IScreenCaptureSource()
Definition: NGIAgoraExtensionScreenSource.h:113
agora::rtc::IScreenCaptureSource::setExcludeWindowList
virtual int setExcludeWindowList(void *const *handles, int count)
Definition: NGIAgoraExtensionScreenSource.h:145
agora::rtc::IScreenCaptureSource::VideoCaptureConfig::VideoCaptureConfig
VideoCaptureConfig()
Definition: NGIAgoraExtensionScreenSource.h:71
agora::rtc::IScreenCaptureSource::VideoCaptureConfig::screen_rect
Rectangle screen_rect
Definition: NGIAgoraExtensionScreenSource.h:81
agora::rtc::IScreenCaptureSource::setExternalMediaProjection
virtual int setExternalMediaProjection(void *mediaProjection)
Definition: NGIAgoraExtensionScreenSource.h:187
agora::rtc::IScreenCaptureSource::setFrameCopy
virtual void setFrameCopy(bool frameCopy)
Definition: NGIAgoraExtensionScreenSource.h:181
agora::rtc::IScreenCaptureSource::AudioCaptureConfig::sample_rate_hz
int sample_rate_hz
Definition: NGIAgoraExtensionScreenSource.h:62
agora::rtc::IScreenCaptureSource::setContentType
virtual int setContentType(int contentType)
Definition: NGIAgoraExtensionScreenSource.h:172
agora::rtc::IScreenCaptureSource::VideoCaptureConfig::frameRate
int frameRate
Definition: NGIAgoraExtensionScreenSource.h:70
agora::rtc::IScreenCaptureSource::getScreenDimensions
virtual int getScreenDimensions(int &width, int &height)
Definition: NGIAgoraExtensionScreenSource.h:157
agora::rtc::IScreenCaptureSource::VideoCaptureConfig
Definition: NGIAgoraExtensionScreenSource.h:68
agora::rtc::ScreenCaptureProfilingStatistics::per_capture_cpu_cycles
uint64_t per_capture_cpu_cycles
Definition: NGIAgoraExtensionScreenSource.h:26
rtc
Definition: video_node_i.h:28