Mercurial > libavcodec.hg
annotate common.h @ 192:1e5f64be86fc libavcodec
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
| author | uid46427 |
|---|---|
| date | Thu, 10 Jan 2002 00:56:05 +0000 |
| parents | ae0516eadae2 |
| children | b691dd3e9088 |
| rev | line source |
|---|---|
| 0 | 1 #ifndef COMMON_H |
| 2 #define COMMON_H | |
| 3 | |
| 86 | 4 #define FFMPEG_VERSION_INT 0x000406 |
| 5 #define FFMPEG_VERSION "0.4.6" | |
| 64 | 6 |
| 76 | 7 #if defined(WIN32) && !defined(__MINGW32__) |
| 64 | 8 #define CONFIG_WIN32 |
| 9 #endif | |
| 10 | |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
11 //#define ALT_BITSTREAM_READER |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
12 |
| 10 | 13 #ifdef HAVE_AV_CONFIG_H |
| 64 | 14 /* only include the following when compiling package */ |
| 0 | 15 #include "../config.h" |
| 64 | 16 |
| 17 #include <stdlib.h> | |
| 18 #include <stdio.h> | |
| 19 #include <string.h> | |
| 20 #include <errno.h> | |
| 21 | |
| 22 #ifndef ENODATA | |
| 23 #define ENODATA 61 | |
| 10 | 24 #endif |
| 0 | 25 |
| 64 | 26 #endif |
| 27 | |
| 28 #ifdef CONFIG_WIN32 | |
| 29 | |
| 30 /* windows */ | |
| 31 | |
| 32 typedef unsigned short UINT16; | |
| 33 typedef signed short INT16; | |
| 34 typedef unsigned char UINT8; | |
| 35 typedef unsigned int UINT32; | |
| 36 typedef unsigned __int64 UINT64; | |
| 37 typedef signed char INT8; | |
| 38 typedef signed int INT32; | |
| 39 typedef signed __int64 INT64; | |
| 40 | |
| 41 typedef UINT8 uint8_t; | |
| 42 typedef INT8 int8_t; | |
| 43 typedef UINT16 uint16_t; | |
| 44 typedef INT16 int16_t; | |
| 45 typedef UINT32 uint32_t; | |
| 46 typedef INT32 int32_t; | |
| 47 | |
| 76 | 48 #ifndef __MINGW32__ |
| 64 | 49 #define INT64_C(c) (c ## i64) |
| 50 #define UINT64_C(c) (c ## i64) | |
| 51 | |
| 52 #define inline __inline | |
| 53 | |
| 54 /* | |
| 55 Disable warning messages: | |
| 56 warning C4244: '=' : conversion from 'double' to 'float', possible loss of data | |
| 57 warning C4305: 'argument' : truncation from 'const double' to 'float' | |
| 58 */ | |
| 59 #pragma warning( disable : 4244 ) | |
| 60 #pragma warning( disable : 4305 ) | |
| 61 | |
| 76 | 62 #else |
| 63 #define INT64_C(c) (c ## LL) | |
| 64 #define UINT64_C(c) (c ## ULL) | |
| 65 #endif /* __MINGW32__ */ | |
| 66 | |
| 64 | 67 #define M_PI 3.14159265358979323846 |
| 68 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ | |
| 69 | |
| 70 #ifdef _DEBUG | |
| 71 #define DEBUG | |
| 72 #endif | |
| 73 | |
| 74 // code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc. | |
| 75 #define bswap_32(x) \ | |
| 76 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ | |
| 77 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) | |
| 78 #define be2me_32(x) bswap_32(x) | |
| 79 | |
| 80 #define snprintf _snprintf | |
| 81 | |
| 76 | 82 #ifndef __MINGW32__ |
| 83 /* no config.h with VC */ | |
| 64 | 84 #define CONFIG_ENCODERS 1 |
| 85 #define CONFIG_DECODERS 1 | |
| 86 #define CONFIG_AC3 1 | |
| 76 | 87 #endif |
| 64 | 88 |
| 89 #else | |
| 90 | |
| 91 /* unix */ | |
| 92 | |
| 93 #include <inttypes.h> | |
| 94 | |
| 2 | 95 #ifndef __WINE_WINDEF16_H |
| 96 /* workaround for typedef conflict in MPlayer (wine typedefs) */ | |
| 0 | 97 typedef unsigned short UINT16; |
| 98 typedef signed short INT16; | |
| 99 #endif | |
| 100 | |
| 101 typedef unsigned char UINT8; | |
| 102 typedef unsigned int UINT32; | |
| 103 typedef unsigned long long UINT64; | |
| 104 typedef signed char INT8; | |
| 105 typedef signed int INT32; | |
| 106 typedef signed long long INT64; | |
| 107 | |
| 64 | 108 #ifdef HAVE_AV_CONFIG_H |
| 109 | |
| 110 #ifdef __FreeBSD__ | |
| 111 #include <sys/param.h> | |
| 112 #endif | |
| 113 | |
| 114 #ifndef INT64_C | |
| 115 #define INT64_C(c) (c ## LL) | |
| 116 #define UINT64_C(c) (c ## ULL) | |
| 117 #endif | |
| 118 | |
| 119 #include "../bswap.h" | |
| 120 | |
| 121 #ifdef USE_FASTMEMCPY | |
| 122 #include "fastmemcpy.h" | |
| 123 #endif | |
| 124 | |
| 76 | 125 #endif /* HAVE_AV_CONFIG_H */ |
| 126 | |
| 127 #endif /* !CONFIG_WIN32 */ | |
| 128 | |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
129 |
| 76 | 130 /* debug stuff */ |
| 131 #ifdef HAVE_AV_CONFIG_H | |
| 132 | |
| 64 | 133 #ifndef DEBUG |
| 134 #define NDEBUG | |
| 135 #endif | |
| 136 #include <assert.h> | |
| 137 | |
| 76 | 138 /* dprintf macros */ |
| 139 #if defined(CONFIG_WIN32) && !defined(__MINGW32__) | |
| 140 | |
| 141 inline void dprintf(const char* fmt,...) {} | |
| 142 | |
| 143 #else | |
| 144 | |
| 145 #ifdef DEBUG | |
| 146 #define dprintf(fmt,args...) printf(fmt, ## args) | |
| 147 #else | |
| 148 #define dprintf(fmt,args...) | |
| 149 #endif | |
| 64 | 150 |
| 151 #endif /* !CONFIG_WIN32 */ | |
| 152 | |
| 76 | 153 #endif /* HAVE_AV_CONFIG_H */ |
| 154 | |
| 0 | 155 /* bit output */ |
| 156 | |
| 157 struct PutBitContext; | |
| 158 | |
| 159 typedef void (*WriteDataFunc)(void *, UINT8 *, int); | |
| 160 | |
| 161 typedef struct PutBitContext { | |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
162 UINT32 bit_buf; |
| 0 | 163 int bit_cnt; |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
164 UINT8 *buf, *buf_ptr, *buf_end; |
| 64 | 165 INT64 data_out_size; /* in bytes */ |
| 0 | 166 void *opaque; |
| 167 WriteDataFunc write_data; | |
| 168 } PutBitContext; | |
| 169 | |
| 170 void init_put_bits(PutBitContext *s, | |
| 171 UINT8 *buffer, int buffer_size, | |
| 172 void *opaque, | |
| 173 void (*write_data)(void *, UINT8 *, int)); | |
| 174 void put_bits(PutBitContext *s, int n, unsigned int value); | |
| 85 | 175 INT64 get_bit_count(PutBitContext *s); /* XXX: change function name */ |
| 0 | 176 void align_put_bits(PutBitContext *s); |
| 177 void flush_put_bits(PutBitContext *s); | |
| 178 | |
| 179 /* jpeg specific put_bits */ | |
| 180 void jput_bits(PutBitContext *s, int n, unsigned int value); | |
| 181 void jflush_put_bits(PutBitContext *s); | |
| 182 | |
| 183 /* bit input */ | |
| 184 | |
| 185 typedef struct GetBitContext { | |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
186 #ifdef ALT_BITSTREAM_READER |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
187 int index; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
188 UINT8 *buffer; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
189 #else |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
190 UINT32 bit_buf; |
| 0 | 191 int bit_cnt; |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
192 UINT8 *buf, *buf_ptr, *buf_end; |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
193 #endif |
| 0 | 194 } GetBitContext; |
| 195 | |
| 196 typedef struct VLC { | |
| 197 int bits; | |
| 198 INT16 *table_codes; | |
| 199 INT8 *table_bits; | |
| 200 int table_size, table_allocated; | |
| 201 } VLC; | |
| 202 | |
| 203 void init_get_bits(GetBitContext *s, | |
| 204 UINT8 *buffer, int buffer_size); | |
| 205 | |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
206 #ifndef ALT_BITSTREAM_READER |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
207 unsigned int get_bits_long(GetBitContext *s, int n); |
| 144 | 208 unsigned int show_bits_long(GetBitContext *s, int n); |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
209 #endif |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
210 |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
211 static inline unsigned int get_bits(GetBitContext *s, int n){ |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
212 #ifdef ALT_BITSTREAM_READER |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
213 int index= s->index; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
214 uint32_t result= be2me_32( *(uint32_t *)(((uint8_t *)s->buffer)+(index>>3)) ); |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
215 |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
216 result<<= (index&0x07); |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
217 result>>= 32 - n; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
218 index+= n; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
219 s->index= index; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
220 |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
221 return result; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
222 #else |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
223 if(s->bit_cnt>=n){ |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
224 /* most common case here */ |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
225 unsigned int val = s->bit_buf >> (32 - n); |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
226 s->bit_buf <<= n; |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
227 s->bit_cnt -= n; |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
228 #ifdef STATS |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
229 st_bit_counts[st_current_index] += n; |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
230 #endif |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
231 return val; |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
232 } |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
233 return get_bits_long(s,n); |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
234 #endif |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
235 } |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
236 |
| 21 | 237 static inline unsigned int get_bits1(GetBitContext *s){ |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
238 #ifdef ALT_BITSTREAM_READER |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
239 int index= s->index; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
240 uint32_t result= be2me_32( *(uint32_t *)(((uint8_t *)s->buffer)+(index>>3)) ); |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
241 |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
242 result<<= (index&0x07); |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
243 result>>= 32 - 1; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
244 index++; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
245 s->index= index; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
246 |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
247 return result; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
248 #else |
| 21 | 249 if(s->bit_cnt>0){ |
| 250 /* most common case here */ | |
| 251 unsigned int val = s->bit_buf >> 31; | |
| 252 s->bit_buf <<= 1; | |
| 253 s->bit_cnt--; | |
| 254 #ifdef STATS | |
| 255 st_bit_counts[st_current_index]++; | |
| 256 #endif | |
| 257 return val; | |
| 258 } | |
| 259 return get_bits_long(s,1); | |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
260 #endif |
| 21 | 261 } |
| 262 | |
| 144 | 263 /* This function is identical to get_bits(), the only */ |
| 264 /* diference is that it doesn't touch the buffer */ | |
| 265 /* it is usefull to see the buffer. */ | |
| 266 static inline unsigned int show_bits(GetBitContext *s, int n) | |
| 267 { | |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
268 #ifdef ALT_BITSTREAM_READER |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
269 int index= s->index; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
270 uint32_t result= be2me_32( *(uint32_t *)(((uint8_t *)s->buffer)+(index>>3)) ); |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
271 |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
272 result<<= (index&0x07); |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
273 result>>= 32 - n; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
274 |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
275 return result; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
276 #else |
| 144 | 277 if(s->bit_cnt>=n) { |
| 278 /* most common case here */ | |
| 279 unsigned int val = s->bit_buf >> (32 - n); | |
| 280 return val; | |
| 281 } | |
| 282 return show_bits_long(s,n); | |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
283 #endif |
| 144 | 284 } |
| 285 | |
| 21 | 286 static inline void skip_bits(GetBitContext *s, int n){ |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
287 #ifdef ALT_BITSTREAM_READER |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
288 s->index+= n; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
289 #else |
| 21 | 290 if(s->bit_cnt>=n){ |
| 291 /* most common case here */ | |
| 292 s->bit_buf <<= n; | |
| 293 s->bit_cnt -= n; | |
| 294 #ifdef STATS | |
| 295 st_bit_counts[st_current_index] += n; | |
| 296 #endif | |
| 297 } else { | |
| 298 get_bits_long(s,n); | |
| 299 } | |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
300 #endif |
| 21 | 301 } |
| 302 | |
| 303 static inline void skip_bits1(GetBitContext *s){ | |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
304 #ifdef ALT_BITSTREAM_READER |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
305 s->index++; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
306 #else |
| 21 | 307 if(s->bit_cnt>0){ |
| 308 /* most common case here */ | |
| 309 s->bit_buf <<= 1; | |
| 310 s->bit_cnt--; | |
| 311 #ifdef STATS | |
| 312 st_bit_counts[st_current_index]++; | |
| 313 #endif | |
| 314 } else { | |
| 315 get_bits_long(s,1); | |
| 316 } | |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
317 #endif |
| 21 | 318 } |
| 319 | |
| 85 | 320 static inline int get_bits_count(GetBitContext *s) |
| 321 { | |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
322 #ifdef ALT_BITSTREAM_READER |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
323 return s->index; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
324 #else |
| 85 | 325 return (s->buf_ptr - s->buf) * 8 - s->bit_cnt; |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
326 #endif |
| 85 | 327 } |
| 21 | 328 |
| 0 | 329 void align_get_bits(GetBitContext *s); |
| 330 int init_vlc(VLC *vlc, int nb_bits, int nb_codes, | |
| 331 const void *bits, int bits_wrap, int bits_size, | |
| 332 const void *codes, int codes_wrap, int codes_size); | |
| 333 void free_vlc(VLC *vlc); | |
| 334 int get_vlc(GetBitContext *s, VLC *vlc); | |
| 335 | |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
336 #ifdef ALT_BITSTREAM_READER |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
337 #define SHOW_BITS(s, val, n) val= show_bits(s, n); |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
338 #define FLUSH_BITS(n) skip_bits(s, n); |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
339 #define SAVE_BITS(s) ; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
340 #define RESTORE_BITS(s) ; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
341 #else |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
342 |
| 0 | 343 /* macro to go faster */ |
| 344 /* n must be <= 24 */ | |
| 345 /* XXX: optimize buffer end test */ | |
| 346 #define SHOW_BITS(s, val, n)\ | |
| 347 {\ | |
| 348 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\ | |
| 349 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\ | |
| 350 bit_cnt += 8;\ | |
| 351 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\ | |
| 352 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\ | |
| 353 bit_cnt += 8;\ | |
| 354 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\ | |
| 355 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\ | |
| 356 bit_cnt += 8;\ | |
| 357 }\ | |
| 358 }\ | |
| 359 }\ | |
| 360 val = bit_buf >> (32 - n);\ | |
| 361 } | |
| 362 | |
| 363 /* SHOW_BITS with n1 >= n must be been done before */ | |
| 364 #define FLUSH_BITS(n)\ | |
| 365 {\ | |
| 366 bit_buf <<= n;\ | |
| 367 bit_cnt -= n;\ | |
| 368 } | |
| 369 | |
| 370 #define SAVE_BITS(s) \ | |
| 371 {\ | |
| 372 bit_cnt = (s)->bit_cnt;\ | |
| 373 bit_buf = (s)->bit_buf;\ | |
| 374 buf_ptr = (s)->buf_ptr;\ | |
| 375 } | |
| 376 | |
| 377 #define RESTORE_BITS(s) \ | |
| 378 {\ | |
| 379 (s)->buf_ptr = buf_ptr;\ | |
| 380 (s)->bit_buf = bit_buf;\ | |
| 381 (s)->bit_cnt = bit_cnt;\ | |
| 382 } | |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
383 #endif // !ALT_BITSTREAM_READER |
| 0 | 384 /* define it to include statistics code (useful only for optimizing |
| 385 codec efficiency */ | |
| 386 //#define STATS | |
| 387 | |
| 388 #ifdef STATS | |
| 389 | |
| 390 enum { | |
| 391 ST_UNKNOWN, | |
| 392 ST_DC, | |
| 393 ST_INTRA_AC, | |
| 394 ST_INTER_AC, | |
| 395 ST_INTRA_MB, | |
| 396 ST_INTER_MB, | |
| 397 ST_MV, | |
| 398 ST_NB, | |
| 399 }; | |
| 400 | |
| 401 extern int st_current_index; | |
| 402 extern unsigned int st_bit_counts[ST_NB]; | |
| 403 extern unsigned int st_out_bit_counts[ST_NB]; | |
| 404 | |
| 405 void print_stats(void); | |
| 406 #endif | |
| 407 | |
| 408 /* misc math functions */ | |
| 409 | |
|
151
ae0516eadae2
fixed gcc-3.0.x compilation (by Michael Niedermayer)
nickols_k
parents:
144
diff
changeset
|
410 static inline int av_log2(unsigned int v) |
| 0 | 411 { |
| 412 int n; | |
| 413 | |
| 414 n = 0; | |
| 415 if (v & 0xffff0000) { | |
| 416 v >>= 16; | |
| 417 n += 16; | |
| 418 } | |
| 419 if (v & 0xff00) { | |
| 420 v >>= 8; | |
| 421 n += 8; | |
| 422 } | |
| 423 if (v & 0xf0) { | |
| 424 v >>= 4; | |
| 425 n += 4; | |
| 426 } | |
| 427 if (v & 0xc) { | |
| 428 v >>= 2; | |
| 429 n += 2; | |
| 430 } | |
| 431 if (v & 0x2) { | |
| 432 n++; | |
| 433 } | |
| 434 return n; | |
| 435 } | |
| 436 | |
| 437 /* memory */ | |
| 438 void *av_mallocz(int size); | |
| 439 | |
| 440 #endif |
