Commit c751bb66 authored by Christophe Massiot's avatar Christophe Massiot

* Fixed an alignment problem in UnalignedShowBits().

parent 19676f4f
......@@ -2,7 +2,7 @@
* input_ext-dec.h: structures exported to the VideoLAN decoders
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
* $Id: input_ext-dec.h,v 1.24 2001/03/02 13:20:28 massiot Exp $
* $Id: input_ext-dec.h,v 1.25 2001/03/06 19:33:58 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Michel Kaempf <maxx@via.ecp.fr>
......@@ -164,10 +164,13 @@ typedef struct bit_stream_s
*/
/* Current data packet (in the current PES packet of the PES stream) */
data_packet_t * p_data;
/* Pointer to the next byte that is to be read (in the current TS packet) */
/* Pointer to the next byte that is to be read (in the current packet) */
byte_t * p_byte;
/* Pointer to the last byte that is to be read (in the current TS packet */
/* Pointer to the last byte that is to be read (in the current packet */
byte_t * p_end;
/* Temporary buffer in case we're not aligned when changing data packets. */
WORD_TYPE i_showbits_buffer;
data_packet_t showbits_data;
} bit_stream_t;
/*****************************************************************************
......
......@@ -156,10 +156,49 @@ u32 UnalignedShowBits( bit_stream_t * p_bit_stream, unsigned int i_bits )
else
{
p_bit_stream->pf_next_data_packet( p_bit_stream );
p_bit_stream->fifo.buffer |= *(p_bit_stream->p_byte++)
<< (8 * sizeof(WORD_TYPE) - 8
- p_bit_stream->fifo.i_available);
p_bit_stream->fifo.i_available += 8;
if( (ptrdiff_t)p_bit_stream->p_byte & (sizeof(WORD_TYPE) - 1) )
{
/* We are not aligned anymore. */
if( ((ptrdiff_t)p_bit_stream->p_byte
& (sizeof(WORD_TYPE) - 1)) * 8
< p_bit_stream->fifo.i_available )
{
/* We are not aligned, and won't be. Copy the first word
* of the packet in a temporary buffer, and we'll see
* later. */
int i;
p_bit_stream->i_showbits_buffer = 0;
for( i = 0; i < sizeof(WORD_TYPE) ; i++ )
{
if( p_bit_stream->p_byte >= p_bit_stream->p_end )
{
p_bit_stream->pf_next_data_packet( p_bit_stream );
}
((byte_t *)&p_bit_stream->i_showbits_buffer)[i] =
* p_bit_stream->p_byte;
p_bit_stream->p_byte++;
}
/* This is kind of kludgy. */
p_bit_stream->p_data->p_payload_start += sizeof(WORD_TYPE);
p_bit_stream->p_byte =
(byte_t *)&p_bit_stream->i_showbits_buffer;
p_bit_stream->p_end =
(byte_t *)&p_bit_stream->i_showbits_buffer
+ sizeof(WORD_TYPE);
p_bit_stream->showbits_data.p_next = p_bit_stream->p_data;
p_bit_stream->p_data = &p_bit_stream->showbits_data;
}
else
{
/* We are not aligned, but we can be. */
AlignWord( p_bit_stream );
}
}
return( ShowBits( p_bit_stream, i_bits ) );
}
}
return( p_bit_stream->fifo.buffer >> (8 * sizeof(WORD_TYPE) - i_bits) );
......
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