summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2002-01-10 00:56:05 +0000
committerMichael Niedermayer <michaelni@gmx.at>2002-01-10 00:56:05 +0000
commit27a3e2c5e036b3199416b5c055a7db775e8f0620 (patch)
treed8f82222487d0eb3cfb29308773d69302c11ec85 /libavcodec
parentbff6ecaa9c707f31be6143946df3a7ac88ee6c9e (diff)
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
Originally committed as revision 252 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/common.c16
-rw-r--r--libavcodec/common.h65
-rw-r--r--libavcodec/mpegaudiodec.c14
3 files changed, 94 insertions, 1 deletions
diff --git a/libavcodec/common.c b/libavcodec/common.c
index aa45c35339..3c7bd64a98 100644
--- a/libavcodec/common.c
+++ b/libavcodec/common.c
@@ -15,6 +15,8 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * alternative bitstream reader by Michael Niedermayer <michaelni@gmx.at>
*/
#include "common.h"
#include <math.h>
@@ -174,6 +176,10 @@ void jflush_put_bits(PutBitContext *s)
void init_get_bits(GetBitContext *s,
UINT8 *buffer, int buffer_size)
{
+#ifdef ALT_BITSTREAM_READER
+ s->index=0;
+ s->buffer= buffer;
+#else
s->buf = buffer;
s->buf_ptr = buffer;
s->buf_end = buffer + buffer_size;
@@ -184,8 +190,10 @@ void init_get_bits(GetBitContext *s,
s->bit_buf |= (*s->buf_ptr++ << (24 - s->bit_cnt));
s->bit_cnt += 8;
}
+#endif
}
+#ifndef ALT_BITSTREAM_READER
/* n must be >= 1 and <= 32 */
/* also true: n > s->bit_cnt */
unsigned int get_bits_long(GetBitContext *s, int n)
@@ -241,15 +249,22 @@ unsigned int get_bits_long(GetBitContext *s, int n)
s->bit_cnt = bit_cnt;
return val;
}
+#endif
void align_get_bits(GetBitContext *s)
{
+#ifdef ALT_BITSTREAM_READER
+ s->index= (s->index + 7) & (~7);
+#else
int n;
n = s->bit_cnt & 7;
if (n > 0) {
get_bits(s, n);
}
+#endif
}
+
+#ifndef ALT_BITSTREAM_READER
/* This function is identical to get_bits_long(), the */
/* only diference is that it doesn't touch the buffer */
/* it is usefull to see the buffer. */
@@ -296,6 +311,7 @@ unsigned int show_bits_long(GetBitContext *s, int n)
return val;
}
+#endif
/* VLC decoding */
diff --git a/libavcodec/common.h b/libavcodec/common.h
index d53e70e91b..8ea66f0a8a 100644
--- a/libavcodec/common.h
+++ b/libavcodec/common.h
@@ -8,6 +8,8 @@
#define CONFIG_WIN32
#endif
+//#define ALT_BITSTREAM_READER
+
#ifdef HAVE_AV_CONFIG_H
/* only include the following when compiling package */
#include "../config.h"
@@ -124,6 +126,7 @@ typedef signed long long INT64;
#endif /* !CONFIG_WIN32 */
+
/* debug stuff */
#ifdef HAVE_AV_CONFIG_H
@@ -180,9 +183,14 @@ void jflush_put_bits(PutBitContext *s);
/* bit input */
typedef struct GetBitContext {
+#ifdef ALT_BITSTREAM_READER
+ int index;
+ UINT8 *buffer;
+#else
UINT32 bit_buf;
int bit_cnt;
UINT8 *buf, *buf_ptr, *buf_end;
+#endif
} GetBitContext;
typedef struct VLC {
@@ -195,10 +203,23 @@ typedef struct VLC {
void init_get_bits(GetBitContext *s,
UINT8 *buffer, int buffer_size);
+#ifndef ALT_BITSTREAM_READER
unsigned int get_bits_long(GetBitContext *s, int n);
unsigned int show_bits_long(GetBitContext *s, int n);
+#endif
static inline unsigned int get_bits(GetBitContext *s, int n){
+#ifdef ALT_BITSTREAM_READER
+ int index= s->index;
+ uint32_t result= be2me_32( *(uint32_t *)(((uint8_t *)s->buffer)+(index>>3)) );
+
+ result<<= (index&0x07);
+ result>>= 32 - n;
+ index+= n;
+ s->index= index;
+
+ return result;
+#else
if(s->bit_cnt>=n){
/* most common case here */
unsigned int val = s->bit_buf >> (32 - n);
@@ -210,9 +231,21 @@ static inline unsigned int get_bits(GetBitContext *s, int n){
return val;
}
return get_bits_long(s,n);
+#endif
}
static inline unsigned int get_bits1(GetBitContext *s){
+#ifdef ALT_BITSTREAM_READER
+ int index= s->index;
+ uint32_t result= be2me_32( *(uint32_t *)(((uint8_t *)s->buffer)+(index>>3)) );
+
+ result<<= (index&0x07);
+ result>>= 32 - 1;
+ index++;
+ s->index= index;
+
+ return result;
+#else
if(s->bit_cnt>0){
/* most common case here */
unsigned int val = s->bit_buf >> 31;
@@ -224,6 +257,7 @@ static inline unsigned int get_bits1(GetBitContext *s){
return val;
}
return get_bits_long(s,1);
+#endif
}
/* This function is identical to get_bits(), the only */
@@ -231,15 +265,28 @@ static inline unsigned int get_bits1(GetBitContext *s){
/* it is usefull to see the buffer. */
static inline unsigned int show_bits(GetBitContext *s, int n)
{
+#ifdef ALT_BITSTREAM_READER
+ int index= s->index;
+ uint32_t result= be2me_32( *(uint32_t *)(((uint8_t *)s->buffer)+(index>>3)) );
+
+ result<<= (index&0x07);
+ result>>= 32 - n;
+
+ return result;
+#else
if(s->bit_cnt>=n) {
/* most common case here */
unsigned int val = s->bit_buf >> (32 - n);
return val;
}
return show_bits_long(s,n);
+#endif
}
static inline void skip_bits(GetBitContext *s, int n){
+#ifdef ALT_BITSTREAM_READER
+ s->index+= n;
+#else
if(s->bit_cnt>=n){
/* most common case here */
s->bit_buf <<= n;
@@ -250,9 +297,13 @@ static inline void skip_bits(GetBitContext *s, int n){
} else {
get_bits_long(s,n);
}
+#endif
}
static inline void skip_bits1(GetBitContext *s){
+#ifdef ALT_BITSTREAM_READER
+ s->index++;
+#else
if(s->bit_cnt>0){
/* most common case here */
s->bit_buf <<= 1;
@@ -263,11 +314,16 @@ static inline void skip_bits1(GetBitContext *s){
} else {
get_bits_long(s,1);
}
+#endif
}
static inline int get_bits_count(GetBitContext *s)
{
+#ifdef ALT_BITSTREAM_READER
+ return s->index;
+#else
return (s->buf_ptr - s->buf) * 8 - s->bit_cnt;
+#endif
}
void align_get_bits(GetBitContext *s);
@@ -277,6 +333,13 @@ int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
void free_vlc(VLC *vlc);
int get_vlc(GetBitContext *s, VLC *vlc);
+#ifdef ALT_BITSTREAM_READER
+#define SHOW_BITS(s, val, n) val= show_bits(s, n);
+#define FLUSH_BITS(n) skip_bits(s, n);
+#define SAVE_BITS(s) ;
+#define RESTORE_BITS(s) ;
+#else
+
/* macro to go faster */
/* n must be <= 24 */
/* XXX: optimize buffer end test */
@@ -317,7 +380,7 @@ int get_vlc(GetBitContext *s, VLC *vlc);
(s)->bit_buf = bit_buf;\
(s)->bit_cnt = bit_cnt;\
}
-
+#endif // !ALT_BITSTREAM_READER
/* define it to include statistics code (useful only for optimizing
codec efficiency */
//#define STATS
diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c
index bbb3ff1c11..bb86bd0ca4 100644
--- a/libavcodec/mpegaudiodec.c
+++ b/libavcodec/mpegaudiodec.c
@@ -1371,7 +1371,11 @@ static void seek_to_maindata(MPADecodeContext *s, long backstep)
UINT8 *ptr;
/* compute current position in stream */
+#ifdef ALT_BITSTREAM_READER
+ ptr = s->gb.buffer + (s->gb.index>>3);
+#else
ptr = s->gb.buf_ptr - (s->gb.bit_cnt >> 3);
+#endif
/* copy old data before current one */
ptr -= backstep;
memcpy(ptr, s->inbuf1[s->inbuf_index ^ 1] +
@@ -1528,15 +1532,25 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
/* some encoders generate an incorrect size for this
part. We must go back into the data */
s_index -= 4;
+#ifdef ALT_BITSTREAM_READER
+ s->gb.buffer = last_buf_ptr;
+ s->gb.index = last_bit_cnt;
+#else
s->gb.buf_ptr = last_buf_ptr;
s->gb.bit_buf = last_bit_buf;
s->gb.bit_cnt = last_bit_cnt;
+#endif
}
break;
}
+#ifdef ALT_BITSTREAM_READER
+ last_buf_ptr = s->gb.buffer;
+ last_bit_cnt = s->gb.index;
+#else
last_buf_ptr = s->gb.buf_ptr;
last_bit_buf = s->gb.bit_buf;
last_bit_cnt = s->gb.bit_cnt;
+#endif
code = get_vlc(&s->gb, vlc);
dprintf("t=%d code=%d\n", g->count1table_select, code);