📄 pmpeg4audio.c
字号:
}
if(pMP3->status != kDecoderStatus_NoError)
{
OSTimeDly(5);
return 1;
//return(0);
}
MPEG4FillBitstream(pMP3, 0);
if (!bitstreamDataToProcess) break;
pMP3->status = pMP3->workspace->Decoder->DecodeFrame( pMP3->workspace->handle,
pMP3->workspace->scratch,
&(pMP3->output),
&(pMP3->bitstream) );
if ( --MP4_Timer < 0 )
break;
}while(pMP3->status == kDecoderStatus_MoreSamples ||
(pMP3->status == kDecoderStatus_MoreData && bitstreamDataToProcess)||
pMP3->status != kDecoderStatus_NoError);
if(pMP3->status != kDecoderStatus_NoError)
{
OSTimeDly(5);
return 1;
// return(0);
}
lLength = pMP3->usSampleRate >= 32000 ? 1152 : 576;
// Increment the time based on the number of samples.
pMP3->ulTimePos = lLength * gAudioFrameNum;
BufferUpdateWritePointer(pMP3->pOutput, lLength,gPlugInSkip);
// If this frame was not discarded, then update the output buffer's
// write pointer.
// Update the output buffer's write pointer.
return(1);
}
else if( ulSubFn ==SUBFN_CODEC_OPEN_DEC)
{
unsigned long test;
long lLength=0;
tMP3 *pMP3;
// The first parameter is a pointer to the MP3 persistent state.
pMP3 = (tMP3 *)ulParam1;
ISFirst = 0;
gAudioFrameNum = 1;
// The first parameter is a pointer to the MP3 persistent state.
pMP3->workspace = &AudioDecoders[0];
pMP3->pmInstance = (tmInstance *)((unsigned long)pMP3 + sizeof(tMP3));
pMP3->pmScratch = (tmScratch *)((unsigned long)pMP3->pmInstance + sizeof(tmInstance));
test = (((unsigned long)pMP3->pmScratch + sizeof(tmScratch)) & 0xFFFF) ;
if(test > 0x9BC0)
//if(test > 0xB3C0) // 0x9bc0 + 0x1800 = 0xb3c0
{
return(0);
}
DynamicLoadMP3DEC();
#if 0
// added by Jeiff with codes which T.H wrote : start
////////////////////////////////////////////////////////////////////
pMP3->ulFirstFrame = ulParam2;
pMP3->ulBitRate = 128;
///////////////////////////////////////////////////////////////////////
// added by Jeiff : End
#else
// added by Jeiff with codes which T.H wrote : start
////////////////////////////////////////////////////////////////////
test = MPEG4_GetHeaderPosition(pMP3);
if(test == 0){
return 0;
}
///////////////////////////////////////////////////////////////////////
// added by Jeiff : End
#endif
pMP3->workspace->instancestate = pMP3->pmInstance;
pMP3->workspace->scratch = pMP3->pmScratch;
pMP3->workspace->formats->outputFormats = OUTPUT_FORMAT_16BIT | OUTPUT_FORMAT_CHANNEL_COUNT_MASK; // All channels
pMP3->workspace->formats->decoderFeatures = DECODER_FEATURE_NONE;
pMP3->status = pMP3->workspace->Decoder->DecoderRequirements( pMP3->workspace->Decoder->DecoderReference,
pMP3->workspace->requirements,
pMP3->workspace->formats );
if((pMP3->status == kDecoderStatus_NoError) || (pMP3->status == kDecoderStatus_UnsupportedFeature))
{
pMP3->workspace->handle = (oDecoderHandle *)pMP3->workspace->Decoder->DecoderCreate( pMP3->workspace->Decoder->DecoderReference,
pMP3->workspace->instancestate,
pMP3->workspace->scratch,
pMP3->workspace->formats );
}
pMP3->status = pMP3->workspace->Decoder->DecoderOpenBitstream(pMP3->workspace->handle,
pMP3->workspace->scratch,
&(pMP3->bitstream),
pMP3->workspace->formats);
bitstreamDataToProcess = -1;
// MPEG4_buffer_size = 1500;
MPEG4_buffer_size = GetOneFrameAudio(&AStreamBuf,pMP3->pcEncodedData, gAudioFrameNum);
pMP3->bitstream.data = pMP3->pcEncodedData; // buffer is global variable.
pMP3->bitstream.dataLength = MPEG4_buffer_size;
pMP3->bitstream.dataOffset = 0;
pMP3->bitstream.dataRequired = 0;
// added by THKIM 03.11.2004
test = 1024;
do
{
MPEG4FillBitstream(pMP3, 0);
if (!bitstreamDataToProcess) break;
pMP3->status = pMP3->workspace->Decoder->DecodeHeader( pMP3->workspace->handle,
pMP3->workspace->scratch,
&(pMP3->bitstream));
if( --test == 0 )
break;
}
while ( (pMP3->status != kDecoderStatus_NoError && bitstreamDataToProcess) );
if(pMP3->status != 0)
{
return(0);
}
if(!bitstreamDataToProcess){
return(1);
}
if(pMP3->status == kDecoderStatus_NoError) MPEG4FirstHeaderDecoded = 1;
// added by Jeiff 02.06.2004
//////////////////////////////////////////////////
MPEG4_sp = pMP3->bitstream.sampleRate;
MPEG4_BR = pMP3->bitstream.bitRate;
lLength = pMP3->bitstream.sampleRate >= 32000 ? 1152 : 576;
pMP3->ulLength = lLength * gAudioTotalFrame;
pMP3->ulBitRate = (unsigned long)pMP3->bitstream.bitRate;
pMP3->usSampleRate = (unsigned short)(pMP3->bitstream.sampleRate);
pMP3->ucChannels = (unsigned char)pMP3->bitstream.channels.total;
pMP3->output.channelsRequired = NULL;
pMP3->output.numberOfChannels = (unsigned int)pMP3->bitstream.channels.total;
pMP3->output.maxNumberOfSamples = (unsigned int)pMP3->workspace->requirements->maxOutputSize;
pMP3->output.channels = pMP3->buffer_ptr;
pMP3->ulTimeLength = (((pMP3->ulLength * 8) / pMP3->ulBitRate) * 1000) +
((((pMP3->ulLength * 8) % pMP3->ulBitRate) * 1000) /
pMP3->ulBitRate);
pMP3->ulTimePos = 0;
pMP3->pOutput = 0;
// gAudioFrameNum = 1;
return(1);
}
// Return the current position (in milliseconds) within the file.
else if( ulSubFn == SUBFN_CODEC_GETTIME)
{
unsigned long *pulTime;
tMP3 *pMP3;
// The first parameter is a pointer to the MP3 persistent state.
pMP3 = (tMP3 *)ulParam1;
// The second parameter is a pointer for the number of seconds.
pulTime = (unsigned long *)ulParam2;
// Determine the time based on the sample rate.
*pulTime = ((pMP3->ulTimePos / pMP3->usSampleRate) * 1000) +
(((pMP3->ulTimePos % pMP3->usSampleRate) * 1000) /
pMP3->usSampleRate);
// Success.
return(1);
}
// Return the sample rate at which this file is encoded.
else if( ulSubFn == SUBFN_CODEC_GETSAMPLERATE)
{
unsigned long *pulSampleRate;
tMP3 *pMP3;
// The first parameter is a pointer to the MP3 persistent state.
pMP3 = (tMP3 *)ulParam1;
pulSampleRate = (unsigned long *)ulParam2;
// Return the sample rate of the file.
*pulSampleRate = pMP3->usSampleRate;
// Success.
return(1);
}
// Return the number of channels in the file.
else if( ulSubFn == SUBFN_CODEC_GETCHANNELS)
{
unsigned long *pulChannels;
tMP3 *pMP3;
// The first parameter is a pointer to the MP3 persistent state.
pMP3 = (tMP3 *)ulParam1;
pulChannels = (unsigned long *)ulParam2;
// Return the number of channels in the file.
*pulChannels = pMP3->ucChannels;
// Success.
return(1);
}
// Return the bitrate at which this file is encoded.
else if( ulSubFn == SUBFN_CODEC_GETBITRATE)
{
unsigned long *pulBitRate;
tMP3 *pMP3;
// The first parameter is a pointer to the MP3 persistent state.
pMP3 = (tMP3 *)ulParam1;
pulBitRate = (unsigned long *)ulParam2;
// Return the number of channels in the file.
*pulBitRate = pMP3->ulBitRate;
// Success.
return(1);
}
// Return the length (in milliseconds) of the file.
else if( ulSubFn == SUBFN_CODEC_GETLENGTH)
{
unsigned long *pulLength;
tMP3 *pMP3;
// The first parameter is a pointer to the MP3 persistent state.
pMP3 = (tMP3 *)ulParam1;
pulLength = (unsigned long *)ulParam2;
// Return the length of the file.
*pulLength = pMP3->ulTimeLength;
// Success.
return(1);
}
// Set the output buffer for the decoder.
else if( ulSubFn == SUBFN_CODEC_SETBUFFER)
{
tMP3 *pMP3;
// The first parameter is a pointer to the MP3 persistent state.
pMP3 = (tMP3 *)ulParam1;
// The second parameter is a pointer to the output buffer.
pMP3->pOutput = (BufferState *)ulParam2;
if(gMpegMode == 1)
{
// Provide the output buffer with our data buffers.
if(pMP3->ucChannels == 2)
{
BufferSetBuffer(pMP3->pOutput, pMP3->psLeft, pMP3->psRight,
MP3_MAX_PCM_LENGTH + MP3_MAX_PCM_LENGTH);
}
else
{
BufferSetBuffer(pMP3->pOutput, pMP3->psLeft, pMP3->psLeft,
MP3_MAX_PCM_LENGTH + MP3_MAX_PCM_LENGTH);
}
}
else
{
// Provide the output buffer with our data buffers.
if(pMP3->ucChannels == 2)
{
BufferSetBuffer(pMP3->pOutput, pMP3->psLeft, pMP3->psRight,
MP3_MAX_PCM_LENGTH);
}
else
{
BufferSetBuffer(pMP3->pOutput, pMP3->psLeft, pMP3->psLeft,
MP3_MAX_PCM_LENGTH);
}
}
// Success.
return(1);
}
else if( ulSubFn == SUBFN_CODEC_GETCAPTUREBUFFER)
{
tMP3 *pMP3;
short **ppsBuffer;
long *plLength;
// The first parameter is a pointer to the MP3 persistent state.
pMP3 = (tMP3 *)ulParam1;
ppsBuffer = (short **)ulParam2;
plLength = (long *)ulParam3;
*ppsBuffer = pMP3->psRight;
*plLength = MP3_MAX_PCM_LENGTH * 2;
//success
return(1);
}
else if( ulSubFn == SUBFN_CODEC_CLOSE)
{
tMP3 *pMP3;
ISFirst = 0;
// The first parameter is a pointer to the MP3 persistent state.
pMP3 = (tMP3 *)ulParam1;
pMP3->status = pMP3->workspace->Decoder->DecoderDestroy(pMP3->workspace->handle, pMP3->workspace->scratch);
if(pMP3->status == kDecoderStatus_NoError) return(1);
else return(0);
return(1);
}
else
{
// Return a failure.
return(0);
}
return 1;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -