Changeset 18188c24971c0fa187494500b865fc12f3955d8d
- Timestamp:
- 18/01/01 18:40:06 (8 years ago)
- git-parent:
- Files:
-
- include/common.h (modified) (3 diffs)
- include/input_ext-dec.h (modified) (11 diffs)
- src/input/input.h (modified) (2 diffs)
- src/input/input_ext-dec.c (modified) (3 diffs)
- src/video_parser/vpar_synchro.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
include/common.h
r647cca0 r18188c2 4 4 ***************************************************************************** 5 5 * Copyright (C) 1998, 1999, 2000 VideoLAN 6 * $Id: common.h,v 1.2 5 2001/01/18 05:13:22 samExp $6 * $Id: common.h,v 1.26 2001/01/18 17:40:06 massiot Exp $ 7 7 * 8 8 * Authors: Samuel Hocevar <sam@via.ecp.fr> … … 156 156 #endif 157 157 158 /*159 * This is stolen from the livid source who stole it from the kernel160 */161 162 #if defined(SYS_BEOS)163 # define swab32(x) B_BENDIAN_TO_HOST_INT32(x)164 #else165 # ifdef WORDS_BIG_ENDIAN166 # define swab32(x) (x)167 # else168 # 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 # else176 # 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 # endif180 # endif181 #endif182 183 158 /* MSB (big endian)/LSB (little endian) conversions - network order is always 184 159 * MSB, and should be used for both network communications and files. Note that … … 205 180 206 181 /* 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) ) ) ) 209 185 include/input_ext-dec.h
r26ee312 r18188c2 3 3 ***************************************************************************** 4 4 * Copyright (C) 1999, 2000 VideoLAN 5 * $Id: input_ext-dec.h,v 1.1 4 2001/01/13 12:57:19 samExp $5 * $Id: input_ext-dec.h,v 1.15 2001/01/18 17:40:06 massiot Exp $ 6 6 * 7 7 * Authors: … … 114 114 * input stream at the bit level. 115 115 *****************************************************************************/ 116 typedef u32 WORD_TYPE; /* only u32 is supported at the moment */116 typedef u32 WORD_TYPE; 117 117 118 118 typedef struct bit_fifo_s … … 173 173 174 174 /* 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. 178 184 */ 179 185 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 243 192 #endif 244 193 245 194 /***************************************************************************** 195 * Protoypes from input_ext-dec.c 196 *****************************************************************************/ 197 u32 UnalignedShowBits( struct bit_stream_s *, unsigned int ); 198 void UnalignedRemoveBits( struct bit_stream_s * ); 199 u32 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 *****************************************************************************/ 206 static __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 /***************************************************************************** 246 230 * ShowBits : return i_bits bits from the bit stream 247 231 *****************************************************************************/ 248 static __inline__ WORD_TYPE _ShowWord( bit_stream_t * p_bit_stream ) 249 { 232 static __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 250 240 if( p_bit_stream->p_byte <= p_bit_stream->p_end - sizeof(WORD_TYPE) ) 251 241 { 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)) 268 245 >> (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 ); 285 249 } 286 250 … … 289 253 * XXX: do not use for 32 bits, see RemoveBits32 290 254 *****************************************************************************/ 291 static __inline__ void RemoveBits( bit_stream_t * p_bit_stream, int i_bits ) 255 static __inline__ void RemoveBits( bit_stream_t * p_bit_stream, 256 unsigned int i_bits ) 292 257 { 293 258 p_bit_stream->fifo.i_available -= i_bits; … … 298 263 return; 299 264 } 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 ); 303 276 } 304 277 … … 307 280 * refill it) 308 281 *****************************************************************************/ 282 #if (WORD_TYPE == u32) 309 283 static __inline__ void RemoveBits32( bit_stream_t * p_bit_stream ) 310 284 { 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 ) 314 290 << (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 321 305 322 306 /***************************************************************************** … … 324 308 * XXX: do not use for 32 bits, see GetBits32 325 309 *****************************************************************************/ 326 static __inline__ WORD_TYPE GetBits( bit_stream_t * p_bit_stream, int i_bits ) 310 static __inline__ u32 GetBits( bit_stream_t * p_bit_stream, 311 unsigned int i_bits ) 327 312 { 328 313 u32 i_result; 329 314 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); 334 320 p_bit_stream->fifo.buffer <<= i_bits; 335 321 return( i_result ); 336 322 } 337 323 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) 342 333 + 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 ); 347 340 } 348 341 … … 350 343 * GetBits32 : returns 32 bits from the bit stream and removes them 351 344 *****************************************************************************/ 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) 346 static __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; 358 353 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 362 366 >> (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)++; 365 373 return( i_result ); 366 374 } 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 372 381 373 382 /***************************************************************************** … … 380 389 } 381 390 382 383 /*384 * Philosophy of the third implementation : the decoder asks for n bytes,385 * and we will copy them in its buffer.386 */387 391 388 392 /***************************************************************************** … … 397 401 { 398 402 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 } 399 412 400 413 if( (i_available = p_bit_stream->p_end - p_bit_stream->p_byte) … … 423 436 } 424 437 } 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 450 static __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 460 static __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 471 static __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; 425 475 } 426 476 src/input/input.h
rb8899c0 r18188c2 3 3 ***************************************************************************** 4 4 * Copyright (C) 1999, 2000 VideoLAN 5 * $Id: input.h,v 1.1 0 2001/01/15 08:07:31 samExp $5 * $Id: input.h,v 1.11 2001/01/18 17:40:06 massiot Exp $ 6 6 * 7 7 * Authors: … … 119 119 } 120 120 121 /* XXX FIXME SARASS TODO: remove the following one-liner kludge when122 * we have bitstream IV, we won't need it anymore */123 ((WORD_TYPE *)p_pad_data->p_payload_start)++;124 125 121 memset( p_pad_data->p_buffer, 0, PADDING_PACKET_SIZE ); 126 122 p_pad_data->b_discard_payload = 1; src/input/input_ext-dec.c
recff1e7 r18188c2 73 73 void NextDataPacket( bit_stream_t * p_bit_stream ) 74 74 { 75 WORD_TYPE buffer_left;76 ptrdiff_t i_bytes_left;77 75 decoder_fifo_t * p_fifo = p_bit_stream->p_decoder_fifo; 78 76 boolean_t b_new_pes; 79 80 /* Put the remaining bytes (not aligned on a word boundary) in a81 * 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);84 77 85 78 /* We are looking for the next data packet that contains real data, … … 134 127 p_bit_stream->pf_bitstream_callback( p_bit_stream, b_new_pes ); 135 128 } 129 } 130 131 void 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 ); 136 142 137 143 /* Copy remaining bits of the previous packet */ … … 139 145 p_bit_stream->p_byte -= i_bytes_left; 140 146 } 147 148 /***************************************************************************** 149 * UnalignedShowBits : return i_bits bits from the bit stream, even when 150 * not aligned on a word boundary 151 *****************************************************************************/ 152 u32 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 *****************************************************************************/ 181 u32 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 *****************************************************************************/ 249 void 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 3 3 ***************************************************************************** 4 4 * Copyright (C) 1999, 2000 VideoLAN 5 * $Id: vpar_synchro.c,v 1.7 8 2001/01/18 05:13:23 samExp $5 * $Id: vpar_synchro.c,v 1.79 2001/01/18 17:40:06 massiot Exp $ 6 6 * 7 7 * Authors: Christophe Massiot <massiot@via.ecp.fr> … … 223 223 #define S p_vpar->synchro 224 224 /* VPAR_SYNCHRO_DEFAULT */ 225 mtime_t now, pts, period, tau_yuv; 225 mtime_t now, period, tau_yuv; 226 mtime_t pts = 0; 226 227 boolean_t b_decode = 0; 227 228 #ifdef DEBUG_VPAR
