[FFmpeg-devel] [PATCH 5/6] vorbisdec: remove variable-length arrays
Mans Rullgard
mans
Wed Aug 19 03:23:01 CEST 2009
---
libavcodec/vorbis_dec.c | 42 +++++++++++++++++++++++++++++++-----------
1 files changed, 31 insertions(+), 11 deletions(-)
diff --git a/libavcodec/vorbis_dec.c b/libavcodec/vorbis_dec.c
index bb582c2..4edb234 100644
--- a/libavcodec/vorbis_dec.c
+++ b/libavcodec/vorbis_dec.c
@@ -104,6 +104,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 {
@@ -155,6 +157,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 */
@@ -178,7 +183,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);
@@ -220,6 +230,7 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc) {
uint_fast16_t cb;
uint8_t *tmp_vlc_bits;
uint32_t *tmp_vlc_codes;
+ uint_fast16_t *codebook_multiplicands;
GetBitContext *gb=&vc->gb;
vc->codebook_count=get_bits(gb,8)+1;
@@ -229,6 +240,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];
@@ -322,7 +334,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));
@@ -406,12 +417,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;
}
@@ -631,6 +644,11 @@ static int vorbis_parse_setup_hdr_residues(vorbis_context *vc){
res_setup->partition_size=get_bits(gb, 24)+1;
res_setup->classifications=get_bits(gb, 6)+1;
res_setup->classbook=get_bits(gb, 8);
+ 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);
@@ -879,6 +897,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);
@@ -1084,9 +1105,9 @@ static uint_fast8_t vorbis_floor1_decode(vorbis_context *vc, vorbis_floor_data *
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;
@@ -1213,9 +1234,8 @@ static uint_fast8_t vorbis_floor1_decode(vorbis_context *vc, vorbis_floor_data *
static av_always_inline int vorbis_residue_decode_internal(vorbis_context *vc, vorbis_residue *vr, uint_fast8_t ch, uint_fast8_t *do_not_decode, float *vec, uint_fast16_t vlen, int vr_type) {
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;
@@ -1412,12 +1432,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;
@@ -1550,7 +1570,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.6.4
More information about the ffmpeg-devel
mailing list