/proc/self/cwd/libfaad/rvlc.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding |
3 | | ** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com |
4 | | ** |
5 | | ** This program is free software; you can redistribute it and/or modify |
6 | | ** it under the terms of the GNU General Public License as published by |
7 | | ** the Free Software Foundation; either version 2 of the License, or |
8 | | ** (at your option) any later version. |
9 | | ** |
10 | | ** This program is distributed in the hope that it will be useful, |
11 | | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | ** GNU General Public License for more details. |
14 | | ** |
15 | | ** You should have received a copy of the GNU General Public License |
16 | | ** along with this program; if not, write to the Free Software |
17 | | ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | | ** |
19 | | ** Any non-GPL usage of this software or parts of this software is strictly |
20 | | ** forbidden. |
21 | | ** |
22 | | ** The "appropriate copyright message" mentioned in section 2c of the GPLv2 |
23 | | ** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com" |
24 | | ** |
25 | | ** Commercial non-GPL licensing of this software is possible. |
26 | | ** For more info contact Nero AG through Mpeg4AAClicense@nero.com. |
27 | | ** |
28 | | ** $Id: rvlc.c,v 1.21 2007/11/01 12:33:34 menno Exp $ |
29 | | **/ |
30 | | |
31 | | /* RVLC scalefactor decoding |
32 | | * |
33 | | * RVLC works like this: |
34 | | * 1. Only symmetric huffman codewords are used |
35 | | * 2. Total length of the scalefactor data is stored in the bitsream |
36 | | * 3. Scalefactors are DPCM coded |
37 | | * 4. Next to the starting value for DPCM the ending value is also stored |
38 | | * |
39 | | * With all this it is possible to read the scalefactor data from 2 sides. |
40 | | * If there is a bit error in the scalefactor data it is possible to start |
41 | | * decoding from the other end of the data, to find all but 1 scalefactor. |
42 | | */ |
43 | | |
44 | | #include "common.h" |
45 | | #include "structs.h" |
46 | | |
47 | | #include <stdlib.h> |
48 | | |
49 | | #include "syntax.h" |
50 | | #include "bits.h" |
51 | | #include "rvlc.h" |
52 | | |
53 | | |
54 | | #ifdef ERROR_RESILIENCE |
55 | | |
56 | | //#define PRINT_RVLC |
57 | | |
58 | | /* static function declarations */ |
59 | | static uint8_t rvlc_decode_sf_forward(ic_stream *ics, |
60 | | bitfile *ld_sf, |
61 | | bitfile *ld_esc, |
62 | | uint8_t *is_used); |
63 | | #if 0 |
64 | | static uint8_t rvlc_decode_sf_reverse(ic_stream *ics, |
65 | | bitfile *ld_sf, |
66 | | bitfile *ld_esc, |
67 | | uint8_t is_used); |
68 | | #endif |
69 | | static int8_t rvlc_huffman_sf(bitfile *ld_sf, bitfile *ld_esc /*, |
70 | | int8_t direction*/); |
71 | | static int8_t rvlc_huffman_esc(bitfile *ld_esc /*, int8_t direction*/); |
72 | | |
73 | | |
74 | | uint8_t rvlc_scale_factor_data(ic_stream *ics, bitfile *ld) |
75 | 0 | { |
76 | 0 | uint8_t bits = 9; |
77 | |
|
78 | 0 | ics->sf_concealment = faad_get1bit(ld |
79 | 0 | DEBUGVAR(1,149,"rvlc_scale_factor_data(): sf_concealment")); |
80 | 0 | ics->rev_global_gain = (uint8_t)faad_getbits(ld, 8 |
81 | 0 | DEBUGVAR(1,150,"rvlc_scale_factor_data(): rev_global_gain")); |
82 | |
|
83 | 0 | if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) |
84 | 0 | bits = 11; |
85 | | |
86 | | /* the number of bits used for the huffman codewords */ |
87 | 0 | ics->length_of_rvlc_sf = (uint16_t)faad_getbits(ld, bits |
88 | 0 | DEBUGVAR(1,151,"rvlc_scale_factor_data(): length_of_rvlc_sf")); |
89 | |
|
90 | 0 | if (ics->noise_used) |
91 | 0 | { |
92 | 0 | ics->dpcm_noise_nrg = (uint16_t)faad_getbits(ld, 9 |
93 | 0 | DEBUGVAR(1,152,"rvlc_scale_factor_data(): dpcm_noise_nrg")); |
94 | |
|
95 | 0 | ics->length_of_rvlc_sf -= 9; |
96 | 0 | } |
97 | |
|
98 | 0 | ics->sf_escapes_present = faad_get1bit(ld |
99 | 0 | DEBUGVAR(1,153,"rvlc_scale_factor_data(): sf_escapes_present")); |
100 | |
|
101 | 0 | if (ics->sf_escapes_present) |
102 | 0 | { |
103 | 0 | ics->length_of_rvlc_escapes = (uint8_t)faad_getbits(ld, 8 |
104 | 0 | DEBUGVAR(1,154,"rvlc_scale_factor_data(): length_of_rvlc_escapes")); |
105 | 0 | } |
106 | |
|
107 | 0 | if (ics->noise_used) |
108 | 0 | { |
109 | 0 | ics->dpcm_noise_last_position = (uint16_t)faad_getbits(ld, 9 |
110 | 0 | DEBUGVAR(1,155,"rvlc_scale_factor_data(): dpcm_noise_last_position")); |
111 | 0 | } |
112 | |
|
113 | 0 | return 0; |
114 | 0 | } |
115 | | |
116 | | uint8_t rvlc_decode_scale_factors(ic_stream *ics, bitfile *ld) |
117 | 0 | { |
118 | 0 | uint8_t result; |
119 | 0 | uint8_t intensity_used = 0; |
120 | 0 | uint8_t *rvlc_sf_buffer = NULL; |
121 | 0 | uint8_t *rvlc_esc_buffer = NULL; |
122 | 0 | bitfile ld_rvlc_sf = {0}, ld_rvlc_esc = {0}; |
123 | | // bitfile ld_rvlc_sf_rev, ld_rvlc_esc_rev; |
124 | |
|
125 | 0 | if (ics->length_of_rvlc_sf > 0) |
126 | 0 | { |
127 | | /* We read length_of_rvlc_sf bits here to put it in a |
128 | | seperate bitfile. |
129 | | */ |
130 | 0 | rvlc_sf_buffer = faad_getbitbuffer(ld, ics->length_of_rvlc_sf |
131 | 0 | DEBUGVAR(1,156,"rvlc_decode_scale_factors(): bitbuffer: length_of_rvlc_sf")); |
132 | |
|
133 | 0 | faad_initbits(&ld_rvlc_sf, (void*)rvlc_sf_buffer, bit2byte(ics->length_of_rvlc_sf)); |
134 | | // faad_initbits_rev(&ld_rvlc_sf_rev, (void*)rvlc_sf_buffer, |
135 | | // ics->length_of_rvlc_sf); |
136 | 0 | } |
137 | 0 | if ((ics->length_of_rvlc_sf == 0) || (ld_rvlc_sf.error != 0)) { |
138 | 0 | memset(&ld_rvlc_sf, 0, sizeof(ld_rvlc_sf)); |
139 | 0 | ld_rvlc_sf.error = 1; |
140 | 0 | } |
141 | |
|
142 | 0 | if (ics->sf_escapes_present) |
143 | 0 | { |
144 | | /* We read length_of_rvlc_escapes bits here to put it in a |
145 | | seperate bitfile. |
146 | | */ |
147 | 0 | rvlc_esc_buffer = faad_getbitbuffer(ld, ics->length_of_rvlc_escapes |
148 | 0 | DEBUGVAR(1,157,"rvlc_decode_scale_factors(): bitbuffer: length_of_rvlc_escapes")); |
149 | |
|
150 | 0 | faad_initbits(&ld_rvlc_esc, (void*)rvlc_esc_buffer, bit2byte(ics->length_of_rvlc_escapes)); |
151 | | // faad_initbits_rev(&ld_rvlc_esc_rev, (void*)rvlc_esc_buffer, |
152 | | // ics->length_of_rvlc_escapes); |
153 | 0 | } |
154 | 0 | if (!ics->sf_escapes_present || (ld_rvlc_esc.error != 0)) { |
155 | 0 | memset(&ld_rvlc_esc, 0, sizeof(ld_rvlc_esc)); |
156 | 0 | ld_rvlc_esc.error = 1; |
157 | 0 | } |
158 | | |
159 | | /* decode the rvlc scale factors and escapes */ |
160 | 0 | result = rvlc_decode_sf_forward(ics, &ld_rvlc_sf, |
161 | 0 | &ld_rvlc_esc, &intensity_used); |
162 | | // result = rvlc_decode_sf_reverse(ics, &ld_rvlc_sf_rev, |
163 | | // &ld_rvlc_esc_rev, intensity_used); |
164 | | |
165 | |
|
166 | 0 | if (rvlc_esc_buffer) faad_free(rvlc_esc_buffer); |
167 | 0 | if (rvlc_sf_buffer) faad_free(rvlc_sf_buffer); |
168 | |
|
169 | 0 | if (ics->length_of_rvlc_sf > 0) |
170 | 0 | faad_endbits(&ld_rvlc_sf); |
171 | 0 | if (ics->sf_escapes_present) |
172 | 0 | faad_endbits(&ld_rvlc_esc); |
173 | |
|
174 | 0 | return result; |
175 | 0 | } |
176 | | |
177 | | static uint8_t rvlc_decode_sf_forward(ic_stream *ics, bitfile *ld_sf, bitfile *ld_esc, |
178 | | uint8_t *intensity_used) |
179 | 0 | { |
180 | 0 | int8_t g, sfb; |
181 | 0 | int8_t t = 0; |
182 | 0 | int8_t error = ld_sf->error | ld_esc->error; |
183 | 0 | int8_t noise_pcm_flag = 1; |
184 | |
|
185 | 0 | int16_t scale_factor = ics->global_gain; |
186 | 0 | int16_t is_position = 0; |
187 | 0 | int16_t noise_energy = ics->global_gain - 90 - 256; |
188 | 0 | int16_t scale_factor_max = 255; |
189 | | #ifdef FIXED_POINT |
190 | | /* TODO: consider rolling out to regular build. */ |
191 | | #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION |
192 | | /* The value is inexact, adjusted to current fuzzer findings. */ |
193 | | scale_factor_max = 165; |
194 | | #endif // FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION |
195 | | #endif // FIXED_POINT |
196 | |
|
197 | | #ifdef PRINT_RVLC |
198 | | printf("\nglobal_gain: %d\n", ics->global_gain); |
199 | | #endif |
200 | |
|
201 | 0 | for (g = 0; g < ics->num_window_groups; g++) |
202 | 0 | { |
203 | 0 | for (sfb = 0; sfb < ics->max_sfb; sfb++) |
204 | 0 | { |
205 | 0 | if (error) |
206 | 0 | { |
207 | 0 | ics->scale_factors[g][sfb] = 0; |
208 | 0 | } else { |
209 | 0 | switch (ics->sfb_cb[g][sfb]) |
210 | 0 | { |
211 | 0 | case ZERO_HCB: /* zero book */ |
212 | 0 | ics->scale_factors[g][sfb] = 0; |
213 | 0 | break; |
214 | 0 | case INTENSITY_HCB: /* intensity books */ |
215 | 0 | case INTENSITY_HCB2: |
216 | |
|
217 | 0 | *intensity_used = 1; |
218 | | |
219 | | /* decode intensity position */ |
220 | 0 | t = rvlc_huffman_sf(ld_sf, ld_esc /*, +1*/); |
221 | |
|
222 | 0 | is_position += t; |
223 | 0 | ics->scale_factors[g][sfb] = is_position; |
224 | |
|
225 | 0 | break; |
226 | 0 | case NOISE_HCB: /* noise books */ |
227 | | |
228 | | /* decode noise energy */ |
229 | 0 | if (noise_pcm_flag) |
230 | 0 | { |
231 | 0 | int16_t n = ics->dpcm_noise_nrg; |
232 | 0 | noise_pcm_flag = 0; |
233 | 0 | noise_energy += n; |
234 | 0 | } else { |
235 | 0 | t = rvlc_huffman_sf(ld_sf, ld_esc /*, +1*/); |
236 | 0 | noise_energy += t; |
237 | 0 | } |
238 | |
|
239 | 0 | ics->scale_factors[g][sfb] = noise_energy; |
240 | |
|
241 | 0 | break; |
242 | 0 | default: /* spectral books */ |
243 | | |
244 | | /* decode scale factor */ |
245 | 0 | t = rvlc_huffman_sf(ld_sf, ld_esc /*, +1*/); |
246 | |
|
247 | 0 | scale_factor += t; |
248 | 0 | if (scale_factor < 0 || scale_factor > 255) |
249 | 0 | return 4; |
250 | | |
251 | 0 | ics->scale_factors[g][sfb] = min(scale_factor, scale_factor_max); |
252 | |
|
253 | 0 | break; |
254 | 0 | } |
255 | | #ifdef PRINT_RVLC |
256 | | printf("%3d:%4d%4d\n", sfb, ics->sfb_cb[g][sfb], |
257 | | ics->scale_factors[g][sfb]); |
258 | | #endif |
259 | 0 | if (t == 99) |
260 | 0 | { |
261 | 0 | error = 1; |
262 | 0 | } |
263 | 0 | } |
264 | 0 | } |
265 | 0 | } |
266 | | #ifdef PRINT_RVLC |
267 | | printf("\n\n"); |
268 | | #endif |
269 | | |
270 | 0 | return 0; |
271 | 0 | } |
272 | | |
273 | | #if 0 // not used right now, doesn't work correctly yet |
274 | | static uint8_t rvlc_decode_sf_reverse(ic_stream *ics, bitfile *ld_sf, bitfile *ld_esc, |
275 | | uint8_t intensity_used) |
276 | | { |
277 | | int8_t g, sfb; |
278 | | int8_t t = 0; |
279 | | int8_t error = 0; |
280 | | int8_t noise_pcm_flag = 1, is_pcm_flag = 1, sf_pcm_flag = 1; |
281 | | |
282 | | int16_t scale_factor = ics->rev_global_gain; |
283 | | int16_t is_position = 0; |
284 | | int16_t noise_energy = ics->rev_global_gain; |
285 | | |
286 | | #ifdef PRINT_RVLC |
287 | | printf("\nrev_global_gain: %d\n", ics->rev_global_gain); |
288 | | #endif |
289 | | |
290 | | if (intensity_used) |
291 | | { |
292 | | is_position = rvlc_huffman_sf(ld_sf, ld_esc, -1); |
293 | | #ifdef PRINT_RVLC |
294 | | printf("is_position: %d\n", is_position); |
295 | | #endif |
296 | | } |
297 | | |
298 | | for (g = ics->num_window_groups-1; g >= 0; g--) |
299 | | { |
300 | | for (sfb = ics->max_sfb-1; sfb >= 0; sfb--) |
301 | | { |
302 | | if (error) |
303 | | { |
304 | | ics->scale_factors[g][sfb] = 0; |
305 | | } else { |
306 | | switch (ics->sfb_cb[g][sfb]) |
307 | | { |
308 | | case ZERO_HCB: /* zero book */ |
309 | | ics->scale_factors[g][sfb] = 0; |
310 | | break; |
311 | | case INTENSITY_HCB: /* intensity books */ |
312 | | case INTENSITY_HCB2: |
313 | | |
314 | | if (is_pcm_flag) |
315 | | { |
316 | | is_pcm_flag = 0; |
317 | | ics->scale_factors[g][sfb] = is_position; |
318 | | } else { |
319 | | t = rvlc_huffman_sf(ld_sf, ld_esc, -1); |
320 | | is_position -= t; |
321 | | |
322 | | ics->scale_factors[g][sfb] = (uint8_t)is_position; |
323 | | } |
324 | | break; |
325 | | case NOISE_HCB: /* noise books */ |
326 | | |
327 | | /* decode noise energy */ |
328 | | if (noise_pcm_flag) |
329 | | { |
330 | | noise_pcm_flag = 0; |
331 | | noise_energy = ics->dpcm_noise_last_position; |
332 | | } else { |
333 | | t = rvlc_huffman_sf(ld_sf, ld_esc, -1); |
334 | | noise_energy -= t; |
335 | | } |
336 | | |
337 | | ics->scale_factors[g][sfb] = (uint8_t)noise_energy; |
338 | | break; |
339 | | default: /* spectral books */ |
340 | | |
341 | | if (sf_pcm_flag || (sfb == 0)) |
342 | | { |
343 | | sf_pcm_flag = 0; |
344 | | if (sfb == 0) |
345 | | scale_factor = ics->global_gain; |
346 | | } else { |
347 | | /* decode scale factor */ |
348 | | t = rvlc_huffman_sf(ld_sf, ld_esc, -1); |
349 | | scale_factor -= t; |
350 | | } |
351 | | |
352 | | if (scale_factor < 0) |
353 | | return 4; |
354 | | |
355 | | ics->scale_factors[g][sfb] = (uint8_t)scale_factor; |
356 | | break; |
357 | | } |
358 | | #ifdef PRINT_RVLC |
359 | | printf("%3d:%4d%4d\n", sfb, ics->sfb_cb[g][sfb], |
360 | | ics->scale_factors[g][sfb]); |
361 | | #endif |
362 | | if (t == 99) |
363 | | { |
364 | | error = 1; |
365 | | } |
366 | | } |
367 | | } |
368 | | } |
369 | | |
370 | | #ifdef PRINT_RVLC |
371 | | printf("\n\n"); |
372 | | #endif |
373 | | |
374 | | return 0; |
375 | | } |
376 | | #endif |
377 | | |
378 | | /* index == 99 means not allowed codeword */ |
379 | | static rvlc_huff_table book_rvlc[] = { |
380 | | /*index length codeword */ |
381 | | { 0, 1, 0 }, /* 0 */ |
382 | | { -1, 3, 5 }, /* 101 */ |
383 | | { 1, 3, 7 }, /* 111 */ |
384 | | { -2, 4, 9 }, /* 1001 */ |
385 | | { -3, 5, 17 }, /* 10001 */ |
386 | | { 2, 5, 27 }, /* 11011 */ |
387 | | { -4, 6, 33 }, /* 100001 */ |
388 | | { 99, 6, 50 }, /* 110010 */ |
389 | | { 3, 6, 51 }, /* 110011 */ |
390 | | { 99, 6, 52 }, /* 110100 */ |
391 | | { -7, 7, 65 }, /* 1000001 */ |
392 | | { 99, 7, 96 }, /* 1100000 */ |
393 | | { 99, 7, 98 }, /* 1100010 */ |
394 | | { 7, 7, 99 }, /* 1100011 */ |
395 | | { 4, 7, 107 }, /* 1101011 */ |
396 | | { -5, 8, 129 }, /* 10000001 */ |
397 | | { 99, 8, 194 }, /* 11000010 */ |
398 | | { 5, 8, 195 }, /* 11000011 */ |
399 | | { 99, 8, 212 }, /* 11010100 */ |
400 | | { 99, 9, 256 }, /* 100000000 */ |
401 | | { -6, 9, 257 }, /* 100000001 */ |
402 | | { 99, 9, 426 }, /* 110101010 */ |
403 | | { 6, 9, 427 }, /* 110101011 */ |
404 | | { 99, 10, 0 } /* Shouldn't come this far */ |
405 | | }; |
406 | | |
407 | | static rvlc_huff_table book_escape[] = { |
408 | | /*index length codeword */ |
409 | | { 1, 2, 0 }, |
410 | | { 0, 2, 2 }, |
411 | | { 3, 3, 2 }, |
412 | | { 2, 3, 6 }, |
413 | | { 4, 4, 14 }, |
414 | | { 7, 5, 13 }, |
415 | | { 6, 5, 15 }, |
416 | | { 5, 5, 31 }, |
417 | | { 11, 6, 24 }, |
418 | | { 10, 6, 25 }, |
419 | | { 9, 6, 29 }, |
420 | | { 8, 6, 61 }, |
421 | | { 13, 7, 56 }, |
422 | | { 12, 7, 120 }, |
423 | | { 15, 8, 114 }, |
424 | | { 14, 8, 242 }, |
425 | | { 17, 9, 230 }, |
426 | | { 16, 9, 486 }, |
427 | | { 19, 10, 463 }, |
428 | | { 18, 10, 974 }, |
429 | | { 22, 11, 925 }, |
430 | | { 20, 11, 1950 }, |
431 | | { 21, 11, 1951 }, |
432 | | { 23, 12, 1848 }, |
433 | | { 25, 13, 3698 }, |
434 | | { 24, 14, 7399 }, |
435 | | { 26, 15, 14797 }, |
436 | | { 49, 19, 236736 }, |
437 | | { 50, 19, 236737 }, |
438 | | { 51, 19, 236738 }, |
439 | | { 52, 19, 236739 }, |
440 | | { 53, 19, 236740 }, |
441 | | { 27, 20, 473482 }, |
442 | | { 28, 20, 473483 }, |
443 | | { 29, 20, 473484 }, |
444 | | { 30, 20, 473485 }, |
445 | | { 31, 20, 473486 }, |
446 | | { 32, 20, 473487 }, |
447 | | { 33, 20, 473488 }, |
448 | | { 34, 20, 473489 }, |
449 | | { 35, 20, 473490 }, |
450 | | { 36, 20, 473491 }, |
451 | | { 37, 20, 473492 }, |
452 | | { 38, 20, 473493 }, |
453 | | { 39, 20, 473494 }, |
454 | | { 40, 20, 473495 }, |
455 | | { 41, 20, 473496 }, |
456 | | { 42, 20, 473497 }, |
457 | | { 43, 20, 473498 }, |
458 | | { 44, 20, 473499 }, |
459 | | { 45, 20, 473500 }, |
460 | | { 46, 20, 473501 }, |
461 | | { 47, 20, 473502 }, |
462 | | { 48, 20, 473503 }, |
463 | | { 99, 21, 0 } /* Shouldn't come this far */ |
464 | | }; |
465 | | |
466 | | static int8_t rvlc_huffman_sf(bitfile *ld_sf, bitfile *ld_esc /*, |
467 | | int8_t direction*/) |
468 | 0 | { |
469 | 0 | uint16_t i, j; |
470 | 0 | int16_t index; |
471 | 0 | uint32_t cw; |
472 | 0 | rvlc_huff_table *h = book_rvlc; |
473 | 0 | int8_t direction = +1; |
474 | |
|
475 | 0 | i = h->len; |
476 | 0 | if (direction > 0) |
477 | 0 | cw = faad_getbits(ld_sf, i DEBUGVAR(1,0,"")); |
478 | 0 | else |
479 | 0 | cw = 0 /* faad_getbits_rev(ld_sf, i DEBUGVAR(1,0,"")) */; |
480 | |
|
481 | 0 | while ((cw != h->cw) |
482 | 0 | && (i < 10)) |
483 | 0 | { |
484 | 0 | h++; |
485 | 0 | j = h->len-i; |
486 | 0 | i += j; |
487 | 0 | cw <<= j; |
488 | 0 | if (direction > 0) |
489 | 0 | cw |= faad_getbits(ld_sf, j DEBUGVAR(1,0,"")); |
490 | 0 | else |
491 | 0 | cw |= 0 /* faad_getbits_rev(ld_sf, j DEBUGVAR(1,0,"")) */; |
492 | 0 | } |
493 | |
|
494 | 0 | index = h->index; |
495 | |
|
496 | 0 | if (index == +ESC_VAL) |
497 | 0 | { |
498 | 0 | int8_t esc = rvlc_huffman_esc(ld_esc /*, direction*/); |
499 | 0 | if (esc == 99) |
500 | 0 | return 99; |
501 | 0 | index += esc; |
502 | | #ifdef PRINT_RVLC |
503 | | printf("esc: %d - ", esc); |
504 | | #endif |
505 | 0 | } |
506 | 0 | if (index == -ESC_VAL) |
507 | 0 | { |
508 | 0 | int8_t esc = rvlc_huffman_esc(ld_esc /*, direction*/); |
509 | 0 | if (esc == 99) |
510 | 0 | return 99; |
511 | 0 | index -= esc; |
512 | | #ifdef PRINT_RVLC |
513 | | printf("esc: %d - ", esc); |
514 | | #endif |
515 | 0 | } |
516 | | |
517 | 0 | return (int8_t)index; |
518 | 0 | } |
519 | | |
520 | | static int8_t rvlc_huffman_esc(bitfile *ld /*, |
521 | | int8_t direction*/) |
522 | 0 | { |
523 | 0 | uint16_t i, j; |
524 | 0 | uint32_t cw; |
525 | 0 | rvlc_huff_table *h = book_escape; |
526 | 0 | int8_t direction = +1; |
527 | |
|
528 | 0 | i = h->len; |
529 | 0 | if (direction > 0) |
530 | 0 | cw = faad_getbits(ld, i DEBUGVAR(1,0,"")); |
531 | 0 | else |
532 | 0 | cw = 0 /* faad_getbits_rev(ld, i DEBUGVAR(1,0,"")) */; |
533 | |
|
534 | 0 | while ((cw != h->cw) |
535 | 0 | && (i < 21)) |
536 | 0 | { |
537 | 0 | h++; |
538 | 0 | j = h->len-i; |
539 | 0 | i += j; |
540 | 0 | cw <<= j; |
541 | 0 | if (direction > 0) |
542 | 0 | cw |= faad_getbits(ld, j DEBUGVAR(1,0,"")); |
543 | 0 | else |
544 | 0 | cw |= 0 /* faad_getbits_rev(ld, j DEBUGVAR(1,0,"")) */; |
545 | 0 | } |
546 | |
|
547 | 0 | return (int8_t)h->index; |
548 | 0 | } |
549 | | |
550 | | #endif |
551 | | |