]> git.sesse.net Git - vlc/commitdiff
* Fixed an alignment problem in UnalignedShowBits().
authorChristophe Massiot <massiot@videolan.org>
Tue, 6 Mar 2001 19:33:58 +0000 (19:33 +0000)
committerChristophe Massiot <massiot@videolan.org>
Tue, 6 Mar 2001 19:33:58 +0000 (19:33 +0000)
include/input_ext-dec.h
src/input/input_ext-dec.c

index 4f58fa401da21ab44ae3d92f7d7c62607f0c3332..3c28efd8edf353d633149aa312108f5c849c0d16 100644 (file)
@@ -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;
 
 /*****************************************************************************
index bb29b1fec9951c4d26fe80f8b834c924101e9917..e89e5218d598ec5824ebd38464e23b381d288c43 100644 (file)
@@ -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) );