mirror of
https://github.com/mpv-player/mpv
synced 2024-12-22 23:02:37 +00:00
faster (and simpler) bitstream reader (in C)
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@3571 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
61c3a3af34
commit
0b64a4a64a
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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,16 +49,31 @@
|
||||
# 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) {
|
||||
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user