📄 maimpadec.c
字号:
{ APIPRINTF((M_TEXT("MPADEC: _processbuffer() pass DATADISCON\n"))); BufferInfo.dwFlags |= MAICOMPBUF_FLAG_DATADISCON; init_ignore_buffer_count(pPInfo->m_sc->sample_rate, pPInfo->m_sc->nb_channels, 4); /* prevent playing chirps in the immediate future */ if (out_size > 0) memset(pPInfo->m_sc->outbuf, 0, out_size); /* kill the chirp */ uiBufFlags&=~MAICOMPBUF_FLAG_DATADISCON; /* clear DATADISCON flag, report only once for this buffer */ } if ((uiBufFlags&MAICOMPBUF_FLAG_EOS)!=0 && insize<=bytesdecoded) /* last buffer to output, check for EOS */ { APIPRINTF((M_TEXT("MPADEC: _processbuffer() pass EOS: out_size=%d insize=%d bytesdecoded=%d\n"), out_size, insize, bytesdecoded)); BufferInfo.dwFlags|=MAICOMPBUF_FLAG_EOS; bytesdecoded = insize; uiBufFlags&=~MAICOMPBUF_FLAG_EOS; /* clear EOS flag, report only once for this buffer */ } BufferInfo.pBuffer = pPInfo->m_sc->outbuf; BufferInfo.uiDataSize = BufferInfo.uiBufSize = out_size; DUMPAUDIO(BufferInfo.pBuffer, BufferInfo.uiDataSize); eStatus=MAICompBase_OutputPutBuf(hComp, 0, &BufferInfo); } if (bytesdecoded > insize) bytesdecoded = insize; /* safety, should never happen */ insize -= bytesdecoded; inbuf_ptr += bytesdecoded; pPInfo->m_uiProcessLoops++; } if ((pInBufferInfo->dwFlags&MAICOMPBUF_FLAG_EOS)!=0) { APIPRINTF((M_TEXT("MPADEC: _processbuffer() EOS received, size %d\n"), pInBufferInfo->uiDataSize)); if ((uiBufFlags&MAICOMPBUF_FLAG_EOS)!=0) /* EOS not yet sent downstream */ { BufferInfo.dwFlags = MAICOMPBUF_FLAG_EOS; APIPRINTF((M_TEXT("MPADEC: _processbuffer() pass EOS\n"))); BufferInfo.pBuffer = NULL; BufferInfo.uiDataSize = 0; eStatus=MAICompBase_OutputPutBuf(hComp, 0, &BufferInfo); } /* note: that MAICompBase_SendEOS(hComp, 0); happens in MAICompBase_ProcessorThread() */ close_mpadec(hComp); /* End of stream, so go to IDLE state. Next piece of data received should switch back to PLAYING state */ if (MAICompBase_IsState(hComp, MAI_RUNSTATE_PAUSING|MAI_RUNSTATE_PAUSED|MAI_RUNSTATE_STARTING|MAI_RUNSTATE_PLAYING)) MAICompBase_ChangeState(hComp, MAI_RUNSTATE_IDLE); MAICompBase_SetFormatState(hComp, FORMAT_STATE_NONE); return eStatus; } DPRINTF((M_TEXT("MPADEC: _processbuffer() exit: result=0x%08X\n"), eStatus)); return eStatus;}static MAIStatus_e MAICompInitInput(MAICompHandle_t hComp, unsigned int uiPinID, pfMAICompGetBufferCB_t *ppfInputGetBuffer, pfMAICompPutBufferCB_t *ppfInputPutBuffer){ MAIStatus_e eStatus; eStatus=MAICompBase_InitInput(hComp, uiPinID, ppfInputGetBuffer, ppfInputPutBuffer, DEFAULT_INBUFSIZE, DEFAULT_INBUFCOUNT); return eStatus;}static MAIStatus_e MAICompInitOutput(MAICompHandle_t hComp, unsigned int uiPinID, pfMAICompGetBufferCB_t pfOutputGetBuf, pfMAICompPutBufferCB_t pfOutputPutBuf, MAICompHandle_t hBufferOwnerComp){ return MAICompBase_InitOutput(hComp, uiPinID, pfOutputGetBuf, pfOutputPutBuf, hBufferOwnerComp);}static MAIStatus_e MAICompStart(MAICompHandle_t hComp){ ProcessorInfo_t *pPInfo=(ProcessorInfo_t *)HCOMP_TO_USERINFO(hComp); MAIStatus_e eStatus = MAI_STATUS_OK; APIPRINTF((M_TEXT("MPADEC: MAICompStart() enter\n"))); _startprocessing(hComp); eStatus=MAICompBase_StartStreaming(hComp, MAICompBase_ProcessorThread, 0); APIPRINTF((M_TEXT("MPADEC: MAICompStart() done: status=0x%X\n"), eStatus)); return eStatus;}static MAIStatus_e MAICompEnd(MAICompHandle_t hComp){ MAIStatus_e eStatus = MAI_STATUS_OK; APIPRINTF((M_TEXT("MPADEC: MAICompEnd() enter\n"))); /* call base EndStreaming to close down any running threads */ eStatus=MAICompBase_EndStreaming(hComp, MAI_TIMEOUT_INFINITE); /* now call our local endprocessing logic */ if (!MAICompBase_IsState(hComp, MAI_RUNSTATE_NONE)) eStatus=_endprocessing(hComp); APIPRINTF((M_TEXT("MPADEC: MAICompEnd() done: status=0x%X\n"), eStatus)); return eStatus;}static MAIStatus_e MAICompSendCommand(MAICompHandle_t hComp, m_u32 uiCommand, m_u32 uiParam1, m_u32 uiParam2, m_u32 uiParam3, void *pUserInstance, MAITimeOut_t uiTimeOut){ ProcessorInfo_t *pPInfo=(ProcessorInfo_t *)HCOMP_TO_USERINFO(hComp); MAIStatus_e eStatus = MAI_STATUS_OK; switch (uiCommand) { /* handle component specific Commands here */ case MAI_CMD_EMPTY: APIPRINTF((M_TEXT("MPADEC: MAICompSendCommand(CMD_EMPTY)\n"))); /* need to flush out data in codec */ init_ignore_buffer_count(pPInfo->m_sc->sample_rate, pPInfo->m_sc->nb_channels, 0); break; } APIPRINTF((M_TEXT("MPADEC: MAICompSendCommand(Cmd=%d,%d,%d,%d) Passing command to compbase\n"), uiCommand, uiParam1, uiParam2, uiParam3) ); eStatus=MAICompBase_SendCommand(hComp, uiCommand, uiParam1, uiParam2, uiParam3, pUserInstance, uiTimeOut); return eStatus;}static MAIStatus_e MAICompGetParam(MAICompHandle_t hComp, unsigned int uiParam, void *pvParamData, unsigned int uiDataSize){ return MAICompBase_GetParam(hComp,uiParam,pvParamData,uiDataSize);}static MAIStatus_e MAICompSetParam(MAICompHandle_t hComp, unsigned int uiParam, void *pvParamData, unsigned int uiDataSize){ return MAICompBase_SetParam(hComp,uiParam,pvParamData,uiDataSize);}static MAIStatus_e MAICompGetMediaType(MAICompHandle_t hComp, MAICompDirection_e eDirection, MAICompPinID_t uiPinID, MAIMediaType_t *pMediaType){ ProcessorInfo_t *pPInfo=(ProcessorInfo_t *)HCOMP_TO_USERINFO(hComp); MAIStatus_e eStatus = MAI_STATUS_UNSUPPORTED; if (eDirection==MAICOMP_DIR_INPUT && uiPinID==0) { if (!pMediaType) eStatus=MAI_STATUS_BADARG; else { MAIMediaTypeAudio_t *pAudioInfo=(MAIMediaTypeAudio_t *)pMediaType; /* clear the info structure */ memset(pAudioInfo, 0, sizeof(MAIMediaTypeAudio_t)); /* fill in Common MediaType fields */ pAudioInfo->MediaTypeInfo.uiSize=sizeof(MAIMediaTypeAudio_t); pAudioInfo->MediaTypeInfo.eMType=MAI_MTYPE_AUDIO; pAudioInfo->MediaTypeInfo.eMSubtype=MAI_MSUBTYPE_MPA; pAudioInfo->MediaTypeInfo.uiFlags=0; pAudioInfo->uiFlags = 0; /* init to no flags set */ if (pPInfo->m_uiProcessLoops) /* fill in audio format details if decoder is running */ { /* Fill in Audio MediaType specific fields */ pAudioInfo->uiFlags = MAI_AUDIOMTFLAG_FORMATKNOWN; /* init to no flags set */ pAudioInfo->uiModeFlags = 0; /* init to no mode flags set */ pAudioInfo->uiSamplesPerSec = mpeg_decoder.decode_context.sample_rate; pAudioInfo->uiBitsPerSample = 16; pAudioInfo->uiChannels = mpeg_decoder.decode_context.nb_channels; pAudioInfo->uiBitrate = mpeg_decoder.decode_context.bit_rate; if (mpeg_decoder.decode_context.vbr) pAudioInfo->uiFlags |= MAI_AUDIOMTFLAG_VBR; pAudioInfo->uiFramesize = mpeg_decoder.decode_context.keep_frame_size; if (mpeg_decoder.decode_context.sbr) pAudioInfo->uiModeFlags |= MAI_AUDIOMODEFLAG_SBR; pAudioInfo->uiEmphasis = mpeg_decoder.decode_context.emphasis; /* 0, 1, 2, 3 */ pAudioInfo->uiLayer = mpeg_decoder.decode_context.layer; if (mpeg_decoder.decode_context.mode_ext & MODE_EXT_I_STEREO) pAudioInfo->uiModeFlags |= MAI_AUDIOMODEFLAG_INTENSITYSTEREO; if (mpeg_decoder.decode_context.mode_ext & MODE_EXT_MS_STEREO) pAudioInfo->uiModeFlags |= MAI_AUDIOMODEFLAG_MSSTEREO; if (mpeg_decoder.decode_context.mode == MPA_JSTEREO) pAudioInfo->uiModeFlags |= MAI_AUDIOMODEFLAG_JOINTSTEREO; } eStatus=MAI_STATUS_OK; } } else if (eDirection==MAICOMP_DIR_OUTPUT && uiPinID==0) { if (!pMediaType) eStatus=MAI_STATUS_BADARG; else { MAIMediaTypeAudio_t *pAudioInfo=(MAIMediaTypeAudio_t *)pMediaType; /* clear the info structure */ memset(pAudioInfo, 0, sizeof(MAIMediaTypeAudio_t)); /* fill in Common MediaType fields */ pAudioInfo->MediaTypeInfo.uiSize=sizeof(MAIMediaTypeAudio_t); pAudioInfo->MediaTypeInfo.eMType=MAI_MTYPE_AUDIO; pAudioInfo->MediaTypeInfo.eMSubtype=MAI_MSUBTYPE_PCM; pAudioInfo->MediaTypeInfo.uiFlags=0; pAudioInfo->uiFlags = 0; /* init to no flags set */ if (pPInfo->m_uiProcessLoops) /* fill in audio format details if decoder is running */ { pAudioInfo->uiFlags = MAI_AUDIOMTFLAG_FORMATKNOWN; pAudioInfo->uiModeFlags = 0; /* init to no mode flags set */ pAudioInfo->uiSamplesPerSec = mpeg_decoder.decode_context.sample_rate; pAudioInfo->uiBitsPerSample = 16; pAudioInfo->uiChannels = mpeg_decoder.decode_context.nb_channels; pAudioInfo->uiMaxBufSize = 8192; } eStatus=MAI_STATUS_OK; } } return eStatus;}/********** Public Component interfaces - REQUIRED **********/#define _COMPCOUNT 1 /* just one component implemented here */static MAICompHandleInfo_t _CompTemplate[_COMPCOUNT] ={ { /* CompInfo #1 - MPEG Audio Decoder */ DECLARE_MAICOMPINFO( /* _eType */ MAICOMP_TYPE_DECODE|MAICOMP_TYPE_AUDIO, /* _uiCompVer */ 0x0001, /* _uiBuildVer */ BUILD_VERSION, /* _GUID */ MAICOMP_GUID(0x00, 0x10, 0xef, 0x00, 0x00, 0x00, 0x00, 0x15), /* _pszName */ "MPADEC", /* _pszDesc */ "MPEG Audio Decoder", /* _uiMaxInputs */ 1, /* _MaxOutputs */ 1, /* _MaxInstances */ 1, /* _uiFlags */ 0 ), /* CompHandle fields */ (pfMAICompErrorCB_t)0, /* pfMAICompErrorCB_t pfErrorCB */ (pfMAICompProgressCB_t)0, /* pfMAICompProgressCB_t pfProgressCB; */ MAICompInitInput, /* pfMAICompInitInput_t pfInitInput */ MAICompInitOutput, /* pfMAICompInitOutput_t pfInitOutput */ MAICompGetMediaType, /* pfMAICompGetMediaType_t pfGetMediaType */ MAICompGetParam, /* pfMAICompGetParam_t pfGetParam */ MAICompSetParam, /* pfMAICompSetParam_t pfSetParam */ MAICompStart, /* pfMAICompStart_t pfStart */ MAICompSendCommand, /* pfMAICompSendCommand_t pfSendCommand */ MAICompEnd, /* pfMAICompEnd_t pfEnd */ MAICompBase_SetErrorCB, /* pfMAICompSetErrorCB_t pfSetErrorCB */ MAICompBase_SetProgressCB, /* pfMAICompSetProgressCB_t pfSetProgressCB */ MAICompBase_GetState, /* pfMAICompGetState_t pfGetState */ (pfMAICompSetStream_t)0, /* pfMAICompSetStream_t pfSetStream */ (pfMAICompReserved_t)0, /* pfMAICompRead_t pfRead */ MAICompBase_ReadBuffer, /* pfMAICompReadBuffer_t pfReadBuffer */ MAICompBase_WriteBuffer, (pfMAICompReserved_t)0, (pfMAICompReserved_t)0, (pfMAICompReserved_t)0, (pfMAICompReserved_t)0, (pfMAICompReserved_t)0 }}; /* MAICompLibInit - initialize the MAI component library */PUBLIC_EXTERN MAIStatus_e MAICompLibInit(){ APIPRINTF((M_TEXT("MPADEC: MAICompLibInit\n"))); return MAICompBase_LibInit(_CompTemplate, _COMPCOUNT);}/* MAICompLibRelease - release the MAI component library */PUBLIC_EXTERN MAIStatus_e MAICompLibRelease(){ APIPRINTF((M_TEXT("MPADEC: MAICompLibRelease\n"))); return MAICompBase_LibRelease();}/* MAICompLibGetCount - return number of components implemented in this library */PUBLIC_EXTERN unsigned int MAICompLibGetCount(){ MAICompLibInit(); /* make sure lib has been initialized */ return MAICompBase_LibGetCount();}/* MAICompGetInfo - return info on a specific component */PUBLIC_EXTERN MAIStatus_e MAICompGetInfo(unsigned int uiCompIndex, MAICompInfo_t *pInfoOut){ MAICompLibInit(); /* make sure lib has been initialized */ return MAICompBase_CompGetInfo(uiCompIndex, pInfoOut);}/* MAICompCreate - create an instance of a specific component */PUBLIC_EXTERN MAIStatus_e MAICompCreate(unsigned char *pucGUID, MAICompHandle_t *phCompOut){ MAIStatus_e eStatus; MAICompHandle_t hComp=M_HANDLE_INVALID; MAICompLibInit(); /* make sure lib has been initialized */ eStatus=MAICompBase_CompCreate(pucGUID, sizeof(ProcessorInfo_t), &hComp); if (eStatus==MAI_STATUS_OK) { /* init private component info */ ProcessorInfo_t *pPInfo=(ProcessorInfo_t *)HCOMP_TO_USERINFO(hComp); /* return handle */ *phCompOut=(MAICompHandle_t)hComp; } return eStatus;}/* MAICompRelease - release an instance of a specific component */PUBLIC_EXTERN MAIStatus_e MAICompRelease(MAICompHandle_t hComp){ MAIStatus_e eStatus; APIPRINTF((M_TEXT("MPADEC: MAICompRelease\n"))); if (hComp!=M_HANDLE_INVALID) { ProcessorInfo_t *pPInfo=(ProcessorInfo_t *)HCOMP_TO_USERINFO(hComp); /* release private component info */ /* call base release */ eStatus=MAICompBase_CompRelease(hComp); } else eStatus=MAI_STATUS_BADHANDLE; return eStatus;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -