我要评分
获取效率
正确性
完整性
易理解

G729a

Decodes G729a audio data streams into the PCM format.

The function calling process is as follows:

  1. Obtain the size of the memory to be applied for decoding (dstBufLen).
  2. Initialize the HmppaG729aDecodePolicy_16s by calling HMPPA_G729a_DecodeInit_8u16s.
  3. Call the main function HMPPA_G729a_Decode_8u16s.
  4. Release the memory of HmppaG729aDecodePolicy_16s by calling HMPPA_G729a_DecodeRelease_8u16s.

The function interface declaration is as follows:

  • Obtaining the size of the memory to be applied for decoding:

    HmppResult HMPPA_G729a_GetDecodeDstBufLen_8u16s(int32_t len, int32_t *dstBufLen);

  • Initialization:

    HmppResult HMPPA_G729a_DecodeInit_8u16s(HmppaG729DecodePolicy_16s **policy);

  • Decoding:

    HmppResult HMPPA_G729a_Decode_8u16s(const uint8_t *src, int32_t len, int16_t *dst, HmppaG729DecodePolicy_16s *policy, int32_t *bytesConsumed, int64_t *bytesDecoded);

  • Release:

    HmppResult HMPPA_G729a_DecodeRelease_8u16s(HmppaG729DecodePolicy_16s *policy);

Parameters

Parameter

Description

Value Range

Input/Output

src

Pointer to the G729a stream to be decoded

The value cannot be NULL.

Input

len

Length of the G729a 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

[0, len]

Output

bytesDecoded

Pointer to the data stream length (in bytes) of the actual decoded output

[0, Theoretical output data stream length after decoding]

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_BAD_ARG_ERR

A member of the policy structure is invalid.

HMPP_STS_MALLOC_FAILED

Memory allocation failed.

HMPP_STS_SIZE_WRN

The value of len is not an integer multiple of the number of bytes contained in each frame.

Example

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "hmpp.h"

#define AUDIO_INBUF_SIZE 20480

int main(int argc, char **argv)
{
    const char *outFileName, *inFileName;
    int32_t len;
    FILE *inFile, *outFile;
    uint8_t *data;
    int32_t dataSize;
    int32_t bytesConsumered = 0;
    int64_t bytesDecoded = 0;

    if (argc <= 2) {
        printf("Usage: %s <input file> <output file>\n", argv[0]);
        exit(0);
    }
    inFileName = argv[1];
    outFileName = argv[2];

    inFile = fopen(inFileName, "rb");
    if (!inFile) {
        printf("Could not open %s\n", inFileName);
        exit(1);
    }
    outFile = fopen(outFileName, "wb");
    if (!outFile) {
        printf("Could not open %s\n", outFileName);
        exit(1);
    }

    HmppaG729aDecodePolicy_16s *policy;
    HmppResult result = HMPPA_G729a_DecodeInit_8u16s(&policy);
    if (result != HMPP_STS_NO_ERR){
	printf("HMPPA_G729a_DecodeInit_8u16s return : %d\n", result);
    }

    fseek(inFile, 0, SEEK_END);
    int32_t srcLen = ftell(inFile);
    fseek(inFile, 0, SEEK_SET);
    int32_t dstLen;
    HMPPA_G729a_GetDecodeDstBufLen_8u16s(srcLen, &dstLen);

    uint8_t *inBuf = (uint8_t*)malloc(srcLen * sizeof(uint8_t));
    int16_t *outBuf = HMPPS_Malloc_16s(dstLen);
    fread(inBuf, sizeof(uint8_t), srcLen, inFile);
    dataSize = srcLen;
    result = HMPPA_G729a_Decode_8u16s(inBuf, dataSize, outBuf, policy, &bytesConsumered, &bytesDecoded);
    fwrite(outBuf, 1, bytesDecoded, outFile);
    printf("HmppResult: %d, bytesConsumed: %d, bytesDecoded: %d\n", result, bytesConsumered, bytesDecoded);

    HMPPA_G729a_DecodeRelease_8u16s(policy);	
    HMPP_Free(outBuf);
    fclose(outFile);
    fclose(inFile);

    return 0;
}

Output:

HmppResult: 0, bytesConsumed: 3160, bytesDecoded: 50560