---
title: GSMEFR
description: "对源GSMEFR（GSM Enhanced Full Rate）协议音频流进行解码操作，输出int16型PCM数据流。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/240RC2/accel/kunpengaccel_hmpp_06_0207.html
sourcePath: /source/zh/kunpengboostkithistory/240RC2/accel/kunpengaccel_hmpp_06_0207.html
indexId: 95efb15976f864ab9fbec421604b7c0402126e3508aeeec57cbf621fe2f6c4b477
---
# GSMEFR

对源GSMEFR（GSM Enhanced Full Rate）协议音频流进行解码操作，输出int16型PCM数据流。

该函数调用流程如下：

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

函数接口声明如下：

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

- 初始化函数：
  HmppResult HMPPA_Gsmefr_DecodeInit_8u16s(HmppaGsmefrDecodePolicy_16s** policy);

- 解码函数：
  HmppResult HMPPA_Gsmefr_Decode_8u16s(const uint8_t* src, int32_t srcLen, int16_t* dst, HmppaGsmefrDecodePolicy_16s* policy, int32_t* bytesConsumed, int64_t* bytesDecoded);

- 释放函数：
  HmppResult HMPPA_Gsmefr_DecodeRelease_8u16s(HmppaGsmefrDecodePolicy_16s* policy);


#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| policy（Init函数中） | 指向GSMEFR Policy结构体的双重指针。 | 非空 | 输出 |
| policy（主函数中和Release函数中） | 指向GSMEFR结构体的指针。 | 非空 | 输入 |
| src | 指向输入的待解码的数据。 | 非空 | 输入 |
| srcLen | 输入数据的长度。 | 非负 | 输入 |
| dst | 指向输出的已解码的数据。 | 非空 | 输出 |
| bytesConsumed | 指向实际解码消耗的长度（以字节为单位）。 | 非空 | 输出 |
| bytesDecoded | 指向实际解码输出的长度（以字节为单位）。 | 可为空 | 输出 |
| dstBufLen | 指向目的向量需要的长度（以双字节为单位）。 | 非空 | 输出 |


#### 返回值

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


#### 错误码

| 错误码 | 描述 |
| --- | --- |
| HMPP\_STS\_NULL\_PTR\_ERR | 指针参数中包含空指针。 |
| HMPP\_STS\_SIZE\_ERR | srcLen不为正数。 |
| HMPP\_STS\_SIZE\_WRN | src未全部解码。 |


#### 示例

```
#include<stdlib.h>
#include<stdio.h>
#include"hmppa.h"
#define ONE_FRAME_GSM 31
#define ONE_FRAME_PCM 160
int main(int argc, char* argv[])
{
if (argc <3) {
printf("%s in.gsmefr out.pcm\n", argv[0]);
return 0;
}
FILE *file =fopen(argv[1], "rb");
if (file ==NULL) {
printf("Open File %s Failed\n", argv[1]);
return 0;
}
fseek(file, 0, SEEK_END);
int32_t srcLen =ftell(file);
int32_t dstLen;
HMPPA_Gsmefr_GetDecodeDstBufLen_8u16s(srcLen, &dstLen);
fseek(file, 0, SEEK_SET);
unsigned char src[srcLen];
short pcm[dstLen];
HmppaGsmefrDecodePolicy_16s *policy;
HMPPA_Gsmefr_DecodeInit_8u16s(&policy);
FILE *out = fopen(argv[2], "wb");
if (out == NULL) {
printf("Open File %s Failed\n", argv[2]);
return 0;
}
fread(src, sizeof(unsignedchar), srcLen, file);
int bytesConsumed;
int64_t bytesDecoded;
int res = HMPPA_Gsmefr_Decode_8u16s(src, srcLen, pcm, policy, &bytesConsumed, &bytesDecoded);
HMPPA_Gsmefr_DecodeRelease_8u16s(policy);
printf("bytesConsumed = %d, bytesDecoded = %d, res = %d\n", bytesConsumed, bytesDecoded, res);
fwrite(pcm, sizeof(short), bytesDecoded / 2, out);
}
```

运行结果：

```
bytesConsumed = 4898, bytesDecoded = 50560, res = 0
```
