annotate common.h @ 85:b0bdab6b8bc6 libavcodec

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