diff options
Diffstat (limited to 'apps/codecs/libffmpegFLAC')
-rw-r--r-- | apps/codecs/libffmpegFLAC/SOURCES | 1 | ||||
-rw-r--r-- | apps/codecs/libffmpegFLAC/bitstream.c | 62 | ||||
-rw-r--r-- | apps/codecs/libffmpegFLAC/bitstream.h | 278 | ||||
-rw-r--r-- | apps/codecs/libffmpegFLAC/shndec.c | 11 |
4 files changed, 1 insertions, 351 deletions
diff --git a/apps/codecs/libffmpegFLAC/SOURCES b/apps/codecs/libffmpegFLAC/SOURCES index deed19bcec..63094b30a6 100644 --- a/apps/codecs/libffmpegFLAC/SOURCES +++ b/apps/codecs/libffmpegFLAC/SOURCES | |||
@@ -1,4 +1,3 @@ | |||
1 | bitstream.c | ||
2 | decoder.c | 1 | decoder.c |
3 | shndec.c | 2 | shndec.c |
4 | #if defined(CPU_COLDFIRE) | 3 | #if defined(CPU_COLDFIRE) |
diff --git a/apps/codecs/libffmpegFLAC/bitstream.c b/apps/codecs/libffmpegFLAC/bitstream.c deleted file mode 100644 index e53ec0fd46..0000000000 --- a/apps/codecs/libffmpegFLAC/bitstream.c +++ /dev/null | |||
@@ -1,62 +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 library 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 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * This library 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 this library; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | * | ||
20 | * alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at> | ||
21 | */ | ||
22 | |||
23 | /** | ||
24 | * @file bitstream.c | ||
25 | * bitstream api. | ||
26 | */ | ||
27 | |||
28 | #include <stdio.h> | ||
29 | #include "bitstream.h" | ||
30 | |||
31 | /* bit input functions */ | ||
32 | |||
33 | /** | ||
34 | * reads 0-32 bits. | ||
35 | */ | ||
36 | unsigned int get_bits_long(GetBitContext *s, int n){ | ||
37 | if(n<=17) return get_bits(s, n); | ||
38 | else{ | ||
39 | int ret= get_bits(s, 16) << (n-16); | ||
40 | return ret | get_bits(s, n-16); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | /** | ||
45 | * shows 0-32 bits. | ||
46 | */ | ||
47 | unsigned int show_bits_long(GetBitContext *s, int n){ | ||
48 | if(n<=17) return show_bits(s, n); | ||
49 | else{ | ||
50 | GetBitContext gb= *s; | ||
51 | int ret= get_bits_long(s, n); | ||
52 | *s= gb; | ||
53 | return ret; | ||
54 | } | ||
55 | } | ||
56 | |||
57 | void align_get_bits(GetBitContext *s) | ||
58 | { | ||
59 | int n= (-get_bits_count(s)) & 7; | ||
60 | if(n) skip_bits(s, n); | ||
61 | } | ||
62 | |||
diff --git a/apps/codecs/libffmpegFLAC/bitstream.h b/apps/codecs/libffmpegFLAC/bitstream.h index 9a8c548d95..1333b9f4b8 100644 --- a/apps/codecs/libffmpegFLAC/bitstream.h +++ b/apps/codecs/libffmpegFLAC/bitstream.h | |||
@@ -7,6 +7,7 @@ | |||
7 | #define BITSTREAM_H | 7 | #define BITSTREAM_H |
8 | 8 | ||
9 | #include <inttypes.h> | 9 | #include <inttypes.h> |
10 | #include "ffmpeg_get_bits.h" | ||
10 | 11 | ||
11 | #ifndef BUILD_STANDALONE | 12 | #ifndef BUILD_STANDALONE |
12 | #include <config.h> | 13 | #include <config.h> |
@@ -61,281 +62,4 @@ | |||
61 | } | 62 | } |
62 | #endif | 63 | #endif |
63 | 64 | ||
64 | /* FLAC files are big-endian */ | ||
65 | #define ALT_BITSTREAM_READER_BE | ||
66 | |||
67 | #define NEG_SSR32(a,s) (((int32_t)(a))>>(32-(s))) | ||
68 | #define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s))) | ||
69 | |||
70 | /* bit input */ | ||
71 | /* buffer, buffer_end and size_in_bits must be present and used by every reader */ | ||
72 | typedef struct GetBitContext { | ||
73 | const uint8_t *buffer, *buffer_end; | ||
74 | int index; | ||
75 | int size_in_bits; | ||
76 | } GetBitContext; | ||
77 | |||
78 | #define VLC_TYPE int16_t | ||
79 | |||
80 | typedef struct VLC { | ||
81 | int bits; | ||
82 | VLC_TYPE (*table)[2]; ///< code, bits | ||
83 | int table_size, table_allocated; | ||
84 | } VLC; | ||
85 | |||
86 | typedef struct RL_VLC_ELEM { | ||
87 | int16_t level; | ||
88 | int8_t len; | ||
89 | uint8_t run; | ||
90 | } RL_VLC_ELEM; | ||
91 | |||
92 | #if defined(ARCH_SPARC) || defined(ARCH_ARMV4L) | ||
93 | #define UNALIGNED_STORES_ARE_BAD | ||
94 | #endif | ||
95 | |||
96 | /* used to avoid missaligned exceptions on some archs (alpha, ...) */ | ||
97 | #if defined(ARCH_X86) || defined(ARCH_X86_64) | ||
98 | # define unaligned32(a) (*(const uint32_t*)(a)) | ||
99 | #else | ||
100 | # ifdef __GNUC__ | ||
101 | static inline uint32_t unaligned32(const void *v) { | ||
102 | struct Unaligned { | ||
103 | uint32_t i; | ||
104 | } __attribute__((packed)); | ||
105 | |||
106 | return ((const struct Unaligned *) v)->i; | ||
107 | } | ||
108 | # elif defined(__DECC) | ||
109 | static inline uint32_t unaligned32(const void *v) { | ||
110 | return *(const __unaligned uint32_t *) v; | ||
111 | } | ||
112 | # else | ||
113 | static inline uint32_t unaligned32(const void *v) { | ||
114 | return *(const uint32_t *) v; | ||
115 | } | ||
116 | # endif | ||
117 | #endif //!ARCH_X86 | ||
118 | |||
119 | |||
120 | /* Bitstream reader API docs: | ||
121 | name | ||
122 | abritary name which is used as prefix for the internal variables | ||
123 | |||
124 | gb | ||
125 | getbitcontext | ||
126 | |||
127 | OPEN_READER(name, gb) | ||
128 | loads gb into local variables | ||
129 | |||
130 | CLOSE_READER(name, gb) | ||
131 | stores local vars in gb | ||
132 | |||
133 | UPDATE_CACHE(name, gb) | ||
134 | refills the internal cache from the bitstream | ||
135 | after this call at least MIN_CACHE_BITS will be available, | ||
136 | |||
137 | GET_CACHE(name, gb) | ||
138 | will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit) | ||
139 | |||
140 | SHOW_UBITS(name, gb, num) | ||
141 | will return the next num bits | ||
142 | |||
143 | SHOW_SBITS(name, gb, num) | ||
144 | will return the next num bits and do sign extension | ||
145 | |||
146 | SKIP_BITS(name, gb, num) | ||
147 | will skip over the next num bits | ||
148 | note, this is equivalent to SKIP_CACHE; SKIP_COUNTER | ||
149 | |||
150 | SKIP_CACHE(name, gb, num) | ||
151 | will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER) | ||
152 | |||
153 | SKIP_COUNTER(name, gb, num) | ||
154 | will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS) | ||
155 | |||
156 | LAST_SKIP_CACHE(name, gb, num) | ||
157 | will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing | ||
158 | |||
159 | LAST_SKIP_BITS(name, gb, num) | ||
160 | is equivalent to SKIP_LAST_CACHE; SKIP_COUNTER | ||
161 | |||
162 | for examples see get_bits, show_bits, skip_bits, get_vlc | ||
163 | */ | ||
164 | |||
165 | static inline int unaligned32_be(const void *v) | ||
166 | { | ||
167 | #ifdef CONFIG_ALIGN | ||
168 | const uint8_t *p=v; | ||
169 | return (((p[0]<<8) | p[1])<<16) | (p[2]<<8) | (p[3]); | ||
170 | #else | ||
171 | return betoh32( unaligned32(v)); //original | ||
172 | #endif | ||
173 | } | ||
174 | |||
175 | static inline int unaligned32_le(const void *v) | ||
176 | { | ||
177 | #ifdef CONFIG_ALIGN | ||
178 | const uint8_t *p=v; | ||
179 | return (((p[3]<<8) | p[2])<<16) | (p[1]<<8) | (p[0]); | ||
180 | #else | ||
181 | return letoh32( unaligned32(v)); //original | ||
182 | #endif | ||
183 | } | ||
184 | |||
185 | # define MIN_CACHE_BITS 25 | ||
186 | |||
187 | # define OPEN_READER(name, gb)\ | ||
188 | int name##_index= (gb)->index;\ | ||
189 | int name##_cache= 0;\ | ||
190 | |||
191 | # define CLOSE_READER(name, gb)\ | ||
192 | (gb)->index= name##_index;\ | ||
193 | |||
194 | # ifdef ALT_BITSTREAM_READER_LE | ||
195 | # define UPDATE_CACHE(name, gb)\ | ||
196 | name##_cache= unaligned32_le( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\ | ||
197 | |||
198 | # define SKIP_CACHE(name, gb, num)\ | ||
199 | name##_cache >>= (num); | ||
200 | # else | ||
201 | # define UPDATE_CACHE(name, gb)\ | ||
202 | name##_cache= unaligned32_be( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\ | ||
203 | |||
204 | # define SKIP_CACHE(name, gb, num)\ | ||
205 | name##_cache <<= (num); | ||
206 | # endif | ||
207 | |||
208 | // FIXME name? | ||
209 | # define SKIP_COUNTER(name, gb, num)\ | ||
210 | name##_index += (num);\ | ||
211 | |||
212 | # define SKIP_BITS(name, gb, num)\ | ||
213 | {\ | ||
214 | SKIP_CACHE(name, gb, num)\ | ||
215 | SKIP_COUNTER(name, gb, num)\ | ||
216 | }\ | ||
217 | |||
218 | # define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num) | ||
219 | # define LAST_SKIP_CACHE(name, gb, num) ; | ||
220 | |||
221 | # ifdef ALT_BITSTREAM_READER_LE | ||
222 | # define SHOW_UBITS(name, gb, num)\ | ||
223 | ((name##_cache) & (NEG_USR32(0xffffffff,num))) | ||
224 | # else | ||
225 | # define SHOW_UBITS(name, gb, num)\ | ||
226 | NEG_USR32(name##_cache, num) | ||
227 | # endif | ||
228 | |||
229 | # define SHOW_SBITS(name, gb, num)\ | ||
230 | NEG_SSR32(name##_cache, num) | ||
231 | |||
232 | # define GET_CACHE(name, gb)\ | ||
233 | ((uint32_t)name##_cache) | ||
234 | |||
235 | static inline int get_bits_count(GetBitContext *s){ | ||
236 | return s->index; | ||
237 | } | ||
238 | |||
239 | static inline int get_sbits(GetBitContext *s, int n){ | ||
240 | register int tmp; | ||
241 | OPEN_READER(re, s) | ||
242 | UPDATE_CACHE(re, s) | ||
243 | tmp= SHOW_SBITS(re, s, n); | ||
244 | LAST_SKIP_BITS(re, s, n) | ||
245 | CLOSE_READER(re, s) | ||
246 | return tmp; | ||
247 | } | ||
248 | |||
249 | /** | ||
250 | * reads 0-17 bits. | ||
251 | * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't | ||
252 | */ | ||
253 | static inline unsigned int get_bits(GetBitContext *s, int n){ | ||
254 | register int tmp; | ||
255 | OPEN_READER(re, s) | ||
256 | UPDATE_CACHE(re, s) | ||
257 | tmp= SHOW_UBITS(re, s, n); | ||
258 | LAST_SKIP_BITS(re, s, n) | ||
259 | CLOSE_READER(re, s) | ||
260 | return tmp; | ||
261 | } | ||
262 | |||
263 | unsigned int get_bits_long(GetBitContext *s, int n) ICODE_ATTR_FLAC; | ||
264 | |||
265 | /** | ||
266 | * shows 0-17 bits. | ||
267 | * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't | ||
268 | */ | ||
269 | static inline unsigned int show_bits(GetBitContext *s, int n){ | ||
270 | register int tmp; | ||
271 | OPEN_READER(re, s) | ||
272 | UPDATE_CACHE(re, s) | ||
273 | tmp= SHOW_UBITS(re, s, n); | ||
274 | // CLOSE_READER(re, s) | ||
275 | return tmp; | ||
276 | } | ||
277 | |||
278 | unsigned int show_bits_long(GetBitContext *s, int n) ICODE_ATTR_FLAC; | ||
279 | |||
280 | static inline void skip_bits(GetBitContext *s, int n){ | ||
281 | //Note gcc seems to optimize this to s->index+=n for the ALT_READER :)) | ||
282 | OPEN_READER(re, s) | ||
283 | UPDATE_CACHE(re, s) | ||
284 | LAST_SKIP_BITS(re, s, n) | ||
285 | CLOSE_READER(re, s) | ||
286 | } | ||
287 | |||
288 | static inline unsigned int get_bits1(GetBitContext *s){ | ||
289 | int index= s->index; | ||
290 | uint8_t result= s->buffer[ index>>3 ]; | ||
291 | #ifdef ALT_BITSTREAM_READER_LE | ||
292 | result>>= (index&0x07); | ||
293 | result&= 1; | ||
294 | #else | ||
295 | result<<= (index&0x07); | ||
296 | result>>= 8 - 1; | ||
297 | #endif | ||
298 | index++; | ||
299 | s->index= index; | ||
300 | |||
301 | return result; | ||
302 | } | ||
303 | |||
304 | static inline unsigned int show_bits1(GetBitContext *s){ | ||
305 | return show_bits(s, 1); | ||
306 | } | ||
307 | |||
308 | static inline void skip_bits1(GetBitContext *s){ | ||
309 | skip_bits(s, 1); | ||
310 | } | ||
311 | |||
312 | /** | ||
313 | * init GetBitContext. | ||
314 | * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits | ||
315 | * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end | ||
316 | * @param bit_size the size of the buffer in bits | ||
317 | */ | ||
318 | static inline void init_get_bits(GetBitContext *s, | ||
319 | const uint8_t *buffer, int bit_size) | ||
320 | { | ||
321 | int buffer_size= (bit_size+7)>>3; | ||
322 | if(buffer_size < 0 || bit_size < 0) { | ||
323 | buffer_size = bit_size = 0; | ||
324 | buffer = 0; | ||
325 | } | ||
326 | |||
327 | s->buffer= buffer; | ||
328 | s->size_in_bits= bit_size; | ||
329 | s->buffer_end= buffer + buffer_size; | ||
330 | s->index=0; | ||
331 | { | ||
332 | OPEN_READER(re, s) | ||
333 | UPDATE_CACHE(re, s) | ||
334 | UPDATE_CACHE(re, s) | ||
335 | CLOSE_READER(re, s) | ||
336 | } | ||
337 | } | ||
338 | |||
339 | void align_get_bits(GetBitContext *s) ICODE_ATTR_FLAC; | ||
340 | |||
341 | #endif /* BITSTREAM_H */ | 65 | #endif /* BITSTREAM_H */ |
diff --git a/apps/codecs/libffmpegFLAC/shndec.c b/apps/codecs/libffmpegFLAC/shndec.c index fb11f77bfa..b107b356d7 100644 --- a/apps/codecs/libffmpegFLAC/shndec.c +++ b/apps/codecs/libffmpegFLAC/shndec.c | |||
@@ -54,22 +54,11 @@ | |||
54 | #define VERBATIM_BYTE_SIZE 8 | 54 | #define VERBATIM_BYTE_SIZE 8 |
55 | #define CANONICAL_HEADER_SIZE 44 | 55 | #define CANONICAL_HEADER_SIZE 44 |
56 | 56 | ||
57 | #define FFMAX(a,b) ((a) > (b) ? (a) : (b)) | ||
58 | #define FFMIN(a,b) ((a) > (b) ? (b) : (a)) | ||
59 | #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24)) | 57 | #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24)) |
60 | 58 | ||
61 | #define get_le16(gb) bswap_16(get_bits_long(gb, 16)) | 59 | #define get_le16(gb) bswap_16(get_bits_long(gb, 16)) |
62 | #define get_le32(gb) bswap_32(get_bits_long(gb, 32)) | 60 | #define get_le32(gb) bswap_32(get_bits_long(gb, 32)) |
63 | 61 | ||
64 | static uint32_t bswap_32(uint32_t x){ | ||
65 | x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); | ||
66 | return (x>>16) | (x<<16); | ||
67 | } | ||
68 | |||
69 | static uint16_t bswap_16(uint16_t x){ | ||
70 | return (x>>8) | (x<<8); | ||
71 | } | ||
72 | |||
73 | /* converts fourcc string to int */ | 62 | /* converts fourcc string to int */ |
74 | static int ff_get_fourcc(const char *s){ | 63 | static int ff_get_fourcc(const char *s){ |
75 | //assert( strlen(s)==4 ); | 64 | //assert( strlen(s)==4 ); |