📄 paac.c
字号:
free(aac_OutRight);
free(aac_OutLeft);
return (0);
}
///////////////////////////////////bitrate
RKFIO_FSeek(pRawFileCache, pAAC->ulLength / 2, SEEK_SET);
bytesLeft = 0;
eofReached = 0;
byte_1 = bytesLeft;
byte_2 = 0;
for (j = 0;j < 11;j++)
{
if (bytesLeft < AAC_MAX_NCHANS * AAC_MAINBUF_SIZE && !eofReached)
{
nRead = FillReadBuffer(readBuf, readPtr, READBUF_SIZE, bytesLeft, pRawFileCache);
bytesLeft += nRead;
readPtr = readBuf;
if (nRead == 0)
eofReached = 1;
}
byte_1 = bytesLeft;
err = AACDecode(hAACDecoder, &readPtr, &bytesLeft, outBuf);
if (j > 0)
{
byte_2 += byte_1 - bytesLeft;
time++;
}
if (err)
{
free(aac_OutRight);
free(aac_OutLeft);
return (0);
}
}
if (time != 0)
byte_2 = byte_2 / time;
/////////////////////////////////////////
//Get Frame Information
AACGetLastFrameInfo(hAACDecoder, &aacFrameInfo);
pAAC->ulTimePos = 0;
pAAC->usSampleRate = aacFrameInfo.sampRateOut;
pAAC->ucChannels = aacFrameInfo.nChans;
OutLength = (aacFrameInfo.outputSamps / aacFrameInfo.nChans);
if (aacFrameInfo.bitRate == 0)
aacFrameInfo.bitRate = (byte_2 * 8 * pAAC->usSampleRate / OutLength / 1000) * 1000;
pAAC->ulBitRate = aacFrameInfo.bitRate;
// pAAC->ulTimeLength =0;//单位为毫秒,nLengthMS的单位是毫秒
pAAC->ulTimeLength = ((((unsigned long long)pAAC->ulLength * 8) / pAAC->ulBitRate) * 1000) +
(((((unsigned long long)pAAC->ulLength * 8) % pAAC->ulBitRate) * 1000) /
pAAC->ulBitRate);
////////////////////////
bytesLeft = 0;
eofReached = 0;
RKFIO_FSeek(pRawFileCache, 0, SEEK_SET);
//initialize frame information
if (bytesLeft < AAC_MAX_NCHANS * AAC_MAINBUF_SIZE && !eofReached)
{
nRead = FillReadBuffer(readBuf, readPtr, READBUF_SIZE, bytesLeft, pRawFileCache);
bytesLeft += nRead;
readPtr = readBuf;
if (nRead == 0)
eofReached = 1;
}
err = AACDecode(hAACDecoder, &readPtr, &bytesLeft, outBuf);
if (err)
{
free(aac_OutRight);
free(aac_OutLeft);
return (0);
}
memset(outBuf, 0, sizeof(outBuf));
//success.
return 1;
}
// Decode a frame of data.
case SUBFN_CODEC_DECODE:
{
//OutLength=(-1);
tAAC *pAAC;
pAAC = (tAAC *)ulParam1;
/* somewhat arbitrary trigger to refill buffer - should always be enough for a full frame */
if (bytesLeft < AAC_MAX_NCHANS * AAC_MAINBUF_SIZE && !eofReached)
{
nRead = FillReadBuffer(readBuf, readPtr, READBUF_SIZE, bytesLeft, pRawFileCache);
bytesLeft += nRead;
readPtr = readBuf;
if (nRead == 0)
eofReached = 1;
}
if(VideoPlaying && eofReached) // added by hwg for 3gp
return 0;
/* decode one AAC frame */
err = AACDecode(hAACDecoder, &readPtr, &bytesLeft, outBuf);
/*error*/
if (err)
{
return (!err);
}
/* no error */
AACGetLastFrameInfo(hAACDecoder, &aacFrameInfo);
if (skipFrames == 0)
{
int i;
//short *p_tmp=PcmOutBuf.out_ptr;
#if 1
//为避免多声道歌曲产生问题
//只播放前两声道的内容
//NOTE: 尚未充分测试,有问题则使用#if 0 代码测试
//by Vincent Hisung.
short *p_tmp1, *p_tmp2;
p_tmp1 = aac_OutLeft;//AudioIOBuf.pOutLeft;
p_tmp2 = aac_OutRight;//AudioIOBuf.pOutRight;
if (tst < 6)
{
tst++;
memset(outBuf, 0, sizeof(outBuf));
}
OutLength = (aacFrameInfo.outputSamps / aacFrameInfo.nChans);
for (i = 0;i < aacFrameInfo.outputSamps;i += aacFrameInfo.nChans)
{
if (aacFrameInfo.nChans == 1)
{
*(p_tmp1++) = outBuf[i];
*(p_tmp2++) = outBuf[i];
}
else
{
//if ((i>>1)&0x1)
{
*(p_tmp1++) = outBuf[i];
*(p_tmp2++) = outBuf[i+1];
}
}
}
pAAC->ulTimePos += OutLength;
#else
short *p_tmp1, *p_tmp2;
p_tmp1 = aac_OutLeft;//AudioIOBuf.pOutLeft;
p_tmp2 = aac_OutRight;//AudioIOBuf.pOutRight;
if (aacFrameInfo.nChans == 2)
{
OutLength = (aacFrameInfo.outputSamps >> 1);
for (i = 0;i < aacFrameInfo.outputSamps;i++)
{
*(p_tmp1++) = outBuf[i];
i++;
*(p_tmp2++) = outBuf[i];
}
}
else
{
for (i = 0;i < aacFrameInfo.outputSamps;i++)
{
*(p_tmp1++) = outBuf[i];
*(p_tmp2++) = outBuf[i];
}
}
#endif
}
if (skipFrames != 0)
skipFrames--;
if (aacFrameInfo.tnsUsed)
{
nFramesTNSOn++;
}
else
{
nFramesTNSOff++;
}
if (nFramesTNSOn + nFramesTNSOff == MAX_FRAMES)
err = 1;
return(!err);
}
// Encode a frame of data.
case SUBFN_CODEC_ENCODE:
{
// We don't support encode, so return an error.
return(0);
}
/// Seek to the specified time position.
case SUBFN_CODEC_SEEK:
{
tAAC *pAAC;
unsigned long ulPos, ulFrameSize;
pAAC = (tAAC *)ulParam1;
ulFrameSize = (aacFrameInfo.outputSamps / aacFrameInfo.nChans);
bytesLeft = 0;
eofReached = 0;
if (ulFrameSize == 0)
return;
// Compute the number of frames that occur before the requested
// time position.
ulPos = (((ulParam2 / 1000) * pAAC->usSampleRate) /
ulFrameSize) +
(((ulParam2 % 1000) * pAAC->usSampleRate) /
(ulFrameSize * 1000));
// Compute the time for the computed frame number.
pAAC->ulTimePos = ulPos = ulPos * ulFrameSize;
// Compute the file position based on the actual seek time.
if (pAAC->usSampleRate)
{
ulPos = ((ulPos / pAAC->usSampleRate) *
(pAAC->ulBitRate / 8)) +
(((ulPos % pAAC->usSampleRate) *
(pAAC->ulBitRate / 8)) / pAAC->usSampleRate);
}
// Seek to the specified position.
if(!VideoPlaying)
RKFIO_FSeek(pRawFileCache, ulPos, SEEK_SET);
//reinitialize data for decoding
bytesLeft = 0;
eofReached = 0;
readPtr = readBuf;
err = 0;
nFramesTNSOn = 0;
nFramesTNSOff = 0;
return(1);
}
// Cleanup after the codec.
case SUBFN_CODEC_CLOSE:
{
AACFreeDecoder(hAACDecoder);
free(aac_OutRight);
free(aac_OutLeft);
// Success.
return(1);
}
// We should never get here, but just in case...
default:
{
// Return a failure.
return(0);
}
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -