• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# AVScreenCapture
2
3
4## Overview
5
6The AVScreenCapture module provides APIs for screen capture.
7
8You can refer to the corresponding development guide and samples based on your development requirements.
9
10- [Using AVScreenCapture to Capture Screens and Obtain Streams](../../media/media/using-avscreencapture-for-buffer.md)
11- [Using AVScreenCapture to Capture Screens and Write Them to Files](../../media/media/using-avscreencapture-for-file.md)
12
13**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
14
15**Since**: 10
16
17
18## Summary
19
20
21### Files
22
23| Name| Description|
24| -------- | -------- |
25| [native_avscreen_capture.h](native__avscreen__capture_8h.md) | Declares the APIs used to create an **OH_AVScreenCapture** instance.|
26| [native_avscreen_capture_base.h](native__avscreen__capture__base_8h.md) | Declares the common structs, character constants, and enums used for running screen capture.|
27| [native_avscreen_capture_errors.h](native__avscreen__capture__errors_8h.md) | Declares the error codes generated during screen capture.|
28
29
30### Structs
31
32| Name| Description|
33| -------- | -------- |
34| struct  [OH_AudioCaptureInfo](_o_h___audio_capture_info.md) | Describes the audio capture information.|
35| struct  [OH_AudioEncInfo](_o_h___audio_enc_info.md) | Describes the audio encoding information.|
36| struct  [OH_AudioInfo](_o_h___audio_info.md) | Describes the audio information.|
37| struct  [OH_VideoCaptureInfo](_o_h___video_capture_info.md) | Describes the video capture information.|
38| struct  [OH_VideoEncInfo](_o_h___video_enc_info.md) | Describes the video encoding information.|
39| struct  [OH_VideoInfo](_o_h___video_info.md) |Describes the video information.|
40| struct  [OH_RecorderInfo](_o_h___recorder_info.md) | Describes the recording file information.|
41| struct  [OH_AVScreenCaptureConfig](_o_h___a_v_screen_capture_config.md) | Describes the screen capture configuration.|
42| struct  [OH_AVScreenCaptureCallback](_o_h___a_v_screen_capture_callback.md) | Describes all the asynchronous callback function pointers of an **OH_AVScreenCapture** instance.|
43| struct  [OH_Rect](_o_h___rect.md) | Describes the width, height, and image information of the rectangle used for screen capture.|
44| struct  [OH_AudioBuffer](_o_h___audio_buffer.md) | Describes the configuration such as the size, type, and timestamp of audio data.|
45
46
47### Types
48
49| Name| Description|
50| -------- | -------- |
51| typedef struct [OH_NativeBuffer](#oh_nativebuffer) [OH_NativeBuffer](#oh_nativebuffer) | Defines the native video stream class for screen capture.|
52| typedef struct [OH_AVScreenCapture](#oh_avscreencapture) [OH_AVScreenCapture](#oh_avscreencapture) | Defines a screen capture instance used to obtain original video and audio streams.|
53| typedef struct [OH_AVScreenCapture_ContentFilter](#oh_avscreencapture_contentfilter) [OH_AVScreenCapture_ContentFilter](#oh_avscreencapture_contentfilter) | Defines a struct for the filter used to filter audio and video content.|
54| typedef enum [OH_CaptureMode](#oh_capturemode-1) [OH_CaptureMode](#oh_capturemode) | Defines an enum for the screen capture modes.|
55| typedef enum [OH_AudioCaptureSourceType](#oh_audiocapturesourcetype-1) [OH_AudioCaptureSourceType](#oh_audiocapturesourcetype) | Defines an enum for the audio source types during screen capture.|
56| typedef enum [OH_AudioCodecFormat](#oh_audiocodecformat-1) [OH_AudioCodecFormat](#oh_audiocodecformat) | Defines an enum for the audio encoding formats.|
57| typedef enum [OH_VideoCodecFormat](#oh_videocodecformat-1) [OH_VideoCodecFormat](#oh_videocodecformat) | Defines an enum for the video encoding formats.|
58| typedef enum [OH_DataType](#oh_datatype-1) [OH_DataType](#oh_datatype) | Defines an enum for the data types of screen capture streams.|
59| typedef enum [OH_VideoSourceType](#oh_videosourcetype-1) [OH_VideoSourceType](#oh_videosourcetype) | Defines an enum for the video source formats. Currently, only the RGBA format is supported.|
60| typedef enum [OH_ContainerFormatType](#oh_containerformattype-1) [OH_ContainerFormatType](#oh_containerformattype) | Defines an enum for the types of files generated during screen capture.|
61| typedef struct [OH_AudioCaptureInfo](_o_h___audio_capture_info.md) [OH_AudioCaptureInfo](#oh_audiocaptureinfo) | Defines a struct for the audio capture information.|
62| typedef struct [OH_AudioEncInfo](_o_h___audio_enc_info.md) [OH_AudioEncInfo](#oh_audioencinfo) | Defines a struct for the audio encoding information.|
63| typedef struct [OH_AudioInfo](_o_h___audio_info.md) [OH_AudioInfo](#oh_audioinfo) | Defines a struct for the audio information.|
64| typedef struct [OH_VideoCaptureInfo](_o_h___video_capture_info.md) [OH_VideoCaptureInfo](#oh_videocaptureinfo) | Defines a struct for the video capture information.|
65| typedef struct [OH_VideoEncInfo](_o_h___video_enc_info.md) [OH_VideoEncInfo](#oh_videoencinfo) | Defines a struct for the video encoding information.|
66| typedef struct [OH_VideoInfo](_o_h___video_info.md) [OH_VideoInfo](#oh_videoinfo) | Defines a struct for the video information.|
67| typedef struct [OH_RecorderInfo](_o_h___recorder_info.md) [OH_RecorderInfo](#oh_recorderinfo) | Defines a struct for the recording file information.|
68| typedef struct [OH_AVScreenCaptureConfig](_o_h___a_v_screen_capture_config.md) [OH_AVScreenCaptureConfig](#oh_avscreencaptureconfig) | Defines a struct for the screen capture configuration.|
69| typedef void(\* [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.|
70| typedef void(\* [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.|
71| typedef void(\* [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.|
72| typedef struct [OH_AVScreenCaptureCallback](_o_h___a_v_screen_capture_callback.md) [OH_AVScreenCaptureCallback](#oh_avscreencapturecallback) | Defines a struct for all the asynchronous callback function pointers of an **OH_AVScreenCapture** instance.|
73| typedef struct [OH_Rect](_o_h___rect.md) [OH_Rect](#oh_rect) | Defines a struct for the width, height, and image information of the rectangle used for screen capture.|
74| typedef struct [OH_AudioBuffer](_o_h___audio_buffer.md) [OH_AudioBuffer](#oh_audiobuffer) | Defines a struct for the configuration such as the size, type, and timestamp of audio data.|
75| typedef enum [OH_AVScreenCaptureStateCode](#oh_avscreencapturestatecode-1) [OH_AVScreenCaptureStateCode](#oh_avscreencapturestatecode) | Defines an enum for the screen capture states.|
76| typedef enum [OH_AVScreenCaptureBufferType](#oh_avscreencapturebuffertype-1) [OH_AVScreenCaptureBufferType](#oh_avscreencapturebuffertype) | Defines an enum for the buffer types.|
77| typedef enum [OH_AVScreenCaptureFilterableAudioContent](#oh_avscreencapturefilterableaudiocontent-1) [OH_AVScreenCaptureFilterableAudioContent](#oh_avscreencapturefilterableaudiocontent) | Defines an enum for the types of audio that can be added to a content filter.|
78| typedef void(\* [OH_AVScreenCapture_OnStateChange](#oh_avscreencapture_onstatechange)) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture, [OH_AVScreenCaptureStateCode](#oh_avscreencapturestatecode) stateCode, void \*userData) | Defines a pointer to a callback function that is called when the state changes during the running of an **OH_AVScreenCapture** instance.|
79| typedef void(\* [OH_AVScreenCapture_OnError](#oh_avscreencapture_onerror)) ([OH_AVScreenCapture](#oh_avscreencapture) \*capture, int32_t errorCode, void \*userData) | Defines a pointer to a callback function that is called when an error occurs during the running of an **OH_AVScreenCapture** instance.|
80| typedef void(\* [OH_AVScreenCapture_OnBufferAvailable](#oh_avscreencapture_onbufferavailable)) ([OH_AVScreenCapture](#oh_avscreencapture) \*capture, OH_AVBuffer \*buffer, [OH_AVScreenCaptureBufferType](#oh_avscreencapturebuffertype) bufferType, int64_t timestamp, void \*userData) | Defines a pointer to a callback function that is called when an audio or a video buffer is available during the running of an **OH_AVScreenCapture** instance.|
81| typedef enum [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1) [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) | Defines an enum for the error codes generated during screen recording.|
82| typedef void(\* [OH_AVScreenCapture_OnDisplaySelected](#oh_avscreencapture_ondisplayselected)) ([OH_AVScreenCapture](#oh_avscreencapture) \*capture, uint64_t displayId, void \*userData) | Defines a pointer to a callback function that is called when screen capture starts.|
83
84
85### Enums
86
87| Name| Description|
88| -------- | -------- |
89| [OH_CaptureMode](#oh_capturemode-1) {<br>OH_CAPTURE_HOME_SCREEN = 0,<br>OH_CAPTURE_SPECIFIED_SCREEN = 1,<br>OH_CAPTURE_SPECIFIED_WINDOW = 2,<br>OH_CAPTURE_INVAILD = -1<br>} | Enumerates the screen capture modes.|
90| [OH_AudioCaptureSourceType](#oh_audiocapturesourcetype-1) {<br>OH_SOURCE_INVALID = -1,<br>OH_SOURCE_DEFAULT = 0,<br>OH_MIC = 1,<br>OH_ALL_PLAYBACK = 2,<br>OH_APP_PLAYBACK = 3<br>} | Enumerates the audio source types during screen capture.|
91| [OH_AudioCodecFormat](#oh_audiocodecformat-1) {<br>OH_AUDIO_DEFAULT = 0,<br>OH_AAC_LC = 3,<br>OH_AUDIO_CODEC_FORMAT_BUTT<br>} | Enumerates the audio encoding formats.|
92| [OH_VideoCodecFormat](#oh_videocodecformat-1) {<br>OH_VIDEO_DEFAULT = 0,<br>OH_H264 = 2,<br>OH_H265 = 4,<br>OH_MPEG4 = 6,<br>OH_VP8 = 8,<br>OH_VP9 = 10,<br>OH_VIDEO_CODEC_FORMAT_BUTT<br>} | Enumerates the video encoding formats.|
93| [OH_DataType](#oh_datatype-1) {<br>OH_ORIGINAL_STREAM = 0,<br>OH_ENCODED_STREAM = 1,<br>OH_CAPTURE_FILE = 2,<br>OH_INVAILD = -1<br>} | Enumerates the data types of screen capture streams.|
94| [OH_VideoSourceType](#oh_videosourcetype-1) {<br>OH_VIDEO_SOURCE_SURFACE_YUV = 0,<br>OH_VIDEO_SOURCE_SURFACE_ES,<br>OH_VIDEO_SOURCE_SURFACE_RGBA,<br>OH_VIDEO_SOURCE_BUTT<br>} | Enumerates the video source formats. Currently, only the RGBA format is supported.|
95| [OH_ContainerFormatType](#oh_containerformattype) {<br>CFT_MPEG_4A = 0,<br>CFT_MPEG_4 = 1<br>} | Enumerates the types of files generated during screen capture.|
96| [OH_AVScreenCaptureStateCode](#oh_avscreencapturestatecode-1) {<br>OH_SCREEN_CAPTURE_STATE_STARTED = 0,<br>OH_SCREEN_CAPTURE_STATE_CANCELED = 1,<br>OH_SCREEN_CAPTURE_STATE_STOPPED_BY_USER = 2,<br>OH_SCREEN_CAPTURE_STATE_INTERRUPTED_BY_OTHER = 3,<br>OH_SCREEN_CAPTURE_STATE_STOPPED_BY_CALL = 4,<br>OH_SCREEN_CAPTURE_STATE_MIC_UNAVAILABLE = 5,<br>OH_SCREEN_CAPTURE_STATE_MIC_MUTED_BY_USER = 6,<br>OH_SCREEN_CAPTURE_STATE_MIC_UNMUTED_BY_USER = 7,<br>OH_SCREEN_CAPTURE_STATE_ENTER_PRIVATE_SCENE = 8,<br>OH_SCREEN_CAPTURE_STATE_EXIT_PRIVATE_SCENE = 9<br>OH_SCREEN_CAPTURE_STATE_STOPPED_BY_USER_SWITCHES = 10<br>} | Enumerates the screen capture states.|
97| [OH_AVScreenCaptureBufferType](#oh_avscreencapturebuffertype-1) {<br>OH_SCREEN_CAPTURE_BUFFERTYPE_VIDEO = 0,<br>OH_SCREEN_CAPTURE_BUFFERTYPE_AUDIO_INNER = 1,<br>OH_SCREEN_CAPTURE_BUFFERTYPE_AUDIO_MIC = 2<br>} | Enumerates the buffer types.|
98| [OH_AVScreenCaptureFilterableAudioContent](#oh_avscreencapturefilterableaudiocontent-1) {<br>OH_SCREEN_CAPTURE_NOTIFICATION_AUDIO = 0, <br>OH_SCREEN_CAPTURE_CURRENT_APP_AUDIO = 1 <br>} | Enumerates the types of audio that can be added to a content filter. |
99| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1) {<br>AV_SCREEN_CAPTURE_ERR_BASE = 0,<br>AV_SCREEN_CAPTURE_ERR_OK = AV_SCREEN_CAPTURE_ERR_BASE,<br>AV_SCREEN_CAPTURE_ERR_NO_MEMORY = AV_SCREEN_CAPTURE_ERR_BASE + 1,<br>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,<br>AV_SCREEN_CAPTURE_ERR_IO = AV_SCREEN_CAPTURE_ERR_BASE + 4,<br>AV_SCREEN_CAPTURE_ERR_TIMEOUT = AV_SCREEN_CAPTURE_ERR_BASE + 5,<br>AV_SCREEN_CAPTURE_ERR_UNKNOWN = AV_SCREEN_CAPTURE_ERR_BASE + 6,<br>AV_SCREEN_CAPTURE_ERR_SERVICE_DIED = AV_SCREEN_CAPTURE_ERR_BASE + 7,<br>AV_SCREEN_CAPTURE_ERR_INVALID_STATE = AV_SCREEN_CAPTURE_ERR_BASE + 8,<br>AV_SCREEN_CAPTURE_ERR_UNSUPPORT = AV_SCREEN_CAPTURE_ERR_BASE + 9,<br>AV_SCREEN_CAPTURE_ERR_EXTEND_START = AV_SCREEN_CAPTURE_ERR_BASE + 100<br>} | Enumerates the error codes generated during screen recording.|
100
101
102### Functions
103
104| Name| Description|
105| -------- | -------- |
106| struct [OH_AVScreenCapture](#oh_avscreencapture) \* [OH_AVScreenCapture_Create](#oh_avscreencapture_create) (void) | Creates an **OH_AVScreenCapture** instance. |
107| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [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, including audio sampling parameters for external capture using microphones (optional), audio sampling parameters for internal capture, and video resolution parameters. |
108| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [OH_AVScreenCapture_StartScreenCapture](#oh_avscreencapture_startscreencapture) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture) | Starts screen capture and collects original streams. |
109| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [OH_AVScreenCapture_StartScreenCaptureWithSurface](#oh_avscreencapture_startscreencapturewithsurface) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture, OHNativeWindow \*window) | Starts screen capture in surface mode. |
110| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [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**. |
111| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [OH_AVScreenCapture_StartScreenRecording](#oh_avscreencapture_startscreenrecording) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture) | Starts screen recording, with recordings saved in files. |
112| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [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**.|
113| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [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. |
114| [OH_NativeBuffer](#oh_nativebuffer) \* [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. |
115| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [OH_AVScreenCapture_ReleaseAudioBuffer](#oh_avscreencapture_releaseaudiobuffer) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture, [OH_AudioCaptureSourceType](#oh_audiocapturesourcetype) type) | Releases an audio buffer. |
116| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [OH_AVScreenCapture_ReleaseVideoBuffer](#oh_avscreencapture_releasevideobuffer) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture) | Releases a video buffer. After the video buffer is no longer needed, call this function to release it. |
117| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [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. |
118| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [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**. |
119| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [OH_AVScreenCapture_SetMicrophoneEnabled](#oh_avscreencapture_setmicrophoneenabled) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture, bool isMicrophone) | Enables or disables the microphone. |
120| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [OH_AVScreenCapture_SetStateCallback](#oh_avscreencapture_setstatecallback) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture, [OH_AVScreenCapture_OnStateChange](#oh_avscreencapture_onstatechange) callback, void \*userData) | Sets a state change callback. This function must be called before screen capture starts. |
121| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [OH_AVScreenCapture_SetDataCallback](#oh_avscreencapture_setdatacallback) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture, [OH_AVScreenCapture_OnBufferAvailable](#oh_avscreencapture_onbufferavailable) callback, void \*userData) | Sets a data processing callback. This function must be called before screen capture starts. |
122| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [OH_AVScreenCapture_SetErrorCallback](#oh_avscreencapture_seterrorcallback) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture, [OH_AVScreenCapture_OnError](#oh_avscreencapture_onerror) callback, void \*userData) | Sets an error processing callback. This function must be called before screen capture starts. |
123| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [OH_AVScreenCapture_SetCanvasRotation](#oh_avscreencapture_setcanvasrotation) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture, bool canvasRotation) | Sets canvas rotation for screen capture. |
124| struct [OH_AVScreenCapture_ContentFilter](#oh_avscreencapture_contentfilter) \* [OH_AVScreenCapture_CreateContentFilter](#oh_avscreencapture_createcontentfilter) (void) | Creates a content filter. |
125| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [OH_AVScreenCapture_ReleaseContentFilter](#oh_avscreencapture_releasecontentfilter) (struct [OH_AVScreenCapture_ContentFilter](#oh_avscreencapture_contentfilter) \*filter) | Releases a content filter. |
126| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [OH_AVScreenCapture_ContentFilter_AddAudioContent](#oh_avscreencapture_contentfilter_addaudiocontent) (struct [OH_AVScreenCapture_ContentFilter](#oh_avscreencapture_contentfilter) \*filter, [OH_AVScreenCaptureFilterableAudioContent](#oh_avscreencapturefilterableaudiocontent) content) | Adds audio content to a content filter. |
127| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [OH_AVScreenCapture_ExcludeContent](#oh_avscreencapture_excludecontent) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture, struct [OH_AVScreenCapture_ContentFilter](#oh_avscreencapture_contentfilter) \*filter) | Sets a content filter for an **OH_AVScreenCapture** instance. |
128| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [OH_AVScreenCapture_ContentFilter_AddWindowContent](#oh_avscreencapture_contentfilter_addwindowcontent) (struct [OH_AVScreenCapture_ContentFilter](#oh_avscreencapture_contentfilter) \*filter, int32_t \*windowIDs, int32_t windowCount) | Adds a list of window IDs to a **ContentFilter** instance. |
129| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [OH_AVScreenCapture_ResizeCanvas](#oh_avscreencapture_resizecanvas) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture, int32_t width, int32_t height) | Adjusts the screen resolution. |
130| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [OH_AVScreenCapture_SkipPrivacyMode](#oh_avscreencapture_skipprivacymode) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture, int32_t \*windowIDs, int32_t windowCount) | Exempts privacy windows during screen capture. |
131| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [OH_AVScreenCapture_SetMaxVideoFrameRate](#oh_avscreencapture_setmaxvideoframerate) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture, int32_t frameRate) | Sets the maximum frame rate for screen capture. |
132| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [OH_AVScreenCapture_ShowCursor](#oh_avscreencapture_showcursor) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture, bool showCursor) | Sets whether to show the cursor.|
133| [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode) [OH_AVScreenCapture_SetDisplayCallback](#oh_avscreencapture_setdisplaycallback) (struct [OH_AVScreenCapture](#oh_avscreencapture) \*capture, [OH_AVScreenCapture_OnDisplaySelected](#oh_avscreencapture_ondisplayselected) callback, void \*userData) | Sets a callback function for obtaining the display ID.|
134
135
136## Type Description
137
138
139### OH_AudioBuffer
140
141```
142typedef struct OH_AudioBuffer OH_AudioBuffer
143```
144**Description**
145Defines a struct for the configuration such as the size, type, and timestamp of audio data.
146
147**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
148
149**Since**: 10
150
151
152### OH_AudioCaptureInfo
153
154```
155typedef struct OH_AudioCaptureInfo OH_AudioCaptureInfo
156```
157**Description**
158Defines a struct for the audio capture information.
159
160When both **audioSampleRate** and **audioChannels** are **0**, the audio-related parameters are ignored and the audio data is not recorded.
161
162**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
163
164**Since**: 10
165
166
167### OH_AudioCaptureSourceType
168
169```
170typedef enum OH_AudioCaptureSourceType OH_AudioCaptureSourceType
171```
172**Description**
173Defines an enum for the audio source types during screen capture.
174
175**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
176
177**Since**: 10
178
179
180### OH_AudioCodecFormat
181
182```
183typedef enum OH_AudioCodecFormat OH_AudioCodecFormat
184```
185**Description**
186Defines an enum for the audio encoding formats.
187
188**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
189
190**Since**: 10
191
192
193### OH_AudioEncInfo
194
195```
196typedef struct OH_AudioEncInfo OH_AudioEncInfo
197```
198**Description**
199Defines a struct for the audio encoding information.
200
201**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
202
203**Since**: 10
204
205
206### OH_AudioInfo
207
208```
209typedef struct OH_AudioInfo OH_AudioInfo
210```
211**Description**
212Defines a struct for the audio information.
213
214To perform both external capture (using microphones) and internal capture, **audioSampleRate** and **audioChannels** must be the same for both audio channels.
215
216**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
217
218**Since**: 10
219
220
221### OH_AVSCREEN_CAPTURE_ErrCode
222
223```
224typedef enum OH_AVSCREEN_CAPTURE_ErrCode OH_AVSCREEN_CAPTURE_ErrCode
225```
226**Description**
227Defines an enum for the error codes generated during screen recording.
228
229**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
230
231**Since**: 10
232
233
234### OH_AVScreenCapture
235
236```
237typedef struct OH_AVScreenCaptureOH_AVScreenCapture
238```
239**Description**
240Defines a screen capture instance used to obtain original video and audio streams.
241
242**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
243
244**Since**: 10
245
246
247### OH_AVScreenCapture_ContentFilter
248
249```
250typedef struct OH_AVScreenCapture_ContentFilterOH_AVScreenCapture_ContentFilter
251```
252**Description**
253Defines a struct for the filter used to filter audio and video content.
254
255**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
256
257**Since**: 12
258
259
260### OH_AVScreenCapture_OnBufferAvailable
261
262```
263typedef void(* OH_AVScreenCapture_OnBufferAvailable) (OH_AVScreenCapture *capture, OH_AVBuffer *buffer, OH_AVScreenCaptureBufferType bufferType, int64_t timestamp, void *userData)
264```
265**Description**
266Defines a pointer to a callback function that is called when an audio or a video buffer is available during the running of an **OH_AVScreenCapture** instance.
267
268**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
269
270**Since**: 12
271
272**Parameters**
273
274| Name| Description|
275| -------- | -------- |
276| capture | Pointer to an **OH_AVScreenCapture** instance. |
277| buffer | Pointer to the **OH_AVBuffer** instance. After the callback is triggered, the buffer is no longer valid. |
278| bufferType | Type of the buffer. |
279| timestamp | Timestamp, in nanoseconds. |
280| userData | Pointer to the user-defined data carried in the function.|
281
282
283### OH_AVScreenCapture_OnDisplaySelected
284
285```
286typedef void (*OH_AVScreenCapture_OnDisplaySelected)(OH_AVScreenCapture *capture, uint64_t displayId, void *userData)
287```
288
289**Description**
290
291Defines a pointer to a callback function that is called when screen capture starts.
292
293**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
294
295**Since**: 15
296
297**Parameters**
298
299| Name| Description|
300| -------- | -------- |
301| capture | Pointer to an **OH_AVScreenCapture** instance.|
302| displayId | ID of the screen to capture.|
303| userData | Pointer to the user-defined data carried in the function.|
304
305
306### OH_AVScreenCapture_OnError
307
308```
309typedef void(* OH_AVScreenCapture_OnError) (OH_AVScreenCapture *capture, int32_t errorCode, void *userData)
310```
311**Description**
312Defines a pointer to a callback function that is called when an error occurs during the running of an **OH_AVScreenCapture** instance.
313
314**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
315
316**Since**: 12
317
318**Parameters**
319
320| Name| Description|
321| -------- | -------- |
322| capture | Pointer to an **OH_AVScreenCapture** instance. |
323| errorCode | Error code. |
324| userData | Pointer to the user-defined data carried in the function.|
325
326
327### OH_AVScreenCapture_OnStateChange
328
329```
330typedef void(* OH_AVScreenCapture_OnStateChange) (struct OH_AVScreenCapture *capture, OH_AVScreenCaptureStateCode stateCode, void *userData)
331```
332**Description**
333Defines a pointer to a callback function that is called when the state changes during the running of an **OH_AVScreenCapture** instance.
334
335**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
336
337**Since**: 12
338
339**Parameters**
340
341| Name| Description|
342| -------- | -------- |
343| capture | Pointer to an **OH_AVScreenCapture** instance. |
344| stateCode | Status code. |
345| userData | Pointer to the user-defined data carried in the function.|
346
347
348### OH_AVScreenCaptureBufferType
349
350```
351typedef enum OH_AVScreenCaptureBufferTypeOH_AVScreenCaptureBufferType
352```
353**Description**
354Defines an enum for the buffer types.
355
356**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
357
358**Since**: 12
359
360
361### OH_AVScreenCaptureCallback
362
363```
364typedef struct OH_AVScreenCaptureCallback OH_AVScreenCaptureCallback
365```
366**Description**
367Defines a struct for 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.
368
369**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
370
371**Since**: 10
372
373**Deprecated from**: 12
374
375**Substitute APIs**
376
377[OH_AVScreenCapture_OnError](#oh_avscreencapture_onerror) and [OH_AVScreenCapture_OnBufferAvailable](#oh_avscreencapture_onbufferavailable)
378
379**Parameters**
380
381| Name| Description|
382| -------- | -------- |
383| 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).|
384| 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).|
385| 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).|
386
387
388### OH_AVScreenCaptureConfig
389
390```
391typedef struct OH_AVScreenCaptureConfig OH_AVScreenCaptureConfig
392```
393**Description**
394Defines a struct for the screen capture configuration.
395
396**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
397
398**Since**: 10
399
400
401### OH_AVScreenCaptureFilterableAudioContent
402
403```
404typedef enum OH_AVScreenCaptureFilterableAudioContent OH_AVScreenCaptureFilterableAudioContent
405```
406**Description**
407Defines an enum for the types of audio that can be added to a content filter.
408
409**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
410
411**Since**: 12
412
413
414### OH_AVScreenCaptureOnAudioBufferAvailable
415
416```
417typedef void(* OH_AVScreenCaptureOnAudioBufferAvailable) (OH_AVScreenCapture *capture, bool isReady, OH_AudioCaptureSourceType type)
418```
419**Description**
420Defines a pointer to a callback function that is called when an audio buffer is available during the running of an **OH_AVScreenCapture** instance.
421
422**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
423
424**Since**: 10
425
426**Deprecated from**: 12
427
428**Substitute API**: [OH_AVScreenCapture_OnBufferAvailable](#oh_avscreencapture_onbufferavailable)
429
430**Parameters**
431
432| Name| Description|
433| -------- | -------- |
434| capture | Pointer to an **OH_AVScreenCapture** instance. |
435| isReady | Whether the audio buffer is available. |
436| type | Audio source type.|
437
438
439### OH_AVScreenCaptureOnError
440
441```
442typedef void(* OH_AVScreenCaptureOnError) (OH_AVScreenCapture *capture, int32_t errorCode)
443```
444**Description**
445Defines a pointer to a callback function that is called when an error occurs during the running of an **OH_AVScreenCapture** instance.
446
447**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
448
449**Since**: 10
450
451**Deprecated from**: 12
452
453**Substitute API**: [OH_AVScreenCapture_OnError](#oh_avscreencapture_onerror)
454
455**Parameters**
456
457| Name| Description|
458| -------- | -------- |
459| capture | Pointer to an **OH_AVScreenCapture** instance. |
460| errorCode | Error code.|
461
462
463### OH_AVScreenCaptureOnVideoBufferAvailable
464
465```
466typedef void(* OH_AVScreenCaptureOnVideoBufferAvailable) (OH_AVScreenCapture *capture, bool isReady)
467```
468**Description**
469Defines a pointer to a callback function that is called when a video buffer is available during the running of an **OH_AVScreenCapture** instance.
470
471**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
472
473**Since**: 10
474
475**Deprecated from**: 12
476
477**Substitute API**: [OH_AVScreenCapture_OnBufferAvailable](#oh_avscreencapture_onbufferavailable)
478
479**Parameters**
480
481| Name| Description|
482| -------- | -------- |
483| capture | Pointer to an **OH_AVScreenCapture** instance. |
484| isReady | Whether the video buffer is available.|
485
486
487### OH_AVScreenCaptureStateCode
488
489```
490typedef enum OH_AVScreenCaptureStateCode OH_AVScreenCaptureStateCode
491```
492**Description**
493Defines an enum for the screen capture states.
494
495**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
496
497**Since**: 12
498
499
500### OH_CaptureMode
501
502```
503typedef enum OH_CaptureMode OH_CaptureMode
504```
505**Description**
506Defines an enum for the screen capture modes.
507
508**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
509
510**Since**: 10
511
512
513### OH_ContainerFormatType
514
515```
516typedef enum OH_ContainerFormatType OH_ContainerFormatType
517```
518**Description**
519Defines an enum for the types of files generated during screen capture.
520
521**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
522
523**Since**: 10
524
525
526### OH_DataType
527
528```
529typedef enum OH_DataType OH_DataType
530```
531**Description**
532Defines an enum for the data types of screen capture streams.
533
534**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
535
536**Since**: 10
537
538
539### OH_NativeBuffer
540
541```
542typedef struct OH_NativeBuffer OH_NativeBuffer
543```
544**Description**
545Defines the native video stream class for screen capture.
546
547**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
548
549**Since**: 10
550
551
552### OH_RecorderInfo
553
554```
555typedef struct OH_RecorderInfo OH_RecorderInfo
556```
557**Description**
558Defines a struct for the recording file information.
559
560**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
561
562**Since**: 10
563
564
565### OH_Rect
566
567```
568typedef struct OH_Rect OH_Rect
569```
570**Description**
571Defines a struct for the width, height, and image information of the rectangle used for screen capture.
572
573**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
574
575**Since**: 10
576
577
578### OH_VideoCaptureInfo
579
580```
581typedef struct OH_VideoCaptureInfo OH_VideoCaptureInfo
582```
583**Description**
584Defines a struct for the video capture information.
585
586When **videoFrameWidth** and **videoFrameHeight** are both **0**, video-related parameters are ignored and screen data is not recorded.
587
588**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
589
590**Since**: 10
591
592
593### OH_VideoCodecFormat
594
595```
596typedef enum OH_VideoCodecFormat OH_VideoCodecFormat
597```
598**Description**
599Defines an enum for the video encoding formats.
600
601**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
602
603**Since**: 10
604
605
606### OH_VideoEncInfo
607
608```
609typedef struct OH_VideoEncInfo OH_VideoEncInfo
610```
611**Description**
612Defines a struct for the video encoding information.
613
614**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
615
616**Since**: 10
617
618
619### OH_VideoInfo
620
621```
622typedef struct OH_VideoInfo OH_VideoInfo
623```
624**Description**
625Defines a struct for the video information.
626
627**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
628
629**Since**: 10
630
631
632### OH_VideoSourceType
633
634```
635typedef enum OH_VideoSourceType OH_VideoSourceType
636```
637**Description**
638Defines an enum for the video source formats. Currently, only the RGBA format is supported.
639
640**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
641
642**Since**: 10
643
644
645## Enum Description
646
647
648### OH_AudioCaptureSourceType
649
650```
651enum OH_AudioCaptureSourceType
652```
653**Description**
654Enumerates the audio source types during screen capture.
655
656**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
657
658**Since**: 10
659
660| Value| Description|
661| -------- | -------- |
662| OH_SOURCE_INVALID  | Invalid audio source.  |
663| OH_SOURCE_DEFAULT  | Default audio source. The default value is **MIC**.  |
664| OH_MIC  | External audio streams recorded by the microphone.  |
665| OH_ALL_PLAYBACK  | All internal audio streams played by the system.  |
666| OH_APP_PLAYBACK  | Internal audio streams played by a specified application.  |
667
668
669### OH_AudioCodecFormat
670
671```
672enum OH_AudioCodecFormat
673```
674**Description**
675Enumerates the audio encoding formats.
676
677**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
678
679**Since**: 10
680
681| Value| Description|
682| -------- | -------- |
683| OH_AUDIO_DEFAULT  | Default audio encoding format. The default value is **AAC_LC**.  |
684| OH_AAC_LC  | AAC_LC audio encoding.  |
685| OH_AUDIO_CODEC_FORMAT_BUTT  | Invalid format.  |
686
687
688### OH_AVSCREEN_CAPTURE_ErrCode
689
690```
691enum OH_AVSCREEN_CAPTURE_ErrCode
692```
693
694**Description**
695
696Enumerates the error codes generated during screen recording.
697
698**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
699
700**Since**: 10
701
702| Value| Description|
703| -------- | -------- |
704| AV_SCREEN_CAPTURE_ERR_BASE | Basic value returned when an API call error occurs.|
705| AV_SCREEN_CAPTURE_ERR_OK | Operation successful.|
706| AV_SCREEN_CAPTURE_ERR_NO_MEMORY | Memory insufficient.|
707| AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT | Operation not allowed.|
708| AV_SCREEN_CAPTURE_ERR_INVALID_VAL | Invalid parameter.|
709| AV_SCREEN_CAPTURE_ERR_IO | Abnormal input and output streams.|
710| AV_SCREEN_CAPTURE_ERR_TIMEOUT | Network timeout.|
711| AV_SCREEN_CAPTURE_ERR_UNKNOWN | Unknown error.|
712| AV_SCREEN_CAPTURE_ERR_SERVICE_DIED | Media service terminated.|
713| AV_SCREEN_CAPTURE_ERR_INVALID_STATE | Unsupported operation in this state.|
714| AV_SCREEN_CAPTURE_ERR_UNSUPPORT | Unsupported interface.|
715| AV_SCREEN_CAPTURE_ERR_EXTEND_START | Unexpected error.|
716
717
718### OH_AVScreenCaptureBufferType
719
720```
721enum OH_AVScreenCaptureBufferType
722```
723**Description**
724Enumerates the buffer types.
725
726**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
727
728**Since**: 12
729
730| Value| Description|
731| -------- | -------- |
732| OH_SCREEN_CAPTURE_BUFFERTYPE_VIDEO  | Video data.  |
733| OH_SCREEN_CAPTURE_BUFFERTYPE_AUDIO_INNER  | Internal audio capture data.  |
734| OH_SCREEN_CAPTURE_BUFFERTYPE_AUDIO_MIC  | Microphone audio data.  |
735
736
737### OH_AVScreenCaptureFilterableAudioContent
738
739```
740enum OH_AVScreenCaptureFilterableAudioContent
741```
742**Description**
743Enumerates the types of audio that can be added to a content filter.
744
745**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
746
747**Since**: 12
748
749| Value| Description|
750| -------- | -------- |
751| OH_SCREEN_CAPTURE_NOTIFICATION_AUDIO  | Notification tone.  |
752| OH_SCREEN_CAPTURE_CURRENT_APP_AUDIO  | Sound of the application itself.  |
753
754
755### OH_AVScreenCaptureStateCode
756
757```
758enum OH_AVScreenCaptureStateCode
759```
760**Description**
761Enumerates the screen capture states.
762
763**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
764
765**Since**: 12
766
767| Value| Description|
768| -------- | -------- |
769| OH_SCREEN_CAPTURE_STATE_STARTED  | Screen capture is started.  |
770| OH_SCREEN_CAPTURE_STATE_CANCELED  | Screen capture is canceled.  |
771| OH_SCREEN_CAPTURE_STATE_STOPPED_BY_USER  | Screen capture is stopped.  |
772| OH_SCREEN_CAPTURE_STATE_INTERRUPTED_BY_OTHER  | Screen capture is interrupted by another screen capture.  |
773| OH_SCREEN_CAPTURE_STATE_STOPPED_BY_CALL  | Screen capture is interrupted by a call.  |
774| OH_SCREEN_CAPTURE_STATE_MIC_UNAVAILABLE  | The microphone is unavailable.  |
775| OH_SCREEN_CAPTURE_STATE_MIC_MUTED_BY_USER  | The microphone is muted.  |
776| OH_SCREEN_CAPTURE_STATE_MIC_UNMUTED_BY_USER  | The microphone is unmuted.   |
777| OH_SCREEN_CAPTURE_STATE_ENTER_PRIVATE_SCENE  | The system enters a privacy dialog box.   |
778| OH_SCREEN_CAPTURE_STATE_EXIT_PRIVATE_SCENE  | The system exits a privacy dialog box.   |
779| OH_SCREEN_CAPTURE_STATE_STOPPED_BY_USER_SWITCHES   | Screen capture is interrupted by system user switching.|
780
781
782### OH_CaptureMode
783
784```
785enum OH_CaptureMode
786```
787**Description**
788Enumerates the screen capture modes.
789
790**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
791
792**Since**: 10
793
794| Value| Description|
795| -------- | -------- |
796| OH_CAPTURE_HOME_SCREEN  | Captures the home screen.  |
797| OH_CAPTURE_SPECIFIED_SCREEN  | Captures a specified screen.  |
798| OH_CAPTURE_SPECIFIED_WINDOW  | Captures a specified window.  |
799| OH_CAPTURE_INVAILD  | Invalid mode.  |
800
801
802### OH_ContainerFormatType
803
804```
805enum OH_ContainerFormatType
806```
807**Description**
808Enumerates the types of files generated during screen capture.
809
810**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
811
812**Since**: 10
813
814| Value| Description|
815| -------- | -------- |
816| CFT_MPEG_4A  | Audio format M4A.  |
817| CFT_MPEG_4  | Video format MP4.  |
818
819
820### OH_DataType
821
822```
823enum OH_DataType
824```
825**Description**
826Enumerates the data types of screen capture streams.
827
828**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
829
830**Since**: 10
831
832| Value| Description|
833| -------- | -------- |
834| OH_ORIGINAL_STREAM  | Original stream format, such as YUV, RGBA, and PCM.  |
835| OH_ENCODED_STREAM  | Encoded stream format, such as H.264 and AAC. This value is not supported yet.  |
836| OH_CAPTURE_FILE  | Format of the recording file. The value can be **mp4**.  |
837| OH_INVAILD  | Invalid format.  |
838
839
840### OH_VideoCodecFormat
841
842```
843enum OH_VideoCodecFormat
844```
845**Description**
846Enumerates the video encoding formats.
847
848**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
849
850**Since**: 10
851
852| Value| Description|
853| -------- | -------- |
854| OH_VIDEO_DEFAULT | Default video encoding format. The default value is **H.264**.|
855| OH_H264 | H.264.|
856| OH_H265 | H.265/HEVC.|
857| OH_MPEG4 | MPEG4.|
858| OH_VP8 | VP8.|
859| OH_VP9 | VP9.|
860| OH_VIDEO_CODEC_FORMAT_BUTT | Invalid format.|
861
862
863### OH_VideoSourceType
864
865```
866enum OH_VideoSourceType
867```
868**Description**
869Enumerates the video source formats. Currently, only the RGBA format is supported.
870
871**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
872
873**Since**: 10
874
875| Value| Description|
876| -------- | -------- |
877| OH_VIDEO_SOURCE_SURFACE_YUV  | YUV format. This value is not supported yet.  |
878| OH_VIDEO_SOURCE_SURFACE_ES  | Raw format. This value is not supported yet. |
879| OH_VIDEO_SOURCE_SURFACE_RGBA  | RGBA format.  |
880| OH_VIDEO_SOURCE_BUTT  | Invalid format.  |
881
882
883## Function Description
884
885
886### OH_AVScreenCapture_AcquireAudioBuffer()
887
888```
889OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_AcquireAudioBuffer (struct OH_AVScreenCapture * capture, OH_AudioBuffer ** audiobuffer, OH_AudioCaptureSourceType type )
890```
891**Description**
892Obtains an audio buffer. When calling this function, the application must allocate the memory of the corresponding struct size to the audio buffer.
893
894**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
895
896**Since**: 10
897
898**Deprecated from**: 12
899
900**Substitute API**: [OH_AVScreenCapture_OnBufferAvailable](#oh_avscreencapture_onbufferavailable)
901
902**Parameters**
903
904| Name| Description|
905| -------- | -------- |
906| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
907| 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.|
908| 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).|
909
910**Returns**
911
912Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
913
914**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
915
916**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** or **audiobuffer** is a null pointer.
917
918**AV_SCREEN_CAPTURE_ERR_NO_MEMORY**: The audio buffer fails to be allocated due to insufficient memory.
919
920**AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. The privacy permission fails to be enabled or the audio buffer fails to be obtained.
921
922
923
924### OH_AVScreenCapture_AcquireVideoBuffer()
925
926```
927OH_NativeBuffer* OH_AVScreenCapture_AcquireVideoBuffer (struct OH_AVScreenCapture * capture, int32_t * fence, int64_t * timestamp, struct OH_Rect * region )
928```
929**Description**
930Obtains 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](#oh_avscreencapture_releasevideobuffer) to release it.
931
932**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
933
934**Since**: 10
935
936**Deprecated from**: 12
937
938**Substitute API**: [OH_AVScreenCapture_OnBufferAvailable](#oh_avscreencapture_onbufferavailable)
939
940**Parameters**
941
942| Name| Description|
943| -------- | -------- |
944| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance. |
945| fence | Pointer to parameters for synchronization display. |
946| timestamp | Pointer to the timestamp of the video frame. |
947| region | Pointer to the coordinates related to video display. |
948
949**Returns**
950
951Returns 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.
952
953
954### OH_AVScreenCapture_ContentFilter_AddAudioContent()
955
956```
957OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_ContentFilter_AddAudioContent (struct OH_AVScreenCapture_ContentFilter * filter, OH_AVScreenCaptureFilterableAudioContent content )
958```
959**Description**
960Adds audio content to a content filter.
961
962**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
963
964**Since**: 12
965
966**Parameters**
967
968| Name| Description|
969| -------- | -------- |
970| filter | Pointer to an [OH_AVScreenCapture_ContentFilter](#oh_avscreencapture_contentfilter) instance.|
971| content | [OH_AVScreenCaptureFilterableAudioContent](#oh_avscreencapturefilterableaudiocontent) instance.|
972
973**Returns**
974
975Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
976
977**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
978
979**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **filter** is a null pointer or the input parameter **content** is invalid.
980
981
982### OH_AVScreenCapture_ContentFilter_AddWindowContent()
983
984```
985OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_ContentFilter_AddWindowContent (struct OH_AVScreenCapture_ContentFilter *filter, int32_t *windowIDs, int32_t windowCount)
986```
987**Description**
988Adds a list of window IDs to a **ContentFilter** instance.
989
990**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
991
992**Since**: 12
993
994**Parameters**
995
996| Name| Description|
997| -------- | -------- |
998| filter | Pointer to an **OH_AVScreenCapture_ContentFilter** instance. |
999| windowIDs | Pointer to the window IDs. |
1000| windowCount | Length of the window ID list. |
1001
1002**Returns**
1003
1004Returns **AV_SCREEN_CAPTURE_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1) otherwise.
1005
1006
1007### OH_AVScreenCapture_Create()
1008
1009```
1010struct OH_AVScreenCapture* OH_AVScreenCapture_Create (void )
1011```
1012**Description**
1013Creates an **OH_AVScreenCapture** instance. You can release the instance by calling [OH_AVScreenCapture_Release](#oh_avscreencapture_release).
1014
1015**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1016
1017**Since**: 10
1018
1019**Returns**
1020
1021Returns the pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.
1022
1023
1024### OH_AVScreenCapture_CreateContentFilter()
1025
1026```
1027struct OH_AVScreenCapture_ContentFilter* OH_AVScreenCapture_CreateContentFilter (void )
1028```
1029**Description**
1030Creates a content filter.
1031
1032**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1033
1034**Since**: 12
1035
1036**Returns**
1037
1038Returns [OH_AVScreenCapture_ContentFilter](#oh_avscreencapture_contentfilter) if the operation is successful; returns a null pointer otherwise.
1039
1040
1041### OH_AVScreenCapture_ExcludeContent()
1042
1043```
1044OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_ExcludeContent (struct OH_AVScreenCapture * capture, struct OH_AVScreenCapture_ContentFilter * filter )
1045```
1046**Description**
1047Sets a content filter for an **OH_AVScreenCapture** instance.
1048
1049**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1050
1051**Since**: 12
1052
1053**Parameters**
1054
1055| Name| Description|
1056| -------- | -------- |
1057| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
1058| filter | Pointer to an [OH_AVScreenCapture_ContentFilter](#oh_avscreencapture_contentfilter) instance.|
1059
1060**Returns**
1061
1062Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1063
1064**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1065
1066**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** or **filter** is a null pointer.
1067
1068**AV_SCREEN_CAPTURE_ERR_UNSUPPORT**: The operation is not supported. For streams, the **AudioCapturer** API must be called for the operation to take effect during the start. For captured files, the **AudioRecorder** API must be called for the operation to take effect during the start.
1069
1070
1071### OH_AVScreenCapture_Init()
1072
1073```
1074OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_Init (struct OH_AVScreenCapture * capture, OH_AVScreenCaptureConfig config )
1075```
1076**Description**
1077Initializes parameters related to an [OH_AVScreenCapture](#oh_avscreencapture) instance, including audio sampling parameters for external capture using microphones (optional), audio sampling parameters for internal capture, and video resolution parameters.
1078
1079In the scenario where screen recording files are stored, the application must ensure that the video encoding parameters, video sampling parameters, audio encoding parameters, audio sampling parameters for internal capture, and audio sampling parameters for external capture using microphones (optional) are valid.
1080
1081In the scenario where screen capture streams are generated, the application must ensure that either audio sampling parameters for internal capture or video sampling parameters are valid, or both are valid, and audio sampling parameters for external capture using microphones are valid (optional).
1082
1083The members of the struct variables are not initialized during initialization. Therefore, the application must correctly set the parameters based on the use scenario. You are advised to
1084set all memory bytes of the OH_AVScreenCaptureConfig struct variables to **0**, and then set valid parameters based on the screen capture scenario.
1085
1086If both **audioSampleRate** and **audioChannels** in the [OH_AudioCaptureInfo](#oh_audiocaptureinfo) struct are **0**,
1087the **OH_AVScreenCapture** instance ignores the audio parameters of this type and does not collect the audio data of this type.
1088
1089If both **videoFrameWidth** and **videoFrameHeight** in the [OH_VideoCaptureInfo](#oh_videocaptureinfo) struct are **0**,
1090the **OH_AVScreenCapture** instance ignores the corresponding video parameters and does not collect screen data.
1091
1092**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1093
1094**Since**: 10
1095
1096**Parameters**
1097
1098| Name| Description|
1099| -------- | -------- |
1100| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
1101| config | Parameters related to screen capture initialization.|
1102
1103**Returns**
1104
1105Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1106
1107**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1108
1109**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** is a null pointer.
1110
1111**AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. The configuration fails to be initialized.
1112
1113
1114### OH_AVScreenCapture_Release()
1115
1116```
1117OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_Release (struct OH_AVScreenCapture * capture)
1118```
1119**Description**
1120Releases an **OH_AVScreenCapture** instance. This function is used in pair with [OH_AVScreenCapture_Create](#oh_avscreencapture_create).
1121
1122**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1123
1124**Since**: 10
1125
1126**Parameters**
1127
1128| Name| Description|
1129| -------- | -------- |
1130| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
1131
1132**Returns**
1133
1134Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1135
1136**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1137
1138**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** is a null pointer.
1139
1140**AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. The **OH_AVScreenCapture** instance fails to be released.
1141
1142### OH_AVScreenCapture_ReleaseAudioBuffer()
1143
1144```
1145OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_ReleaseAudioBuffer (struct OH_AVScreenCapture * capture, OH_AudioCaptureSourceType type )
1146```
1147**Description**
1148Releases an audio buffer. After the audio buffer is no longer needed, call this function to release it.
1149
1150**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1151
1152**Since**: 10
1153
1154**Deprecated from**: 12
1155
1156**Substitute API**: [OH_AVScreenCapture_OnBufferAvailable](#oh_avscreencapture_onbufferavailable)
1157
1158**Parameters**
1159
1160| Name| Description|
1161| -------- | -------- |
1162| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
1163| type | Type of the audio buffer, which is used to distinguish external streams recorded by the microphone from internal streams played by the system.|
1164
1165**Returns**
1166
1167Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1168
1169**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1170
1171**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** is a null pointer.
1172
1173**AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. The data callback has been set or the audio buffer fails to be released.
1174
1175
1176### OH_AVScreenCapture_ReleaseContentFilter()
1177
1178```
1179OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_ReleaseContentFilter (struct OH_AVScreenCapture_ContentFilter * filter)
1180```
1181**Description**
1182Releases a content filter.
1183
1184**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1185
1186**Since**: 12
1187
1188**Parameters**
1189
1190| Name| Description|
1191| -------- | -------- |
1192| filter | Pointer to an [OH_AVScreenCapture_ContentFilter](#oh_avscreencapture_contentfilter) instance.|
1193
1194**Returns**
1195
1196Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1197
1198**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1199
1200**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **filter** is a null pointer.
1201
1202
1203### OH_AVScreenCapture_ReleaseVideoBuffer()
1204
1205```
1206OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_ReleaseVideoBuffer (struct OH_AVScreenCapture * capture)
1207```
1208**Description**
1209Releases a video buffer. After the video buffer is no longer needed, call this function to release it.
1210
1211**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1212
1213**Since**: 10
1214
1215**Deprecated from**: 12
1216
1217**Substitute API**: [OH_AVScreenCapture_OnBufferAvailable](#oh_avscreencapture_onbufferavailable)
1218
1219**Parameters**
1220
1221| Name| Description|
1222| -------- | -------- |
1223| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
1224
1225**Returns**
1226
1227Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1228
1229**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1230
1231**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** is a null pointer.
1232
1233**AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. The data callback has been set or the video buffer fails to be released.
1234
1235
1236### OH_AVScreenCapture_SetCallback()
1237
1238```
1239OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetCallback (struct OH_AVScreenCapture * capture, struct OH_AVScreenCaptureCallback callback )
1240```
1241**Description**
1242Sets a callback to listen for available video buffers and audio buffers and errors that occur during the function calling.
1243
1244**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1245
1246**Since**: 10
1247
1248**Deprecated from**: 12
1249
1250**Substitute API**: [OH_AVScreenCapture_SetErrorCallback](#oh_avscreencapture_seterrorcallback) and [OH_AVScreenCapture_SetDataCallback](#oh_avscreencapture_setdatacallback)
1251
1252**Parameters**
1253
1254| Name| Description|
1255| -------- | -------- |
1256| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
1257| callback | [OH_AVScreenCaptureCallback](_o_h___a_v_screen_capture_callback.md) struct, which stores related callback function pointers.|
1258
1259**Returns**
1260
1261Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1262
1263**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1264
1265**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** or **callback** is a null pointer.
1266
1267**AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. The callback fails to be set.
1268
1269
1270### OH_AVScreenCapture_SetCanvasRotation()
1271
1272```
1273OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetCanvasRotation (struct OH_AVScreenCapture * capture, bool canvasRotation )
1274```
1275**Description**
1276Sets canvas rotation for screen capture.
1277
1278You can call this function to set whether to rotate the recorded screen data. When **canvasRotation** is set to **true**, screen capture rotation is enabled and the recorded screen data remains positive.
1279
1280The default value is **false**.
1281
1282**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1283
1284**Since**: 12
1285
1286**Parameters**
1287
1288| Name| Description|
1289| -------- | -------- |
1290| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
1291| canvasRotation | Whether to enable screen data rotation.|
1292
1293**Returns**
1294
1295Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1296
1297**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1298
1299**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** is a null pointer.
1300
1301**AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. Canvas rotation fails to be set for screen capture.
1302
1303
1304### OH_AVScreenCapture_SetDataCallback()
1305
1306```
1307OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetDataCallback (struct OH_AVScreenCapture * capture, OH_AVScreenCapture_OnBufferAvailable callback, void * userData )
1308```
1309**Description**
1310Sets a data processing callback. This function must be called before screen capture starts.
1311
1312The callback is triggered when an audio buffer or a video buffer becomes available during the running of an **OH_AVScreenCapture** instance.
1313
1314The application needs to process microphone audio, internal audio, and video data based on the data type in the callback. After the callback is triggered, the buffer is no longer valid.
1315
1316A successful call to this function leads to the following scenarios:
1317
13181. The callbacks [OH_AVScreenCaptureOnAudioBufferAvailable](#oh_avscreencaptureonaudiobufferavailable) and [OH_AVScreenCaptureOnVideoBufferAvailable](#oh_avscreencaptureonvideobufferavailable) set by calling [OH_AVScreenCapture_SetCallback](#oh_avscreencapture_setcallback) will no longer be triggered, even when an audio buffer or a video buffer becomes available.
13192. A failure message is returned for a call to any of the following functions: [OH_AVScreenCapture_AcquireAudioBuffer](#oh_avscreencapture_acquireaudiobuffer), [OH_AVScreenCapture_ReleaseAudioBuffer](#oh_avscreencapture_releaseaudiobuffer), [OH_AVScreenCapture_AcquireVideoBuffer](#oh_avscreencapture_acquirevideobuffer), and [OH_AVScreenCapture_ReleaseVideoBuffer](#oh_avscreencapture_releasevideobuffer).
1320
1321**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1322
1323**Since**: 12
1324
1325**Parameters**
1326
1327| Name| Description|
1328| -------- | -------- |
1329| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
1330| callback | Data processing callback, which is [OH_AVScreenCapture_OnBufferAvailable](#oh_avscreencapture_onbufferavailable).|
1331| userData | Pointer to the user-defined data. The data is returned as an input parameter when the data processing callback is triggered.|
1332
1333**Returns**
1334
1335Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1336
1337**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1338
1339**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** or **callback** is a null pointer.
1340
1341**AV_SCREEN_CAPTURE_ERR_NO_MEMORY**: The memory fails to be allocated due to insufficient memory.
1342
1343**AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. The data callback fails to be set.
1344
1345
1346### OH_AVScreenCapture_SetDisplayCallback()
1347
1348```
1349OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetDisplayCallback(struct OH_AVScreenCapture *capture, OH_AVScreenCapture_OnDisplaySelected callback, void *userData)
1350```
1351
1352**Description**
1353
1354Sets a callback function for obtaining the display ID.
1355
1356**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1357
1358**Since**: 15
1359
1360**Parameters**
1361
1362| Name| Description|
1363| -------- | -------- |
1364| capture | Pointer to an **OH_AVScreenCapture** instance.|
1365| callback | Callback function for returning the display ID. The callback function is an [OH_AVScreenCapture_OnDisplaySelected](#oh_avscreencapture_ondisplayselected) object.|
1366| userData | Pointer to the user-defined data. The data is returned as an input parameter when the state change callback is triggered.|
1367
1368**Returns**
1369
1370Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1)..
1371
1372**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1373
1374**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** or **callback** is a null pointer.
1375
1376**AV_SCREEN_CAPTURE_ERR_NO_MEMORY**: The memory fails to be allocated due to insufficient memory.
1377
1378**AV_SCREEN_CAPTURE_ERR_INVALID_STATE**: This operation is not supported in the current state. The callback function must be called before **start** is called.
1379
1380
1381### OH_AVScreenCapture_SetErrorCallback()
1382
1383```
1384OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetErrorCallback (struct OH_AVScreenCapture * capture, OH_AVScreenCapture_OnError callback, void * userData )
1385```
1386**Description**
1387Sets an error processing callback. This function must be called before screen capture starts.
1388
1389The callback is triggered when an error occurs during the running of an **OH_AVScreenCapture** instance.
1390
1391After a successful call to this function, the callback [OH_AVScreenCaptureOnError](#oh_avscreencaptureonerror) set by calling [OH_AVScreenCapture_SetCallback](#oh_avscreencapture_setcallback) will no longer be triggered, even when an error occurs in the **OH_AVScreenCapture** instance.
1392
1393**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1394
1395**Since**: 12
1396
1397**Parameters**
1398
1399| Name| Description|
1400| -------- | -------- |
1401| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
1402| callback | Error processing callback, which is [OH_AVScreenCapture_OnError](#oh_avscreencapture_onerror).|
1403| userData | Pointer to the user-defined data. The data is returned as an input parameter when the error processing callback is triggered.|
1404
1405**Returns**
1406
1407Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1408
1409**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1410
1411**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** or **callback** is a null pointer.
1412
1413**AV_SCREEN_CAPTURE_ERR_NO_MEMORY**: The memory fails to be allocated due to insufficient memory.
1414
1415**AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. The error callback fails to be set.
1416
1417
1418### OH_AVScreenCapture_SetMicrophoneEnabled()
1419
1420```
1421OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetMicrophoneEnabled (struct OH_AVScreenCapture * capture, bool isMicrophone )
1422```
1423**Description**
1424Enables 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_StartScreenCapture](#oh_avscreencapture_startscreencapture) and [OH_AVScreenCapture_AcquireAudioBuffer](#oh_avscreencapture_acquireaudiobuffer). When **isMicrophone** is set to **false**, the obtained audio data is silent data.
1425
1426By default, the microphone is enabled.
1427
1428**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1429
1430**Since**: 10
1431
1432**Parameters**
1433
1434| Name| Description|
1435| -------- | -------- |
1436| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
1437| isMicrophone | Whether to enable the microphone.|
1438
1439**Returns**
1440
1441Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1442
1443**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1444
1445**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** is a null pointer.
1446
1447**AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. The microphone fails to be enabled or disabled.
1448
1449
1450### OH_AVScreenCapture_SetStateCallback()
1451
1452```
1453OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetStateCallback (struct OH_AVScreenCapture * capture, OH_AVScreenCapture_OnStateChange callback, void * userData )
1454```
1455**Description**
1456Sets a state change callback. This function must be called before screen capture starts.
1457
1458The callback is triggered when the state changes during the running of an **OH_AVScreenCapture** instance.
1459
1460A privacy dialog box is displayed to ask for user consent before screen capture starts. After a successful call to this function, the following scenarios are possible:
1461
14621. If the user agrees, the screen capture startup process starts. If screen capture starts successfully, the state change callback is triggered to report the [OH_SCREEN_CAPTURE_STATE_STARTED](#oh_avscreencapturestatecode-1) status to notify the application of the startup success, with a screen capture notification displayed.
1463
1464   If screen capture fails to start, the state change callback is triggered to report the failure information (for example, [OH_SCREEN_CAPTURE_STATE_MIC_UNAVAILABLE](#oh_avscreencapturestatecode-1) if the microphone is unavailable), or the error processing callback [OH_AVScreenCapture_OnError](#oh_avscreencapture_onerror) is triggered to report the error information.
1465
14662. If the user disagrees, the screen capture startup process stops. The state change callback is triggered to report the [OH_SCREEN_CAPTURE_STATE_CANCELED](#oh_avscreencapturestatecode-1) status to notify the application of the startup failure due to user rejection.
1467
1468**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1469
1470**Since**: 12
1471
1472**Parameters**
1473
1474| Name| Description|
1475| -------- | -------- |
1476| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
1477| callback | State change callback, which is [OH_AVScreenCapture_OnStateChange](#oh_avscreencapture_onstatechange).|
1478| userData | Pointer to the user-defined data. The data is returned as an input parameter when the state change callback is triggered.|
1479
1480**Returns**
1481
1482Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1483
1484**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1485
1486**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** or **callback** is a null pointer.
1487
1488**AV_SCREEN_CAPTURE_ERR_NO_MEMORY**: The memory fails to be allocated due to insufficient memory.
1489
1490**AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. The state callback fails to be set.
1491
1492
1493### OH_AVScreenCapture_StartScreenCapture()
1494
1495```
1496OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StartScreenCapture (struct OH_AVScreenCapture * capture)
1497```
1498**Description**
1499Starts screen capture and collects original streams. After this function is called, the callback ([OH_AVScreenCapture_OnBufferAvailable](#oh_avscreencapture_onbufferavailable)) can be used to check whether streams are generated, and the callback ([OH_AVScreenCapture_OnStateChange](#oh_avscreencapture_onstatechange)) can be used to check the startup status.
1500
1501The application can obtain the original streams of screen capture by calling [OH_AVScreenCapture_AcquireAudioBuffer](#oh_avscreencapture_acquireaudiobuffer) and [OH_AVScreenCapture_ReleaseVideoBuffer](#oh_avscreencapture_releasevideobuffer).
1502
1503**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1504
1505**Since**: 10
1506
1507**Parameters**
1508
1509| Name| Description|
1510| -------- | -------- |
1511| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
1512
1513**Returns**
1514
1515Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1516
1517**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1518
1519**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** is a null pointer.
1520
1521**AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. The privacy permission fails to be enabled or screen capture fails to start.
1522
1523
1524### OH_AVScreenCapture_StartScreenCaptureWithSurface()
1525
1526```
1527OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StartScreenCaptureWithSurface (struct OH_AVScreenCapture * capture, OHNativeWindow * window )
1528```
1529**Description**
1530Starts screen capture in surface mode.
1531
1532**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1533
1534**Since**: 12
1535
1536**Parameters**
1537
1538| Name| Description|
1539| -------- | -------- |
1540| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
1541| window | Pointer to an [OHNativeWindow](../apis-arkgraphics2d/_native_window.md#ohnativewindow) instance.|
1542
1543**Returns**
1544
1545Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1546
1547**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1548
1549**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture**, input parameter **window**, or **windowSurface** pointed to by **window** is a null pointer.
1550
1551**AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. The privacy permission fails to be enabled or screen capture with a surface fails to start.
1552
1553
1554### OH_AVScreenCapture_StartScreenRecording()
1555
1556```
1557OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StartScreenRecording (struct OH_AVScreenCapture * capture)
1558```
1559**Description**
1560Starts screen recording, with recordings saved in files.
1561
1562**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1563
1564**Since**: 10
1565
1566**Parameters**
1567
1568| Name| Description|
1569| -------- | -------- |
1570| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
1571
1572**Returns**
1573
1574Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1575
1576**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1577
1578**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** is a null pointer.
1579
1580**AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. The privacy permission fails to be enabled or screen capture fails to start.
1581
1582
1583### OH_AVScreenCapture_StopScreenCapture()
1584
1585```
1586OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StopScreenCapture (struct OH_AVScreenCapture * capture)
1587```
1588**Description**
1589Stops screen capture. This function is used in pair with [OH_AVScreenCapture_StartScreenCapture](#oh_avscreencapture_startscreencapture). After calling this function, the application stops screen capture or screen share and releases the microphone.
1590
1591**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1592
1593**Since**: 10
1594
1595**Parameters**
1596
1597| Name| Description|
1598| -------- | -------- |
1599| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
1600
1601**Returns**
1602
1603Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1604
1605**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1606
1607**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** is a null pointer.
1608
1609**AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. Screen capture fails to stop.
1610
1611
1612### OH_AVScreenCapture_StopScreenRecording()
1613
1614```
1615OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StopScreenRecording (struct OH_AVScreenCapture * capture)
1616```
1617**Description**
1618Stops screen recording. This function is used in pair with [OH_AVScreenCapture_StartScreenRecording](#oh_avscreencapture_startscreenrecording).
1619
1620**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1621
1622**Since**: 10
1623
1624**Parameters**
1625
1626| Name| Description|
1627| -------- | -------- |
1628| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
1629
1630**Returns**
1631
1632Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1633
1634**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1635
1636**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** is a null pointer.
1637
1638**AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. Screen capture fails to stop.
1639
1640### OH_AVScreenCapture_ResizeCanvas()
1641
1642```
1643OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_ResizeCanvas (struct OH_AVScreenCapture * capture, int32_t width, int32_t height)
1644```
1645**Description**
1646Adjusts the screen resolution.
1647
1648This function is used to set the resolution of screen capture data. **width** indicates the screen width and **height** indicates the screen height.
1649
1650Currently, this function supports only the scenario of capturing streams, but not the scenario of storing captured files. In addition, the caller of this function and the video data consumer must ensure that they support resolution changes of the received video data.
1651
1652**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1653
1654**Since**: 12
1655
1656**Parameters**
1657
1658| Name| Description|
1659| -------- | -------- |
1660| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
1661| width | Width of the screen to capture.|
1662| height | Height of the screen to capture.|
1663
1664**Returns**
1665
1666Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1667
1668**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1669
1670**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** is a null pointer.
1671
1672**AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed.
1673
1674
1675### OH_AVScreenCapture_ShowCursor()
1676
1677```
1678OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_ShowCursor(struct OH_AVScreenCapture *capture, bool showCursor)
1679```
1680
1681**Description**
1682
1683Sets whether to show the cursor.
1684
1685**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1686
1687**Since**: 15
1688
1689**Parameters**
1690
1691| Name| Description|
1692| -------- | -------- |
1693| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
1694| showCursor | Whether to show the cursor.|
1695
1696**Returns**
1697
1698Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1699
1700**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1701
1702**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** is a null pointer.
1703
1704**AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. The cursor setting fails.
1705
1706
1707### OH_AVScreenCapture_SkipPrivacyMode()
1708
1709```
1710OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SkipPrivacyMode (struct OH_AVScreenCapture * capture, int32_t *windowIDs, int32_t windowCount)
1711```
1712**Description**
1713Exempts privacy windows during screen capture.
1714
1715Currently, all the IDs of the subwindows and main windows to skip must be passed in.
1716
1717**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1718
1719**Since**: 12
1720
1721**Parameters**
1722
1723| Name| Description|
1724| -------- | -------- |
1725| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
1726| windowIDs | Pointer to the IDs of the privacy windows to skip.|
1727| windowCount | Length of the privacy window ID list.|
1728
1729**Returns**
1730
1731Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1732
1733**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1734
1735**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** is a null pointer.
1736
1737**AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed.
1738
1739
1740### OH_AVScreenCapture_SetMaxVideoFrameRate()
1741```
1742OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetMaxVideoFrameRate (struct OH_AVScreenCapture * capture, int32_t frameRate)
1743```
1744**Description**
1745Sets the maximum frame rate for screen capture.
1746
1747This function must be called after screen capture starts.
1748
1749
1750
1751The maximum frame rate that can be configured is subject to the device's limitations and is ultimately governed by the capabilities of the underlying system.
1752
1753 Although there is no limit on the maximum value of the input parameter, the maximum frame rate supported is 60 FPS. If the input parameter value exceeds 60 FPS, 60 FPS is used. If the value does not exceed the upper limit, the passed value is used.
1754
1755**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
1756
1757**Since**: 14
1758
1759**Parameters**
1760
1761| Name| Description|
1762| -------- | -------- |
1763| capture | Pointer to an [OH_AVScreenCapture](#oh_avscreencapture) instance.|
1764| frameRate | Maximum frame rate.|
1765
1766**Returns**
1767
1768Returns a result code defined in [OH_AVSCREEN_CAPTURE_ErrCode](#oh_avscreen_capture_errcode-1).
1769
1770**AV_SCREEN_CAPTURE_ERR_OK**: The operation is successful.
1771
1772**AV_SCREEN_CAPTURE_ERR_INVALID_VAL**: The input parameter **capture** is a null pointer, or the input parameter **frameRate** is not supported.
1773
1774**AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT**: The operation is restricted. You are advised to try again.
1775