Justin H.
Justin H.

Reputation: 143

libfdk_aac not reading into buffer

I am trying to decode an AAC encoded file using libfdk_aac. The file consists of a stream of raw AAC-LC ADTS packets that were generated using libfdk_aac. I'm sure the data is well formed because I can play the file using VLC and Window Media Player.

Here's my setup:

UCHAR* inputBuffer = new UCHAR[ 2048 ] ;
UINT bufSize[] = { 0 } ;

INT_PCM* outputBuffer = new INT_PCM[ 4096 ] ;
int outputbufSize = 8192 ;
UINT flags = 0 ;

//Set up the Audio Specific Config
UCHAR* asc = new UCHAR[ 2 ] ;
asc[ 0 ] = (UCHAR) 0x11 ;
asc[ 1 ] = (UCHAR) 0x90 ;
UINT ascSize[] = { 2 } ;

HANDLE_DECODER decoder = aacDecoder_Open( TT_MP4_ADTS, 1 ) ;
AAC_DECODER_ERROR aacError = aacDecoder_ConfigRaw( decoder, &asc, ascSize ) ;
if( aacError )
{
   printf( "Configure error\n" ) ;
   exit( -1 ) ;
}

int dataAvailable = 1 ;
do
{
   //Reads the file and gets the next ADTS packet with one AAC frame
   unsigned int adtsPacketSize ;
   dataAvailable = readMPEGFile( filePtr, inputBuffer, &adtsPacketSize ) ;
   bufSize[ 0 ] = adtsPacketSize ;

   aacError = aacDecoder_Fill( decoder, &inputBuffer, bufSize, &bytesValid ) ;
   //Check to see if bytesValid == 0
   //If bytesValid > 0, keep calling aacDecoder_Fill()

   //If bytesValid == 0, decode audio
   aacError = aacDecoder_DecodeFrame( decoder, outputBuffer, outputBufSize, flags ) ;

   //If no error, write raw PCM data to file.
}while( dataAvailable ) ;

The problem is that aacDecoder_DecodeFrame continues to return with AAC_DEC_NOT_ENOUGH_BITS. Calls to aacDecoder_GetFreeBytes() shows that the internal buffer is not getting any of the input data. Any ideas on why this is happening?

Upvotes: 2

Views: 1014

Answers (1)

Jagger Yu
Jagger Yu

Reputation: 647

bytesValid should equal to bufSize in every loop.

Upvotes: 0

Related Questions