1# avrecorder_base.h 2<!--Kit: Media Kit--> 3<!--Subsystem: Multimedia--> 4<!--Owner: @shiwei75--> 5<!--Designer: @HmQQQ--> 6<!--Tester: @xdlinc--> 7<!--Adviser: @zengyawen--> 8 9## Overview 10 11The file declares the struct and enums used by the AVRecorder. 12 13**File to include**: <multimedia/player_framework/avrecorder_base.h> 14 15**Library**: libavrecorder.so 16 17**System capability**: SystemCapability.Multimedia.Media.AVRecorder 18 19**Since**: 18 20 21**Related module**: [AVRecorder](capi-avrecorder.md) 22 23## Summary 24 25### Structs 26 27| Name| typedef Keyword| Description| 28| -- | -- | -- | 29| [OH_AVRecorder_Profile](capi-avrecorder-oh-avrecorder-profile.md) | OH_AVRecorder_Profile | Describes the parameters used for audio and video recording.| 30| [OH_AVRecorder](capi-avrecorder-oh-avrecorder.md) | OH_AVRecorder | Describes an initialized AVRecorder.| 31| [OH_AVRecorder_Location](capi-avrecorder-oh-avrecorder-location.md) | OH_AVRecorder_Location | Describes the geographical location information about a media asset.| 32| [OH_AVRecorder_MetadataTemplate](capi-avrecorder-oh-avrecorder-metadatatemplate.md) | OH_AVRecorder_MetadataTemplate | Describes the basic template of metadata.| 33| [OH_AVRecorder_Metadata](capi-avrecorder-oh-avrecorder-metadata.md) | OH_AVRecorder_Metadata | Describes the metadata.| 34| [OH_AVRecorder_Config](capi-avrecorder-oh-avrecorder-config.md) | OH_AVRecorder_Config | Describes the AVRecorder configuration.| 35| [OH_AVRecorder_Range](capi-avrecorder-oh-avrecorder-range.md) | OH_AVRecorder_Range | Describes the range.| 36| [OH_AVRecorder_EncoderInfo](capi-avrecorder-oh-avrecorder-encoderinfo.md) | OH_AVRecorder_EncoderInfo | Describes the encoder information.| 37 38### Enums 39 40| Name| typedef Keyword| Description| 41| -- | -- | -- | 42| [OH_AVRecorder_AudioSourceType](#oh_avrecorder_audiosourcetype) | OH_AVRecorder_AudioSourceType | Enumerates the audio source types of the AVRecorder.| 43| [OH_AVRecorder_VideoSourceType](#oh_avrecorder_videosourcetype) | OH_AVRecorder_VideoSourceType | Enumerates the video source types of the AVRecorder.| 44| [OH_AVRecorder_CodecMimeType](#oh_avrecorder_codecmimetype) | OH_AVRecorder_CodecMimeType | Enumerates the MIME types of the encoder.| 45| [OH_AVRecorder_ContainerFormatType](#oh_avrecorder_containerformattype) | OH_AVRecorder_ContainerFormatType | Enumerates the Container Format Types (CFTs).| 46| [OH_AVRecorder_State](#oh_avrecorder_state) | OH_AVRecorder_State | Enumerates the AVRecorder states.| 47| [OH_AVRecorder_StateChangeReason](#oh_avrecorder_statechangereason) | OH_AVRecorder_StateChangeReason | Enumerates the reasons for AVRecorder state changes.| 48| [OH_AVRecorder_FileGenerationMode](#oh_avrecorder_filegenerationmode) | OH_AVRecorder_FileGenerationMode | Enumerates the modes available for creating a recording file.| 49 50### Functions 51 52| Name| typedef Keyword| Description| 53| -- | -- | -- | 54| [typedef void (\*OH_AVRecorder_OnStateChange)(OH_AVRecorder *recorder, OH_AVRecorder_State state, OH_AVRecorder_StateChangeReason reason, void *userData)](#oh_avrecorder_onstatechange) | OH_AVRecorder_OnStateChange | Called when the AVRecorder state changes.| 55| [typedef void (\*OH_AVRecorder_OnError)(OH_AVRecorder *recorder, int32_t errorCode, const char *errorMsg, void *userData)](#oh_avrecorder_onerror) | OH_AVRecorder_OnError | Called when an error occurs during recording.| 56| [typedef void (\*OH_AVRecorder_OnUri)(OH_AVRecorder *recorder, OH_MediaAsset *asset, void *userData)](#oh_avrecorder_onuri) | OH_AVRecorder_OnUri | Called when the recording is in [OH_AVRecorder_FileGenerationMode](#oh_avrecorder_filegenerationmode).AVRECORDER_AUTO_CREATE_CAMERA_SCENE mode.| 57 58## Enum Description 59 60### OH_AVRecorder_AudioSourceType 61 62``` 63enum OH_AVRecorder_AudioSourceType 64``` 65 66**Description** 67 68Enumerates the audio source types of the AVRecorder. 69 70**System capability**: SystemCapability.Multimedia.Media.AVRecorder 71 72**Since**: 18 73 74| Enum Item| Description| 75| -- | -- | 76| AVRECORDER_DEFAULT = 0 | Default audio source.| 77| AVRECORDER_MIC = 1 | Microphone audio source.| 78| AVRECORDER_VOICE_RECOGNITION = 2 | Audio source in speech recognition scenarios.| 79| AVRECORDER_VOICE_COMMUNICATION = 7 | Voice communication source.| 80| AVRECORDER_VOICE_MESSAGE = 10 | Voice message source.| 81| AVRECORDER_CAMCORDER = 13 | Audio source in camera recording scenarios.| 82 83### OH_AVRecorder_VideoSourceType 84 85``` 86enum OH_AVRecorder_VideoSourceType 87``` 88 89**Description** 90 91Enumerates the video source types of the AVRecorder. 92 93**System capability**: SystemCapability.Multimedia.Media.AVRecorder 94 95**Since**: 18 96 97| Enum Item| Description| 98| -- | -- | 99| AVRECORDER_SURFACE_YUV = 0 | Raw data surface.| 100| AVRECORDER_SURFACE_ES = 1 | ES data surface.| 101 102### OH_AVRecorder_CodecMimeType 103 104``` 105enum OH_AVRecorder_CodecMimeType 106``` 107 108**Description** 109 110Enumerates the MIME types of the encoder. 111 112**System capability**: SystemCapability.Multimedia.Media.AVRecorder 113 114**Since**: 18 115 116| Enum Item| Description| 117| -- | -- | 118| AVRECORDER_VIDEO_AVC = 2 | MIME type of the H.264 encoder.| 119| AVRECORDER_AUDIO_AAC = 3 | MIME type of the AAC encoder.| 120| AVRECORDER_AUDIO_MP3 = 4 | MIME type of the MP3 encoder.| 121| AVRECORDER_AUDIO_G711MU = 5 | MIME type of the G711-mulaw encoder.| 122| AVRECORDER_VIDEO_MPEG4 = 6 | MIME type of the MPEG4 encoder.| 123| AVRECORDER_VIDEO_HEVC = 8 | MIME type of the H.265 encoder.| 124| AVRECORDER_AUDIO_AMR_NB = 9 | MIME type of the AMR-NB codec.| 125| AVRECORDER_AUDIO_AMR_WB = 10 | MIME type of the AMR-WB codec.| 126 127### OH_AVRecorder_ContainerFormatType 128 129``` 130enum OH_AVRecorder_ContainerFormatType 131``` 132 133**Description** 134 135Enumerates the Container Format Types (CFTs). 136 137**System capability**: SystemCapability.Multimedia.Media.AVRecorder 138 139**Since**: 18 140 141| Enum Item| Description| 142| -- | -- | 143| AVRECORDER_CFT_MPEG_4 = 2 | Video container format mp4.| 144| AVRECORDER_CFT_MPEG_4A = 6 | Audio container format m4a.| 145| AVRECORDER_CFT_AMR = 8 | Audio container format amr.| 146| AVRECORDER_CFT_MP3 = 9 | Audio container format mp3.| 147| AVRECORDER_CFT_WAV = 10 | Audio container format wav.| 148| AVRECORDER_CFT_AAC = 11 | Audio container format aac (with ADTS header).<br>**Since**: 20| 149 150### OH_AVRecorder_State 151 152``` 153enum OH_AVRecorder_State 154``` 155 156**Description** 157 158Enumerates the AVRecorder states. 159 160**System capability**: SystemCapability.Multimedia.Media.AVRecorder 161 162**Since**: 18 163 164| Enum Item| Description| 165| -- | -- | 166| AVRECORDER_IDLE = 0 | Idle. In this state, you can call [OH_AVRecorder_Prepare](capi-avrecorder-h.md#oh_avrecorder_prepare) to set recording parameters, and the AVRecorder transitions to the AVRECORDER_PREPARED state.| 167| AVRECORDER_PREPARED = 1 | Prepared. After the parameters are set, you can call [OH_AVRecorder_Start](capi-avrecorder-h.md#oh_avrecorder_start) to start recording, and the AVRecorder transitions to the AVRECORDER_STARTED state.| 168| AVRECORDER_STARTED = 2 | Started. Recording is in progress. In this case, you can call [OH_AVRecorder_Pause](capi-avrecorder-h.md#oh_avrecorder_pause) to pause recording, and the AVRecorder transitions to the AVRECORDER_PAUSED state.<br>You can also call [OH_AVRecorder_Stop](capi-avrecorder-h.md#oh_avrecorder_stop) to stop recording, and the AVRecorder transitions to the AVRECORDER_STOPPED state.| 169| AVRECORDER_PAUSED = 3 | Paused. In this state, you can call [OH_AVRecorder_Resume](capi-avrecorder-h.md#oh_avrecorder_resume) to resume recording, and the AVRecorder transitions to the AVRECORDER_STARTED state.<br>You can also call [OH_AVRecorder_Stop](capi-avrecorder-h.md#oh_avrecorder_stop) to stop recording, and the AVRecorder transitions to the AVRECORDER_STOPPED state.| 170| AVRECORDER_STOPPED = 4 | Stopped. In this state, you can call [OH_AVRecorder_Prepare](capi-avrecorder-h.md#oh_avrecorder_prepare) to set recording parameters, and the AVRecorder transitions to the AVRECORDER_PREPARED state again.| 171| AVRECORDER_RELEASED = 5 | Released. The recording resources are released. No operation can be performed at this time. In any other state, you can call [OH_AVRecorder_Release](capi-avrecorder-h.md#oh_avrecorder_release) to transition to the AVRECORDER_RELEASED state.| 172| AVRECORDER_ERROR = 6 | Error state. The AVRecorder transitions to this state when an irreversible error occurs in the instance.<br>In this state, the [OH_AVRecorder_OnError](#oh_avrecorder_onerror) event is reported, with the detailed error cause.<br>You should call [OH_AVRecorder_Reset](capi-avrecorder-h.md#oh_avrecorder_reset) to reset the AVRecorder instance or call [OH_AVRecorder_Release](capi-avrecorder-h.md#oh_avrecorder_release) to release resources.| 173 174### OH_AVRecorder_StateChangeReason 175 176``` 177enum OH_AVRecorder_StateChangeReason 178``` 179 180**Description** 181 182Enumerates the reasons for AVRecorder state changes. 183 184**System capability**: SystemCapability.Multimedia.Media.AVRecorder 185 186**Since**: 18 187 188| Enum Item| Description| 189| -- | -- | 190| AVRECORDER_USER = 0 | The state change is caused by user operations.| 191| AVRECORDER_BACKGROUND = 1 | The state change is caused by background operations.| 192 193### OH_AVRecorder_FileGenerationMode 194 195``` 196enum OH_AVRecorder_FileGenerationMode 197``` 198 199**Description** 200 201Enumerates the modes available for creating a recording file. 202 203**System capability**: SystemCapability.Multimedia.Media.AVRecorder 204 205**Since**: 18 206 207| Enum Item| Description| 208| -- | -- | 209| AVRECORDER_APP_CREATE = 0 | The application creates a media file in the sandbox.| 210| AVRECORDER_AUTO_CREATE_CAMERA_SCENE = 1 | The system creates a media file. This value is valid only in camera recording scenarios.| 211 212 213## Function Description 214 215### OH_AVRecorder_OnStateChange() 216 217``` 218typedef void (*OH_AVRecorder_OnStateChange)(OH_AVRecorder *recorder,OH_AVRecorder_State state, OH_AVRecorder_StateChangeReason reason, void *userData) 219``` 220 221**Description** 222 223Called when the AVRecorder state changes. 224 225**System capability**: SystemCapability.Multimedia.Media.AVRecorder 226 227**Since**: 18 228 229 230**Parameters** 231 232| Parameter| Description| 233| -- | -- | 234| [OH_AVRecorder](capi-avrecorder-oh-avrecorder.md) *recorder | Pointer to the OH_AVRecorder instance.| 235| [OH_AVRecorder_State](#oh_avrecorder_state) state | AVRecorder state.| 236| [OH_AVRecorder_StateChangeReason](#oh_avrecorder_statechangereason) reason | Reason for the AVRecorder state change.| 237| void *userData | Pointer to user-defined data.| 238 239### OH_AVRecorder_OnError() 240 241``` 242typedef void (*OH_AVRecorder_OnError)(OH_AVRecorder *recorder, int32_t errorCode, const char *errorMsg,void *userData) 243``` 244 245**Description** 246 247Called when an error occurs during recording. 248 249**System capability**: SystemCapability.Multimedia.Media.AVRecorder 250 251**Since**: 18 252 253 254**Parameters** 255 256| Parameter| Description| 257| -- | -- | 258| [OH_AVRecorder](capi-avrecorder-oh-avrecorder.md) *recorder | Pointer to the OH_AVRecorder instance.| 259| int32_t errorCode | Error code. For details, see [AVErrorCode](../apis-avcodec-kit/_core.md#oh_averrcode-1).| 260| const char *errorMsg | Pointer to the error message.| 261| void *userData | Pointer to user-defined data.| 262 263### OH_AVRecorder_OnUri() 264 265``` 266typedef void (*OH_AVRecorder_OnUri)(OH_AVRecorder *recorder, OH_MediaAsset *asset, void *userData) 267``` 268 269**Description** 270 271Called when the recording is in [OH_AVRecorder_FileGenerationMode](#oh_avrecorder_filegenerationmode).AVRECORDER_AUTO_CREATE_CAMERA_SCENE mode. 272 273**System capability**: SystemCapability.Multimedia.Media.AVRecorder 274 275**Since**: 18 276 277 278**Parameters** 279 280| Parameter| Description| 281| -- | -- | 282| [OH_AVRecorder](capi-avrecorder-oh-avrecorder.md) *recorder | Pointer to the OH_AVRecorder instance.| 283| [OH_MediaAsset](../apis-media-library-kit/capi-mediaassetmanager-oh-mediaasset.md) *asset | Pointer to the OH_MediaAsset instance.| 284| void *userData | Pointer to user-defined data.| 285