diff options
author | Mohamed Tarek <mt@rockbox.org> | 2009-08-15 22:06:42 +0000 |
---|---|---|
committer | Mohamed Tarek <mt@rockbox.org> | 2009-08-15 22:06:42 +0000 |
commit | adf3f09251db5269214952820732ae39f859ba25 (patch) | |
tree | 0f352b8619b9d1906beaf397cca0bf8350da72a5 | |
parent | 29ac0a6278d6f5967e80b82333d40a46b77e5e64 (diff) | |
download | rockbox-adf3f09251db5269214952820732ae39f859ba25.tar.gz rockbox-adf3f09251db5269214952820732ae39f859ba25.zip |
Move bitstream.[ch] to codecs/lib/ffmpeg_bitstream.[ch] to avoid duplicate copies across codecs.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22337 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/codecs/lib/ffmpeg_bitstream.c (renamed from apps/codecs/libatrac/bitstream.c) | 2 | ||||
-rw-r--r-- | apps/codecs/lib/ffmpeg_bitstream.h (renamed from apps/codecs/libcook/bitstream.h) | 2 | ||||
-rw-r--r-- | apps/codecs/libatrac/Makefile.test | 4 | ||||
-rw-r--r-- | apps/codecs/libatrac/SOURCES | 2 | ||||
-rw-r--r-- | apps/codecs/libatrac/atrac3.h | 2 | ||||
-rw-r--r-- | apps/codecs/libatrac/bitstream.h | 963 | ||||
-rw-r--r-- | apps/codecs/libatrac/ffmpeg_config.h | 14 | ||||
-rw-r--r-- | apps/codecs/libcook/Makefile.test | 4 | ||||
-rw-r--r-- | apps/codecs/libcook/SOURCES | 2 | ||||
-rw-r--r-- | apps/codecs/libcook/bitstream.c | 276 | ||||
-rw-r--r-- | apps/codecs/libcook/cook.h | 2 | ||||
-rw-r--r-- | apps/codecs/libcook/ffmpeg_config.h | 14 | ||||
-rw-r--r-- | apps/codecs/libwma/SOURCES | 2 | ||||
-rw-r--r-- | apps/codecs/libwma/bitstream.c | 271 | ||||
-rw-r--r-- | apps/codecs/libwma/bitstream.h | 989 | ||||
-rw-r--r-- | apps/codecs/libwma/ffmpeg_config.h | 14 | ||||
-rw-r--r-- | apps/codecs/libwma/wmadec.h | 2 | ||||
-rw-r--r-- | apps/codecs/libwma/wmadeci.c | 28 |
18 files changed, 40 insertions, 2553 deletions
diff --git a/apps/codecs/libatrac/bitstream.c b/apps/codecs/lib/ffmpeg_bitstream.c index 1375134b21..88e3cbfe3a 100644 --- a/apps/codecs/libatrac/bitstream.c +++ b/apps/codecs/lib/ffmpeg_bitstream.c | |||
@@ -22,7 +22,7 @@ | |||
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include "bitstream.h" | 25 | #include "ffmpeg_bitstream.h" |
26 | 26 | ||
27 | #ifdef ROCKBOX | 27 | #ifdef ROCKBOX |
28 | #undef DEBUGF | 28 | #undef DEBUGF |
diff --git a/apps/codecs/libcook/bitstream.h b/apps/codecs/lib/ffmpeg_bitstream.h index c4b5496d00..f0105a4afe 100644 --- a/apps/codecs/libcook/bitstream.h +++ b/apps/codecs/lib/ffmpeg_bitstream.h | |||
@@ -26,7 +26,7 @@ | |||
26 | //#include <assert.h> | 26 | //#include <assert.h> |
27 | #include <string.h> | 27 | #include <string.h> |
28 | #include <stdio.h> | 28 | #include <stdio.h> |
29 | #include "../lib/ffmpeg_bswap.h" | 29 | #include "ffmpeg_bswap.h" |
30 | 30 | ||
31 | /* The following 2 defines are taken from libavutil/intreadwrite.h */ | 31 | /* The following 2 defines are taken from libavutil/intreadwrite.h */ |
32 | #define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \ | 32 | #define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \ |
diff --git a/apps/codecs/libatrac/Makefile.test b/apps/codecs/libatrac/Makefile.test index f9a1c2f0e6..25843fdeac 100644 --- a/apps/codecs/libatrac/Makefile.test +++ b/apps/codecs/libatrac/Makefile.test | |||
@@ -1,5 +1,5 @@ | |||
1 | CFLAGS = -Wall -O3 -DTEST -D"DEBUGF=printf" -D"ROCKBOX_LITTLE_ENDIAN=1" -D"ICONST_ATTR=" -D"ICODE_ATTR=" | 1 | CFLAGS = -Wall -O3 -I../lib -DTEST -D"DEBUGF=printf" -D"ROCKBOX_LITTLE_ENDIAN=1" -D"ICONST_ATTR=" -D"ICODE_ATTR=" |
2 | OBJS = atrac3.o bitstream.o ../librm/rm.o fixp_math.o ../lib/mdct2.o ../lib/mdct_lookup.o main.o | 2 | OBJS = atrac3.o ../lib/ffmpeg_bitstream.o ../librm/rm.o fixp_math.o ../lib/mdct2.o ../lib/mdct_lookup.o main.o |
3 | 3 | ||
4 | atractest: $(OBJS) | 4 | atractest: $(OBJS) |
5 | gcc -o atractest $(OBJS) | 5 | gcc -o atractest $(OBJS) |
diff --git a/apps/codecs/libatrac/SOURCES b/apps/codecs/libatrac/SOURCES index 9db9ac3dab..76e0385186 100644 --- a/apps/codecs/libatrac/SOURCES +++ b/apps/codecs/libatrac/SOURCES | |||
@@ -1,3 +1,3 @@ | |||
1 | atrac3.c | 1 | atrac3.c |
2 | fixp_math.c | 2 | fixp_math.c |
3 | bitstream.c | 3 | ../lib/ffmpeg_bitstream.c |
diff --git a/apps/codecs/libatrac/atrac3.h b/apps/codecs/libatrac/atrac3.h index e4121d7b4e..f81fc0a734 100644 --- a/apps/codecs/libatrac/atrac3.h +++ b/apps/codecs/libatrac/atrac3.h | |||
@@ -1,4 +1,4 @@ | |||
1 | #include "bitstream.h" | 1 | #include "ffmpeg_bitstream.h" |
2 | #include "../librm/rm.h" | 2 | #include "../librm/rm.h" |
3 | 3 | ||
4 | /* These structures are needed to store the parsed gain control data. */ | 4 | /* These structures are needed to store the parsed gain control data. */ |
diff --git a/apps/codecs/libatrac/bitstream.h b/apps/codecs/libatrac/bitstream.h deleted file mode 100644 index c4b5496d00..0000000000 --- a/apps/codecs/libatrac/bitstream.h +++ /dev/null | |||
@@ -1,963 +0,0 @@ | |||
1 | /* | ||
2 | * copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at> | ||
3 | * | ||
4 | * This file is part of FFmpeg. | ||
5 | * | ||
6 | * FFmpeg is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * FFmpeg is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with FFmpeg; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | #ifndef BITSTREAM_H | ||
22 | #define BITSTREAM_H | ||
23 | |||
24 | #include <inttypes.h> | ||
25 | #include <stdlib.h> | ||
26 | //#include <assert.h> | ||
27 | #include <string.h> | ||
28 | #include <stdio.h> | ||
29 | #include "../lib/ffmpeg_bswap.h" | ||
30 | |||
31 | /* The following 2 defines are taken from libavutil/intreadwrite.h */ | ||
32 | #define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \ | ||
33 | (((const uint8_t*)(x))[1] << 16) | \ | ||
34 | (((const uint8_t*)(x))[2] << 8) | \ | ||
35 | ((const uint8_t*)(x))[3]) | ||
36 | #define AV_WB32(p, d) do { \ | ||
37 | ((uint8_t*)(p))[3] = (d); \ | ||
38 | ((uint8_t*)(p))[2] = (d)>>8; \ | ||
39 | ((uint8_t*)(p))[1] = (d)>>16; \ | ||
40 | ((uint8_t*)(p))[0] = (d)>>24; } while(0) | ||
41 | |||
42 | #if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER) | ||
43 | # define ALT_BITSTREAM_READER | ||
44 | #endif | ||
45 | |||
46 | //#define ALT_BITSTREAM_WRITER | ||
47 | //#define ALIGNED_BITSTREAM_WRITER | ||
48 | #if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER) | ||
49 | # if defined(ARCH_ARM) | ||
50 | # define A32_BITSTREAM_READER | ||
51 | # else | ||
52 | # define ALT_BITSTREAM_READER | ||
53 | //#define LIBMPEG2_BITSTREAM_READER | ||
54 | //#define A32_BITSTREAM_READER | ||
55 | # endif | ||
56 | #endif | ||
57 | |||
58 | extern const uint8_t ff_reverse[256]; | ||
59 | |||
60 | #if defined(ARCH_X86) | ||
61 | // avoid +32 for shift optimization (gcc should do that ...) | ||
62 | static inline int32_t NEG_SSR32( int32_t a, int8_t s){ | ||
63 | __asm__ ("sarl %1, %0\n\t" | ||
64 | : "+r" (a) | ||
65 | : "ic" ((uint8_t)(-s)) | ||
66 | ); | ||
67 | return a; | ||
68 | } | ||
69 | static inline uint32_t NEG_USR32(uint32_t a, int8_t s){ | ||
70 | __asm__ ("shrl %1, %0\n\t" | ||
71 | : "+r" (a) | ||
72 | : "ic" ((uint8_t)(-s)) | ||
73 | ); | ||
74 | return a; | ||
75 | } | ||
76 | #else | ||
77 | # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s))) | ||
78 | # define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s))) | ||
79 | #endif | ||
80 | |||
81 | /* bit output */ | ||
82 | |||
83 | /* buf and buf_end must be present and used by every alternative writer. */ | ||
84 | typedef struct PutBitContext { | ||
85 | #ifdef ALT_BITSTREAM_WRITER | ||
86 | uint8_t *buf, *buf_end; | ||
87 | int index; | ||
88 | #else | ||
89 | uint32_t bit_buf; | ||
90 | int bit_left; | ||
91 | uint8_t *buf, *buf_ptr, *buf_end; | ||
92 | #endif | ||
93 | int size_in_bits; | ||
94 | } PutBitContext; | ||
95 | |||
96 | static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size) | ||
97 | { | ||
98 | if(buffer_size < 0) { | ||
99 | buffer_size = 0; | ||
100 | buffer = NULL; | ||
101 | } | ||
102 | |||
103 | s->size_in_bits= 8*buffer_size; | ||
104 | s->buf = buffer; | ||
105 | s->buf_end = s->buf + buffer_size; | ||
106 | #ifdef ALT_BITSTREAM_WRITER | ||
107 | s->index=0; | ||
108 | ((uint32_t*)(s->buf))[0]=0; | ||
109 | // memset(buffer, 0, buffer_size); | ||
110 | #else | ||
111 | s->buf_ptr = s->buf; | ||
112 | s->bit_left=32; | ||
113 | s->bit_buf=0; | ||
114 | #endif | ||
115 | } | ||
116 | |||
117 | /* return the number of bits output */ | ||
118 | static inline int put_bits_count(PutBitContext *s) | ||
119 | { | ||
120 | #ifdef ALT_BITSTREAM_WRITER | ||
121 | return s->index; | ||
122 | #else | ||
123 | return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left; | ||
124 | #endif | ||
125 | } | ||
126 | |||
127 | /* pad the end of the output stream with zeros */ | ||
128 | static inline void flush_put_bits(PutBitContext *s) | ||
129 | { | ||
130 | #ifdef ALT_BITSTREAM_WRITER | ||
131 | align_put_bits(s); | ||
132 | #else | ||
133 | #ifndef BITSTREAM_WRITER_LE | ||
134 | s->bit_buf<<= s->bit_left; | ||
135 | #endif | ||
136 | while (s->bit_left < 32) { | ||
137 | /* XXX: should test end of buffer */ | ||
138 | #ifdef BITSTREAM_WRITER_LE | ||
139 | *s->buf_ptr++=s->bit_buf; | ||
140 | s->bit_buf>>=8; | ||
141 | #else | ||
142 | *s->buf_ptr++=s->bit_buf >> 24; | ||
143 | s->bit_buf<<=8; | ||
144 | #endif | ||
145 | s->bit_left+=8; | ||
146 | } | ||
147 | s->bit_left=32; | ||
148 | s->bit_buf=0; | ||
149 | #endif | ||
150 | } | ||
151 | |||
152 | void align_put_bits(PutBitContext *s); | ||
153 | void ff_put_string(PutBitContext * pbc, const char *s, int put_zero); | ||
154 | void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length); | ||
155 | |||
156 | /* bit input */ | ||
157 | /* buffer, buffer_end and size_in_bits must be present and used by every reader */ | ||
158 | typedef struct GetBitContext { | ||
159 | const uint8_t *buffer, *buffer_end; | ||
160 | #ifdef ALT_BITSTREAM_READER | ||
161 | int index; | ||
162 | #elif defined LIBMPEG2_BITSTREAM_READER | ||
163 | uint8_t *buffer_ptr; | ||
164 | uint32_t cache; | ||
165 | int bit_count; | ||
166 | #elif defined A32_BITSTREAM_READER | ||
167 | uint32_t *buffer_ptr; | ||
168 | uint32_t cache0; | ||
169 | uint32_t cache1; | ||
170 | int bit_count; | ||
171 | #endif | ||
172 | int size_in_bits; | ||
173 | } GetBitContext; | ||
174 | |||
175 | #define VLC_TYPE int16_t | ||
176 | |||
177 | typedef struct VLC { | ||
178 | int bits; | ||
179 | VLC_TYPE (*table)[2]; ///< code, bits | ||
180 | int table_size, table_allocated; | ||
181 | } VLC; | ||
182 | |||
183 | typedef struct RL_VLC_ELEM { | ||
184 | int16_t level; | ||
185 | int8_t len; | ||
186 | uint8_t run; | ||
187 | } RL_VLC_ELEM; | ||
188 | |||
189 | #ifndef ALT_BITSTREAM_WRITER | ||
190 | static inline void put_bits(PutBitContext *s, int n, unsigned int value) | ||
191 | { | ||
192 | unsigned int bit_buf; | ||
193 | int bit_left; | ||
194 | |||
195 | // printf("put_bits=%d %x\n", n, value); | ||
196 | //assert(n == 32 || value < (1U << n)); | ||
197 | |||
198 | bit_buf = s->bit_buf; | ||
199 | bit_left = s->bit_left; | ||
200 | |||
201 | // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf); | ||
202 | /* XXX: optimize */ | ||
203 | #ifdef BITSTREAM_WRITER_LE | ||
204 | bit_buf |= value << (32 - bit_left); | ||
205 | if (n >= bit_left) { | ||
206 | #if !HAVE_FAST_UNALIGNED | ||
207 | if (3 & (intptr_t) s->buf_ptr) { | ||
208 | AV_WL32(s->buf_ptr, bit_buf); | ||
209 | } else | ||
210 | #endif | ||
211 | *(uint32_t *)s->buf_ptr = le2me_32(bit_buf); | ||
212 | s->buf_ptr+=4; | ||
213 | bit_buf = (bit_left==32)?0:value >> bit_left; | ||
214 | bit_left+=32; | ||
215 | } | ||
216 | bit_left-=n; | ||
217 | #else | ||
218 | if (n < bit_left) { | ||
219 | bit_buf = (bit_buf<<n) | value; | ||
220 | bit_left-=n; | ||
221 | } else { | ||
222 | bit_buf<<=bit_left; | ||
223 | bit_buf |= value >> (n - bit_left); | ||
224 | #if !defined(HAVE_FAST_UNALIGNED) | ||
225 | if (3 & (intptr_t) s->buf_ptr) { | ||
226 | AV_WB32(s->buf_ptr, bit_buf); | ||
227 | } else | ||
228 | #endif | ||
229 | *(uint32_t *)s->buf_ptr = be2me_32(bit_buf); | ||
230 | //printf("bitbuf = %08x\n", bit_buf); | ||
231 | s->buf_ptr+=4; | ||
232 | bit_left+=32 - n; | ||
233 | bit_buf = value; | ||
234 | } | ||
235 | #endif | ||
236 | |||
237 | s->bit_buf = bit_buf; | ||
238 | s->bit_left = bit_left; | ||
239 | } | ||
240 | #endif | ||
241 | |||
242 | |||
243 | #ifdef ALT_BITSTREAM_WRITER | ||
244 | static inline void put_bits(PutBitContext *s, int n, unsigned int value) | ||
245 | { | ||
246 | # ifdef ALIGNED_BITSTREAM_WRITER | ||
247 | # if ARCH_X86 | ||
248 | __asm__ volatile( | ||
249 | "movl %0, %%ecx \n\t" | ||
250 | "xorl %%eax, %%eax \n\t" | ||
251 | "shrdl %%cl, %1, %%eax \n\t" | ||
252 | "shrl %%cl, %1 \n\t" | ||
253 | "movl %0, %%ecx \n\t" | ||
254 | "shrl $3, %%ecx \n\t" | ||
255 | "andl $0xFFFFFFFC, %%ecx \n\t" | ||
256 | "bswapl %1 \n\t" | ||
257 | "orl %1, (%2, %%ecx) \n\t" | ||
258 | "bswapl %%eax \n\t" | ||
259 | "addl %3, %0 \n\t" | ||
260 | "movl %%eax, 4(%2, %%ecx) \n\t" | ||
261 | : "=&r" (s->index), "=&r" (value) | ||
262 | : "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n)) | ||
263 | : "%eax", "%ecx" | ||
264 | ); | ||
265 | # else | ||
266 | int index= s->index; | ||
267 | uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5); | ||
268 | |||
269 | value<<= 32-n; | ||
270 | |||
271 | ptr[0] |= be2me_32(value>>(index&31)); | ||
272 | ptr[1] = be2me_32(value<<(32-(index&31))); | ||
273 | //if(n>24) printf("%d %d\n", n, value); | ||
274 | index+= n; | ||
275 | s->index= index; | ||
276 | # endif | ||
277 | # else //ALIGNED_BITSTREAM_WRITER | ||
278 | # if ARCH_X86 | ||
279 | __asm__ volatile( | ||
280 | "movl $7, %%ecx \n\t" | ||
281 | "andl %0, %%ecx \n\t" | ||
282 | "addl %3, %%ecx \n\t" | ||
283 | "negl %%ecx \n\t" | ||
284 | "shll %%cl, %1 \n\t" | ||
285 | "bswapl %1 \n\t" | ||
286 | "movl %0, %%ecx \n\t" | ||
287 | "shrl $3, %%ecx \n\t" | ||
288 | "orl %1, (%%ecx, %2) \n\t" | ||
289 | "addl %3, %0 \n\t" | ||
290 | "movl $0, 4(%%ecx, %2) \n\t" | ||
291 | : "=&r" (s->index), "=&r" (value) | ||
292 | : "r" (s->buf), "r" (n), "0" (s->index), "1" (value) | ||
293 | : "%ecx" | ||
294 | ); | ||
295 | # else | ||
296 | int index= s->index; | ||
297 | uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3)); | ||
298 | |||
299 | ptr[0] |= be2me_32(value<<(32-n-(index&7) )); | ||
300 | ptr[1] = 0; | ||
301 | //if(n>24) printf("%d %d\n", n, value); | ||
302 | index+= n; | ||
303 | s->index= index; | ||
304 | # endif | ||
305 | # endif //!ALIGNED_BITSTREAM_WRITER | ||
306 | } | ||
307 | #endif | ||
308 | |||
309 | static inline void put_sbits(PutBitContext *pb, int bits, int32_t val) | ||
310 | { | ||
311 | //assert(bits >= 0 && bits <= 31); | ||
312 | |||
313 | put_bits(pb, bits, val & ((1<<bits)-1)); | ||
314 | } | ||
315 | |||
316 | |||
317 | static inline uint8_t* pbBufPtr(PutBitContext *s) | ||
318 | { | ||
319 | #ifdef ALT_BITSTREAM_WRITER | ||
320 | return s->buf + (s->index>>3); | ||
321 | #else | ||
322 | return s->buf_ptr; | ||
323 | #endif | ||
324 | } | ||
325 | |||
326 | /** | ||
327 | * | ||
328 | * PutBitContext must be flushed & aligned to a byte boundary before calling this. | ||
329 | */ | ||
330 | static inline void skip_put_bytes(PutBitContext *s, int n){ | ||
331 | //assert((put_bits_count(s)&7)==0); | ||
332 | #ifdef ALT_BITSTREAM_WRITER | ||
333 | FIXME may need some cleaning of the buffer | ||
334 | s->index += n<<3; | ||
335 | #else | ||
336 | //assert(s->bit_left==32); | ||
337 | s->buf_ptr += n; | ||
338 | #endif | ||
339 | } | ||
340 | |||
341 | /** | ||
342 | * Skips the given number of bits. | ||
343 | * Must only be used if the actual values in the bitstream do not matter. | ||
344 | */ | ||
345 | static inline void skip_put_bits(PutBitContext *s, int n){ | ||
346 | #ifdef ALT_BITSTREAM_WRITER | ||
347 | s->index += n; | ||
348 | #else | ||
349 | s->bit_left -= n; | ||
350 | s->buf_ptr-= s->bit_left>>5; | ||
351 | s->bit_left &= 31; | ||
352 | #endif | ||
353 | } | ||
354 | |||
355 | /** | ||
356 | * Changes the end of the buffer. | ||
357 | */ | ||
358 | static inline void set_put_bits_buffer_size(PutBitContext *s, int size){ | ||
359 | s->buf_end= s->buf + size; | ||
360 | } | ||
361 | |||
362 | /* Bitstream reader API docs: | ||
363 | name | ||
364 | arbitrary name which is used as prefix for the internal variables | ||
365 | |||
366 | gb | ||
367 | getbitcontext | ||
368 | |||
369 | OPEN_READER(name, gb) | ||
370 | loads gb into local variables | ||
371 | |||
372 | CLOSE_READER(name, gb) | ||
373 | stores local vars in gb | ||
374 | |||
375 | UPDATE_CACHE(name, gb) | ||
376 | refills the internal cache from the bitstream | ||
377 | after this call at least MIN_CACHE_BITS will be available, | ||
378 | |||
379 | GET_CACHE(name, gb) | ||
380 | will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit) | ||
381 | |||
382 | SHOW_UBITS(name, gb, num) | ||
383 | will return the next num bits | ||
384 | |||
385 | SHOW_SBITS(name, gb, num) | ||
386 | will return the next num bits and do sign extension | ||
387 | |||
388 | SKIP_BITS(name, gb, num) | ||
389 | will skip over the next num bits | ||
390 | note, this is equivalent to SKIP_CACHE; SKIP_COUNTER | ||
391 | |||
392 | SKIP_CACHE(name, gb, num) | ||
393 | will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER) | ||
394 | |||
395 | SKIP_COUNTER(name, gb, num) | ||
396 | will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS) | ||
397 | |||
398 | LAST_SKIP_CACHE(name, gb, num) | ||
399 | will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing | ||
400 | |||
401 | LAST_SKIP_BITS(name, gb, num) | ||
402 | is equivalent to SKIP_LAST_CACHE; SKIP_COUNTER | ||
403 | |||
404 | for examples see get_bits, show_bits, skip_bits, get_vlc | ||
405 | */ | ||
406 | |||
407 | #ifdef ALT_BITSTREAM_READER | ||
408 | # define MIN_CACHE_BITS 25 | ||
409 | |||
410 | # define OPEN_READER(name, gb)\ | ||
411 | int name##_index= (gb)->index;\ | ||
412 | int name##_cache= 0;\ | ||
413 | |||
414 | # define CLOSE_READER(name, gb)\ | ||
415 | (gb)->index= name##_index;\ | ||
416 | |||
417 | # ifdef ALT_BITSTREAM_READER_LE | ||
418 | # define UPDATE_CACHE(name, gb)\ | ||
419 | name##_cache= AV_RL32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\ | ||
420 | |||
421 | # define SKIP_CACHE(name, gb, num)\ | ||
422 | name##_cache >>= (num); | ||
423 | # else | ||
424 | # define UPDATE_CACHE(name, gb)\ | ||
425 | name##_cache= AV_RB32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\ | ||
426 | |||
427 | # define SKIP_CACHE(name, gb, num)\ | ||
428 | name##_cache <<= (num); | ||
429 | # endif | ||
430 | |||
431 | // FIXME name? | ||
432 | # define SKIP_COUNTER(name, gb, num)\ | ||
433 | name##_index += (num);\ | ||
434 | |||
435 | # define SKIP_BITS(name, gb, num)\ | ||
436 | {\ | ||
437 | SKIP_CACHE(name, gb, num)\ | ||
438 | SKIP_COUNTER(name, gb, num)\ | ||
439 | }\ | ||
440 | |||
441 | # define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num) | ||
442 | # define LAST_SKIP_CACHE(name, gb, num) ; | ||
443 | |||
444 | # ifdef ALT_BITSTREAM_READER_LE | ||
445 | # define SHOW_UBITS(name, gb, num)\ | ||
446 | ((name##_cache) & (NEG_USR32(0xffffffff,num))) | ||
447 | |||
448 | # define SHOW_SBITS(name, gb, num)\ | ||
449 | NEG_SSR32((name##_cache)<<(32-(num)), num) | ||
450 | # else | ||
451 | # define SHOW_UBITS(name, gb, num)\ | ||
452 | NEG_USR32(name##_cache, num) | ||
453 | |||
454 | # define SHOW_SBITS(name, gb, num)\ | ||
455 | NEG_SSR32(name##_cache, num) | ||
456 | # endif | ||
457 | |||
458 | # define GET_CACHE(name, gb)\ | ||
459 | ((uint32_t)name##_cache) | ||
460 | |||
461 | static inline int get_bits_count(GetBitContext *s){ | ||
462 | return s->index; | ||
463 | } | ||
464 | |||
465 | static inline void skip_bits_long(GetBitContext *s, int n){ | ||
466 | s->index += n; | ||
467 | } | ||
468 | |||
469 | #elif defined LIBMPEG2_BITSTREAM_READER | ||
470 | //libmpeg2 like reader | ||
471 | |||
472 | # define MIN_CACHE_BITS 17 | ||
473 | |||
474 | # define OPEN_READER(name, gb)\ | ||
475 | int name##_bit_count=(gb)->bit_count;\ | ||
476 | int name##_cache= (gb)->cache;\ | ||
477 | uint8_t * name##_buffer_ptr=(gb)->buffer_ptr;\ | ||
478 | |||
479 | # define CLOSE_READER(name, gb)\ | ||
480 | (gb)->bit_count= name##_bit_count;\ | ||
481 | (gb)->cache= name##_cache;\ | ||
482 | (gb)->buffer_ptr= name##_buffer_ptr;\ | ||
483 | |||
484 | # define UPDATE_CACHE(name, gb)\ | ||
485 | if(name##_bit_count >= 0){\ | ||
486 | name##_cache+= AV_RB16(name##_buffer_ptr) << name##_bit_count; \ | ||
487 | name##_buffer_ptr+=2;\ | ||
488 | name##_bit_count-= 16;\ | ||
489 | }\ | ||
490 | |||
491 | # define SKIP_CACHE(name, gb, num)\ | ||
492 | name##_cache <<= (num);\ | ||
493 | |||
494 | # define SKIP_COUNTER(name, gb, num)\ | ||
495 | name##_bit_count += (num);\ | ||
496 | |||
497 | # define SKIP_BITS(name, gb, num)\ | ||
498 | {\ | ||
499 | SKIP_CACHE(name, gb, num)\ | ||
500 | SKIP_COUNTER(name, gb, num)\ | ||
501 | }\ | ||
502 | |||
503 | # define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num) | ||
504 | # define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num) | ||
505 | |||
506 | # define SHOW_UBITS(name, gb, num)\ | ||
507 | NEG_USR32(name##_cache, num) | ||
508 | |||
509 | # define SHOW_SBITS(name, gb, num)\ | ||
510 | NEG_SSR32(name##_cache, num) | ||
511 | |||
512 | # define GET_CACHE(name, gb)\ | ||
513 | ((uint32_t)name##_cache) | ||
514 | |||
515 | static inline int get_bits_count(GetBitContext *s){ | ||
516 | return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count; | ||
517 | } | ||
518 | |||
519 | static inline void skip_bits_long(GetBitContext *s, int n){ | ||
520 | OPEN_READER(re, s) | ||
521 | re_bit_count += n; | ||
522 | re_buffer_ptr += 2*(re_bit_count>>4); | ||
523 | re_bit_count &= 15; | ||
524 | re_cache = ((re_buffer_ptr[-2]<<8) + re_buffer_ptr[-1]) << (16+re_bit_count); | ||
525 | UPDATE_CACHE(re, s) | ||
526 | CLOSE_READER(re, s) | ||
527 | } | ||
528 | |||
529 | #elif defined A32_BITSTREAM_READER | ||
530 | |||
531 | # define MIN_CACHE_BITS 32 | ||
532 | |||
533 | # define OPEN_READER(name, gb)\ | ||
534 | int name##_bit_count=(gb)->bit_count;\ | ||
535 | uint32_t name##_cache0= (gb)->cache0;\ | ||
536 | uint32_t name##_cache1= (gb)->cache1;\ | ||
537 | uint32_t * name##_buffer_ptr=(gb)->buffer_ptr;\ | ||
538 | |||
539 | # define CLOSE_READER(name, gb)\ | ||
540 | (gb)->bit_count= name##_bit_count;\ | ||
541 | (gb)->cache0= name##_cache0;\ | ||
542 | (gb)->cache1= name##_cache1;\ | ||
543 | (gb)->buffer_ptr= name##_buffer_ptr;\ | ||
544 | |||
545 | # define UPDATE_CACHE(name, gb)\ | ||
546 | if(name##_bit_count > 0){\ | ||
547 | const uint32_t next= be2me_32( *name##_buffer_ptr );\ | ||
548 | name##_cache0 |= NEG_USR32(next,name##_bit_count);\ | ||
549 | name##_cache1 |= next<<name##_bit_count;\ | ||
550 | name##_buffer_ptr++;\ | ||
551 | name##_bit_count-= 32;\ | ||
552 | }\ | ||
553 | |||
554 | #if ARCH_X86 | ||
555 | # define SKIP_CACHE(name, gb, num)\ | ||
556 | __asm__(\ | ||
557 | "shldl %2, %1, %0 \n\t"\ | ||
558 | "shll %2, %1 \n\t"\ | ||
559 | : "+r" (name##_cache0), "+r" (name##_cache1)\ | ||
560 | : "Ic" ((uint8_t)(num))\ | ||
561 | ); | ||
562 | #else | ||
563 | # define SKIP_CACHE(name, gb, num)\ | ||
564 | name##_cache0 <<= (num);\ | ||
565 | name##_cache0 |= NEG_USR32(name##_cache1,num);\ | ||
566 | name##_cache1 <<= (num); | ||
567 | #endif | ||
568 | |||
569 | # define SKIP_COUNTER(name, gb, num)\ | ||
570 | name##_bit_count += (num);\ | ||
571 | |||
572 | # define SKIP_BITS(name, gb, num)\ | ||
573 | {\ | ||
574 | SKIP_CACHE(name, gb, num)\ | ||
575 | SKIP_COUNTER(name, gb, num)\ | ||
576 | }\ | ||
577 | |||
578 | # define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num) | ||
579 | # define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num) | ||
580 | |||
581 | # define SHOW_UBITS(name, gb, num)\ | ||
582 | NEG_USR32(name##_cache0, num) | ||
583 | |||
584 | # define SHOW_SBITS(name, gb, num)\ | ||
585 | NEG_SSR32(name##_cache0, num) | ||
586 | |||
587 | # define GET_CACHE(name, gb)\ | ||
588 | (name##_cache0) | ||
589 | |||
590 | static inline int get_bits_count(GetBitContext *s){ | ||
591 | return ((uint8_t*)s->buffer_ptr - s->buffer)*8 - 32 + s->bit_count; | ||
592 | } | ||
593 | |||
594 | static inline void skip_bits_long(GetBitContext *s, int n){ | ||
595 | OPEN_READER(re, s) | ||
596 | re_bit_count += n; | ||
597 | re_buffer_ptr += re_bit_count>>5; | ||
598 | re_bit_count &= 31; | ||
599 | re_cache0 = be2me_32( re_buffer_ptr[-1] ) << re_bit_count; | ||
600 | re_cache1 = 0; | ||
601 | UPDATE_CACHE(re, s) | ||
602 | CLOSE_READER(re, s) | ||
603 | } | ||
604 | |||
605 | #endif | ||
606 | |||
607 | /** | ||
608 | * read mpeg1 dc style vlc (sign bit + mantisse with no MSB). | ||
609 | * if MSB not set it is negative | ||
610 | * @param n length in bits | ||
611 | * @author BERO | ||
612 | */ | ||
613 | static inline int get_xbits(GetBitContext *s, int n){ | ||
614 | register int sign; | ||
615 | register int32_t cache; | ||
616 | OPEN_READER(re, s) | ||
617 | UPDATE_CACHE(re, s) | ||
618 | cache = GET_CACHE(re,s); | ||
619 | sign=(~cache)>>31; | ||
620 | LAST_SKIP_BITS(re, s, n) | ||
621 | CLOSE_READER(re, s) | ||
622 | return (NEG_USR32(sign ^ cache, n) ^ sign) - sign; | ||
623 | } | ||
624 | |||
625 | static inline int get_sbits(GetBitContext *s, int n){ | ||
626 | register int tmp; | ||
627 | OPEN_READER(re, s) | ||
628 | UPDATE_CACHE(re, s) | ||
629 | tmp= SHOW_SBITS(re, s, n); | ||
630 | LAST_SKIP_BITS(re, s, n) | ||
631 | CLOSE_READER(re, s) | ||
632 | return tmp; | ||
633 | } | ||
634 | |||
635 | /** | ||
636 | * reads 1-17 bits. | ||
637 | * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't | ||
638 | */ | ||
639 | static inline unsigned int get_bits(GetBitContext *s, int n){ | ||
640 | register int tmp; | ||
641 | OPEN_READER(re, s) | ||
642 | UPDATE_CACHE(re, s) | ||
643 | tmp= SHOW_UBITS(re, s, n); | ||
644 | LAST_SKIP_BITS(re, s, n) | ||
645 | CLOSE_READER(re, s) | ||
646 | return tmp; | ||
647 | } | ||
648 | |||
649 | /** | ||
650 | * shows 1-17 bits. | ||
651 | * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't | ||
652 | */ | ||
653 | static inline unsigned int show_bits(GetBitContext *s, int n){ | ||
654 | register int tmp; | ||
655 | OPEN_READER(re, s) | ||
656 | UPDATE_CACHE(re, s) | ||
657 | tmp= SHOW_UBITS(re, s, n); | ||
658 | // CLOSE_READER(re, s) | ||
659 | return tmp; | ||
660 | } | ||
661 | |||
662 | static inline void skip_bits(GetBitContext *s, int n){ | ||
663 | //Note gcc seems to optimize this to s->index+=n for the ALT_READER :)) | ||
664 | OPEN_READER(re, s) | ||
665 | UPDATE_CACHE(re, s) | ||
666 | LAST_SKIP_BITS(re, s, n) | ||
667 | CLOSE_READER(re, s) | ||
668 | } | ||
669 | |||
670 | static inline unsigned int get_bits1(GetBitContext *s){ | ||
671 | #ifdef ALT_BITSTREAM_READER | ||
672 | int index= s->index; | ||
673 | uint8_t result= s->buffer[ index>>3 ]; | ||
674 | #ifdef ALT_BITSTREAM_READER_LE | ||
675 | result>>= (index&0x07); | ||
676 | result&= 1; | ||
677 | #else | ||
678 | result<<= (index&0x07); | ||
679 | result>>= 8 - 1; | ||
680 | #endif | ||
681 | index++; | ||
682 | s->index= index; | ||
683 | |||
684 | return result; | ||
685 | #else | ||
686 | return get_bits(s, 1); | ||
687 | #endif | ||
688 | } | ||
689 | |||
690 | static inline unsigned int show_bits1(GetBitContext *s){ | ||
691 | return show_bits(s, 1); | ||
692 | } | ||
693 | |||
694 | static inline void skip_bits1(GetBitContext *s){ | ||
695 | skip_bits(s, 1); | ||
696 | } | ||
697 | |||
698 | /** | ||
699 | * reads 0-32 bits. | ||
700 | */ | ||
701 | static inline unsigned int get_bits_long(GetBitContext *s, int n){ | ||
702 | if(n<=17) return get_bits(s, n); | ||
703 | else{ | ||
704 | #ifdef ALT_BITSTREAM_READER_LE | ||
705 | int ret= get_bits(s, 16); | ||
706 | return ret | (get_bits(s, n-16) << 16); | ||
707 | #else | ||
708 | int ret= get_bits(s, 16) << (n-16); | ||
709 | return ret | get_bits(s, n-16); | ||
710 | #endif | ||
711 | } | ||
712 | } | ||
713 | |||
714 | #if 0 | ||
715 | /** | ||
716 | * reads 0-32 bits as a signed integer. | ||
717 | */ | ||
718 | static inline int get_sbits_long(GetBitContext *s, int n) { | ||
719 | return sign_extend(get_bits_long(s, n), n); | ||
720 | } | ||
721 | #endif | ||
722 | |||
723 | /** | ||
724 | * shows 0-32 bits. | ||
725 | */ | ||
726 | static inline unsigned int show_bits_long(GetBitContext *s, int n){ | ||
727 | if(n<=17) return show_bits(s, n); | ||
728 | else{ | ||
729 | GetBitContext gb= *s; | ||
730 | return get_bits_long(&gb, n); | ||
731 | } | ||
732 | } | ||
733 | |||
734 | #if 0 | ||
735 | static inline int check_marker(GetBitContext *s, const char *msg) | ||
736 | { | ||
737 | int bit= get_bits1(s); | ||
738 | if(!bit) | ||
739 | printf("Marker bit missing %s\n", msg); | ||
740 | |||
741 | return bit; | ||
742 | } | ||
743 | #endif | ||
744 | |||
745 | /** | ||
746 | * init GetBitContext. | ||
747 | * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits | ||
748 | * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end | ||
749 | * @param bit_size the size of the buffer in bits | ||
750 | */ | ||
751 | static inline void init_get_bits(GetBitContext *s, | ||
752 | const uint8_t *buffer, int bit_size) | ||
753 | { | ||
754 | int buffer_size= (bit_size+7)>>3; | ||
755 | if(buffer_size < 0 || bit_size < 0) { | ||
756 | buffer_size = bit_size = 0; | ||
757 | buffer = NULL; | ||
758 | } | ||
759 | |||
760 | s->buffer= buffer; | ||
761 | s->size_in_bits= bit_size; | ||
762 | s->buffer_end= buffer + buffer_size; | ||
763 | #ifdef ALT_BITSTREAM_READER | ||
764 | s->index=0; | ||
765 | #elif defined LIBMPEG2_BITSTREAM_READER | ||
766 | s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1)); | ||
767 | s->bit_count = 16 + 8*((intptr_t)buffer&1); | ||
768 | skip_bits_long(s, 0); | ||
769 | #elif defined A32_BITSTREAM_READER | ||
770 | s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3)); | ||
771 | s->bit_count = 32 + 8*((intptr_t)buffer&3); | ||
772 | skip_bits_long(s, 0); | ||
773 | #endif | ||
774 | } | ||
775 | |||
776 | static inline void align_get_bits(GetBitContext *s) | ||
777 | { | ||
778 | int n= (-get_bits_count(s)) & 7; | ||
779 | if(n) skip_bits(s, n); | ||
780 | } | ||
781 | |||
782 | #define init_vlc(vlc, nb_bits, nb_codes,\ | ||
783 | bits, bits_wrap, bits_size,\ | ||
784 | codes, codes_wrap, codes_size,\ | ||
785 | flags)\ | ||
786 | init_vlc_sparse(vlc, nb_bits, nb_codes,\ | ||
787 | bits, bits_wrap, bits_size,\ | ||
788 | codes, codes_wrap, codes_size,\ | ||
789 | NULL, 0, 0, flags) | ||
790 | |||
791 | int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, | ||
792 | const void *bits, int bits_wrap, int bits_size, | ||
793 | const void *codes, int codes_wrap, int codes_size, | ||
794 | const void *symbols, int symbols_wrap, int symbols_size, | ||
795 | int flags); | ||
796 | #define INIT_VLC_USE_STATIC 1 ///< VERY strongly deprecated and forbidden | ||
797 | #define INIT_VLC_LE 2 | ||
798 | #define INIT_VLC_USE_NEW_STATIC 4 | ||
799 | void free_vlc(VLC *vlc); | ||
800 | |||
801 | #define INIT_VLC_STATIC(vlc, bits, a,b,c,d,e,f,g, static_size)\ | ||
802 | {\ | ||
803 | static VLC_TYPE table[static_size][2];\ | ||
804 | (vlc)->table= table;\ | ||
805 | (vlc)->table_allocated= static_size;\ | ||
806 | init_vlc(vlc, bits, a,b,c,d,e,f,g, INIT_VLC_USE_NEW_STATIC);\ | ||
807 | } | ||
808 | |||
809 | |||
810 | /** | ||
811 | * | ||
812 | * if the vlc code is invalid and max_depth=1 than no bits will be removed | ||
813 | * if the vlc code is invalid and max_depth>1 than the number of bits removed | ||
814 | * is undefined | ||
815 | */ | ||
816 | #define GET_VLC(code, name, gb, table, bits, max_depth)\ | ||
817 | {\ | ||
818 | int n, index, nb_bits;\ | ||
819 | \ | ||
820 | index= SHOW_UBITS(name, gb, bits);\ | ||
821 | code = table[index][0];\ | ||
822 | n = table[index][1];\ | ||
823 | \ | ||
824 | if(max_depth > 1 && n < 0){\ | ||
825 | LAST_SKIP_BITS(name, gb, bits)\ | ||
826 | UPDATE_CACHE(name, gb)\ | ||
827 | \ | ||
828 | nb_bits = -n;\ | ||
829 | \ | ||
830 | index= SHOW_UBITS(name, gb, nb_bits) + code;\ | ||
831 | code = table[index][0];\ | ||
832 | n = table[index][1];\ | ||
833 | if(max_depth > 2 && n < 0){\ | ||
834 | LAST_SKIP_BITS(name, gb, nb_bits)\ | ||
835 | UPDATE_CACHE(name, gb)\ | ||
836 | \ | ||
837 | nb_bits = -n;\ | ||
838 | \ | ||
839 | index= SHOW_UBITS(name, gb, nb_bits) + code;\ | ||
840 | code = table[index][0];\ | ||
841 | n = table[index][1];\ | ||
842 | }\ | ||
843 | }\ | ||
844 | SKIP_BITS(name, gb, n)\ | ||
845 | } | ||
846 | |||
847 | #define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\ | ||
848 | {\ | ||
849 | int n, index, nb_bits;\ | ||
850 | \ | ||
851 | index= SHOW_UBITS(name, gb, bits);\ | ||
852 | level = table[index].level;\ | ||
853 | n = table[index].len;\ | ||
854 | \ | ||
855 | if(max_depth > 1 && n < 0){\ | ||
856 | SKIP_BITS(name, gb, bits)\ | ||
857 | if(need_update){\ | ||
858 | UPDATE_CACHE(name, gb)\ | ||
859 | }\ | ||
860 | \ | ||
861 | nb_bits = -n;\ | ||
862 | \ | ||
863 | index= SHOW_UBITS(name, gb, nb_bits) + level;\ | ||
864 | level = table[index].level;\ | ||
865 | n = table[index].len;\ | ||
866 | }\ | ||
867 | run= table[index].run;\ | ||
868 | SKIP_BITS(name, gb, n)\ | ||
869 | } | ||
870 | |||
871 | |||
872 | /** | ||
873 | * parses a vlc code, faster then get_vlc() | ||
874 | * @param bits is the number of bits which will be read at once, must be | ||
875 | * identical to nb_bits in init_vlc() | ||
876 | * @param max_depth is the number of times bits bits must be read to completely | ||
877 | * read the longest vlc code | ||
878 | * = (max_vlc_length + bits - 1) / bits | ||
879 | */ | ||
880 | static inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2], | ||
881 | int bits, int max_depth) | ||
882 | { | ||
883 | int code; | ||
884 | |||
885 | OPEN_READER(re, s) | ||
886 | UPDATE_CACHE(re, s) | ||
887 | |||
888 | GET_VLC(code, re, s, table, bits, max_depth) | ||
889 | |||
890 | CLOSE_READER(re, s) | ||
891 | return code; | ||
892 | } | ||
893 | |||
894 | //#define TRACE | ||
895 | |||
896 | #ifdef TRACE | ||
897 | static inline void print_bin(int bits, int n){ | ||
898 | int i; | ||
899 | |||
900 | for(i=n-1; i>=0; i--){ | ||
901 | printf("%d", (bits>>i)&1); | ||
902 | } | ||
903 | for(i=n; i<24; i++) | ||
904 | printf(" "); | ||
905 | } | ||
906 | |||
907 | static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ | ||
908 | int r= get_bits(s, n); | ||
909 | |||
910 | print_bin(r, n); | ||
911 | printf("%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line); | ||
912 | return r; | ||
913 | } | ||
914 | static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, const char *func, int line){ | ||
915 | int show= show_bits(s, 24); | ||
916 | int pos= get_bits_count(s); | ||
917 | int r= get_vlc2(s, table, bits, max_depth); | ||
918 | int len= get_bits_count(s) - pos; | ||
919 | int bits2= show>>(24-len); | ||
920 | |||
921 | print_bin(bits2, len); | ||
922 | |||
923 | printf("%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line); | ||
924 | return r; | ||
925 | } | ||
926 | static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ | ||
927 | int show= show_bits(s, n); | ||
928 | int r= get_xbits(s, n); | ||
929 | |||
930 | print_bin(show, n); | ||
931 | printf("%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line); | ||
932 | return r; | ||
933 | } | ||
934 | |||
935 | #define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__) | ||
936 | #define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__) | ||
937 | #define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__) | ||
938 | #define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__) | ||
939 | #define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__) | ||
940 | |||
941 | #define tprintf(p, ...) printf | ||
942 | |||
943 | #else //TRACE | ||
944 | #define tprintf(p, ...) {} | ||
945 | #endif | ||
946 | |||
947 | static inline int decode012(GetBitContext *gb){ | ||
948 | int n; | ||
949 | n = get_bits1(gb); | ||
950 | if (n == 0) | ||
951 | return 0; | ||
952 | else | ||
953 | return get_bits1(gb) + 1; | ||
954 | } | ||
955 | |||
956 | static inline int decode210(GetBitContext *gb){ | ||
957 | if (get_bits1(gb)) | ||
958 | return 0; | ||
959 | else | ||
960 | return 2 - get_bits1(gb); | ||
961 | } | ||
962 | |||
963 | #endif /* BITSTREAM_H */ | ||
diff --git a/apps/codecs/libatrac/ffmpeg_config.h b/apps/codecs/libatrac/ffmpeg_config.h deleted file mode 100644 index 707e14df52..0000000000 --- a/apps/codecs/libatrac/ffmpeg_config.h +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | /* Automatically generated by configure - do not modify */ | ||
2 | #ifndef _FFMPEG_CONFIG_H | ||
3 | #define _FFMPEG_CONFIG_H | ||
4 | // CHECK THIS : #include "codecs.h" | ||
5 | |||
6 | #ifdef CPU_ARM | ||
7 | #define CONFIG_ALIGN 1 | ||
8 | #endif | ||
9 | |||
10 | #ifdef ROCKBOX_BIG_ENDIAN | ||
11 | #define WORDS_BIGENDIAN | ||
12 | #endif | ||
13 | |||
14 | #endif | ||
diff --git a/apps/codecs/libcook/Makefile.test b/apps/codecs/libcook/Makefile.test index 2fc34648d1..32e3549452 100644 --- a/apps/codecs/libcook/Makefile.test +++ b/apps/codecs/libcook/Makefile.test | |||
@@ -1,5 +1,5 @@ | |||
1 | CFLAGS = -Wall -O3 -DTEST -D"DEBUGF=printf" -D"ROCKBOX_LITTLE_ENDIAN=1" -D"ICONST_ATTR=" -D"ICODE_ATTR=" | 1 | CFLAGS = -Wall -O3 -I../lib -DTEST -D"DEBUGF=printf" -D"ROCKBOX_LITTLE_ENDIAN=1" -D"ICONST_ATTR=" -D"ICODE_ATTR=" |
2 | OBJS = main.o bitstream.o cook.o ../librm/rm.o ../lib/mdct2.o ../lib/mdct_lookup.o | 2 | OBJS = main.o ../lib/ffmpeg_bitstream.o cook.o ../librm/rm.o ../lib/mdct2.o ../lib/mdct_lookup.o |
3 | cooktest: $(OBJS) | 3 | cooktest: $(OBJS) |
4 | gcc -o cooktest $(OBJS) | 4 | gcc -o cooktest $(OBJS) |
5 | 5 | ||
diff --git a/apps/codecs/libcook/SOURCES b/apps/codecs/libcook/SOURCES index bfcb24c8cd..d093173aea 100644 --- a/apps/codecs/libcook/SOURCES +++ b/apps/codecs/libcook/SOURCES | |||
@@ -1,2 +1,2 @@ | |||
1 | cook.c | 1 | cook.c |
2 | bitstream.c | 2 | ../lib/ffmpeg_bitstream.c |
diff --git a/apps/codecs/libcook/bitstream.c b/apps/codecs/libcook/bitstream.c deleted file mode 100644 index 1375134b21..0000000000 --- a/apps/codecs/libcook/bitstream.c +++ /dev/null | |||
@@ -1,276 +0,0 @@ | |||
1 | /* | ||
2 | * Common bit i/o utils | ||
3 | * Copyright (c) 2000, 2001 Fabrice Bellard | ||
4 | * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> | ||
5 | * | ||
6 | * alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at> | ||
7 | * | ||
8 | * This file is part of FFmpeg. | ||
9 | * | ||
10 | * FFmpeg is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU Lesser General Public | ||
12 | * License as published by the Free Software Foundation; either | ||
13 | * version 2.1 of the License, or (at your option) any later version. | ||
14 | * | ||
15 | * FFmpeg is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
18 | * Lesser General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU Lesser General Public | ||
21 | * License along with FFmpeg; if not, write to the Free Software | ||
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
23 | */ | ||
24 | |||
25 | #include "bitstream.h" | ||
26 | |||
27 | #ifdef ROCKBOX | ||
28 | #undef DEBUGF | ||
29 | #define DEBUGF(...) | ||
30 | #endif | ||
31 | |||
32 | const uint8_t ff_log2_run[32]={ | ||
33 | 0, 0, 0, 0, 1, 1, 1, 1, | ||
34 | 2, 2, 2, 2, 3, 3, 3, 3, | ||
35 | 4, 4, 5, 5, 6, 6, 7, 7, | ||
36 | 8, 9,10,11,12,13,14,15 | ||
37 | }; | ||
38 | |||
39 | /** | ||
40 | * Same as av_mallocz_static(), but does a realloc. | ||
41 | * | ||
42 | * @param[in] ptr The block of memory to reallocate. | ||
43 | * @param[in] size The requested size. | ||
44 | * @return Block of memory of requested size. | ||
45 | * @deprecated. Code which uses ff_realloc_static is broken/misdesigned | ||
46 | * and should correctly use static arrays | ||
47 | */ | ||
48 | |||
49 | |||
50 | void ff_put_string(PutBitContext * pbc, const char *s, int put_zero) | ||
51 | { | ||
52 | while(*s){ | ||
53 | put_bits(pbc, 8, *s); | ||
54 | s++; | ||
55 | } | ||
56 | if(put_zero) | ||
57 | put_bits(pbc, 8, 0); | ||
58 | } | ||
59 | |||
60 | /* VLC decoding */ | ||
61 | |||
62 | //#define DEBUG_VLC | ||
63 | |||
64 | #define GET_DATA(v, table, i, wrap, size) \ | ||
65 | {\ | ||
66 | const uint8_t *ptr = (const uint8_t *)table + i * wrap;\ | ||
67 | switch(size) {\ | ||
68 | case 1:\ | ||
69 | v = *(const uint8_t *)ptr;\ | ||
70 | break;\ | ||
71 | case 2:\ | ||
72 | v = *(const uint16_t *)ptr;\ | ||
73 | break;\ | ||
74 | default:\ | ||
75 | v = *(const uint32_t *)ptr;\ | ||
76 | break;\ | ||
77 | }\ | ||
78 | } | ||
79 | |||
80 | |||
81 | static int alloc_table(VLC *vlc, int size, int use_static) | ||
82 | { | ||
83 | int index; | ||
84 | index = vlc->table_size; | ||
85 | vlc->table_size += size; | ||
86 | if (vlc->table_size > vlc->table_allocated) { | ||
87 | if(use_static>1){ | ||
88 | DEBUGF("init_vlc() used with too little memory : table_size > allocated_memory\n"); | ||
89 | } | ||
90 | |||
91 | if (!vlc->table) | ||
92 | return -1; | ||
93 | } | ||
94 | return index; | ||
95 | } | ||
96 | |||
97 | static int build_table(VLC *vlc, int table_nb_bits, | ||
98 | int nb_codes, | ||
99 | const void *bits, int bits_wrap, int bits_size, | ||
100 | const void *codes, int codes_wrap, int codes_size, | ||
101 | const void *symbols, int symbols_wrap, int symbols_size, | ||
102 | uint32_t code_prefix, int n_prefix, int flags) | ||
103 | { | ||
104 | int i, j, k, n, table_size, table_index, nb, n1, index, code_prefix2, symbol; | ||
105 | uint32_t code; | ||
106 | VLC_TYPE (*table)[2]; | ||
107 | |||
108 | table_size = 1 << table_nb_bits; | ||
109 | table_index = alloc_table(vlc, table_size, flags & (INIT_VLC_USE_STATIC|INIT_VLC_USE_NEW_STATIC)); | ||
110 | #ifdef DEBUG_VLC | ||
111 | DEBUGF("new table index=%d size=%d code_prefix=%x n=%d\n", | ||
112 | table_index, table_size, code_prefix, n_prefix); | ||
113 | #endif | ||
114 | if (table_index < 0) | ||
115 | return -1; | ||
116 | table = &vlc->table[table_index]; | ||
117 | |||
118 | for(i=0;i<table_size;i++) { | ||
119 | table[i][1] = 0; //bits | ||
120 | table[i][0] = -1; //codes | ||
121 | } | ||
122 | |||
123 | /* first pass: map codes and compute auxillary table sizes */ | ||
124 | for(i=0;i<nb_codes;i++) { | ||
125 | GET_DATA(n, bits, i, bits_wrap, bits_size); | ||
126 | GET_DATA(code, codes, i, codes_wrap, codes_size); | ||
127 | /* we accept tables with holes */ | ||
128 | if (n <= 0) | ||
129 | continue; | ||
130 | if (!symbols) | ||
131 | symbol = i; | ||
132 | else | ||
133 | GET_DATA(symbol, symbols, i, symbols_wrap, symbols_size); | ||
134 | #if defined(DEBUG_VLC) && 0 | ||
135 | DEBUGF("i=%d n=%d code=0x%x\n", i, n, code); | ||
136 | #endif | ||
137 | /* if code matches the prefix, it is in the table */ | ||
138 | n -= n_prefix; | ||
139 | if(flags & INIT_VLC_LE) | ||
140 | code_prefix2= code & (n_prefix>=32 ? (int)0xffffffff : (1 << n_prefix)-1); | ||
141 | else | ||
142 | code_prefix2= code >> n; | ||
143 | if (n > 0 && code_prefix2 == (int)code_prefix) { | ||
144 | if (n <= table_nb_bits) { | ||
145 | /* no need to add another table */ | ||
146 | j = (code << (table_nb_bits - n)) & (table_size - 1); | ||
147 | nb = 1 << (table_nb_bits - n); | ||
148 | for(k=0;k<nb;k++) { | ||
149 | if(flags & INIT_VLC_LE) | ||
150 | j = (code >> n_prefix) + (k<<n); | ||
151 | #ifdef DEBUG_VLC | ||
152 | DEBUGF("%4x: code=%d n=%d\n", | ||
153 | j, i, n); | ||
154 | #endif | ||
155 | if (table[j][1] /*bits*/ != 0) { | ||
156 | DEBUGF("incorrect codes\n"); | ||
157 | return -1; | ||
158 | } | ||
159 | table[j][1] = n; //bits | ||
160 | table[j][0] = symbol; | ||
161 | j++; | ||
162 | } | ||
163 | } else { | ||
164 | n -= table_nb_bits; | ||
165 | j = (code >> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << table_nb_bits) - 1); | ||
166 | #ifdef DEBUG_VLC | ||
167 | DEBUGF("%4x: n=%d (subtable)\n", | ||
168 | j, n); | ||
169 | #endif | ||
170 | /* compute table size */ | ||
171 | n1 = -table[j][1]; //bits | ||
172 | if (n > n1) | ||
173 | n1 = n; | ||
174 | table[j][1] = -n1; //bits | ||
175 | } | ||
176 | } | ||
177 | } | ||
178 | |||
179 | /* second pass : fill auxillary tables recursively */ | ||
180 | for(i=0;i<table_size;i++) { | ||
181 | n = table[i][1]; //bits | ||
182 | if (n < 0) { | ||
183 | n = -n; | ||
184 | if (n > table_nb_bits) { | ||
185 | n = table_nb_bits; | ||
186 | table[i][1] = -n; //bits | ||
187 | } | ||
188 | index = build_table(vlc, n, nb_codes, | ||
189 | bits, bits_wrap, bits_size, | ||
190 | codes, codes_wrap, codes_size, | ||
191 | symbols, symbols_wrap, symbols_size, | ||
192 | (flags & INIT_VLC_LE) ? (code_prefix | (i << n_prefix)) : ((code_prefix << table_nb_bits) | i), | ||
193 | n_prefix + table_nb_bits, flags); | ||
194 | if (index < 0) | ||
195 | return -1; | ||
196 | /* note: realloc has been done, so reload tables */ | ||
197 | table = &vlc->table[table_index]; | ||
198 | table[i][0] = index; //code | ||
199 | } | ||
200 | } | ||
201 | return table_index; | ||
202 | } | ||
203 | |||
204 | |||
205 | /* Build VLC decoding tables suitable for use with get_vlc(). | ||
206 | |||
207 | 'nb_bits' set thee decoding table size (2^nb_bits) entries. The | ||
208 | bigger it is, the faster is the decoding. But it should not be too | ||
209 | big to save memory and L1 cache. '9' is a good compromise. | ||
210 | |||
211 | 'nb_codes' : number of vlcs codes | ||
212 | |||
213 | 'bits' : table which gives the size (in bits) of each vlc code. | ||
214 | |||
215 | 'codes' : table which gives the bit pattern of of each vlc code. | ||
216 | |||
217 | 'symbols' : table which gives the values to be returned from get_vlc(). | ||
218 | |||
219 | 'xxx_wrap' : give the number of bytes between each entry of the | ||
220 | 'bits' or 'codes' tables. | ||
221 | |||
222 | 'xxx_size' : gives the number of bytes of each entry of the 'bits' | ||
223 | or 'codes' tables. | ||
224 | |||
225 | 'wrap' and 'size' allows to use any memory configuration and types | ||
226 | (byte/word/long) to store the 'bits', 'codes', and 'symbols' tables. | ||
227 | |||
228 | 'use_static' should be set to 1 for tables, which should be freed | ||
229 | with av_free_static(), 0 if free_vlc() will be used. | ||
230 | */ | ||
231 | int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, | ||
232 | const void *bits, int bits_wrap, int bits_size, | ||
233 | const void *codes, int codes_wrap, int codes_size, | ||
234 | const void *symbols, int symbols_wrap, int symbols_size, | ||
235 | int flags) | ||
236 | { | ||
237 | vlc->bits = nb_bits; | ||
238 | if(flags & INIT_VLC_USE_NEW_STATIC){ | ||
239 | if(vlc->table_size && vlc->table_size == vlc->table_allocated){ | ||
240 | return 0; | ||
241 | }else if(vlc->table_size){ | ||
242 | return -1; // fatal error, we are called on a partially initialized table | ||
243 | } | ||
244 | }else if(!(flags & INIT_VLC_USE_STATIC)) { | ||
245 | vlc->table = NULL; | ||
246 | vlc->table_allocated = 0; | ||
247 | vlc->table_size = 0; | ||
248 | } else { | ||
249 | /* Static tables are initially always NULL, return | ||
250 | if vlc->table != NULL to avoid double allocation */ | ||
251 | if(vlc->table) | ||
252 | return 0; | ||
253 | } | ||
254 | |||
255 | #ifdef DEBUG_VLC | ||
256 | DEBUGF("build table nb_codes=%d\n", nb_codes); | ||
257 | #endif | ||
258 | |||
259 | if (build_table(vlc, nb_bits, nb_codes, | ||
260 | bits, bits_wrap, bits_size, | ||
261 | codes, codes_wrap, codes_size, | ||
262 | symbols, symbols_wrap, symbols_size, | ||
263 | 0, 0, flags) < 0) { | ||
264 | //free(&vlc->table); | ||
265 | return -1; | ||
266 | } | ||
267 | /* Changed the following condition to be true if table_size > table_allocated. * | ||
268 | * This would be more sensible for static tables since we want warnings for * | ||
269 | * memory shortages only. */ | ||
270 | #ifdef TEST | ||
271 | if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size > vlc->table_allocated) | ||
272 | DEBUGF("needed %d had %d\n", vlc->table_size, vlc->table_allocated); | ||
273 | #endif | ||
274 | return 0; | ||
275 | } | ||
276 | |||
diff --git a/apps/codecs/libcook/cook.h b/apps/codecs/libcook/cook.h index 078e67b872..4fb7b1c0db 100644 --- a/apps/codecs/libcook/cook.h +++ b/apps/codecs/libcook/cook.h | |||
@@ -23,7 +23,7 @@ | |||
23 | #define _COOK_H | 23 | #define _COOK_H |
24 | 24 | ||
25 | #include <inttypes.h> | 25 | #include <inttypes.h> |
26 | #include "bitstream.h" | 26 | #include "ffmpeg_bitstream.h" |
27 | #include "../librm/rm.h" | 27 | #include "../librm/rm.h" |
28 | #include "cookdata_fixpoint.h" | 28 | #include "cookdata_fixpoint.h" |
29 | 29 | ||
diff --git a/apps/codecs/libcook/ffmpeg_config.h b/apps/codecs/libcook/ffmpeg_config.h deleted file mode 100644 index 707e14df52..0000000000 --- a/apps/codecs/libcook/ffmpeg_config.h +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | /* Automatically generated by configure - do not modify */ | ||
2 | #ifndef _FFMPEG_CONFIG_H | ||
3 | #define _FFMPEG_CONFIG_H | ||
4 | // CHECK THIS : #include "codecs.h" | ||
5 | |||
6 | #ifdef CPU_ARM | ||
7 | #define CONFIG_ALIGN 1 | ||
8 | #endif | ||
9 | |||
10 | #ifdef ROCKBOX_BIG_ENDIAN | ||
11 | #define WORDS_BIGENDIAN | ||
12 | #endif | ||
13 | |||
14 | #endif | ||
diff --git a/apps/codecs/libwma/SOURCES b/apps/codecs/libwma/SOURCES index 967577d0db..14cf0c8922 100644 --- a/apps/codecs/libwma/SOURCES +++ b/apps/codecs/libwma/SOURCES | |||
@@ -1,3 +1,3 @@ | |||
1 | wmadeci.c | 1 | wmadeci.c |
2 | wmafixed.c | 2 | wmafixed.c |
3 | bitstream.c | 3 | ../lib/ffmpeg_bitstream.c |
diff --git a/apps/codecs/libwma/bitstream.c b/apps/codecs/libwma/bitstream.c deleted file mode 100644 index 618148b721..0000000000 --- a/apps/codecs/libwma/bitstream.c +++ /dev/null | |||
@@ -1,271 +0,0 @@ | |||
1 | /* | ||
2 | * Common bit i/o utils | ||
3 | * Copyright (c) 2000, 2001 Fabrice Bellard. | ||
4 | * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> | ||
5 | * | ||
6 | * This file is part of FFmpeg. | ||
7 | * | ||
8 | * FFmpeg is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU Lesser General Public | ||
10 | * License as published by the Free Software Foundation; either | ||
11 | * version 2.1 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | * FFmpeg is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public | ||
19 | * License along with FFmpeg; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | * | ||
22 | * alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at> | ||
23 | */ | ||
24 | |||
25 | /** | ||
26 | * @file bitstream.c | ||
27 | * bitstream api. | ||
28 | */ | ||
29 | |||
30 | #include "bitstream.h" | ||
31 | #include <codecs/lib/codeclib.h> | ||
32 | |||
33 | /** | ||
34 | * Same as av_mallocz_static(), but does a realloc. | ||
35 | * | ||
36 | * @param[in] ptr The block of memory to reallocate. | ||
37 | * @param[in] size The requested size. | ||
38 | * @return Block of memory of requested size. | ||
39 | * @deprecated. Code which uses ff_realloc_static is broken/missdesigned | ||
40 | * and should correctly use static arrays | ||
41 | */ | ||
42 | attribute_deprecated void *ff_realloc_static(void *ptr, unsigned int size); | ||
43 | |||
44 | |||
45 | const uint8_t ff_sqrt_tab[128]={ | ||
46 | 0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, | ||
47 | 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, | ||
48 | 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, | ||
49 | 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11 | ||
50 | }; | ||
51 | |||
52 | const uint8_t ff_log2_tab[256]={ | ||
53 | 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, | ||
54 | 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, | ||
55 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, | ||
56 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, | ||
57 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
58 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
59 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
60 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 | ||
61 | }; | ||
62 | |||
63 | |||
64 | void align_put_bits(PutBitContext *s) | ||
65 | { | ||
66 | #ifdef ALT_BITSTREAM_WRITER | ||
67 | put_bits(s,( - s->index) & 7,0); | ||
68 | #else | ||
69 | put_bits(s,s->bit_left & 7,0); | ||
70 | #endif | ||
71 | } | ||
72 | |||
73 | void ff_put_string(PutBitContext * pbc, char *s, int put_zero) | ||
74 | { | ||
75 | while(*s){ | ||
76 | put_bits(pbc, 8, *s); | ||
77 | s++; | ||
78 | } | ||
79 | if(put_zero) | ||
80 | put_bits(pbc, 8, 0); | ||
81 | } | ||
82 | |||
83 | /* VLC decoding */ | ||
84 | |||
85 | //#define DEBUG_VLC | ||
86 | |||
87 | #define GET_DATA(v, table, i, wrap, size) \ | ||
88 | {\ | ||
89 | const uint8_t *ptr = (const uint8_t *)table + i * wrap;\ | ||
90 | switch(size) {\ | ||
91 | case 1:\ | ||
92 | v = *(const uint8_t *)ptr;\ | ||
93 | break;\ | ||
94 | case 2:\ | ||
95 | v = *(const uint16_t *)ptr;\ | ||
96 | break;\ | ||
97 | default:\ | ||
98 | v = *(const uint32_t *)ptr;\ | ||
99 | break;\ | ||
100 | }\ | ||
101 | } | ||
102 | |||
103 | |||
104 | static int alloc_table(VLC *vlc, int size) | ||
105 | { | ||
106 | int index; | ||
107 | index = vlc->table_size; | ||
108 | vlc->table_size += size; | ||
109 | if (vlc->table_size > vlc->table_allocated) { | ||
110 | DEBUGF("Tried to allocate past the end of a Huffman table: %d/%d\n", | ||
111 | vlc->table_allocated, vlc->table_allocated+(1 << vlc->bits)); | ||
112 | vlc->table_allocated += (1 << vlc->bits); | ||
113 | if (!vlc->table) | ||
114 | return -1; | ||
115 | } | ||
116 | return index; | ||
117 | } | ||
118 | |||
119 | static int build_table(VLC *vlc, int table_nb_bits, | ||
120 | int nb_codes, | ||
121 | const void *bits, int bits_wrap, int bits_size, | ||
122 | const void *codes, int codes_wrap, int codes_size, | ||
123 | uint32_t code_prefix, int n_prefix) | ||
124 | { | ||
125 | int i, j, k, n, table_size, table_index, nb, n1, index, code_prefix2; | ||
126 | uint32_t code; | ||
127 | int flags = 0; | ||
128 | VLC_TYPE (*table)[2]; | ||
129 | |||
130 | table_size = 1 << table_nb_bits; | ||
131 | table_index = alloc_table(vlc, table_size); | ||
132 | #ifdef DEBUG_VLC | ||
133 | printf("new table index=%d size=%d code_prefix=%x n=%d\n", | ||
134 | table_index, table_size, code_prefix, n_prefix); | ||
135 | #endif | ||
136 | if (table_index < 0) | ||
137 | return -1; | ||
138 | table = &vlc->table[table_index]; | ||
139 | |||
140 | for(i=0;i<table_size;i++) { | ||
141 | table[i][1] = 0; //bits | ||
142 | table[i][0] = -1; //codes | ||
143 | } | ||
144 | |||
145 | /* first pass: map codes and compute auxillary table sizes */ | ||
146 | for(i=0;i<nb_codes;i++) { | ||
147 | GET_DATA(n, bits, i, bits_wrap, bits_size); | ||
148 | GET_DATA(code, codes, i, codes_wrap, codes_size); | ||
149 | /* we accept tables with holes */ | ||
150 | if (n <= 0) | ||
151 | continue; | ||
152 | #if defined(DEBUG_VLC) && 0 | ||
153 | printf("i=%d n=%d code=0x%x\n", i, n, code); | ||
154 | #endif | ||
155 | /* if code matches the prefix, it is in the table */ | ||
156 | n -= n_prefix; | ||
157 | if(flags & INIT_VLC_LE) | ||
158 | code_prefix2= code & (n_prefix>=32 ? 0xffffffff : (uint32_t)(1 << n_prefix)-1); | ||
159 | else | ||
160 | code_prefix2= code >> n; | ||
161 | if (n > 0 && (int)code_prefix2 == (int)code_prefix) { | ||
162 | if (n <= table_nb_bits) { | ||
163 | /* no need to add another table */ | ||
164 | j = (code << (table_nb_bits - n)) & (table_size - 1); | ||
165 | nb = 1 << (table_nb_bits - n); | ||
166 | for(k=0;k<nb;k++) { | ||
167 | if(flags & INIT_VLC_LE) | ||
168 | j = (code >> n_prefix) + (k<<n); | ||
169 | #ifdef DEBUG_VLC | ||
170 | av_log(NULL, 0, "%4x: code=%d n=%d\n", | ||
171 | j, i, n); | ||
172 | #endif | ||
173 | if (table[j][1] /*bits*/ != 0) { | ||
174 | return -1; | ||
175 | } | ||
176 | table[j][1] = n; //bits | ||
177 | table[j][0] = i; //code | ||
178 | j++; | ||
179 | } | ||
180 | } else { | ||
181 | n -= table_nb_bits; | ||
182 | j = (code >> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << table_nb_bits) - 1); | ||
183 | #ifdef DEBUG_VLC | ||
184 | av_log(NULL, 0,"%4x: n=%d (subtable)\n", | ||
185 | j, n); | ||
186 | #endif | ||
187 | /* compute table size */ | ||
188 | n1 = -table[j][1]; //bits | ||
189 | if (n > n1) | ||
190 | n1 = n; | ||
191 | table[j][1] = -n1; //bits | ||
192 | } | ||
193 | } | ||
194 | } | ||
195 | |||
196 | /* second pass : fill auxillary tables recursively */ | ||
197 | for(i=0;i<table_size;i++) { | ||
198 | n = table[i][1]; //bits | ||
199 | if (n < 0) { | ||
200 | n = -n; | ||
201 | if (n > table_nb_bits) { | ||
202 | n = table_nb_bits; | ||
203 | table[i][1] = -n; //bits | ||
204 | } | ||
205 | index = build_table(vlc, n, nb_codes, | ||
206 | bits, bits_wrap, bits_size, | ||
207 | codes, codes_wrap, codes_size, | ||
208 | (flags & INIT_VLC_LE) ? (code_prefix | (i << n_prefix)) : ((code_prefix << table_nb_bits) | i), | ||
209 | n_prefix + table_nb_bits); | ||
210 | if (index < 0) | ||
211 | return -1; | ||
212 | /* note: realloc has been done, so reload tables */ | ||
213 | table = &vlc->table[table_index]; | ||
214 | table[i][0] = index; //code | ||
215 | } | ||
216 | } | ||
217 | return table_index; | ||
218 | } | ||
219 | |||
220 | |||
221 | /* Build VLC decoding tables suitable for use with get_vlc(). | ||
222 | |||
223 | 'nb_bits' set thee decoding table size (2^nb_bits) entries. The | ||
224 | bigger it is, the faster is the decoding. But it should not be too | ||
225 | big to save memory and L1 cache. '9' is a good compromise. | ||
226 | |||
227 | 'nb_codes' : number of vlcs codes | ||
228 | |||
229 | 'bits' : table which gives the size (in bits) of each vlc code. | ||
230 | |||
231 | 'codes' : table which gives the bit pattern of of each vlc code. | ||
232 | |||
233 | 'xxx_wrap' : give the number of bytes between each entry of the | ||
234 | 'bits' or 'codes' tables. | ||
235 | |||
236 | 'xxx_size' : gives the number of bytes of each entry of the 'bits' | ||
237 | or 'codes' tables. | ||
238 | |||
239 | 'wrap' and 'size' allows to use any memory configuration and types | ||
240 | (byte/word/long) to store the 'bits' and 'codes' tables. | ||
241 | |||
242 | 'use_static' should be set to 1 for tables, which should be freed | ||
243 | with av_free_static(), 0 if free_vlc() will be used. | ||
244 | */ | ||
245 | int init_vlc(VLC *vlc, int nb_bits, int nb_codes, | ||
246 | const void *bits, int bits_wrap, int bits_size, | ||
247 | const void *codes, int codes_wrap, int codes_size, | ||
248 | int flags) | ||
249 | { | ||
250 | |||
251 | vlc->bits = nb_bits; | ||
252 | vlc->table_size = 0; | ||
253 | |||
254 | #ifdef DEBUG_VLC | ||
255 | printf("build table nb_codes=%d\n", nb_codes); | ||
256 | #endif | ||
257 | |||
258 | if (build_table(vlc, nb_bits, nb_codes, | ||
259 | bits, bits_wrap, bits_size, | ||
260 | codes, codes_wrap, codes_size, | ||
261 | 0, 0) < 0) { | ||
262 | //av_free(vlc->table); | ||
263 | return -1; | ||
264 | } | ||
265 | /* return flags to block gcc warning while allowing us to keep | ||
266 | * consistent with ffmpeg's function parameters | ||
267 | */ | ||
268 | return flags; | ||
269 | } | ||
270 | |||
271 | |||
diff --git a/apps/codecs/libwma/bitstream.h b/apps/codecs/libwma/bitstream.h deleted file mode 100644 index 7de6411db9..0000000000 --- a/apps/codecs/libwma/bitstream.h +++ /dev/null | |||
@@ -1,989 +0,0 @@ | |||
1 | /* | ||
2 | * copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at> | ||
3 | * | ||
4 | * This file is part of FFmpeg. | ||
5 | * | ||
6 | * FFmpeg is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * FFmpeg is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with FFmpeg; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file bitstream.h | ||
23 | * bitstream api header. | ||
24 | */ | ||
25 | |||
26 | #ifndef BITSTREAM_H | ||
27 | #define BITSTREAM_H | ||
28 | |||
29 | #define av_always_inline inline | ||
30 | #define attribute_deprecated | ||
31 | |||
32 | #include <inttypes.h> | ||
33 | #include "ffmpeg_config.h" | ||
34 | #include <stdlib.h> | ||
35 | |||
36 | #include "../lib/ffmpeg_bswap.h" | ||
37 | |||
38 | extern const uint8_t ff_log2_tab[256]; | ||
39 | |||
40 | |||
41 | /*misc utility functions added to make it compile */ | ||
42 | static inline int av_log2(unsigned int v) | ||
43 | { | ||
44 | int n; | ||
45 | |||
46 | n = 0; | ||
47 | if (v & 0xffff0000) { | ||
48 | v >>= 16; | ||
49 | n += 16; | ||
50 | } | ||
51 | if (v & 0xff00) { | ||
52 | v >>= 8; | ||
53 | n += 8; | ||
54 | } | ||
55 | n += ff_log2_tab[v]; | ||
56 | |||
57 | return n; | ||
58 | } | ||
59 | |||
60 | |||
61 | //#include "log.h" | ||
62 | |||
63 | #if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER) | ||
64 | #define ALT_BITSTREAM_READER | ||
65 | #endif | ||
66 | |||
67 | //#define ALT_BITSTREAM_WRITER | ||
68 | //#define ALIGNED_BITSTREAM_WRITER | ||
69 | #if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER) | ||
70 | # ifdef ARCH_ARMV4L | ||
71 | # define A32_BITSTREAM_READER | ||
72 | # else | ||
73 | #define ALT_BITSTREAM_READER | ||
74 | //#define LIBMPEG2_BITSTREAM_READER | ||
75 | //#define A32_BITSTREAM_READER | ||
76 | # endif | ||
77 | #endif | ||
78 | #define LIBMPEG2_BITSTREAM_READER_HACK //add BERO | ||
79 | |||
80 | extern const uint8_t ff_reverse[256]; | ||
81 | |||
82 | #if defined(ARCH_X86) | ||
83 | // avoid +32 for shift optimization (gcc should do that ...) | ||
84 | static inline int32_t NEG_SSR32( int32_t a, int8_t s){ | ||
85 | asm ("sarl %1, %0\n\t" | ||
86 | : "+r" (a) | ||
87 | : "ic" ((uint8_t)(-s)) | ||
88 | ); | ||
89 | return a; | ||
90 | } | ||
91 | static inline uint32_t NEG_USR32(uint32_t a, int8_t s){ | ||
92 | asm ("shrl %1, %0\n\t" | ||
93 | : "+r" (a) | ||
94 | : "ic" ((uint8_t)(-s)) | ||
95 | ); | ||
96 | return a; | ||
97 | } | ||
98 | #else | ||
99 | # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s))) | ||
100 | # define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s))) | ||
101 | #endif | ||
102 | |||
103 | /* bit output */ | ||
104 | |||
105 | /* buf and buf_end must be present and used by every alternative writer. */ | ||
106 | typedef struct PutBitContext { | ||
107 | #ifdef ALT_BITSTREAM_WRITER | ||
108 | uint8_t *buf, *buf_end; | ||
109 | int index; | ||
110 | #else | ||
111 | uint32_t bit_buf; | ||
112 | int bit_left; | ||
113 | uint8_t *buf, *buf_ptr, *buf_end; | ||
114 | #endif | ||
115 | } PutBitContext; | ||
116 | |||
117 | static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size) | ||
118 | { | ||
119 | if(buffer_size < 0) { | ||
120 | buffer_size = 0; | ||
121 | buffer = NULL; | ||
122 | } | ||
123 | |||
124 | s->buf = buffer; | ||
125 | s->buf_end = s->buf + buffer_size; | ||
126 | #ifdef ALT_BITSTREAM_WRITER | ||
127 | s->index=0; | ||
128 | ((uint32_t*)(s->buf))[0]=0; | ||
129 | // memset(buffer, 0, buffer_size); | ||
130 | #else | ||
131 | s->buf_ptr = s->buf; | ||
132 | s->bit_left=32; | ||
133 | s->bit_buf=0; | ||
134 | #endif | ||
135 | } | ||
136 | |||
137 | /* return the number of bits output */ | ||
138 | static inline int put_bits_count(PutBitContext *s) | ||
139 | { | ||
140 | #ifdef ALT_BITSTREAM_WRITER | ||
141 | return s->index; | ||
142 | #else | ||
143 | return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left; | ||
144 | #endif | ||
145 | } | ||
146 | |||
147 | /* pad the end of the output stream with zeros */ | ||
148 | static inline void flush_put_bits(PutBitContext *s) | ||
149 | { | ||
150 | #ifdef ALT_BITSTREAM_WRITER | ||
151 | align_put_bits(s); | ||
152 | #else | ||
153 | s->bit_buf<<= s->bit_left; | ||
154 | while (s->bit_left < 32) { | ||
155 | /* XXX: should test end of buffer */ | ||
156 | *s->buf_ptr++=s->bit_buf >> 24; | ||
157 | s->bit_buf<<=8; | ||
158 | s->bit_left+=8; | ||
159 | } | ||
160 | s->bit_left=32; | ||
161 | s->bit_buf=0; | ||
162 | #endif | ||
163 | } | ||
164 | |||
165 | void align_put_bits(PutBitContext *s); | ||
166 | void ff_put_string(PutBitContext * pbc, char *s, int put_zero); | ||
167 | |||
168 | /* bit input */ | ||
169 | /* buffer, buffer_end and size_in_bits must be present and used by every reader */ | ||
170 | typedef struct GetBitContext { | ||
171 | const uint8_t *buffer, *buffer_end; | ||
172 | #ifdef ALT_BITSTREAM_READER | ||
173 | int index; | ||
174 | #elif defined LIBMPEG2_BITSTREAM_READER | ||
175 | uint8_t *buffer_ptr; | ||
176 | uint32_t cache; | ||
177 | int bit_count; | ||
178 | #elif defined A32_BITSTREAM_READER | ||
179 | uint32_t *buffer_ptr; | ||
180 | uint32_t cache0; | ||
181 | uint32_t cache1; | ||
182 | int bit_count; | ||
183 | #endif | ||
184 | int size_in_bits; | ||
185 | } GetBitContext; | ||
186 | |||
187 | #define VLC_TYPE int16_t | ||
188 | |||
189 | typedef struct VLC { | ||
190 | int bits; | ||
191 | VLC_TYPE (*table)[2]; ///< code, bits | ||
192 | int table_size, table_allocated; | ||
193 | } VLC; | ||
194 | |||
195 | typedef struct RL_VLC_ELEM { | ||
196 | int16_t level; | ||
197 | int8_t len; | ||
198 | uint8_t run; | ||
199 | } RL_VLC_ELEM; | ||
200 | |||
201 | #if defined(ARCH_SPARC) || defined(ARCH_ARMV4L) || defined(ARCH_MIPS) || defined(ARCH_BFIN) | ||
202 | #define UNALIGNED_STORES_ARE_BAD | ||
203 | #endif | ||
204 | |||
205 | /* used to avoid missaligned exceptions on some archs (alpha, ...) */ | ||
206 | #if defined(ARCH_X86) || defined(CPU_COLDFIRE) | ||
207 | # define unaligned16(a) (*(const uint16_t*)(a)) | ||
208 | # define unaligned32(a) (*(const uint32_t*)(a)) | ||
209 | # define unaligned64(a) (*(const uint64_t*)(a)) | ||
210 | #else | ||
211 | # ifdef __GNUC__ | ||
212 | # define unaligned(x) \ | ||
213 | static inline uint##x##_t unaligned##x(const void *v) { \ | ||
214 | struct Unaligned { \ | ||
215 | uint##x##_t i; \ | ||
216 | } __attribute__((packed)); \ | ||
217 | \ | ||
218 | return ((const struct Unaligned *) v)->i; \ | ||
219 | } | ||
220 | # elif defined(__DECC) | ||
221 | # define unaligned(x) \ | ||
222 | static inline uint##x##_t unaligned##x(const void *v) { \ | ||
223 | return *(const __unaligned uint##x##_t *) v; \ | ||
224 | } | ||
225 | # else | ||
226 | # define unaligned(x) \ | ||
227 | static inline uint##x##_t unaligned##x(const void *v) { \ | ||
228 | return *(const uint##x##_t *) v; \ | ||
229 | } | ||
230 | # endif | ||
231 | unaligned(16) | ||
232 | unaligned(32) | ||
233 | unaligned(64) | ||
234 | #undef unaligned | ||
235 | #endif /* defined(ARCH_X86) */ | ||
236 | |||
237 | #ifndef ALT_BITSTREAM_WRITER | ||
238 | static inline void put_bits(PutBitContext *s, int n, unsigned int value) | ||
239 | { | ||
240 | unsigned int bit_buf; | ||
241 | int bit_left; | ||
242 | |||
243 | // printf("put_bits=%d %x\n", n, value); | ||
244 | // assert(n == 32 || value < (1U << n)); | ||
245 | |||
246 | bit_buf = s->bit_buf; | ||
247 | bit_left = s->bit_left; | ||
248 | |||
249 | // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf); | ||
250 | /* XXX: optimize */ | ||
251 | if (n < bit_left) { | ||
252 | bit_buf = (bit_buf<<n) | value; | ||
253 | bit_left-=n; | ||
254 | } else { | ||
255 | bit_buf<<=bit_left; | ||
256 | bit_buf |= value >> (n - bit_left); | ||
257 | #ifdef UNALIGNED_STORES_ARE_BAD | ||
258 | if (3 & (intptr_t) s->buf_ptr) { | ||
259 | s->buf_ptr[0] = bit_buf >> 24; | ||
260 | s->buf_ptr[1] = bit_buf >> 16; | ||
261 | s->buf_ptr[2] = bit_buf >> 8; | ||
262 | s->buf_ptr[3] = bit_buf ; | ||
263 | } else | ||
264 | #endif | ||
265 | *(uint32_t *)s->buf_ptr = be2me_32(bit_buf); | ||
266 | //printf("bitbuf = %08x\n", bit_buf); | ||
267 | s->buf_ptr+=4; | ||
268 | bit_left+=32 - n; | ||
269 | bit_buf = value; | ||
270 | } | ||
271 | |||
272 | s->bit_buf = bit_buf; | ||
273 | s->bit_left = bit_left; | ||
274 | } | ||
275 | #endif | ||
276 | |||
277 | |||
278 | #ifdef ALT_BITSTREAM_WRITER | ||
279 | static inline void put_bits(PutBitContext *s, int n, unsigned int value) | ||
280 | { | ||
281 | # ifdef ALIGNED_BITSTREAM_WRITER | ||
282 | # if defined(ARCH_X86) | ||
283 | asm volatile( | ||
284 | "movl %0, %%ecx \n\t" | ||
285 | "xorl %%eax, %%eax \n\t" | ||
286 | "shrdl %%cl, %1, %%eax \n\t" | ||
287 | "shrl %%cl, %1 \n\t" | ||
288 | "movl %0, %%ecx \n\t" | ||
289 | "shrl $3, %%ecx \n\t" | ||
290 | "andl $0xFFFFFFFC, %%ecx \n\t" | ||
291 | "bswapl %1 \n\t" | ||
292 | "orl %1, (%2, %%ecx) \n\t" | ||
293 | "bswapl %%eax \n\t" | ||
294 | "addl %3, %0 \n\t" | ||
295 | "movl %%eax, 4(%2, %%ecx) \n\t" | ||
296 | : "=&r" (s->index), "=&r" (value) | ||
297 | : "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n)) | ||
298 | : "%eax", "%ecx" | ||
299 | ); | ||
300 | # else | ||
301 | int index= s->index; | ||
302 | uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5); | ||
303 | |||
304 | value<<= 32-n; | ||
305 | |||
306 | ptr[0] |= be2me_32(value>>(index&31)); | ||
307 | ptr[1] = be2me_32(value<<(32-(index&31))); | ||
308 | //if(n>24) printf("%d %d\n", n, value); | ||
309 | index+= n; | ||
310 | s->index= index; | ||
311 | # endif | ||
312 | # else //ALIGNED_BITSTREAM_WRITER | ||
313 | # if defined(ARCH_X86) | ||
314 | asm volatile( | ||
315 | "movl $7, %%ecx \n\t" | ||
316 | "andl %0, %%ecx \n\t" | ||
317 | "addl %3, %%ecx \n\t" | ||
318 | "negl %%ecx \n\t" | ||
319 | "shll %%cl, %1 \n\t" | ||
320 | "bswapl %1 \n\t" | ||
321 | "movl %0, %%ecx \n\t" | ||
322 | "shrl $3, %%ecx \n\t" | ||
323 | "orl %1, (%%ecx, %2) \n\t" | ||
324 | "addl %3, %0 \n\t" | ||
325 | "movl $0, 4(%%ecx, %2) \n\t" | ||
326 | : "=&r" (s->index), "=&r" (value) | ||
327 | : "r" (s->buf), "r" (n), "0" (s->index), "1" (value) | ||
328 | : "%ecx" | ||
329 | ); | ||
330 | # else | ||
331 | int index= s->index; | ||
332 | uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3)); | ||
333 | |||
334 | ptr[0] |= be2me_32(value<<(32-n-(index&7) )); | ||
335 | ptr[1] = 0; | ||
336 | //if(n>24) printf("%d %d\n", n, value); | ||
337 | index+= n; | ||
338 | s->index= index; | ||
339 | # endif | ||
340 | # endif //!ALIGNED_BITSTREAM_WRITER | ||
341 | } | ||
342 | #endif | ||
343 | |||
344 | |||
345 | static inline uint8_t* pbBufPtr(PutBitContext *s) | ||
346 | { | ||
347 | #ifdef ALT_BITSTREAM_WRITER | ||
348 | return s->buf + (s->index>>3); | ||
349 | #else | ||
350 | return s->buf_ptr; | ||
351 | #endif | ||
352 | } | ||
353 | |||
354 | /** | ||
355 | * | ||
356 | * PutBitContext must be flushed & aligned to a byte boundary before calling this. | ||
357 | */ | ||
358 | static inline void skip_put_bytes(PutBitContext *s, int n){ | ||
359 | // assert((put_bits_count(s)&7)==0); | ||
360 | #ifdef ALT_BITSTREAM_WRITER | ||
361 | FIXME may need some cleaning of the buffer | ||
362 | s->index += n<<3; | ||
363 | #else | ||
364 | // assert(s->bit_left==32); | ||
365 | s->buf_ptr += n; | ||
366 | #endif | ||
367 | } | ||
368 | |||
369 | /** | ||
370 | * skips the given number of bits. | ||
371 | * must only be used if the actual values in the bitstream dont matter | ||
372 | */ | ||
373 | static inline void skip_put_bits(PutBitContext *s, int n){ | ||
374 | #ifdef ALT_BITSTREAM_WRITER | ||
375 | s->index += n; | ||
376 | #else | ||
377 | s->bit_left -= n; | ||
378 | s->buf_ptr-= s->bit_left>>5; | ||
379 | s->bit_left &= 31; | ||
380 | #endif | ||
381 | } | ||
382 | |||
383 | /** | ||
384 | * Changes the end of the buffer. | ||
385 | */ | ||
386 | static inline void set_put_bits_buffer_size(PutBitContext *s, int size){ | ||
387 | s->buf_end= s->buf + size; | ||
388 | } | ||
389 | |||
390 | /* Bitstream reader API docs: | ||
391 | name | ||
392 | abritary name which is used as prefix for the internal variables | ||
393 | |||
394 | gb | ||
395 | getbitcontext | ||
396 | |||
397 | OPEN_READER(name, gb) | ||
398 | loads gb into local variables | ||
399 | |||
400 | CLOSE_READER(name, gb) | ||
401 | stores local vars in gb | ||
402 | |||
403 | UPDATE_CACHE(name, gb) | ||
404 | refills the internal cache from the bitstream | ||
405 | after this call at least MIN_CACHE_BITS will be available, | ||
406 | |||
407 | GET_CACHE(name, gb) | ||
408 | will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit) | ||
409 | |||
410 | SHOW_UBITS(name, gb, num) | ||
411 | will return the next num bits | ||
412 | |||
413 | SHOW_SBITS(name, gb, num) | ||
414 | will return the next num bits and do sign extension | ||
415 | |||
416 | SKIP_BITS(name, gb, num) | ||
417 | will skip over the next num bits | ||
418 | note, this is equivalent to SKIP_CACHE; SKIP_COUNTER | ||
419 | |||
420 | SKIP_CACHE(name, gb, num) | ||
421 | will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER) | ||
422 | |||
423 | SKIP_COUNTER(name, gb, num) | ||
424 | will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS) | ||
425 | |||
426 | LAST_SKIP_CACHE(name, gb, num) | ||
427 | will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing | ||
428 | |||
429 | LAST_SKIP_BITS(name, gb, num) | ||
430 | is equivalent to SKIP_LAST_CACHE; SKIP_COUNTER | ||
431 | |||
432 | for examples see get_bits, show_bits, skip_bits, get_vlc | ||
433 | */ | ||
434 | |||
435 | static inline int unaligned32_be(const void *v) | ||
436 | { | ||
437 | #ifdef CONFIG_ALIGN | ||
438 | const uint8_t *p=v; | ||
439 | return (((p[0]<<8) | p[1])<<16) | (p[2]<<8) | (p[3]); | ||
440 | #else | ||
441 | return be2me_32( unaligned32(v)); //original | ||
442 | #endif | ||
443 | } | ||
444 | |||
445 | static inline int unaligned32_le(const void *v) | ||
446 | { | ||
447 | #ifdef CONFIG_ALIGN | ||
448 | const uint8_t *p=v; | ||
449 | return (((p[3]<<8) | p[2])<<16) | (p[1]<<8) | (p[0]); | ||
450 | #else | ||
451 | return le2me_32( unaligned32(v)); //original | ||
452 | #endif | ||
453 | } | ||
454 | |||
455 | #ifdef ALT_BITSTREAM_READER | ||
456 | # define MIN_CACHE_BITS 25 | ||
457 | |||
458 | # define OPEN_READER(name, gb)\ | ||
459 | int name##_index= (gb)->index;\ | ||
460 | int name##_cache= 0;\ | ||
461 | |||
462 | # define CLOSE_READER(name, gb)\ | ||
463 | (gb)->index= name##_index;\ | ||
464 | |||
465 | # ifdef ALT_BITSTREAM_READER_LE | ||
466 | # define UPDATE_CACHE(name, gb)\ | ||
467 | name##_cache= unaligned32_le( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\ | ||
468 | |||
469 | # define SKIP_CACHE(name, gb, num)\ | ||
470 | name##_cache >>= (num); | ||
471 | # else | ||
472 | # define UPDATE_CACHE(name, gb)\ | ||
473 | name##_cache= unaligned32_be( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\ | ||
474 | |||
475 | # define SKIP_CACHE(name, gb, num)\ | ||
476 | name##_cache <<= (num); | ||
477 | # endif | ||
478 | |||
479 | // FIXME name? | ||
480 | # define SKIP_COUNTER(name, gb, num)\ | ||
481 | name##_index += (num);\ | ||
482 | |||
483 | # define SKIP_BITS(name, gb, num)\ | ||
484 | {\ | ||
485 | SKIP_CACHE(name, gb, num)\ | ||
486 | SKIP_COUNTER(name, gb, num)\ | ||
487 | }\ | ||
488 | |||
489 | # define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num) | ||
490 | # define LAST_SKIP_CACHE(name, gb, num) ; | ||
491 | |||
492 | # ifdef ALT_BITSTREAM_READER_LE | ||
493 | # define SHOW_UBITS(name, gb, num)\ | ||
494 | ((name##_cache) & (NEG_USR32(0xffffffff,num))) | ||
495 | |||
496 | # define SHOW_SBITS(name, gb, num)\ | ||
497 | NEG_SSR32((name##_cache)<<(32-(num)), num) | ||
498 | # else | ||
499 | # define SHOW_UBITS(name, gb, num)\ | ||
500 | NEG_USR32(name##_cache, num) | ||
501 | |||
502 | # define SHOW_SBITS(name, gb, num)\ | ||
503 | NEG_SSR32(name##_cache, num) | ||
504 | # endif | ||
505 | |||
506 | # define GET_CACHE(name, gb)\ | ||
507 | ((uint32_t)name##_cache) | ||
508 | |||
509 | static inline int get_bits_count(GetBitContext *s){ | ||
510 | return s->index; | ||
511 | } | ||
512 | |||
513 | static inline void skip_bits_long(GetBitContext *s, int n){ | ||
514 | s->index += n; | ||
515 | } | ||
516 | |||
517 | #elif defined LIBMPEG2_BITSTREAM_READER | ||
518 | //libmpeg2 like reader | ||
519 | |||
520 | # define MIN_CACHE_BITS 17 | ||
521 | |||
522 | # define OPEN_READER(name, gb)\ | ||
523 | int name##_bit_count=(gb)->bit_count;\ | ||
524 | int name##_cache= (gb)->cache;\ | ||
525 | uint8_t * name##_buffer_ptr=(gb)->buffer_ptr;\ | ||
526 | |||
527 | # define CLOSE_READER(name, gb)\ | ||
528 | (gb)->bit_count= name##_bit_count;\ | ||
529 | (gb)->cache= name##_cache;\ | ||
530 | (gb)->buffer_ptr= name##_buffer_ptr;\ | ||
531 | |||
532 | #ifdef LIBMPEG2_BITSTREAM_READER_HACK | ||
533 | |||
534 | # define UPDATE_CACHE(name, gb)\ | ||
535 | if(name##_bit_count >= 0){\ | ||
536 | name##_cache+= (int)be2me_16(*(uint16_t*)name##_buffer_ptr) << name##_bit_count;\ | ||
537 | name##_buffer_ptr += 2;\ | ||
538 | name##_bit_count-= 16;\ | ||
539 | }\ | ||
540 | |||
541 | #else | ||
542 | |||
543 | # define UPDATE_CACHE(name, gb)\ | ||
544 | if(name##_bit_count >= 0){\ | ||
545 | name##_cache+= ((name##_buffer_ptr[0]<<8) + name##_buffer_ptr[1]) << name##_bit_count;\ | ||
546 | name##_buffer_ptr+=2;\ | ||
547 | name##_bit_count-= 16;\ | ||
548 | }\ | ||
549 | |||
550 | #endif | ||
551 | |||
552 | # define SKIP_CACHE(name, gb, num)\ | ||
553 | name##_cache <<= (num);\ | ||
554 | |||
555 | # define SKIP_COUNTER(name, gb, num)\ | ||
556 | name##_bit_count += (num);\ | ||
557 | |||
558 | # define SKIP_BITS(name, gb, num)\ | ||
559 | {\ | ||
560 | SKIP_CACHE(name, gb, num)\ | ||
561 | SKIP_COUNTER(name, gb, num)\ | ||
562 | }\ | ||
563 | |||
564 | # define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num) | ||
565 | # define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num) | ||
566 | |||
567 | # define SHOW_UBITS(name, gb, num)\ | ||
568 | NEG_USR32(name##_cache, num) | ||
569 | |||
570 | # define SHOW_SBITS(name, gb, num)\ | ||
571 | NEG_SSR32(name##_cache, num) | ||
572 | |||
573 | # define GET_CACHE(name, gb)\ | ||
574 | ((uint32_t)name##_cache) | ||
575 | |||
576 | static inline int get_bits_count(GetBitContext *s){ | ||
577 | return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count; | ||
578 | } | ||
579 | |||
580 | static inline void skip_bits_long(GetBitContext *s, int n){ | ||
581 | OPEN_READER(re, s) | ||
582 | re_bit_count += n; | ||
583 | re_buffer_ptr += 2*(re_bit_count>>4); | ||
584 | re_bit_count &= 15; | ||
585 | re_cache = ((re_buffer_ptr[-2]<<8) + re_buffer_ptr[-1]) << (16+re_bit_count); | ||
586 | UPDATE_CACHE(re, s) | ||
587 | CLOSE_READER(re, s) | ||
588 | } | ||
589 | |||
590 | #elif defined A32_BITSTREAM_READER | ||
591 | |||
592 | # define MIN_CACHE_BITS 32 | ||
593 | |||
594 | # define OPEN_READER(name, gb)\ | ||
595 | int name##_bit_count=(gb)->bit_count;\ | ||
596 | uint32_t name##_cache0= (gb)->cache0;\ | ||
597 | uint32_t name##_cache1= (gb)->cache1;\ | ||
598 | uint32_t * name##_buffer_ptr=(gb)->buffer_ptr;\ | ||
599 | |||
600 | # define CLOSE_READER(name, gb)\ | ||
601 | (gb)->bit_count= name##_bit_count;\ | ||
602 | (gb)->cache0= name##_cache0;\ | ||
603 | (gb)->cache1= name##_cache1;\ | ||
604 | (gb)->buffer_ptr= name##_buffer_ptr;\ | ||
605 | |||
606 | # define UPDATE_CACHE(name, gb)\ | ||
607 | if(name##_bit_count > 0){\ | ||
608 | const uint32_t next= be2me_32( *name##_buffer_ptr );\ | ||
609 | name##_cache0 |= NEG_USR32(next,name##_bit_count);\ | ||
610 | name##_cache1 |= next<<name##_bit_count;\ | ||
611 | name##_buffer_ptr++;\ | ||
612 | name##_bit_count-= 32;\ | ||
613 | }\ | ||
614 | |||
615 | #if defined(ARCH_X86) | ||
616 | # define SKIP_CACHE(name, gb, num)\ | ||
617 | asm(\ | ||
618 | "shldl %2, %1, %0 \n\t"\ | ||
619 | "shll %2, %1 \n\t"\ | ||
620 | : "+r" (name##_cache0), "+r" (name##_cache1)\ | ||
621 | : "Ic" ((uint8_t)(num))\ | ||
622 | ); | ||
623 | #else | ||
624 | # define SKIP_CACHE(name, gb, num)\ | ||
625 | name##_cache0 <<= (num);\ | ||
626 | name##_cache0 |= NEG_USR32(name##_cache1,num);\ | ||
627 | name##_cache1 <<= (num); | ||
628 | #endif | ||
629 | |||
630 | # define SKIP_COUNTER(name, gb, num)\ | ||
631 | name##_bit_count += (num);\ | ||
632 | |||
633 | # define SKIP_BITS(name, gb, num)\ | ||
634 | {\ | ||
635 | SKIP_CACHE(name, gb, num)\ | ||
636 | SKIP_COUNTER(name, gb, num)\ | ||
637 | }\ | ||
638 | |||
639 | # define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num) | ||
640 | # define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num) | ||
641 | |||
642 | # define SHOW_UBITS(name, gb, num)\ | ||
643 | NEG_USR32(name##_cache0, num) | ||
644 | |||
645 | # define SHOW_SBITS(name, gb, num)\ | ||
646 | NEG_SSR32(name##_cache0, num) | ||
647 | |||
648 | # define GET_CACHE(name, gb)\ | ||
649 | (name##_cache0) | ||
650 | |||
651 | static inline int get_bits_count(GetBitContext *s){ | ||
652 | return ((uint8_t*)s->buffer_ptr - s->buffer)*8 - 32 + s->bit_count; | ||
653 | } | ||
654 | |||
655 | static inline void skip_bits_long(GetBitContext *s, int n){ | ||
656 | OPEN_READER(re, s) | ||
657 | re_bit_count += n; | ||
658 | re_buffer_ptr += re_bit_count>>5; | ||
659 | re_bit_count &= 31; | ||
660 | re_cache0 = be2me_32( re_buffer_ptr[-1] ) << re_bit_count; | ||
661 | re_cache1 = 0; | ||
662 | UPDATE_CACHE(re, s) | ||
663 | CLOSE_READER(re, s) | ||
664 | } | ||
665 | |||
666 | #endif | ||
667 | |||
668 | /** | ||
669 | * read mpeg1 dc style vlc (sign bit + mantisse with no MSB). | ||
670 | * if MSB not set it is negative | ||
671 | * @param n length in bits | ||
672 | * @author BERO | ||
673 | */ | ||
674 | static inline int get_xbits(GetBitContext *s, int n){ | ||
675 | register int sign; | ||
676 | register int32_t cache; | ||
677 | OPEN_READER(re, s) | ||
678 | UPDATE_CACHE(re, s) | ||
679 | cache = GET_CACHE(re,s); | ||
680 | sign=(~cache)>>31; | ||
681 | LAST_SKIP_BITS(re, s, n) | ||
682 | CLOSE_READER(re, s) | ||
683 | return (NEG_USR32(sign ^ cache, n) ^ sign) - sign; | ||
684 | } | ||
685 | |||
686 | static inline int get_sbits(GetBitContext *s, int n){ | ||
687 | register int tmp; | ||
688 | OPEN_READER(re, s) | ||
689 | UPDATE_CACHE(re, s) | ||
690 | tmp= SHOW_SBITS(re, s, n); | ||
691 | LAST_SKIP_BITS(re, s, n) | ||
692 | CLOSE_READER(re, s) | ||
693 | return tmp; | ||
694 | } | ||
695 | |||
696 | /** | ||
697 | * reads 1-17 bits. | ||
698 | * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't | ||
699 | */ | ||
700 | static inline unsigned int get_bits(GetBitContext *s, int n){ | ||
701 | register int tmp; | ||
702 | OPEN_READER(re, s) | ||
703 | UPDATE_CACHE(re, s) | ||
704 | tmp= SHOW_UBITS(re, s, n); | ||
705 | LAST_SKIP_BITS(re, s, n) | ||
706 | CLOSE_READER(re, s) | ||
707 | return tmp; | ||
708 | } | ||
709 | |||
710 | /** | ||
711 | * shows 1-17 bits. | ||
712 | * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't | ||
713 | */ | ||
714 | static inline unsigned int show_bits(GetBitContext *s, int n){ | ||
715 | register int tmp; | ||
716 | OPEN_READER(re, s) | ||
717 | UPDATE_CACHE(re, s) | ||
718 | tmp= SHOW_UBITS(re, s, n); | ||
719 | // CLOSE_READER(re, s) | ||
720 | return tmp; | ||
721 | } | ||
722 | |||
723 | static inline void skip_bits(GetBitContext *s, int n){ | ||
724 | //Note gcc seems to optimize this to s->index+=n for the ALT_READER :)) | ||
725 | OPEN_READER(re, s) | ||
726 | UPDATE_CACHE(re, s) | ||
727 | LAST_SKIP_BITS(re, s, n) | ||
728 | CLOSE_READER(re, s) | ||
729 | } | ||
730 | |||
731 | static inline unsigned int get_bits1(GetBitContext *s){ | ||
732 | #ifdef ALT_BITSTREAM_READER | ||
733 | int index= s->index; | ||
734 | uint8_t result= s->buffer[ index>>3 ]; | ||
735 | #ifdef ALT_BITSTREAM_READER_LE | ||
736 | result>>= (index&0x07); | ||
737 | result&= 1; | ||
738 | #else | ||
739 | result<<= (index&0x07); | ||
740 | result>>= 8 - 1; | ||
741 | #endif | ||
742 | index++; | ||
743 | s->index= index; | ||
744 | |||
745 | return result; | ||
746 | #else | ||
747 | return get_bits(s, 1); | ||
748 | #endif | ||
749 | } | ||
750 | |||
751 | static inline unsigned int show_bits1(GetBitContext *s){ | ||
752 | return show_bits(s, 1); | ||
753 | } | ||
754 | |||
755 | static inline void skip_bits1(GetBitContext *s){ | ||
756 | skip_bits(s, 1); | ||
757 | } | ||
758 | |||
759 | /** | ||
760 | * reads 0-32 bits. | ||
761 | */ | ||
762 | static inline unsigned int get_bits_long(GetBitContext *s, int n){ | ||
763 | if(n<=17) return get_bits(s, n); | ||
764 | else{ | ||
765 | #ifdef ALT_BITSTREAM_READER_LE | ||
766 | int ret= get_bits(s, 16); | ||
767 | return ret | (get_bits(s, n-16) << 16); | ||
768 | #else | ||
769 | int ret= get_bits(s, 16) << (n-16); | ||
770 | return ret | get_bits(s, n-16); | ||
771 | #endif | ||
772 | } | ||
773 | } | ||
774 | |||
775 | /** | ||
776 | * shows 0-32 bits. | ||
777 | */ | ||
778 | static inline unsigned int show_bits_long(GetBitContext *s, int n){ | ||
779 | if(n<=17) return show_bits(s, n); | ||
780 | else{ | ||
781 | GetBitContext gb= *s; | ||
782 | int ret= get_bits_long(s, n); | ||
783 | *s= gb; | ||
784 | return ret; | ||
785 | } | ||
786 | } | ||
787 | |||
788 | /* | ||
789 | static inline int check_marker(GetBitContext *s, const char *msg) | ||
790 | { | ||
791 | int bit= get_bits1(s); | ||
792 | if(!bit) | ||
793 | av_log(NULL, AV_LOG_INFO, "Marker bit missing %s\n", msg); | ||
794 | |||
795 | return bit; | ||
796 | } | ||
797 | */ | ||
798 | /** | ||
799 | * init GetBitContext. | ||
800 | * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits | ||
801 | * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end | ||
802 | * @param bit_size the size of the buffer in bits | ||
803 | */ | ||
804 | static inline void init_get_bits(GetBitContext *s, | ||
805 | const uint8_t *buffer, int bit_size) | ||
806 | { | ||
807 | int buffer_size= (bit_size+7)>>3; | ||
808 | if(buffer_size < 0 || bit_size < 0) { | ||
809 | buffer_size = bit_size = 0; | ||
810 | buffer = NULL; | ||
811 | } | ||
812 | |||
813 | s->buffer= buffer; | ||
814 | s->size_in_bits= bit_size; | ||
815 | s->buffer_end= buffer + buffer_size; | ||
816 | #ifdef ALT_BITSTREAM_READER | ||
817 | s->index=0; | ||
818 | #elif defined LIBMPEG2_BITSTREAM_READER | ||
819 | s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1)); | ||
820 | s->bit_count = 16 + 8*((intptr_t)buffer&1); | ||
821 | skip_bits_long(s, 0); | ||
822 | #elif defined A32_BITSTREAM_READER | ||
823 | s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3)); | ||
824 | s->bit_count = 32 + 8*((intptr_t)buffer&3); | ||
825 | skip_bits_long(s, 0); | ||
826 | #endif | ||
827 | } | ||
828 | |||
829 | static inline void align_get_bits(GetBitContext *s) | ||
830 | { | ||
831 | int n= (-get_bits_count(s)) & 7; | ||
832 | if(n) skip_bits(s, n); | ||
833 | } | ||
834 | |||
835 | int init_vlc(VLC *vlc, int nb_bits, int nb_codes, | ||
836 | const void *bits, int bits_wrap, int bits_size, | ||
837 | const void *codes, int codes_wrap, int codes_size, | ||
838 | int flags); | ||
839 | #define INIT_VLC_USE_STATIC 1 | ||
840 | #define INIT_VLC_LE 2 | ||
841 | void free_vlc(VLC *vlc); | ||
842 | |||
843 | /** | ||
844 | * | ||
845 | * if the vlc code is invalid and max_depth=1 than no bits will be removed | ||
846 | * if the vlc code is invalid and max_depth>1 than the number of bits removed | ||
847 | * is undefined | ||
848 | */ | ||
849 | #define GET_VLC(code, name, gb, table, bits, max_depth)\ | ||
850 | {\ | ||
851 | int n, index, nb_bits;\ | ||
852 | \ | ||
853 | index= SHOW_UBITS(name, gb, bits);\ | ||
854 | code = table[index][0];\ | ||
855 | n = table[index][1];\ | ||
856 | \ | ||
857 | if(max_depth > 1 && n < 0){\ | ||
858 | LAST_SKIP_BITS(name, gb, bits)\ | ||
859 | UPDATE_CACHE(name, gb)\ | ||
860 | \ | ||
861 | nb_bits = -n;\ | ||
862 | \ | ||
863 | index= SHOW_UBITS(name, gb, nb_bits) + code;\ | ||
864 | code = table[index][0];\ | ||
865 | n = table[index][1];\ | ||
866 | if(max_depth > 2 && n < 0){\ | ||
867 | LAST_SKIP_BITS(name, gb, nb_bits)\ | ||
868 | UPDATE_CACHE(name, gb)\ | ||
869 | \ | ||
870 | nb_bits = -n;\ | ||
871 | \ | ||
872 | index= SHOW_UBITS(name, gb, nb_bits) + code;\ | ||
873 | code = table[index][0];\ | ||
874 | n = table[index][1];\ | ||
875 | }\ | ||
876 | }\ | ||
877 | SKIP_BITS(name, gb, n)\ | ||
878 | } | ||
879 | |||
880 | #define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\ | ||
881 | {\ | ||
882 | int n, index, nb_bits;\ | ||
883 | \ | ||
884 | index= SHOW_UBITS(name, gb, bits);\ | ||
885 | level = table[index].level;\ | ||
886 | n = table[index].len;\ | ||
887 | \ | ||
888 | if(max_depth > 1 && n < 0){\ | ||
889 | SKIP_BITS(name, gb, bits)\ | ||
890 | if(need_update){\ | ||
891 | UPDATE_CACHE(name, gb)\ | ||
892 | }\ | ||
893 | \ | ||
894 | nb_bits = -n;\ | ||
895 | \ | ||
896 | index= SHOW_UBITS(name, gb, nb_bits) + level;\ | ||
897 | level = table[index].level;\ | ||
898 | n = table[index].len;\ | ||
899 | }\ | ||
900 | run= table[index].run;\ | ||
901 | SKIP_BITS(name, gb, n)\ | ||
902 | } | ||
903 | |||
904 | |||
905 | /** | ||
906 | * parses a vlc code, faster then get_vlc() | ||
907 | * @param bits is the number of bits which will be read at once, must be | ||
908 | * identical to nb_bits in init_vlc() | ||
909 | * @param max_depth is the number of times bits bits must be read to completely | ||
910 | * read the longest vlc code | ||
911 | * = (max_vlc_length + bits - 1) / bits | ||
912 | */ | ||
913 | static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2], | ||
914 | int bits, int max_depth) | ||
915 | { | ||
916 | int code; | ||
917 | |||
918 | OPEN_READER(re, s) | ||
919 | UPDATE_CACHE(re, s) | ||
920 | |||
921 | GET_VLC(code, re, s, table, bits, max_depth) | ||
922 | |||
923 | CLOSE_READER(re, s) | ||
924 | return code; | ||
925 | } | ||
926 | |||
927 | //#define TRACE | ||
928 | |||
929 | #ifdef TRACE | ||
930 | static inline void print_bin(int bits, int n){ | ||
931 | int i; | ||
932 | |||
933 | for(i=n-1; i>=0; i--){ | ||
934 | av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1); | ||
935 | } | ||
936 | for(i=n; i<24; i++) | ||
937 | av_log(NULL, AV_LOG_DEBUG, " "); | ||
938 | } | ||
939 | |||
940 | static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ | ||
941 | int r= get_bits(s, n); | ||
942 | |||
943 | print_bin(r, n); | ||
944 | av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line); | ||
945 | return r; | ||
946 | } | ||
947 | static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, const char *func, int line){ | ||
948 | int show= show_bits(s, 24); | ||
949 | int pos= get_bits_count(s); | ||
950 | int r= get_vlc2(s, table, bits, max_depth); | ||
951 | int len= get_bits_count(s) - pos; | ||
952 | int bits2= show>>(24-len); | ||
953 | |||
954 | print_bin(bits2, len); | ||
955 | |||
956 | av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line); | ||
957 | return r; | ||
958 | } | ||
959 | static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ | ||
960 | int show= show_bits(s, n); | ||
961 | int r= get_xbits(s, n); | ||
962 | |||
963 | print_bin(show, n); | ||
964 | av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line); | ||
965 | return r; | ||
966 | } | ||
967 | |||
968 | #define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__) | ||
969 | #define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__) | ||
970 | #define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__) | ||
971 | #define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__) | ||
972 | #define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__) | ||
973 | |||
974 | #define tprintf(p, ...) av_log(p, AV_LOG_DEBUG, __VA_ARGS__) | ||
975 | |||
976 | #else //TRACE | ||
977 | #define tprintf(p, ...) {} | ||
978 | #endif | ||
979 | |||
980 | static inline int decode012(GetBitContext *gb){ | ||
981 | int n; | ||
982 | n = get_bits1(gb); | ||
983 | if (n == 0) | ||
984 | return 0; | ||
985 | else | ||
986 | return get_bits1(gb) + 1; | ||
987 | } | ||
988 | |||
989 | #endif /* BITSTREAM_H */ | ||
diff --git a/apps/codecs/libwma/ffmpeg_config.h b/apps/codecs/libwma/ffmpeg_config.h deleted file mode 100644 index 12b0666e42..0000000000 --- a/apps/codecs/libwma/ffmpeg_config.h +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | /* Automatically generated by configure - do not modify */ | ||
2 | #ifndef _FFMPEG_CONFIG_H | ||
3 | #define _FFMPEG_CONFIG_H | ||
4 | #include "codecs.h" | ||
5 | |||
6 | #ifdef CPU_ARM | ||
7 | #define CONFIG_ALIGN 1 | ||
8 | #endif | ||
9 | |||
10 | #ifdef ROCKBOX_BIG_ENDIAN | ||
11 | #define WORDS_BIGENDIAN | ||
12 | #endif | ||
13 | |||
14 | #endif | ||
diff --git a/apps/codecs/libwma/wmadec.h b/apps/codecs/libwma/wmadec.h index d22e435304..0b09f3e817 100644 --- a/apps/codecs/libwma/wmadec.h +++ b/apps/codecs/libwma/wmadec.h | |||
@@ -21,7 +21,7 @@ | |||
21 | #define _WMADEC_H | 21 | #define _WMADEC_H |
22 | 22 | ||
23 | #include "asf.h" | 23 | #include "asf.h" |
24 | #include "bitstream.h" /* For GetBitContext */ | 24 | #include "ffmpeg_bitstream.h" /* For GetBitContext */ |
25 | #include "types.h" | 25 | #include "types.h" |
26 | //#include "dsputil.h" /* For MDCTContext */ | 26 | //#include "dsputil.h" /* For MDCTContext */ |
27 | 27 | ||
diff --git a/apps/codecs/libwma/wmadeci.c b/apps/codecs/libwma/wmadeci.c index d1baca4c99..f01ffefc13 100644 --- a/apps/codecs/libwma/wmadeci.c +++ b/apps/codecs/libwma/wmadeci.c | |||
@@ -30,6 +30,34 @@ | |||
30 | #include "bitstream.h" | 30 | #include "bitstream.h" |
31 | #include "wmadata.h" | 31 | #include "wmadata.h" |
32 | 32 | ||
33 | static const uint8_t ff_log2_tab[256]={ | ||
34 | 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, | ||
35 | 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, | ||
36 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, | ||
37 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, | ||
38 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
39 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
40 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
41 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 | ||
42 | }; | ||
43 | |||
44 | static inline int av_log2(unsigned int v) | ||
45 | { | ||
46 | int n; | ||
47 | |||
48 | n = 0; | ||
49 | if (v & 0xffff0000) { | ||
50 | v >>= 16; | ||
51 | n += 16; | ||
52 | } | ||
53 | if (v & 0xff00) { | ||
54 | v >>= 8; | ||
55 | n += 8; | ||
56 | } | ||
57 | n += ff_log2_tab[v]; | ||
58 | |||
59 | return n; | ||
60 | } | ||
33 | 61 | ||
34 | static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len); | 62 | static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len); |
35 | inline void vector_fmul_add_add(fixed32 *dst, const fixed32 *data, | 63 | inline void vector_fmul_add_add(fixed32 *dst, const fixed32 *data, |