[Mplayer-cvslog] CVS: main/liba52 bitstream.c,1.1,1.2 bitstream.h,1.1,1.2
Michael Niedermayer
michael at mplayer.dev.hu
Mon Dec 17 22:53:55 CET 2001
Update of /cvsroot/mplayer/main/liba52
In directory mplayer:/var/tmp.root/cvs-serv15145
Modified Files:
bitstream.c bitstream.h
Log Message:
faster (and simpler) bitstream reader (in C)
Index: bitstream.c
===================================================================
RCS file: /cvsroot/mplayer/main/liba52/bitstream.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- bitstream.c 9 Dec 2001 15:28:44 -0000 1.1
+++ bitstream.c 17 Dec 2001 21:53:49 -0000 1.2
@@ -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 @@
align = (int)buf & 3;
buffer_start = (uint32_t *) (buf - align);
bits_left = 0;
+#ifdef ALT_BITSTREAM_READER
+ indx=0;
+#endif
bitstream_get (align * 8);
}
Index: bitstream.h
===================================================================
RCS file: /cvsroot/mplayer/main/liba52/bitstream.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- bitstream.h 9 Dec 2001 15:28:44 -0000 1.1
+++ bitstream.h 17 Dec 2001 21:53:49 -0000 1.2
@@ -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 @@
}
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 @@
}
return bitstream_get_bh_2(num_bits);
+#endif
}
More information about the MPlayer-cvslog
mailing list