Commit cdde2391 authored by Laurent Aimar's avatar Laurent Aimar

* all: new way to gather frame (same as ffmpeg).

parent 3a68b7ea
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* decoder.c: AAC decoder using libfaad2 * decoder.c: AAC decoder using libfaad2
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * Copyright (C) 2001, 2002 VideoLAN
* $Id: decoder.c,v 1.9 2002/10/27 17:23:17 titer Exp $ * $Id: decoder.c,v 1.10 2002/10/27 18:06:33 fenrir Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -148,74 +148,39 @@ static void faac_GetWaveFormatEx( waveformatex_t *p_wh, ...@@ -148,74 +148,39 @@ static void faac_GetWaveFormatEx( waveformatex_t *p_wh,
} }
} }
static inline void __GetFrame( adec_thread_t *p_adec ) static void GetPESData( u8 *p_buf, int i_max, pes_packet_t *p_pes )
{ {
pes_packet_t *p_pes; int i_copy;
int i_count;
data_packet_t *p_data; data_packet_t *p_data;
byte_t *p_buffer;
input_ExtractPES( p_adec->p_fifo, &p_pes ); i_count = 0;
if( !p_pes ) p_data = p_pes->p_first;
while( p_data != NULL && i_count < i_max )
{ {
p_adec->p_framedata = NULL;
return;
}
if( p_pes->i_pts ) i_copy = __MIN( p_data->p_payload_end - p_data->p_payload_start,
{ i_max - i_count );
p_adec->pts = p_pes->i_pts;
}
while( ( !p_pes->i_nb_data )||( !p_pes->i_pes_size ) ) if( i_copy > 0 )
{ {
input_DeletePES( p_adec->p_fifo->p_packets_mgt, p_pes ); memcpy( p_buf,
input_ExtractPES( p_adec->p_fifo, &p_pes ); p_data->p_payload_start,
if( !p_pes ) i_copy );
{
p_adec->p_framedata = NULL;
return;
}
}
p_adec->i_framesize = p_pes->i_pes_size;
if( p_pes->i_nb_data == 1 )
{
p_adec->p_framedata = p_pes->p_first->p_payload_start;
return;
}
/* get a buffer and gather all data packet */
if( p_adec->i_buffer_size < p_pes->i_pes_size )
{
p_adec->i_buffer_size = 3 * p_pes->i_pes_size / 2;
if( p_adec->p_buffer )
{
p_adec->p_buffer = realloc( p_adec->p_buffer,
p_adec->i_buffer_size );
}
else
{
p_adec->p_buffer = malloc( p_adec->i_buffer_size );
}
} }
p_buffer = p_adec->p_framedata = p_adec->p_buffer;
p_data = p_pes->p_first;
do
{
p_adec->p_fifo->p_vlc->pf_memcpy( p_buffer, p_data->p_payload_start,
p_data->p_payload_end - p_data->p_payload_start );
p_buffer += p_data->p_payload_end - p_data->p_payload_start;
p_data = p_data->p_next; p_data = p_data->p_next;
} while( p_data ); i_count += i_copy;
p_buf += i_copy;
input_DeletePES( p_adec->p_fifo->p_packets_mgt, p_pes ); }
}
static inline void __NextFrame( adec_thread_t *p_adec ) if( i_count < i_max )
{ {
input_ExtractPES( p_adec->p_fifo, NULL ); memset( p_buf, 0, i_max - i_count );
}
} }
/***************************************************************************** /*****************************************************************************
* InitThread: initialize data before entering main loop * InitThread: initialize data before entering main loop
*****************************************************************************/ *****************************************************************************/
...@@ -238,6 +203,10 @@ static int InitThread( adec_thread_t * p_adec ) ...@@ -238,6 +203,10 @@ static int InitThread( adec_thread_t * p_adec )
(u8*)p_adec->p_fifo->p_demux_data ); (u8*)p_adec->p_fifo->p_demux_data );
} }
p_adec->p_buffer = NULL;
p_adec->i_buffer = 0;
if( !( p_adec->p_handle = faacDecOpen() ) ) if( !( p_adec->p_handle = faacDecOpen() ) )
{ {
msg_Err( p_adec->p_fifo, msg_Err( p_adec->p_fifo,
...@@ -248,16 +217,43 @@ static int InitThread( adec_thread_t * p_adec ) ...@@ -248,16 +217,43 @@ static int InitThread( adec_thread_t * p_adec )
if( !p_adec->format.p_data ) if( !p_adec->format.p_data )
{ {
int i_frame_size;
pes_packet_t *p_pes;
msg_Warn( p_adec->p_fifo, msg_Warn( p_adec->p_fifo,
"DecoderSpecificInfo missing, trying with first frame" ); "DecoderSpecificInfo missing, trying with first frame" );
__GetFrame( p_adec ); // gather first frame
do
{
input_ExtractPES( p_adec->p_fifo, &p_pes );
if( !p_pes )
{
return( -1 );
}
i_frame_size = p_pes->i_pes_size;
if( i_frame_size > 0 )
{
if( p_adec->i_buffer < i_frame_size + 16 )
{
FREE( p_adec->p_buffer );
p_adec->p_buffer = malloc( i_frame_size + 16 );
p_adec->i_buffer = i_frame_size + 16;
}
GetPESData( p_adec->p_buffer, p_adec->i_buffer, p_pes );
}
else
{
input_DeletePES( p_adec->p_fifo->p_packets_mgt, p_pes );
}
} while( i_frame_size <= 0 );
i_status = faacDecInit( p_adec->p_handle, i_status = faacDecInit( p_adec->p_handle,
p_adec->p_framedata, p_adec->p_buffer,
&i_rate, &i_rate,
&i_channels ); &i_channels );
// __NextFrame( p_adec );
} }
else else
{ {
...@@ -294,16 +290,7 @@ static int InitThread( adec_thread_t * p_adec ) ...@@ -294,16 +290,7 @@ static int InitThread( adec_thread_t * p_adec )
p_adec->p_aout = NULL; p_adec->p_aout = NULL;
p_adec->p_aout_input = NULL; p_adec->p_aout_input = NULL;
#if 0 p_adec->pts = 0;
if( !p_adec->format.p_data )
{
/* Init the BitStream */
InitBitstream( &p_adec->bit_stream, p_adec->p_fifo,
NULL, NULL );
p_adec->p_framedata = malloc( AAC_MAXCHANNELS * FAAD_MIN_STREAMSIZE );
p_adec->i_framesize = 0;
}
#endif
return( 0 ); return( 0 );
} }
...@@ -321,58 +308,42 @@ static void DecodeThread( adec_thread_t *p_adec ) ...@@ -321,58 +308,42 @@ static void DecodeThread( adec_thread_t *p_adec )
void *p_faad_buffer; void *p_faad_buffer;
faacDecFrameInfo faad_frame; faacDecFrameInfo faad_frame;
int i_frame_size;
pes_packet_t *p_pes;
/* **** Get a new frames from streams **** */ /* **** Get a new frames from streams **** */
__GetFrame( p_adec ); do
{
/* **** decode this frame **** */ input_ExtractPES( p_adec->p_fifo, &p_pes );
p_faad_buffer = faacDecDecode( p_adec->p_handle, if( !p_pes )
&faad_frame, {
p_adec->p_framedata ); p_adec->p_fifo->b_error = 1;
/* **** switch to the next frame **** */ return;
__NextFrame( p_adec ); }
if( p_pes->i_pts != 0 )
{
p_adec->pts = p_pes->i_pts;
}
i_frame_size = p_pes->i_pes_size;
#if 0 if( i_frame_size > 0 )
/*
* XXX don't work ! XXX
*
* first even without format.p_data stream can be frame based
* and it make libfaad segfault
*
*/
if( p_adec->format.p_data )
{ {
__GetFrame( p_adec ); if( p_adec->i_buffer < i_frame_size + 16 )
/* Now decode data */ {
p_faad_buffer = faacDecDecode( p_adec->p_handle, FREE( p_adec->p_buffer );
&faad_frame, p_adec->p_buffer = malloc( i_frame_size + 16 );
p_adec->p_framedata ); p_adec->i_buffer = i_frame_size + 16;
__NextFrame( p_adec ); }
GetPESData( p_adec->p_buffer, p_adec->i_buffer, p_pes );
} }
else input_DeletePES( p_adec->p_fifo->p_packets_mgt, p_pes );
{ } while( i_frame_size <= 0 );
int i_count;
/* fill buffer */ /* **** decode this frame **** */
i_count = __MAX( 1, p_adec->output_format.i_channels ) * FAAD_MIN_STREAMSIZE -
p_adec->i_framesize;
GetChunk( &p_adec->bit_stream,
p_adec->p_framedata + p_adec->i_framesize,
i_count );
p_adec->i_framesize += i_count;
p_faad_buffer = faacDecDecode( p_adec->p_handle, p_faad_buffer = faacDecDecode( p_adec->p_handle,
&faad_frame, &faad_frame,
p_adec->p_framedata ); p_adec->p_buffer );
/* update data buffer pos */
i_count = __MIN( p_adec->i_framesize,
__MAX( 1, faad_frame.bytesconsumed ) );
memcpy( p_adec->p_framedata,
p_adec->p_framedata + i_count,
p_adec->i_framesize - i_count );
p_adec->i_framesize -= i_count;
}
#endif
/* **** some sanity checks to see if we have samples to out **** */ /* **** some sanity checks to see if we have samples to out **** */
if( faad_frame.error > 0 ) if( faad_frame.error > 0 )
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 2001 VideoLAN * Copyright (C) 2001 VideoLAN
* $Id: decoder.h,v 1.3 2002/10/20 17:44:17 fenrir Exp $ * $Id: decoder.h,v 1.4 2002/10/27 18:06:33 fenrir Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -55,10 +55,9 @@ typedef struct adec_thread_s ...@@ -55,10 +55,9 @@ typedef struct adec_thread_s
*/ */
decoder_fifo_t *p_fifo; decoder_fifo_t *p_fifo;
u8 *p_framedata;
int i_framesize;
u8 *p_buffer; u8 *p_buffer;
int i_buffer_size; int i_buffer;
/* /*
* Output properties * Output properties
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment