?? audio_decoder.c
字號:
/* * audio_decoder.c *//* Standard Linux headers */#include <stdio.h> // always include stdio.h#include <stdlib.h> // always include stdlib.h#include <string.h> // memset, memcpy, strcmp, strcpy/* Codec Engine headers */#include <xdc/std.h> // xdc base definitions. Must come 1st#include <ti/sdo/ce/Engine.h> // Engine_open, Engine_Handle, etc#include <ti/sdo/ce/audio/auddec.h> // AUDDEC_create, AUDDEC_Handle, etc/* Application headers */#include "audio_decoder.h" // must be preceded by Engine.h and auddec.h#include "debug.h" // defines debug routines/* Macro for clearing structures */#define CLEAR(x) memset (&(x), 0, sizeof (x))/****************************************************************************** * audio_decoder_setup ******************************************************************************//* input parameters: *//* Engine_Handle engineHandle -- handle to the codec engine *//* int *decoderName -- name of the video decoder to create *//* AUDDEC_Handle *decoderHandleByRef -- pointer to audio decoder handle, *//* used to return the handle of the decoder *//* created by this function. *//* *//* *//* return value: *//* int -- ADEC_SUCCESS or ADEC_FAILURE as defined in audio_decoder.h *//* *//******************************************************************************/int audio_decoder_setup(Engine_Handle engineHandle, char *decoderName, AUDDEC_Handle *decoderHandleByRef){ AUDDEC_Handle decoderHandle; // Speech Decoder Handle /* Create audio decoder instance */ /* Null attributes value specifies default attributes */ decoderHandle = AUDDEC_create(engineHandle, decoderName, NULL); if (decoderHandle == NULL) { ERR("Can't create audio decode instance of %s\n", decoderName); return ADEC_FAILURE; } DBG("Created audio decoder instance of %s\n", decoderName); DBG("\tWith handle %#0lx\n", (unsigned long) decoderHandle); DBG("\tUsing default static and dynamic parameters\n"); /* return audio decoder handle through decoderHandleByRef pointer */ *decoderHandleByRef = decoderHandle; /* return ADEC_SUCCESS if AUDDEC_create executes successfully */ return ADEC_SUCCESS;}/****************************************************************************** * decode_audio ******************************************************************************//* input parameters: *//* AUDDEC_Handle decoderHandle -- handle to the audio decoder as *//* returned by audio_decoder_setup *//* char *inputBuffer -- buffer of encoded input data *//* int inputSize -- size of inputBuffer in bytes *//* char *outputBuffer -- buffer to output decoded frame into *//* int outputSize -- size of outputBuffer in bytes *//* *//* *//* return value: *//* int -- ADEC_SUCCESS or ADEC_FAILURE as defined in audio_decoder.h *//* *//******************************************************************************/int decode_audio(AUDDEC_Handle decoderHandle, char *inputBuffer, int inputSize, char *outputBuffer, int outputSize){/* Declare arguments and return value for AUDDEC_process */ AUDDEC_InArgs inArgs; // input args for AUDDEC_process AUDDEC_OutArgs outArgs; // output (return) from AUDDEC_process XDM_BufDesc inBufDesc; // buffer descriptor for input buffer XDM_BufDesc outBufDesc; // buffer descriptor for output buffer XDAS_Int32 status; // success or failure for AUDDEC_process/* Declare Buffer descriptor elements */ XDAS_Int32 inBufSizeArray[1]; // pointed to by inBufDesc.bufSizes XDAS_Int32 outBufSizeArray[1]; // pointed to by outBufDesc.bufSizes/* Fill in input buffer descriptor */ inBufSizeArray[0] = inputSize; inBufDesc.numBufs = 1; // One input buffer inBufDesc.bufSizes = inBufSizeArray; // of this size inBufDesc.bufs = (XDAS_Int8 **) &inputBuffer; // located here/* Fill in output buffer descriptor */ outBufSizeArray[0] = outputSize; outBufDesc.numBufs = 1; // One output buffer outBufDesc.bufSizes = outBufSizeArray; // of this size outBufDesc.bufs = (XDAS_Int8 **) &outputBuffer; // located here/* Fill in input arguments structure */ inArgs.size = sizeof(AUDDEC_InArgs); inArgs.numBytes = inputSize;/* Specify size of output arguments (return) structure */ outArgs.size = sizeof(AUDDEC_OutArgs); /* Decode audio buffer */ status = AUDDEC_process(decoderHandle, &inBufDesc, &outBufDesc, &inArgs, &outArgs); if (status != AUDDEC_EOK) { ERR("AUDDEC_process() failed in decode_audio()\n"); ERR("\twith extended error mask %#0x\n", (unsigned int) outArgs.extendedError); return ADEC_FAILURE; } /* return ADEC_SUCCESS if AUDDEC_process executes correctly */ return ADEC_SUCCESS;}/****************************************************************************** * audio_decoder_cleanup ******************************************************************************//* input parameters: *//* AUDDEC_Handle decoderHandle -- handle to the audio decoder as *//* returned by audio_decoder_setup *//* *//* *//* return value: *//* int -- always returns ADEC_SUCCESS as defined in audio_decoder.h *//* *//******************************************************************************/int audio_decoder_cleanup(AUDDEC_Handle decoderHandle){ AUDDEC_Status status; AUDDEC_DynamicParams dynParams; /* Zero out the status and dynParams structures */ CLEAR(status); CLEAR(dynParams); /* Set size field of status and dynParams */ status.size = sizeof(AUDDEC_Status); dynParams.size = sizeof(AUDDEC_DynamicParams); /* Query decoder for status */ AUDDEC_control(decoderHandle, XDM_GETSTATUS, &dynParams, &status); /* Delete decoder instance */ AUDDEC_delete(decoderHandle); /* Report any errors */ if(status.extendedError){ ERR("Deleted audio decoder instance with handle %#0lx\n", (unsigned long) decoderHandle); ERR("\tDecoder exited with error mask %#0x\n", (unsigned int) status.extendedError ); } else{ DBG("Deleted audio decoder instance with handle %#0lx\n", (unsigned long) decoderHandle); DBG("\tDecoder exited with no errors\n"); } /* Return success */ return ADEC_SUCCESS;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -