Commit 525c7039 authored by Laurent Aimar's avatar Laurent Aimar

* adpcm: changed the way that data are read and thus seek will work.

parent 23ba8c3e
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* adpcm.c : adpcm variant audio decoder * adpcm.c : adpcm variant audio decoder
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * Copyright (C) 2001, 2002 VideoLAN
* $Id: adpcm.c,v 1.5 2003/01/07 21:49:01 fenrir Exp $ * $Id: adpcm.c,v 1.6 2003/01/13 17:39:05 fenrir Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -48,12 +48,13 @@ typedef struct adec_thread_s ...@@ -48,12 +48,13 @@ typedef struct adec_thread_s
WAVEFORMATEX *p_wf; WAVEFORMATEX *p_wf;
/* The bit stream structure handles the PES stream at the bit level */
bit_stream_t bit_stream;
int i_block; int i_block;
uint8_t *p_block; uint8_t *p_block;
int i_samplesperblock; int i_samplesperblock;
uint8_t *p_buffer; /* buffer for gather pes */ \
int i_buffer; /* bytes present in p_buffer */
/* Input properties */ /* Input properties */
decoder_fifo_t *p_fifo; decoder_fifo_t *p_fifo;
...@@ -266,7 +267,7 @@ static int InitThread( adec_thread_t * p_adec ) ...@@ -266,7 +267,7 @@ static int InitThread( adec_thread_t * p_adec )
"block size undefined, using %d default", "block size undefined, using %d default",
p_adec->i_block ); p_adec->i_block );
} }
p_adec->p_block = malloc( p_adec->i_block ); p_adec->p_block = NULL;
/* calculate samples per block */ /* calculate samples per block */
switch( p_adec->i_codec ) switch( p_adec->i_codec )
...@@ -320,27 +321,90 @@ static int InitThread( adec_thread_t * p_adec ) ...@@ -320,27 +321,90 @@ static int InitThread( adec_thread_t * p_adec )
} }
/* Init the BitStream */ /* Init the BitStream */
InitBitstream( &p_adec->bit_stream, p_adec->p_fifo, // InitBitstream( &p_adec->bit_stream, p_adec->p_fifo,
NULL, NULL ); // NULL, NULL );
return( 0 ); return( 0 );
} }
static void GetPESData( uint8_t *p_buf, int i_max, pes_packet_t *p_pes )
{
int i_copy;
int i_count;
data_packet_t *p_data;
i_count = 0;
p_data = p_pes->p_first;
while( p_data != NULL && i_count < i_max )
{
i_copy = __MIN( p_data->p_payload_end - p_data->p_payload_start,
i_max - i_count );
if( i_copy > 0 )
{
memcpy( p_buf,
p_data->p_payload_start,
i_copy );
}
p_data = p_data->p_next;
i_count += i_copy;
p_buf += i_copy;
}
if( i_count < i_max )
{
memset( p_buf, 0, i_max - i_count );
}
}
/***************************************************************************** /*****************************************************************************
* DecodeThread: decodes a frame * DecodeThread: decodes a frame
*****************************************************************************/ *****************************************************************************/
static void DecodeThread( adec_thread_t *p_adec ) static void DecodeThread( adec_thread_t *p_adec )
{ {
aout_buffer_t *p_aout_buffer; aout_buffer_t *p_aout_buffer;
pes_packet_t *p_pes;
/* get pts */ int i_frame_size;
CurrentPTS( &p_adec->bit_stream, &p_adec->pts, NULL );
/* gather block */
GetChunk( &p_adec->bit_stream,
p_adec->p_block,
p_adec->i_block );
/* **** Get a new frames from streams **** */
do
{
input_ExtractPES( p_adec->p_fifo, &p_pes );
if( !p_pes )
{
p_adec->p_fifo->b_error = 1;
return;
}
if( p_pes->i_pts != 0 )
{
p_adec->pts = p_pes->i_pts;
}
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 );
}
input_DeletePES( p_adec->p_fifo->p_packets_mgt, p_pes );
} while( i_frame_size <= 0 );
for( p_adec->p_block = p_adec->p_buffer;
i_frame_size >= p_adec->i_block;
p_adec->p_block += p_adec->i_block, i_frame_size -= p_adec->i_block )
{
/* get output buffer */ /* get output buffer */
if( p_adec->pts != 0 && p_adec->pts != aout_DateGet( &p_adec->date ) ) if( p_adec->pts != 0 && p_adec->pts != aout_DateGet( &p_adec->date ) )
{ {
...@@ -350,6 +414,7 @@ static void DecodeThread( adec_thread_t *p_adec ) ...@@ -350,6 +414,7 @@ static void DecodeThread( adec_thread_t *p_adec )
{ {
return; return;
} }
p_adec->pts = 0;
p_aout_buffer = aout_DecNewBuffer( p_adec->p_aout, p_aout_buffer = aout_DecNewBuffer( p_adec->p_aout,
p_adec->p_aout_input, p_adec->p_aout_input,
...@@ -384,6 +449,7 @@ static void DecodeThread( adec_thread_t *p_adec ) ...@@ -384,6 +449,7 @@ static void DecodeThread( adec_thread_t *p_adec )
/* **** Now we can output these samples **** */ /* **** Now we can output these samples **** */
aout_DecPlay( p_adec->p_aout, p_adec->p_aout_input, p_aout_buffer ); aout_DecPlay( p_adec->p_aout, p_adec->p_aout_input, p_aout_buffer );
}
} }
...@@ -399,7 +465,7 @@ static void EndThread (adec_thread_t *p_adec) ...@@ -399,7 +465,7 @@ static void EndThread (adec_thread_t *p_adec)
msg_Dbg( p_adec->p_fifo, "adpcm audio decoder closed" ); msg_Dbg( p_adec->p_fifo, "adpcm audio decoder closed" );
free( p_adec->p_block ); FREE( p_adec->p_buffer );
free( p_adec ); free( p_adec );
} }
#define CLAMP( v, min, max ) \ #define CLAMP( v, min, max ) \
......
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