summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--liba52/bitstream.c8
-rw-r--r--liba52/bitstream.h33
2 files changed, 39 insertions, 2 deletions
diff --git a/liba52/bitstream.c b/liba52/bitstream.c
index 0a48cab2c4..9c01de8ff7 100644
--- a/liba52/bitstream.c
+++ b/liba52/bitstream.c
@@ -31,7 +31,12 @@
#define BUFFER_SIZE 4096
+#ifdef ALT_BITSTREAM_READER
+int indx=0;
+uint32_t * buffer_start;
+#else
static uint32_t * buffer_start;
+#endif
uint32_t bits_left;
uint32_t current_word;
@@ -43,6 +48,9 @@ void bitstream_set_ptr (uint8_t * buf)
align = (int)buf & 3;
buffer_start = (uint32_t *) (buf - align);
bits_left = 0;
+#ifdef ALT_BITSTREAM_READER
+ indx=0;
+#endif
bitstream_get (align * 8);
}
diff --git a/liba52/bitstream.h b/liba52/bitstream.h
index 0be249e1f2..0b7e31dcc9 100644
--- a/liba52/bitstream.h
+++ b/liba52/bitstream.h
@@ -21,6 +21,9 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+// alternative (faster) bitstram reader (reades upto 3 bytes over the end of the input)
+#define ALT_BITSTREAM_READER
+
/* (stolen from the kernel) */
#ifdef WORDS_BIGENDIAN
@@ -46,18 +49,33 @@
# endif
#endif
+#ifdef ALT_BITSTREAM_READER
+extern uint32_t *buffer_start;
+extern int indx;
+#else
extern uint32_t bits_left;
extern uint32_t current_word;
+#endif
void bitstream_set_ptr (uint8_t * buf);
uint32_t bitstream_get_bh(uint32_t num_bits);
int32_t bitstream_get_bh_2(uint32_t num_bits);
+
static inline uint32_t
-bitstream_get(uint32_t num_bits)
+bitstream_get(uint32_t num_bits) // note num_bits is practically a constant due to inlineing
{
+#ifdef ALT_BITSTREAM_READER
+ uint32_t result= swab32( *(uint32_t *)(((uint8_t *)buffer_start)+(indx>>3)) );
+
+ result<<= (indx&0x07);
+ result>>= 32 - num_bits;
+ indx+= num_bits;
+
+ return result;
+#else
uint32_t result;
-
+
if(num_bits < bits_left) {
result = (current_word << (32 - bits_left)) >> (32 - num_bits);
bits_left -= num_bits;
@@ -65,11 +83,21 @@ bitstream_get(uint32_t num_bits)
}
return bitstream_get_bh(num_bits);
+#endif
}
static inline int32_t
bitstream_get_2(uint32_t num_bits)
{
+#ifdef ALT_BITSTREAM_READER
+ int32_t result= swab32( *(uint32_t *)(((uint8_t *)buffer_start)+(indx>>3)) );
+
+ result<<= (indx&0x07);
+ result>>= 32 - num_bits;
+ indx+= num_bits;
+
+ return result;
+#else
int32_t result;
if(num_bits < bits_left) {
@@ -79,4 +107,5 @@ bitstream_get_2(uint32_t num_bits)
}
return bitstream_get_bh_2(num_bits);
+#endif
}