comparison vorbis_dec.c @ 12050:a3fe680377aa libavcodec

vorbisdec: remove variable-length arrays
author mru
date Thu, 01 Jul 2010 23:36:48 +0000
parents 7ca225db75e8
children e2d6add92a73
comparison
equal deleted inserted replaced
12049:e6305257ceb6 12050:a3fe680377aa
100 uint_fast32_t partition_size; 100 uint_fast32_t partition_size;
101 uint_fast8_t classifications; 101 uint_fast8_t classifications;
102 uint_fast8_t classbook; 102 uint_fast8_t classbook;
103 int_fast16_t books[64][8]; 103 int_fast16_t books[64][8];
104 uint_fast8_t maxpass; 104 uint_fast8_t maxpass;
105 uint_fast16_t ptns_to_read;
106 uint_fast8_t *classifs;
105 } vorbis_residue; 107 } vorbis_residue;
106 108
107 typedef struct { 109 typedef struct {
108 uint_fast8_t submaps; 110 uint_fast8_t submaps;
109 uint_fast16_t coupling_steps; 111 uint_fast16_t coupling_steps;
192 194
193 av_freep(&vc->channel_residues); 195 av_freep(&vc->channel_residues);
194 av_freep(&vc->channel_floors); 196 av_freep(&vc->channel_floors);
195 av_freep(&vc->saved); 197 av_freep(&vc->saved);
196 198
199 for (i = 0; i < vc->residue_count; i++)
200 av_free(vc->residues[i].classifs);
197 av_freep(&vc->residues); 201 av_freep(&vc->residues);
198 av_freep(&vc->modes); 202 av_freep(&vc->modes);
199 203
200 ff_mdct_end(&vc->mdct[0]); 204 ff_mdct_end(&vc->mdct[0]);
201 ff_mdct_end(&vc->mdct[1]); 205 ff_mdct_end(&vc->mdct[1]);
234 { 238 {
235 uint_fast16_t cb; 239 uint_fast16_t cb;
236 uint8_t *tmp_vlc_bits; 240 uint8_t *tmp_vlc_bits;
237 uint32_t *tmp_vlc_codes; 241 uint32_t *tmp_vlc_codes;
238 GetBitContext *gb = &vc->gb; 242 GetBitContext *gb = &vc->gb;
243 uint_fast16_t *codebook_multiplicands;
239 244
240 vc->codebook_count = get_bits(gb, 8) + 1; 245 vc->codebook_count = get_bits(gb, 8) + 1;
241 246
242 AV_DEBUG(" Codebooks: %d \n", vc->codebook_count); 247 AV_DEBUG(" Codebooks: %d \n", vc->codebook_count);
243 248
244 vc->codebooks = av_mallocz(vc->codebook_count * sizeof(vorbis_codebook)); 249 vc->codebooks = av_mallocz(vc->codebook_count * sizeof(vorbis_codebook));
245 tmp_vlc_bits = av_mallocz(V_MAX_VLCS * sizeof(uint8_t)); 250 tmp_vlc_bits = av_mallocz(V_MAX_VLCS * sizeof(uint8_t));
246 tmp_vlc_codes = av_mallocz(V_MAX_VLCS * sizeof(uint32_t)); 251 tmp_vlc_codes = av_mallocz(V_MAX_VLCS * sizeof(uint32_t));
252 codebook_multiplicands = av_malloc(V_MAX_VLCS * sizeof(*codebook_multiplicands));
247 253
248 for (cb = 0; cb < vc->codebook_count; ++cb) { 254 for (cb = 0; cb < vc->codebook_count; ++cb) {
249 vorbis_codebook *codebook_setup = &vc->codebooks[cb]; 255 vorbis_codebook *codebook_setup = &vc->codebooks[cb];
250 uint_fast8_t ordered; 256 uint_fast8_t ordered;
251 uint_fast32_t t, used_entries = 0; 257 uint_fast32_t t, used_entries = 0;
334 // If the codebook is used for (inverse) VQ, calculate codevectors. 340 // If the codebook is used for (inverse) VQ, calculate codevectors.
335 341
336 if (codebook_setup->lookup_type == 1) { 342 if (codebook_setup->lookup_type == 1) {
337 uint_fast16_t i, j, k; 343 uint_fast16_t i, j, k;
338 uint_fast16_t codebook_lookup_values = ff_vorbis_nth_root(entries, codebook_setup->dimensions); 344 uint_fast16_t codebook_lookup_values = ff_vorbis_nth_root(entries, codebook_setup->dimensions);
339 uint_fast16_t codebook_multiplicands[codebook_lookup_values];
340 345
341 float codebook_minimum_value = vorbisfloat2float(get_bits_long(gb, 32)); 346 float codebook_minimum_value = vorbisfloat2float(get_bits_long(gb, 32));
342 float codebook_delta_value = vorbisfloat2float(get_bits_long(gb, 32)); 347 float codebook_delta_value = vorbisfloat2float(get_bits_long(gb, 32));
343 uint_fast8_t codebook_value_bits = get_bits(gb, 4)+1; 348 uint_fast8_t codebook_value_bits = get_bits(gb, 4)+1;
344 uint_fast8_t codebook_sequence_p = get_bits1(gb); 349 uint_fast8_t codebook_sequence_p = get_bits1(gb);
418 } 423 }
419 } 424 }
420 425
421 av_free(tmp_vlc_bits); 426 av_free(tmp_vlc_bits);
422 av_free(tmp_vlc_codes); 427 av_free(tmp_vlc_codes);
428 av_free(codebook_multiplicands);
423 return 0; 429 return 0;
424 430
425 // Error: 431 // Error:
426 error: 432 error:
427 av_free(tmp_vlc_bits); 433 av_free(tmp_vlc_bits);
428 av_free(tmp_vlc_codes); 434 av_free(tmp_vlc_codes);
435 av_free(codebook_multiplicands);
429 return -1; 436 return -1;
430 } 437 }
431 438
432 // Process time domain transforms part (unused in Vorbis I) 439 // Process time domain transforms part (unused in Vorbis I)
433 440
652 } 659 }
653 660
654 res_setup->classifications = get_bits(gb, 6) + 1; 661 res_setup->classifications = get_bits(gb, 6) + 1;
655 GET_VALIDATED_INDEX(res_setup->classbook, 8, vc->codebook_count) 662 GET_VALIDATED_INDEX(res_setup->classbook, 8, vc->codebook_count)
656 663
664 res_setup->ptns_to_read =
665 (res_setup->end - res_setup->begin) / res_setup->partition_size;
666 res_setup->classifs = av_malloc(res_setup->ptns_to_read *
667 vc->audio_channels *
668 sizeof(*res_setup->classifs));
669
657 AV_DEBUG(" begin %d end %d part.size %d classif.s %d classbook %d \n", res_setup->begin, res_setup->end, res_setup->partition_size, 670 AV_DEBUG(" begin %d end %d part.size %d classif.s %d classbook %d \n", res_setup->begin, res_setup->end, res_setup->partition_size,
658 res_setup->classifications, res_setup->classbook); 671 res_setup->classifications, res_setup->classbook);
659 672
660 for (j = 0; j < res_setup->classifications; ++j) { 673 for (j = 0; j < res_setup->classifications; ++j) {
661 high_bits = 0; 674 high_bits = 0;
1114 { 1127 {
1115 vorbis_floor1 *vf = &vfu->t1; 1128 vorbis_floor1 *vf = &vfu->t1;
1116 GetBitContext *gb = &vc->gb; 1129 GetBitContext *gb = &vc->gb;
1117 uint_fast16_t range_v[4] = { 256, 128, 86, 64 }; 1130 uint_fast16_t range_v[4] = { 256, 128, 86, 64 };
1118 uint_fast16_t range = range_v[vf->multiplier-1]; 1131 uint_fast16_t range = range_v[vf->multiplier-1];
1119 uint_fast16_t floor1_Y[vf->x_list_dim]; 1132 uint_fast16_t floor1_Y[258];
1120 uint_fast16_t floor1_Y_final[vf->x_list_dim]; 1133 uint_fast16_t floor1_Y_final[258];
1121 int floor1_flag[vf->x_list_dim]; 1134 int floor1_flag[258];
1122 uint_fast8_t class_; 1135 uint_fast8_t class_;
1123 uint_fast8_t cdim; 1136 uint_fast8_t cdim;
1124 uint_fast8_t cbits; 1137 uint_fast8_t cbits;
1125 uint_fast8_t csub; 1138 uint_fast8_t csub;
1126 uint_fast8_t cval; 1139 uint_fast8_t cval;
1250 uint_fast16_t vlen, 1263 uint_fast16_t vlen,
1251 int vr_type) 1264 int vr_type)
1252 { 1265 {
1253 GetBitContext *gb = &vc->gb; 1266 GetBitContext *gb = &vc->gb;
1254 uint_fast8_t c_p_c = vc->codebooks[vr->classbook].dimensions; 1267 uint_fast8_t c_p_c = vc->codebooks[vr->classbook].dimensions;
1255 uint_fast16_t n_to_read = vr->end-vr->begin; 1268 uint_fast16_t ptns_to_read = vr->ptns_to_read;
1256 uint_fast16_t ptns_to_read = n_to_read/vr->partition_size; 1269 uint_fast8_t *classifs = vr->classifs;
1257 uint_fast8_t classifs[ptns_to_read*vc->audio_channels];
1258 uint_fast8_t pass; 1270 uint_fast8_t pass;
1259 uint_fast8_t ch_used; 1271 uint_fast8_t ch_used;
1260 uint_fast8_t i,j,l; 1272 uint_fast8_t i,j,l;
1261 uint_fast16_t k; 1273 uint_fast16_t k;
1262 1274
1448 uint_fast8_t previous_window = vc->previous_window; 1460 uint_fast8_t previous_window = vc->previous_window;
1449 uint_fast8_t mode_number; 1461 uint_fast8_t mode_number;
1450 uint_fast8_t blockflag; 1462 uint_fast8_t blockflag;
1451 uint_fast16_t blocksize; 1463 uint_fast16_t blocksize;
1452 int_fast32_t i,j; 1464 int_fast32_t i,j;
1453 uint_fast8_t no_residue[vc->audio_channels]; 1465 uint_fast8_t no_residue[255];
1454 uint_fast8_t do_not_decode[vc->audio_channels]; 1466 uint_fast8_t do_not_decode[255];
1455 vorbis_mapping *mapping; 1467 vorbis_mapping *mapping;
1456 float *ch_res_ptr = vc->channel_residues; 1468 float *ch_res_ptr = vc->channel_residues;
1457 float *ch_floor_ptr = vc->channel_floors; 1469 float *ch_floor_ptr = vc->channel_floors;
1458 uint_fast8_t res_chan[vc->audio_channels]; 1470 uint_fast8_t res_chan[255];
1459 uint_fast8_t res_num = 0; 1471 uint_fast8_t res_num = 0;
1460 int_fast16_t retlen = 0; 1472 int_fast16_t retlen = 0;
1461 float fadd_bias = vc->add_bias; 1473 float fadd_bias = vc->add_bias;
1462 1474
1463 if (get_bits1(gb)) { 1475 if (get_bits1(gb)) {
1585 { 1597 {
1586 const uint8_t *buf = avpkt->data; 1598 const uint8_t *buf = avpkt->data;
1587 int buf_size = avpkt->size; 1599 int buf_size = avpkt->size;
1588 vorbis_context *vc = avccontext->priv_data ; 1600 vorbis_context *vc = avccontext->priv_data ;
1589 GetBitContext *gb = &(vc->gb); 1601 GetBitContext *gb = &(vc->gb);
1590 const float *channel_ptrs[vc->audio_channels]; 1602 const float *channel_ptrs[255];
1591 int i; 1603 int i;
1592 1604
1593 int_fast16_t len; 1605 int_fast16_t len;
1594 1606
1595 if (!buf_size) 1607 if (!buf_size)