1 /*
2  * Copyright (C) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef NATIVE_AVSCREEN_CAPTURE_H
17 #define NATIVE_AVSCREEN_CAPTURE_H
18 
19 #include <stdint.h>
20 #include <stdio.h>
21 #include "native_avscreen_capture_errors.h"
22 #include "native_avscreen_capture_base.h"
23 #include "external_window.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /**
30  * @brief Create a screen capture
31  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
32  * @return Returns a pointer to an OH_AVScreenCapture instance
33  * @since 10
34  * @version 1.0
35  */
36 struct OH_AVScreenCapture *OH_AVScreenCapture_Create(void);
37 
38 /**
39  * @brief To init the screen capture, typically, you need to configure the description information of the audio
40  * and video, which can be extracted from the container. This interface must be called before StartAVScreenCapture
41  * called.
42  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
43  * @param capture Pointer to an OH_AVScreenCapture instance
44  * @param config Information describing the audio and video config
45  * @return Returns AV_SCREEN_CAPTURE_ERR_OK if the execution is successful,
46  * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode}
47  * @since 10
48  * @version 1.0
49  */
50 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_Init(struct OH_AVScreenCapture *capture,
51     OH_AVScreenCaptureConfig config);
52 
53 /**
54  * @brief Start the av screen capture
55  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
56  * @param capture Pointer to an OH_AVScreenCapture instance
57  * @return Returns AV_SCREEN_CAPTURE_ERR_OK if the execution is successful,
58  * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode}
59  * @since 10
60  * @version 1.0
61  */
62 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StartScreenCapture(struct OH_AVScreenCapture *capture);
63 
64 /**
65  * @brief Start the av screen capture
66  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
67  * @param capture Pointer to an OH_AVScreenCapture instance
68  * @param window Pointer to an OHNativeWindow instance
69  * @return Returns AV_SCREEN_CAPTURE_ERR_OK if the execution is successful,
70  * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode}
71  * @since 12
72  * @version 1.0
73  */
74 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StartScreenCaptureWithSurface(struct OH_AVScreenCapture *capture,
75     OHNativeWindow* window);
76 
77 /**
78  * @brief Stop the av screen capture
79  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
80  * @param capture Pointer to an OH_AVScreenCapture instance
81  * @return Returns AV_SCREEN_CAPTURE_ERR_OK if the execution is successful,
82  * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode}
83  * @since 10
84  * @version 1.0
85  */
86 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StopScreenCapture(struct OH_AVScreenCapture *capture);
87 
88 /**
89  * @brief Start av screen record use to start save screen record file.
90  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
91  * @param capture Pointer to an OH_AVScreenCapture instance
92  * @return Returns AV_SCREEN_CAPTURE_ERR_OK if the execution is successful,
93  * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode}
94  * @since 10
95  * @version 1.0
96  */
97 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StartScreenRecording(struct OH_AVScreenCapture *capture);
98 
99 /**
100  * @brief Start av screen record use to stop save screen record file.
101  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
102  * @param capture Pointer to an OH_AVScreenCapture instance
103  * @return Returns AV_SCREEN_CAPTURE_ERR_OK if the execution is successful,
104  * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode}
105  * @since 10
106  * @version 1.0
107  */
108 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StopScreenRecording(struct OH_AVScreenCapture *capture);
109 
110 /**
111  * @brief Acquire the audio buffer for the av screen capture
112  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
113  * @param capture Pointer to an OH_AVScreenCapture instance
114  * @param audiobuffer Information describing the audio buffer of the capture
115  * @param type Information describing the audio source type
116  * @return Returns AV_SCREEN_CAPTURE_ERR_OK if the execution is successful,
117  * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode}
118  * @deprecated since 12
119  * @useinstead {@link OH_AVScreenCapture_OnBufferAvailable}
120  * @since 10
121  * @version 1.0
122  */
123 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_AcquireAudioBuffer(struct OH_AVScreenCapture *capture,
124     OH_AudioBuffer **audiobuffer, OH_AudioCaptureSourceType type);
125 
126 /**
127  * @brief Acquire the video buffer for the av screen capture
128  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
129  * @param capture Pointer to an OH_AVScreenCapture instance
130  * @param fence A processing state of display buffer
131  * @param timestamp Information about the video buffer
132  * @param region Information about the video buffer
133  * @return Returns a pointer to an OH_NativeBuffer instance
134  * @deprecated since 12
135  * @useinstead {@link OH_AVScreenCapture_OnBufferAvailable}
136  * @since 10
137  * @version 1.0
138  */
139 OH_NativeBuffer* OH_AVScreenCapture_AcquireVideoBuffer(struct OH_AVScreenCapture *capture,
140     int32_t *fence, int64_t *timestamp, struct OH_Rect *region);
141 
142 /**
143  * @brief Release the audio buffer for the av screen capture
144  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
145  * @param capture Pointer to an OH_AVScreenCapture instance
146  * @param type Information describing the audio source type
147  * @return Returns AV_SCREEN_CAPTURE_ERR_OK if the execution is successful,
148  * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode}
149  * @deprecated since 12
150  * @useinstead {@link OH_AVScreenCapture_OnBufferAvailable}
151  * @since 10
152  * @version 1.0
153  */
154 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_ReleaseAudioBuffer(struct OH_AVScreenCapture *capture,
155     OH_AudioCaptureSourceType type);
156 
157 /**
158  * @brief Release the video buffer for the av screen capture
159  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
160  * @param capture Pointer to an OH_AVScreenCapture instance
161  * @return Returns AV_SCREEN_CAPTURE_ERR_OK if the execution is successful,
162  * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode}
163  * @deprecated since 12
164  * @useinstead {@link OH_AVScreenCapture_OnBufferAvailable}
165  * @since 10
166  * @version 1.0
167  */
168 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_ReleaseVideoBuffer(struct OH_AVScreenCapture *capture);
169 
170 /**
171  * @brief Set the callback function so that your application
172  * can respond to the events generated by the av screen capture. This interface must be called before Init is called.
173  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
174  * @param capture Pointer to an OH_AVScreenCapture instance
175  * @param callback A collection of all callback functions, see {@link OH_AVScreenCaptureCallback}
176  * @return Returns AV_SCREEN_CAPTURE_ERR_OK if the execution is successful,
177  * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode}
178  * @deprecated since 12
179  * @useinstead {@link OH_AVScreenCapture_SetErrorCallback} {@link OH_AVScreenCapture_SetDataCallback}
180  * @since 10
181  * @version 1.0
182  */
183 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetCallback(struct OH_AVScreenCapture *capture,
184     struct OH_AVScreenCaptureCallback callback);
185 
186 /**
187  * @brief Release the av screen capture
188  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
189  * @param capture Pointer to an OH_AVScreenCapture instance
190  * @return Returns AV_SCREEN_CAPTURE_ERR_OK if the execution is successful,
191  * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode}
192  * @since 10
193  * @version 1.0
194  */
195 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_Release(struct OH_AVScreenCapture *capture);
196 
197 /**
198  * @brief Controls the switch of the microphone, which is turned on by default
199  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
200  * @param capture Pointer to an OH_AVScreenCapture instance
201  * @param isMicrophone The switch of the microphone
202  * @return Returns AV_SCREEN_CAPTURE_ERR_OK if the execution is successful,
203  * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode}
204  * @since 10
205  * @version 1.0
206  */
207 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetMicrophoneEnabled(struct OH_AVScreenCapture *capture,
208     bool isMicrophone);
209 /**
210  * @brief Set the state callback function so that your application can respond to the
211  * state change events generated by the av screen capture. This interface must be called before Start is called.
212  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
213  * @param capture Pointer to an OH_AVScreenCapture instance
214  * @param callback State callback function, see {@link OH_AVScreenCapture_OnStateChange}
215  * @param userData Pointer to user specific data
216  * @return Returns AV_SCREEN_CAPTURE_ERR_OK if the execution is successful,
217  * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode}
218  * @since 12
219  * @version 1.0
220  */
221 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetStateCallback(struct OH_AVScreenCapture *capture,
222     OH_AVScreenCapture_OnStateChange callback, void *userData);
223 
224 /**
225  * @brief Set the data callback function so that your application can respond to the
226  * data available events generated by the av screen capture. This interface must be called before Start is called.
227  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
228  * @param capture Pointer to an OH_AVScreenCapture instance
229  * @param callback Data callback function, see {@link OH_AVScreenCapture_OnBufferAvailable}
230  * @param userData Pointer to user specific data
231  * @return Returns AV_SCREEN_CAPTURE_ERR_OK if the execution is successful,
232  * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode}
233  * @since 12
234  * @version 1.0
235  */
236 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetDataCallback(struct OH_AVScreenCapture *capture,
237     OH_AVScreenCapture_OnBufferAvailable callback, void *userData);
238 
239 /**
240  * @brief Set the error callback function so that your application can respond to the
241  * error events generated by the av screen capture. This interface must be called before Start is called.
242  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
243  * @param capture Pointer to an OH_AVScreenCapture instance
244  * @param callback Error callback function, see {@link OH_AVScreenCapture_OnError}
245  * @param userData Pointer to user specific data
246  * @return Returns AV_SCREEN_CAPTURE_ERR_OK if the execution is successful,
247  * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode}
248  * @since 12
249  * @version 1.0
250  */
251 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetErrorCallback(struct OH_AVScreenCapture *capture,
252     OH_AVScreenCapture_OnError callback, void *userData);
253 
254 /**
255  * @brief Controls the Rotation of the Screen, which is no rotate by default
256  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
257  * @param capture Pointer to an OH_AVScreenCapture instance
258  * @param canvasRotation Rotate The screen or not
259  * @return Returns AV_SCREEN_CAPTURE_ERR_OK if the execution is successful,
260  * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode}
261  * @since 12
262  * @version 1.0
263  */
264 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetCanvasRotation(struct OH_AVScreenCapture *capture,
265     bool canvasRotation);
266 
267 /**
268  * @brief Create a screen capture content filter
269  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
270  * @return Returns a pointer to an OH_AVScreenCapture_ContentFilter instance
271  * @since 12
272  * @version 1.0
273  */
274 struct OH_AVScreenCapture_ContentFilter *OH_AVScreenCapture_CreateContentFilter(void);
275 
276 /**
277  * @brief Release the screen capture content filter
278  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
279  * @param filter Pointer to an OH_AVScreenCapture_ContentFilter instance
280  * @return Returns AVSCREEN_CAPTURE_ERR_OK if the execution is successful,
281  * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode}
282  * @since 12
283  * @version 1.0
284  */
285 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_ReleaseContentFilter(struct OH_AVScreenCapture_ContentFilter *filter);
286 
287 /**
288  * @brief Add content to the screen capture content filter
289  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
290  * @param filter Pointer to an OH_AVScreenCapture_ContentFilter instance
291  * @param content content to be added
292  * @return Returns AVSCREEN_CAPTURE_ERR_OK if the execution is successful,
293  * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode}
294  * @since 12
295  * @version 1.0
296  */
297 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_ContentFilter_AddAudioContent(
298     struct OH_AVScreenCapture_ContentFilter *filter, OH_AVScreenCaptureFilterableAudioContent content);
299 
300 /**
301  * @brief Set content filter to screen capture
302  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
303  * @param capture Pointer to an OH_AVScreenCapture instance
304  * @param filter Pointer to an OH_AVScreenCapture_ContentFilter instance
305  * @return Returns AVSCREEN_CAPTURE_ERR_OK if the execution is successful,
306  * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode}
307  * @since 12
308  * @version 1.0
309  */
310 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_ExcludeContent(struct OH_AVScreenCapture *capture,
311     struct OH_AVScreenCapture_ContentFilter *filter);
312 
313 /**
314  * @brief Add Window content to the screen capture content filter
315  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
316  * @param filter Pointer to an OH_AVScreenCapture_ContentFilter instance
317  * @param Pointer to windowIDs to be added
318  * @param windowCount to be added
319  * @return Returns AV_SCREEN_CAPTURE_ERR_OK if the execution is successful,
320  * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode}
321  * @since 12
322  * @version 1.0
323  */
324 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_ContentFilter_AddWindowContent(
325     struct OH_AVScreenCapture_ContentFilter *filter, int32_t *windowIDs, int32_t windowCount);
326 
327 /**
328  * @brief Resize the Resolution of the Screen
329  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
330  * @param capture Pointer to an OH_AVScreenCapture instance
331  * @param width Video frame width of avscreeencapture
332  * @param height Video frame height of avscreeencapture
333  * @return Function result code.
334  *         {@link AV_SCREEN_CAPTURE_ERR_OK} if the execution is successful.
335  *         {@link AV_SCREEN_CAPTURE_ERR_INVALID_VAL} input capture is nullptr.
336  *         {@link AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT} opertation not be permitted.
337  * @since 12
338  * @version 1.0
339  */
340 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_ResizeCanvas(struct OH_AVScreenCapture *capture,
341     int32_t width, int32_t height);
342 
343 /**
344  * @brief skip some windows' privacy mode of current app during the screen recording
345  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
346  * @param capture Pointer to an OH_AVScreenCapture instance
347  * @param Pointer of windowID list
348  * @param length of windowID list
349  * @return Function result code.
350  *         {@link AV_SCREEN_CAPTURE_ERR_OK} if the execution is successful.
351  *         {@link AV_SCREEN_CAPTURE_ERR_INVALID_VAL} input capture is nullptr or input windowIDs are not belong current
352  *         app.
353  *         {@link AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT} opertation not be permitted.
354  * @since 12
355  * @version 1.0
356  */
357 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SkipPrivacyMode(struct OH_AVScreenCapture *capture,
358     int32_t *windowIDs, int32_t windowCount);
359 
360 /**
361  * @brief set up the max number of video frame per second
362  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
363  * @param capture Pointer to an OH_AVScreenCapture instance
364  * @param frameRate Max frame rate of video
365  * @return Function result code.
366  *         {@link AV_SCREEN_CAPTURE_ERR_OK} if the execution is successful.
367  *         {@link AV_SCREEN_CAPTURE_ERR_INVALID_VAL} input capture is nullptr or frameRate is not support.
368  *         {@link AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT} opertation not be permitted.
369  * @since 14
370  * @version 1.0
371  */
372 OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetMaxVideoFrameRate(struct OH_AVScreenCapture *capture,
373     int32_t frameRate);
374 #ifdef __cplusplus
375 }
376 #endif
377 
378 #endif // NATIVE_AVSCREEN_CAPTURE_H