aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2002-07-10 17:32:59 +0000
committerMichael Niedermayer <michaelni@gmx.at>2002-07-10 17:32:59 +0000
commitcceabc8656118f2a5478a17264df434a63838691 (patch)
treecac4b5eb72abc56ce7882fc6e30a158137e3cff3 /libavcodec
parent82dd7d0dec29ee59af91ce18c29eb151b363ff37 (diff)
downloadffmpeg-cceabc8656118f2a5478a17264df434a63838691.tar.gz
get_vlc() optimization
Originally committed as revision 735 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/common.c2
-rw-r--r--libavcodec/common.h86
2 files changed, 39 insertions, 49 deletions
diff --git a/libavcodec/common.c b/libavcodec/common.c
index 63d17b6c2b..abfa19072f 100644
--- a/libavcodec/common.c
+++ b/libavcodec/common.c
@@ -286,7 +286,7 @@ static int build_table(VLC *vlc, int table_nb_bits,
return -1;
/* note: realloc has been done, so reload tables */
table = &vlc->table[table_index];
- table[i][0] = index; //code
+ table[i][0] = index - table_index; //code
}
}
return table_index;
diff --git a/libavcodec/common.h b/libavcodec/common.h
index 61eee5f287..35c04a8758 100644
--- a/libavcodec/common.h
+++ b/libavcodec/common.h
@@ -732,64 +732,54 @@ int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
const void *codes, int codes_wrap, int codes_size);
void free_vlc(VLC *vlc);
+//note table will be trashed (pointer increased)
+#define GET_VLC(code, name, gb, table, bits, max_depth)\
+{\
+ int n, index, nb_bits;\
+\
+ index= SHOW_UBITS(name, gb, bits);\
+ code = table[index][0];\
+ n = table[index][1];\
+\
+ if(max_depth > 1 && n < 0){\
+ LAST_SKIP_BITS(name, gb, bits)\
+ UPDATE_CACHE(name, gb)\
+\
+ nb_bits = -n;\
+ table += code;\
+\
+ index= SHOW_UBITS(name, gb, nb_bits);\
+ code = table[index][0];\
+ n = table[index][1];\
+ if(max_depth > 2 && n < 0){\
+ LAST_SKIP_BITS(name, gb, nb_bits)\
+ UPDATE_CACHE(name, gb)\
+\
+ nb_bits = -n;\
+ table += code;\
+\
+ index= SHOW_UBITS(name, gb, nb_bits);\
+ code = table[index][0];\
+ n = table[index][1];\
+ }\
+ }\
+ SKIP_BITS(name, gb, n)\
+}
+
static inline int get_vlc(GetBitContext *s, VLC *vlc)
{
- int code, n, nb_bits, index;
- VLC_TYPE (*table)[2];
+ int code;
+ VLC_TYPE (*table)[2]= vlc->table;
+
OPEN_READER(re, s)
-
UPDATE_CACHE(re, s)
- nb_bits = vlc->bits;
- table = vlc->table;
-
-#ifdef FAST_GET_FIRST_VLC
- index= SHOW_UBITS(re, s, nb_bits);
- code = table[index][0];
- n = table[index][1];
- if (n > 0) {
- /* most common case (90%)*/
- LAST_SKIP_BITS(re, s, n)
- CLOSE_READER(re, s)
- return code;
- } else if (n == 0) {
- return -1;
- } else {
- LAST_SKIP_BITS(re, s, nb_bits)
- UPDATE_CACHE(re, s) //this isnt needed but its faster if its here
+ GET_VLC(code, re, s, table, vlc->bits, 3)
- nb_bits = -n;
- table = vlc->table + code;
- }
-#endif
- for(;;) {
- index= SHOW_UBITS(re, s, nb_bits);
- code = table[index][0];
- n = table[index][1];
- if (n > 0) {
- /* most common case */
- SKIP_BITS(re, s, n)
-#ifdef STATS
- st_bit_counts[st_current_index] += n;
-#endif
- break;
- } else if (n == 0) {
- return -1;
- } else {
- LAST_SKIP_BITS(re, s, nb_bits)
- UPDATE_CACHE(re, s)
-#ifdef STATS
- st_bit_counts[st_current_index] += nb_bits;
-#endif
- nb_bits = -n;
- table = vlc->table + code;
- }
- }
CLOSE_READER(re, s)
return code;
}
-
/* define it to include statistics code (useful only for optimizing
codec efficiency */
//#define STATS