Mercurial > libavcodec.hg
annotate common.h @ 20:907b67420d84 libavcodec
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
author | arpi_esp |
---|---|
date | Fri, 03 Aug 2001 23:09:15 +0000 |
parents | f439e6867cac |
children | 20e680e7a490 |
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 |
0 | 83 void align_get_bits(GetBitContext *s); |
84 int init_vlc(VLC *vlc, int nb_bits, int nb_codes, | |
85 const void *bits, int bits_wrap, int bits_size, | |
86 const void *codes, int codes_wrap, int codes_size); | |
87 void free_vlc(VLC *vlc); | |
88 int get_vlc(GetBitContext *s, VLC *vlc); | |
89 | |
90 /* macro to go faster */ | |
91 /* n must be <= 24 */ | |
92 /* XXX: optimize buffer end test */ | |
93 #define SHOW_BITS(s, val, n)\ | |
94 {\ | |
95 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\ | |
96 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\ | |
97 bit_cnt += 8;\ | |
98 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\ | |
99 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\ | |
100 bit_cnt += 8;\ | |
101 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\ | |
102 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\ | |
103 bit_cnt += 8;\ | |
104 }\ | |
105 }\ | |
106 }\ | |
107 val = bit_buf >> (32 - n);\ | |
108 } | |
109 | |
110 /* SHOW_BITS with n1 >= n must be been done before */ | |
111 #define FLUSH_BITS(n)\ | |
112 {\ | |
113 bit_buf <<= n;\ | |
114 bit_cnt -= n;\ | |
115 } | |
116 | |
117 #define SAVE_BITS(s) \ | |
118 {\ | |
119 bit_cnt = (s)->bit_cnt;\ | |
120 bit_buf = (s)->bit_buf;\ | |
121 buf_ptr = (s)->buf_ptr;\ | |
122 } | |
123 | |
124 #define RESTORE_BITS(s) \ | |
125 {\ | |
126 (s)->buf_ptr = buf_ptr;\ | |
127 (s)->bit_buf = bit_buf;\ | |
128 (s)->bit_cnt = bit_cnt;\ | |
129 } | |
130 | |
131 /* define it to include statistics code (useful only for optimizing | |
132 codec efficiency */ | |
133 //#define STATS | |
134 | |
135 #ifdef STATS | |
136 | |
137 enum { | |
138 ST_UNKNOWN, | |
139 ST_DC, | |
140 ST_INTRA_AC, | |
141 ST_INTER_AC, | |
142 ST_INTRA_MB, | |
143 ST_INTER_MB, | |
144 ST_MV, | |
145 ST_NB, | |
146 }; | |
147 | |
148 extern int st_current_index; | |
149 extern unsigned int st_bit_counts[ST_NB]; | |
150 extern unsigned int st_out_bit_counts[ST_NB]; | |
151 | |
152 void print_stats(void); | |
153 #endif | |
154 | |
155 /* misc math functions */ | |
156 | |
157 extern inline int log2(unsigned int v) | |
158 { | |
159 int n; | |
160 | |
161 n = 0; | |
162 if (v & 0xffff0000) { | |
163 v >>= 16; | |
164 n += 16; | |
165 } | |
166 if (v & 0xff00) { | |
167 v >>= 8; | |
168 n += 8; | |
169 } | |
170 if (v & 0xf0) { | |
171 v >>= 4; | |
172 n += 4; | |
173 } | |
174 if (v & 0xc) { | |
175 v >>= 2; | |
176 n += 2; | |
177 } | |
178 if (v & 0x2) { | |
179 n++; | |
180 } | |
181 return n; | |
182 } | |
183 | |
184 /* memory */ | |
185 void *av_mallocz(int size); | |
186 | |
187 #endif |