Agora Java API Reference for Android

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 #if !defined(__linux__)
77 enum class CapturerMode {
78 kUnspecified = 0,
79 // Mac only
80 kScreenCaptureKit = 10,
81 kCoreGraphic = 11,
82 kAVFoundation = 12,
83 };
84 #endif
85
86 enum CaptureType {
87 CaptureWindow,
88 CaptureScreen,
89 };
90 CaptureType type;
91 Rectangle screen_rect;
92 Rectangle region_offset;
93 int64_t display_id;
94 view_t window_id;
95
96 bool window_focused;
97
98 // Mac only
99 bool disable_avf;
100 #if !defined(__linux__)
101 CapturerMode capturerMode = CapturerMode::kUnspecified;
102
103 bool captureAudio = false;
104 int audio_channel_count = 2;
105 int audio_sample_rate = 48000;
106 bool excludeCurrentProcessAudio = true;
107 #endif
108
109 VideoCaptureConfig()
110 : type(CaptureScreen), screen_rect(), region_offset(), display_id(0), window_id(NULL), window_focused(false), disable_avf(false) { }
111 };
112 #endif
113
114 struct ScreenSourceListOption {
115 int thumb_width;
116 int thumb_height;
117 int icon_width;
118 int icon_height;
119 bool include_screen;
120 bool unfiltered;
121 bool unskip_system_window;
122 bool ignore_unresponsive;
123 };
124
125 enum CaptureMode {
126 kPull, // SDK needs to poll the captured frame actively
127 kPush // Capture source pushes the captured frame to sdk
128 };
129
130
131 virtual ~IScreenCaptureSource() {}
132
133 virtual int initializeCapture(const agora_refptr<Control>& control) = 0;
134
135 virtual int initVideo(const VideoCaptureConfig& config) = 0;
136 // Start video capture interface for desktop capturing
137 virtual int startVideoCapture(const VideoCaptureConfig& config) = 0;
138 virtual int stopVideoCapture() = 0;
139 virtual int stopVideoCaptureAsync() = 0;
140
141 virtual CaptureMode getVideoCaptureMode() = 0;
142
143 // Implementation of the following interfaces are not mandatory
144 virtual bool isAudioCaptureSupported() {
145 return false;
146 }
147 virtual int startAudioCapture(const AudioCaptureConfig& config) {
148 return -ERR_NOT_SUPPORTED;
149 }
150 virtual int stopAudioCapture() {
151 return -ERR_NOT_SUPPORTED;
152 }
153 virtual int setAudioVolume(uint32_t volume) {
154 return -ERR_NOT_SUPPORTED;
155 }
156 virtual int setFrameRate(int fps) {
157 return -ERR_NOT_SUPPORTED;
158 }
159
160 virtual int setScreenCaptureDimensions(const agora::rtc::VideoDimensions& dimensions) {
161 return -ERR_NOT_SUPPORTED;
162 }
163 virtual int updateCaptureRegion(const agora::rtc::Rectangle& captureRegion) {
164 return -ERR_NOT_SUPPORTED;
165 }
166 virtual int setExcludeWindowList(void* const * handles, int count) {
167 return -ERR_NOT_SUPPORTED;
168 }
169 virtual int captureMouseCursor(bool capture) {
170 return -ERR_NOT_SUPPORTED;
171 }
172 virtual int capture(agora::agora_refptr<IVideoFrame>& frame) {
173 return -ERR_NOT_SUPPORTED;
174 }
175 virtual int getProfilingStats(ScreenCaptureProfilingStatistics& stats) {
176 return -ERR_NOT_SUPPORTED;
177 }
178 virtual int getScreenDimensions(int& width, int& height) {
179 return ERR_NOT_SUPPORTED;
180 }
181 virtual int setProperty(const char* key, const char* json_value) {
182 return -ERR_NOT_SUPPORTED;
183 }
184 virtual int setCustomContext(const char* key, const void* context) {
185 return -ERR_NOT_SUPPORTED;
186 }
187 virtual int getProperty(const char* key, char* json_value, int& length) {
188 return -ERR_NOT_SUPPORTED;
189 }
190 virtual int setHighLight(bool isHighLight, unsigned int color, int width) {
191 return -ERR_NOT_SUPPORTED;
192 }
193 virtual int setContentType(int contentType) {
194 return -ERR_NOT_SUPPORTED;
195 }
196 virtual void* getCustomContext(const char* key) {
197 return NULL;
198 }
199 virtual void* getScreenCaptureSources(const ScreenSourceListOption& option) {
200 return NULL;
201 }
202 virtual void setFrameCopy(bool frameCopy) {};
203 #if defined(WEBRTC_ANDROID) && !defined(RTC_EXCLUDE_JAVA)
204 virtual void setSmoothCapture(bool smoothCapture) {};
205 virtual void setResetVitualDisplay(bool reset) {};
206 #endif
207 #if defined(WEBRTC_ANDROID)
208 virtual int setExternalMediaProjection(void* mediaProjection) {
209 return -ERR_NOT_SUPPORTED;
210 }
211 #endif
212 };
213
214 } // namespace rtc
215 } // namespace agora
agora::rtc::ScreenCaptureProfilingStatistics
Definition: NGIAgoraExtensionScreenSource.h:20
agora::agora_refptr
Definition: AgoraRefPtr.h:44
agora::rtc::Rectangle
Definition: AgoraBase.h:2221
agora::media::IAudioFrameObserverBase::AudioFrame
Definition: AgoraMediaBase.h:1282
agora::rtc::IScreenCaptureSource::ScreenSourceListOption
Definition: NGIAgoraExtensionScreenSource.h:114
agora::rtc::IScreenCaptureSource::AudioCaptureConfig
Definition: NGIAgoraExtensionScreenSource.h:60
agora::rtc::IScreenCaptureSource::Control
Definition: NGIAgoraExtensionScreenSource.h:43
agora::rtc::IScreenCaptureSource
Definition: NGIAgoraExtensionScreenSource.h:41
agora::RefCountInterface
Definition: AgoraRefPtr.h:31
agora::rtc::VideoDimensions
Definition: AgoraBase.h:1100
agora::rtc::IScreenCaptureSource::VideoCaptureConfig
Definition: NGIAgoraExtensionScreenSource.h:75