未验证 提交 46958847 编写于 作者: O openharmony_ci 提交者: Gitee

!17454 Add 英文native api,无需翻译

Merge pull request !17454 from zengyawen/nativeapis-en
# Native API
- Modules
- [Native XComponent](_o_h___native_x_component.md)
- [HiLog](_hi_log.md)
- [NativeWindow](_native_window.md)
- [Drawing](_drawing.md)
- [Image](image.md)
- [Rawfile](rawfile.md)
- [MindSpore](_mind_spore.md)
- [NeuralNeworkRuntime](_neural_nework_runtime.md)
- [AudioDecoder](_audio_decoder.md)
- [AudioEncoder](_audio_encoder.md)
- [CodecBase](_codec_base.md)
- [VideoDecoder](_video_decoder.md)
- [VideoEncoder](_video_encoder.md)
- [Core](_core.md)
- [HuksKeyApi](_huks_key_api.md)
- [HuksParamSetApi](_huks_param_set_api.md)
- [HuksTypeApi](_huks_type_api.md)
- Header Files
- [drawing_bitmap.h](drawing__bitmap_8h.md)
- [drawing_brush.h](drawing__brush_8h.md)
- [drawing_canvas.h](drawing__canvas_8h.md)
- [drawing_color.h](drawing__color_8h.md)
- [drawing_font_collection.h](drawing__font__collection_8h.md)
- [drawing_path.h](drawing__path_8h.md)
- [drawing_pen.h](drawing__pen_8h.md)
- [drawing_text_declaration.h](drawing__text__declaration_8h.md)
- [drawing_text_typography.h](drawing__text__typography_8h.md)
- [drawing_types.h](drawing__types_8h.md)
- [external_window.h](external__window_8h.md)
- [image_pixel_map_napi.h](image__pixel__map__napi_8h.md)
- [log.h](log_8h.md)
- [native_interface_xcomponent.h](native__interface__xcomponent_8h.md)
- [raw_dir.h](raw__dir_8h.md)
- [raw_file_manager.h](raw__file__manager_8h.md)
- [raw_file.h](raw__file_8h.md)
- [context.h](context_8h.md)
- [data_type.h](data__type_8h.md)
- [format.h](format_8h.md)
- [model.h](model_8h.md)
- [status.h](status_8h.md)
- [tensor.h](tensor_8h.md)
- [types.h](types_8h.md)
- [neural_network_runtime_type.h](neural__network__runtime__type_8h.md)
- [neural_network_runtime.h](neural__network__runtime_8h.md)
- [native_avcodec_audiodecoder.h](native__avcodec__audiodecoder_8h.md)
- [native_avcodec_audioencoder.h](native__avcodec__audioencoder_8h.md)
- [native_avcodec_base.h](native__avcodec__base_8h.md)
- [native_avcodec_videodecoder.h](native__avcodec__videodecoder_8h.md)
- [native_avcodec_videoencoder.h](native__avcodec__videoencoder_8h.md)
- [native_averrors.h](native__averrors_8h.md)
- [native_avformat.h](native__avformat_8h.md)
- [native_avmemory.h](native__avmemory_8h.md)
- [native_huks_api.h](native__huks__api_8h.md)
- [native_huks_param.h](native__huks__param_8h.md)
- [native_huks_type.h](native__huks__type_8h.md)
- Structs
- [OH_Drawing_BitmapFormat](_o_h___drawing___bitmap_format.md)
- [OH_NativeXComponent_Callback](_o_h___native_x_component___callback.md)
- [OH_NativeXComponent_MouseEvent](_o_h___native_x_component___mouse_event.md)
- [OH_NativeXComponent_MouseEvent_Callback](_o_h___native_x_component___mouse_event___callback.md)
- [OH_NativeXComponent_TouchEvent](_o_h___native_x_component___touch_event.md)
- [OH_NativeXComponent_TouchPoint](_o_h___native_x_component___touch_point.md)
- [OHExtDataHandle](_o_h_ext_data_handle.md)
- [OHHDRMetaData](_o_h_h_d_r_meta_data.md)
- [OhosPixelMapCreateOps](_ohos_pixel_map_create_ops.md)
- [OhosPixelMapInfo](_ohos_pixel_map_info.md)
- [RawFileDescriptor](_raw_file_descriptor.md)
- [Region](_region.md)
- [Rect](_rect.md)
- [OH_AI_CallBackParam](_o_h___a_i___call_back_param.md)
- [OH_AI_ShapeInfo](_o_h___a_i___shape_info.md)
- [OH_AI_TensorHandleArray](_o_h___a_i___tensor_handle_array.md)
- [OH_NN_Memory](_o_h___n_n___memory.md)
- [OH_NN_QuantParam](_o_h___n_n___quant_param.md)
- [OH_NN_Tensor](_o_h___n_n___tensor.md)
- [OH_NN_UInt32Array](_o_h___n_n___u_int32_array.md)
- [OH_AVCodecAsyncCallback](_o_h___a_v_codec_async_callback.md)
- [OH_AVCodecBufferAttr](_o_h___a_v_codec_buffer_attr.md)
- [OH_Huks_Blob](_o_h___huks___blob.md)
- [OH_Huks_CertChain](_o_h___huks___cert_chain.md)
- [OH_Huks_KeyInfo](_o_h___huks___key_info.md)
- [OH_Huks_KeyMaterial25519](_o_h___huks___key_material25519.md)
- [OH_Huks_KeyMaterialDh](_o_h___huks___key_material_dh.md)
- [OH_Huks_KeyMaterialDsa](_o_h___huks___key_material_dsa.md)
- [OH_Huks_KeyMaterialEcc](_o_h___huks___key_material_ecc.md)
- [OH_Huks_KeyMaterialRsa](_o_h___huks___key_material_rsa.md)
- [OH_Huks_Param](_o_h___huks___param.md)
- [OH_Huks_ParamSet](_o_h___huks___param_set.md)
- [OH_Huks_PubKeyInfo](_o_h___huks___pub_key_info.md)
- [OH_Huks_Result](_o_h___huks___result.md)
# AudioDecoder
## Overview
Provides the functions for audio decoding.
\@syscap SystemCapability.Multimedia.Media.AudioDecoder
**Since:**
9
## Summary
### Files
| Name | Description |
| -------- | -------- |
| [native_avcodec_audiodecoder.h](native__avcodec__audiodecoder_8h.md) | Declares the native APIs used for audio decoding. <br>File to Include: <multimedia/player_framework/native_avcodec_audiodecoder.h> |
### Functions
| Name | Description |
| -------- | -------- |
| [OH_AudioDecoder_CreateByMime](#oh_audiodecoder_createbymime) (const char \*mime) | Creates an audio decoder instance based on a Multipurpose Internet Mail Extension (MIME) type. This API is recommended in most cases. |
| [OH_AudioDecoder_CreateByName](#oh_audiodecoder_createbyname) (const char \*name) | Creates an audio decoder instance based on an audio decoder name. To use this API, you must know the exact name of the audio decoder. |
| [OH_AudioDecoder_Destroy](#oh_audiodecoder_destroy) (OH_AVCodec \*codec) | Clears the internal resources of an audio decoder and destroys the audio decoder instance. |
| [OH_AudioDecoder_SetCallback](#oh_audiodecoder_setcallback) (OH_AVCodec \*codec, [OH_AVCodecAsyncCallback](_o_h___a_v_codec_async_callback.md) callback, void \*userData) | Sets an asynchronous callback so that your application can respond to events generated by an audio decoder. This API must be called prior to **Prepare**. |
| [OH_AudioDecoder_Configure](#oh_audiodecoder_configure) (OH_AVCodec \*codec, OH_AVFormat \*format) | Configures an audio decoder. Typically, you need to configure the attributes, which can be extracted from the container, of the audio track that can be decoded. This API must be called prior to **Prepare**. |
| [OH_AudioDecoder_Prepare](#oh_audiodecoder_prepare) (OH_AVCodec \*codec) | Prepares internal resources for an audio decoder. This API must be called after **Configure**. |
| [OH_AudioDecoder_Start](#oh_audiodecoder_start) (OH_AVCodec \*codec) | Starts an audio decoder. This API can be called only after the decoder is prepared successfully. After being started, the decoder starts to report the [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) event. |
| [OH_AudioDecoder_Stop](#oh_audiodecoder_stop) (OH_AVCodec \*codec) | Stops an audio decoder. After the decoder is stopped, you can call **Start** to start it again. If you have passed codec-specific data in the previous **Start** for the decoder, you must pass it again. |
| [OH_AudioDecoder_Flush](#oh_audiodecoder_flush) (OH_AVCodec \*codec) | Clears the input and output data in the internal buffer of an audio decoder. This API invalidates the indexes of all buffers previously reported through the asynchronous callback. Therefore, before calling this API, ensure that the buffers corresponding to the indexes are no longer required. |
| [OH_AudioDecoder_Reset](#oh_audiodecoder_reset) (OH_AVCodec \*codec) | Resets an audio decoder. To continue decoding, you must call **Configure** and **Start** to configure and start the decoder again. |
| [OH_AudioDecoder_GetOutputDescription](#oh_audiodecoder_getoutputdescription) (OH_AVCodec \*codec) | Obtains the attributes of the output data of an audio decoder. The caller must manually release the **OH_AVFormat** instance in the return value. |
| [OH_AudioDecoder_SetParameter](#oh_audiodecoder_setparameter) (OH_AVCodec \*codec, OH_AVFormat \*format) | Sets dynamic parameters for an audio decoder. This API can be called only after the decoder is started. Incorrect parameter settings may cause decoding failure. |
| [OH_AudioDecoder_PushInputData](#oh_audiodecoder_pushinputdata) (OH_AVCodec \*codec, uint32_t index, [OH_AVCodecBufferAttr](_o_h___a_v_codec_buffer_attr.md) attr) | Pushes the input buffer filled with data to an audio decoder. The [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) callback reports available input buffers and their indexes. After being pushed to the decoder, a buffer is not accessible until the buffer with the same index is reported again through the [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) callback. In addition, some decoders require the input of codec-specific data to initialize the decoding process. |
| [OH_AudioDecoder_FreeOutputData](#oh_audiodecoder_freeoutputdata) (OH_AVCodec \*codec, uint32_t index) | Frees an output buffer of an audio decoder. |
## Function Description
### OH_AudioDecoder_Configure()
```
OH_AVErrCode OH_AudioDecoder_Configure (OH_AVCodec * codec, OH_AVFormat * format )
```
**Description**<br>
Configures an audio decoder. Typically, you need to configure the attributes, which can be extracted from the container, of the audio track that can be decoded. This API must be called prior to **Prepare**.
\@syscap SystemCapability.Multimedia.Media.AudioDecoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
| format | Indicates the handle to an **OH_AVFormat** instance, which provides the attributes of the audio track to be decoded. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_AudioDecoder_CreateByMime()
```
OH_AVCodec* OH_AudioDecoder_CreateByMime (const char * mime)
```
**Description**<br>
Creates an audio decoder instance based on a Multipurpose Internet Mail Extension (MIME) type. This API is recommended in most cases.
\@syscap SystemCapability.Multimedia.Media.AudioDecoder
**Parameters**
| Name | Description |
| -------- | -------- |
| mime | Indicates the pointer to a MIME type. For details, see [OH_AVCODEC_MIMETYPE_AUDIO_AAC](_codec_base.md#oh_avcodec_mimetype_audio_aac). |
**Returns**
Returns the pointer to an **OH_AVCodec** instance.
### OH_AudioDecoder_CreateByName()
```
OH_AVCodec* OH_AudioDecoder_CreateByName (const char * name)
```
**Description**<br>
Creates an audio decoder instance based on an audio decoder name. To use this API, you must know the exact name of the audio decoder.
\@syscap SystemCapability.Multimedia.Media.AudioDecoder
**Parameters**
| Name | Description |
| -------- | -------- |
| name | Indicates the pointer to an audio decoder name. |
**Returns**
Returns the pointer to an **OH_AVCodec** instance.
### OH_AudioDecoder_Destroy()
```
OH_AVErrCode OH_AudioDecoder_Destroy (OH_AVCodec * codec)
```
**Description**<br>
Clears the internal resources of an audio decoder and destroys the audio decoder instance.
\@syscap SystemCapability.Multimedia.Media.AudioDecoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_AudioDecoder_Flush()
```
OH_AVErrCode OH_AudioDecoder_Flush (OH_AVCodec * codec)
```
**Description**<br>
Clears the input and output data in the internal buffer of an audio decoder. This API invalidates the indexes of all buffers previously reported through the asynchronous callback. Therefore, before calling this API, ensure that the buffers corresponding to the indexes are no longer required.
\@syscap SystemCapability.Multimedia.Media.AudioDecoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_AudioDecoder_FreeOutputData()
```
OH_AVErrCode OH_AudioDecoder_FreeOutputData (OH_AVCodec * codec, uint32_t index )
```
**Description**<br>
Frees an output buffer of an audio decoder.
\@syscap SystemCapability.Multimedia.Media.AudioDecoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
| index | Indicates the index of an output buffer. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_AudioDecoder_GetOutputDescription()
```
OH_AVFormat* OH_AudioDecoder_GetOutputDescription (OH_AVCodec * codec)
```
**Description**<br>
Obtains the attributes of the output data of an audio decoder. The caller must manually release the **OH_AVFormat** instance in the return value.
\@syscap SystemCapability.Multimedia.Media.AudioDecoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns the handle to an **OH_AVFormat** instance, which must be manually released.
### OH_AudioDecoder_Prepare()
```
OH_AVErrCode OH_AudioDecoder_Prepare (OH_AVCodec * codec)
```
**Description**<br>
Prepares internal resources for an audio decoder. This API must be called after **Configure**.
\@syscap SystemCapability.Multimedia.Media.AudioDecoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_AudioDecoder_PushInputData()
```
OH_AVErrCode OH_AudioDecoder_PushInputData (OH_AVCodec * codec, uint32_t index, OH_AVCodecBufferAttr attr )
```
**Description**<br>
Pushes the input buffer filled with data to an audio decoder. The [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) callback reports available input buffers and their indexes. After being pushed to the decoder, a buffer is not accessible until the buffer with the same index is reported again through the [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) callback. In addition, some decoders require the input of codec-specific data to initialize the decoding process.
\@syscap SystemCapability.Multimedia.Media.AudioDecoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
| index | Indicates the index of an input buffer. |
| attr | Indicates the attributes of the data contained in the buffer. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_AudioDecoder_Reset()
```
OH_AVErrCode OH_AudioDecoder_Reset (OH_AVCodec * codec)
```
**Description**<br>
Resets an audio decoder. To continue decoding, you must call **Configure** and **Start** to configure and start the decoder again.
\@syscap SystemCapability.Multimedia.Media.AudioDecoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_AudioDecoder_SetCallback()
```
OH_AVErrCode OH_AudioDecoder_SetCallback (OH_AVCodec * codec, OH_AVCodecAsyncCallback callback, void * userData )
```
**Description**<br>
Sets an asynchronous callback so that your application can respond to events generated by an audio decoder. This API must be called prior to **Prepare**.
\@syscap SystemCapability.Multimedia.Media.AudioDecoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
| callback | Indicates a collection of all callback functions. For details, see [OH_AVCodecAsyncCallback](_o_h___a_v_codec_async_callback.md). |
| userData | Indicates the pointer to user-specific data. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_AudioDecoder_SetParameter()
```
OH_AVErrCode OH_AudioDecoder_SetParameter (OH_AVCodec * codec, OH_AVFormat * format )
```
**Description**<br>
Sets dynamic parameters for an audio decoder. This API can be called only after the decoder is started. Incorrect parameter settings may cause decoding failure.
\@syscap SystemCapability.Multimedia.Media.AudioDecoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
| format | Indicates the handle to an **OH_AVFormat** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_AudioDecoder_Start()
```
OH_AVErrCode OH_AudioDecoder_Start (OH_AVCodec * codec)
```
**Description**<br>
Starts an audio decoder. This API can be called only after the decoder is prepared successfully. After being started, the decoder starts to report the [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) event.
\@syscap SystemCapability.Multimedia.Media.AudioDecoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_AudioDecoder_Stop()
```
OH_AVErrCode OH_AudioDecoder_Stop (OH_AVCodec * codec)
```
**Description**<br>
Stops an audio decoder. After the decoder is stopped, you can call **Start** to start it again. If you have passed codec-specific data in the previous **Start** for the decoder, you must pass it again.
\@syscap SystemCapability.Multimedia.Media.AudioDecoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
# AudioEncoder
## Overview
Provides the functions for audio encoding.
\@syscap SystemCapability.Multimedia.Media.AudioEncoder
**Since:**
9
## Summary
### Files
| Name | Description |
| -------- | -------- |
| [native_avcodec_audioencoder.h](native__avcodec__audioencoder_8h.md) | Declares the native APIs used for audio encoding. <br>File to Include: <multimedia/player_framework/native_avcodec_audioencoder.h> |
### Functions
| Name | Description |
| -------- | -------- |
| [OH_AudioEncoder_CreateByMime](#oh_audioencoder_createbymime) (const char \*mime) | Creates an audio encoder instance based on a Multipurpose Internet Mail Extension (MIME) type. This API is recommended in most cases. |
| [OH_AudioEncoder_CreateByName](#oh_audioencoder_createbyname) (const char \*name) | Creates an audio encoder instance based on an audio encoder name. To use this API, you must know the exact name of the audio encoder. |
| [OH_AudioEncoder_Destroy](#oh_audioencoder_destroy) (OH_AVCodec \*codec) | Clears the internal resources of an audio encoder and destroys the audio encoder instance. |
| [OH_AudioEncoder_SetCallback](#oh_audioencoder_setcallback) (OH_AVCodec \*codec, [OH_AVCodecAsyncCallback](_o_h___a_v_codec_async_callback.md) callback, void \*userData) | Sets an asynchronous callback so that your application can respond to events generated by an audio encoder. This API must be called prior to **Prepare**. |
| [OH_AudioEncoder_Configure](#oh_audioencoder_configure) (OH_AVCodec \*codec, OH_AVFormat \*format) | Configures an audio encoder. Typically, you need to configure the attributes of the audio track that can be encoded. This API must be called prior to **Prepare**. |
| [OH_AudioEncoder_Prepare](#oh_audioencoder_prepare) (OH_AVCodec \*codec) | Prepares internal resources for an audio encoder. This API must be called after **Configure**. |
| [OH_AudioEncoder_Start](#oh_audioencoder_start) (OH_AVCodec \*codec) | Starts an audio encoder. This API can be called only after the encoder is prepared successfully. After being started, the encoder starts to report the [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) event. |
| [OH_AudioEncoder_Stop](#oh_audioencoder_stop) (OH_AVCodec \*codec) | Stops an audio encoder. After the encoder is stopped, you can call **Start** to start it again. |
| [OH_AudioEncoder_Flush](#oh_audioencoder_flush) (OH_AVCodec \*codec) | Clears the input and output data in the internal buffer of an audio encoder. This API invalidates the indexes of all buffers previously reported through the asynchronous callback. Therefore, before calling this API, ensure that the buffers corresponding to the indexes are no longer required. |
| [OH_AudioEncoder_Reset](#oh_audioencoder_reset) (OH_AVCodec \*codec) | Resets an audio encoder. To continue encoding, you must call **Configure** and **Start** to configure and start the encoder again. |
| [OH_AudioEncoder_GetOutputDescription](#oh_audioencoder_getoutputdescription) (OH_AVCodec \*codec) | Obtains the attributes of the output data of an audio encoder. The caller must manually release the **OH_AVFormat** instance in the return value. |
| [OH_AudioEncoder_SetParameter](#oh_audioencoder_setparameter) (OH_AVCodec \*codec, OH_AVFormat \*format) | Sets dynamic parameters for an audio encoder. This API can be called only after the encoder is started. Incorrect parameter settings may cause encoding failure. |
| [OH_AudioEncoder_PushInputData](#oh_audioencoder_pushinputdata) (OH_AVCodec \*codec, uint32_t index, [OH_AVCodecBufferAttr](_o_h___a_v_codec_buffer_attr.md) attr) | Pushes the input buffer filled with data to an audio encoder. The [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) callback reports available input buffers and their indexes. After being pushed to the decoder, a buffer is not accessible until the buffer with the same index is reported again through the [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) callback. |
| [OH_AudioEncoder_FreeOutputData](#oh_audioencoder_freeoutputdata) (OH_AVCodec \*codec, uint32_t index) | Frees an output buffer of an audio encoder. |
## Function Description
### OH_AudioEncoder_Configure()
```
OH_AVErrCode OH_AudioEncoder_Configure (OH_AVCodec * codec, OH_AVFormat * format )
```
**Description**<br>
Configures an audio encoder. Typically, you need to configure the attributes of the audio track that can be encoded. This API must be called prior to **Prepare**.
\@syscap SystemCapability.Multimedia.Media.AudioEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
| format | Indicates the handle to an **OH_AVFormat** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_AudioEncoder_CreateByMime()
```
OH_AVCodec* OH_AudioEncoder_CreateByMime (const char * mime)
```
**Description**<br>
Creates an audio encoder instance based on a Multipurpose Internet Mail Extension (MIME) type. This API is recommended in most cases.
\@syscap SystemCapability.Multimedia.Media.AudioEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| mime | Indicates the pointer to a MIME type. For details, see [OH_AVCODEC_MIMETYPE_AUDIO_AAC](_codec_base.md#oh_avcodec_mimetype_audio_aac). |
**Returns**
Returns the pointer to an **OH_AVCodec** instance.
### OH_AudioEncoder_CreateByName()
```
OH_AVCodec* OH_AudioEncoder_CreateByName (const char * name)
```
**Description**<br>
Creates an audio encoder instance based on an audio encoder name. To use this API, you must know the exact name of the audio encoder.
\@syscap SystemCapability.Multimedia.Media.AudioEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| name | Indicates the pointer to an audio encoder name. |
**Returns**
Returns the pointer to an **OH_AVCodec** instance.
### OH_AudioEncoder_Destroy()
```
OH_AVErrCode OH_AudioEncoder_Destroy (OH_AVCodec * codec)
```
**Description**<br>
Clears the internal resources of an audio encoder and destroys the audio encoder instance.
\@syscap SystemCapability.Multimedia.Media.AudioEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_AudioEncoder_Flush()
```
OH_AVErrCode OH_AudioEncoder_Flush (OH_AVCodec * codec)
```
**Description**<br>
Clears the input and output data in the internal buffer of an audio encoder. This API invalidates the indexes of all buffers previously reported through the asynchronous callback. Therefore, before calling this API, ensure that the buffers corresponding to the indexes are no longer required.
\@syscap SystemCapability.Multimedia.Media.AudioEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_AudioEncoder_FreeOutputData()
```
OH_AVErrCode OH_AudioEncoder_FreeOutputData (OH_AVCodec * codec, uint32_t index )
```
**Description**<br>
Frees an output buffer of an audio encoder.
\@syscap SystemCapability.Multimedia.Media.AudioEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
| index | Indicates the index of an output buffer. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_AudioEncoder_GetOutputDescription()
```
OH_AVFormat* OH_AudioEncoder_GetOutputDescription (OH_AVCodec * codec)
```
**Description**<br>
Obtains the attributes of the output data of an audio encoder. The caller must manually release the **OH_AVFormat** instance in the return value.
\@syscap SystemCapability.Multimedia.Media.AudioEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns the handle to an **OH_AVFormat** instance, which must be manually released.
### OH_AudioEncoder_Prepare()
```
OH_AVErrCode OH_AudioEncoder_Prepare (OH_AVCodec * codec)
```
**Description**<br>
Prepares internal resources for an audio encoder. This API must be called after **Configure**.
\@syscap SystemCapability.Multimedia.Media.AudioEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_AudioEncoder_PushInputData()
```
OH_AVErrCode OH_AudioEncoder_PushInputData (OH_AVCodec * codec, uint32_t index, OH_AVCodecBufferAttr attr )
```
**Description**<br>
Pushes the input buffer filled with data to an audio encoder. The [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) callback reports available input buffers and their indexes. After being pushed to the decoder, a buffer is not accessible until the buffer with the same index is reported again through the [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) callback.
\@syscap SystemCapability.Multimedia.Media.AudioEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
| index | Indicates the index of an input buffer. |
| attr | Indicates the attributes of the data contained in the buffer. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_AudioEncoder_Reset()
```
OH_AVErrCode OH_AudioEncoder_Reset (OH_AVCodec * codec)
```
**Description**<br>
Resets an audio encoder. To continue encoding, you must call **Configure** and **Start** to configure and start the encoder again.
\@syscap SystemCapability.Multimedia.Media.AudioEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_AudioEncoder_SetCallback()
```
OH_AVErrCode OH_AudioEncoder_SetCallback (OH_AVCodec * codec, OH_AVCodecAsyncCallback callback, void * userData )
```
**Description**<br>
Sets an asynchronous callback so that your application can respond to events generated by an audio encoder. This API must be called prior to **Prepare**.
\@syscap SystemCapability.Multimedia.Media.AudioEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
| callback | Indicates a collection of all callback functions. For details, see [OH_AVCodecAsyncCallback](_o_h___a_v_codec_async_callback.md). |
| userData | Indicates the pointer to user-specific data. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_AudioEncoder_SetParameter()
```
OH_AVErrCode OH_AudioEncoder_SetParameter (OH_AVCodec * codec, OH_AVFormat * format )
```
**Description**<br>
Sets dynamic parameters for an audio encoder. This API can be called only after the encoder is started. Incorrect parameter settings may cause encoding failure.
\@syscap SystemCapability.Multimedia.Media.AudioEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
| format | Indicates the handle to an **OH_AVFormat** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_AudioEncoder_Start()
```
OH_AVErrCode OH_AudioEncoder_Start (OH_AVCodec * codec)
```
**Description**<br>
Starts an audio encoder. This API can be called only after the encoder is prepared successfully. After being started, the encoder starts to report the [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) event.
\@syscap SystemCapability.Multimedia.Media.AudioEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
### OH_AudioEncoder_Stop()
```
OH_AVErrCode OH_AudioEncoder_Stop (OH_AVCodec * codec)
```
**Description**<br>
Stops an audio encoder. After the encoder is stopped, you can call **Start** to start it again.
\@syscap SystemCapability.Multimedia.Media.AudioEncoder
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
**Returns**
Returns **AV_ERR_OK** if the operation is successful.
Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.
# CodecBase
## Overview
Provides the common structs, character constants, and enums for running **OH_AVCodec** instances.
\@syscap SystemCapability.Multimedia.Media.CodecBase
**Since:**
9
## Summary
### Files
| Name | Description |
| -------- | -------- |
| [native_avcodec_base.h](native__avcodec__base_8h.md) | Declares the common structs, character constants, and enums for running **OH_AVCodec** instances. <br>File to Include: <multimedia/player_framework/native_avcodec_base.h> |
### Structs
| Name | Description |
| -------- | -------- |
| [OH_AVCodecBufferAttr](_o_h___a_v_codec_buffer_attr.md) | Defines the buffer attributes of an **OH_AVCodec** instance. |
| [OH_AVCodecAsyncCallback](_o_h___a_v_codec_async_callback.md) | Defines a collection of asynchronous callback functions for an **OH_AVCodec** instance. You must register this struct instance for an **OH_AVCodec** instance and process the information reported through these callbacks to ensure the normal running of the instance. |
### Types
| Name | Description |
| -------- | -------- |
| [OH_AVCodecBufferFlags](#oh_avcodecbufferflags) | Enumerates the buffer flags of an **OH_AVCodec** instance. |
| [OH_AVCodecBufferAttr](#oh_avcodecbufferattr) | Defines the buffer attributes of an **OH_AVCodec** instance. |
| [OH_AVCodecOnError](#oh_avcodeconerror)) (OH_AVCodec \*codec, int32_t errorCode, void \*userData) | Defines the function pointer that is called to report error information when an error occurs during the running of an **OH_AVCodec** instance. |
| [OH_AVCodecOnStreamChanged](#oh_avcodeconstreamchanged)) (OH_AVCodec \*codec, OH_AVFormat \*format, void \*userData) | Defines the function pointer that is called to report the attributes of the new stream when the output stream changes. Note that the lifecycle of the pointer to the **OH_AVFormat** instance is valid only when the function pointer is being called. Do not access the pointer to the instance after the function pointer is called. |
| [OH_AVCodecOnNeedInputData](#oh_avcodeconneedinputdata)) (OH_AVCodec \*codec, uint32_t index, OH_AVMemory \*data, void \*userData) | Defines the function pointer that is called, with a new buffer to fill in new input data, when new input data is required during the running of an **OH_AVCodec** instance. |
| [OH_AVCodecOnNewOutputData](#oh_avcodeconnewoutputdata)) (OH_AVCodec \*codec, uint32_t index, OH_AVMemory \*data, [OH_AVCodecBufferAttr](_o_h___a_v_codec_buffer_attr.md) \*attr, void \*userData) | Defines the function pointer that is called, with a buffer containing new output data, when the new output data is generated during the running of an **OH_AVCodec** instance. Note that the lifecycle of the pointer to the **[OH_AVCodecBufferAttr](_o_h___a_v_codec_buffer_attr.md)** instance is valid only when the function pointer is being called. Do not access the pointer to the instance after the function pointer is called. |
| [OH_AVCodecAsyncCallback](#oh_avcodecasynccallback) | Defines a collection of asynchronous callback functions for an **OH_AVCodec** instance. You must register this struct instance for an **OH_AVCodec** instance and process the information reported through these callbacks to ensure the normal running of the instance. |
| [OH_MediaType](#oh_mediatype) | Enumerates the media types. |
| [OH_AVCProfile](#oh_avcprofile) | Enumerates the AVC profiles. |
| [OH_AACProfile](#oh_aacprofile) | Enumerates the AAC profiles. |
### Enums
| Name | Description |
| -------- | -------- |
| [OH_AVCodecBufferFlags](#oh_avcodecbufferflags) {<br/>**AVCODEC_BUFFER_FLAGS_NONE** = 0, AVCODEC_BUFFER_FLAGS_EOS = 1 &lt;&lt; 0, AVCODEC_BUFFER_FLAGS_SYNC_FRAME = 1 &lt;&lt; 1, AVCODEC_BUFFER_FLAGS_INCOMPLETE_FRAME = 1 &lt;&lt; 2,<br/>AVCODEC_BUFFER_FLAGS_CODEC_DATA = 1 &lt;&lt; 3<br/>} | Enumerates the buffer flags of an **OH_AVCodec** instance. |
| [OH_MediaType](#oh_mediatype) { MEDIA_TYPE_AUD = 0, MEDIA_TYPE_VID = 1 } | Enumerates the media types. |
| [OH_AVCProfile](#oh_avcprofile) { **AVC_PROFILE_BASELINE** = 0, **AVC_PROFILE_HIGH** = 4, **AVC_PROFILE_MAIN** = 8 } | Enumerates the AVC profiles. |
| [OH_AACProfile](#oh_aacprofile) { **AAC_PROFILE_LC** = 0 } | Enumerates the AAC profiles. |
### Variables
| Name | Description |
| -------- | -------- |
| [OH_AVCodecBufferAttr::pts](#pts) | Presentation timestamp of the buffer, in microseconds. |
| [OH_AVCodecBufferAttr::size](#size) | Size of the data contained in the buffer, in bytes. |
| [OH_AVCodecBufferAttr::offset](#offset) | Start offset of valid data in the buffer. |
| [OH_AVCodecBufferAttr::flags](#flags) | Buffer flag, which is a combination of multiple [OH_AVCodecBufferFlags](#oh_avcodecbufferflags). |
| [OH_AVCODEC_MIMETYPE_VIDEO_AVC](#oh_avcodec_mimetype_video_avc) | Defines the Multipurpose Internet Mail Extension (MIME) type for Advanced Video Coding (AVC). |
| [OH_AVCODEC_MIMETYPE_AUDIO_AAC](#oh_avcodec_mimetype_audio_aac) | Defines the MIME type for Advanced Audio Coding (AAC). |
| [OH_ED_KEY_TIME_STAMP](#oh_ed_key_time_stamp) | Provides unified character descriptors for the auxiliary data of the surface buffer. |
| [OH_ED_KEY_EOS](#oh_ed_key_eos) | Character descriptor of the end-of-stream in the surface auxiliary data. The value type is bool. |
| [OH_MD_KEY_TRACK_TYPE](#oh_md_key_track_type) | Provides unified character descriptors for the media playback framework. |
| [OH_MD_KEY_CODEC_MIME](#oh_md_key_codec_mime) | Character descriptor of the MIME type. The value type is string. |
| [OH_MD_KEY_DURATION](#oh_md_key_duration) | Character descriptor of duration. The value type is int64_t. |
| [OH_MD_KEY_BITRATE](#oh_md_key_bitrate) | Character descriptor of the bit rate. The value type is uint32_t. |
| [OH_MD_KEY_MAX_INPUT_SIZE](#oh_md_key_max_input_size) | Character descriptor of the maximum input size. The value type is uint32_t. |
| [OH_MD_KEY_WIDTH](#oh_md_key_width) | Character descriptor of the video width. The value type is uint32_t. |
| [OH_MD_KEY_HEIGHT](#oh_md_key_height) | Character descriptor of the video height. The value type is uint32_t. |
| [OH_MD_KEY_PIXEL_FORMAT](#oh_md_key_pixel_format) | Character descriptor of the video pixel format. The value type is int32_t. For details, see [OH_AVPixelFormat](_core.md#oh_avpixelformat). |
| [OH_MD_KEY_AUDIO_SAMPLE_FORMAT](#oh_md_key_audio_sample_format) | Character descriptor of the audio sample format. The value type is uint32_t. |
| [OH_MD_KEY_FRAME_RATE](#oh_md_key_frame_rate) | Character descriptor of the video frame rate. The value type is double. |
| [OH_MD_KEY_VIDEO_ENCODE_BITRATE_MODE](#oh_md_key_video_encode_bitrate_mode) | Character descriptor of the video encoding bit rate mode. The value type is int32_t. For details, see [OH_VideoEncodeBitrateMode](_video_encoder.md#oh_videoencodebitratemode). |
| [OH_MD_KEY_PROFILE](#oh_md_key_profile) | Character descriptor of the audio/video encoding capability. The value type is int32_t. For details, see [OH_AVCProfile](#oh_avcprofile) or [OH_AACProfile](#oh_aacprofile). |
| [OH_MD_KEY_AUD_CHANNEL_COUNT](#oh_md_key_aud_channel_count) | Character descriptor of the number of audio channels. The value type is uint32_t. |
| [OH_MD_KEY_AUD_SAMPLE_RATE](#oh_md_key_aud_sample_rate) | Character descriptor of the audio sampling rate. The value type is uint32_t. |
| [OH_MD_KEY_I_FRAME_INTERVAL](#oh_md_key_i_frame_interval) | Character descriptor of the I-frame interval. The value type is int32_t, and the unit is ms. |
| [OH_MD_KEY_ROTATION](#oh_md_key_rotation) | Character descriptor of the surface rotation angle. The value type is int32_t. The value range is {0, 90, 180, 270}. The default value is 0. |
## Type Description
### OH_AACProfile
```
typedef enum OH_AACProfileOH_AACProfile
```
**Description**<br>
Enumerates the AAC profiles.
\@syscap SystemCapability.Multimedia.Media.CodecBase
### OH_AVCodecAsyncCallback
```
typedef struct OH_AVCodecAsyncCallbackOH_AVCodecAsyncCallback
```
**Description**<br>
Defines a collection of asynchronous callback functions for an **OH_AVCodec** instance. You must register this struct instance for an **OH_AVCodec** instance and process the information reported through these callbacks to ensure the normal running of the instance.
\@syscap SystemCapability.Multimedia.Media.CodecBase
**Parameters**
| Name | Description |
| -------- | -------- |
| onError | Indicates the callback used to report errors occurred during the running of the instance. For details, see [OH_AVCodecOnError](#oh_avcodeconerror). |
| onStreamChanged | Indicates the callback used to report stream information. For details, see [OH_AVCodecOnStreamChanged](#oh_avcodeconstreamchanged). |
| onNeedInputData | Indicates the callback used to report input data needed. For details, see [OH_AVCodecOnNeedInputData](#oh_avcodeconneedinputdata). |
| onNeedInputData | Indicates the callback used to report output data needed. For details, see [OH_AVCodecOnNewOutputData](#oh_avcodeconnewoutputdata). |
### OH_AVCodecBufferAttr
```
typedef struct OH_AVCodecBufferAttrOH_AVCodecBufferAttr
```
**Description**<br>
Defines the buffer attributes of an **OH_AVCodec** instance.
\@syscap SystemCapability.Multimedia.Media.CodecBase
### OH_AVCodecBufferFlags
```
typedef enum OH_AVCodecBufferFlagsOH_AVCodecBufferFlags
```
**Description**<br>
Enumerates the buffer flags of an **OH_AVCodec** instance.
\@syscap SystemCapability.Multimedia.Media.CodecBase
### OH_AVCodecOnError
```
typedef void(* OH_AVCodecOnError) (OH_AVCodec *codec, int32_t errorCode, void *userData)
```
**Description**<br>
Defines the function pointer that is called to report error information when an error occurs during the running of an **OH_AVCodec** instance.
\@syscap SystemCapability.Multimedia.Media.CodecBase
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
| errorCode | Indicates an error code. |
| userData | Indicates the pointer to user-specific data. |
### OH_AVCodecOnNeedInputData
```
typedef void(* OH_AVCodecOnNeedInputData) (OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, void *userData)
```
**Description**<br>
Defines the function pointer that is called, with a new buffer to fill in new input data, when new input data is required during the running of an **OH_AVCodec** instance.
\@syscap SystemCapability.Multimedia.Media.CodecBase
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
| index | Indicates the index of an input buffer. |
| data | Indicates the pointer to the new input data. |
| userData | Indicates the pointer to user-specific data. |
### OH_AVCodecOnNewOutputData
```
typedef void(* OH_AVCodecOnNewOutputData) (OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, OH_AVCodecBufferAttr *attr, void *userData)
```
**Description**<br>
Defines the function pointer that is called, with a buffer containing new output data, when the new output data is generated during the running of an **OH_AVCodec** instance. Note that the lifecycle of the pointer to the **[OH_AVCodecBufferAttr](_o_h___a_v_codec_buffer_attr.md)** instance is valid only when the function pointer is being called. Do not access the pointer to the instance after the function pointer is called.
\@syscap SystemCapability.Multimedia.Media.CodecBase
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
| index | Indicates the index of a new output buffer. |
| data | Indicates the pointer to the new output data. |
| attr | Indicates the pointer to the attributes of the new output buffer. For details, see [OH_AVCodecBufferAttr](_o_h___a_v_codec_buffer_attr.md). |
| userData | Indicates the pointer to user-specific data. |
| userData | specified data |
### OH_AVCodecOnStreamChanged
```
typedef void(* OH_AVCodecOnStreamChanged) (OH_AVCodec *codec, OH_AVFormat *format, void *userData)
```
**Description**<br>
Defines the function pointer that is called to report the attributes of the new stream when the output stream changes. Note that the lifecycle of the pointer to the **OH_AVFormat** instance is valid only when the function pointer is being called. Do not access the pointer to the instance after the function pointer is called.
\@syscap SystemCapability.Multimedia.Media.CodecBase
**Parameters**
| Name | Description |
| -------- | -------- |
| codec | Indicates the pointer to an **OH_AVCodec** instance. |
| format | Indicates the handle to the attributes of the new output stream. |
| userData | Indicates the pointer to user-specific data. |
### OH_AVCProfile
```
typedef enum OH_AVCProfileOH_AVCProfile
```
**Description**<br>
Enumerates the AVC profiles.
\@syscap SystemCapability.Multimedia.Media.CodecBase
### OH_MediaType
```
typedef enum OH_MediaTypeOH_MediaType
```
**Description**<br>
Enumerates the media types.
\@syscap SystemCapability.Multimedia.Media.CodecBase
## Enum Description
### OH_AACProfile
```
enum OH_AACProfile
```
**Description**<br>
Enumerates the AAC profiles.
\@syscap SystemCapability.Multimedia.Media.CodecBase
### OH_AVCodecBufferFlags
```
enum OH_AVCodecBufferFlags
```
**Description**<br>
Enumerates the buffer flags of an **OH_AVCodec** instance.
\@syscap SystemCapability.Multimedia.Media.CodecBase
| Name | Description |
| -------- | -------- |
| AVCODEC_BUFFER_FLAGS_EOS | The buffer contains an end-of-stream frame. |
| AVCODEC_BUFFER_FLAGS_SYNC_FRAME | The buffer contains a sync frame. |
| AVCODEC_BUFFER_FLAGS_INCOMPLETE_FRAME | The buffer contains part of a frame. |
| AVCODEC_BUFFER_FLAGS_CODEC_DATA | The buffer contains codec-specific data. |
### OH_AVCProfile
```
enum OH_AVCProfile
```
**Description**<br>
Enumerates the AVC profiles.
\@syscap SystemCapability.Multimedia.Media.CodecBase
### OH_MediaType
```
enum OH_MediaType
```
**Description**<br>
Enumerates the media types.
\@syscap SystemCapability.Multimedia.Media.CodecBase
| Name | Description |
| -------- | -------- |
| MEDIA_TYPE_AUD | Audio track. |
| MEDIA_TYPE_VID | Video track. |
## Variable Description
### flags
```
uint32_t OH_AVCodecBufferAttr::flags
```
**Description**<br>
Buffer flag, which is a combination of multiple [OH_AVCodecBufferFlags](#oh_avcodecbufferflags).
### offset
```
int32_t OH_AVCodecBufferAttr::offset
```
**Description**<br>
Start offset of valid data in the buffer.
### OH_AVCODEC_MIMETYPE_AUDIO_AAC
```
const char* OH_AVCODEC_MIMETYPE_AUDIO_AAC
```
**Description**<br>
Defines the MIME type for Advanced Audio Coding (AAC).
\@syscap SystemCapability.Multimedia.Media.CodecBase
### OH_AVCODEC_MIMETYPE_VIDEO_AVC
```
const char* OH_AVCODEC_MIMETYPE_VIDEO_AVC
```
**Description**<br>
Defines the Multipurpose Internet Mail Extension (MIME) type for Advanced Video Coding (AVC).
\@syscap SystemCapability.Multimedia.Media.CodecBase
### OH_ED_KEY_EOS
```
const char* OH_ED_KEY_EOS
```
**Description**<br>
Character descriptor of the end-of-stream in the surface auxiliary data. The value type is bool.
### OH_ED_KEY_TIME_STAMP
```
const char* OH_ED_KEY_TIME_STAMP
```
**Description**<br>
Provides unified character descriptors for the auxiliary data of the surface buffer.
\@syscap SystemCapability.Multimedia.Media.CodecBase
### OH_MD_KEY_AUD_CHANNEL_COUNT
```
const char* OH_MD_KEY_AUD_CHANNEL_COUNT
```
**Description**<br>
Character descriptor of the number of audio channels. The value type is uint32_t.
### OH_MD_KEY_AUD_SAMPLE_RATE
```
const char* OH_MD_KEY_AUD_SAMPLE_RATE
```
**Description**<br>
Character descriptor of the audio sampling rate. The value type is uint32_t.
### OH_MD_KEY_AUDIO_SAMPLE_FORMAT
```
const char* OH_MD_KEY_AUDIO_SAMPLE_FORMAT
```
**Description**<br>
Character descriptor of the audio sample format. The value type is uint32_t.
### OH_MD_KEY_BITRATE
```
const char* OH_MD_KEY_BITRATE
```
**Description**<br>
Character descriptor of the bit rate. The value type is uint32_t.
### OH_MD_KEY_CODEC_MIME
```
const char* OH_MD_KEY_CODEC_MIME
```
**Description**<br>
Character descriptor of the MIME type. The value type is string.
### OH_MD_KEY_DURATION
```
const char* OH_MD_KEY_DURATION
```
**Description**<br>
Character descriptor of duration. The value type is int64_t.
### OH_MD_KEY_FRAME_RATE
```
const char* OH_MD_KEY_FRAME_RATE
```
**Description**<br>
Character descriptor of the video frame rate. The value type is double.
### OH_MD_KEY_HEIGHT
```
const char* OH_MD_KEY_HEIGHT
```
**Description**<br>
Character descriptor of the video height. The value type is uint32_t.
### OH_MD_KEY_I_FRAME_INTERVAL
```
const char* OH_MD_KEY_I_FRAME_INTERVAL
```
**Description**<br>
Character descriptor of the I-frame interval. The value type is int32_t, and the unit is ms.
### OH_MD_KEY_MAX_INPUT_SIZE
```
const char* OH_MD_KEY_MAX_INPUT_SIZE
```
**Description**<br>
Character descriptor of the maximum input size. The value type is uint32_t.
### OH_MD_KEY_PIXEL_FORMAT
```
const char* OH_MD_KEY_PIXEL_FORMAT
```
**Description**<br>
Character descriptor of the video pixel format. The value type is int32_t. For details, see [OH_AVPixelFormat](_core.md#oh_avpixelformat).
### OH_MD_KEY_PROFILE
```
const char* OH_MD_KEY_PROFILE
```
**Description**<br>
Character descriptor of the audio/video encoding capability. The value type is int32_t. For details, see [OH_AVCProfile](#oh_avcprofile) or [OH_AACProfile](#oh_aacprofile).
### OH_MD_KEY_ROTATION
```
const char* OH_MD_KEY_ROTATION
```
**Description**<br>
Character descriptor of the surface rotation angle. The value type is int32_t. The value range is {0, 90, 180, 270}. The default value is 0.
### OH_MD_KEY_TRACK_TYPE
```
const char* OH_MD_KEY_TRACK_TYPE
```
**Description**<br>
Provides unified character descriptors for the media playback framework.
\@syscap SystemCapability.Multimedia.Media.CodecBase
### OH_MD_KEY_VIDEO_ENCODE_BITRATE_MODE
```
const char* OH_MD_KEY_VIDEO_ENCODE_BITRATE_MODE
```
**Description**<br>
Character descriptor of the video encoding bit rate mode. The value type is int32_t. For details, see [OH_VideoEncodeBitrateMode](_video_encoder.md#oh_videoencodebitratemode).
### OH_MD_KEY_WIDTH
```
const char* OH_MD_KEY_WIDTH
```
**Description**<br>
Character descriptor of the video width. The value type is uint32_t.
### pts
```
int64_t OH_AVCodecBufferAttr::pts
```
**Description**<br>
Presentation timestamp of the buffer, in microseconds.
### size
```
int32_t OH_AVCodecBufferAttr::size
```
**Description**<br>
Size of the data contained in the buffer, in bytes.
# Core
## Overview
Provides the basic backbone capabilities for the media playback framework, including functions related to the memory, error code, and format carrier.
\@syscap SystemCapability.Multimedia.Media.Core
**Since:**
9
## Summary
### Files
| Name | Description |
| -------- | -------- |
| [native_averrors.h](native__averrors_8h.md) | Declares the error codes used by the media playback framework. <br>File to Include: <multimedia/player_framework/native_averrors.h> |
| [native_avformat.h](native__avformat_8h.md) | Declares the format-related functions and enums. <br>File to Include: <multimedia/player_framework/native_avformat.h> |
| [native_avmemory.h](native__avmemory_8h.md) | Declares the memory-related functions. <br>File to Include: <multimedia/player_framework/native_avmemory.h> |
### Types
| Name | Description |
| -------- | -------- |
| [OH_AVErrCode](#oh_averrcode) | Enumerates the audio and video error codes. |
| [OH_AVPixelFormat](#oh_avpixelformat) | Enumerates the audio and video pixel formats. |
### Enums
| Name | Description |
| -------- | -------- |
| [OH_AVErrCode](#oh_averrcode) {<br/>AV_ERR_OK = 0, AV_ERR_NO_MEMORY = 1, AV_ERR_OPERATE_NOT_PERMIT = 2, AV_ERR_INVALID_VAL = 3,<br/>AV_ERR_IO = 4, AV_ERR_TIMEOUT = 5, AV_ERR_UNKNOWN = 6, AV_ERR_SERVICE_DIED = 7,<br/>AV_ERR_INVALID_STATE = 8, AV_ERR_UNSUPPORT = 9, AV_ERR_EXTEND_START = 100<br/>} | Enumerates the audio and video error codes. |
| [OH_AVPixelFormat](#oh_avpixelformat) {<br/>AV_PIXEL_FORMAT_YUVI420 = 1, AV_PIXEL_FORMAT_NV12 = 2, AV_PIXEL_FORMAT_NV21 = 3, AV_PIXEL_FORMAT_SURFACE_FORMAT = 4,<br/>AV_PIXEL_FORMAT_RGBA = 5<br/>} | Enumerates the audio and video pixel formats. |
### Functions
| Name | Description |
| -------- | -------- |
| [OH_AVFormat_Create](#oh_avformat_create) (void) | Creates an **OH_AVFormat** instance for reading and writing data. |
| [OH_AVFormat_Destroy](#oh_avformat_destroy) (struct OH_AVFormat \*format) | Destroys an **OH_AVFormat** instance. |
| [OH_AVFormat_Copy](#oh_avformat_copy) (struct OH_AVFormat \*to, struct OH_AVFormat \*from) | Copies the resources from an **OH_AVFormat** instance to another. |
| [OH_AVFormat_SetIntValue](#oh_avformat_setintvalue) (struct OH_AVFormat \*format, const char \*key, int32_t value) | Writes data of the int type to an **OH_AVFormat** instance. |
| [OH_AVFormat_SetLongValue](#oh_avformat_setlongvalue) (struct OH_AVFormat \*format, const char \*key, int64_t value) | Writes data of the long type to an **OH_AVFormat** instance. |
| [OH_AVFormat_SetFloatValue](#oh_avformat_setfloatvalue) (struct OH_AVFormat \*format, const char \*key, float value) | Writes data of the float type to an **OH_AVFormat** instance. |
| [OH_AVFormat_SetDoubleValue](#oh_avformat_setdoublevalue) (struct OH_AVFormat \*format, const char \*key, double value) | Writes data of the double type to an **OH_AVFormat** instance. |
| [OH_AVFormat_SetStringValue](#oh_avformat_setstringvalue) (struct OH_AVFormat \*format, const char \*key, const char \*value) | Writes data of the string type to an **OH_AVFormat** instance. |
| [OH_AVFormat_SetBuffer](#oh_avformat_setbuffer) (struct OH_AVFormat \*format, const char \*key, const uint8_t \*addr, size_t size) | Writes data with a specified size to an **OH_AVFormat** instance. |
| [OH_AVFormat_GetIntValue](#oh_avformat_getintvalue) (struct OH_AVFormat \*format, const char \*key, int32_t \*out) | Reads data of the int type from an **OH_AVFormat** instance. |
| [OH_AVFormat_GetLongValue](#oh_avformat_getlongvalue) (struct OH_AVFormat \*format, const char \*key, int64_t \*out) | Reads data of the long type from an **OH_AVFormat** instance. |
| [OH_AVFormat_GetFloatValue](#oh_avformat_getfloatvalue) (struct OH_AVFormat \*format, const char \*key, float \*out) | Reads data of the float type from an **OH_AVFormat** instance. |
| [OH_AVFormat_GetDoubleValue](#oh_avformat_getdoublevalue) (struct OH_AVFormat \*format, const char \*key, double \*out) | Reads data of the double type from an **OH_AVFormat** instance. |
| [OH_AVFormat_GetStringValue](#oh_avformat_getstringvalue) (struct OH_AVFormat \*format, const char \*key, const char \*\*out) | Reads data of the double type from an **OH_AVFormat** instance. |
| [OH_AVFormat_GetBuffer](#oh_avformat_getbuffer) (struct OH_AVFormat \*format, const char \*key, uint8_t \*\*addr, size_t \*size) | Reads data with a specified size from an **OH_AVFormat** instance. |
| [OH_AVFormat_DumpInfo](#oh_avformat_dumpinfo) (struct OH_AVFormat \*format) | Dumps the information contained in an**OH_AVFormat** instance as a string. |
| [OH_AVMemory_GetAddr](#oh_avmemory_getaddr) (struct OH_AVMemory \*mem) | Obtains the virtual memory address of an **OH_AVMemory** instance. |
| [OH_AVMemory_GetSize](#oh_avmemory_getsize) (struct OH_AVMemory \*mem) | Obtains the memory size of an **OH_AVMemory** instance. |
## Type Description
### OH_AVErrCode
```
typedef enum OH_AVErrCodeOH_AVErrCode
```
**Description**<br>
Enumerates the audio and video error codes.
\@syscap SystemCapability.Multimedia.Media.Core
### OH_AVPixelFormat
```
typedef enum OH_AVPixelFormatOH_AVPixelFormat
```
**Description**<br>
Enumerates the audio and video pixel formats.
\@syscap SystemCapability.Multimedia.Media.Core
## Enum Description
### OH_AVErrCode
```
enum OH_AVErrCode
```
**Description**<br>
Enumerates the audio and video error codes.
\@syscap SystemCapability.Multimedia.Media.Core
| Name | Description |
| -------- | -------- |
| AV_ERR_OK | Operation successful. |
| AV_ERR_NO_MEMORY | No memory. |
| AV_ERR_OPERATE_NOT_PERMIT | Invalid parameter. |
| AV_ERR_INVALID_VAL | Invalid value. |
| AV_ERR_IO | I/O error. |
| AV_ERR_TIMEOUT | Timeout. |
| AV_ERR_UNKNOWN | Unknown error. |
| AV_ERR_SERVICE_DIED | Unavailable media service. |
| AV_ERR_INVALID_STATE | Unsupported operation in this state. |
| AV_ERR_UNSUPPORT | Unsupported API. |
| AV_ERR_EXTEND_START | Initial value for extended error codes. |
### OH_AVPixelFormat
```
enum OH_AVPixelFormat
```
**Description**<br>
Enumerates the audio and video pixel formats.
\@syscap SystemCapability.Multimedia.Media.Core
| Name | Description |
| -------- | -------- |
| AV_PIXEL_FORMAT_YUVI420 | YUV 420 Planar. |
| AV_PIXEL_FORMAT_NV12 | NV12. YUV 420 Semi-planar. |
| AV_PIXEL_FORMAT_NV21 | NV21. YVU 420 Semi-planar. |
| AV_PIXEL_FORMAT_SURFACE_FORMAT | Surface. |
| AV_PIXEL_FORMAT_RGBA | RGBA8888. |
## Function Description
### OH_AVFormat_Copy()
```
bool OH_AVFormat_Copy (struct OH_AVFormat * to, struct OH_AVFormat * from )
```
**Description**<br>
Copies the resources from an **OH_AVFormat** instance to another.
\@syscap SystemCapability.Multimedia.Media.Core
**Parameters**
| Name | Description |
| -------- | -------- |
| to | Indicates the handle to the **OH_AVFormat** instance to which the data will be copied. |
| from | Indicates the handle to the **OH_AVFormat** instance from which the data will be copied. |
**Returns**
Returns **TRUE** if the operation is successful.
Returns **FALSE** if the operation fails.
### OH_AVFormat_Create()
```
struct OH_AVFormat* OH_AVFormat_Create (void )
```
**Description**<br>
Creates an **OH_AVFormat** instance for reading and writing data.
\@syscap SystemCapability.Multimedia.Media.Core
**Returns**
Returns the handle to an **OH_AVFormat** instance.
### OH_AVFormat_Destroy()
```
void OH_AVFormat_Destroy (struct OH_AVFormat * format)
```
**Description**<br>
Destroys an **OH_AVFormat** instance.
\@syscap SystemCapability.Multimedia.Media.Core
**Parameters**
| Name | Description |
| -------- | -------- |
| format | Indicates the handle to an **OH_AVFormat** instance. |
**Returns**
void
### OH_AVFormat_DumpInfo()
```
const char* OH_AVFormat_DumpInfo (struct OH_AVFormat * format)
```
**Description**<br>
Dumps the information contained in an**OH_AVFormat** instance as a string.
\@syscap SystemCapability.Multimedia.Media.Core
**Parameters**
| Name | Description |
| -------- | -------- |
| format | Indicates the handle to an **OH_AVFormat** instance. |
**Returns**
Returns the pointer to a collect of strings, each of which consists of a key and value.
### OH_AVFormat_GetBuffer()
```
bool OH_AVFormat_GetBuffer (struct OH_AVFormat * format, const char * key, uint8_t ** addr, size_t * size )
```
**Description**<br>
Reads data with a specified size from an **OH_AVFormat** instance.
\@syscap SystemCapability.Multimedia.Media.Core
**Parameters**
| Name | Description |
| -------- | -------- |
| format | Indicates the handle to an **OH_AVFormat** instance. |
| key | Indicates the pointer to the key of the data to read. |
| addr | Indicates the double pointer to the address where the data read is stored. The data read is destroyed when the **OH_AVFormat** instance is destroyed. To hold the data for an extended period of time, copy it to the memory. |
| size | Indicates the pointer to the size of the data read. |
**Returns**
Returns **TRUE** if the operation is successful.
Returns **FALSE** if the operation fails.
### OH_AVFormat_GetDoubleValue()
```
bool OH_AVFormat_GetDoubleValue (struct OH_AVFormat * format, const char * key, double * out )
```
**Description**<br>
Reads data of the double type from an **OH_AVFormat** instance.
\@syscap SystemCapability.Multimedia.Media.Core
**Parameters**
| Name | Description |
| -------- | -------- |
| format | Indicates the handle to an **OH_AVFormat** instance. |
| key | Indicates the pointer to the key of the data to read. |
| out | Indicates the pointer to the data read. |
**Returns**
Returns **TRUE** if the operation is successful.
Returns **FALSE** if the operation fails.
### OH_AVFormat_GetFloatValue()
```
bool OH_AVFormat_GetFloatValue (struct OH_AVFormat * format, const char * key, float * out )
```
**Description**<br>
Reads data of the float type from an **OH_AVFormat** instance.
\@syscap SystemCapability.Multimedia.Media.Core
**Parameters**
| Name | Description |
| -------- | -------- |
| format | Indicates the handle to an **OH_AVFormat** instance. |
| key | Indicates the pointer to the key of the data to read. |
| out | Indicates the pointer to the data read. |
**Returns**
Returns **TRUE** if the operation is successful.
Returns **FALSE** if the operation fails.
### OH_AVFormat_GetIntValue()
```
bool OH_AVFormat_GetIntValue (struct OH_AVFormat * format, const char * key, int32_t * out )
```
**Description**<br>
Reads data of the int type from an **OH_AVFormat** instance.
\@syscap SystemCapability.Multimedia.Media.Core
**Parameters**
| Name | Description |
| -------- | -------- |
| format | Indicates the handle to an **OH_AVFormat** instance. |
| key | Indicates the pointer to the key of the data to read. |
| out | Indicates the pointer to the data read. |
**Returns**
Returns **TRUE** if the operation is successful.
Returns **FALSE** if the operation fails.
### OH_AVFormat_GetLongValue()
```
bool OH_AVFormat_GetLongValue (struct OH_AVFormat * format, const char * key, int64_t * out )
```
**Description**<br>
Reads data of the long type from an **OH_AVFormat** instance.
\@syscap SystemCapability.Multimedia.Media.Core
**Parameters**
| Name | Description |
| -------- | -------- |
| format | Indicates the handle to an **OH_AVFormat** instance. |
| key | Indicates the pointer to the key of the data to read. |
| out | Indicates the pointer to the data read. |
**Returns**
Returns **TRUE** if the operation is successful.
Returns **FALSE** if the operation fails.
### OH_AVFormat_GetStringValue()
```
bool OH_AVFormat_GetStringValue (struct OH_AVFormat * format, const char * key, const char ** out )
```
**Description**<br>
Reads data of the double type from an **OH_AVFormat** instance.
\@syscap SystemCapability.Multimedia.Media.Core
**Parameters**
| Name | Description |
| -------- | -------- |
| format | Indicates the handle to an **OH_AVFormat** instance. |
| key | Indicates the pointer to the key of the data to read. |
| out | Indicates the double pointer to the data read. The data read is updated when **GetString** is called and destroyed when the **OH_AVFormat** instance is destroyed. To hold the data for an extended period of time, copy it to the memory. |
**Returns**
Returns **TRUE** if the operation is successful.
Returns **FALSE** if the operation fails.
### OH_AVFormat_SetBuffer()
```
bool OH_AVFormat_SetBuffer (struct OH_AVFormat * format, const char * key, const uint8_t * addr, size_t size )
```
**Description**<br>
Writes data with a specified size to an **OH_AVFormat** instance.
\@syscap SystemCapability.Multimedia.Media.Core
**Parameters**
| Name | Description |
| -------- | -------- |
| format | Indicates the handle to an **OH_AVFormat** instance. |
| key | Indicates the pointer to the key of the data to write. |
| addr | Indicates the pointer to the address where the data is written. |
| size | Indicates the size of the data written. |
**Returns**
Returns **TRUE** if the operation is successful.
Returns **FALSE** if the operation fails.
### OH_AVFormat_SetDoubleValue()
```
bool OH_AVFormat_SetDoubleValue (struct OH_AVFormat * format, const char * key, double value )
```
**Description**<br>
Writes data of the double type to an **OH_AVFormat** instance.
\@syscap SystemCapability.Multimedia.Media.Core
**Parameters**
| Name | Description |
| -------- | -------- |
| format | Indicates the handle to an **OH_AVFormat** instance. |
| key | Indicates the pointer to the key of the data to write. |
| value | Indicates the value of the data to write. |
**Returns**
Returns **TRUE** if the operation is successful.
Returns **FALSE** if the operation fails.
### OH_AVFormat_SetFloatValue()
```
bool OH_AVFormat_SetFloatValue (struct OH_AVFormat * format, const char * key, float value )
```
**Description**<br>
Writes data of the float type to an **OH_AVFormat** instance.
\@syscap SystemCapability.Multimedia.Media.Core
**Parameters**
| Name | Description |
| -------- | -------- |
| format | Indicates the handle to an **OH_AVFormat** instance. |
| key | Indicates the pointer to the key of the data to write. |
| value | Indicates the value of the data to write. |
**Returns**
Returns **TRUE** if the operation is successful.
Returns **FALSE** if the operation fails.
### OH_AVFormat_SetIntValue()
```
bool OH_AVFormat_SetIntValue (struct OH_AVFormat * format, const char * key, int32_t value )
```
**Description**<br>
Writes data of the int type to an **OH_AVFormat** instance.
\@syscap SystemCapability.Multimedia.Media.Core
**Parameters**
| Name | Description |
| -------- | -------- |
| format | Indicates the handle to an **OH_AVFormat** instance. |
| key | Indicates the pointer to the key of the data to write. |
| value | Indicates the value of the data to write. |
**Returns**
Returns **TRUE** if the operation is successful.
Returns **FALSE** if the operation fails.
### OH_AVFormat_SetLongValue()
```
bool OH_AVFormat_SetLongValue (struct OH_AVFormat * format, const char * key, int64_t value )
```
**Description**<br>
Writes data of the long type to an **OH_AVFormat** instance.
\@syscap SystemCapability.Multimedia.Media.Core
**Parameters**
| Name | Description |
| -------- | -------- |
| format | Indicates the handle to an **OH_AVFormat** instance. |
| key | Indicates the pointer to the key of the data to write. |
| value | Indicates the value of the data to write. |
**Returns**
Returns **TRUE** if the operation is successful.
Returns **FALSE** if the operation fails.
### OH_AVFormat_SetStringValue()
```
bool OH_AVFormat_SetStringValue (struct OH_AVFormat * format, const char * key, const char * value )
```
**Description**<br>
Writes data of the string type to an **OH_AVFormat** instance.
\@syscap SystemCapability.Multimedia.Media.Core
**Parameters**
| Name | Description |
| -------- | -------- |
| format | Indicates the handle to an **OH_AVFormat** instance. |
| key | Indicates the pointer to the key of the data to write. |
| value | Indicates the pointer to the value of the data to write. |
**Returns**
Returns **TRUE** if the operation is successful.
Returns **FALSE** if the operation fails.
### OH_AVMemory_GetAddr()
```
uint8_t* OH_AVMemory_GetAddr (struct OH_AVMemory * mem)
```
**Description**<br>
Obtains the virtual memory address of an **OH_AVMemory** instance.
\@syscap SystemCapability.Multimedia.Media.Core
**Parameters**
| Name | Description |
| -------- | -------- |
| mem | Indicates the pointer to an **OH_AVMemory** instance. |
**Returns**
Returns the virtual address if the memory is valid.
Returns a null pointer if the memory is invalid.
### OH_AVMemory_GetSize()
```
int32_t OH_AVMemory_GetSize (struct OH_AVMemory * mem)
```
**Description**<br>
Obtains the memory size of an **OH_AVMemory** instance.
\@syscap SystemCapability.Multimedia.Media.Core
**Parameters**
| Name | Description |
| -------- | -------- |
| mem | Indicates the pointer to an **OH_AVMemory** instance. |
**Returns**
Returns the size if the memory is valid.
Returns **-1** if the memory is invalid.
此差异已折叠。
# HiLog
## Overview
Provides logging functions.
For example, you can use logging functions to output logs of the specified log type, service domain, log tag, and log level.
\@syscap SystemCapability.HiviewDFX.HiLog
**Since:**
8
## Summary
### Files
| Name | Description |
| -------- | -------- |
| [log.h](log_8h.md) | Defines the logging functions of the HiLog module.<br>File to Include: <hilog/log.h> |
### Macros
| Name | Description |
| -------- | -------- |
| [LOG_DOMAIN](#log_domain) 0 | Defines the service domain for a log file. |
| [LOG_TAG](#log_tag) NULL | Defines a string constant used to identify the class, file, or service. |
| [OH_LOG_DEBUG](#oh_log_debug)(type, ...) ((void)[OH_LOG_Print](#oh_log_print)((type), LOG_DEBUG, [LOG_DOMAIN](#log_domain), [LOG_TAG](#log_tag), __VA_ARGS__)) | Outputs DEBUG logs. This is a function-like macro. |
| [OH_LOG_INFO](#oh_log_info)(type, ...) ((void)[OH_LOG_Print](#oh_log_print)((type), LOG_INFO, [LOG_DOMAIN](#log_domain), [LOG_TAG](#log_tag), __VA_ARGS__)) | Outputs INFO logs. This is a function-like macro. |
| [OH_LOG_WARN](#oh_log_warn)(type, ...) ((void)[OH_LOG_Print](#oh_log_print)((type), LOG_WARN, [LOG_DOMAIN](#log_domain), [LOG_TAG](#log_tag), __VA_ARGS__)) | Outputs WARN logs. This is a function-like macro. |
| [OH_LOG_ERROR](#oh_log_error)(type, ...) ((void)[OH_LOG_Print](#oh_log_print)((type), LOG_ERROR, [LOG_DOMAIN](#log_domain), [LOG_TAG](#log_tag), __VA_ARGS__)) | Outputs ERROR logs. This is a function-like macro. |
| [OH_LOG_FATAL](#oh_log_fatal)(type, ...) ((void)HiLogPrint((type), LOG_FATAL, [LOG_DOMAIN](#log_domain), [LOG_TAG](#log_tag), __VA_ARGS__)) | Outputs FATAL logs. This is a function-like macro. |
### Enums
| Name | Description |
| -------- | -------- |
| [LogType](#logtype) { LOG_APP = 0 } | Enumerates log types. |
| [LogLevel](#loglevel) {<br/>LOG_DEBUG = 3, LOG_INFO = 4, LOG_WARN = 5, LOG_ERROR = 6,<br/>LOG_FATAL = 7<br/>} | Enumerates log levels. |
### Functions
| Name | Description |
| -------- | -------- |
| [OH_LOG_Print](#oh_log_print) ([LogType](#logtype) type, [LogLevel](#loglevel) level, unsigned int domain, const char *tag, const char *fmt,...) \_\_attribute\_\_((\_\_format\_\_(os_log, 5,6))) |Outputs logs. |
| [OH_LOG_IsLoggable](#oh_log_isloggable) (unsigned int domain, const char \*tag, [LogLevel](#loglevel) level) | Checks whether logs of the specified service domain, log tag, and log level can be output. |
## Macro Description
### LOG_DOMAIN
```
#define LOG_DOMAIN 0
```
**Description**<br>
Defines the service domain for a log file.
The service domain is used to identify the subsystem and module of a service. Its value is a hexadecimal integer ranging from 0x0 to 0xFFFF. If the value is beyond the range, its significant bits are automatically truncated.
### LOG_TAG
```
#define LOG_TAG NULL
```
**Description**<br>
Defines a string constant used to identify the class, file, or service.
### OH_LOG_DEBUG
```
#define OH_LOG_DEBUG( type, ... ) ((void)OH_LOG_Print((type), LOG_DEBUG, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
```
**Description**<br>
Outputs DEBUG logs. This is a function-like macro.
Before calling this function, define the log service domain and log tag. Generally, you need to define them at the beginning of the source file.
**Parameters**
| Name | Description |
| -------- | -------- |
| type | Indicates the log type. The type for third-party applications is defined by LOG_APP. |
| fmt | Indicates the format string, which is an enhancement of a printf format string and supports the privacy identifier. Specifically, **{public}** or **{private}** is added between the % character and the format specifier in each parameter. |
| ... | Indicates the parameter list corresponding to the parameter type in the format string. The number and type of parameters must be mapped onto the identifier in the format string. |
**See**
[OH_LOG_Print](#oh_log_print)
### OH_LOG_ERROR
```
#define OH_LOG_ERROR( type, ... ) ((void)OH_LOG_Print((type), LOG_ERROR, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
```
**Description**<br>
Outputs ERROR logs. This is a function-like macro.
Before calling this function, define the log service domain and log tag. Generally, you need to define them at the beginning of the source file.
**Parameters**
| Name | Description |
| -------- | -------- |
| type | Indicates the log type. The type for third-party applications is defined by LOG_APP. |
| fmt | Indicates the format string, which is an enhancement of a printf format string and supports the privacy identifier. Specifically, **{public}** or **{private}** is added between the % character and the format specifier in each parameter. |
| ... | Indicates the parameter list corresponding to the parameter type in the format string. The number and type of parameters must be mapped onto the identifier in the format string. |
**See**
[OH_LOG_Print](#oh_log_print)
### OH_LOG_FATAL
```
#define OH_LOG_FATAL( type, ... ) ((void)HiLogPrint((type), LOG_FATAL, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
```
**Description**<br>
Outputs FATAL logs. This is a function-like macro.
Before calling this function, define the log service domain and log tag. Generally, you need to define them at the beginning of the source file.
**Parameters**
| Name | Description |
| -------- | -------- |
| type | Indicates the log type. The type for third-party applications is defined by LOG_APP. |
| fmt | Indicates the format string, which is an enhancement of a printf format string and supports the privacy identifier. Specifically, **{public}** or **{private}** is added between the % character and the format specifier in each parameter. |
| ... | Indicates the parameter list corresponding to the parameter type in the format string. The number and type of parameters must be mapped onto the identifier in the format string. |
**See**
[OH_LOG_Print](#oh_log_print)
### OH_LOG_INFO
```
#define OH_LOG_INFO( type, ... ) ((void)OH_LOG_Print((type), LOG_INFO, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
```
**Description**<br>
Outputs INFO logs. This is a function-like macro.
Before calling this function, define the log service domain and log tag. Generally, you need to define them at the beginning of the source file.
**Parameters**
| Name | Description |
| -------- | -------- |
| type | Indicates the log type. The type for third-party applications is defined by LOG_APP. |
| fmt | Indicates the format string, which is an enhancement of a printf format string and supports the privacy identifier. Specifically, **{public}** or **{private}** is added between the % character and the format specifier in each parameter. |
| ... | Indicates the parameter list corresponding to the parameter type in the format string. The number and type of parameters must be mapped onto the identifier in the format string. |
**See**
[OH_LOG_Print](#oh_log_print)
### OH_LOG_WARN
```
#define OH_LOG_WARN( type, ... ) ((void)OH_LOG_Print((type), LOG_WARN, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
```
**Description**<br>
Outputs WARN logs. This is a function-like macro.
Before calling this function, define the log service domain and log tag. Generally, you need to define them at the beginning of the source file.
**Parameters**
| Name | Description |
| -------- | -------- |
| type | Indicates the log type. The type for third-party applications is defined by LOG_APP. |
| fmt | Indicates the format string, which is an enhancement of a printf format string and supports the privacy identifier. Specifically, **{public}** or **{private}** is added between the % character and the format specifier in each parameter. |
| ... | Indicates the parameter list corresponding to the parameter type in the format string. The number and type of parameters must be mapped onto the identifier in the format string. |
**See**
[OH_LOG_Print](#oh_log_print)
## Enum Description
### LogLevel
```
enum LogLevel
```
**Description**<br>
Enumerates log levels.
You are advised to select log levels based on their respective use cases:
DEBUG: provides more detailed process information than INFO logs to help developers analyze service processes and locate faults. DEBUG logs are not recorded in official versions by default. They are available in debug versions or in official versions with the debug function enabled.
INFO: indicates the key service process nodes and exceptions (for example, no network signal or login failure) that occur during service running. These logs should be recorded by the dominant module in the service to avoid repeated logging conducted by multiple invoked modules or low-level functions.
WARN: indicates a severe, unexpected fault that has little impact on users and can be rectified by the programs themselves or through simple operations.
ERROR: indicates a program or functional error that affects the normal running or use of the functionality and can be fixed at a high cost, for example, by resetting data.
FATAL: indicates that a program or functionality is about to crash and the fault cannot be rectified.
| Name | Description |
| -------- | -------- |
| LOG_DEBUG | DEBUG level to be used by OH_LOG_DEBUG |
| LOG_INFO | INFO level to be used by OH_LOG_INFO |
| LOG_WARN | WARN level to be used by OH_LOG_WARN |
| LOG_ERROR | ERROR level to be used by OH_LOG_ERROR |
| LOG_FATAL | FATAL level to be used by OH_LOG_FATAL |
### LogType
```
enum LogType
```
**Description**<br>
Enumerates log types.
Currently, only LOG_APP is available.
| Name | Description |
| -------- | -------- |
| LOG_APP | Application log |
## Function Description
### OH_LOG_IsLoggable()
```
int bool OH_LOG_IsLoggable (unsigned int domain, const char * tag, LogLevel level )
```
**Description**<br>
Checks whether logs of the specified service domain, log tag, and log level can be output.
**Parameters**
| Name | Description |
| -------- | -------- |
| domain | Indicates the service domain of logs. |
| tag | Indicates the log tag. |
| level | Indicates the log level. |
**Returns**
Returns **true** if the specified logs can be output; returns **false** otherwise.
### OH_LOG_Print()
```
int OH_LOG_Print (LogType type, LogLevel level, unsigned int domain, const char * tag, const char * fmt, ... )
```
**Description**<br>
Outputs logs.
You can use this function to output logs based on the specified log type, log level, service domain, log tag, and variable parameters determined by the format specifier and privacy identifier in the printf format.
**Parameters**
| Name | Description |
| -------- | -------- |
| type | Indicates the log type. The type for third-party applications is defined by LOG_APP. |
| level | Indicates the log level, which can be **LOG_DEBUG**, **LOG_INFO**, **LOG_WARN**, **LOG_ERROR**, and **LOG_FATAL**. |
| domain | Indicates the service domain. Its value is a hexadecimal integer ranging from 0x0 to 0xFFFF. |
| tag | Indicates the log tag, which is a string used to identify the class, file, or service. |
| fmt | Indicates the format string, which is an enhancement of a printf format string and supports the privacy identifier. Specifically, **{public}** or **{private}** is added between the % character and the format specifier in each parameter. |
| ... | Indicates the parameter list corresponding to the parameter type in the format string. The number and type of parameters must be mapped onto the identifier in the format string. |
**Returns**
Returns **0** or a larger value if the operation is successful; returns a value smaller than **0** otherwise.
# HuksKeyApi
## Overview
Describes the OpenHarmony Universal KeyStore (HUKS) capabilities, including key management and cryptography operations, provided for applications. The keys managed by HUKS can be imported by applications or generated by calling the HUKS APIs.
\@syscap SystemCapability.Security.Huks
**Since:**
9
## Summary
### Files
| Name | Description |
| -------- | -------- |
| [native_huks_api.h](native__huks__api_8h.md) | Declares the APIs used to access the HUKS. <br>File to Include: <huks/native_huks/api.h> |
### Functions
| Name | Description |
| -------- | -------- |
| [OH_Huks_GetSdkVersion](#oh_huks_getsdkversion) (struct [OH_Huks_Blob](_o_h___huks___blob.md) \*sdkVersion) | Obtains the current HUKS SDK version. |
| [OH_Huks_GenerateKeyItem](#oh_huks_generatekeyitem) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*keyAlias, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSetIn, struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSetOut) | Generates a key. |
| [OH_Huks_ImportKeyItem](#oh_huks_importkeyitem) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*keyAlias, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet, const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*key) | Imports a key in plaintext. |
| [OH_Huks_ImportWrappedKeyItem](#oh_huks_importwrappedkeyitem) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*keyAlias, const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*wrappingKeyAlias, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet, const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*wrappedKeyData) | Imports a wrapped key. |
| [OH_Huks_ExportPublicKeyItem](#oh_huks_exportpublickeyitem) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*keyAlias, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet, struct [OH_Huks_Blob](_o_h___huks___blob.md) \*key) | Exports a public key. |
| [OH_Huks_DeleteKeyItem](#oh_huks_deletekeyitem) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*keyAlias, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet) | Deletes a key. |
| [OH_Huks_GetKeyItemParamSet](#oh_huks_getkeyitemparamset) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*keyAlias, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSetIn, struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSetOut) | Obtains the attributes of a key. |
| [OH_Huks_IsKeyItemExist](#oh_huks_iskeyitemexist) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*keyAlias, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet) | Checks whether a key exists. |
| [OH_Huks_AttestKeyItem](#oh_huks_attestkeyitem) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*keyAlias, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet, struct [OH_Huks_CertChain](_o_h___huks___cert_chain.md) \*certChain) | Obtain the key certificate chain. |
| [OH_Huks_InitSession](#oh_huks_initsession) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*keyAlias, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet, struct [OH_Huks_Blob](_o_h___huks___blob.md) \*handle, struct [OH_Huks_Blob](_o_h___huks___blob.md) \*challenge) | Initializes the key session interface and obtains a handle (mandatory) and challenge value (optional). |
| [OH_Huks_UpdateSession](#oh_huks_updatesession) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*handle, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet, const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*inData, struct [OH_Huks_Blob](_o_h___huks___blob.md) \*outData) | Adds data by segment for the key operation, performs the related key operation, and outputs the processed data. |
| [OH_Huks_FinishSession](#oh_huks_finishsession) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*handle, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet, const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*inData, struct [OH_Huks_Blob](_o_h___huks___blob.md) \*outData) | Ends the key session. |
| [OH_Huks_AbortSession](#oh_huks_abortsession) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*handle, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet) | Aborts a key session. |
## Function Description
### OH_Huks_AbortSession()
```
struct OH_Huks_Result OH_Huks_AbortSession (const struct OH_Huks_Blob * handle, const struct OH_Huks_ParamSet * paramSet )
```
**Description**<br>
Aborts a key session.
**Parameters**
| Name | Description |
| -------- | -------- |
| handle | Indicates the pointer to the key session handle, which is generated by [OH_Huks_InitSession](#oh_huks_initsession). |
| paramSet | Indicates the pointer to the parameters required for aborting the key session. By default, this parameter is a null pointer. |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the operation is successful; returns an error code otherwise.
**See**
[OH_Huks_InitSession](#oh_huks_initsession)
[OH_Huks_UpdateSession](#oh_huks_updatesession)
[OH_Huks_FinishSession](#oh_huks_finishsession)
### OH_Huks_AttestKeyItem()
```
struct OH_Huks_Result OH_Huks_AttestKeyItem (const struct OH_Huks_Blob * keyAlias, const struct OH_Huks_ParamSet * paramSet, struct OH_Huks_CertChain * certChain )
```
**Description**<br>
Obtain the key certificate chain.
**Parameters**
| Name | Description |
| -------- | -------- |
| keyAlias | Indicates the pointer to the alias of the target key. |
| paramSet | Indicates the pointer to the parameters required for obtaining the key certificate. |
| certChain | Indicates the pointer to the key certificate chain obtained. |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the operation is successful; returns an error code otherwise.
### OH_Huks_DeleteKeyItem()
```
struct OH_Huks_Result OH_Huks_DeleteKeyItem (const struct OH_Huks_Blob * keyAlias, const struct OH_Huks_ParamSet * paramSet )
```
**Description**<br>
Deletes a key.
**Parameters**
| Name | Description |
| -------- | -------- |
| keyAlias | Indicates the pointer to the alias of the key to delete. The alias must be the same as the alias for the key generated. |
| paramSet | Indicates the pointer to the parameters required for deleting the key. By default, this parameter is a null pointer. |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the operation is successful; returns an error code otherwise.
### OH_Huks_ExportPublicKeyItem()
```
struct OH_Huks_Result OH_Huks_ExportPublicKeyItem (const struct OH_Huks_Blob * keyAlias, const struct OH_Huks_ParamSet * paramSet, struct OH_Huks_Blob * key )
```
**Description**<br>
Exports a public key.
**Parameters**
| Name | Description |
| -------- | -------- |
| keyAlias | Indicates the pointer to the alias of the public key to export. The alias must be the same as the alias for the key generated. |
| paramSet | Indicates the pointer to the parameters required for exporting the public key. |
| key | Indicates the pointer to the public key exported. |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the operation is successful; returns an error code otherwise.
### OH_Huks_FinishSession()
```
struct OH_Huks_Result OH_Huks_FinishSession (const struct OH_Huks_Blob * handle, const struct OH_Huks_ParamSet * paramSet, const struct OH_Huks_Blob * inData, struct OH_Huks_Blob * outData )
```
**Description**<br>
Ends the key session.
**Parameters**
| Name | Description |
| -------- | -------- |
| handle | Indicates the pointer to the key session handle, which is generated by [OH_Huks_InitSession](#oh_huks_initsession). |
| paramSet | Indicates the pointer to the parameters required for the key operation. |
| inData | Indicates the pointer to the data to be processed. |
| outData | Indicates the pointer to the output data. |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the operation is successful; returns an error code otherwise.
**See**
[OH_Huks_InitSession](#oh_huks_initsession)
[OH_Huks_UpdateSession](#oh_huks_updatesession)
[OH_Huks_AbortSession](#oh_huks_abortsession)
### OH_Huks_GenerateKeyItem()
```
struct OH_Huks_Result OH_Huks_GenerateKeyItem (const struct OH_Huks_Blob * keyAlias, const struct OH_Huks_ParamSet * paramSetIn, struct OH_Huks_ParamSet * paramSetOut )
```
**Description**<br>
Generates a key.
**Parameters**
| Name | Description |
| -------- | -------- |
| keyAlias | Indicates the pointer to the alias of the key to generate. The alias must be unique in the process of the service. Otherwise, the key will be overwritten. |
| paramSetIn | Indicates the pointer to the parameter set for generating the key. |
| paramSetOut | Indicates the pointer to a temporary key generated. If the generated key is not of a temporary type, this parameter is a null pointer. |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the operation is successful; returns an error code otherwise.
### OH_Huks_GetKeyItemParamSet()
```
struct OH_Huks_Result OH_Huks_GetKeyItemParamSet (const struct OH_Huks_Blob * keyAlias, const struct OH_Huks_ParamSet * paramSetIn, struct OH_Huks_ParamSet * paramSetOut )
```
**Description**<br>
Obtains the attributes of a key.
**Parameters**
| Name | Description |
| -------- | -------- |
| keyAlias | Indicates the pointer to the alias of the target key. |
| paramSetIn | Indicates the pointer to the attribute tag required for obtaining the attributes. By default, this parameter is a null pointer. |
| paramSetOut | Indicates the pointer to the attributes obtained. |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the operation is successful; returns an error code otherwise.
### OH_Huks_GetSdkVersion()
```
struct OH_Huks_Result OH_Huks_GetSdkVersion (struct OH_Huks_Blob * sdkVersion)
```
**Description**<br>
Obtains the current HUKS SDK version.
**Parameters**
| Name | Description |
| -------- | -------- |
| sdkVersion | Indicates the pointer to the SDK version (in string format) obtained. |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the operation is successful; returns an error code otherwise.
### OH_Huks_ImportKeyItem()
```
struct OH_Huks_Result OH_Huks_ImportKeyItem (const struct OH_Huks_Blob * keyAlias, const struct OH_Huks_ParamSet * paramSet, const struct OH_Huks_Blob * key )
```
**Description**<br>
Imports a key in plaintext.
**Parameters**
| Name | Description |
| -------- | -------- |
| keyAlias | Indicates the pointer to the alias of the key to import. The alias must be unique in the process of the service. Otherwise, the key will be overwritten. |
| paramSet | Indicates the pointer to the parameters of the key to import. |
| key | Indicates the pointer to the key to import. The key must be in the format required by the HUKS. For details, see [HuksTypeApi](_huks_type_api.md). |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the operation is successful; returns an error code otherwise.
### OH_Huks_ImportWrappedKeyItem()
```
struct OH_Huks_Result OH_Huks_ImportWrappedKeyItem (const struct OH_Huks_Blob * keyAlias, const struct OH_Huks_Blob * wrappingKeyAlias, const struct OH_Huks_ParamSet * paramSet, const struct OH_Huks_Blob * wrappedKeyData )
```
**Description**<br>
Imports a wrapped key.
**Parameters**
| Name | Description |
| -------- | -------- |
| keyAlias | Indicates the pointer to the alias of the key to import. The alias must be unique in the process of the service. Otherwise, the key will be overwritten. |
| wrappingKeyAlias | Indicates the pointer to the alias of the wrapping key, which is obtained through key agreement and used to decrypt the key to import. |
| paramSet | Indicates the pointer to the parameters of the wrapped key to import. |
| wrappedKeyData | Indicates the pointer to the wrapped key to import. The key must be in the format required by the HUKS. For details, see [OH_Huks_AlgSuite](_huks_type_api.md#oh_huks_algsuite). |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the operation is successful; returns an error code otherwise.
### OH_Huks_InitSession()
```
struct OH_Huks_Result OH_Huks_InitSession (const struct OH_Huks_Blob * keyAlias, const struct OH_Huks_ParamSet * paramSet, struct OH_Huks_Blob * handle, struct OH_Huks_Blob * challenge )
```
**Description**<br>
Initializes the key session interface and obtains a handle (mandatory) and challenge value (optional).
**Parameters**
| Name | Description |
| -------- | -------- |
| keyAlias | Indicates the pointer to the alias of the target key. |
| paramSet | Indicates the pointer to the parameters for the initialization operation. |
| handle | Indicates the pointer to the handle of the key session obtained. This handle is required for subsequent operations, including [OH_Huks_UpdateSession](#oh_huks_updatesession), [OH_Huks_FinishSession](#oh_huks_finishsession), and [OH_Huks_AbortSession](#oh_huks_abortsession). |
| challenge | Indicates the pointer to the challenge value obtained. |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the operation is successful; returns an error code otherwise.
**See**
[OH_Huks_UpdateSession](#oh_huks_updatesession)
[OH_Huks_FinishSession](#oh_huks_finishsession)
[OH_Huks_AbortSession](#oh_huks_abortsession)
### OH_Huks_IsKeyItemExist()
```
struct OH_Huks_Result OH_Huks_IsKeyItemExist (const struct OH_Huks_Blob * keyAlias, const struct OH_Huks_ParamSet * paramSet )
```
**Description**<br>
Checks whether a key exists.
**Parameters**
| Name | Description |
| -------- | -------- |
| keyAlias | Indicates the pointer to the alias of the target key. |
| paramSet | Indicates the pointer to the attribute tag required for checking the key. By default, this parameter is a null pointer. |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the key exists.
Returns [OH_Huks_ErrCode#OH_HUKS_ERR_CODE_ITEM_NOT_EXIST](_huks_type_api.md) if the key does not exist.
Returns any other error code for other cases.
### OH_Huks_UpdateSession()
```
struct OH_Huks_Result OH_Huks_UpdateSession (const struct OH_Huks_Blob * handle, const struct OH_Huks_ParamSet * paramSet, const struct OH_Huks_Blob * inData, struct OH_Huks_Blob * outData )
```
**Description**<br>
Adds data by segment for the key operation, performs the related key operation, and outputs the processed data.
**Parameters**
| Name | Description |
| -------- | -------- |
| handle | Indicates the pointer to the key session handle, which is generated by [OH_Huks_InitSession](#oh_huks_initsession). |
| paramSet | Indicates the pointer to the parameters required for the key operation. |
| inData | Indicates the pointer to the data to be processed. This API can be called multiples time to process large data by segment. |
| outData | Indicates the pointer to the output data. |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the operation is successful; returns an error code otherwise.
**See**
[OH_Huks_InitSession](#oh_huks_initsession)
[OH_Huks_FinishSession](#oh_huks_finishsession)
[OH_Huks_AbortSession](#oh_huks_abortsession)
# HuksParamSetApi
## Overview
Defines the capabilities of OpenHarmony Universal KeyStore (HUKS) parameter sets. The HUKS APIs can be used to perform parameter set lifecycle management, including initializing a parameter set, adding parameters to a parameter set, constructing a parameter set, and destroying a parameter set. They can also be used to obtain parameters, copy parameter sets, and check parameter validity.
\@syscap SystemCapability.Security.Huks
**Since:**
9
## Summary
### Files
| Name | Description |
| -------- | -------- |
| [native_huks_param.h](native__huks__param_8h.md) | Provides APIs for constructing, using, and destroying parameter sets. <br>File to Include: <huks/native_huks/native_huks_param.h> |
### Functions
| Name | Description |
| -------- | -------- |
| [OH_Huks_InitParamSet](#oh_huks_initparamset) (struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*\*paramSet) | Initializes a parameter set. |
| [OH_Huks_AddParams](#oh_huks_addparams) (struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet, const struct [OH_Huks_Param](_o_h___huks___param.md) \*params, uint32_t paramCnt) | Adds parameters to a parameter set. |
| [OH_Huks_BuildParamSet](#oh_huks_buildparamset) (struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*\*paramSet) | Constructs a parameter set. |
| [OH_Huks_FreeParamSet](#oh_huks_freeparamset) (struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*\*paramSet) | Destroys a parameter set. |
| [OH_Huks_CopyParamSet](#oh_huks_copyparamset) (const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*fromParamSet, uint32_t fromParamSetSize, struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*\*paramSet) | Copies a parameter set (deep copy). |
| [OH_Huks_GetParam](#oh_huks_getparam) (const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet, uint32_t tag, struct [OH_Huks_Param](_o_h___huks___param.md) \*\*param) | Obtains parameters from a parameter set. |
| [OH_Huks_FreshParamSet](#oh_huks_freshparamset) (struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet, bool isCopy) | Refreshes data of the **Blob** type in a parameter set. |
| [OH_Huks_isParamSetTagValid](#oh_huks_isparamsettagvalid) (const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet) | Checks whether the parameters in a parameter set are valid. |
| [OH_Huks_isParamSetValid](#oh_huks_isparamsetvalid) (const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet, uint32_t size) | Checks whether a parameter set is of the valid size. |
| [OH_Huks_CheckParamMatch](#oh_huks_checkparammatch) (const struct [OH_Huks_Param](_o_h___huks___param.md) \*baseParam, const struct [OH_Huks_Param](_o_h___huks___param.md) \*param) | Checks whether two parameters are the same. |
## Function Description
### OH_Huks_AddParams()
```
int32_t OH_Huks_AddParams (struct OH_Huks_ParamSet * paramSet, const struct OH_Huks_Param * params, uint32_t paramCnt )
```
**Description**<br>
Adds parameters to a parameter set.
**Parameters**
| Name | Description |
| -------- | -------- |
| paramSet | Indicates the pointer to the parameter set to which parameters are to be added. |
| params | Indicates the pointer to the array of parameters to add. |
| paramCnt | Indicates the number of parameters to add. |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the operation is successful; returns an error code otherwise.
### OH_Huks_BuildParamSet()
```
int32_t OH_Huks_BuildParamSet (struct OH_Huks_ParamSet ** paramSet)
```
**Description**<br>
Constructs a parameter set.
**Parameters**
| Name | Description |
| -------- | -------- |
| paramSet | Indicates the double pointer to the parameter set to construct. |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the operation is successful; returns an error code otherwise.
### OH_Huks_CheckParamMatch()
```
int32_t OH_Huks_CheckParamMatch (const struct OH_Huks_Param * baseParam, const struct OH_Huks_Param * param )
```
**Description**<br>
Checks whether two parameters are the same.
**Parameters**
| Name | Description |
| -------- | -------- |
| baseParam | Indicates the pointer to the first parameter. |
| param | Indicates the pointer to the second parameter. |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the two parameters are the same; returns an error code otherwise.
### OH_Huks_CopyParamSet()
```
int32_t OH_Huks_CopyParamSet (const struct OH_Huks_ParamSet * fromParamSet, uint32_t fromParamSetSize, struct OH_Huks_ParamSet ** paramSet )
```
**Description**<br>
Copies a parameter set (deep copy).
**Parameters**
| Name | Description |
| -------- | -------- |
| fromParamSet | Indicates the pointer to the parameter set to copy. |
| fromParamSetSize | Indicates the memory size occupied by the source parameter set. |
| paramSet | Indicates the double pointer to the new parameter set generated. |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the operation is successful; returns an error code otherwise.
### OH_Huks_FreeParamSet()
```
void OH_Huks_FreeParamSet (struct OH_Huks_ParamSet ** paramSet)
```
**Description**<br>
Destroys a parameter set.
**Parameters**
| Name | Description |
| -------- | -------- |
| paramSet | Indicates the double pointer to the parameter set to destroy. |
### OH_Huks_FreshParamSet()
```
int32_t OH_Huks_FreshParamSet (struct OH_Huks_ParamSet * paramSet, bool isCopy )
```
**Description**<br>
Refreshes data of the **Blob** type in a parameter set.
**Parameters**
| Name | Description |
| -------- | -------- |
| paramSet | Indicates the pointer to the target parameter set. |
| isCopy | Specifies whether to copy the data of the **Blob** type to the parameter set. If yes, the data of the **Blob** type will be copied to the parameter set. Otherwise, only the address of the **Blob** data will be refreshed. |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if operation is successful; returns an error code otherwise.
### OH_Huks_GetParam()
```
int32_t OH_Huks_GetParam (const struct OH_Huks_ParamSet * paramSet, uint32_t tag, struct OH_Huks_Param ** param )
```
**Description**<br>
Obtains parameters from a parameter set.
**Parameters**
| Name | Description |
| -------- | -------- |
| paramSet | Indicates the pointer to the target parameter set. |
| tag | Indicates the value of the parameter to be obtained. |
| param | Indicates the double pointer to the parameter obtained. |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the operation is successful, returns an error code otherwise.
### OH_Huks_InitParamSet()
```
int32_t OH_Huks_InitParamSet (struct OH_Huks_ParamSet ** paramSet)
```
**Description**<br>
Initializes a parameter set.
**Parameters**
| Name | Description |
| -------- | -------- |
| paramSet | Indicates the double pointer to the parameter set to initialize. |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the initialization is successful; returns an error code otherwise.
### OH_Huks_isParamSetTagValid()
```
int32_t OH_Huks_isParamSetTagValid (const struct OH_Huks_ParamSet * paramSet)
```
**Description**<br>
Checks whether the parameters in a parameter set are valid.
**Parameters**
| Name | Description |
| -------- | -------- |
| paramSet | Indicates the pointer to the parameter set to check. |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the parameters in the parameter set are valid; returns other values if the parameter set has invalid, duplicate, or incorrect parameters.
### OH_Huks_isParamSetValid()
```
int32_t OH_Huks_isParamSetValid (const struct OH_Huks_ParamSet * paramSet, uint32_t size )
```
**Description**<br>
Checks whether a parameter set is of the valid size.
**Parameters**
| Name | Description |
| -------- | -------- |
| paramSet | Indicates the pointer to the parameter set to check. |
| size | Indicates the memory size occupied by the parameter set. |
**Returns**
Returns [OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md) if the parameter set is of the valid size; returns an error code otherwise.
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册