comparison bitstream.h @ 2663:b33be8b00488 libavcodec

LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
author michael
date Wed, 11 May 2005 01:46:13 +0000
parents 0d88e3f89379
children be04f746d1fe
comparison
equal deleted inserted replaced
2662:2fe9599170f6 2663:b33be8b00488
366 #else 366 #else
367 return be2me_32( unaligned32(v)); //original 367 return be2me_32( unaligned32(v)); //original
368 #endif 368 #endif
369 } 369 }
370 370
371 static inline int unaligned32_le(const void *v)
372 {
373 #ifdef CONFIG_ALIGN
374 const uint8_t *p=v;
375 return (((p[3]<<8) | p[2])<<16) | (p[1]<<8) | (p[0]);
376 #else
377 return le2me_32( unaligned32(v)); //original
378 #endif
379 }
380
371 #ifdef ALT_BITSTREAM_READER 381 #ifdef ALT_BITSTREAM_READER
372 # define MIN_CACHE_BITS 25 382 # define MIN_CACHE_BITS 25
373 383
374 # define OPEN_READER(name, gb)\ 384 # define OPEN_READER(name, gb)\
375 int name##_index= (gb)->index;\ 385 int name##_index= (gb)->index;\
376 int name##_cache= 0;\ 386 int name##_cache= 0;\
377 387
378 # define CLOSE_READER(name, gb)\ 388 # define CLOSE_READER(name, gb)\
379 (gb)->index= name##_index;\ 389 (gb)->index= name##_index;\
380 390
391 # ifdef ALT_BITSTREAM_READER_LE
392 # define UPDATE_CACHE(name, gb)\
393 name##_cache= unaligned32_le( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\
394
395 # define SKIP_CACHE(name, gb, num)\
396 name##_cache >>= (num);
397 # else
381 # define UPDATE_CACHE(name, gb)\ 398 # define UPDATE_CACHE(name, gb)\
382 name##_cache= unaligned32_be( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\ 399 name##_cache= unaligned32_be( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\
383 400
384 # define SKIP_CACHE(name, gb, num)\ 401 # define SKIP_CACHE(name, gb, num)\
385 name##_cache <<= (num);\ 402 name##_cache <<= (num);
403 # endif
386 404
387 // FIXME name? 405 // FIXME name?
388 # define SKIP_COUNTER(name, gb, num)\ 406 # define SKIP_COUNTER(name, gb, num)\
389 name##_index += (num);\ 407 name##_index += (num);\
390 408
395 }\ 413 }\
396 414
397 # define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num) 415 # define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num)
398 # define LAST_SKIP_CACHE(name, gb, num) ; 416 # define LAST_SKIP_CACHE(name, gb, num) ;
399 417
418 # ifdef ALT_BITSTREAM_READER_LE
419 # define SHOW_UBITS(name, gb, num)\
420 ((name##_cache) & (NEG_USR32(0xffffffff,num)))
421 # else
400 # define SHOW_UBITS(name, gb, num)\ 422 # define SHOW_UBITS(name, gb, num)\
401 NEG_USR32(name##_cache, num) 423 NEG_USR32(name##_cache, num)
424 # endif
402 425
403 # define SHOW_SBITS(name, gb, num)\ 426 # define SHOW_SBITS(name, gb, num)\
404 NEG_SSR32(name##_cache, num) 427 NEG_SSR32(name##_cache, num)
405 428
406 # define GET_CACHE(name, gb)\ 429 # define GET_CACHE(name, gb)\
614 637
615 static inline unsigned int get_bits1(GetBitContext *s){ 638 static inline unsigned int get_bits1(GetBitContext *s){
616 #ifdef ALT_BITSTREAM_READER 639 #ifdef ALT_BITSTREAM_READER
617 int index= s->index; 640 int index= s->index;
618 uint8_t result= s->buffer[ index>>3 ]; 641 uint8_t result= s->buffer[ index>>3 ];
642 #ifdef ALT_BITSTREAM_READER_LE
643 result>>= (index&0x07);
644 result&= 1;
645 #else
619 result<<= (index&0x07); 646 result<<= (index&0x07);
620 result>>= 8 - 1; 647 result>>= 8 - 1;
648 #endif
621 index++; 649 index++;
622 s->index= index; 650 s->index= index;
623 651
624 return result; 652 return result;
625 #else 653 #else
685 int check_marker(GetBitContext *s, const char *msg); 713 int check_marker(GetBitContext *s, const char *msg);
686 void align_get_bits(GetBitContext *s); 714 void align_get_bits(GetBitContext *s);
687 int init_vlc(VLC *vlc, int nb_bits, int nb_codes, 715 int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
688 const void *bits, int bits_wrap, int bits_size, 716 const void *bits, int bits_wrap, int bits_size,
689 const void *codes, int codes_wrap, int codes_size, 717 const void *codes, int codes_wrap, int codes_size,
690 int use_static); 718 int flags);
719 #define INIT_VLC_USE_STATIC 1
720 #define INIT_VLC_LE 2
691 void free_vlc(VLC *vlc); 721 void free_vlc(VLC *vlc);
692 722
693 /** 723 /**
694 * 724 *
695 * if the vlc code is invalid and max_depth=1 than no bits will be removed 725 * if the vlc code is invalid and max_depth=1 than no bits will be removed