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 /**
17  * @addtogroup AVScreenCapture
18  * @{
19  *
20  * @brief Provides APIs of request capability for Screen Capture.
21  * @since 10
22  */
23 
24 /**
25  * @file native_avscreen_capture_base.h
26  *
27  * @brief Declare screen capture related struct.
28  *
29  * @library libnative_avscreen_capture.so
30  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
31  * @kit MediaKit
32  * @since 10
33  */
34 
35 #ifndef NATIVE_AVSCREEN_CAPTURE_BASE_H
36 #define NATIVE_AVSCREEN_CAPTURE_BASE_H
37 
38 #include <stdbool.h>
39 #include <stdint.h>
40 #include "native_avbuffer.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /**
47  * @brief Nativebuffer of avscreeencapture that from graphics.
48  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
49  *
50  * @since 10
51  * @version 1.0
52  */
53 typedef struct OH_NativeBuffer OH_NativeBuffer;
54 
55 /**
56  * @brief Initialization of avscreeencapture
57  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
58  *
59  * @since 10
60  * @version 1.0
61  */
62 typedef struct OH_AVScreenCapture OH_AVScreenCapture;
63 
64 /**
65  * @brief Initialization of OH_AVScreenCapture_ContentFilter
66  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
67  *
68  * @since 12
69  * @version 1.0
70  */
71 typedef struct OH_AVScreenCapture_ContentFilter OH_AVScreenCapture_ContentFilter;
72 
73 /**
74  * @brief Enumerates screen capture mode.
75  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
76  *
77  * @since 10
78  * @version 1.0
79  */
80 typedef enum OH_CaptureMode {
81     /* capture home screen */
82     OH_CAPTURE_HOME_SCREEN = 0,
83     /* capture a specified screen */
84     OH_CAPTURE_SPECIFIED_SCREEN = 1,
85     /* capture a specified window */
86     OH_CAPTURE_SPECIFIED_WINDOW = 2,
87     OH_CAPTURE_INVAILD = -1
88 } OH_CaptureMode;
89 
90 /**
91  * @brief Enumerates audio cap source type.
92  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
93  *
94  * @since 10
95  * @version 1.0
96  */
97 typedef enum OH_AudioCaptureSourceType {
98     /* Invalid audio source */
99     OH_SOURCE_INVALID = -1,
100     /* Default audio source */
101     OH_SOURCE_DEFAULT = 0,
102     /* Microphone */
103     OH_MIC = 1,
104     /* inner all PlayBack */
105     OH_ALL_PLAYBACK = 2,
106     /* inner app PlayBack */
107     OH_APP_PLAYBACK = 3,
108 } OH_AudioCaptureSourceType;
109 
110 /**
111  * @brief Enumerates audio codec formats.
112  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
113  *
114  * @since 10
115  * @version 1.0
116  */
117 typedef enum OH_AudioCodecFormat {
118     /* Default format */
119     OH_AUDIO_DEFAULT = 0,
120     /* Advanced Audio Coding Low Complexity (AAC-LC) */
121     OH_AAC_LC = 3,
122     /* Invalid value */
123     OH_AUDIO_CODEC_FORMAT_BUTT,
124 } OH_AudioCodecFormat;
125 
126 /**
127  * @brief Enumerates video codec formats.
128  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
129  *
130  * @since 10
131  * @version 1.0
132  */
133 typedef enum OH_VideoCodecFormat {
134     /* Default format */
135     OH_VIDEO_DEFAULT = 0,
136     /* H.264 */
137     OH_H264 = 2,
138     /* H.265/HEVC */
139     OH_H265 = 4,
140     /* MPEG4 */
141     OH_MPEG4 = 6,
142     /* VP8 */
143     OH_VP8 = 8,
144     /* VP9 */
145     OH_VP9 = 10,
146     /* Invalid format */
147     OH_VIDEO_CODEC_FORMAT_BUTT,
148 } OH_VideoCodecFormat;
149 
150 /**
151  * @brief Enumerates screen capture data type.
152  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
153  *
154  * @since 10
155  * @version 1.0
156  */
157 typedef enum OH_DataType {
158     /* YUV/RGBA/PCM, etc. original stream */
159     OH_ORIGINAL_STREAM = 0,
160     /* h264/AAC, etc. encoded stream */
161     OH_ENCODED_STREAM = 1,
162     /* mp4 file */
163     OH_CAPTURE_FILE = 2,
164     OH_INVAILD = -1
165 } OH_DataType;
166 
167 /**
168  * @brief Enumerates video source types.
169  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
170  *
171  * @since 10
172  * @version 1.0
173  */
174 typedef enum OH_VideoSourceType {
175     /* Unsupported App Usage. */
176     /* YUV video data provided through graphic */
177     OH_VIDEO_SOURCE_SURFACE_YUV = 0,
178     /* Raw encoded data provided through graphic */
179     OH_VIDEO_SOURCE_SURFACE_ES,
180     /* RGBA video data provided through graphic */
181     OH_VIDEO_SOURCE_SURFACE_RGBA,
182     /* Invalid value */
183     OH_VIDEO_SOURCE_BUTT
184 } OH_VideoSourceType;
185 
186 /**
187  * @brief Enumerates the container format types.
188  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
189  *
190  * @since 10
191  * @version 1.0
192  */
193 typedef enum OH_ContainerFormatType {
194     /* Audio format type -- m4a */
195     CFT_MPEG_4A = 0,
196     /* Video format type -- mp4 */
197     CFT_MPEG_4 = 1
198 } OH_ContainerFormatType;
199 
200 /**
201  * @brief Audio capture info struct
202  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
203  *
204  * @since 10
205  * @version 1.0
206  */
207 typedef struct OH_AudioCaptureInfo {
208     /* Audio capture sample rate info */
209     int32_t audioSampleRate;
210     /* Audio capture channel info */
211     int32_t audioChannels;
212     /* Audio capture source type */
213     OH_AudioCaptureSourceType audioSource;
214 } OH_AudioCaptureInfo;
215 
216 /**
217  * @brief Audio encoder info
218  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
219  *
220  * @since 10
221  * @version 1.0
222  */
223 typedef struct OH_AudioEncInfo {
224     /* Audio encoder bitrate */
225     int32_t audioBitrate;
226     /* Audio codec format */
227     OH_AudioCodecFormat audioCodecformat;
228 } OH_AudioEncInfo;
229 
230 /**
231  * @brief The audio info of avscreeencapture
232  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
233  *
234  * @since 10
235  * @version 1.0
236  */
237 typedef struct OH_AudioInfo {
238     /* Audio capture info of microphone */
239     OH_AudioCaptureInfo micCapInfo;
240     /* Audio capture info of inner */
241     OH_AudioCaptureInfo innerCapInfo;
242     /* Audio encoder info, no need to set, while dataType = OH_ORIGINAL_STREAM */
243     OH_AudioEncInfo audioEncInfo;
244 } OH_AudioInfo;
245 
246 /**
247  * @brief Video capture info
248  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
249  *
250  * @since 10
251  * @version 1.0
252  */
253 typedef struct OH_VideoCaptureInfo {
254     /* Display id, should be set while captureMode = CAPTURE_SPECIFIED_SCREEN */
255     uint64_t displayId;
256     /* The  ids of mission, should be set while captureMode = CAPTURE_SPECIFIED_WINDOW */
257     int32_t *missionIDs;
258     /* Mission ids length, should be set while captureMode = CAPTURE_SPECIFIED_WINDOW */
259     int32_t missionIDsLen;
260     /* Video frame width of avscreeencapture */
261     int32_t videoFrameWidth;
262     /* Video frame height of avscreeencapture */
263     int32_t videoFrameHeight;
264     /* Video source type of avscreeencapture */
265     OH_VideoSourceType videoSource;
266 } OH_VideoCaptureInfo;
267 
268 /**
269  * @brief Videoc encoder info
270  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
271  *
272  * @since 10
273  * @version 1.0
274  */
275 typedef struct OH_VideoEncInfo {
276     /* Video encoder format */
277     OH_VideoCodecFormat videoCodec;
278     /* Video encoder bitrate */
279     int32_t videoBitrate;
280     /* Video encoder frame rate */
281     int32_t videoFrameRate;
282 } OH_VideoEncInfo;
283 
284 /**
285  * @brief Video info
286  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
287  *
288  * @since 10
289  * @version 1.0
290  */
291 typedef struct OH_VideoInfo {
292     /* Video capture info */
293     OH_VideoCaptureInfo videoCapInfo;
294     /* Video encoder info */
295     OH_VideoEncInfo videoEncInfo;
296 } OH_VideoInfo;
297 
298 /**
299  * @brief Recorder file info
300  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
301  *
302  * @since 10
303  * @version 1.0
304  */
305 typedef struct OH_RecorderInfo {
306     /* Recorder file url */
307     char *url;
308     /* Recorder file url length */
309     uint32_t urlLen;
310     /* Recorder file format */
311     OH_ContainerFormatType fileFormat;
312 } OH_RecorderInfo;
313 
314 /**
315  * @brief AV screeen capture config info
316  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
317  *
318  * @since 10
319  * @version 1.0
320  */
321 typedef struct OH_AVScreenCaptureConfig {
322     OH_CaptureMode captureMode;
323     OH_DataType dataType;
324     OH_AudioInfo audioInfo;
325     OH_VideoInfo videoInfo;
326     /* should be set, while dataType = OH_CAPTURE_FILE */
327     OH_RecorderInfo recorderInfo;
328 } OH_AVScreenCaptureConfig;
329 
330 /**
331  * @brief When an error occurs in the running of the OH_AVScreenCapture instance, the function pointer will be called
332  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
333  * @param capture Pointer to an OH_AVScreenCapture instance
334  * @param errorCode specific error code
335  *
336  * @since 10
337  * @version 1.0
338  */
339 typedef void (*OH_AVScreenCaptureOnError)(OH_AVScreenCapture *capture, int32_t errorCode);
340 
341 /**
342  * @brief When audio buffer is available during the operation of OH_AVScreenCapture, the function pointer will
343  * be called.
344  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
345  * @param capture Pointer to an OH_AVScreenCapture instance
346  * @param isReady Information describing whether audio buffer is available
347  * @param type Information describing the audio source type
348  *
349  * @since 10
350  * @version 1.0
351  */
352 typedef void (*OH_AVScreenCaptureOnAudioBufferAvailable)(OH_AVScreenCapture *capture, bool isReady,
353     OH_AudioCaptureSourceType type);
354 
355 /**
356  * @brief When video buffer is available during the operation of OH_AVScreenCapture, the function pointer will
357  * be called.
358  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
359  * @param capture Pointer to an OH_AVScreenCapture instance
360  * @param isReady Information describing whether video buffer is available
361  *
362  * @since 10
363  * @version 1.0
364  */
365 typedef void (*OH_AVScreenCaptureOnVideoBufferAvailable)(OH_AVScreenCapture *capture, bool isReady);
366 
367 /**
368  * @brief A collection of all callback function pointers in OH_AVScreenCapture. Register an instance of this
369  * structure to the OH_AVScreenCapture instance, and process the information reported through the callback to ensure the
370  * normal operation of OH_AVScreenCapture.
371  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
372  * @param onError Monitor OH_AVScreenCapture operation errors, refer to {@link OH_AVScreenCaptureOnError}
373  * @param onAudioBufferAvailable Monitor audio buffer, refer to {@link OH_AVScreenCaptureOnAudioBufferAvailable}
374  * @param onVideoBufferAvailable Monitor video buffer, refer to {@link OH_AVScreenCaptureOnVideoBufferAvailable}
375  *
376  * @since 10
377  * @version 1.0
378  */
379 typedef struct OH_AVScreenCaptureCallback {
380     OH_AVScreenCaptureOnError onError;
381     OH_AVScreenCaptureOnAudioBufferAvailable onAudioBufferAvailable;
382     OH_AVScreenCaptureOnVideoBufferAvailable onVideoBufferAvailable;
383 } OH_AVScreenCaptureCallback;
384 
385 /**
386  * @brief avscreeencapture rect info
387  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
388  *
389  * @since 10
390  * @version 1.0
391  */
392 typedef struct OH_Rect {
393     /* X-coordinate of screen recording */
394     int32_t x;
395     /* y-coordinate of screen recording */
396     int32_t y;
397     /* Width of screen recording */
398     int32_t width;
399     /* Height of screen recording */
400     int32_t height;
401 } OH_Rect;
402 
403 
404 /**
405  * @brief Audiobuffer struct info
406  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
407  *
408  * @since 10
409  * @version 1.0
410  */
411 typedef struct OH_AudioBuffer {
412     /* Audio buffer memory block  */
413     uint8_t *buf;
414     /* Audio buffer memory block size */
415     int32_t size;
416     /* Audio buffer timestamp info */
417     int64_t timestamp;
418     /* Audio capture source type */
419     OH_AudioCaptureSourceType type;
420 } OH_AudioBuffer;
421 
422 /**
423  * @brief Enumerates screen capture state code.
424  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
425  *
426  * @since 12
427  * @version 1.0
428  */
429 typedef enum OH_AVScreenCaptureStateCode {
430     /* Screen capture started by user */
431     OH_SCREEN_CAPTURE_STATE_STARTED = 0,
432     /* Screen capture canceled by user */
433     OH_SCREEN_CAPTURE_STATE_CANCELED = 1,
434     /* ScreenCapture stopped by user */
435     OH_SCREEN_CAPTURE_STATE_STOPPED_BY_USER = 2,
436     /* ScreenCapture interrupted by other screen capture */
437     OH_SCREEN_CAPTURE_STATE_INTERRUPTED_BY_OTHER = 3,
438     /* ScreenCapture stopped by SIM call */
439     OH_SCREEN_CAPTURE_STATE_STOPPED_BY_CALL = 4,
440     /* Microphone is temporarily unavailable */
441     OH_SCREEN_CAPTURE_STATE_MIC_UNAVAILABLE = 5,
442     /* Microphone is muted by user */
443     OH_SCREEN_CAPTURE_STATE_MIC_MUTED_BY_USER = 6,
444     /* Microphone is unmuted by user */
445     OH_SCREEN_CAPTURE_STATE_MIC_UNMUTED_BY_USER = 7,
446     /* Current captured screen has private window */
447     OH_SCREEN_CAPTURE_STATE_ENTER_PRIVATE_SCENE = 8,
448     /* Private window disappeared on current captured screen*/
449     OH_SCREEN_CAPTURE_STATE_EXIT_PRIVATE_SCENE = 9,
450     /* ScreenCapture stopped by user switches */
451     OH_SCREEN_CAPTURE_STATE_STOPPED_BY_USER_SWITCHES = 10,
452 } OH_AVScreenCaptureStateCode;
453 
454 /**
455  * @brief Enumerates screen capture buffer type.
456  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
457  *
458  * @since 12
459  * @version 1.0
460  */
461 typedef enum OH_AVScreenCaptureBufferType {
462     /* Buffer of video data from screen */
463     OH_SCREEN_CAPTURE_BUFFERTYPE_VIDEO = 0,
464     /* Buffer of audio data from inner capture */
465     OH_SCREEN_CAPTURE_BUFFERTYPE_AUDIO_INNER = 1,
466     /* Buffer of audio data from microphone */
467     OH_SCREEN_CAPTURE_BUFFERTYPE_AUDIO_MIC = 2,
468 } OH_AVScreenCaptureBufferType;
469 
470 /**
471  * @brief Enumerates screen capture buffer type.
472  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
473  *
474  * @since 12
475  * @version 1.0
476  */
477 typedef enum OH_AVScreenCaptureFilterableAudioContent {
478     /* Audio content of notification sound */
479     OH_SCREEN_CAPTURE_NOTIFICATION_AUDIO = 0,
480     /* Audio content of the sound of the app itself */
481     OH_SCREEN_CAPTURE_CURRENT_APP_AUDIO = 1,
482 } OH_AVScreenCaptureFilterableAudioContent;
483 
484 /**
485  * @brief When state of OH_AVScreenCapture is changed, the function pointer will be called.
486  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
487  * @param capture Pointer to an OH_AVScreenCapture instance
488  * @param stateCode Information describing current state, see {@link OH_AVScreenCaptureStateCode}
489  * @param userData Pointer to user specific data
490  *
491  * @since 12
492  * @version 1.0
493  */
494 typedef void (*OH_AVScreenCapture_OnStateChange)(struct OH_AVScreenCapture *capture,
495     OH_AVScreenCaptureStateCode stateCode, void *userData);
496 
497 /**
498  * @brief When an error occurs in the running of the OH_AVScreenCapture instance, the function pointer will be called
499  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
500  * @param capture Pointer to an OH_AVScreenCapture instance
501  * @param errorCode specific error code
502  * @param userData Pointer to user specific data
503  *
504  * @since 12
505  * @version 1.0
506  */
507 typedef void (*OH_AVScreenCapture_OnError)(OH_AVScreenCapture *capture, int32_t errorCode, void *userData);
508 
509 /**
510  * @brief When data is ready from the OH_AVScreenCapture instance, the function pointer will be called
511  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
512  * @param capture Pointer to an OH_AVScreenCapture instance
513  * @param buffer Pointer to a buffer containing media data
514  * @param bufferType Data type of the buffer, see {@link OH_AVScreenCaptureBufferType}
515  * @param timestamp Timestamp of the buffer
516  * @param userData Pointer to user specific data
517  *
518  * @since 12
519  * @version 1.0
520  */
521 typedef void (*OH_AVScreenCapture_OnBufferAvailable)(OH_AVScreenCapture *capture, OH_AVBuffer *buffer,
522     OH_AVScreenCaptureBufferType bufferType, int64_t timestamp, void *userData);
523 
524 #ifdef __cplusplus
525 }
526 #endif
527 
528 #endif // NATIVE_AVSCREEN_CAPTURE_BASE_H
529 /** @} */