Mercurial > libavcodec.hg
annotate common.h @ 66:2bb522261514 libavcodec
log2 to av_log2 - added integer version define
| author | glantau |
|---|---|
| date | Wed, 15 Aug 2001 13:09:28 +0000 |
| parents | 5aa6292a1660 |
| children | 0b09bd08ef4b |
| rev | line source |
|---|---|
| 0 | 1 #ifndef COMMON_H |
| 2 #define COMMON_H | |
| 3 | |
| 66 | 4 #define FFMPEG_VERSION_INT 0x000405 |
| 5 #define FFMPEG_VERSION "0.4.5" | |
| 64 | 6 |
| 7 #ifdef WIN32 | |
| 8 #define CONFIG_WIN32 | |
| 9 #endif | |
| 10 | |
| 10 | 11 #ifdef HAVE_AV_CONFIG_H |
| 64 | 12 /* only include the following when compiling package */ |
| 0 | 13 #include "../config.h" |
| 64 | 14 |
| 15 #include <stdlib.h> | |
| 16 #include <stdio.h> | |
| 17 #include <string.h> | |
| 18 #include <errno.h> | |
| 19 | |
| 20 #ifndef ENODATA | |
| 21 #define ENODATA 61 | |
| 10 | 22 #endif |
| 0 | 23 |
| 64 | 24 #endif |
| 25 | |
| 26 #ifdef CONFIG_WIN32 | |
| 27 | |
| 28 /* windows */ | |
| 29 | |
| 30 typedef unsigned short UINT16; | |
| 31 typedef signed short INT16; | |
| 32 typedef unsigned char UINT8; | |
| 33 typedef unsigned int UINT32; | |
| 34 typedef unsigned __int64 UINT64; | |
| 35 typedef signed char INT8; | |
| 36 typedef signed int INT32; | |
| 37 typedef signed __int64 INT64; | |
| 38 | |
| 39 typedef UINT8 uint8_t; | |
| 40 typedef INT8 int8_t; | |
| 41 typedef UINT16 uint16_t; | |
| 42 typedef INT16 int16_t; | |
| 43 typedef UINT32 uint32_t; | |
| 44 typedef INT32 int32_t; | |
| 45 | |
| 46 #define INT64_C(c) (c ## i64) | |
| 47 #define UINT64_C(c) (c ## i64) | |
| 48 | |
| 49 #define inline __inline | |
| 50 | |
| 51 /* | |
| 52 Disable warning messages: | |
| 53 warning C4244: '=' : conversion from 'double' to 'float', possible loss of data | |
| 54 warning C4305: 'argument' : truncation from 'const double' to 'float' | |
| 55 */ | |
| 56 #pragma warning( disable : 4244 ) | |
| 57 #pragma warning( disable : 4305 ) | |
| 58 | |
| 59 #define M_PI 3.14159265358979323846 | |
| 60 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ | |
| 61 | |
| 62 #ifdef _DEBUG | |
| 63 #define DEBUG | |
| 64 #endif | |
| 65 | |
| 66 // code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc. | |
| 67 #define bswap_32(x) \ | |
| 68 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ | |
| 69 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) | |
| 70 #define be2me_32(x) bswap_32(x) | |
| 71 | |
| 72 #define snprintf _snprintf | |
| 73 | |
| 74 #define CONFIG_ENCODERS 1 | |
| 75 #define CONFIG_DECODERS 1 | |
| 76 #define CONFIG_AC3 1 | |
| 77 #define CONFIG_MPGLIB 1 | |
| 78 | |
| 79 #else | |
| 80 | |
| 81 /* unix */ | |
| 82 | |
| 83 #include <inttypes.h> | |
| 84 | |
| 2 | 85 #ifndef __WINE_WINDEF16_H |
| 86 /* workaround for typedef conflict in MPlayer (wine typedefs) */ | |
| 0 | 87 typedef unsigned short UINT16; |
| 88 typedef signed short INT16; | |
| 89 #endif | |
| 90 | |
| 91 typedef unsigned char UINT8; | |
| 92 typedef unsigned int UINT32; | |
| 93 typedef unsigned long long UINT64; | |
| 94 typedef signed char INT8; | |
| 95 typedef signed int INT32; | |
| 96 typedef signed long long INT64; | |
| 97 | |
| 64 | 98 #ifdef HAVE_AV_CONFIG_H |
| 99 | |
| 100 #ifdef __FreeBSD__ | |
| 101 #include <sys/param.h> | |
| 102 #endif | |
| 103 | |
| 104 #ifndef INT64_C | |
| 105 #define INT64_C(c) (c ## LL) | |
| 106 #define UINT64_C(c) (c ## ULL) | |
| 107 #endif | |
| 108 | |
| 109 #include "../bswap.h" | |
| 110 | |
| 111 #ifdef USE_FASTMEMCPY | |
| 112 #include "fastmemcpy.h" | |
| 113 #endif | |
| 114 | |
| 115 #ifndef DEBUG | |
| 116 #define NDEBUG | |
| 117 #endif | |
| 118 #include <assert.h> | |
| 119 | |
| 120 #endif /* HAVE_AV_CONFIG_H */ | |
| 121 | |
| 122 #endif /* !CONFIG_WIN32 */ | |
| 123 | |
| 0 | 124 /* bit output */ |
| 125 | |
| 126 struct PutBitContext; | |
| 127 | |
| 128 typedef void (*WriteDataFunc)(void *, UINT8 *, int); | |
| 129 | |
| 130 typedef struct PutBitContext { | |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
131 UINT32 bit_buf; |
| 0 | 132 int bit_cnt; |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
133 UINT8 *buf, *buf_ptr, *buf_end; |
| 64 | 134 INT64 data_out_size; /* in bytes */ |
| 0 | 135 void *opaque; |
| 136 WriteDataFunc write_data; | |
| 137 } PutBitContext; | |
| 138 | |
| 139 void init_put_bits(PutBitContext *s, | |
| 140 UINT8 *buffer, int buffer_size, | |
| 141 void *opaque, | |
| 142 void (*write_data)(void *, UINT8 *, int)); | |
| 143 void put_bits(PutBitContext *s, int n, unsigned int value); | |
| 64 | 144 INT64 get_bit_count(PutBitContext *s); |
| 0 | 145 void align_put_bits(PutBitContext *s); |
| 146 void flush_put_bits(PutBitContext *s); | |
| 147 | |
| 148 /* jpeg specific put_bits */ | |
| 149 void jput_bits(PutBitContext *s, int n, unsigned int value); | |
| 150 void jflush_put_bits(PutBitContext *s); | |
| 151 | |
| 152 /* bit input */ | |
| 153 | |
| 154 typedef struct GetBitContext { | |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
155 UINT32 bit_buf; |
| 0 | 156 int bit_cnt; |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
157 UINT8 *buf, *buf_ptr, *buf_end; |
| 0 | 158 } GetBitContext; |
| 159 | |
| 160 typedef struct VLC { | |
| 161 int bits; | |
| 162 INT16 *table_codes; | |
| 163 INT8 *table_bits; | |
| 164 int table_size, table_allocated; | |
| 165 } VLC; | |
| 166 | |
| 167 void init_get_bits(GetBitContext *s, | |
| 168 UINT8 *buffer, int buffer_size); | |
| 169 | |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
170 unsigned int get_bits_long(GetBitContext *s, int n); |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
171 |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
172 static inline unsigned int get_bits(GetBitContext *s, int n){ |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
173 if(s->bit_cnt>=n){ |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
174 /* most common case here */ |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
175 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
|
176 s->bit_buf <<= n; |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
177 s->bit_cnt -= n; |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
178 #ifdef STATS |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
179 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
|
180 #endif |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
181 return val; |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
182 } |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
183 return get_bits_long(s,n); |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
184 } |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
185 |
| 21 | 186 static inline unsigned int get_bits1(GetBitContext *s){ |
| 187 if(s->bit_cnt>0){ | |
| 188 /* most common case here */ | |
| 189 unsigned int val = s->bit_buf >> 31; | |
| 190 s->bit_buf <<= 1; | |
| 191 s->bit_cnt--; | |
| 192 #ifdef STATS | |
| 193 st_bit_counts[st_current_index]++; | |
| 194 #endif | |
| 195 return val; | |
| 196 } | |
| 197 return get_bits_long(s,1); | |
| 198 } | |
| 199 | |
| 200 static inline void skip_bits(GetBitContext *s, int n){ | |
| 201 if(s->bit_cnt>=n){ | |
| 202 /* most common case here */ | |
| 203 s->bit_buf <<= n; | |
| 204 s->bit_cnt -= n; | |
| 205 #ifdef STATS | |
| 206 st_bit_counts[st_current_index] += n; | |
| 207 #endif | |
| 208 } else { | |
| 209 get_bits_long(s,n); | |
| 210 } | |
| 211 } | |
| 212 | |
| 213 static inline void skip_bits1(GetBitContext *s){ | |
| 214 if(s->bit_cnt>0){ | |
| 215 /* most common case here */ | |
| 216 s->bit_buf <<= 1; | |
| 217 s->bit_cnt--; | |
| 218 #ifdef STATS | |
| 219 st_bit_counts[st_current_index]++; | |
| 220 #endif | |
| 221 } else { | |
| 222 get_bits_long(s,1); | |
| 223 } | |
| 224 } | |
| 225 | |
| 226 | |
| 0 | 227 void align_get_bits(GetBitContext *s); |
| 228 int init_vlc(VLC *vlc, int nb_bits, int nb_codes, | |
| 229 const void *bits, int bits_wrap, int bits_size, | |
| 230 const void *codes, int codes_wrap, int codes_size); | |
| 231 void free_vlc(VLC *vlc); | |
| 232 int get_vlc(GetBitContext *s, VLC *vlc); | |
| 233 | |
| 234 /* macro to go faster */ | |
| 235 /* n must be <= 24 */ | |
| 236 /* XXX: optimize buffer end test */ | |
| 237 #define SHOW_BITS(s, val, n)\ | |
| 238 {\ | |
| 239 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\ | |
| 240 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\ | |
| 241 bit_cnt += 8;\ | |
| 242 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\ | |
| 243 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\ | |
| 244 bit_cnt += 8;\ | |
| 245 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\ | |
| 246 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\ | |
| 247 bit_cnt += 8;\ | |
| 248 }\ | |
| 249 }\ | |
| 250 }\ | |
| 251 val = bit_buf >> (32 - n);\ | |
| 252 } | |
| 253 | |
| 254 /* SHOW_BITS with n1 >= n must be been done before */ | |
| 255 #define FLUSH_BITS(n)\ | |
| 256 {\ | |
| 257 bit_buf <<= n;\ | |
| 258 bit_cnt -= n;\ | |
| 259 } | |
| 260 | |
| 261 #define SAVE_BITS(s) \ | |
| 262 {\ | |
| 263 bit_cnt = (s)->bit_cnt;\ | |
| 264 bit_buf = (s)->bit_buf;\ | |
| 265 buf_ptr = (s)->buf_ptr;\ | |
| 266 } | |
| 267 | |
| 268 #define RESTORE_BITS(s) \ | |
| 269 {\ | |
| 270 (s)->buf_ptr = buf_ptr;\ | |
| 271 (s)->bit_buf = bit_buf;\ | |
| 272 (s)->bit_cnt = bit_cnt;\ | |
| 273 } | |
| 274 | |
| 275 /* define it to include statistics code (useful only for optimizing | |
| 276 codec efficiency */ | |
| 277 //#define STATS | |
| 278 | |
| 279 #ifdef STATS | |
| 280 | |
| 281 enum { | |
| 282 ST_UNKNOWN, | |
| 283 ST_DC, | |
| 284 ST_INTRA_AC, | |
| 285 ST_INTER_AC, | |
| 286 ST_INTRA_MB, | |
| 287 ST_INTER_MB, | |
| 288 ST_MV, | |
| 289 ST_NB, | |
| 290 }; | |
| 291 | |
| 292 extern int st_current_index; | |
| 293 extern unsigned int st_bit_counts[ST_NB]; | |
| 294 extern unsigned int st_out_bit_counts[ST_NB]; | |
| 295 | |
| 296 void print_stats(void); | |
| 297 #endif | |
| 298 | |
| 299 /* misc math functions */ | |
| 300 | |
| 66 | 301 extern inline int av_log2(unsigned int v) |
| 0 | 302 { |
| 303 int n; | |
| 304 | |
| 305 n = 0; | |
| 306 if (v & 0xffff0000) { | |
| 307 v >>= 16; | |
| 308 n += 16; | |
| 309 } | |
| 310 if (v & 0xff00) { | |
| 311 v >>= 8; | |
| 312 n += 8; | |
| 313 } | |
| 314 if (v & 0xf0) { | |
| 315 v >>= 4; | |
| 316 n += 4; | |
| 317 } | |
| 318 if (v & 0xc) { | |
| 319 v >>= 2; | |
| 320 n += 2; | |
| 321 } | |
| 322 if (v & 0x2) { | |
| 323 n++; | |
| 324 } | |
| 325 return n; | |
| 326 } | |
| 327 | |
| 328 /* memory */ | |
| 329 void *av_mallocz(int size); | |
| 330 | |
| 331 #endif |
