📄 maioggdec.c
字号:
/* <LIC_AMD_STD> * Copyright (c) 2005 Advanced Micro Devices, Inc. * * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * </LIC_AMD_STD> *//* <CTL_AMD_STD> * </CTL_AMD_STD> *//* <DOC_AMD_STD> * Filename: maioggdec.c - MPEG Audio decoder interfaces for MAIengine * </DOC_AMD_STD> */#if defined(WIN32) || defined(UNDER_CE) #include <windows.h>#endif#include <stdio.h>#include <stdlib.h>#include "mai_osal.h" /* needed for threads */#include "mai_component.h" /* was mai_def.h, mai_readandparse.h */#include "mai_compbase.h"#include "ivorbiscodec.h"#include "ivorbisfile.h"#ifdef TRACE_BUILD #define DPRINTF(_args_) MAIOSDebugPrint _args_ #define APIPRINTF(_args_) MAIOSDebugPrint _args_ #define FILLPRINTF(_args_) MAIOSDebugPrint _args_ #define ERRORPRINTF(_args_) MAIOSDebugPrint _args_ #else #define DPRINTF(_args_) /* MAIOSDebugPrint _args_ */ #define APIPRINTF(_args_) /* MAIOSDebugPrint _args_ */ #define FILLPRINTF(_args_) /* MAIOSDebugPrint _args_ */ #define ERRORPRINTF(_args_) /* MAIOSDebugPrint _args_ */#endif#define DEFAULT_INBUFSIZE (8*1024)#define DEFAULT_INBUFCOUNT 8#define OGG_INTERNAL_INPUT_BUFFER_SIZE 8192#define AUDIOINITBUFSIZE 4096#if defined(UNDER_CE) #define NUMBER_OF_OUTPUT_BUFFERS 64 /* If we make this any larger, we lose buffers. */#else #define NUMBER_OF_OUTPUT_BUFFERS ((512*1024)/OPTIMAL_OGG_OUTBUFFER_SIZE)#endif//#define DUMP_TO_FILE //#define DUMP_AUDIO_TO_FILE //#define DUMP_COMPRESSED_AUDIO_TO_FILE/* Decoder State Definitions: MAI_RUNSTATE_NONE - decoder not initialized MAI_RUNSTATE_INIT - decoder initialized, decodes not started yet MAI_RUNSTATE_PLAYING - decoder initialized, decodes active MAI_RUNSTATE_PAUSED - decoder initialized, decodes paused MAI_RUNSTATE_DESTROYING - MAICompEnd() in progress - destroying decoder*//* Our component's private processor variables are stored here */typedef struct ProcessorInfo_s { unsigned int m_uiProcessLoops; unsigned int m_uiNeedsInit; unsigned int m_uiMaxInBufferSize; unsigned int m_uiStreamPosition; unsigned int m_bNewFormat; unsigned int m_uiPrevSRate; unsigned int m_nPrevChannels; unsigned int m_nErrorCount; OggVorbis_File vf; vorbis_info *vi; unsigned int m_bReversedByteOrder; unsigned int m_uiAudioInbufSize; unsigned int m_uiNormalAudioInbufSize; int m_iLastFrame; unsigned int m_uiOutcount; unsigned int m_uiInitialInputBufValid; unsigned char m_InitialInputBuf[AUDIOINITBUFSIZE]; unsigned char *m_pucAudioInBuf; unsigned char *m_pAudioOutBuf; unsigned char *m_pAudioInitBuf;} ProcessorInfo_t;static MAIStatus_e open_ogg(ProcessorInfo_t *pPInfo){ MAIStatus_e eStatus = MAI_STATUS_OK; /* open the OGG audio decoder */ pPInfo->m_uiProcessLoops = 0; pPInfo->m_uiMaxInBufferSize = 0; pPInfo->m_bReversedByteOrder = 0; pPInfo->m_uiPrevSRate=0; pPInfo->m_nPrevChannels=0; pPInfo->m_bNewFormat = 1; pPInfo->m_pAudioOutBuf = malloc(OPTIMAL_OGG_OUTBUFFER_SIZE); pPInfo->m_uiNeedsInit = 0; pPInfo->m_uiAudioInbufSize = 0; if (pPInfo->m_pAudioOutBuf == NULL) eStatus = MAI_STATUS_NOBUFAVAIL; pPInfo->m_pAudioInitBuf = malloc(AUDIOINITBUFSIZE); if (pPInfo->m_pAudioInitBuf == NULL) eStatus = MAI_STATUS_NOBUFAVAIL; APIPRINTF((M_TEXT("OGGDEC: open_ogg() exit: status %x\n"), eStatus)); return eStatus;}MAIStatus_e _startprocessing(MAICompHandle_t hComp){ ProcessorInfo_t *pPInfo=(ProcessorInfo_t *)HCOMP_TO_USERINFO(hComp); MAIStatus_e eStatus = MAI_STATUS_OK; APIPRINTF((M_TEXT("OGGDEC: _startprocessing() enter\n"))); if (!MAICompBase_IsState(hComp, MAI_RUNSTATE_NONE)) eStatus=MAI_STATUS_WRONGSTATE; else { APIPRINTF((M_TEXT("OGGDEC: _startprocessing() Init codec\n"))); /* open the ogg audio decoder */ eStatus = open_ogg(pPInfo); /* Register output setup (needed for Read/WriteBuffer) */ MAICompBase_RegisterOutput(hComp, 0, M_NULL /* pfOutputGetBuffer */, M_NULL /* pfOutputPutBuffer */, hComp, OPTIMAL_OGG_OUTBUFFER_SIZE, NUMBER_OF_OUTPUT_BUFFERS); /* allocate max 512kb of output buffering */ } if (eStatus==MAI_STATUS_OK) { MAICompHandleInfo_t *pCompInfo=HCOMP_TO_HANDLEINFO(hComp); /* update codec name in Component info */ sprintf(pCompInfo->Info.pszDesc, "OggVorbis"); /* call default StartProcessing */ MAICompBase_StartProcessing(hComp); } APIPRINTF((M_TEXT("OGGDEC: _startprocessing() exit: status=0x%X\n"), eStatus)); return eStatus;}static void close_ogg(ProcessorInfo_t *pPInfo){ if (pPInfo->m_pAudioInitBuf != NULL) { free(pPInfo->m_pAudioInitBuf); pPInfo->m_pAudioInitBuf = NULL; } if (pPInfo->m_pAudioOutBuf != NULL) { free(pPInfo->m_pAudioOutBuf); pPInfo->m_pAudioOutBuf = NULL; } if (pPInfo->m_pucAudioInBuf != NULL) { free(pPInfo->m_pucAudioInBuf); pPInfo->m_pucAudioInBuf = NULL; } pPInfo->m_uiNeedsInit = 1; pPInfo->m_uiProcessLoops = 0; ov_clear(&(pPInfo->vf)); APIPRINTF((M_TEXT("OGGDEC: close_ogg() exit\n")));}MAIStatus_e _endprocessing(MAICompHandle_t hComp){ ProcessorInfo_t *pPInfo=(ProcessorInfo_t *)HCOMP_TO_USERINFO(hComp); MAIStatus_e eStatus = MAI_STATUS_OK; APIPRINTF((M_TEXT("OGGDEC: _endprocessing() enter\n"))); if (MAICompBase_IsState(hComp, MAI_RUNSTATE_NONE)) eStatus=MAI_STATUS_WRONGSTATE; else close_ogg(pPInfo); MAICompBase_EndProcessing(hComp); APIPRINTF((M_TEXT("OGGDEC: _endprocessing() exit: status=0x%X\n"), eStatus)); return eStatus;}int wrap_errno;//int cur_position;long wrap_ftell(FILE *fp){// long ret = ftell(fp);// DPRINTF((M_TEXT("ftell %x %x\n"), ret, cur_position));// cur_position = ret;// return ret; return -1;}int wrap_fclose(FILE *fp){// DPRINTF((M_TEXT("close\n")));// return fclose(fp); return 0;}#ifdef DUMP_AUDIO_TO_FILE #define DUMPAUDIO(bb, ss) dump_audio((unsigned char *)bb, ss) #define dDPRINTF(_args_) MAIOSDebugPrint _args_ static FILE *daofp = NULL; static int iteration = 0; void close_dump_audio(void) { if (daofp != NULL) { fclose(daofp); daofp = NULL; dDPRINTF((M_TEXT("OGGDEC: close_dump_audio %d\n"), iteration)); iteration++; } else { dDPRINTF((M_TEXT("OGGDEC: close_dump_audio trying to close a closed file, iteration %d\n"), iteration)); } } void dump_audio(unsigned char *buf, unsigned int size) { static char name[256]; if (daofp == NULL) { #if defined(UNDER_CE) sprintf(name, "\\Hard Disk\\dumpogg%d.pcm", iteration); #elif defined(WIN32) sprintf(name, "c:\\temp\\dumpogg%d.pcm", iteration); #else sprintf(name, "dumpogg%d.pcm", iteration); #endif daofp = fopen(name, "wb"); dDPRINTF((M_TEXT("opening %s %p\n"), name, daofp)); } if (daofp != NULL) { int vv = fwrite(buf, 1, size, daofp); //printf("wrote %d bytes\n", vv); } }#else #define DUMPAUDIO(bb, ss) #define close_dump_audio()#endif#ifdef DUMP_COMPRESSED_AUDIO_TO_FILE #define DUMPCOMPAUDIO(bb, ss) dump_compressed_audio((unsigned char *)bb, ss) static FILE *dcaofp = NULL; static int citeration = 0; void close_dump_compressed_audio(void) { if (dcaofp != NULL) fclose(dcaofp); dcaofp = NULL; printf("OGGDEC: close_dump_compressed_audio %d\n", citeration); citeration++; } void dump_compressed_audio(unsigned char *buf, unsigned int size) { static char name[256]; if (dcaofp == NULL) { #if defined(UNDER_CE) sprintf(name, "\\Hard Disk\\dumpogg%d.ogg", citeration); #elif defined(WIN32) sprintf(name, "c:\\temp\\dumpogg%d.ogg", citeration); #else sprintf(name, "dumpogg%d.ogg", citeration); #endif dcaofp = fopen(name, "wb"); printf("opening %s %p\n", name, dcaofp); } if (dcaofp != NULL) { int vv = fwrite(buf, 1, size, dcaofp); //printf("wrote %d bytes\n", vv); } }#else #define DUMPCOMPAUDIO(bb, ss) #define close_dump_compressed_audio()#endifstatic ProcessorInfo_t *pPInfo;long wrap_fread(unsigned char *buf, size_t aa, size_t bb, FILE *fp){ unsigned int to_get = aa * bb; FILLPRINTF((M_TEXT("fread want %x, have %x\n"), to_get, pPInfo->m_uiAudioInbufSize)); if (pPInfo->m_uiAudioInbufSize >= to_get) { memcpy(buf, pPInfo->m_pucAudioInBuf, to_get);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -