Mercurial > libavcodec.hg
annotate common.h @ 59:efd3c19f6d62 libavcodec
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
| author | glantau |
|---|---|
| date | Sun, 12 Aug 2001 00:52:01 +0000 |
| parents | 20e680e7a490 |
| children | 5aa6292a1660 |
| rev | line source |
|---|---|
| 0 | 1 #ifndef COMMON_H |
| 2 #define COMMON_H | |
| 3 | |
| 10 | 4 #ifdef HAVE_AV_CONFIG_H |
| 0 | 5 #include "../config.h" |
| 10 | 6 #endif |
| 0 | 7 |
| 2 | 8 #ifndef __WINE_WINDEF16_H |
| 9 /* workaround for typedef conflict in MPlayer (wine typedefs) */ | |
| 0 | 10 typedef unsigned short UINT16; |
| 11 typedef signed short INT16; | |
| 12 #endif | |
| 13 | |
| 14 typedef unsigned char UINT8; | |
| 15 typedef unsigned int UINT32; | |
| 16 typedef unsigned long long UINT64; | |
| 17 typedef signed char INT8; | |
| 18 typedef signed int INT32; | |
| 19 typedef signed long long INT64; | |
| 20 | |
| 21 /* bit output */ | |
| 22 | |
| 23 struct PutBitContext; | |
| 24 | |
| 25 typedef void (*WriteDataFunc)(void *, UINT8 *, int); | |
| 26 | |
| 27 typedef struct PutBitContext { | |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
28 UINT32 bit_buf; |
| 0 | 29 int bit_cnt; |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
30 UINT8 *buf, *buf_ptr, *buf_end; |
| 0 | 31 long long data_out_size; /* in bytes */ |
| 32 void *opaque; | |
| 33 WriteDataFunc write_data; | |
| 34 } PutBitContext; | |
| 35 | |
| 36 void init_put_bits(PutBitContext *s, | |
| 37 UINT8 *buffer, int buffer_size, | |
| 38 void *opaque, | |
| 39 void (*write_data)(void *, UINT8 *, int)); | |
| 40 void put_bits(PutBitContext *s, int n, unsigned int value); | |
| 41 long long get_bit_count(PutBitContext *s); | |
| 42 void align_put_bits(PutBitContext *s); | |
| 43 void flush_put_bits(PutBitContext *s); | |
| 44 | |
| 45 /* jpeg specific put_bits */ | |
| 46 void jput_bits(PutBitContext *s, int n, unsigned int value); | |
| 47 void jflush_put_bits(PutBitContext *s); | |
| 48 | |
| 49 /* bit input */ | |
| 50 | |
| 51 typedef struct GetBitContext { | |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
52 UINT32 bit_buf; |
| 0 | 53 int bit_cnt; |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
54 UINT8 *buf, *buf_ptr, *buf_end; |
| 0 | 55 } GetBitContext; |
| 56 | |
| 57 typedef struct VLC { | |
| 58 int bits; | |
| 59 INT16 *table_codes; | |
| 60 INT8 *table_bits; | |
| 61 int table_size, table_allocated; | |
| 62 } VLC; | |
| 63 | |
| 64 void init_get_bits(GetBitContext *s, | |
| 65 UINT8 *buffer, int buffer_size); | |
| 66 | |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
67 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
|
68 |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
69 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
|
70 if(s->bit_cnt>=n){ |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
71 /* most common case here */ |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
72 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
|
73 s->bit_buf <<= n; |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
74 s->bit_cnt -= n; |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
75 #ifdef STATS |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
76 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
|
77 #endif |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
78 return val; |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
79 } |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
80 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
|
81 } |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
82 |
| 21 | 83 static inline unsigned int get_bits1(GetBitContext *s){ |
| 84 if(s->bit_cnt>0){ | |
| 85 /* most common case here */ | |
| 86 unsigned int val = s->bit_buf >> 31; | |
| 87 s->bit_buf <<= 1; | |
| 88 s->bit_cnt--; | |
| 89 #ifdef STATS | |
| 90 st_bit_counts[st_current_index]++; | |
| 91 #endif | |
| 92 return val; | |
| 93 } | |
| 94 return get_bits_long(s,1); | |
| 95 } | |
| 96 | |
| 97 static inline void skip_bits(GetBitContext *s, int n){ | |
| 98 if(s->bit_cnt>=n){ | |
| 99 /* most common case here */ | |
| 100 s->bit_buf <<= n; | |
| 101 s->bit_cnt -= n; | |
| 102 #ifdef STATS | |
| 103 st_bit_counts[st_current_index] += n; | |
| 104 #endif | |
| 105 } else { | |
| 106 get_bits_long(s,n); | |
| 107 } | |
| 108 } | |
| 109 | |
| 110 static inline void skip_bits1(GetBitContext *s){ | |
| 111 if(s->bit_cnt>0){ | |
| 112 /* most common case here */ | |
| 113 s->bit_buf <<= 1; | |
| 114 s->bit_cnt--; | |
| 115 #ifdef STATS | |
| 116 st_bit_counts[st_current_index]++; | |
| 117 #endif | |
| 118 } else { | |
| 119 get_bits_long(s,1); | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 | |
| 0 | 124 void align_get_bits(GetBitContext *s); |
| 125 int init_vlc(VLC *vlc, int nb_bits, int nb_codes, | |
| 126 const void *bits, int bits_wrap, int bits_size, | |
| 127 const void *codes, int codes_wrap, int codes_size); | |
| 128 void free_vlc(VLC *vlc); | |
| 129 int get_vlc(GetBitContext *s, VLC *vlc); | |
| 130 | |
| 131 /* macro to go faster */ | |
| 132 /* n must be <= 24 */ | |
| 133 /* XXX: optimize buffer end test */ | |
| 134 #define SHOW_BITS(s, val, n)\ | |
| 135 {\ | |
| 136 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\ | |
| 137 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\ | |
| 138 bit_cnt += 8;\ | |
| 139 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\ | |
| 140 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\ | |
| 141 bit_cnt += 8;\ | |
| 142 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\ | |
| 143 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\ | |
| 144 bit_cnt += 8;\ | |
| 145 }\ | |
| 146 }\ | |
| 147 }\ | |
| 148 val = bit_buf >> (32 - n);\ | |
| 149 } | |
| 150 | |
| 151 /* SHOW_BITS with n1 >= n must be been done before */ | |
| 152 #define FLUSH_BITS(n)\ | |
| 153 {\ | |
| 154 bit_buf <<= n;\ | |
| 155 bit_cnt -= n;\ | |
| 156 } | |
| 157 | |
| 158 #define SAVE_BITS(s) \ | |
| 159 {\ | |
| 160 bit_cnt = (s)->bit_cnt;\ | |
| 161 bit_buf = (s)->bit_buf;\ | |
| 162 buf_ptr = (s)->buf_ptr;\ | |
| 163 } | |
| 164 | |
| 165 #define RESTORE_BITS(s) \ | |
| 166 {\ | |
| 167 (s)->buf_ptr = buf_ptr;\ | |
| 168 (s)->bit_buf = bit_buf;\ | |
| 169 (s)->bit_cnt = bit_cnt;\ | |
| 170 } | |
| 171 | |
| 172 /* define it to include statistics code (useful only for optimizing | |
| 173 codec efficiency */ | |
| 174 //#define STATS | |
| 175 | |
| 176 #ifdef STATS | |
| 177 | |
| 178 enum { | |
| 179 ST_UNKNOWN, | |
| 180 ST_DC, | |
| 181 ST_INTRA_AC, | |
| 182 ST_INTER_AC, | |
| 183 ST_INTRA_MB, | |
| 184 ST_INTER_MB, | |
| 185 ST_MV, | |
| 186 ST_NB, | |
| 187 }; | |
| 188 | |
| 189 extern int st_current_index; | |
| 190 extern unsigned int st_bit_counts[ST_NB]; | |
| 191 extern unsigned int st_out_bit_counts[ST_NB]; | |
| 192 | |
| 193 void print_stats(void); | |
| 194 #endif | |
| 195 | |
| 196 /* misc math functions */ | |
| 197 | |
| 198 extern inline int log2(unsigned int v) | |
| 199 { | |
| 200 int n; | |
| 201 | |
| 202 n = 0; | |
| 203 if (v & 0xffff0000) { | |
| 204 v >>= 16; | |
| 205 n += 16; | |
| 206 } | |
| 207 if (v & 0xff00) { | |
| 208 v >>= 8; | |
| 209 n += 8; | |
| 210 } | |
| 211 if (v & 0xf0) { | |
| 212 v >>= 4; | |
| 213 n += 4; | |
| 214 } | |
| 215 if (v & 0xc) { | |
| 216 v >>= 2; | |
| 217 n += 2; | |
| 218 } | |
| 219 if (v & 0x2) { | |
| 220 n++; | |
| 221 } | |
| 222 return n; | |
| 223 } | |
| 224 | |
| 225 /* memory */ | |
| 226 void *av_mallocz(int size); | |
| 227 | |
| 228 #endif |
