EVRC
Decodes enhanced variable rate codec (EVRC) audio data streams into the PCM format.
The function calling process is as follows:
- Obtain the size of the memory to be applied for decoding (dstBufLen).
- Initialize the HmppaEvrcDecodePolicy_16s structure by calling HMPPA_Evrc_DecodeInit_8u16s.
- Call the main function HMPPA_Evrc_Decode_8u16s for decoding.
- Call HMPPA_Evrc_DecodeRelease_8u16s to release the memory contained in the HmppaEvrcDecodePolicy_16s structure.
The function interface declaration is as follows:
- Obtaining the size of the memory to be applied for decoding:
HmppResult HMPPA_Evrc_GetDecodeDstBufLen_8u16s(int32_t len, int32_t *dstBufLen);
- Initialization:
HmppResult HMPPA_Evrc_DecodeInit_8u16s(HmppaEvrcDecodePolicy_16s **policy);
- Decoding:
HmppResult HMPPA_Evrc_Decode_8u16s(const uint8_t *src, int32_t len, int16_t *dst, HmppaEvrcDecodePolicy_16s *policy, int32_t *bytesConsumed, int64_t *bytesDecoded);
- Release:
HmppResult HMPPA_Evrc_DecodeRelease_8u16s(HmppaEvrcDecodePolicy_16s *policy);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Pointer to the EVRC stream to be decoded |
The value cannot be NULL. |
Input |
len |
Length of the data stream to be decoded, in bytes |
(0, INT_MAX] |
Input |
dst |
Pointer to the destination vector |
The value cannot be NULL. |
Output |
policy |
Pointer to the special structure |
The value cannot be NULL. |
Input/Output |
bytesConsumed |
Pointer to the data stream length (in bytes) actually consumed for decoding |
|
Output |
bytesDecoded |
Pointer to the data stream length (in bytes) of the actual decoded output |
|
Output |
dstBufLen |
Length (in duel-bytes) required to point to the destination vector |
The value cannot be NULL. |
Output |
Return Value
- Success: HMPP_STS_NO_ERR
- Failure: An error code is returned.
Error Codes
Error Code |
Description |
|---|---|
HMPP_STS_NULL_PTR_ERR |
The value of src, dst, or policy is NULL. |
HMPP_STS_SIZE_ERR |
The value of len is less than or equal to 0. |
HMPP_STS_MALLOC_FAILED |
Memory allocation failed. |
HMPP_STS_SIZE_WRN |
The input data stream is not completely decoded. |
Example
#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;
}
Output:
SUCCESS: result = 0, bytesConsumed = 3220872, bytesDecoded = 42944960.