#endif
#if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER)
-# if ARCH_ARM
+# if ARCH_ARM && !HAVE_FAST_UNALIGNED
# define A32_BITSTREAM_READER
# else
# define ALT_BITSTREAM_READER
# endif
#endif
-extern const uint8_t ff_reverse[256];
-
-#if ARCH_X86
-// avoid +32 for shift optimization (gcc should do that ...)
-static inline int32_t NEG_SSR32( int32_t a, int8_t s){
- __asm__ ("sarl %1, %0\n\t"
- : "+r" (a)
- : "ic" ((uint8_t)(-s))
- );
- return a;
-}
-static inline uint32_t NEG_USR32(uint32_t a, int8_t s){
- __asm__ ("shrl %1, %0\n\t"
- : "+r" (a)
- : "ic" ((uint8_t)(-s))
- );
- return a;
-}
-#else
-# define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))
-# define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
-#endif
-
/* bit input */
/* buffer, buffer_end and size_in_bits must be present and used by every reader */
typedef struct GetBitContext {
# define MIN_CACHE_BITS 25
# define OPEN_READER(name, gb)\
- int name##_index= (gb)->index;\
+ unsigned int name##_index= (gb)->index;\
int name##_cache= 0;\
# define CLOSE_READER(name, gb)\
# ifdef ALT_BITSTREAM_READER_LE
# define SHOW_UBITS(name, gb, num)\
- ((name##_cache) & (NEG_USR32(0xffffffff,num)))
+ zero_extend(name##_cache, num)
# define SHOW_SBITS(name, gb, num)\
- NEG_SSR32((name##_cache)<<(32-(num)), num)
+ sign_extend(name##_cache, num)
# else
# define SHOW_UBITS(name, gb, num)\
NEG_USR32(name##_cache, num)
# define GET_CACHE(name, gb)\
((uint32_t)name##_cache)
-static inline int get_bits_count(GetBitContext *s){
+static inline int get_bits_count(const GetBitContext *s){
return s->index;
}
# define GET_CACHE(name, gb)\
((uint32_t)name##_cache)
-static inline int get_bits_count(GetBitContext *s){
+static inline int get_bits_count(const GetBitContext *s){
return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count;
}
# define GET_CACHE(name, gb)\
(name##_cache0)
-static inline int get_bits_count(GetBitContext *s){
+static inline int get_bits_count(const GetBitContext *s){
return ((uint8_t*)s->buffer_ptr - s->buffer)*8 - 32 + s->bit_count;
}
static inline unsigned int get_bits1(GetBitContext *s){
#ifdef ALT_BITSTREAM_READER
- int index= s->index;
+ unsigned int index= s->index;
uint8_t result= s->buffer[ index>>3 ];
#ifdef ALT_BITSTREAM_READER_LE
result>>= (index&0x07);
* reads 0-32 bits.
*/
static inline unsigned int get_bits_long(GetBitContext *s, int n){
- if(n<=17) return get_bits(s, n);
+ if(n<=MIN_CACHE_BITS) return get_bits(s, n);
else{
#ifdef ALT_BITSTREAM_READER_LE
int ret= get_bits(s, 16);
* shows 0-32 bits.
*/
static inline unsigned int show_bits_long(GetBitContext *s, int n){
- if(n<=17) return show_bits(s, n);
+ if(n<=MIN_CACHE_BITS) return show_bits(s, n);
else{
GetBitContext gb= *s;
return get_bits_long(&gb, n);
/**
*
- * if the vlc code is invalid and max_depth=1 than no bits will be removed
- * if the vlc code is invalid and max_depth>1 than the number of bits removed
- * is undefined
+ * If the vlc code is invalid and max_depth=1, then no bits will be removed.
+ * If the vlc code is invalid and max_depth>1, then the number of bits removed
+ * is undefined.
*/
#define GET_VLC(code, name, gb, table, bits, max_depth)\
{\
- int n, index, nb_bits;\
+ int n, nb_bits;\
+ unsigned int index;\
\
index= SHOW_UBITS(name, gb, bits);\
code = table[index][0];\
#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\
{\
- int n, index, nb_bits;\
+ int n, nb_bits;\
+ unsigned int index;\
\
index= SHOW_UBITS(name, gb, bits);\
level = table[index].level;\
return 2 - get_bits1(gb);
}
+static inline int get_bits_left(GetBitContext *gb)
+{
+ return gb->size_in_bits - get_bits_count(gb);
+}
+
#endif /* AVCODEC_GET_BITS_H */