Changeset 18188c24971c0fa187494500b865fc12f3955d8d

Show
Ignore:
Timestamp:
18/01/01 18:40:06 (8 years ago)
Author:
Christophe Massiot <massiot@videolan.org>
git-committer:
Christophe Massiot <massiot@videolan.org> 979839606 +0000
git-parent:

[647cca0ebb2e897a570018ba80483bb81a7d90c6]

git-author:
Christophe Massiot <massiot@videolan.org> 979839606 +0000
Message:

* 32-bit aligned bitstream (not that fast).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/common.h

    r647cca0 r18188c2  
    44 ***************************************************************************** 
    55 * Copyright (C) 1998, 1999, 2000 VideoLAN 
    6  * $Id: common.h,v 1.25 2001/01/18 05:13:22 sam Exp $ 
     6 * $Id: common.h,v 1.26 2001/01/18 17:40:06 massiot Exp $ 
    77 * 
    88 * Authors: Samuel Hocevar <sam@via.ecp.fr> 
     
    156156#endif 
    157157 
    158 /* 
    159  * This is stolen from the livid source who stole it from the kernel 
    160  */ 
    161  
    162 #if defined(SYS_BEOS) 
    163 #   define swab32(x) B_BENDIAN_TO_HOST_INT32(x) 
    164 #else 
    165 #   ifdef WORDS_BIG_ENDIAN 
    166 #       define swab32(x) (x) 
    167 #   else 
    168 #       if defined (HAVE_X86_BSWAP) 
    169 static __inline__ const u32 __i386_swab32( u32 x ) 
    170 { 
    171     __asm__("bswap %0" : "=r" (x) : "0" (x)); 
    172     return x; 
    173 } 
    174 #           define swab32(x) __i386_swab32(x) 
    175 #       else 
    176 #           define swab32(x)                                                 \ 
    177             ( ( (u32)(((u8*)&x)[0]) << 24 ) | ( (u32)(((u8*)&x)[1]) << 16 ) |\ 
    178               ( (u32)(((u8*)&x)[2]) << 8 )  | ( (u32)(((u8*)&x)[3])) ) 
    179 #       endif 
    180 #   endif 
    181 #endif 
    182  
    183158/* MSB (big endian)/LSB (little endian) conversions - network order is always 
    184159 * MSB, and should be used for both network communications and files. Note that 
     
    205180 
    206181/* Macros with automatic casts */ 
    207 #define U32_AT(p)   ( swab32 ( *( (u32 *)(p) ) ) ) 
    208 #define U16_AT(p)   ( ntohs ( *( (u16 *)(p) ) ) ) 
     182#define U64_AT(p)   ( ntoh64 ( *( (u64 *)(p) ) ) ) 
     183#define U32_AT(p)   ( ntoh32 ( *( (u32 *)(p) ) ) ) 
     184#define U16_AT(p)   ( ntoh16 ( *( (u16 *)(p) ) ) ) 
    209185 
  • include/input_ext-dec.h

    r26ee312 r18188c2  
    33 ***************************************************************************** 
    44 * Copyright (C) 1999, 2000 VideoLAN 
    5  * $Id: input_ext-dec.h,v 1.14 2001/01/13 12:57:19 sam Exp $ 
     5 * $Id: input_ext-dec.h,v 1.15 2001/01/18 17:40:06 massiot Exp $ 
    66 * 
    77 * Authors: 
     
    114114 * input stream at the bit level. 
    115115 *****************************************************************************/ 
    116 typedef u32         WORD_TYPE;        /* only u32 is supported at the moment */ 
     116typedef u32         WORD_TYPE; 
    117117 
    118118typedef struct bit_fifo_s 
     
    173173 
    174174/* 
    175  * Philosophy of the first implementation : the bit buffer is first filled by 
    176  * NeedBits, then the buffer can be read via p_bit_stream->fifo.buffer, and 
    177  * unnecessary bits are dumped with a DumpBits() call. 
     175 * DISCUSSION : How to use the bit_stream structures 
     176 * 
     177 * sizeof(WORD_TYPE) (usually 32) bits are read at the same time, thus 
     178 * minimizing the number of p_byte changes. 
     179 * Bits are read via GetBits() or ShowBits. 
     180 * 
     181 * XXX : Be aware that if, in the forthcoming functions, i_bits > 24, 
     182 * the data have to be already aligned on an 8-bit boundary, or wrong 
     183 * results will be returned. Use RealignBits() if unsure. 
    178184 */ 
    179185 
    180 /***************************************************************************** 
    181  * GetByte : reads the next byte in the input stream (PRIVATE) 
    182  *****************************************************************************/ 
    183 static __inline__ byte_t _GetByte( bit_stream_t * p_bit_stream ) 
    184 
    185     /* Are there some bytes left in the current data packet ? */ 
    186     /* could change this test to have a if (! (bytes--)) instead */ 
    187     if ( p_bit_stream->p_byte >= p_bit_stream->p_end ) 
    188     { 
    189         /* no, switch to next data packet */ 
    190         p_bit_stream->pf_next_data_packet( p_bit_stream ); 
    191     } 
    192  
    193     return( *(p_bit_stream->p_byte++) ); 
    194 
    195  
    196 /***************************************************************************** 
    197  * NeedBits : reads i_bits new bits in the bit stream and stores them in the 
    198  *            bit buffer 
    199  ***************************************************************************** 
    200  * - i_bits must be less or equal 32 ! 
    201  * - There is something important to notice with that function : if the number 
    202  * of bits available in the bit buffer when calling NeedBits() is greater than 
    203  * 24 (i_available > 24) but less than the number of needed bits 
    204  * (i_available < i_bits), the byte returned by GetByte() will be shifted with 
    205  * a negative value and the number of bits available in the bit buffer will be 
    206  * set to more than 32 ! 
    207  *****************************************************************************/ 
    208 static __inline__ void NeedBits( bit_stream_t * p_bit_stream, int i_bits ) 
    209 
    210     while ( p_bit_stream->fifo.i_available < i_bits ) 
    211     { 
    212         p_bit_stream->fifo.buffer |= ((WORD_TYPE)_GetByte( p_bit_stream )) 
    213                                      << (sizeof(WORD_TYPE) - 8 
    214                                             - p_bit_stream->fifo.i_available); 
    215         p_bit_stream->fifo.i_available += 8; 
    216     } 
    217 
    218  
    219 /***************************************************************************** 
    220  * DumpBits : removes i_bits bits from the bit buffer 
    221  ***************************************************************************** 
    222  * - i_bits <= i_available 
    223  * - i_bits < 32 (because (u32 << 32) <=> (u32 = u32)) 
    224  *****************************************************************************/ 
    225 static __inline__ void DumpBits( bit_stream_t * p_bit_stream, int i_bits ) 
    226 
    227     p_bit_stream->fifo.buffer <<= i_bits; 
    228     p_bit_stream->fifo.i_available -= i_bits; 
    229 
    230  
    231  
    232 /* 
    233  * Philosophy of the second implementation : WORD_LENGTH (usually 32) bits 
    234  * are read at the same time, thus minimizing the number of p_byte changes. 
    235  * Bits are read via GetBits() or ShowBits. This is slightly faster. Be 
    236  * aware that if, in the forthcoming functions, i_bits > 24, the data have to 
    237  * be already aligned on an 8-bit boundary, or wrong results will be 
    238  * returned. 
    239  */ 
    240  
    241 #if (WORD_TYPE != u32) 
    242 #   error Not supported word 
     186#if (WORD_TYPE == u32) 
     187#   define WORD_AT      U32_AT 
     188#elif (WORD_TYPE == u64) 
     189#   define WORD_AT      U64_AT 
     190#else 
     191#   error Unsupported WORD_TYPE 
    243192#endif 
    244193 
    245194/***************************************************************************** 
     195 * Protoypes from input_ext-dec.c 
     196 *****************************************************************************/ 
     197u32  UnalignedShowBits( struct bit_stream_s *, unsigned int ); 
     198void UnalignedRemoveBits( struct bit_stream_s * ); 
     199u32  UnalignedGetBits( struct bit_stream_s *, unsigned int ); 
     200 
     201/***************************************************************************** 
     202 * AlignWord : fill in the bit buffer so that the byte pointer be aligned 
     203 * on a word boundary (XXX: there must be at least sizeof(WORD_TYPE) - 1 
     204 * empty bytes in the bit buffer) 
     205 *****************************************************************************/ 
     206static __inline__ void AlignWord( bit_stream_t * p_bit_stream ) 
     207{ 
     208    while( (p_bit_stream->p_byte - p_bit_stream->p_data->p_buffer) 
     209             & (sizeof(WORD_TYPE) - 1) ) 
     210    { 
     211        if( p_bit_stream->p_byte < p_bit_stream->p_end ) 
     212        { 
     213            p_bit_stream->fifo.buffer |= *(p_bit_stream->p_byte++) 
     214                << (8 * sizeof(WORD_TYPE) - 8 
     215                     - p_bit_stream->fifo.i_available); 
     216            p_bit_stream->fifo.i_available += 8; 
     217        } 
     218        else 
     219        { 
     220            p_bit_stream->pf_next_data_packet( p_bit_stream ); 
     221            p_bit_stream->fifo.buffer |= *(p_bit_stream->p_byte++) 
     222                << (8 * sizeof(WORD_TYPE) - 8 
     223                     - p_bit_stream->fifo.i_available); 
     224            p_bit_stream->fifo.i_available += 8; 
     225        } 
     226    } 
     227} 
     228 
     229/***************************************************************************** 
    246230 * ShowBits : return i_bits bits from the bit stream 
    247231 *****************************************************************************/ 
    248 static __inline__ WORD_TYPE _ShowWord( bit_stream_t * p_bit_stream ) 
    249 
     232static __inline__ u32 ShowBits( bit_stream_t * p_bit_stream, 
     233                                unsigned int i_bits ) 
     234
     235    if( p_bit_stream->fifo.i_available >= i_bits ) 
     236    { 
     237        return( p_bit_stream->fifo.buffer >> (8 * sizeof(WORD_TYPE) - i_bits) ); 
     238    } 
     239 
    250240    if( p_bit_stream->p_byte <= p_bit_stream->p_end - sizeof(WORD_TYPE) ) 
    251241    { 
    252         return( swab32( *((WORD_TYPE *)p_bit_stream->p_byte) ) ); 
    253     } 
    254  
    255     p_bit_stream->pf_next_data_packet( p_bit_stream ); 
    256     return( swab32( *((WORD_TYPE *)p_bit_stream->p_byte) ) ); 
    257 
    258  
    259 static __inline__ WORD_TYPE ShowBits( bit_stream_t * p_bit_stream, int i_bits ) 
    260 
    261     if( p_bit_stream->fifo.i_available >= i_bits ) 
    262     { 
    263         return( p_bit_stream->fifo.buffer >> (8 * sizeof(WORD_TYPE) - i_bits) ); 
    264     } 
    265  
    266     return( (p_bit_stream->fifo.buffer | 
    267             (_ShowWord( p_bit_stream ) >> p_bit_stream->fifo.i_available)) 
     242        return( (p_bit_stream->fifo.buffer | 
     243                    (WORD_AT( p_bit_stream->p_byte ) 
     244                        >> p_bit_stream->fifo.i_available)) 
    268245                    >> (8 * sizeof(WORD_TYPE) - i_bits) ); 
    269 
    270  
    271 /***************************************************************************** 
    272  * GetWord : returns the next word to be read (PRIVATE) 
    273  *****************************************************************************/ 
    274 static __inline__ WORD_TYPE _GetWord( bit_stream_t * p_bit_stream ) 
    275 
    276     if( p_bit_stream->p_byte <= p_bit_stream->p_end - sizeof(WORD_TYPE) ) 
    277     { 
    278         return( swab32( *(((WORD_TYPE *)p_bit_stream->p_byte)++) ) ); 
    279     } 
    280     else 
    281     { 
    282         p_bit_stream->pf_next_data_packet( p_bit_stream ); 
    283         return( swab32( *(((WORD_TYPE *)p_bit_stream->p_byte)++) ) ); 
    284     } 
     246    } 
     247 
     248    return UnalignedShowBits( p_bit_stream, i_bits ); 
    285249} 
    286250 
     
    289253 *              XXX: do not use for 32 bits, see RemoveBits32 
    290254 *****************************************************************************/ 
    291 static __inline__ void RemoveBits( bit_stream_t * p_bit_stream, int i_bits ) 
     255static __inline__ void RemoveBits( bit_stream_t * p_bit_stream, 
     256                                   unsigned int i_bits ) 
    292257{ 
    293258    p_bit_stream->fifo.i_available -= i_bits; 
     
    298263        return; 
    299264    } 
    300     p_bit_stream->fifo.buffer = _GetWord( p_bit_stream ) 
    301                             << ( -p_bit_stream->fifo.i_available ); 
    302     p_bit_stream->fifo.i_available += sizeof(WORD_TYPE) * 8; 
     265 
     266    if( p_bit_stream->p_byte <= p_bit_stream->p_end - sizeof(WORD_TYPE) ) 
     267    { 
     268        p_bit_stream->fifo.buffer = WORD_AT( p_bit_stream->p_byte ) 
     269                                        << ( -p_bit_stream->fifo.i_available ); 
     270        ((WORD_TYPE *)p_bit_stream->p_byte)++; 
     271        p_bit_stream->fifo.i_available += sizeof(WORD_TYPE) * 8; 
     272        return; 
     273    } 
     274 
     275    UnalignedRemoveBits( p_bit_stream ); 
    303276} 
    304277 
     
    307280 *                refill it) 
    308281 *****************************************************************************/ 
     282#if (WORD_TYPE == u32) 
    309283static __inline__ void RemoveBits32( bit_stream_t * p_bit_stream ) 
    310284{ 
    311     if( p_bit_stream->fifo.i_available ) 
    312     { 
    313         p_bit_stream->fifo.buffer = _GetWord( p_bit_stream ) 
     285    if( p_bit_stream->p_byte <= p_bit_stream->p_end - sizeof(WORD_TYPE) ) 
     286    { 
     287        if( p_bit_stream->fifo.i_available ) 
     288        { 
     289            p_bit_stream->fifo.buffer = WORD_AT( p_bit_stream->p_byte ) 
    314290                            << (32 - p_bit_stream->fifo.i_available); 
    315     } 
    316     else 
    317     { 
    318         _GetWord( p_bit_stream ); 
    319     } 
    320 
     291            ((WORD_TYPE *)p_bit_stream->p_byte)++; 
     292            return; 
     293        } 
     294 
     295        ((WORD_TYPE *)p_bit_stream->p_byte)++; 
     296        return; 
     297    } 
     298 
     299    p_bit_stream->fifo.i_available -= 32; 
     300    UnalignedRemoveBits( p_bit_stream ); 
     301
     302#else 
     303#   define RemoveBits32( p_bit_stream )     RemoveBits( p_bit_stream, 32 ) 
     304#endif 
    321305 
    322306/***************************************************************************** 
     
    324308 *           XXX: do not use for 32 bits, see GetBits32 
    325309 *****************************************************************************/ 
    326 static __inline__ WORD_TYPE GetBits( bit_stream_t * p_bit_stream, int i_bits ) 
     310static __inline__ u32 GetBits( bit_stream_t * p_bit_stream, 
     311                               unsigned int i_bits ) 
    327312{ 
    328313    u32             i_result; 
    329314 
    330     p_bit_stream->fifo.i_available -= i_bits; 
    331     if( p_bit_stream->fifo.i_available >= 0 ) 
    332     { 
    333         i_result = p_bit_stream->fifo.buffer >> (8 * sizeof(WORD_TYPE) - i_bits); 
     315    if( p_bit_stream->fifo.i_available >= i_bits ) 
     316    { 
     317        p_bit_stream->fifo.i_available -= i_bits; 
     318        i_result = p_bit_stream->fifo.buffer 
     319                        >> (8 * sizeof(WORD_TYPE) - i_bits); 
    334320        p_bit_stream->fifo.buffer <<= i_bits; 
    335321        return( i_result ); 
    336322    } 
    337323 
    338     i_result = p_bit_stream->fifo.buffer >> (8 * sizeof(WORD_TYPE) - i_bits); 
    339     p_bit_stream->fifo.buffer = _GetWord( p_bit_stream ); 
    340     i_result |= p_bit_stream->fifo.buffer 
    341                              >> (8 * sizeof(WORD_TYPE) 
     324    if( p_bit_stream->p_byte <= p_bit_stream->p_end - sizeof(WORD_TYPE) ) 
     325    { 
     326        p_bit_stream->fifo.i_available -= i_bits; 
     327        i_result = p_bit_stream->fifo.buffer 
     328                        >> (8 * sizeof(WORD_TYPE) - i_bits); 
     329        p_bit_stream->fifo.buffer = WORD_AT( p_bit_stream->p_byte ); 
     330        ((WORD_TYPE *)p_bit_stream->p_byte)++; 
     331        i_result |= p_bit_stream->fifo.buffer 
     332                        >> (8 * sizeof(WORD_TYPE) 
    342333                                     + p_bit_stream->fifo.i_available); 
    343     p_bit_stream->fifo.buffer <<= ( -p_bit_stream->fifo.i_available ); 
    344     p_bit_stream->fifo.i_available += sizeof(WORD_TYPE) * 8; 
    345  
    346     return( i_result ); 
     334        p_bit_stream->fifo.buffer <<= ( -p_bit_stream->fifo.i_available ); 
     335        p_bit_stream->fifo.i_available += sizeof(WORD_TYPE) * 8; 
     336        return( i_result ); 
     337    } 
     338 
     339    return UnalignedGetBits( p_bit_stream, i_bits ); 
    347340} 
    348341 
     
    350343 * GetBits32 : returns 32 bits from the bit stream and removes them 
    351344 *****************************************************************************/ 
    352 static __inline__ WORD_TYPE GetBits32( bit_stream_t * p_bit_stream ) 
    353 
    354     WORD_TYPE               i_result; 
    355  
    356     if( p_bit_stream->fifo.i_available ) 
    357     { 
     345#if (WORD_TYPE == u32) 
     346static __inline__ u32 GetBits32( bit_stream_t * p_bit_stream ) 
     347
     348    u32             i_result; 
     349 
     350    if( p_bit_stream->fifo.i_available == 32 ) 
     351    { 
     352        p_bit_stream->fifo.i_available = 0; 
    358353        i_result = p_bit_stream->fifo.buffer; 
    359         p_bit_stream->fifo.buffer = _GetWord( p_bit_stream ); 
    360  
    361         i_result |= p_bit_stream->fifo.buffer 
     354        p_bit_stream->fifo.buffer = 0; 
     355        return( i_result ); 
     356    } 
     357 
     358    if( p_bit_stream->p_byte <= p_bit_stream->p_end - sizeof(WORD_TYPE) ) 
     359    { 
     360        if( p_bit_stream->fifo.i_available ) 
     361        { 
     362            i_result = p_bit_stream->fifo.buffer; 
     363            p_bit_stream->fifo.buffer = WORD_AT( p_bit_stream->p_byte ); 
     364            ((WORD_TYPE *)p_bit_stream->p_byte)++; 
     365            i_result |= p_bit_stream->fifo.buffer 
    362366                             >> (p_bit_stream->fifo.i_available); 
    363         p_bit_stream->fifo.buffer <<= (8 * sizeof(WORD_TYPE) 
    364                                     - p_bit_stream->fifo.i_available); 
     367            p_bit_stream->fifo.buffer <<= (32 - p_bit_stream->fifo.i_available); 
     368            return( i_result ); 
     369        } 
     370 
     371        i_result = WORD_AT( p_bit_stream->p_byte ); 
     372        ((WORD_TYPE *)p_bit_stream->p_byte)++; 
    365373        return( i_result ); 
    366374    } 
    367     else 
    368     { 
    369         return( _GetWord( p_bit_stream ) ); 
    370     } 
    371 
     375 
     376    return UnalignedGetBits( p_bit_stream, 32 ); 
     377
     378#else 
     379#   define GetBits32( p_bit_stream )    GetBits( p_bit_stream, 32 ) 
     380#endif 
    372381 
    373382/***************************************************************************** 
     
    380389} 
    381390 
    382  
    383 /* 
    384  * Philosophy of the third implementation : the decoder asks for n bytes, 
    385  * and we will copy them in its buffer. 
    386  */ 
    387391 
    388392/***************************************************************************** 
     
    397401{ 
    398402    ptrdiff_t           i_available; 
     403 
     404    if( p_bit_stream->fifo.i_available ) 
     405    { 
     406        *((WORD_TYPE *)p_buffer) = WORD_AT( p_bit_stream->fifo.buffer ); 
     407        p_buffer += p_bit_stream->fifo.i_available >> 3; 
     408        i_buf_len -= p_bit_stream->fifo.i_available >> 3; 
     409        p_bit_stream->fifo.buffer = 0; 
     410        p_bit_stream->fifo.i_available = 0; 
     411    } 
    399412 
    400413    if( (i_available = p_bit_stream->p_end - p_bit_stream->p_byte) 
     
    423436        } 
    424437    } 
     438 
     439    if( p_bit_stream->p_byte <= p_bit_stream->p_end - sizeof(WORD_TYPE) ) 
     440    { 
     441        AlignWord( p_bit_stream ); 
     442    } 
     443} 
     444 
     445 
     446/* 
     447 * The following functions are now deprecated. 
     448 */ 
     449 
     450static __inline__ byte_t _GetByte( bit_stream_t * p_bit_stream ) 
     451{ 
     452    if ( p_bit_stream->p_byte >= p_bit_stream->p_end ) 
     453    { 
     454        p_bit_stream->pf_next_data_packet( p_bit_stream ); 
     455    } 
     456 
     457    return( *(p_bit_stream->p_byte++) ); 
     458} 
     459 
     460static __inline__ void NeedBits( bit_stream_t * p_bit_stream, int i_bits ) 
     461{ 
     462    while ( p_bit_stream->fifo.i_available < i_bits ) 
     463    { 
     464        p_bit_stream->fifo.buffer |= ((WORD_TYPE)_GetByte( p_bit_stream )) 
     465                                     << (8 * sizeof(WORD_TYPE) - 8 
     466                                            - p_bit_stream->fifo.i_available); 
     467        p_bit_stream->fifo.i_available += 8; 
     468    } 
     469} 
     470 
     471static __inline__ void DumpBits( bit_stream_t * p_bit_stream, int i_bits ) 
     472{ 
     473    p_bit_stream->fifo.buffer <<= i_bits; 
     474    p_bit_stream->fifo.i_available -= i_bits; 
    425475} 
    426476 
  • src/input/input.h

    rb8899c0 r18188c2  
    33 ***************************************************************************** 
    44 * Copyright (C) 1999, 2000 VideoLAN 
    5  * $Id: input.h,v 1.10 2001/01/15 08:07:31 sam Exp $ 
     5 * $Id: input.h,v 1.11 2001/01/18 17:40:06 massiot Exp $ 
    66 * 
    77 * Authors: 
     
    119119    } 
    120120 
    121     /* XXX FIXME SARASS TODO: remove the following one-liner kludge when 
    122      * we have bitstream IV, we won't need it anymore */ 
    123     ((WORD_TYPE *)p_pad_data->p_payload_start)++; 
    124  
    125121    memset( p_pad_data->p_buffer, 0, PADDING_PACKET_SIZE ); 
    126122    p_pad_data->b_discard_payload = 1; 
  • src/input/input_ext-dec.c

    recff1e7 r18188c2  
    7373void NextDataPacket( bit_stream_t * p_bit_stream ) 
    7474{ 
    75     WORD_TYPE           buffer_left; 
    76     ptrdiff_t           i_bytes_left; 
    7775    decoder_fifo_t *    p_fifo = p_bit_stream->p_decoder_fifo; 
    7876    boolean_t           b_new_pes; 
    79  
    80     /* Put the remaining bytes (not aligned on a word boundary) in a 
    81      * temporary buffer. */ 
    82     i_bytes_left = p_bit_stream->p_end - p_bit_stream->p_byte; 
    83     buffer_left = *((WORD_TYPE *)p_bit_stream->p_end - 1); 
    8477 
    8578    /* We are looking for the next data packet that contains real data, 
     
    134127        p_bit_stream->pf_bitstream_callback( p_bit_stream, b_new_pes ); 
    135128    } 
     129} 
     130 
     131void OldKludge( bit_stream_t * p_bit_stream ) 
     132{ 
     133    WORD_TYPE           buffer_left; 
     134    ptrdiff_t           i_bytes_left; 
     135 
     136    /* Put the remaining bytes (not aligned on a word boundary) in a 
     137     * temporary buffer. */ 
     138    i_bytes_left = p_bit_stream->p_end - p_bit_stream->p_byte; 
     139    buffer_left = *((WORD_TYPE *)p_bit_stream->p_end - 1); 
     140 
     141    p_bit_stream->pf_next_data_packet( p_bit_stream ); 
    136142 
    137143    /* Copy remaining bits of the previous packet */ 
     
    139145    p_bit_stream->p_byte -= i_bytes_left; 
    140146} 
     147 
     148/***************************************************************************** 
     149 * UnalignedShowBits : return i_bits bits from the bit stream, even when 
     150 * not aligned on a word boundary 
     151 *****************************************************************************/ 
     152u32 UnalignedShowBits( bit_stream_t * p_bit_stream, unsigned int i_bits ) 
     153{ 
     154    /* We just fill in the bit buffer. */ 
     155    while( p_bit_stream->fifo.i_available < i_bits ) 
     156    { 
     157        if( p_bit_stream->p_byte < p_bit_stream->p_end ) 
     158        { 
     159            p_bit_stream->fifo.buffer |= *(p_bit_stream->p_byte++) 
     160                                            << (8 * sizeof(WORD_TYPE) - 8 
     161                                            - p_bit_stream->fifo.i_available); 
     162            p_bit_stream->fifo.i_available += 8; 
     163        } 
     164        else 
     165        { 
     166            p_bit_stream->pf_next_data_packet( p_bit_stream ); 
     167            p_bit_stream->fifo.buffer |= *(p_bit_stream->p_byte++) 
     168                                            << (8 * sizeof(WORD_TYPE) - 8 
     169                                            - p_bit_stream->fifo.i_available); 
     170            p_bit_stream->fifo.i_available += 8; 
     171        } 
     172    } 
     173    return( p_bit_stream->fifo.buffer >> (8 * sizeof(WORD_TYPE) - i_bits) ); 
     174} 
     175 
     176/***************************************************************************** 
     177 * UnalignedGetBits : returns i_bits bits from the bit stream and removes 
     178 * them from the buffer, even when the bit stream is not aligned on a word 
     179 * boundary 
     180 *****************************************************************************/ 
     181u32 UnalignedGetBits( bit_stream_t * p_bit_stream, unsigned int i_bits ) 
     182{ 
     183    u32         i_result; 
     184 
     185    i_result = p_bit_stream->fifo.buffer 
     186                    >> (8 * sizeof(WORD_TYPE) - i_bits); 
     187    i_bits -= p_bit_stream->fifo.i_available; 
     188 
     189    /* Gather missing bytes. */ 
     190    while( i_bits >= 8 ) 
     191    { 
     192        if( p_bit_stream->p_byte < p_bit_stream->p_end ) 
     193        { 
     194            i_result |= *(p_bit_stream->p_byte++) << (i_bits - 8); 
     195            i_bits -= 8; 
     196        } 
     197        else 
     198        { 
     199            p_bit_stream->pf_next_data_packet( p_bit_stream ); 
     200            i_result |= *(p_bit_stream->p_byte++) << (i_bits - 8); 
     201            i_bits -= 8; 
     202        } 
     203    } 
     204 
     205    /* Gather missing bits. */ 
     206    if( i_bits > 0 ) 
     207    { 
     208        unsigned int    i_tmp = 8 - i_bits; 
     209 
     210        if( p_bit_stream->p_byte < p_bit_stream->p_end ) 
     211        { 
     212            i_result |= *p_bit_stream->p_byte >> i_tmp; 
     213            p_bit_stream->fifo.buffer = *(p_bit_stream->p_byte++) 
     214                 << ( sizeof(WORD_TYPE) * 8 - i_tmp ); 
     215            p_bit_stream->fifo.i_available = i_tmp; 
     216        } 
     217        else 
     218        { 
     219            p_bit_stream->pf_next_data_packet( p_bit_stream ); 
     220            i_result |= *p_bit_stream->p_byte >> i_tmp; 
     221            p_bit_stream->fifo.buffer = *(p_bit_stream->p_byte++) 
     222                 << ( sizeof(WORD_TYPE) * 8 - i_tmp ); 
     223            p_bit_stream->fifo.i_available = i_tmp; 
     224        } 
     225    } 
     226    else 
     227    { 
     228        p_bit_stream->fifo.i_available = 0; 
     229        p_bit_stream->fifo.buffer = 0; 
     230    } 
     231 
     232    if( p_bit_stream->p_byte <= p_bit_stream->p_end - sizeof(WORD_TYPE) ) 
     233    { 
     234        /* Get aligned on a word boundary. Otherwise it is safer 
     235         * to do it the next time. 
     236         * NB : we _will_ get aligned, because we have at most  
     237         * sizeof(WORD_TYPE) - 1 bytes to store, and at least 
     238         * sizeof(WORD_TYPE) - 1 empty bytes in the bit buffer. */ 
     239        AlignWord( p_bit_stream ); 
     240    } 
     241 
     242    return( i_result ); 
     243} 
     244 
     245/***************************************************************************** 
     246 * UnalignedRemoveBits : removes i_bits (== -i_available) from the bit 
     247 * buffer, even when the bit stream is not aligned on a word boundary 
     248 *****************************************************************************/ 
     249void UnalignedRemoveBits( bit_stream_t * p_bit_stream ) 
     250{ 
     251    /* First remove all unnecessary bytes. */ 
     252    while( p_bit_stream->fifo.i_available <= -8 ) 
     253    { 
     254        if( p_bit_stream->p_byte < p_bit_stream->p_end ) 
     255        { 
     256            p_bit_stream->p_byte++; 
     257            p_bit_stream->fifo.i_available += 8; 
     258        } 
     259        else 
     260        { 
     261            p_bit_stream->pf_next_data_packet( p_bit_stream ); 
     262            p_bit_stream->p_byte++; 
     263            p_bit_stream->fifo.i_available += 8; 
     264        } 
     265    } 
     266 
     267    /* Remove unnecessary bits. */ 
     268    if( p_bit_stream->fifo.i_available < 0 ) 
     269    { 
     270        if( p_bit_stream->p_byte < p_bit_stream->p_end ) 
     271        { 
     272            p_bit_stream->fifo.buffer = *(p_bit_stream->p_byte++) 
     273                 << ( sizeof(WORD_TYPE) * 8 - 8 
     274                         - p_bit_stream->fifo.i_available ); 
     275            p_bit_stream->fifo.i_available += 8; 
     276        } 
     277        else 
     278        { 
     279            p_bit_stream->pf_next_data_packet( p_bit_stream ); 
     280            p_bit_stream->fifo.buffer = *(p_bit_stream->p_byte++) 
     281                 << ( sizeof(WORD_TYPE) * 8 - 8 
     282                         - p_bit_stream->fifo.i_available ); 
     283            p_bit_stream->fifo.i_available += 8; 
     284        } 
     285    } 
     286    else 
     287    { 
     288        p_bit_stream->fifo.buffer = 0; 
     289    } 
     290 
     291    if( p_bit_stream->p_byte <= p_bit_stream->p_end - sizeof(WORD_TYPE) ) 
     292    { 
     293        /* Get aligned on a word boundary. Otherwise it is safer 
     294         * to do it the next time. 
     295         * NB : we _will_ get aligned, because we have at most  
     296         * sizeof(WORD_TYPE) - 1 bytes to store, and at least 
     297         * sizeof(WORD_TYPE) - 1 empty bytes in the bit buffer. */ 
     298        AlignWord( p_bit_stream ); 
     299    } 
     300} 
     301 
  • src/video_parser/vpar_synchro.c

    r647cca0 r18188c2  
    33 ***************************************************************************** 
    44 * Copyright (C) 1999, 2000 VideoLAN 
    5  * $Id: vpar_synchro.c,v 1.78 2001/01/18 05:13:23 sam Exp $ 
     5 * $Id: vpar_synchro.c,v 1.79 2001/01/18 17:40:06 massiot Exp $ 
    66 * 
    77 * Authors: Christophe Massiot <massiot@via.ecp.fr> 
     
    223223#define S                           p_vpar->synchro 
    224224        /* VPAR_SYNCHRO_DEFAULT */ 
    225         mtime_t         now, pts, period, tau_yuv; 
     225        mtime_t         now, period, tau_yuv; 
     226        mtime_t         pts = 0; 
    226227        boolean_t       b_decode = 0; 
    227228#ifdef DEBUG_VPAR