---
title: EVRC
description: "将EVRC（Enhanced Variable Rate Codec）协议音频数据流解码成PCM格式音频数据流。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2200/accel/kunpengaccel_hmpp_06_0206.html
sourcePath: /source/zh/kunpengboostkithistory/2200/accel/kunpengaccel_hmpp_06_0206.html
indexId: 22ebf89fc05426536abb4497b35b16f27666e87eac04ced7b7a89549bf5343ce75
---
# EVRC

将EVRC（Enhanced Variable Rate Codec）协议音频数据流解码成PCM格式音频数据流。

该函数调用流程如下：

1. 获取解码需要申请的内存大小dstBufLen。
2. 调用HMPPA_Evrc_DecodeInit_8u16s初始化HmppaEvrcDecodePolicy_16s结构体。
3. 调用主函数HMPPA_Evrc_Decode_8u16s解码。
4. 最后调用HMPPA_Evrc_DecodeRelease_8u16s释放HmppaEvrcDecodePolicy_16s结构体所包含的内存。

函数接口声明如下：

- 获取解码需要申请的内存大小：
  HmppResult HMPPA_Evrc_GetDecodeDstBufLen_8u16s(int32_t len, int32_t *dstBufLen);

- 初始化函数：
  HmppResult HMPPA_Evrc_DecodeInit_8u16s(HmppaEvrcDecodePolicy_16s **policy);

- 解码函数：
  HmppResult HMPPA_Evrc_Decode_8u16s(const uint8_t *src, int32_t len, int16_t *dst, HmppaEvrcDecodePolicy_16s *policy, int32_t *bytesConsumed, int64_t *bytesDecoded);

- 释放函数：
  HmppResult HMPPA_Evrc_DecodeRelease_8u16s(HmppaEvrcDecodePolicy_16s *policy);


#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| src | 指向待解码的EVRC码流指针。 | 非空 | 输入 |
| len | 待解码数据流长度（以字节为单位）。 | (0, INT\_MAX] | 输入 |
| dst | 指向目的向量的指针。 | 非空 | 输出 |
| policy | 特殊结构体的指针。 | 非空 | 输入/输出 |
| bytesConsumed | 指向实际解码消耗的长度（以字节为单位）。 | 输入：空或者非空。 输出：当输入为空，不输出；当输入为非空时，输出范围为[0, len]。 | 输出 |
| bytesDecoded | 指向实际解码输出的长度（以字节为单位）。 | 输入：空或者非空。 输出：当输入为空，不输出；当输入为非空时，输出范围为[0, 理论解码len后输出的字节数]。 | 输出 |
| dstBufLen | 指向目的向量需要的长度（以双字节为单位）。 | 非空 | 输出 |


#### 返回值

- 成功：返回HMPP_STS_NO_ERR。
- 失败：返回错误码。


#### 错误码

| 错误码 | 描述 |
| --- | --- |
| HMPP\_STS\_NULL\_PTR\_ERR | src、dst、policy中存在空指针。 |
| HMPP\_STS\_SIZE\_ERR | len小于或者等于0。 |
| HMPP\_STS\_MALLOC\_FAILED | 申请内存失败。 |
| HMPP\_STS\_SIZE\_WRN | 输入的数据流未能完全解码。 |


#### 示例

```
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include "hmppa.h"
int main(int argc, char **argv)
{
int32_t len;
FILE *inFile;
FILE *outFile;
int32_t bytesConsumed = 0;
int64_t bytesDecoded = 0;
struct stat buf;
uint8_t *src = NULL;
int16_t *dst = NULL;
int32_t srcLen = 0;
int64_t dstLen = 0;
HmppResult result = 0;
if (argc < 3)
{
printf("Usage: %s <input.pkt> <output.pcm>\n", argv[0]);
return 0;
}
if (stat(argv[1], &buf) != 0)
{
printf("stat %s error\n", argv[1]);
return -1;
}
srcLen = buf.st_size;
result = HMPPA_Evrc_GetDecodeDstBufLen_8u16s(srcLen, &dstLen);
src = HMPP_Malloc(srcLen);
if (src == NULL)
{
printf("src buffer malloc failed.\n");
return -1;
}
dst = HMPPS_Malloc_16s(dstLen);
if (dst == NULL)
{
HMPP_Free(src);
printf("dst buffer malloc failed.\n");
return -1;
}
inFile = fopen(argv[1], "rb");
if (!inFile)
{
printf("Open File %s Failed.\n", argv[1]);
HMPP_Free(src);
HMPP_Free(dst);
return -1;
}
outFile = fopen(argv[2], "wb");
if (!outFile)
{
printf("Open File %s Failed.\n", argv[2]);
HMPP_Free(src);
HMPP_Free(dst);
fclose(inFile);
return -1;
}
(void)HMPPS_Zero_8u(src, srcLen);
(void)HMPPS_Zero_16s(dst, dstLen);
fread(src, sizeof(uint8_t), srcLen, inFile);
HmppaEvrcDecodePolicy_16s *policy;
result = HMPPA_Evrc_DecodeInit_8u16s(&policy);
if (result != HMPP_STS_NO_ERR)
{
printf("Evrc decode init failed : %d\n", result);
HMPP_Free(src);
HMPP_Free(dst);
fclose(inFile);
fclose(outFile);
return result;
}
result = HMPPA_Evrc_Decode_8u16s(src, srcLen, dst, policy, &bytesConsumed, &bytesDecoded);
if (result == HMPP_STS_NO_ERR)
{
fwrite((uint8_t *)dst, sizeof(uint8_t), bytesDecoded, outFile);
printf("SUCCESS: result = %d, bytesConsumed = %d, bytesDecoded = %ld.\n", result, bytesConsumed,
bytesDecoded);
}
else if (result == HMPP_STS_SIZE_WRN)
{
fwrite((uint8_t *)dst, sizeof(uint8_t), bytesDecoded, outFile);
printf("WARNING: result = %d, bytesConsumed = %d, bytesDecoded = %ld.\n", result,
bytesConsumed, bytesDecoded);
}
else
{
printf("ERROR: result = %d\n", result);
}
(void)HMPPA_Evrc_DecodeRelease_8u16s(policy);
HMPP_Free(src);
HMPP_Free(dst);
fclose(outFile);
fclose(inFile);
return result;
}
```

运行结果：

```
SUCCESS: result = 0, bytesConsumed = 3220872, bytesDecoded = 42944960.
```
