OLD | NEW |
1 /* | 1 /* |
2 * copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at> | 2 * copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at> |
3 * | 3 * |
4 * This file is part of FFmpeg. | 4 * This file is part of FFmpeg. |
5 * | 5 * |
6 * FFmpeg is free software; you can redistribute it and/or | 6 * FFmpeg is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Lesser General Public | 7 * modify it under the terms of the GNU Lesser General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2.1 of the License, or (at your option) any later version. | 9 * version 2.1 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !de
fined(ALT_BITSTREAM_READER) | 42 #if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !de
fined(ALT_BITSTREAM_READER) |
43 # if ARCH_ARM && !HAVE_FAST_UNALIGNED | 43 # if ARCH_ARM && !HAVE_FAST_UNALIGNED |
44 # define A32_BITSTREAM_READER | 44 # define A32_BITSTREAM_READER |
45 # else | 45 # else |
46 # define ALT_BITSTREAM_READER | 46 # define ALT_BITSTREAM_READER |
47 //#define LIBMPEG2_BITSTREAM_READER | 47 //#define LIBMPEG2_BITSTREAM_READER |
48 //#define A32_BITSTREAM_READER | 48 //#define A32_BITSTREAM_READER |
49 # endif | 49 # endif |
50 #endif | 50 #endif |
51 | 51 |
52 #if ARCH_X86 | |
53 // avoid +32 for shift optimization (gcc should do that ...) | |
54 static inline int32_t NEG_SSR32( int32_t a, int8_t s){ | |
55 __asm__ ("sarl %1, %0\n\t" | |
56 : "+r" (a) | |
57 : "ic" ((uint8_t)(-s)) | |
58 ); | |
59 return a; | |
60 } | |
61 static inline uint32_t NEG_USR32(uint32_t a, int8_t s){ | |
62 __asm__ ("shrl %1, %0\n\t" | |
63 : "+r" (a) | |
64 : "ic" ((uint8_t)(-s)) | |
65 ); | |
66 return a; | |
67 } | |
68 #else | |
69 # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s))) | |
70 # define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s))) | |
71 #endif | |
72 | |
73 /* bit input */ | 52 /* bit input */ |
74 /* buffer, buffer_end and size_in_bits must be present and used by every reader
*/ | 53 /* buffer, buffer_end and size_in_bits must be present and used by every reader
*/ |
75 typedef struct GetBitContext { | 54 typedef struct GetBitContext { |
76 const uint8_t *buffer, *buffer_end; | 55 const uint8_t *buffer, *buffer_end; |
77 /* Ugly, but clients of this bit reader do not seem to check for enough | 56 /* Ugly, but clients of this bit reader do not seem to check for enough |
78 * data before calling. So we'll return 0's on overrun rather than crashing | 57 * data before calling. So we'll return 0's on overrun rather than crashing |
79 * with random read faults. | 58 * with random read faults. |
80 */ | 59 */ |
81 int buffer_exhausted; | 60 int buffer_exhausted; |
82 int buffer_enforcing; | 61 int buffer_enforcing; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 {\ | 175 {\ |
197 SKIP_CACHE(name, gb, num)\ | 176 SKIP_CACHE(name, gb, num)\ |
198 SKIP_COUNTER(name, gb, num)\ | 177 SKIP_COUNTER(name, gb, num)\ |
199 }\ | 178 }\ |
200 | 179 |
201 # define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num) | 180 # define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num) |
202 # define LAST_SKIP_CACHE(name, gb, num) ; | 181 # define LAST_SKIP_CACHE(name, gb, num) ; |
203 | 182 |
204 # ifdef ALT_BITSTREAM_READER_LE | 183 # ifdef ALT_BITSTREAM_READER_LE |
205 # define SHOW_UBITS(name, gb, num)\ | 184 # define SHOW_UBITS(name, gb, num)\ |
206 ((name##_cache) & (NEG_USR32(0xffffffff,num))) | 185 zero_extend(name##_cache, num) |
207 | 186 |
208 # define SHOW_SBITS(name, gb, num)\ | 187 # define SHOW_SBITS(name, gb, num)\ |
209 NEG_SSR32((name##_cache)<<(32-(num)), num) | 188 sign_extend(name##_cache, num) |
210 # else | 189 # else |
211 # define SHOW_UBITS(name, gb, num)\ | 190 # define SHOW_UBITS(name, gb, num)\ |
212 NEG_USR32(name##_cache, num) | 191 NEG_USR32(name##_cache, num) |
213 | 192 |
214 # define SHOW_SBITS(name, gb, num)\ | 193 # define SHOW_SBITS(name, gb, num)\ |
215 NEG_SSR32(name##_cache, num) | 194 NEG_SSR32(name##_cache, num) |
216 # endif | 195 # endif |
217 | 196 |
218 # define GET_CACHE(name, gb)\ | 197 # define GET_CACHE(name, gb)\ |
219 ((uint32_t)name##_cache) | 198 ((uint32_t)name##_cache) |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 } | 443 } |
465 | 444 |
466 static inline void skip_bits1(GetBitContext *s){ | 445 static inline void skip_bits1(GetBitContext *s){ |
467 skip_bits(s, 1); | 446 skip_bits(s, 1); |
468 } | 447 } |
469 | 448 |
470 /** | 449 /** |
471 * reads 0-32 bits. | 450 * reads 0-32 bits. |
472 */ | 451 */ |
473 static inline unsigned int get_bits_long(GetBitContext *s, int n){ | 452 static inline unsigned int get_bits_long(GetBitContext *s, int n){ |
474 if(n<=17) return get_bits(s, n); | 453 if(n<=MIN_CACHE_BITS) return get_bits(s, n); |
475 else{ | 454 else{ |
476 #ifdef ALT_BITSTREAM_READER_LE | 455 #ifdef ALT_BITSTREAM_READER_LE |
477 int ret= get_bits(s, 16); | 456 int ret= get_bits(s, 16); |
478 return ret | (get_bits(s, n-16) << 16); | 457 return ret | (get_bits(s, n-16) << 16); |
479 #else | 458 #else |
480 int ret= get_bits(s, 16) << (n-16); | 459 int ret= get_bits(s, 16) << (n-16); |
481 return ret | get_bits(s, n-16); | 460 return ret | get_bits(s, n-16); |
482 #endif | 461 #endif |
483 } | 462 } |
484 } | 463 } |
485 | 464 |
486 /** | 465 /** |
487 * reads 0-32 bits as a signed integer. | 466 * reads 0-32 bits as a signed integer. |
488 */ | 467 */ |
489 static inline int get_sbits_long(GetBitContext *s, int n) { | 468 static inline int get_sbits_long(GetBitContext *s, int n) { |
490 return sign_extend(get_bits_long(s, n), n); | 469 return sign_extend(get_bits_long(s, n), n); |
491 } | 470 } |
492 | 471 |
493 /** | 472 /** |
494 * shows 0-32 bits. | 473 * shows 0-32 bits. |
495 */ | 474 */ |
496 static inline unsigned int show_bits_long(GetBitContext *s, int n){ | 475 static inline unsigned int show_bits_long(GetBitContext *s, int n){ |
497 if(n<=17) return show_bits(s, n); | 476 if(n<=MIN_CACHE_BITS) return show_bits(s, n); |
498 else{ | 477 else{ |
499 GetBitContext gb= *s; | 478 GetBitContext gb= *s; |
500 return get_bits_long(&gb, n); | 479 return get_bits_long(&gb, n); |
501 } | 480 } |
502 } | 481 } |
503 | 482 |
504 static inline int check_marker(GetBitContext *s, const char *msg) | 483 static inline int check_marker(GetBitContext *s, const char *msg) |
505 { | 484 { |
506 int bit= get_bits1(s); | 485 int bit= get_bits1(s); |
507 if(!bit) | 486 if(!bit) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 {\ | 553 {\ |
575 static VLC_TYPE table[static_size][2];\ | 554 static VLC_TYPE table[static_size][2];\ |
576 (vlc)->table= table;\ | 555 (vlc)->table= table;\ |
577 (vlc)->table_allocated= static_size;\ | 556 (vlc)->table_allocated= static_size;\ |
578 init_vlc(vlc, bits, a,b,c,d,e,f,g, INIT_VLC_USE_NEW_STATIC);\ | 557 init_vlc(vlc, bits, a,b,c,d,e,f,g, INIT_VLC_USE_NEW_STATIC);\ |
579 } | 558 } |
580 | 559 |
581 | 560 |
582 /** | 561 /** |
583 * | 562 * |
584 * if the vlc code is invalid and max_depth=1 than no bits will be removed | 563 * If the vlc code is invalid and max_depth=1, then no bits will be removed. |
585 * if the vlc code is invalid and max_depth>1 than the number of bits removed | 564 * If the vlc code is invalid and max_depth>1, then the number of bits removed |
586 * is undefined | 565 * is undefined. |
587 */ | 566 */ |
588 #define GET_VLC(code, name, gb, table, bits, max_depth)\ | 567 #define GET_VLC(code, name, gb, table, bits, max_depth)\ |
589 {\ | 568 {\ |
590 int n, nb_bits;\ | 569 int n, nb_bits;\ |
591 unsigned int index;\ | 570 unsigned int index;\ |
592 \ | 571 \ |
593 index= SHOW_UBITS(name, gb, bits);\ | 572 index= SHOW_UBITS(name, gb, bits);\ |
594 code = table[index][0];\ | 573 code = table[index][0];\ |
595 n = table[index][1];\ | 574 n = table[index][1];\ |
596 \ | 575 \ |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 else | 712 else |
734 return 2 - get_bits1(gb); | 713 return 2 - get_bits1(gb); |
735 } | 714 } |
736 | 715 |
737 static inline int get_bits_left(GetBitContext *gb) | 716 static inline int get_bits_left(GetBitContext *gb) |
738 { | 717 { |
739 return gb->size_in_bits - get_bits_count(gb); | 718 return gb->size_in_bits - get_bits_count(gb); |
740 } | 719 } |
741 | 720 |
742 #endif /* AVCODEC_GET_BITS_H */ | 721 #endif /* AVCODEC_GET_BITS_H */ |
OLD | NEW |