1# AudioCodec 2 3<!--Kit: AVCodec Kit--> 4<!--Subsystem: Multimedia--> 5<!--Owner: @mr-chencxy--> 6<!--Designer: @dpy2650---> 7<!--Tester: @baotianhao--> 8<!--Adviser: @zengyawen--> 9 10## Overview 11 12The AudioCodec module provides the functions for audio encoding and decoding. 13 14You can refer to the corresponding development guide and samples based on your development requirements. 15 16- [Audio Encoding](../../media/avcodec/audio-encoding.md) 17- [Audio Decoding](../../media/avcodec/audio-decoding.md) 18 19**System capability**: SystemCapability.Multimedia.Media.AudioCodec 20 21**Since**: 11 22 23 24## Summary 25 26 27### Files 28 29| Name| Description| 30| -------- | -------- | 31| [native_avcodec_audiocodec.h](native__avcodec__audiocodec_8h.md) | Declares the native APIs used for audio encoding and decoding.| 32 33 34### Functions 35 36| Name| Description| 37| -------- | -------- | 38| [OH_AVCodec](_codec_base.md#oh_avcodec) \* [OH_AudioCodec_CreateByMime](#oh_audiocodec_createbymime) (const char \*mime, bool isEncoder) | Creates an audio codec instance based on a [MIME](_codec_base.md#media-codec-formats) type.| 39| [OH_AVCodec](_codec_base.md#oh_avcodec) \* [OH_AudioCodec_CreateByName](#oh_audiocodec_createbyname) (const char \*name) | Creates an audio codec instance based on a codec name. | 40| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AudioCodec_Destroy](#oh_audiocodec_destroy) ([OH_AVCodec](_codec_base.md#oh_avcodec) \*codec) | Clears the internal resources of an audio codec and destroys the codec instance.| 41| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AudioCodec_RegisterCallback](#oh_audiocodec_registercallback) ([OH_AVCodec](_codec_base.md#oh_avcodec) \*codec, [OH_AVCodecCallback](_o_h___a_v_codec_callback.md) callback, void \*userData) | Sets an asynchronous callback so that your application can respond to events generated by an audio codec. This function must be called prior to **Prepare**. | 42| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AudioCodec_Configure](#oh_audiocodec_configure) ([OH_AVCodec](_codec_base.md#oh_avcodec) \*codec, const [OH_AVFormat](_core.md#oh_avformat) \*format) | Configures the audio description. The audio codec is usually configured based on the audio description.| 43| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AudioCodec_Prepare](#oh_audiocodec_prepare) ([OH_AVCodec](_codec_base.md#oh_avcodec) \*codec) | Prepares internal resources for an audio codec.| 44| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AudioCodec_Start](#oh_audiocodec_start) ([OH_AVCodec](_codec_base.md#oh_avcodec) \*codec) | Starts an audio codec after it is prepared successfully.| 45| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AudioCodec_Stop](#oh_audiocodec_stop) ([OH_AVCodec](_codec_base.md#oh_avcodec) \*codec) | Stops an audio codec.| 46| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AudioCodec_Flush](#oh_audiocodec_flush) ([OH_AVCodec](_codec_base.md#oh_avcodec) \*codec) | Clears the input and output data in the internal buffer of an audio codec.| 47| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AudioCodec_Reset](#oh_audiocodec_reset) ([OH_AVCodec](_codec_base.md#oh_avcodec) \*codec) | Resets an audio codec. The configured parameters and input and output data are cleared.<br>To continue encoding or decoding, you must call **Configure** to configure the codec again. | 48| [OH_AVFormat](_core.md#oh_avformat) \* [OH_AudioCodec_GetOutputDescription](#oh_audiocodec_getoutputdescription) ([OH_AVCodec](_codec_base.md#oh_avcodec) \*codec) | Obtains the description information about the output data of an audio codec. | 49| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AudioCodec_SetParameter](#oh_audiocodec_setparameter) ([OH_AVCodec](_codec_base.md#oh_avcodec) \*codec, const [OH_AVFormat](_core.md#oh_avformat) \*format) | Sets dynamic parameters for an audio codec. | 50| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AudioCodec_PushInputBuffer](#oh_audiocodec_pushinputbuffer) ([OH_AVCodec](_codec_base.md#oh_avcodec) \*codec, uint32_t index) | Notifies the audio codec that the input data has been written to the buffer identified by **index**. | 51| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AudioCodec_FreeOutputBuffer](#oh_audiocodec_freeoutputbuffer) ([OH_AVCodec](_codec_base.md#oh_avcodec) \*codec, uint32_t index) | Frees an output buffer of an audio codec. | 52| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AudioCodec_IsValid](#oh_audiocodec_isvalid) ([OH_AVCodec](_codec_base.md#oh_avcodec) \*codec, bool \*isValid) | Checks whether an audio codec instance is valid.<br>This function is used to detect the codec status when a background fault is rectified or an application is switched from the background. | 53| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AudioCodec_SetDecryptionConfig](#oh_audiocodec_setdecryptionconfig) ([OH_AVCodec](_codec_base.md#oh_avcodec) \*codec, MediaKeySession \*mediaKeySession, bool secureAudio) | Sets the decryption information. | 54| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AudioCodec_QueryInputBuffer](#oh_audiocodec_queryinputbuffer) ([OH_AVCodec](_codec_base.md#oh_avcodec) \*codec, uint32_t *index, int64_t timeoutUs) | Obtains the available input buffer of an audio codec. This function returns the result synchronously.| 55| [OH_AVBuffer](_core.md#oh_avbuffer) *[OH_AudioCodec_GetInputBuffer](#oh_audiocodec_getinputbuffer) ([OH_AVCodec](_codec_base.md#oh_avcodec) \*codec, uint32_t index) | Obtains the input buffer identified by **index** of an audio codec.| 56| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AudioCodec_QueryOutputBuffer](#oh_audiocodec_queryoutputbuffer) ([OH_AVCodec](_codec_base.md#oh_avcodec) \*codec, uint32_t *index, int64_t timeoutUs) | Obtains the available output buffer of an audio codec. This function returns the result synchronously.| 57| [OH_AVBuffer](_core.md#oh_avbuffer) *[OH_AudioCodec_GetOutputBuffer](#oh_audiocodec_getoutputbuffer) ([OH_AVCodec](_codec_base.md#oh_avcodec) \*codec, uint32_t index) | Obtains the output buffer identified by **index** of an audio codec.| 58 59## Function Description 60 61### OH_AudioCodec_Configure() 62 63``` 64OH_AVErrCode OH_AudioCodec_Configure (OH_AVCodec *codec, const OH_AVFormat *format) 65``` 66 67**Description** 68 69Configures the audio description. The audio codec is usually configured based on the audio description. This function must be called prior to **Prepare**. 70 71**System capability**: SystemCapability.Multimedia.Media.AudioCodec 72 73**Since**: 11 74 75**Parameters** 76 77| Name| Description| 78| -------- | -------- | 79| codec | Pointer to an OH_AVCodec instance.| 80| format | Pointer to an OH_AVFormat instance, which provides the description information about the audio track to be encoded or decoded.| 81 82**Returns** 83 84**AV_ERR_OK** if the operation is successful; an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 85 86 87### OH_AudioCodec_CreateByMime() 88 89``` 90OH_AVCodec* OH_AudioCodec_CreateByMime (const char *mime, bool isEncoder) 91``` 92 93**Description** 94 95Creates an audio codec instance based on a MIME type. This function is recommended in most cases. 96 97**System capability**: SystemCapability.Multimedia.Media.AudioCodec 98 99**Since**: 11 100 101**Parameters** 102 103| Name| Description| 104| -------- | -------- | 105| mime | Pointer to a string that describes the MIME type. For details, see [AVCODEC_MIMETYPE](_codec_base.md#variables).| 106| isEncoder | The value **true** means to create an encoder, and **false** means to create a decoder.| 107 108**Returns** 109 110Pointer to an OH_AVCodec instance. 111 112 113### OH_AudioCodec_CreateByName() 114 115``` 116OH_AVCodec* OH_AudioCodec_CreateByName (const char *name) 117``` 118 119**Description** 120 121Creates an audio codec instance based on a codec name. 122 123To use this function, you must know the exact name of the codec, which can be obtained by calling [the corresponding API](_a_v_capability.md#oh_avcapability_getname). 124 125**System capability**: SystemCapability.Multimedia.Media.AudioCodec 126 127**Since**: 11 128 129**Parameters** 130 131| Name| Description| 132| -------- | -------- | 133| name | Pointer to an audio codec name.| 134 135**Returns** 136 137Pointer to an OH_AVCodec instance. 138 139 140### OH_AudioCodec_Destroy() 141 142``` 143OH_AVErrCode OH_AudioCodec_Destroy (OH_AVCodec *codec) 144``` 145 146**Description** 147 148Clears the internal resources of an audio codec and destroys the codec instance. 149 150Do not repeatedly destroy the instance. Otherwise, the program may crash. 151 152**System capability**: SystemCapability.Multimedia.Media.AudioCodec 153 154**Since**: 11 155 156**Parameters** 157 158| Name| Description| 159| -------- | -------- | 160| codec | Pointer to an OH_AVCodec instance. | 161 162**Returns** 163 164**AV_ERR_OK** if the operation is successful; an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 165 166 167### OH_AudioCodec_Flush() 168 169``` 170OH_AVErrCode OH_AudioCodec_Flush (OH_AVCodec *codec) 171``` 172 173**Description** 174 175Clears the input and output data in the internal buffer of an audio codec. 176 177This function invalidates the indexes of all buffers previously reported through the asynchronous callback. Therefore, before calling this function, ensure that the buffers with the specified indexes are no longer required. 178 179**System capability**: SystemCapability.Multimedia.Media.AudioCodec 180 181**Since**: 11 182 183**Parameters** 184 185| Name| Description| 186| -------- | -------- | 187| codec | Pointer to an OH_AVCodec instance.| 188 189**Returns** 190 191**AV_ERR_OK** if the operation is successful; an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 192 193 194### OH_AudioCodec_FreeOutputBuffer() 195 196``` 197OH_AVErrCode OH_AudioCodec_FreeOutputBuffer (OH_AVCodec *codec, uint32_t index) 198``` 199 200**Description** 201 202Frees an output buffer of an audio codec. 203 204You need to call this function to release the output buffer in a timely manner. Otherwise, the encoding or decoding process is blocked. 205 206**System capability**: SystemCapability.Multimedia.Media.AudioCodec 207 208**Since**: 11 209 210**Parameters** 211 212| Name| Description| 213| -------- | -------- | 214| codec | Pointer to an OH_AVCodec instance.| 215| index | Index of the [OH_AVCodecOnNewOutputBuffer](_codec_base.md#oh_avcodeconnewoutputbuffer).| 216 217**Returns** 218 219**AV_ERR_OK** if the operation is successful; an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 220 221 222### OH_AudioCodec_GetInputBuffer() 223 224``` 225OH_AVBuffer *OH_AudioCodec_GetInputBuffer(OH_AVCodec *codec, uint32_t index) 226``` 227 228**Description** 229 230Obtains the input buffer identified by **index** for an audio codec, and fills it with new data. 231 232After the buffer is filled, call [OH_AudioCodec_PushInputBuffer](#oh_audiocodec_pushinputbuffer) with the same index to push the buffer to the codec. 233 234After the buffer is pushed to the codec, you can no longer access the input buffer for that index. 235 236**System capability**: SystemCapability.Multimedia.Media.AudioCodec 237 238**Since**: 20 239 240**Parameters** 241 242| Name| Description| 243| -------- | -------- | 244| codec | Pointer to an OH_AVCodec instance.| 245| index | Index of the input buffer. It is obtained by calling [OH_AudioCodec_QueryInputBuffer](#oh_audiocodec_queryinputbuffer).| 246 247**Returns** 248 249Pointer to the OH_AVBuffer instance created. If the operation fails, NULL is returned. 250 251 252### OH_AudioCodec_GetOutputBuffer() 253 254``` 255OH_AVBuffer *OH_AudioCodec_GetOutputBuffer(OH_AVCodec *codec, uint32_t index) 256``` 257 258**Description** 259 260Obtains the output buffer identified by **index** for an audio codec. 261 262After using the buffer, call [OH_AudioCodec_FreeOutputBuffer](#oh_audiocodec_freeoutputbuffer) to release the buffer. Once released, the buffer cannot be reused. Prolonged failure to release buffers will block the codec process. 263 264**System capability**: SystemCapability.Multimedia.Media.AudioCodec 265 266**Since**: 20 267 268**Parameters** 269 270| Name| Description| 271| -------- | -------- | 272| codec | Pointer to an OH_AVCodec instance.| 273| index | Index of the output buffer. It is obtained by calling [OH_AudioCodec_QueryOutputBuffer](#oh_audiocodec_queryoutputbuffer).| 274 275**Returns** 276 277Pointer to the OH_AVBuffer instance created. If the operation fails, NULL is returned. 278 279 280### OH_AudioCodec_GetOutputDescription() 281 282``` 283OH_AVFormat* OH_AudioCodec_GetOutputDescription (OH_AVCodec *codec) 284``` 285 286**Description** 287 288Obtains the **OH_AVFormat** information about the output data of an audio codec. 289 290 291You must call [OH_AVFormat_Destroy](_core.md#oh_avformat_destroy) to manually release the OH_AVFormat instance in the return value. 292 293**System capability**: SystemCapability.Multimedia.Media.AudioCodec 294 295**Since**: 11 296 297**Parameters** 298 299| Name| Description| 300| -------- | -------- | 301| codec | Pointer to an OH_AVCodec instance.| 302 303**Returns** 304 305Handle to an OH_AVFormat instance. The lifecycle of this instance is refreshed when **GetOutputDescription** is called again and destroyed when the OH_AVCodec instance is destroyed. 306 307 308### OH_AudioCodec_IsValid() 309 310``` 311OH_AVErrCode OH_AudioCodec_IsValid (OH_AVCodec *codec, bool *isValid) 312``` 313 314**Description** 315 316Checks whether an audio codec instance is valid.<br>This function is used to detect the codec status when a background fault is rectified or an application is switched from the background. 317 318**System capability**: SystemCapability.Multimedia.Media.AudioCodec 319 320**Since**: 11 321 322**Parameters** 323 324| Name| Description| 325| -------- | -------- | 326| codec | Pointer to an OH_AVCodec instance.| 327| isValid | Pointer to an instance of the Boolean type. The value **true** means that the codec instance is valid, and **false** means the opposite.| 328 329**Returns** 330 331**AV_ERR_OK** if the operation is successful; an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 332 333 334### OH_AudioCodec_Prepare() 335 336``` 337OH_AVErrCode OH_AudioCodec_Prepare (OH_AVCodec *codec) 338``` 339 340**Description** 341 342Prepares internal resources for an audio codec. This function must be called after **Configure**. 343 344**System capability**: SystemCapability.Multimedia.Media.AudioCodec 345 346**Since**: 11 347 348**Parameters** 349 350| Name| Description| 351| -------- | -------- | 352| codec | Pointer to an OH_AVCodec instance.| 353 354**Returns** 355 356**AV_ERR_OK** if the operation is successful; an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 357 358 359### OH_AudioCodec_PushInputBuffer() 360 361``` 362OH_AVErrCode OH_AudioCodec_PushInputBuffer (OH_AVCodec *codec, uint32_t index) 363``` 364 365**Description** 366 367Notifies the audio codec that the input data has been written to the buffer identified by **index**. 368 369The [OH_AVCodecOnNeedInputBuffer](_codec_base.md#oh_avcodeconneedinputbuffer) callback reports the available input buffer and the index. After being pushed to the codec, a buffer is not accessible until the buffer with the same index is reported again through the [OH_AVCodecOnNeedInputBuffer](_codec_base.md#oh_avcodeconneedinputbuffer) callback. 370 371In addition, some codecs require the input of codec-specific data to initialize the encoding or decoding process. 372 373> **NOTE** 374> 375> If the return value is **AV_ERR_UNKNOWN**, the call does not take effect, and the input buffer is still in the unprocessed state. You need to handle the error according to the specific error code and then call [OH_AudioCodec_PushInputBuffer](#oh_audiocodec_pushinputbuffer) again with the same index. 376 377**System capability**: SystemCapability.Multimedia.Media.AudioCodec 378 379**Since**: 11 380 381**Parameters** 382 383| Name| Description| 384| -------- | -------- | 385| codec | Pointer to an OH_AVCodec instance.| 386| index | Index of the [OH_AVCodecOnNeedInputBuffer](_codec_base.md#oh_avcodeconneedinputbuffer).| 387 388**Returns** 389 390One of the following result codes defined in [OH_AVErrCode](_core.md#oh_averrcode): 391 392- **AV_ERR_OK**: The operation is successful. 393 394- **AV_ERR_INVALID_VAL**: The input index is used or invalid. Use the index returned by the [OH_AVCodecOnNeedInputBuffer](_codec_base.md#oh_avcodeconneedinputbuffer) callback. 395 396- **AV_ERR_INVALID_STATE**: The codec state is incorrect. Before calling [OH_AudioCodec_PushInputBuffer](#oh_audiocodec_pushinputbuffer), ensure that [OH_AudioCodec_Configure](#oh_audiocodec_configure), [OH_AudioCodec_Prepare](#oh_audiocodec_prepare), and [OH_AudioCodec_Start](#oh_audiocodec_start) are successfully called in sequence. 397 398- **AV_ERR_UNKNOWN**: The input buffer size is invalid. Ensure that the buffer size and flags are correctly set. 399 400 401### OH_AudioCodec_QueryInputBuffer() 402 403``` 404OH_AVErrCode OH_AudioCodec_QueryInputBuffer(OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs) 405``` 406 407**Description** 408 409Obtains the index of an available input buffer for an audio codec within the specified timeout period. 410 411**System capability**: SystemCapability.Multimedia.Media.AudioCodec 412 413**Since**: 20 414 415**Parameters** 416 417| Name| Description| 418| -------- | -------- | 419| codec | Pointer to an OH_AVCodec instance.| 420| index | Pointer to the index of the input buffer obtained.| 421| timeoutUs | Timeout period, in microseconds. A negative value means to wait infinitely.| 422 423**Returns** 424 425One of the following result codes: 426 427- **AV_ERR_OK**: The operation is successful. 428 429- **AV_ERR_INVALID_VAL**: The operation fails due to incorrect input parameters. 430 431- **AV_ERR_INVALID_STATE**: The operation fails due to an invalid state, for example, the codec not being started. 432 433- **AV_ERR_OPERATE_NOT_PERMIT**: The operation fails because the call is not allowed in asynchronous mode. 434 435- **AV_ERR_TRY_AGAIN_LATER**: The operation fails because no available buffer is obtained within the timeout period. 436 437### OH_AudioCodec_QueryOutputBuffer() 438 439``` 440OH_AVErrCode OH_AudioCodec_QueryOutputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs) 441``` 442 443**Description** 444 445Obtains the index of an available output buffer for an audio codec within the specified timeout period. 446 447**System capability**: SystemCapability.Multimedia.Media.AudioCodec 448 449**Since**: 20 450 451**Parameters** 452 453| Name| Description| 454| -------- | -------- | 455| codec | Pointer to an OH_AVCodec instance.| 456| index | Pointer to the index of the output buffer obtained.| 457| timeoutUs | Timeout period, in microseconds. A negative value means to wait infinitely.| 458 459**Returns** 460 461One of the following result codes: 462 463- **AV_ERR_OK**: The operation is successful. 464 465- **AV_ERR_INVALID_VAL**: The operation fails due to incorrect input parameters. 466 467- **AV_ERR_INVALID_STATE**: The operation fails due to an invalid state, for example, the codec not being started. 468 469- **AV_ERR_OPERATE_NOT_PERMIT**: The operation fails because the call is not allowed in asynchronous mode. 470 471- **AV_ERR_STREAM_CHANGED**: The format of the decoded output stream changes. You can call [OH_AudioCodec_GetOutputDescription](#oh_audiocodec_getoutputdescription) to obtain the new stream information. 472 473- **AV_ERR_TRY_AGAIN_LATER**: The operation fails because no available buffer is obtained within the timeout period. 474 475### OH_AudioCodec_RegisterCallback() 476 477``` 478OH_AVErrCode OH_AudioCodec_RegisterCallback (OH_AVCodec *codec, OH_AVCodecCallback callback, void *userData) 479``` 480 481**Description** 482 483Sets an asynchronous callback so that your application can respond to events generated by an audio codec. This function must be called prior to **Prepare**. 484 485**System capability**: SystemCapability.Multimedia.Media.AudioCodec 486 487**Since**: 11 488 489**Parameters** 490 491| Name| Description| 492| -------- | -------- | 493| codec | Pointer to an OH_AVCodec instance.| 494| callback | Callback function to set. For details, see [OH_AVCodecCallback](_o_h___a_v_codec_callback.md).| 495| userData | User-specific data.| 496 497**Returns** 498 499**AV_ERR_OK** if the operation is successful; an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 500 501 502### OH_AudioCodec_Reset() 503 504``` 505OH_AVErrCode OH_AudioCodec_Reset (OH_AVCodec *codec) 506``` 507 508**Description** 509 510Resets an audio codec. The configured parameters and input and output data are cleared. 511 512To continue encoding or decoding, you must call **Configure** to configure the codec again. 513 514**System capability**: SystemCapability.Multimedia.Media.AudioCodec 515 516**Since**: 11 517 518**Parameters** 519 520| Name| Description| 521| -------- | -------- | 522| codec | Pointer to an OH_AVCodec instance. | 523 524**Returns** 525 526**AV_ERR_OK** if the operation is successful; an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 527 528 529### OH_AudioCodec_SetDecryptionConfig() 530 531``` 532OH_AVErrCode OH_AudioCodec_SetDecryptionConfig (OH_AVCodec *codec, MediaKeySession *mediaKeySession, bool secureAudio) 533``` 534 535**Description** 536 537Sets the decryption information. 538 539**System capability**: SystemCapability.Multimedia.Media.AudioCodec 540 541**Since**: 12 542 543**Parameters** 544 545| Name| Description| 546| -------- | -------- | 547| codec | Pointer to an OH_AVCodec instance. | 548| mediaKeySession | Pointer to the media key session with the decryption feature. | 549| secureAudio | Whether a secure decoder is used. The value **true** means that a secure decoder is used, and **false** means the opposite.<br>Currently, the secure decoder is not supported for audio decryption. | 550 551**Returns** 552 553One of the following result codes defined in [OH_AVErrCode](_core.md#oh_averrcode): 554 555**AV_ERR_OK**: The operation is successful. 556 557**AV_ERR_INVALID_VAL**: The OH_AVCodec instance is nullptr or invalid, or the mediaKeySystemInfo instance is nullptr or invalid. 558 559**AV_ERR_INVALID_STATE**: The decoder service is unavailable. 560 561 562### OH_AudioCodec_SetParameter() 563 564``` 565OH_AVErrCode OH_AudioCodec_SetParameter (OH_AVCodec *codec, const OH_AVFormat *format) 566``` 567 568**Description** 569 570Sets dynamic parameters for an audio codec. 571 572This function can be called only after the codec is started. Incorrect parameter settings may cause encoding or decoding failure. 573 574**System capability**: SystemCapability.Multimedia.Media.AudioCodec 575 576**Since**: 11 577 578**Parameters** 579 580| Name| Description| 581| -------- | -------- | 582| codec | Pointer to an OH_AVCodec instance.| 583| format | Handle to an OH_AVFormat instance.| 584 585**Returns** 586 587**AV_ERR_OK** if the operation is successful; an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 588 589 590### OH_AudioCodec_Start() 591 592``` 593OH_AVErrCode OH_AudioCodec_Start (OH_AVCodec *codec) 594``` 595 596**Description** 597 598Starts an audio codec after it is prepared successfully. After being started, the codec starts to report the **OH_AVCodecOnNeedInputBuffer** event. 599 600**System capability**: SystemCapability.Multimedia.Media.AudioCodec 601 602**Since**: 11 603 604**Parameters** 605 606| Name| Description| 607| -------- | -------- | 608| codec | Pointer to an OH_AVCodec instance.| 609 610**Returns** 611 612**AV_ERR_OK** if the operation is successful; an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 613 614 615### OH_AudioCodec_Stop() 616 617``` 618OH_AVErrCode OH_AudioCodec_Stop (OH_AVCodec *codec) 619``` 620 621**Description** 622 623Stops an audio codec. 624 625After the codec is stopped, you can call **Start** to start it again. If you have passed specific data in the previous **Start** for the codec, you must pass it again. 626 627**System capability**: SystemCapability.Multimedia.Media.AudioCodec 628 629**Since**: 11 630 631**Parameters** 632 633| Name| Description| 634| -------- | -------- | 635| codec | Pointer to an OH_AVCodec instance.| 636 637**Returns** 638 639**AV_ERR_OK** if the operation is successful; an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 640