diff options
author | jep <jep@2b0047a9-a6d8-0310-accf-f7200b2a168c> | 2012-04-22 06:36:31 +0000 |
---|---|---|
committer | jep <jep@2b0047a9-a6d8-0310-accf-f7200b2a168c> | 2012-04-22 06:36:31 +0000 |
commit | ed5f65bf0df19e68271c0e5090e56496355a002f (patch) | |
tree | 9d1ca1b1d3e7d1efcc64a92393eed429555a198d /src | |
parent | cafeda68c464962b0205ef8ea095f5b7abc355b6 (diff) |
* src/bitstream.h:
Fix some more bugs in the optimized path and reenable it again.
git-svn-id: https://core.fluendo.com/gstreamer/svn/trunk/gst-fluendo-mp3@2273 2b0047a9-a6d8-0310-accf-f7200b2a168c
Diffstat (limited to 'src')
-rw-r--r-- | src/bitstream.h | 73 |
1 files changed, 47 insertions, 26 deletions
diff --git a/src/bitstream.h b/src/bitstream.h index a90c5c7..f732f9e 100644 --- a/src/bitstream.h +++ b/src/bitstream.h @@ -16,7 +16,7 @@ #include <gst/gst.h> /* Accumulator optimization on bitstream management */ -#define ENABLE_OPT_BS 0 +#define ENABLE_OPT_BS 1 /* Bit stream reader definitions */ #define MAX_LENGTH 32 /* Maximum length of word written or @@ -160,7 +160,11 @@ static inline void h_byte_align (huffdec_bitbuf * bb); static inline guint h_bytes_avail (huffdec_bitbuf * bb); /* Return the current bit stream position (in bits) */ +#if ENABLE_OPT_BS +#define h_sstell(bb) ((bb->buf_byte_idx * 8) - bb->buf_bit_idx) +#else #define h_sstell(bb) ((bb->buf_byte_idx * 8) + (BS_ACUM_SIZE - bb->buf_bit_idx)) +#endif static inline guint32 bs_get1bit (Bit_stream_struc * bs) @@ -380,34 +384,51 @@ h_get1bit (huffdec_bitbuf * bb) static inline void h_flushbits (huffdec_bitbuf * bb, guint N) { - guint bits = N % 8; - guint bytes = N / 8; - guint acc_bytes; - - if (bb->buf_bit_idx >= bits) - bb->buf_bit_idx -= bits; - - acc_bytes = bb->buf_bit_idx / 8; - - if (acc_bytes >= bytes) - bb->buf_bit_idx -= bytes * 8; - else { - bb->buf_bit_idx -= acc_bytes * 8; - bytes -= acc_bytes; - if (bytes <= bb->remaining) { - bytes--; - bits = 8 - bb->buf_bit_idx; - if (bytes > 0) { - bb->buf += bytes; - bb->remaining -= bytes; + guint bits; + guint bytes; + + if (N < 32) { + bits = N; + } else { + N -= bb->buf_bit_idx; + bytes = N >> 3; + bits = N & 0x7; + bb->buf_byte_idx += bytes; + bb->remaining -= bytes; + bb->buf_bit_idx = 0; + + if (bb->remaining >= 4) { + /* reload the accumulator */ + bb->buf_bit_idx = 32; /* subtract 1 bit */ + bb->remaining -= 4; + + /* we need reverse the byte order */ + #if defined(HAVE_CPU_I386) && !defined (_MSC_VER) + register guint32 tmp = *((guint32 *) (bb->buf + bb->buf_byte_idx)); + __asm__ ("bswap %0 \n\t": "=r" (tmp):"0" (tmp)); + bb->accumulator = tmp; + #else + bb->accumulator = (guint32) bb->buf[bb->buf_byte_idx + 3]; + bb->accumulator |= (guint32) (bb->buf[bb->buf_byte_idx + 2]) << 8; + bb->accumulator |= (guint32) (bb->buf[bb->buf_byte_idx + 1]) << 16; + bb->accumulator |= (guint32) (bb->buf[bb->buf_byte_idx + 0]) << 24; + #endif + bb->buf_byte_idx += 4; + } else if (bb->remaining > 0) { + /* reload the accumulator */ + bb->buf_bit_idx = (bb->remaining * 8) - 1; /* subtract 1 bit */ + + bb->accumulator = 0; + /* load remaining bytes into the accumulator in the right order */ + for (; bb->remaining > 0; bb->remaining--) { + bb->accumulator <<= 8; + bb->accumulator |= (guint32) bb->buf[bb->buf_byte_idx++]; } - bb->buf_bit_idx = 0; - h_getbits (bb, bits); - } else { - bb->remaining = 0; - bb->buf_bit_idx = 0; } } + + if (bits) + h_getbits (bb, bits); } #else |