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_BASE_H
17 #define NATIVE_AVSCREEN_CAPTURE_BASE_H
18 
19 #include <stdint.h>
20 #include "native_avbuffer.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /**
27  * @brief Nativebuffer of avscreeencapture that from graphics.
28  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
29  *
30  * @since 10
31  * @version 1.0
32  */
33 typedef struct OH_NativeBuffer OH_NativeBuffer;
34 
35 /**
36  * @brief Initialization of avscreeencapture
37  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
38  *
39  * @since 10
40  * @version 1.0
41  */
42 typedef struct OH_AVScreenCapture OH_AVScreenCapture;
43 
44 /**
45  * @brief Initialization of OH_AVScreenCapture_ContentFilter
46  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
47  *
48  * @since 12
49  * @version 1.0
50  */
51 typedef struct OH_AVScreenCapture_ContentFilter OH_AVScreenCapture_ContentFilter;
52 
53 /**
54  * @brief Enumerates screen capture mode.
55  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
56  *
57  * @since 10
58  * @version 1.0
59  */
60 typedef enum OH_CaptureMode {
61     /* capture home screen */
62     OH_CAPTURE_HOME_SCREEN = 0,
63     /* capture a specified screen */
64     OH_CAPTURE_SPECIFIED_SCREEN = 1,
65     /* capture a specified window */
66     OH_CAPTURE_SPECIFIED_WINDOW = 2,
67     OH_CAPTURE_INVAILD = -1
68 } OH_CaptureMode;
69 
70 /**
71  * @brief Enumerates audio cap source type.
72  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
73  *
74  * @since 10
75  * @version 1.0
76  */
77 typedef enum OH_AudioCaptureSourceType {
78     /* Invalid audio source */
79     OH_SOURCE_INVALID = -1,
80     /* Default audio source */
81     OH_SOURCE_DEFAULT = 0,
82     /* Microphone */
83     OH_MIC = 1,
84     /* inner all PlayBack */
85     OH_ALL_PLAYBACK = 2,
86     /* inner app PlayBack */
87     OH_APP_PLAYBACK = 3,
88 } OH_AudioCaptureSourceType;
89 
90 /**
91  * @brief Enumerates audio codec formats.
92  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
93  *
94  * @since 10
95  * @version 1.0
96  */
97 typedef enum OH_AudioCodecFormat {
98     /* Default format */
99     OH_AUDIO_DEFAULT = 0,
100     /* Advanced Audio Coding Low Complexity (AAC-LC) */
101     OH_AAC_LC = 3,
102     /* Invalid value */
103     OH_AUDIO_CODEC_FORMAT_BUTT,
104 } OH_AudioCodecFormat;
105 
106 /**
107  * @brief Enumerates video codec formats.
108  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
109  *
110  * @since 10
111  * @version 1.0
112  */
113 typedef enum OH_VideoCodecFormat {
114     /* Default format */
115     OH_VIDEO_DEFAULT = 0,
116     /* H.264 */
117     OH_H264 = 2,
118     /* H.265/HEVC */
119     OH_H265 = 4,
120     /* MPEG4 */
121     OH_MPEG4 = 6,
122     /* VP8 */
123     OH_VP8 = 8,
124     /* VP9 */
125     OH_VP9 = 10,
126     /* Invalid format */
127     OH_VIDEO_CODEC_FORMAT_BUTT,
128 } OH_VideoCodecFormat;
129 
130 /**
131  * @brief Enumerates screen capture data type.
132  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
133  *
134  * @since 10
135  * @version 1.0
136  */
137 typedef enum OH_DataType {
138     /* YUV/RGBA/PCM, etc. original stream */
139     OH_ORIGINAL_STREAM = 0,
140     /* h264/AAC, etc. encoded stream */
141     OH_ENCODED_STREAM = 1,
142     /* mp4 file */
143     OH_CAPTURE_FILE = 2,
144     OH_INVAILD = -1
145 } OH_DataType;
146 
147 /**
148  * @brief Enumerates video source types.
149  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
150  *
151  * @since 10
152  * @version 1.0
153  */
154 typedef enum OH_VideoSourceType {
155     /* Unsupported App Usage. */
156     /* YUV video data provided through graphic */
157     OH_VIDEO_SOURCE_SURFACE_YUV = 0,
158     /* Raw encoded data provided through graphic */
159     OH_VIDEO_SOURCE_SURFACE_ES,
160     /* RGBA video data provided through graphic */
161     OH_VIDEO_SOURCE_SURFACE_RGBA,
162     /* Invalid value */
163     OH_VIDEO_SOURCE_BUTT
164 } OH_VideoSourceType;
165 
166 /**
167  * @brief Enumerates the container format types.
168  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
169  *
170  * @since 10
171  * @version 1.0
172  */
173 typedef enum OH_ContainerFormatType {
174     /* Audio format type -- m4a */
175     CFT_MPEG_4A = 0,
176     /* Video format type -- mp4 */
177     CFT_MPEG_4 = 1
178 } OH_ContainerFormatType;
179 
180 /**
181  * @brief Audio capture info struct
182  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
183  *
184  * @since 10
185  * @version 1.0
186  */
187 typedef struct OH_AudioCaptureInfo {
188     /* Audio capture sample rate info */
189     int32_t audioSampleRate;
190     /* Audio capture channel info */
191     int32_t audioChannels;
192     /* Audio capture source type */
193     OH_AudioCaptureSourceType audioSource;
194 } OH_AudioCaptureInfo;
195 
196 /**
197  * @brief Audio encoder info
198  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
199  *
200  * @since 10
201  * @version 1.0
202  */
203 typedef struct OH_AudioEncInfo {
204     /* Audio encoder bitrate */
205     int32_t audioBitrate;
206     /* Audio codec format */
207     OH_AudioCodecFormat audioCodecformat;
208 } OH_AudioEncInfo;
209 
210 /**
211  * @brief The audio info of avscreeencapture
212  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
213  *
214  * @since 10
215  * @version 1.0
216  */
217 typedef struct OH_AudioInfo {
218     /* Audio capture info of microphone */
219     OH_AudioCaptureInfo micCapInfo;
220     /* Audio capture info of inner */
221     OH_AudioCaptureInfo innerCapInfo;
222     /* Audio encoder info, no need to set, while dataType = OH_ORIGINAL_STREAM */
223     OH_AudioEncInfo audioEncInfo;
224 } OH_AudioInfo;
225 
226 /**
227  * @brief Video capture info
228  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
229  *
230  * @since 10
231  * @version 1.0
232  */
233 typedef struct OH_VideoCaptureInfo {
234     /* Display id, should be set while captureMode = CAPTURE_SPECIFIED_SCREEN */
235     uint64_t displayId;
236     /* The  ids of mission, should be set while captureMode = CAPTURE_SPECIFIED_WINDOW */
237     int32_t *missionIDs;
238     /* Mission ids length, should be set while captureMode = CAPTURE_SPECIFIED_WINDOW */
239     int32_t missionIDsLen;
240     /* Video frame width of avscreeencapture */
241     int32_t videoFrameWidth;
242     /* Video frame height of avscreeencapture */
243     int32_t videoFrameHeight;
244     /* Video source type of avscreeencapture */
245     OH_VideoSourceType videoSource;
246 } OH_VideoCaptureInfo;
247 
248 /**
249  * @brief Videoc encoder info
250  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
251  *
252  * @since 10
253  * @version 1.0
254  */
255 typedef struct OH_VideoEncInfo {
256     /* Video encoder format */
257     OH_VideoCodecFormat videoCodec;
258     /* Video encoder bitrate */
259     int32_t videoBitrate;
260     /* Video encoder frame rate */
261     int32_t videoFrameRate;
262 } OH_VideoEncInfo;
263 
264 /**
265  * @brief Video info
266  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
267  *
268  * @since 10
269  * @version 1.0
270  */
271 typedef struct OH_VideoInfo {
272     /* Video capture info */
273     OH_VideoCaptureInfo videoCapInfo;
274     /* Video encoder info */
275     OH_VideoEncInfo videoEncInfo;
276 } OH_VideoInfo;
277 
278 /**
279  * @brief Recorder file info
280  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
281  *
282  * @since 10
283  * @version 1.0
284  */
285 typedef struct OH_RecorderInfo {
286     /* Recorder file url */
287     char *url;
288     /* Recorder file url length */
289     uint32_t urlLen;
290     /* Recorder file format */
291     OH_ContainerFormatType fileFormat;
292 } OH_RecorderInfo;
293 
294 /**
295  * @brief AV screeen capture config info
296  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
297  *
298  * @since 10
299  * @version 1.0
300  */
301 typedef struct OH_AVScreenCaptureConfig {
302     OH_CaptureMode captureMode;
303     OH_DataType dataType;
304     OH_AudioInfo audioInfo;
305     OH_VideoInfo videoInfo;
306     /* should be set, while dataType = OH_CAPTURE_FILE */
307     OH_RecorderInfo recorderInfo;
308 } OH_AVScreenCaptureConfig;
309 
310 /**
311  * @brief When an error occurs in the running of the OH_AVScreenCapture instance, the function pointer will be called
312  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
313  * @param capture Pointer to an OH_AVScreenCapture instance
314  * @param errorCode specific error code
315  *
316  * @since 10
317  * @version 1.0
318  * @deprecated since 12
319  * @useinstead {@link OH_AVScreenCapture_OnError}
320  */
321 typedef void (*OH_AVScreenCaptureOnError)(OH_AVScreenCapture *capture, int32_t errorCode);
322 
323 /**
324  * @brief When audio buffer is available during the operation of OH_AVScreenCapture, the function pointer will
325  * be called.
326  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
327  * @param capture Pointer to an OH_AVScreenCapture instance
328  * @param isReady Information describing whether audio buffer is available
329  * @param type Information describing the audio source type
330  *
331  * @since 10
332  * @version 1.0
333  * @deprecated since 12
334  * @useinstead {@link OH_AVScreenCapture_OnBufferAvailable}
335  */
336 typedef void (*OH_AVScreenCaptureOnAudioBufferAvailable)(OH_AVScreenCapture *capture, bool isReady,
337     OH_AudioCaptureSourceType type);
338 
339 /**
340  * @brief When video buffer is available during the operation of OH_AVScreenCapture, the function pointer will
341  * be called.
342  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
343  * @param capture Pointer to an OH_AVScreenCapture instance
344  * @param isReady Information describing whether video buffer is available
345  *
346  * @since 10
347  * @version 1.0
348  * @deprecated since 12
349  * @useinstead {@link OH_AVScreenCapture_OnBufferAvailable}
350  */
351 typedef void (*OH_AVScreenCaptureOnVideoBufferAvailable)(OH_AVScreenCapture *capture, bool isReady);
352 
353 /**
354  * @brief A collection of all callback function pointers in OH_AVScreenCapture. Register an instance of this
355  * structure to the OH_AVScreenCapture instance, and process the information reported through the callback to ensure the
356  * normal operation of OH_AVScreenCapture.
357  * @syscap SystemCapability.Multimedia.Media.AVScreenCapture
358  * @param onError Monitor OH_AVScreenCapture operation errors, refer to {@link OH_AVScreenCaptureOnError}
359  * @param onAudioBufferAvailable Monitor audio buffer, refer to {@link OH_AVScreenCaptureOnAudioBufferAvailable}
360  * @param onVideoBufferAvailable Monitor video buffer, refer to {@link OH_AVScreenCaptureOnVideoBufferAvailable}
361  *
362  * @since 10
363  * @version 1.0
364  * @deprecated since 12
365  * @useinstead {@link OH_AVScreenCapture_OnError} {@link OH_AVScreenCapture_OnBufferAvailable}
366  */
367 typedef struct OH_AVScreenCaptureCallback {
368     /**
369      * @deprecated since 12
370      * @useinstead {@link OH_AVScreenCapture_OnError}
371      */
372     OH_AVScreenCaptureOnError onError;
373     /**
374      * @deprecated since 12
375      * @useinstead {@link OH_AVScreenCapture_OnBufferAvailable}
376      */
377     OH_AVScreenCaptureOnAudioBufferAvailable onAudioBufferAvailable;
378     /**
379      * @deprecated since 12
380      * @useinstead {@link OH_AVScreenCapture_OnBufferAvailable}
381      */
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 filterable audio content.
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