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 {
|
|
28 UINT8 *buf, *buf_ptr, *buf_end;
|
|
29 int bit_cnt;
|
|
30 UINT32 bit_buf;
|
|
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 {
|
|
52 UINT8 *buf, *buf_ptr, *buf_end;
|
|
53 int bit_cnt;
|
|
54 UINT32 bit_buf;
|
|
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
|
|
67 unsigned int get_bits(GetBitContext *s, int n);
|
|
68 void align_get_bits(GetBitContext *s);
|
|
69 int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
|
|
70 const void *bits, int bits_wrap, int bits_size,
|
|
71 const void *codes, int codes_wrap, int codes_size);
|
|
72 void free_vlc(VLC *vlc);
|
|
73 int get_vlc(GetBitContext *s, VLC *vlc);
|
|
74
|
|
75 /* macro to go faster */
|
|
76 /* n must be <= 24 */
|
|
77 /* XXX: optimize buffer end test */
|
|
78 #define SHOW_BITS(s, val, n)\
|
|
79 {\
|
|
80 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\
|
|
81 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\
|
|
82 bit_cnt += 8;\
|
|
83 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\
|
|
84 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\
|
|
85 bit_cnt += 8;\
|
|
86 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\
|
|
87 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\
|
|
88 bit_cnt += 8;\
|
|
89 }\
|
|
90 }\
|
|
91 }\
|
|
92 val = bit_buf >> (32 - n);\
|
|
93 }
|
|
94
|
|
95 /* SHOW_BITS with n1 >= n must be been done before */
|
|
96 #define FLUSH_BITS(n)\
|
|
97 {\
|
|
98 bit_buf <<= n;\
|
|
99 bit_cnt -= n;\
|
|
100 }
|
|
101
|
|
102 #define SAVE_BITS(s) \
|
|
103 {\
|
|
104 bit_cnt = (s)->bit_cnt;\
|
|
105 bit_buf = (s)->bit_buf;\
|
|
106 buf_ptr = (s)->buf_ptr;\
|
|
107 }
|
|
108
|
|
109 #define RESTORE_BITS(s) \
|
|
110 {\
|
|
111 (s)->buf_ptr = buf_ptr;\
|
|
112 (s)->bit_buf = bit_buf;\
|
|
113 (s)->bit_cnt = bit_cnt;\
|
|
114 }
|
|
115
|
|
116 /* define it to include statistics code (useful only for optimizing
|
|
117 codec efficiency */
|
|
118 //#define STATS
|
|
119
|
|
120 #ifdef STATS
|
|
121
|
|
122 enum {
|
|
123 ST_UNKNOWN,
|
|
124 ST_DC,
|
|
125 ST_INTRA_AC,
|
|
126 ST_INTER_AC,
|
|
127 ST_INTRA_MB,
|
|
128 ST_INTER_MB,
|
|
129 ST_MV,
|
|
130 ST_NB,
|
|
131 };
|
|
132
|
|
133 extern int st_current_index;
|
|
134 extern unsigned int st_bit_counts[ST_NB];
|
|
135 extern unsigned int st_out_bit_counts[ST_NB];
|
|
136
|
|
137 void print_stats(void);
|
|
138 #endif
|
|
139
|
|
140 /* misc math functions */
|
|
141
|
|
142 extern inline int log2(unsigned int v)
|
|
143 {
|
|
144 int n;
|
|
145
|
|
146 n = 0;
|
|
147 if (v & 0xffff0000) {
|
|
148 v >>= 16;
|
|
149 n += 16;
|
|
150 }
|
|
151 if (v & 0xff00) {
|
|
152 v >>= 8;
|
|
153 n += 8;
|
|
154 }
|
|
155 if (v & 0xf0) {
|
|
156 v >>= 4;
|
|
157 n += 4;
|
|
158 }
|
|
159 if (v & 0xc) {
|
|
160 v >>= 2;
|
|
161 n += 2;
|
|
162 }
|
|
163 if (v & 0x2) {
|
|
164 n++;
|
|
165 }
|
|
166 return n;
|
|
167 }
|
|
168
|
|
169 /* memory */
|
|
170 void *av_mallocz(int size);
|
|
171
|
|
172 #endif
|