EVRC
将EVRC(Enhanced Variable Rate Codec)协议音频数据流解码成PCM格式音频数据流。
该函数调用流程如下:
- 调用HMPPA_Evrc_DecodeInit_8u16s初始化HmppaEvrcDecodePolicy_16s结构体。
- 调用主函数HMPPA_Evrc_Decode_8u16s解码。
- 最后调用HMPPA_Evrc_DecodeRelease_8u16s释放HmppaEvrcDecodePolicy_16s结构体所包含的内存。
函数接口声明如下:
- 初始化函数:
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 |
指向实际解码消耗的长度(以字节为单位)。 |
|
输出 |
bytesDecoded |
指向实际解码输出的长度(以字节为单位)。 |
|
输出 |
返回值
- 成功:返回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; dstLen = srcLen / 24 * 320; src = HMPP_Malloc(srcLen); if (src == NULL) { printf("src buffer malloc failed.\n"); return -1; } dst = HMPP_Malloc(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; } memset(src, 0, srcLen); memset(dst, 0, 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.
父主题: 音频库接口函数