Mercurial > libavcodec.hg
comparison mpegaudiodec.c @ 404:29dc52c127c6 libavcodec
fixed one overflow problem
author | glantau |
---|---|
date | Mon, 20 May 2002 21:15:53 +0000 |
parents | 4ef26ed29399 |
children | c3aebacf546e |
comparison
equal
deleted
inserted
replaced
403:2c3e25f4c496 | 404:29dc52c127c6 |
---|---|
1 /* | 1 /* |
2 * MPEG Audio decoder | 2 * MPEG Audio decoder |
3 * Copyright (c) 2001 Gerard Lantau. | 3 * Copyright (c) 2001, 2002 Gerard Lantau. |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 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 | 7 * the Free Software Foundation; either version 2 of the License, or |
8 * (at your option) any later version. | 8 * (at your option) any later version. |
125 static VLC huff_quad_vlc[2]; | 125 static VLC huff_quad_vlc[2]; |
126 /* computed from band_size_long */ | 126 /* computed from band_size_long */ |
127 static UINT16 band_index_long[9][23]; | 127 static UINT16 band_index_long[9][23]; |
128 /* XXX: free when all decoders are closed */ | 128 /* XXX: free when all decoders are closed */ |
129 #define TABLE_4_3_SIZE (8191 + 16) | 129 #define TABLE_4_3_SIZE (8191 + 16) |
130 static UINT8 *table_4_3_exp; | 130 static INT8 *table_4_3_exp; |
131 #if FRAC_BITS <= 15 | 131 #if FRAC_BITS <= 15 |
132 static UINT16 *table_4_3_value; | 132 static UINT16 *table_4_3_value; |
133 #else | 133 #else |
134 static UINT32 *table_4_3_value; | 134 static UINT32 *table_4_3_value; |
135 #endif | 135 #endif |
1953 } | 1953 } |
1954 buf += 18; | 1954 buf += 18; |
1955 } | 1955 } |
1956 } | 1956 } |
1957 | 1957 |
1958 #ifdef DEBUG | 1958 #if defined(DEBUG) |
1959 void sample_dump(int fnum, INT32 *tab, int n) | 1959 void sample_dump(int fnum, INT32 *tab, int n) |
1960 { | 1960 { |
1961 static FILE *files[16], *f; | 1961 static FILE *files[16], *f; |
1962 char buf[512]; | 1962 char buf[512]; |
1963 | 1963 |
2166 } | 2166 } |
2167 } | 2167 } |
2168 } | 2168 } |
2169 g->scale_factors[j++] = 0; | 2169 g->scale_factors[j++] = 0; |
2170 } | 2170 } |
2171 #ifdef DEBUG | 2171 #if defined(DEBUG) |
2172 { | 2172 { |
2173 printf("scfsi=%x gr=%d ch=%d scale_factors:\n", | 2173 printf("scfsi=%x gr=%d ch=%d scale_factors:\n", |
2174 g->scfsi, gr, ch); | 2174 g->scfsi, gr, ch); |
2175 for(i=0;i<j;i++) | 2175 for(i=0;i<j;i++) |
2176 printf(" %d", g->scale_factors[i]); | 2176 printf(" %d", g->scale_factors[i]); |
2223 g->scale_factors[j++] = get_bitsz(&s->gb, sl); | 2223 g->scale_factors[j++] = get_bitsz(&s->gb, sl); |
2224 } | 2224 } |
2225 /* XXX: should compute exact size */ | 2225 /* XXX: should compute exact size */ |
2226 for(;j<40;j++) | 2226 for(;j<40;j++) |
2227 g->scale_factors[j] = 0; | 2227 g->scale_factors[j] = 0; |
2228 #ifdef DEBUG | 2228 #if defined(DEBUG) |
2229 { | 2229 { |
2230 printf("gr=%d ch=%d scale_factors:\n", | 2230 printf("gr=%d ch=%d scale_factors:\n", |
2231 gr, ch); | 2231 gr, ch); |
2232 for(i=0;i<40;i++) | 2232 for(i=0;i<40;i++) |
2233 printf(" %d", g->scale_factors[i]); | 2233 printf(" %d", g->scale_factors[i]); |
2240 | 2240 |
2241 /* read Huffman coded residue */ | 2241 /* read Huffman coded residue */ |
2242 if (huffman_decode(s, g, exponents, | 2242 if (huffman_decode(s, g, exponents, |
2243 bits_pos + g->part2_3_length) < 0) | 2243 bits_pos + g->part2_3_length) < 0) |
2244 return -1; | 2244 return -1; |
2245 #if defined(DEBUG) && 0 | 2245 #if defined(DEBUG) |
2246 sample_dump(3, g->sb_hybrid, 576); | 2246 sample_dump(0, g->sb_hybrid, 576); |
2247 #endif | 2247 #endif |
2248 | 2248 |
2249 /* skip extension bits */ | 2249 /* skip extension bits */ |
2250 bits_left = g->part2_3_length - (get_bits_count(&s->gb) - bits_pos); | 2250 bits_left = g->part2_3_length - (get_bits_count(&s->gb) - bits_pos); |
2251 if (bits_left < 0) { | 2251 if (bits_left < 0) { |
2265 | 2265 |
2266 for(ch=0;ch<s->nb_channels;ch++) { | 2266 for(ch=0;ch<s->nb_channels;ch++) { |
2267 g = &granules[ch][gr]; | 2267 g = &granules[ch][gr]; |
2268 | 2268 |
2269 reorder_block(s, g); | 2269 reorder_block(s, g); |
2270 #ifdef DEBUG | 2270 #if defined(DEBUG) |
2271 sample_dump(0, g->sb_hybrid, 576); | 2271 sample_dump(0, g->sb_hybrid, 576); |
2272 #endif | 2272 #endif |
2273 compute_antialias(s, g); | 2273 compute_antialias(s, g); |
2274 #ifdef DEBUG | 2274 #ifdef DEBUG |
2275 sample_dump(1, g->sb_hybrid, 576); | 2275 sample_dump(1, g->sb_hybrid, 576); |