[FFmpeg-devel] [PATCH 01/12] vorbisdec: remove variable-length arrays
Mans Rullgard
mans
Wed Jun 23 19:26:39 CEST 2010
---
libavcodec/vorbis_dec.c | 43 ++++++++++++++++++++++++++++++++-----------
1 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/libavcodec/vorbis_dec.c b/libavcodec/vorbis_dec.c
index 8c56400..d49022c 100644
--- a/libavcodec/vorbis_dec.c
+++ b/libavcodec/vorbis_dec.c
@@ -103,6 +103,8 @@ typedef struct {
uint_fast8_t classbook;
int_fast16_t books[64][8];
uint_fast8_t maxpass;
+ uint_fast16_t ptns_to_read;
+ uint_fast8_t *classifs;
} vorbis_residue;
typedef struct {
@@ -154,6 +156,9 @@ typedef struct vorbis_context_s {
float *saved;
uint_fast32_t add_bias; // for float->int conversion
uint_fast32_t exp_bias;
+ uint_fast8_t *no_residue;
+ uint_fast8_t *do_not_decode;
+ uint_fast8_t *res_chan;
} vorbis_context;
/* Helper functions */
@@ -194,7 +199,12 @@ static void vorbis_free(vorbis_context *vc)
av_freep(&vc->channel_residues);
av_freep(&vc->channel_floors);
av_freep(&vc->saved);
+ av_freep(&vc->no_residue);
+ av_freep(&vc->do_not_decode);
+ av_freep(&vc->res_chan);
+ for (i = 0; i < vc->residue_count; i++)
+ av_free(vc->residues[i].classifs);
av_freep(&vc->residues);
av_freep(&vc->modes);
@@ -237,6 +247,7 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
uint8_t *tmp_vlc_bits;
uint32_t *tmp_vlc_codes;
GetBitContext *gb = &vc->gb;
+ uint_fast16_t *codebook_multiplicands;
vc->codebook_count = get_bits(gb, 8) + 1;
@@ -245,6 +256,7 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
vc->codebooks = av_mallocz(vc->codebook_count * sizeof(vorbis_codebook));
tmp_vlc_bits = av_mallocz(V_MAX_VLCS * sizeof(uint8_t));
tmp_vlc_codes = av_mallocz(V_MAX_VLCS * sizeof(uint32_t));
+ codebook_multiplicands = av_malloc(V_MAX_VLCS * sizeof(*codebook_multiplicands));
for (cb = 0; cb < vc->codebook_count; ++cb) {
vorbis_codebook *codebook_setup = &vc->codebooks[cb];
@@ -337,7 +349,6 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
if (codebook_setup->lookup_type == 1) {
uint_fast16_t i, j, k;
uint_fast16_t codebook_lookup_values = ff_vorbis_nth_root(entries, codebook_setup->dimensions);
- uint_fast16_t codebook_multiplicands[codebook_lookup_values];
float codebook_minimum_value = vorbisfloat2float(get_bits_long(gb, 32));
float codebook_delta_value = vorbisfloat2float(get_bits_long(gb, 32));
@@ -421,12 +432,14 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
av_free(tmp_vlc_bits);
av_free(tmp_vlc_codes);
+ av_free(codebook_multiplicands);
return 0;
// Error:
error:
av_free(tmp_vlc_bits);
av_free(tmp_vlc_codes);
+ av_free(codebook_multiplicands);
return -1;
}
@@ -657,6 +670,12 @@ static int vorbis_parse_setup_hdr_residues(vorbis_context *vc)
res_setup->classifications = get_bits(gb, 6) + 1;
GET_VALIDATED_INDEX(res_setup->classbook, 8, vc->codebook_count)
+ res_setup->ptns_to_read =
+ (res_setup->end - res_setup->begin) / res_setup->partition_size;
+ res_setup->classifs = av_malloc(res_setup->ptns_to_read *
+ vc->audio_channels *
+ sizeof(*res_setup->classifs));
+
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,
res_setup->classifications, res_setup->classbook);
@@ -909,6 +928,9 @@ static int vorbis_parse_id_hdr(vorbis_context *vc)
vc->channel_residues = av_malloc((vc->blocksize[1] / 2) * vc->audio_channels * sizeof(float));
vc->channel_floors = av_malloc((vc->blocksize[1] / 2) * vc->audio_channels * sizeof(float));
vc->saved = av_mallocz((vc->blocksize[1] / 4) * vc->audio_channels * sizeof(float));
+ vc->no_residue = av_malloc(vc->audio_channels*sizeof(*vc->no_residue));
+ vc->do_not_decode = av_malloc(vc->audio_channels*sizeof(*vc->do_not_decode));
+ vc->res_chan = av_malloc(vc->audio_channels*sizeof(*vc->res_chan));
vc->previous_window = 0;
ff_mdct_init(&vc->mdct[0], bl0, 1, vc->exp_bias ? -(1 << 15) : -1.0);
@@ -1119,9 +1141,9 @@ static uint_fast8_t vorbis_floor1_decode(vorbis_context *vc,
GetBitContext *gb = &vc->gb;
uint_fast16_t range_v[4] = { 256, 128, 86, 64 };
uint_fast16_t range = range_v[vf->multiplier-1];
- uint_fast16_t floor1_Y[vf->x_list_dim];
- uint_fast16_t floor1_Y_final[vf->x_list_dim];
- int floor1_flag[vf->x_list_dim];
+ uint_fast16_t floor1_Y[258];
+ uint_fast16_t floor1_Y_final[258];
+ int floor1_flag[258];
uint_fast8_t class_;
uint_fast8_t cdim;
uint_fast8_t cbits;
@@ -1255,9 +1277,8 @@ static av_always_inline int vorbis_residue_decode_internal(vorbis_context *vc,
{
GetBitContext *gb = &vc->gb;
uint_fast8_t c_p_c = vc->codebooks[vr->classbook].dimensions;
- uint_fast16_t n_to_read = vr->end-vr->begin;
- uint_fast16_t ptns_to_read = n_to_read/vr->partition_size;
- uint_fast8_t classifs[ptns_to_read*vc->audio_channels];
+ uint_fast16_t ptns_to_read = vr->ptns_to_read;
+ uint_fast8_t *classifs = vr->classifs;
uint_fast8_t pass;
uint_fast8_t ch_used;
uint_fast8_t i,j,l;
@@ -1453,12 +1474,12 @@ static int vorbis_parse_audio_packet(vorbis_context *vc)
uint_fast8_t blockflag;
uint_fast16_t blocksize;
int_fast32_t i,j;
- uint_fast8_t no_residue[vc->audio_channels];
- uint_fast8_t do_not_decode[vc->audio_channels];
+ uint_fast8_t *no_residue = vc->no_residue;
+ uint_fast8_t *do_not_decode = vc->do_not_decode;
vorbis_mapping *mapping;
float *ch_res_ptr = vc->channel_residues;
float *ch_floor_ptr = vc->channel_floors;
- uint_fast8_t res_chan[vc->audio_channels];
+ uint_fast8_t *res_chan = vc->res_chan;
uint_fast8_t res_num = 0;
int_fast16_t retlen = 0;
float fadd_bias = vc->add_bias;
@@ -1590,7 +1611,7 @@ static int vorbis_decode_frame(AVCodecContext *avccontext,
int buf_size = avpkt->size;
vorbis_context *vc = avccontext->priv_data ;
GetBitContext *gb = &(vc->gb);
- const float *channel_ptrs[vc->audio_channels];
+ const float *channel_ptrs[255];
int i;
int_fast16_t len;
--
1.7.1
More information about the ffmpeg-devel
mailing list