GetChunk() : reads n bytes from the elementary stream and places them

in a big buffer (a gift for Sam).
This commit is contained in:
Christophe Massiot 2000-12-19 19:55:35 +00:00
parent deff6eb9e7
commit 0661d2e7de
1 changed files with 45 additions and 0 deletions

View File

@ -361,6 +361,51 @@ static __inline__ void RealignBits( bit_stream_t * p_bit_stream )
}
/*
* Philosophy of the third implementation : the decoder asks for n bytes,
* and we will copy them in its buffer.
*/
/*****************************************************************************
* GetChunk : reads a large chunk of data
*****************************************************************************
* The position in the stream must be byte-aligned, if unsure call
* RealignBits(). p_buffer must to a buffer at least as big as i_buf_len
* otherwise your code will crash.
*****************************************************************************/
static __inline__ void GetChunk( bit_stream_t * p_bit_stream,
byte_t * p_buffer, size_t i_buf_len )
{
int i_available;
if( (i_available = p_bit_stream->p_end - p_bit_stream->p_byte)
>= i_buf_len )
{
memcpy( p_buffer, p_bit_stream->p_byte, i_buf_len );
p_bit_stream->p_byte += i_buf_len;
}
else
{
do
{
memcpy( p_buffer, p_bit_stream->p_byte, i_available );
p_bit_stream->p_byte = p_bit_stream->p_end;
p_buffer += i_available;
i_buf_len -= i_available;
p_bit_stream->pf_next_data_packet( p_bit_stream );
}
while( (i_available = p_bit_stream->p_end - p_bit_stream->p_byte)
<= i_buf_len );
if( i_buf_len )
{
memcpy( p_buffer, p_bit_stream->p_byte, i_buf_len );
p_bit_stream->p_byte += i_buf_len;
}
}
}
/*
* Communication interface between input and decoders
*/