static void* aacd_opencore_init() { AACDOpenCore *oc = (AACDOpenCore*) calloc( 1, sizeof(struct AACDOpenCore)); oc->pExt = calloc( 1, sizeof( tPVMP4AudioDecoderExternal )); oc->pMem = malloc( PVMP4AudioDecoderGetMemRequirements()); tPVMP4AudioDecoderExternal *pExt = oc->pExt; pExt->desiredChannels = 2; pExt->outputFormat = OUTPUTFORMAT_16PCM_INTERLEAVED; pExt->repositionFlag = TRUE; pExt->aacPlusEnabled = TRUE; Int err = PVMP4AudioDecoderInitLibrary(pExt, oc->pMem); if (err) { AACD_ERROR( "PVMP4AudioDecoderInitLibrary failed err=%d", err ); free( pExt ); free( oc->pMem ); free( oc ); oc = NULL; } return oc; }
int aacdec_init() { int memreq; pExt = malloc(sizeof(tPVMP4AudioDecoderExternal)); iInputBuf = calloc(KAAC_MAX_STREAMING_BUFFER_SIZE, sizeof(uint8_t)); memreq = PVMP4AudioDecoderGetMemRequirements(); pMem = malloc(memreq); //pExt->pOutputBuffer_plus = &iOutputBuf[2048]; pExt->pInputBuffer = iInputBuf; //pExt->pOutputBuffer = iOutputBuf; pExt->inputBufferMaxLength = KAAC_MAX_STREAMING_BUFFER_SIZE; pExt->desiredChannels = 2; pExt->inputBufferCurrentLength = 0; pExt->outputFormat = OUTPUTFORMAT_16PCM_INTERLEAVED; pExt->repositionFlag = TRUE; pExt->aacPlusEnabled = TRUE; /* Dynamically enable AAC+ decoding */ pExt->inputBufferUsedLength = 0; pExt->remainderBits = 0; pExt->frameLength = 0; pExt->inputBufferUsedLength=0; pExt->inputBufferCurrentLength = 0; if (PVMP4AudioDecoderInitLibrary(pExt, pMem) != 0) { fprintf(stderr, "init library failed\n"); return -1; } return 0; }
OMX_BOOL OmxAacDecoder::AacDecInit(OMX_U32 aDesiredChannels) { Int Status; iMemReq = PVMP4AudioDecoderGetMemRequirements(); ipMem = oscl_malloc(iMemReq); if (0 == ipMem) { return OMX_FALSE; } oscl_memset(&iExt, 0, sizeof(tPVMP4AudioDecoderExternal)); iExt.inputBufferCurrentLength = 0; iExt.remainderBits = 0; // Not needed anymore. iExt.inputBufferMaxLength = PVMP4AUDIODECODER_INBUFSIZE; iExt.outputFormat = OUTPUTFORMAT_16PCM_INTERLEAVED; iExt.desiredChannels = aDesiredChannels; iExt.aacPlusEnabled = TRUE; iAacInitFlag = 0; iInputUsedLength = 0; //This var is required to do init again inbetween iNumOfChannels = aDesiredChannels; Status = PVMP4AudioDecoderInitLibrary(&iExt, ipMem); return OMX_TRUE; }
status_t AACDecoder::initCheck() { memset(mConfig, 0, sizeof(tPVMP4AudioDecoderExternal)); mConfig->outputFormat = OUTPUTFORMAT_16PCM_INTERLEAVED; mConfig->aacPlusEnabled = 1; // The software decoder doesn't properly support mono output on // AACplus files. Always output stereo. mConfig->desiredChannels = 2; UInt32 memRequirements = PVMP4AudioDecoderGetMemRequirements(); mDecoderBuf = malloc(memRequirements); status_t err = PVMP4AudioDecoderInitLibrary(mConfig, mDecoderBuf); if (err != MP4AUDEC_SUCCESS) { ALOGE("Failed to initialize MP4 audio decoder"); return UNKNOWN_ERROR; } uint32_t type; const void *data; size_t size; sp<MetaData> meta = mSource->getFormat(); if (meta->findData(kKeyESDS, &type, &data, &size)) { ESDS esds((const char *)data, size); CHECK_EQ(esds.InitCheck(), (status_t)OK); const void *codec_specific_data; size_t codec_specific_data_size; esds.getCodecSpecificInfo( &codec_specific_data, &codec_specific_data_size); mConfig->pInputBuffer = (UChar *)codec_specific_data; mConfig->inputBufferCurrentLength = codec_specific_data_size; mConfig->inputBufferMaxLength = 0; UChar * spec = (UChar *)codec_specific_data; for(int i = 0; i < codec_specific_data_size; i++) { ALOGE("spec[%d] = 0x%x",i+1,spec[i]); } if (PVMP4AudioDecoderConfig(mConfig, mDecoderBuf) != MP4AUDEC_SUCCESS) { return ERROR_UNSUPPORTED; } }else if(meta->findData(kKeyAacInfo,&type,&data,&size)){ mConfig->pInputBuffer = (UChar *)data; mConfig->inputBufferCurrentLength = size; mConfig->inputBufferMaxLength = 0; if (PVMP4AudioDecoderConfig(mConfig, mDecoderBuf) != MP4AUDEC_SUCCESS) { return ERROR_UNSUPPORTED; } } return OK; }
// Initialize the aac reader. int aac_init(audio_decoder_p decoder, void *dec_ext) { decoder->dec_ext = calloc(1, sizeof(tPVMP4AudioDecoderExternal)); RETURN_VAL_IF_FAIL((decoder->dec_ext != NULL), AUDIO_DECODER_ERROR); decoder->dec_mem = calloc(1, PVMP4AudioDecoderGetMemRequirements()); RETURN_VAL_IF_FAIL((decoder->dec_mem != NULL), AUDIO_DECODER_ERROR); *((tPVMP4AudioDecoderExternal *) decoder->dec_ext) = *((tPVMP4AudioDecoderExternal *) dec_ext); PVMP4AudioDecoderResetBuffer(decoder->dec_mem); Int err = PVMP4AudioDecoderInitLibrary((tPVMP4AudioDecoderExternal *) decoder->dec_ext, decoder->dec_mem); RETURN_VAL_IF_FAIL((err == MP4AUDEC_SUCCESS), AUDIO_DECODER_ERROR); return AUDIO_DECODER_OK; }
OSCL_EXPORT_REF int32 CDecoder_AAC::StartL(tPVMP4AudioDecoderExternal * pExt, uint8 num_channels, bool aAllocateInputBuffer, bool aAllocateOutputBuffer, bool aAacplusEnabler) { iFirstFrame = true; iAllocateInputBuffer = aAllocateInputBuffer; iAllocateOutputBuffer = aAllocateOutputBuffer; if (iAllocateInputBuffer) { iInputBuf = OSCL_ARRAY_NEW(uint8, KAAC_MAX_STREAMING_BUFFER_SIZE); if (iInputBuf == NULL) { return KCAI_CODEC_INIT_FAILURE; } pExt->pInputBuffer = iInputBuf; pExt->inputBufferMaxLength = KAAC_MAX_STREAMING_BUFFER_SIZE; } else { pExt->pInputBuffer = NULL; pExt->inputBufferMaxLength = 0; } if (iAllocateOutputBuffer) { #ifdef AAC_PLUS iOutputBuf = OSCL_ARRAY_NEW(int16, 4096); #else iOutputBuf = OSCL_ARRAY_NEW(int16, 2048); #endif if (iOutputBuf == NULL) { return KCAI_CODEC_INIT_FAILURE; } pExt->pOutputBuffer = iOutputBuf; #ifdef AAC_PLUS pExt->pOutputBuffer_plus = &iOutputBuf[2048]; #else pExt->pOutputBuffer_plus = NULL; #endif } else { pExt->pOutputBuffer = NULL; pExt->pOutputBuffer_plus = NULL; } pExt->desiredChannels = num_channels; pExt->inputBufferCurrentLength = 0; pExt->outputFormat = OUTPUTFORMAT_16PCM_INTERLEAVED; pExt->repositionFlag = TRUE; pExt->aacPlusEnabled = aAacplusEnabler; /* Dynamically enable AAC+ decoding */ pExt->inputBufferUsedLength = 0; pExt->remainderBits = 0; int32 memreq = PVMP4AudioDecoderGetMemRequirements(); pMem = OSCL_ARRAY_NEW(uint8 , memreq); if (pMem == 0) { return KCAI_CODEC_NO_MEMORY; } return SUCCESS; }
OSCL_EXPORT_REF int32 CDecoder_AAC::StartL(tPVMP4AudioDecoderExternal * pExt, uint8 num_channels, bool aAllocateInputBuffer, bool aAllocateOutputBuffer, Int upsamplingFactor, Int samp_rate, tMP4AudioObjectType audioObjectType) { iFirstFrame = true; iAllocateInputBuffer = aAllocateInputBuffer; iAllocateOutputBuffer = aAllocateOutputBuffer; if (iAllocateInputBuffer) { iInputBuf = OSCL_ARRAY_NEW(uint8, KAAC_MAX_STREAMING_BUFFER_SIZE); if (iInputBuf == NULL) { return KCAI_CODEC_INIT_FAILURE; } pExt->pInputBuffer = iInputBuf; pExt->inputBufferMaxLength = KAAC_MAX_STREAMING_BUFFER_SIZE; } else { pExt->pInputBuffer = NULL; pExt->inputBufferMaxLength = 0; } if (iAllocateOutputBuffer) { #ifdef AAC_PLUS iOutputBuf = OSCL_ARRAY_NEW(int16, 4096); #else iOutputBuf = OSCL_ARRAY_NEW(int16, 2048); #endif if (iOutputBuf == NULL) { return KCAI_CODEC_INIT_FAILURE; } pExt->pOutputBuffer = iOutputBuf; #ifdef AAC_PLUS pExt->pOutputBuffer_plus = &iOutputBuf[2048]; #else pExt->pOutputBuffer_plus = NULL; #endif } else { pExt->pOutputBuffer = NULL; pExt->pOutputBuffer_plus = NULL; } pExt->desiredChannels = num_channels; pExt->inputBufferCurrentLength = 0; pExt->outputFormat = OUTPUTFORMAT_16PCM_INTERLEAVED; pExt->repositionFlag = TRUE; pExt->inputBufferUsedLength = 0; pExt->remainderBits = 0; int32 memreq = PVMP4AudioDecoderGetMemRequirements(); pMem = OSCL_ARRAY_NEW(uint8 , memreq); if (pMem == 0) { return KCAI_CODEC_NO_MEMORY; } if (PVMP4AudioDecoderInitLibrary(pExt, pMem) != 0) { return(KCAI_CODEC_INIT_FAILURE); } if (PVMP4SetAudioConfig(pExt, pMem, upsamplingFactor, samp_rate, num_channels, audioObjectType) != SUCCESS) { return KCAI_CODEC_INIT_FAILURE; } iNumSamplesPerFrame = KAAC_NUM_SAMPLES_PER_FRAME; pExt->desiredChannels = pExt->encodedChannels; iFirstFrame = false; return SUCCESS; }
OSCL_EXPORT_REF int32 GetActualAacConfig(uint8* aConfigHeader, uint8* aAudioObjectType, int32* aConfigHeaderSize, uint8* SamplingRateIndex, uint32* NumChannels) { tPVMP4AudioDecoderExternal * iAACDecExt = NULL; UInt initialUsedBits; /* Unsigned for C55x */ tDec_Int_File *pVars; /* Helper pointer */ MC_Info *pMC_Info; /* Helper pointer */ Int status = ERROR_BUFFER_OVERRUN; /* * Allocate memory to decode one AAC frame */ if (!iAACDecExt) { iAACDecExt = new tPVMP4AudioDecoderExternal; if (!iAACDecExt) { return 1; } iAACDecExt->inputBufferCurrentLength = 0; } iAACDecExt->pInputBuffer = aConfigHeader; iAACDecExt->inputBufferMaxLength = PVMP4AUDIODECODER_INBUFSIZE; iAACDecExt->inputBufferUsedLength = 0; iAACDecExt->remainderBits = 0; int32 memreq = PVMP4AudioDecoderGetMemRequirements(); uint8 *pMem = OSCL_ARRAY_NEW(uint8 , memreq); if (pMem == 0) { return KCODEC_INIT_FAILURE; } if (PVMP4AudioDecoderInitLibrary(iAACDecExt, pMem) != 0) { return KCODEC_INIT_FAILURE; } iAACDecExt->inputBufferCurrentLength = *aConfigHeaderSize; /* * Initialize "helper" pointers to existing memory. */ pVars = (tDec_Int_File *)pMem; pMC_Info = &pVars->mc_info; /* * Translate input buffer variables. */ pVars->inputStream.pBuffer = iAACDecExt->pInputBuffer; pVars->inputStream.availableBits = (UInt)(iAACDecExt->inputBufferCurrentLength << INBUF_ARRAY_INDEX_SHIFT); initialUsedBits = (UInt)((iAACDecExt->inputBufferUsedLength << INBUF_ARRAY_INDEX_SHIFT) + iAACDecExt->remainderBits); pVars->inputStream.inputBufferCurrentLength = (UInt)iAACDecExt->inputBufferCurrentLength; pVars->inputStream.usedBits = initialUsedBits; pVars->aacPlusEnabled = true; /* Always enable aacplus decoding */ if (initialUsedBits <= pVars->inputStream.availableBits) { /* * Buffer is not overrun, then * decode the AudioSpecificConfig() structure */ status = get_audio_specific_config(pVars); } byte_align(&pVars->inputStream); *aConfigHeaderSize = (Int32)((pVars->inputStream.usedBits) >> 3); *SamplingRateIndex = pVars->prog_config.sampling_rate_idx; *NumChannels = pVars->mc_info.nch; *aAudioObjectType = pVars->mc_info.audioObjectType; /* * Set parameters based on the explicit information from the * audio specific config */ if (pVars->mc_info.sbrPresentFlag) { if (pVars->mc_info.psPresentFlag) { *NumChannels += 1; } } pVars->status = status; /* * Clear allocated memory */ if (pMem != NULL) { OSCL_ARRAY_DELETE(pMem); pMem = NULL; } if (iAACDecExt) { OSCL_DELETE(iAACDecExt); iAACDecExt = NULL; } return status; }