• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# AVScreenCapture
2
3
4## Overview
5
6The **AVScreenCapture** module provides APIs for screen capture.
7
8**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
9
10**Since**
11
1210
13
14
15## Summary
16
17
18### Files
19
20| Name| Description|
21| -------- | -------- |
22| [native_avscreen_capture.h](native__avscreen__capture_8h.md) | Declares the native APIs used to create an **OH_AVScreenCapture** instance.<br>**File to include**: <multimedia/player_framework/native_avscreen_capture.h> <br>**Library**: libnative_avscreen_capture.so|
23| [native_avscreen_capture_base.h](native__avscreen__capture__base_8h.md) | Declares the common structs, character constants, and enums used for running screen capture.<br>**File to include**: <multimedia/player_framework/native_avscreen_capture_base.h><br>**Library**: libnative_avscreen_capture.so|
24| [native_avscreen_capture_errors.h](native__avscreen__capture__errors_8h.md) | Declares the error codes generated during screen capture.<br>**File to include**: <multimedia/player_framework/native_avscreen_capture_errors.h><br>**Library**: libnative_avscreen_capture.so|
25
26
27### Structs
28
29| Name| Description|
30| -------- | -------- |
31| [OH_AudioCaptureInfo](_o_h___audio_capture_info.md) | Defines audio capture information.|
32| [OH_AudioEncInfo](_o_h___audio_enc_info.md) | Defines audio encoding information.<br>**NOTE**: This struct is reserved and will be provided in later versions.|
33| [OH_AudioInfo](_o_h___audio_info.md) | Defines audio capture parameters.|
34| [OH_VideoCaptureInfo](_o_h___video_capture_info.md) | Defines video capture information.|
35| [OH_VideoEncInfo](_o_h___video_enc_info.md) | Defines video encoding information.<br>**NOTE**: This struct is reserved and will be provided in later versions.|
36| [OH_VideoInfo](_o_h___video_info.md) | Defines video capture parameters.|
37| [OH_RecorderInfo](_o_h___recorder_info.md) | Defines recording file information.<br>**NOTE**: This struct is reserved and will be provided in later versions.|
38| [OH_AVScreenCaptureConfig](_o_h___a_v_screen_capture_config.md) | Defines the screen capture configuration.|
39| [OH_AVScreenCaptureCallback](_o_h___a_v_screen_capture_callback.md) | Defines all the asynchronous callback function pointers of an **OH_AVScreenCapture** instance.|
40| [OH_Rect](_o_h___rect.md) | Defines the width, height, and image information of the rectangle used for screen capture.|
41| [OH_AudioBuffer](_o_h___audio_buffer.md) | Defines the configuration such as the size, type, and timestamp of audio data.|
42
43
44### Types
45
46| Name| Description|
47| -------- | -------- |
48| [OH_NativeBuffer](#oh_nativebuffer) | Defines the native video stream class for screen capture.|
49| [OH_AVScreenCapture](#oh_avscreencapture) | Defines a screen capture instance used to obtain original video and audio streams.|
50| [OH_CaptureMode](#oh_capturemode) | Defines an enum that enumerates the screen capture modes.|
51| [OH_AudioCaptureSourceType](#oh_audiocapturesourcetype) | Defines an enum that enumerates the audio source types during screen capture.|
52| [OH_AudioCodecFormat](#oh_audiocodecformat) | Defines an enum that enumerates the audio encoding formats.|
53| [OH_VideoCodecFormat](#oh_videocodecformat) | Defines an enum that enumerates the video encoding formats.|
54| [OH_DataType](#oh_datatype) | Defines an enum that enumerates the data types of screen capture streams.|
55| [OH_VideoSourceType](#oh_videosourcetype) | Defines an enum that enumerates the video source formats.|
56| [OH_ContainerFormatType](#oh_containerformattype) | Defines an enum that enumerates the types of files generated during screen capture.<br>**NOTE**: This type is reserved and will be provided in later versions.|
57| [OH_AudioCaptureInfo](#oh_audiocaptureinfo) | Defines audio capture information.|
58| [OH_AudioEncInfo](#oh_audioencinfo) | Defines audio encoding information.<br>**NOTE**: This type is reserved and will be provided in later versions.|
59| [OH_AudioInfo](#oh_audioinfo) | Defines audio capture parameters.|
60| [OH_VideoCaptureInfo](#oh_videocaptureinfo) | Defines video capture information.|
61| [OH_VideoEncInfo](#oh_videoencinfo) | Defines video encoding information.<br>**NOTE**: This type is reserved and will be provided in later versions.|
62| [OH_VideoInfo](#oh_videoinfo) | Defines video capture parameters.|
63| [OH_RecorderInfo](#oh_recorderinfo) | Defines recording file information.|
64| [OH_AVScreenCaptureConfig](#oh_avscreencaptureconfig) | Defines the screen capture configuration.|
65| (\*[OH_AVScreenCaptureOnError](#oh_avscreencaptureonerror)) ([OH_AVScreenCapture](#oh_avscreencapture) \*capture, int32_t errorCode) | Defines a pointer to a callback function that is called when an error occurs during the running of an **OH_AVScreenCapture** instance.|
66| (\*[OH_AVScreenCaptureOnAudioBufferAvailable](#oh_avscreencaptureonaudiobufferavailable)) ([OH_AVScreenCapture](#oh_avscreencapture) \*capture, bool isReady, [OH_AudioCaptureSourceType](#oh_audiocapturesourcetype) type) | Defines a pointer to a callback function that is called when an audio buffer is available during the running of an **OH_AVScreenCapture** instance.|
67| (\*[OH_AVScreenCaptureOnVideoBufferAvailable](#oh_avscreencaptureonvideobufferavailable)) ([OH_AVScreenCapture](#oh_avscreencapture) \*capture, bool isReady) | Defines a pointer to a callback function that is called when a video buffer is available during the running of an **OH_AVScreenCapture** instance.|
68| [OH_AVScreenCaptureCallback](#oh_avscreencapturecallback) | Defines all the asynchronous callback function pointers of an **OH_AVScreenCapture** instance.|
69| [OH_Rect](#oh_rect) | Defines the width, height, and image information of the rectangle used for screen capture.|
70| [OH_AudioBuffer](#oh_audiobuffer) | Defines the configuration such as the size, type, and timestamp of audio data.|
71| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) | Defines an enum that enumerates the error codes generated during screen recording.|
72
73
74### Enums
75
76| Name| Description|
77| -------- | -------- |
78| [OH_CaptureMode](#oh_capturemode) { OH_CAPTURE_HOME_SCREEN = 0, OH_CAPTURE_SPECIFIED_SCREEN = 1, OH_CAPTURE_SPECIFIED_WINDOW = 2, OH_CAPTURE_INVAILD = -1 } | Enumerates the screen capture modes.|
79| [OH_AudioCaptureSourceType](#oh_audiocapturesourcetype) {<br>OH_SOURCE_INVALID = -1, OH_SOURCE_DEFAULT = 0, OH_MIC = 1, OH_ALL_PLAYBACK = 2,<br>OH_APP_PLAYBACK = 3<br>} | Enumerates the audio source types during screen capture.|
80| [OH_AudioCodecFormat](#oh_audiocodecformat) { OH_AUDIO_DEFAULT = 0, OH_AAC_LC = 3, OH_AUDIO_CODEC_FORMAT_BUTT } | Enumerates the audio encoding formats.|
81| [OH_VideoCodecFormat](#oh_videocodecformat) {<br>OH_VIDEO_DEFAULT = 0, OH_H264 = 2, OH_H265 = 4, OH_MPEG4 = 6,<br>OH_VP8 = 8, OH_VP9 = 10, OH_VIDEO_CODEC_FORMAT_BUTT<br>} | Enumerates the video encoding formats.|
82| [OH_DataType](#oh_datatype) { OH_ORIGINAL_STREAM = 0, OH_ENCODED_STREAM = 1, OH_CAPTURE_FILE = 2, OH_INVAILD = -1 } | Enumerates the data types of screen capture streams.|
83| [OH_VideoSourceType](#oh_videosourcetype) { OH_VIDEO_SOURCE_SURFACE_YUV = 0, OH_VIDEO_SOURCE_SURFACE_ES, OH_VIDEO_SOURCE_SURFACE_RGBA, OH_VIDEO_SOURCE_BUTT } | Enumerates the video source formats.|
84| [OH_ContainerFormatType](#oh_containerformattype) { CFT_MPEG_4A = 0, CFT_MPEG_4 = 1 } | Enumerates the types of files generated during screen capture.<br>**NOTE**: This enum is reserved and will be provided in later versions.|
85| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) {<br>AV_SCREEN_CAPTURE_ERR_BASE = 0, AV_SCREEN_CAPTURE_ERR_OK = AV_SCREEN_CAPTURE_ERR_BASE, AV_SCREEN_CAPTURE_ERR_NO_MEMORY = AV_SCREEN_CAPTURE_ERR_BASE + 1, AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT = AV_SCREEN_CAPTURE_ERR_BASE + 2,<br>AV_SCREEN_CAPTURE_ERR_INVALID_VAL = AV_SCREEN_CAPTURE_ERR_BASE + 3, AV_SCREEN_CAPTURE_ERR_IO = AV_SCREEN_CAPTURE_ERR_BASE + 4, AV_SCREEN_CAPTURE_ERR_TIMEOUT = AV_SCREEN_CAPTURE_ERR_BASE + 5, AV_SCREEN_CAPTURE_ERR_UNKNOWN = AV_SCREEN_CAPTURE_ERR_BASE + 6,<br>AV_SCREEN_CAPTURE_ERR_SERVICE_DIED = AV_SCREEN_CAPTURE_ERR_BASE + 7, AV_SCREEN_CAPTURE_ERR_INVALID_STATE = AV_SCREEN_CAPTURE_ERR_BASE + 8, AV_SCREEN_CAPTURE_ERR_UNSUPPORT = AV_SCREEN_CAPTURE_ERR_BASE + 9, AV_SCREEN_CAPTURE_ERR_EXTEND_START = AV_SCREEN_CAPTURE_ERR_BASE + 100<br>} | Enumerates the error codes generated during screen recording.|
86
87
88### Functions
89
90| Name| Description|
91| -------- | -------- |
92| [OH_AVScreenCapture_Create](#oh_avscreencapture_create) (void) | Creates an **OH_AVScreenCapture** instance.|
93| [OH_AVScreenCapture_Init](#oh_avscreencapture_init) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture, [OH_AVScreenCaptureConfig](_o_h___a_v_screen_capture_config.md) config) | Initializes parameters related to an **OH_AVScreenCapture** instance.|
94| [OH_AVScreenCapture_StartScreenCapture](#oh_avscreencapture_startscreencapture) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture) | Starts screen capture and collects original streams. After calling this function, the application can use the callback listeners **OH_AVScreenCaptureOnAudioBufferAvailable** and **OH_AVScreenCaptureOnVideoBufferAvailable** to check whether streams are generated.|
95| [OH_AVScreenCapture_StopScreenCapture](#oh_avscreencapture_stopscreencapture) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture) | Stops screen capture. This function is used in pair with **OH_AVScreenCapture_StartScreenCapture**. After calling this function, the application stops screen capture or screen share and releases the microphone.|
96| [OH_AVScreenCapture_StartScreenRecording](#oh_avscreencapture_startscreenrecording) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture) | Starts screen recording and collects encoded streams.<br>**NOTE**: This function is reserved and will be provided in later versions.|
97| [OH_AVScreenCapture_StopScreenRecording](#oh_avscreencapture_stopscreenrecording) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture) | Stops screen recording. This function is used in pair with **OH_AVScreenCapture_StartScreenRecording**.<br>**NOTE**: This function is reserved and will be provided in later versions.|
98| [OH_AVScreenCapture_AcquireAudioBuffer](#oh_avscreencapture_acquireaudiobuffer) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture, [OH_AudioBuffer](_o_h___audio_buffer.md) \*\*audiobuffer, [OH_AudioCaptureSourceType](#oh_audiocapturesourcetype) type) | Obtains an audio buffer. When calling this function, the application must allocate the memory of the corresponding struct size to the audio buffer.|
99| [OH_AVScreenCapture_AcquireVideoBuffer](#oh_avscreencapture_acquirevideobuffer) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture, int32_t \*fence, int64_t \*timestamp, struct [OH_Rect](_o_h___rect.md) \*region) | Obtains a video buffer. An application can call this function to obtain information such as the video buffer and timestamp.|
100| [OH_AVScreenCapture_ReleaseAudioBuffer](#oh_avscreencapture_releaseaudiobuffer) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture, [OH_AudioCaptureSourceType](#oh_audiocapturesourcetype) type) | Releases an audio buffer.|
101| [OH_AVScreenCapture_ReleaseVideoBuffer](#oh_avscreencapture_releasevideobuffer) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture) | Releases a video buffer.|
102| [OH_AVScreenCapture_SetCallback](#oh_avscreencapture_setcallback) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture, struct [OH_AVScreenCaptureCallback](_o_h___a_v_screen_capture_callback.md) callback) | Sets a callback to listen for available video buffers and audio buffers and errors that occur during the function calling.|
103| [OH_AVScreenCapture_Release](#oh_avscreencapture_release) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture) | Releases an **OH_AVScreenCapture** instance. This function is used in pair with **OH_AVScreenCapture_Create**.|
104| [OH_AVScreenCapture_SetMicrophoneEnabled](#oh_avscreencapture_setmicrophoneenabled) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture, bool isMicrophone) | Enables or disables the microphone.|
105
106
107## Type Description
108
109
110### OH_AudioBuffer
111
112```
113typedef struct OH_AudioBuffer OH_AudioBuffer
114```
115
116**Description**
117
118Defines the configuration such as the size, type, and timestamp of audio data.
119
120**System capability**
121
122SystemCapability.Multimedia.Media.AVScreenCapture
123
124
125### OH_AudioCaptureInfo
126
127```
128typedef struct OH_AudioCaptureInfo OH_AudioCaptureInfo
129```
130
131**Description**
132
133Defines audio capture information.
134
135**System capability**
136
137SystemCapability.Multimedia.Media.AVScreenCapture
138
139
140### OH_AudioCaptureSourceType
141
142```
143typedef enum OH_AudioCaptureSourceType OH_AudioCaptureSourceType
144```
145
146**Description**
147
148Defines an enum that enumerates the audio source types during screen capture.
149
150**System capability**
151
152SystemCapability.Multimedia.Media.AVScreenCapture
153
154
155### OH_AudioCodecFormat
156
157```
158typedef enum OH_AudioCodecFormat OH_AudioCodecFormat
159```
160
161**Description**
162
163Defines an enum that enumerates the audio encoding formats.
164
165**System capability**
166
167SystemCapability.Multimedia.Media.AVScreenCapture
168
169
170### OH_AudioEncInfo
171
172```
173typedef struct OH_AudioEncInfo OH_AudioEncInfo
174```
175
176**Description**
177
178Defines audio encoding information.
179
180> **NOTE**
181>
182> This type is reserved and will be provided in later versions.
183
184**System capability**
185
186SystemCapability.Multimedia.Media.AVScreenCapture
187
188
189### OH_AudioInfo
190
191```
192typedef struct OH_AudioInfo OH_AudioInfo
193```
194
195**Description**
196
197Defines audio capture parameters.
198
199**System capability**
200
201SystemCapability.Multimedia.Media.AVScreenCapture
202
203
204### OH_AVSCREEN_CAPTURE_ErrCode
205
206```
207typedef enum OH_AVSCREEN_CAPTURE_ErrCode OH_AVSCREEN_CAPTURE_ErrCode
208```
209
210**Description**
211
212Defines an enum that enumerates the error codes generated during screen recording.
213
214**System capability**
215
216SystemCapability.Multimedia.Media.AVScreenCapture
217
218
219### OH_AVScreenCapture
220
221```
222typedef struct OH_AVScreenCapture OH_AVScreenCapture
223```
224
225**Description**
226
227Defines a screen capture instance used to obtain original video and audio streams.
228
229**System capability**
230
231SystemCapability.Multimedia.Media.AVScreenCapture
232
233
234### OH_AVScreenCaptureCallback
235
236```
237typedef struct OH_AVScreenCaptureCallback OH_AVScreenCaptureCallback
238```
239
240**Description**
241
242Defines all the asynchronous callback function pointers of an **OH_AVScreenCapture** instance. To ensure the normal running of **OH_AVScreenCapture**, you must register the instance of this struct with the **OH_AVScreenCapture** instance and process the information reported by the callback functions.
243
244**Parameters**
245
246| Name| Description|
247| -------- | -------- |
248| onError | Pointer to a callback function that is called when an error occurs during the running of an **OH_AVScreenCapture** instance. For details, see [OH_AVScreenCaptureOnError](#oh_avscreencaptureonerror).|
249| onAudioBufferAvailable | Pointer to a callback function that is called when an audio buffer is available during the running of an **OH_AVScreenCapture** instance. For details, see [OH_AVScreenCaptureOnAudioBufferAvailable](#oh_avscreencaptureonaudiobufferavailable).|
250| onVideoBufferAvailable | Pointer to a callback function that is called when a video buffer is available during the running of an **OH_AVScreenCapture** instance. For details, see [OH_AVScreenCaptureOnVideoBufferAvailable](#oh_avscreencaptureonvideobufferavailable).|
251
252**System capability**
253
254SystemCapability.Multimedia.Media.AVScreenCapture
255
256
257### OH_AVScreenCaptureConfig
258
259```
260typedef struct OH_AVScreenCaptureConfig OH_AVScreenCaptureConfig
261```
262
263**Description**
264
265Defines the screen capture configuration.
266
267**System capability**
268
269SystemCapability.Multimedia.Media.AVScreenCapture
270
271
272### OH_AVScreenCaptureOnAudioBufferAvailable
273
274```
275typedef void(* OH_AVScreenCaptureOnAudioBufferAvailable) (OH_AVScreenCapture *capture, bool isReady, OH_AudioCaptureSourceType type)
276```
277
278**Description**
279
280Defines a pointer to a callback function that is called when an audio buffer is available during the running of an **OH_AVScreenCapture** instance.
281
282**Parameters**
283
284| Name| Description|
285| -------- | -------- |
286| capture | Pointer to an **OH_AVScreenCapture** instance.|
287| isReady | Whether the audio buffer is available.|
288| type | Audio source type.|
289
290**System capability**
291
292SystemCapability.Multimedia.Media.AVScreenCapture
293
294
295### OH_AVScreenCaptureOnError
296
297```
298typedef void(* OH_AVScreenCaptureOnError) (OH_AVScreenCapture *capture, int32_t errorCode)
299```
300
301**Description**
302
303Defines a pointer to a callback function that is called when an error occurs during the running of an **OH_AVScreenCapture** instance.
304
305**Parameters**
306
307| Name| Description|
308| -------- | -------- |
309| capture | Pointer to an **OH_AVScreenCapture** instance.|
310| errorCode | Error code.|
311
312**System capability**
313
314SystemCapability.Multimedia.Media.AVScreenCapture
315
316
317### OH_AVScreenCaptureOnVideoBufferAvailable
318
319```
320typedef void(* OH_AVScreenCaptureOnVideoBufferAvailable) (OH_AVScreenCapture *capture, bool isReady)
321```
322
323**Description**
324
325Defines a pointer to a callback function that is called when a video buffer is available during the running of an **OH_AVScreenCapture** instance.
326
327**Parameters**
328
329| Name| Description|
330| -------- | -------- |
331| capture | Pointer to an **OH_AVScreenCapture** instance.|
332| isReady | Whether the video buffer is available.|
333
334**System capability**
335
336SystemCapability.Multimedia.Media.AVScreenCapture
337
338
339### OH_CaptureMode
340
341```
342typedef enum OH_CaptureModeOH_CaptureMode
343```
344
345**Description**
346
347Defines an enum that enumerates the screen capture modes.
348
349**System capability**
350
351SystemCapability.Multimedia.Media.AVScreenCapture
352
353
354### OH_ContainerFormatType
355
356```
357typedef enum OH_ContainerFormatType OH_ContainerFormatType
358```
359
360**Description**
361
362Defines an enum that enumerates the types of files generated during screen capture.
363
364> **NOTE**
365>
366> This type is reserved and will be provided in later versions.
367
368**System capability**
369
370SystemCapability.Multimedia.Media.AVScreenCapture
371
372
373### OH_DataType
374
375```
376typedef enum OH_DataType OH_DataType
377```
378
379**Description**
380
381Defines an enum that enumerates the data types of screen capture streams.
382
383**System capability**
384
385SystemCapability.Multimedia.Media.AVScreenCapture
386
387
388### OH_NativeBuffer
389
390```
391typedef struct OH_NativeBuffer OH_NativeBuffer
392```
393
394**Description**
395
396Defines the native video stream class for screen capture.
397
398**System capability**
399
400SystemCapability.Multimedia.Media.AVScreenCapture
401
402
403### OH_RecorderInfo
404
405```
406typedef struct OH_RecorderInfo OH_RecorderInfo
407```
408
409**Description**
410
411Defines recording file information.
412
413**System capability**
414
415SystemCapability.Multimedia.Media.AVScreenCapture
416
417
418### OH_Rect
419
420```
421typedef struct OH_Rect OH_Rect
422```
423
424**Description**
425
426Defines the width, height, and image information of the rectangle used for screen capture.
427
428**System capability**
429
430SystemCapability.Multimedia.Media.AVScreenCapture
431
432
433### OH_VideoCaptureInfo
434
435```
436typedef struct OH_VideoCaptureInfo OH_VideoCaptureInfo
437```
438
439**Description**
440
441Defines video capture information.
442
443**System capability**
444
445SystemCapability.Multimedia.Media.AVScreenCapture
446
447
448### OH_VideoCodecFormat
449
450```
451typedef enum OH_VideoCodecFormat OH_VideoCodecFormat
452```
453
454**Description**
455
456Defines an enum that enumerates the video encoding formats.
457
458**System capability**
459
460SystemCapability.Multimedia.Media.AVScreenCapture
461
462
463### OH_VideoEncInfo
464
465```
466typedef struct OH_VideoEncInfo OH_VideoEncInfo
467```
468
469**Description**
470
471Defines video encoding parameters.
472
473> **NOTE**
474>
475> This type is reserved and will be provided in later versions.
476
477**System capability**
478
479SystemCapability.Multimedia.Media.AVScreenCapture
480
481
482### OH_VideoInfo
483
484```
485typedef struct OH_VideoInfo OH_VideoInfo
486```
487
488**Description**
489
490Defines video capture parameters.
491
492**System capability**
493
494SystemCapability.Multimedia.Media.AVScreenCapture
495
496
497### OH_VideoSourceType
498
499```
500typedef enum OH_VideoSourceType OH_VideoSourceType
501```
502
503**Description**
504
505Defines an enum that enumerates the video source formats.
506
507**System capability**
508
509SystemCapability.Multimedia.Media.AVScreenCapture
510
511
512## Enum Description
513
514
515### OH_AudioCaptureSourceType
516
517```
518enum OH_AudioCaptureSourceType
519```
520
521**Description**
522
523Enumerates the audio source types during screen capture.
524
525**System capability**
526
527SystemCapability.Multimedia.Media.AVScreenCapture
528
529| Value| Description|
530| -------- | -------- |
531| OH_SOURCE_INVALID | Invalid audio source.|
532| OH_SOURCE_DEFAULT | Default audio source. The default value is **MIC**.|
533| OH_MIC | External audio streams recorded by the microphone.|
534| OH_ALL_PLAYBACK | All internal audio streams played by the system.|
535| OH_APP_PLAYBACK | Internal audio streams played by a specified application.|
536
537
538### OH_AudioCodecFormat
539
540```
541enum OH_AudioCodecFormat
542```
543
544**Description**
545
546Enumerates the audio encoding formats.
547
548**System capability**
549
550SystemCapability.Multimedia.Media.AVScreenCapture
551
552| Value| Description|
553| -------- | -------- |
554| OH_AUDIO_DEFAULT | Default audio encoding format. The default value is **AAC_LC**.|
555| OH_AAC_LC | AAC_LC audio encoding.|
556| OH_AUDIO_CODEC_FORMAT_BUTT | Invalid format.|
557
558
559### OH_AVSCREEN_CAPTURE_ErrCode
560
561```
562enum OH_AVSCREEN_CAPTURE_ErrCode
563```
564
565**Description**
566
567Enumerates the error codes generated during screen recording.
568
569**System capability**
570
571SystemCapability.Multimedia.Media.AVScreenCapture
572
573| Value| Description|
574| -------- | -------- |
575| AV_SCREEN_CAPTURE_ERR_BASE | Basic value returned when an API call error occurs.|
576| AV_SCREEN_CAPTURE_ERR_OK | Operation successful.|
577| AV_SCREEN_CAPTURE_ERR_NO_MEMORY | Memory insufficient.|
578| AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT | Operation not allowed.|
579| AV_SCREEN_CAPTURE_ERR_INVALID_VAL | Invalid parameter.|
580| AV_SCREEN_CAPTURE_ERR_IO | Abnormal input and output streams.|
581| AV_SCREEN_CAPTURE_ERR_TIMEOUT | Network timeout.|
582| AV_SCREEN_CAPTURE_ERR_UNKNOWN | Unknown error.|
583| AV_SCREEN_CAPTURE_ERR_SERVICE_DIED | Media service terminated.|
584| AV_SCREEN_CAPTURE_ERR_INVALID_STATE | Unsupported operation in this state.|
585| AV_SCREEN_CAPTURE_ERR_UNSUPPORT | Unsupported interface.|
586| AV_SCREEN_CAPTURE_ERR_EXTEND_START | Unexpected error.|
587
588
589### OH_CaptureMode
590
591```
592enum OH_CaptureMode
593```
594
595**Description**
596
597Enumerates the screen capture modes.
598
599**System capability**
600
601SystemCapability.Multimedia.Media.AVScreenCapture
602
603| Value| Description|
604| -------- | -------- |
605| OH_CAPTURE_HOME_SCREEN | To capture the home screen.|
606| OH_CAPTURE_SPECIFIED_SCREEN | To capture a specified screen.<br>**NOTE**: This value is reserved and will be provided in later versions.|
607| OH_CAPTURE_SPECIFIED_WINDOW | To capture a specified window.<br>**NOTE**: This value is reserved and will be provided in later versions.|
608| OH_CAPTURE_INVAILD | Invalid mode.|
609
610
611### OH_ContainerFormatType
612
613```
614enum OH_ContainerFormatType
615```
616
617**Description**
618
619Enumerates the types of files generated during screen capture.
620
621> **NOTE**
622>
623> This enum is reserved and will be provided in later versions.
624
625**System capability**
626
627SystemCapability.Multimedia.Media.AVScreenCapture
628
629| Value| Description|
630| -------- | -------- |
631| CFT_MPEG_4A | Audio format M4A.|
632| CFT_MPEG_4 | Video format MP4.|
633
634
635### OH_DataType
636
637```
638enum OH_DataType
639```
640
641**Description**
642
643Enumerates the data types of screen capture streams.
644
645**System capability**
646
647SystemCapability.Multimedia.Media.AVScreenCapture
648
649| Value| Description|
650| -------- | -------- |
651| OH_ORIGINAL_STREAM | Original stream format, such as YUV, RGBA, and PCM.|
652| OH_ENCODED_STREAM | Encoded stream format, such as H.264 and AAC.<br>**NOTE**: This value is reserved and will be provided in later versions.|
653| OH_CAPTURE_FILE | Format of the recording file. The value can be **mp4**.<br>**NOTE**: This value is reserved and will be provided in later versions.|
654| OH_INVAILD | Invalid format.|
655
656
657### OH_VideoCodecFormat
658
659```
660enum OH_VideoCodecFormat
661```
662
663**Description**
664
665Enumerates the video encoding formats.
666
667**System capability**
668
669SystemCapability.Multimedia.Media.AVScreenCapture
670
671| Value| Description|
672| -------- | -------- |
673| OH_VIDEO_DEFAULT | Default video encoding format. The default value is **H.264**.|
674| OH_H264 | H.264.|
675| OH_H265 | H.265/HEVC.|
676| OH_MPEG4 | MPEG4.|
677| OH_VP8 | VP8.|
678| OH_VP9 | VP9.|
679| OH_VIDEO_CODEC_FORMAT_BUTT | Invalid format.|
680
681
682### OH_VideoSourceType
683
684```
685enum OH_VideoSourceType
686```
687
688**Description**
689
690Enumerates the video source formats.
691
692**System capability**
693
694SystemCapability.Multimedia.Media.AVScreenCapture
695
696| Value| Description|
697| -------- | -------- |
698| OH_VIDEO_SOURCE_SURFACE_YUV | YUV format.|
699| OH_VIDEO_SOURCE_SURFACE_ES | Raw format.|
700| OH_VIDEO_SOURCE_SURFACE_RGBA | RGBA format.|
701| OH_VIDEO_SOURCE_BUTT | Invalid format.|
702
703
704## Function Description
705
706
707### OH_AVScreenCapture_AcquireAudioBuffer()
708
709```
710OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_AcquireAudioBuffer (struct OH_AVScreenCapture * capture, OH_AudioBuffer ** audiobuffer, OH_AudioCaptureSourceType type )
711```
712
713**Description**
714
715Obtains an audio buffer. When calling this function, the application must allocate the memory of the corresponding struct size to the audio buffer.
716
717**Parameters**
718
719| Name| Description|
720| -------- | -------- |
721| capture | Pointer to an **OH_AVScreenCapture** instance.|
722| audiobuffer | Pointer to the struct for storing the audio buffer. This struct is used to obtain the information about the audio buffer and the timestamp of the buffer.|
723| type | Type of the audio buffer, which is used to distinguish external streams recorded by the microphone from internal streams played by the system. For details, see [OH_AudioCaptureSourceType](#oh_audiocapturesourcetype).|
724
725**System capability**
726
727SystemCapability.Multimedia.Media.AVScreenCapture
728
729**Returns**
730
731Returns **AV_SCREEN_CAPTURE_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) otherwise.
732
733
734### OH_AVScreenCapture_AcquireVideoBuffer()
735
736```
737OH_NativeBuffer* OH_AVScreenCapture_AcquireVideoBuffer (struct OH_AVScreenCapture * capture, int32_t * fence, int64_t * timestamp, struct OH_Rect * region )
738```
739
740**Description**
741
742Obtains a video buffer. An application can call this function to obtain information such as the video buffer and timestamp. After the buffer is no longer needed, call **OH_AVScreenCapture_ReleaseVideoBuffer** to release it.
743
744**Parameters**
745
746| Name| Description|
747| -------- | -------- |
748| capture | Pointer to an **OH_AVScreenCapture** instance.|
749| fence | Pointer to parameters for synchronization display.|
750| timestamp | Pointer to the timestamp of the video frame.|
751| region | Pointer to the coordinates related to video display.|
752
753**System capability**
754
755SystemCapability.Multimedia.Media.AVScreenCapture
756
757**Returns**
758
759Returns an **OH_NativeBuffer** object if the operation is successful. The application can call the APIs provided by the **OH_NativeBuffer** object to obtain information such as the video buffer and resolution.
760
761
762### OH_AVScreenCapture_Create()
763
764```
765struct OH_AVScreenCapture* OH_AVScreenCapture_Create (void )
766```
767
768**Description**
769
770Creates an **OH_AVScreenCapture** instance. You can release the instance by calling **OH_AVScreenCapture_Release**.
771
772**System capability**
773
774SystemCapability.Multimedia.Media.AVScreenCapture
775
776**Returns**
777
778Returns the pointer to an **OH_AVScreenCapture** instance.
779
780
781### OH_AVScreenCapture_Init()
782
783```
784OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_Init (struct OH_AVScreenCapture * capture, OH_AVScreenCaptureConfig config )
785```
786
787**Description**
788
789Initializes **OH_AVScreenCapture** parameters, including audio microphone sampling parameters, audio capture parameters (optional), and video resolution parameters.
790
791To call this function, you must configure the **ohos.permission.MICROPHONE** and **ohos.permission.CAPTURE_SCREEN** permissions. Otherwise, the initialization fails and screen capture cannot be performed properly.
792
793**Parameters**
794
795| Name| Description|
796| -------- | -------- |
797| capture | Pointer to an **OH_AVScreenCapture** instance.|
798| config | Parameters related to screen capture initialization.|
799
800**System capability**
801
802SystemCapability.Multimedia.Media.AVScreenCapture
803
804**Returns**
805
806Returns **AV_SCREEN_CAPTURE_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) otherwise.
807
808
809### OH_AVScreenCapture_Release()
810
811```
812OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_Release (struct OH_AVScreenCapture * capture)
813```
814
815**Description**
816
817Releases an **OH_AVScreenCapture** instance. This function is used in pair with **OH_AVScreenCapture_Create**.
818
819**Parameters**
820
821| Name| Description|
822| -------- | -------- |
823| capture | Pointer to an **OH_AVScreenCapture** instance.|
824
825**System capability**
826
827SystemCapability.Multimedia.Media.AVScreenCapture
828
829**Returns**
830
831Returns **AV_SCREEN_CAPTURE_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) otherwise.
832
833
834### OH_AVScreenCapture_ReleaseAudioBuffer()
835
836```
837OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_ReleaseAudioBuffer (struct OH_AVScreenCapture * capture, OH_AudioCaptureSourceType type )
838```
839
840**Description**
841
842Releases an audio buffer. After the audio buffer is no longer needed, call this function to release it.
843
844**Parameters**
845
846| Name| Description|
847| -------- | -------- |
848| capture | Pointer to an **OH_AVScreenCapture** instance.|
849| type | Type of the audio buffer, which is used to distinguish external streams recorded by the microphone from internal streams played by the system.|
850
851**System capability**
852
853SystemCapability.Multimedia.Media.AVScreenCapture
854
855**Returns**
856
857Returns **AV_SCREEN_CAPTURE_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) otherwise.
858
859
860### OH_AVScreenCapture_ReleaseVideoBuffer()
861
862```
863OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_ReleaseVideoBuffer (struct OH_AVScreenCapture * capture)
864```
865
866**Description**
867
868Releases a video buffer. After the video buffer is no longer needed, call this function to release it.
869
870**Parameters**
871
872| Name| Description|
873| -------- | -------- |
874| capture | Pointer to an **OH_AVScreenCapture** instance.|
875
876**System capability**
877
878SystemCapability.Multimedia.Media.AVScreenCapture
879
880**Returns**
881
882Returns **AV_SCREEN_CAPTURE_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) otherwise.
883
884
885### OH_AVScreenCapture_SetCallback()
886
887```
888OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetCallback (struct OH_AVScreenCapture * capture, struct OH_AVScreenCaptureCallback callback )
889```
890
891**Description**
892
893Sets a callback to listen for available video buffers and audio buffers and errors that occur during the function calling.
894
895**Parameters**
896
897| Name| Description|
898| -------- | -------- |
899| capture | Pointer to an **OH_AVScreenCapture** instance.|
900| callback | [OH_AVScreenCaptureCallback](_o_h___a_v_screen_capture_callback.md) struct, which stores related callback function pointers.|
901
902**System capability**
903
904SystemCapability.Multimedia.Media.AVScreenCapture
905
906**Returns**
907
908Returns **AV_SCREEN_CAPTURE_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) otherwise.
909
910
911### OH_AVScreenCapture_SetMicrophoneEnabled()
912
913```
914OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetMicrophoneEnabled (struct OH_AVScreenCapture * capture, bool isMicrophone )
915```
916
917**Description**
918
919Enables or disables the microphone. When **isMicrophone** is set to **true**, the microphone is enabled, and the original PCM data of the microphone can be obtained by calling **OH_AVScreenCapture_StartScreenRecording** and **OH_AVScreenCapture_AcquireAudioBuffer**. When **isMicrophone** is set to **false**, the obtained audio data is silent data.
920
921**Parameters**
922
923| Name| Description|
924| -------- | -------- |
925| capture | Pointer to an **OH_AVScreenCapture** instance.|
926| isMicrophone | Whether to enable the microphone.|
927
928**System capability**
929
930SystemCapability.Multimedia.Media.AVScreenCapture
931
932**Returns**
933
934Returns **AV_SCREEN_CAPTURE_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) otherwise.
935
936
937### OH_AVScreenCapture_StartScreenCapture()
938
939```
940OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StartScreenCapture (struct OH_AVScreenCapture * capture)
941```
942
943**Description**
944
945Starts screen capture and collects original streams. After calling this function, the application can use the callback listeners **OH_AVScreenCaptureOnAudioBufferAvailable** and **OH_AVScreenCaptureOnVideoBufferAvailable** to check whether streams are generated.
946
947The application can obtain the original streams of screen capture by calling **OH_AVScreenCapture_AcquireAudioBuffer** and **OH_AVScreenCapture_ReleaseVideoBuffer**.
948
949**Parameters**
950
951| Name| Description|
952| -------- | -------- |
953| capture | Pointer to an **OH_AVScreenCapture** instance.|
954
955**System capability**
956
957SystemCapability.Multimedia.Media.AVScreenCapture
958
959**Returns**
960
961Returns **AV_SCREEN_CAPTURE_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) otherwise.
962
963
964### OH_AVScreenCapture_StartScreenRecording()
965
966```
967OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StartScreenRecording (struct OH_AVScreenCapture * capture)
968```
969
970**Description**
971
972Starts screen recording and collects encoded streams.
973
974> **NOTE**
975>
976> This function is reserved and will be provided in later versions.
977
978**Parameters**
979
980| Name| Description|
981| -------- | -------- |
982| capture | Pointer to an **OH_AVScreenCapture** instance.|
983
984**System capability**
985
986SystemCapability.Multimedia.Media.AVScreenCapture
987
988**Returns**
989
990Returns **AV_SCREEN_CAPTURE_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) otherwise.
991
992
993### OH_AVScreenCapture_StopScreenCapture()
994
995```
996OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StopScreenCapture (struct OH_AVScreenCapture * capture)
997```
998
999**Description**
1000
1001Stops screen capture. This function is used in pair with **OH_AVScreenCapture_StartScreenCapture**. After calling this function, the application stops screen capture or screen share and releases the microphone.
1002
1003**Parameters**
1004
1005| Name| Description|
1006| -------- | -------- |
1007| capture | Pointer to an **OH_AVScreenCapture** instance.|
1008
1009**System capability**
1010
1011SystemCapability.Multimedia.Media.AVScreenCapture
1012
1013**Returns**
1014
1015Returns **AV_SCREEN_CAPTURE_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) otherwise.
1016
1017
1018### OH_AVScreenCapture_StopScreenRecording()
1019
1020```
1021OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StopScreenRecording (struct OH_AVScreenCapture * capture)
1022```
1023
1024**Description**
1025
1026Stops screen recording. This function is used in pair with **OH_AVScreenCapture_StartScreenRecording**.
1027
1028> **NOTE**
1029>
1030> This function is reserved and will be provided in later versions.
1031
1032**Parameters**
1033
1034| Name| Description|
1035| -------- | -------- |
1036| capture | Pointer to an **OH_AVScreenCapture** instance.|
1037
1038**System capability**
1039
1040SystemCapability.Multimedia.Media.AVScreenCapture
1041
1042**Returns**
1043
1044Returns **AV_SCREEN_CAPTURE_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) otherwise.
1045