📄 mp3_demux.cpp
字号:
if( configInfo->ulInputSize > 0 )
{
configInfo->pbInputData += 1;
configInfo->ulInputSize -= 1;
}
}
}
if( fPrintDebug == TRUE )
{
DbgPrint(("MP3_GetHeader:Header back in sync %d\n", (int)ulMP3FrameCount));
}
return( fRet );
} /* end MP3_GetHeader() */
/************************************************************************/
/************************************************************************/
/** **/
/************************************************************************/
/************************************************************************/
BOOLEAN MP3_GetFrameSize( MP3DEMUXINFO *configInfo )
{
configInfo->ulFrameSize = ulMP3Tabsel_123[0][2][configInfo->tMP3Header.ulBitRate] * 144000;
configInfo->ulFrameSize /= ulMP3Freqs[configInfo->tMP3Header.ulSampleFreq];
configInfo->ulFrameSize += configInfo->tMP3Header.ulPadding;
configInfo->ulFrameSize -= 4;
return( MP3_SUCCESS );
} /* end MP3_GetFrameSize() */
/************************************************************************/
/************************************************************************/
/** **/
/************************************************************************/
/************************************************************************/
BOOLEAN MP3_GetFrameData( MP3DEMUXINFO *configInfo )
{
BYTE *pbDestin = NULL;
BYTE *pbSource = NULL;
// DbgPrint(("MP3_GetFrameData:begin %d %d\n", configInfo->ulFrameSize, configInfo->ulInputSize));
if( configInfo->ulFrameSize > configInfo->ulInputSize )
{
//
// The MP3 frame spans across two payloads. Pack the frame data into
// the front of the first payload
//
configInfo->ptFramePayload = configInfo->messInput->payload->REF_PAYLOAD;
pbSource = (BYTE *)configInfo->ptFramePayload->get_base_ptr();
configInfo->ptFramePayload->set_rd_ptr( (PVOID)pbSource );
pbSource += configInfo->ulFrameSize;
configInfo->ptFramePayload->set_wr_ptr( (PVOID)pbSource );
pbDestin = (BYTE *)KSEG1( configInfo->ptFramePayload->get_rd_ptr() );
pbSource = (BYTE *)KSEG1( configInfo->pbInputData );
memcpy( pbDestin, pbSource, configInfo->ulInputSize );
pbDestin += configInfo->ulInputSize;
configInfo->ulFrameSize -= configInfo->ulInputSize;
configInfo->ulInputSize = 0;
MP3_GetValidPacket( configInfo, __LINE__ );
pbSource = (BYTE *)KSEG1( configInfo->pbInputData );
memcpy( pbDestin, pbSource, configInfo->ulFrameSize );
configInfo->pbInputData += configInfo->ulFrameSize;
configInfo->ulInputSize -= configInfo->ulFrameSize;
}
else
{
//Save the current pointers
configInfo->pbData = configInfo->pbInputData;
configInfo->ulSize = configInfo->ulFrameSize;
configInfo->ptFramePayload = configInfo->messInput->payload->REF_PAYLOAD;
configInfo->ptFramePayload->set_rd_ptr( (PVOID)KSEG1( configInfo->pbData ) );
configInfo->ptFramePayload->set_wr_ptr( (PVOID)KSEG1( configInfo->pbData + configInfo->ulFrameSize ) );
//Update the local pointers
configInfo->pbInputData += configInfo->ulFrameSize;
configInfo->ulInputSize -= configInfo->ulFrameSize;
}
// OS_TaskDelay(1);
return( MP3_SUCCESS );
} /* end MP3_GetFrameData() */
/************************************************************************/
/************************************************************************/
/** **/
/************************************************************************/
/************************************************************************/
void MP3_SendData( MP3DEMUXINFO *configInfo )
{
DEMUXOUTPUTMESSAGE *pOutMessage;
// DbgPrint(("MP3_SendData:begin 0x%08x\n", (ULONG)configInfo->ptFramePayload->get_rd_ptr() ));
/* Grab an empty message from the output pin */
do
{
pOutMessage = (DEMUXOUTPUTMESSAGE *)configInfo->tOutputPin.pDestStream->GetMsg();
if( pOutMessage == NULL )
{
OS_TaskDelay(OS_WAIT_1S / 50);
}
} while( pOutMessage == NULL );
/* Load the empty message with a pointer to the payload and its length */
pOutMessage->payload = configInfo->ptFramePayload;
pOutMessage->Encryption = NONE;
memcpy( (BYTE *)&pOutMessage->pvMp3Hdr, (BYTE *)&configInfo->tMP3Header, 4 );
/* Send the message to the output pin */
configInfo->tOutputPin.pDestStream->Write( (PVOID)pOutMessage, OS_WAIT_FOREVER );
} /* end MP3_SendData() */
/************************************************************************/
/************************************************************************/
/** **/
/** procedure MP3DemuxGetErrorCnt() **/
/** **/
/** PURPOSE: To return the current error count. **/
/** **/
/************************************************************************/
/************************************************************************/
ULONG MP3DemuxGetErrorCnt( void )
{
return( ulMP3DemuxErrorCnt );
} /* end MP3DemuxGetErrorCnt() */
/************************************************************************/
/************************************************************************/
/** **/
/************************************************************************/
/************************************************************************/
void MP3FlushPayload( void )
{
DEMUXIOSTREAM *pInputPin = NULL;
DEMUXINPUTMESSAGE *pInMessage = NULL;
DbgPrint(("MP3FlushPayload:begin\n"));
pInputPin = tDemuxInfo.tConfigInfo.tInputPin;
if( pInputPin != NULL )
{
//Remove the current payload
if( tDemuxInfo.messInput != NULL )
{
//Delete the payload
delete (DEMUXPAYLOAD *)tDemuxInfo.messInput->payload;
tDemuxInfo.messInput->payload = NULL;
//Delete the message
pInputPin->ReleaseMsg( tDemuxInfo.messInput );
tDemuxInfo.messInput = NULL;
}
//Remove any queued payloads
pInMessage = (DEMUXINPUTMESSAGE *)pInputPin->Remove();
while( pInMessage != NULL )
{
//Delete the payload if any
if( pInMessage->payload != NULL )
{
delete (DEMUXPAYLOAD *)pInMessage->payload;
pInMessage->payload = NULL;
}
//Delete the message
pInputPin->ReleaseMsg( pInMessage );
pInMessage = NULL;
//Check for another
pInMessage = (DEMUXINPUTMESSAGE *)pInputPin->Remove();
} /* end while( pInMessage != NULL ) */
} /* end if( pInputPin != NULL ) */
DbgPrint(("MP3FlushPayload:end\n"));
} /* end MP3FlushPayload() */
/************************************************************************/
/************************************************************************/
/** **/
/** MP3 Demux Thread **/
/** **/
/************************************************************************/
/************************************************************************/
/**
* MP3DemuxThreadProc Function. Implements the state machine of the MP3
* Demux.
*
* @param
* PVOID pvDemuxInfo - Demux information
*
* @retval
* None.
*
* @remark
* None.
*
* @verified
* No.
*/
ULONG MP3DemuxThreadProc( PVOID pvDemuxInfo )
{
MP3DEMUXINFO *pDemuxInfo;
/* Initialization */
DbgPrint(("MP3DemuxThreadProc: Begin 0x%08x\n", (int)pvDemuxInfo));
/* Clear the error count */
ulMP3DemuxErrorCnt = 0;
ulMP3FrameCount = 0;
/* Save the pointer to the demux configuration record */
pDemuxInfo = &tDemuxInfo;
pDemuxInfo->pDynamicConfigInfo = (DEMUXCONFIGINFO *)pvDemuxInfo;
/* Initialize and wait until there is an input payload */
MP3_DemuxInit( pDemuxInfo );
do
{
OS_TaskDelay( OS_WAIT_1S / 100 );
MP3_DemuxUpdate( pDemuxInfo );
} while( (MP3_GetValidPacket( pDemuxInfo, __LINE__ ) == MP3_FAILURE) );
DbgPrint(("MP3DemuxThreadProc: ready to process\n"));
//Loop here forever and consume the input
while( 1 )
{
switch( pDemuxInfo->ulDemuxState )
{
case MP3_HEADER:
if( MP3_GetHeader( pDemuxInfo ) == MP3_SUCCESS )
{
pDemuxInfo->ulDemuxState = MP3_DATA;
ulMP3FrameCount++;
}
break;
case MP3_DATA:
if( MP3_GetFrameSize( pDemuxInfo ) == MP3_SUCCESS )
{
MP3_GetFrameData( pDemuxInfo );
if( pDemuxInfo->tOutputPin.pDestStream != NULL )
{
MP3_SendData( pDemuxInfo );
}
else
{
delete pDemuxInfo->ptFramePayload;
}
}
pDemuxInfo->ulDemuxState = MP3_HEADER;
break;
default:
break;
}
#if 0
// DbgPrint(("MP3DemuxThreadProc:Wait for data\n"));
//Dummy delay
OS_TaskDelay( OS_WAIT_1S / 100 );
// DbgPrint(("MP3DemuxThreadProc:Delete data\n"));
//Delete the packet
delete (DEMUXPAYLOAD *)pDemuxInfo->messInput->payload;
pDemuxInfo->messInput->payload = NULL;
pDemuxInfo->tConfigInfo.tInputPin->ReleaseMsg( pDemuxInfo->messInput );
pDemuxInfo->messInput = NULL;
MP3_DemuxUpdate( pDemuxInfo );
//Wait for a data packet
while( MP3_GetValidPacket( pDemuxInfo, __LINE__) == MP3_FAILURE )
{
OS_TaskDelay(OS_WAIT_1S / 50);
}
#endif
}
DbgPrint(("MP3DemuxThreadProc: End\n"));
} /* end MP3DemuxThreadProc() */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -