⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aacwrap.c

📁 本程序为ST公司开发的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/************************************************** * * aacwrap.c * * CVS ID:   $Id: aacwrap.c,v 1.19 2007/03/19 17:58:06 belardi Exp $ * Author:   Sangwon Bae [swbae] - Optomech * Date:     $Date: 2007/03/19 17:58:06 $ * Revision: $Revision: 1.19 $ *  * Description: *  * Wrapper functions around the ARM AAC library functions. *  *************************************************** *  * COPYRIGHT (C) Optomech  2006 *            All Rights Reserved * *************************************************** * * STM CVS Log: * * $Log: aacwrap.c,v $ * Revision 1.19  2007/03/19 17:58:06  belardi * Integration of Optomech AAC decoder P150307 * * Revision 1.18  2007/02/27 09:23:33  belardi * Optomech patch 070226 * - compilation in ARM mode no longer required * * Revision 1.17  2007/02/26 16:37:00  belardi * Minor modification to compile when DEBUG_INCLUDE_COUNTERS is defined * * Revision 1.16  2007/02/01 16:51:45  chlapik * fixed bug - song_number * * Revision 1.15  2007/01/30 09:38:16  chlapik * fixed bug: * song_number and xid sent from CTR to PLY is not set in CTR task but it is provided by DEC to AB * * Revision 1.14  2006/12/19 11:04:33  belardi * Integration of Optomech AAC decode P061219 * * Revision 1.13  2006/11/28 09:26:53  belardi * m4a decoder alfa release from Optomech * * Revision 1.12  2006/11/09 15:00:32  chlapik * fixed bugs - aligned with latest mp3wrap.c * * Revision 1.11  2006/11/09 12:40:45  chlapik * fixed bug - clearing of dataOffset variable after OpenBitstream(), now play, stop, play works * * Revision 1.10  2006/11/08 15:45:42  chlapik * fixed bug with no clearing of BOS event * * Revision 1.9  2006/10/31 15:23:02  chlapik * fixed compilation error due to 3 removed variables in mp3wrap.c * * Revision 1.8  2006/09/26 13:16:18  belardi * Removed compilation warnings * * Revision 1.7  2006/09/26 09:30:38  belardi * Removed unused variables * * Revision 1.6  2006/09/25 16:40:44  belardi * Added the CVS Log keyword * * ***************************************************/#include <stdio.h>#include <string.h>#include "gendef.h"#if (0 != HAVE_AAC)#include "osal.h"#include "decoder_task.h"#include "aac/aacdec.h"#include "mp3wrap.h"#include "aacwrap.h"#include "framebuffer.h"#include "audiobuffer.h"#include "controller.h"#include "filesys.h"#include "ioread.h"#include "allocation.h"CADecoderStateType AACDecoderNextState = notInitialized;extern t_PlayMode decoderPlayMode;extern unsigned char g_FB_readFrom; 			// from framebuffer.cextern FrameBufferElement pBufferElement;	// from mp3wrap.cuint8 CheckBitstreamParams;				// from mp3wrap.ceDecoderSampleRate PreviousSampleRate;	// from mp3wrap.cuint32 PreviousChannels;								// from mp3wrap.cstatic uint32 unreported_subcode_event_type;// Variables required by the ARM AAC librarystatic oDecoderHandle AACDecoderHandle;static sDecoderRequirements *AACRequirements_p;static sDecoderFormats *AACFormats_p;static void *AACScratch_p;static void *AACInstanceState_p;static sDecoderBitstream *AACBitstream_p;static sDecoderOutput *AACOutput_p;// AAC libary private datastatic void *outputChannelArray[2];static sDecoderFormats decoderFormatsStructure;static sDecoderRequirements decoderRequirementsStructure;static sDecoderOutput decoderOutputStructure;static sDecoderBitstream decoderBitstreamStructure;#if (1 == HAVE_SHOCK_MEMORY)uint32 AACIndexSize;uint8* AACIndexBuffer;#endif /* HAVE_SHOCK_MEMORY */extern void zeroMemory(char *pt, int size);#if (DEBUG_INCLUDE_COUNTERS==1)extern uint32 countMP3GoodFrames;extern uint32 countMP3BadFrames;#define countAACGoodFrames	countMP3GoodFrames#define countAACBadFrames		countMP3BadFrames#endif#define AACUpdateStatus			MP3UpdateStatus#define AACUpdateBitstream	MP3UpdateBitstreamextern AACUpdateStatus AACUpdateBitstream(sDecoderBitstream *Bitstream, int flag);void AACUpdateOutput(pAudioBufferData pBuf){	AACOutput_p->channels[0] = (void *) (pBuf + 2048);	AACOutput_p->channels[1] = (void *) (pBuf + 2560);}decoderReturnType AACInitHeader(oDecoderHandle* pHandle, void** pScratch,                                sDecoderFormats** pFormat,                                sDecoderBitstream** pBitstream){  //create input bitstream  AACBitstream_p = &decoderBitstreamStructure;  	// Define our required features for AAC decoder	AACFormats_p = &decoderFormatsStructure;	// to avoid having to explicitely set every field of the AACformats	// it is better to initialize it here.	zeroMemory((char *)AACFormats_p, sizeof(sDecoderFormats));	// 0x02 is the number of requested channels	AACFormats_p->outputFormats = OUTPUT_FORMAT_16BIT | OUTPUT_FORMAT_STEREO;	AACFormats_p->decoderFeatures = DECODER_FEATURE_NONE;	// Check decoder requirements	AACRequirements_p = &decoderRequirementsStructure;	AACDecoderRequirements(MPEG4AudioDecoder.DecoderReference, AACRequirements_p, AACFormats_p);	// Create decoder	AACInstanceState_p = MALLOC(AACRequirements_p->instanceStateSize);	if(AACRequirements_p->instanceStateSize && !AACInstanceState_p)	{    return decoderFatalError;	}#if (1 == HAVE_SHOCK_MEMORY)	if(sizeof(uint32) < AACIndexSize)	{		AACScratch_p = AACIndexBuffer;		*((uint32*)AACScratch_p) = AACIndexSize;	}	else	{		FREE(AACInstanceState_p);		INIT_FAST_MALLOC();    AACInstanceState_p = NULL;    return decoderFatalError;	}#else    	AACScratch_p = MALLOC(AACRequirements_p->scratchSize);	if(AACRequirements_p->scratchSize && !AACScratch_p)	{		FREE(AACInstanceState_p);		INIT_FAST_MALLOC();    AACInstanceState_p = NULL;    return decoderFatalError;	}	*((uint32*)AACScratch_p) = AACRequirements_p->scratchSize;  FREE(AACScratch_p); // simle & dangerous#endif /* HAVE_SHOCK_MEMORY */  FREE(AACDecoderHandle); // simle & dangerous  INIT_FAST_MALLOC();  AACDecoderHandle = AACDecoderCreate(MPEG4AudioDecoder.DecoderReference,                                      AACInstanceState_p, AACScratch_p,                                      AACFormats_p);	  *pHandle = AACDecoderHandle;  *pScratch = AACScratch_p;  *pFormat = AACFormats_p;  *pBitstream = AACBitstream_p;  return decoderUninitilaized;}void AACInit(void){  // check handle  if(NULL == AACInstanceState_p)  {		AACDecoderNextState = fatalError;		return;	}		//create output buffer	AACOutput_p = &decoderOutputStructure;	AACOutput_p->channelsRequired = NULL;	AACOutput_p->numberOfChannels = 2;		AACOutput_p->maxNumberOfSamples = AUDIO_BUFFER_ELEMENT_LENGTH / 2;	AACOutput_p->channels = (void *) outputChannelArray;	AACUpdateOutput(AudioBuffer[0].data);	AACOutput_p->channelOffsets = NULL;				// Cannot assume data is already present in FrameBuffer	// so leave the decoder in not initialized state	AACDecoderNextState = notInitialized;		unreported_subcode_event_type = 0;		decoderPlayMode = playModePlay;}decoderReturnType AACDecode(int flag){	eDecoderStatus ret;	pAudioBufferData AudioBuffer_p;		static ElementFlagType nextElementFlag;	static uint8 AACDataEOF;	static uint8 AACDataEOPB;	static CADecoderStateType NextStateAfterWaitAB;	static uint32 LastReportedFragment;	uint32 Fragment;		uint8 FB_clearFrom;	uint8 FB_clearTill;	// uint32 timeinfo_msf, timeinfo_msf_min;	uint32 CurrentBitRate;	uint32 CurrentFilePosAfterTAG;		tDecoderTime_event time_event;	t_position position;		while (1)	{	  switch (AACDecoderNextState) 	  {		case notInitialized:			// set pointer according to g_FB_readFrom			AACBitstream_p->data = (char*)FrameBuffer[(g_FB_readFrom % FrameBufferElements) + 1].data;				AACBitstream_p->dataLength = 0; 			AACBitstream_p->dataOffset = 0;			LastReportedFragment = 0xFFFFFFFF; //to ensure to report 1st time						nextElementFlag = FT_FIRST;//			ret = AACDecoderOpenBitstream(AACDecoderHandle, AACScratch_p, AACBitstream_p, AACFormats_p);			AACBitstream_p->dataRequired = 200;						//open bitstream doesn't clear dataOffset, so we must do that, otherwise AACUpdateBitstream() fails			AACBitstream_p->dataOffset = 0;				// Don't leave the loop, there may be more data already available			AACDecoderNextState = searchingHeader;	  	pBufferElement = FrameBuffer[0];						CheckBitstreamParams = 0;			break;    case waitingHeaderData:		  break;		case searchingHeader:			// We are searching for the first frame header in the			// compressed bistream. No data decoding happens here.			AACDataEOF = 0; // clear			AACDataEOPB = 0;			// Update bitstream data pointers before decoding			switch(AACUpdateBitstream(AACBitstream_p, flag))			{			case waitingForData:  // not enough data				return decoderWaitingFBdata;							case dataEOF: 		   // EOF				AACDataEOF = 1; // set				break;							case dataReady:	   // data ready				break;							case immediateEOF:    // request from Controller				return decoderEOF_immediate;							case dataEOPB:		   // end of play block (FF/FB)				AACDataEOPB = 1; // to wrap and start header decoding again				break;								   			}			// cheat for file offset			SetDecodedBytes(0);			AACBitstream_p->frameRemain = GetDecodedBytes() - AACBitstream_p->dataLength;			ret = AACDecodeHeader(AACDecoderHandle, AACScratch_p, AACBitstream_p);			// set number of DECODED bytes			SetDecodedBytes(AACBitstream_p->dataLength - AACBitstream_p->dataOffset);			//clear used FB elements			FB_clearFrom = GetElementNumber((unsigned char*)(AACBitstream_p->data));			FB_clearTill = GetElementNumber((unsigned char*)(AACBitstream_p->data + AACBitstream_p->dataOffset));			SetEmptyFBE(FB_clearFrom, FB_clearTill);			unreported_subcode_event_type |= pBufferElement.subcode.event_type;						//check if sample_rate and channels are the same values as before			//to make aac decoder more robust against lost of synchronization			//especially in case of fast seek

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -