]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/bitstream.h
6% faster decode_cabac_residual
[ffmpeg] / libavcodec / bitstream.h
index fd69915d8f0285b4cf7a35bfb404b55650bfd5c1..0182b630b11ab390c1706849a2e45d0c1c10ec4a 100644 (file)
@@ -53,6 +53,11 @@ typedef struct PutBitContext {
 
 static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
 {
+    if(buffer_size < 0) {
+        buffer_size = 0;
+        buffer = NULL;
+    }
+
     s->buf = buffer;
     s->buf_end = s->buf + buffer_size;
 #ifdef ALT_BITSTREAM_WRITER
@@ -95,7 +100,7 @@ static inline void flush_put_bits(PutBitContext *s)
 }
 
 void align_put_bits(PutBitContext *s);
-void put_string(PutBitContext * pbc, char *s, int put_zero);
+void ff_put_string(PutBitContext * pbc, char *s, int put_zero);
 
 /* bit input */
 /* buffer, buffer_end and size_in_bits must be present and used by every reader */
@@ -130,7 +135,7 @@ typedef struct RL_VLC_ELEM {
     uint8_t run;
 } RL_VLC_ELEM;
 
-#ifdef ARCH_SPARC
+#if defined(ARCH_SPARC) || defined(ARCH_ARMV4L)
 #define UNALIGNED_STORES_ARE_BAD
 #endif
 
@@ -334,14 +339,14 @@ GET_CACHE(name, gb)
     will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit)
 
 SHOW_UBITS(name, gb, num)
-    will return the nest num bits
+    will return the next num bits
 
 SHOW_SBITS(name, gb, num)
-    will return the nest num bits and do sign extension
+    will return the next num bits and do sign extension
 
 SKIP_BITS(name, gb, num)
     will skip over the next num bits
-    note, this is equinvalent to SKIP_CACHE; SKIP_COUNTER
+    note, this is equivalent to SKIP_CACHE; SKIP_COUNTER
 
 SKIP_CACHE(name, gb, num)
     will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER)
@@ -353,7 +358,7 @@ LAST_SKIP_CACHE(name, gb, num)
     will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing
 
 LAST_SKIP_BITS(name, gb, num)
-    is equinvalent to SKIP_LAST_CACHE; SKIP_COUNTER
+    is equivalent to SKIP_LAST_CACHE; SKIP_COUNTER
 
 for examples see get_bits, show_bits, skip_bits, get_vlc
 */
@@ -368,6 +373,16 @@ static inline int unaligned32_be(const void *v)
 #endif
 }
 
+static inline int unaligned32_le(const void *v)
+{
+#ifdef CONFIG_ALIGN
+       const uint8_t *p=v;
+       return (((p[3]<<8) | p[2])<<16) | (p[1]<<8) | (p[0]);
+#else
+       return le2me_32( unaligned32(v)); //original
+#endif
+}
+
 #ifdef ALT_BITSTREAM_READER
 #   define MIN_CACHE_BITS 25
 
@@ -378,11 +393,19 @@ static inline int unaligned32_be(const void *v)
 #   define CLOSE_READER(name, gb)\
         (gb)->index= name##_index;\
 
+# ifdef ALT_BITSTREAM_READER_LE
+#   define UPDATE_CACHE(name, gb)\
+        name##_cache= unaligned32_le( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\
+
+#   define SKIP_CACHE(name, gb, num)\
+        name##_cache >>= (num);
+# else
 #   define UPDATE_CACHE(name, gb)\
         name##_cache= unaligned32_be( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\
 
 #   define SKIP_CACHE(name, gb, num)\
-        name##_cache <<= (num);\
+        name##_cache <<= (num);
+# endif
 
 // FIXME name?
 #   define SKIP_COUNTER(name, gb, num)\
@@ -397,8 +420,13 @@ static inline int unaligned32_be(const void *v)
 #   define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num)
 #   define LAST_SKIP_CACHE(name, gb, num) ;
 
+# ifdef ALT_BITSTREAM_READER_LE
+#   define SHOW_UBITS(name, gb, num)\
+        ((name##_cache) & (NEG_USR32(0xffffffff,num)))
+# else
 #   define SHOW_UBITS(name, gb, num)\
         NEG_USR32(name##_cache, num)
+# endif
 
 #   define SHOW_SBITS(name, gb, num)\
         NEG_SSR32(name##_cache, num)
@@ -575,7 +603,7 @@ static inline int get_sbits(GetBitContext *s, int n){
 
 /**
  * reads 0-17 bits.
- * Note, the alt bitstream reader can read upto 25 bits, but the libmpeg2 reader cant
+ * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
  */
 static inline unsigned int get_bits(GetBitContext *s, int n){
     register int tmp;
@@ -591,7 +619,7 @@ unsigned int get_bits_long(GetBitContext *s, int n);
 
 /**
  * shows 0-17 bits.
- * Note, the alt bitstream reader can read upto 25 bits, but the libmpeg2 reader cant
+ * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
  */
 static inline unsigned int show_bits(GetBitContext *s, int n){
     register int tmp;
@@ -616,8 +644,13 @@ static inline unsigned int get_bits1(GetBitContext *s){
 #ifdef ALT_BITSTREAM_READER
     int index= s->index;
     uint8_t result= s->buffer[ index>>3 ];
+#ifdef ALT_BITSTREAM_READER_LE
+    result>>= (index&0x07);
+    result&= 1;
+#else
     result<<= (index&0x07);
     result>>= 8 - 1;
+#endif
     index++;
     s->index= index;
 
@@ -644,7 +677,11 @@ static inline void skip_bits1(GetBitContext *s){
 static inline void init_get_bits(GetBitContext *s,
                    const uint8_t *buffer, int bit_size)
 {
-    const int buffer_size= (bit_size+7)>>3;
+    int buffer_size= (bit_size+7)>>3;
+    if(buffer_size < 0 || bit_size < 0) {
+        buffer_size = bit_size = 0;
+        buffer = NULL;
+    }
 
     s->buffer= buffer;
     s->size_in_bits= bit_size;
@@ -687,7 +724,9 @@ void align_get_bits(GetBitContext *s);
 int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
              const void *bits, int bits_wrap, int bits_size,
              const void *codes, int codes_wrap, int codes_size,
-             int use_static);
+             int flags);
+#define INIT_VLC_USE_STATIC 1
+#define INIT_VLC_LE         2
 void free_vlc(VLC *vlc);
 
 /**