[FFmpeg-devel] [PATCH 02/12] Replace some variable-length arrays with av_malloc/free
Mans Rullgard
mans
Wed Jun 23 19:26:40 CEST 2010
---
libavcodec/aacenc.c | 4 +++-
libavcodec/error_resilience.c | 8 +++++---
libavcodec/ratecontrol.c | 7 +++++--
libavcodec/resample2.c | 6 +++++-
4 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index 219a4c1..b40247a 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -488,7 +488,7 @@ static int aac_encode_frame(AVCodecContext *avctx,
int i, j, chans, tag, start_ch;
const uint8_t *chan_map = aac_chan_configs[avctx->channels-1];
int chan_el_counter[4];
- FFPsyWindowInfo windows[avctx->channels];
+ FFPsyWindowInfo *windows = av_malloc(avctx->channels * sizeof(*windows));
if (s->last_frame)
return 0;
@@ -612,6 +612,8 @@ static int aac_encode_frame(AVCodecContext *avctx,
s->lambda = FFMIN(s->lambda, 65536.f);
}
+ av_free(windows);
+
if (!data)
s->last_frame = 1;
memcpy(s->samples, s->samples + 1024 * avctx->channels,
diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c
index dc015b9..f343578 100644
--- a/libavcodec/error_resilience.c
+++ b/libavcodec/error_resilience.c
@@ -357,7 +357,7 @@ static void v_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int st
}
static void guess_mv(MpegEncContext *s){
- uint8_t fixed[s->mb_stride * s->mb_height];
+ uint8_t *fixed = av_malloc(s->mb_stride * s->mb_height);
#define MV_FROZEN 3
#define MV_CHANGED 2
#define MV_UNCHANGED 1
@@ -405,7 +405,7 @@ static void guess_mv(MpegEncContext *s){
decode_mb(s, 0);
}
}
- return;
+ goto end;
}
for(depth=0;; depth++){
@@ -606,7 +606,7 @@ score_sum+= best_score;
}
if(none_left)
- return;
+ goto end;
for(i=0; i<s->mb_num; i++){
int mb_xy= s->mb_index2xy[i];
@@ -615,6 +615,8 @@ score_sum+= best_score;
}
// printf(":"); fflush(stdout);
}
+end:
+ av_free(fixed);
}
static int is_intra_more_likely(MpegEncContext *s){
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index 4261678..6a66f2f 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -537,8 +537,8 @@ static void adaptive_quantization(MpegEncContext *s, double q){
const float border_masking = s->avctx->border_masking;
float bits_sum= 0.0;
float cplx_sum= 0.0;
- float cplx_tab[s->mb_num];
- float bits_tab[s->mb_num];
+ float *cplx_tab = av_malloc(s->mb_num * sizeof(*cplx_tab));
+ float *bits_tab = av_malloc(s->mb_num * sizeof(*bits_tab));
const int qmin= s->avctx->mb_lmin;
const int qmax= s->avctx->mb_lmax;
Picture * const pic= &s->current_picture;
@@ -639,6 +639,9 @@ static void adaptive_quantization(MpegEncContext *s, double q){
//printf("%2d%3d ", intq, ff_sqrt(s->mc_mb_var[i]));
s->lambda_table[mb_xy]= intq;
}
+
+ av_free(cplx_tab);
+ av_free(bits_tab);
}
void ff_get_2pass_fcode(MpegEncContext *s){
diff --git a/libavcodec/resample2.c b/libavcodec/resample2.c
index 45f41a1..53fe793 100644
--- a/libavcodec/resample2.c
+++ b/libavcodec/resample2.c
@@ -97,7 +97,8 @@ static double bessel(double x){
*/
static void build_filter(FELEM *filter, double factor, int tap_count, int phase_count, int scale, int type){
int ph, i;
- double x, y, w, tab[tap_count];
+ double x, y, w;
+ double *tab = av_malloc(tap_count * sizeof(*tab));
const int center= (tap_count-1)/2;
/* if upsampling, only need to interpolate, no filter */
@@ -140,6 +141,9 @@ static void build_filter(FELEM *filter, double factor, int tap_count, int phase_
#endif
}
}
+
+ av_free(tab);
+
#if 0
{
#define LEN 1024
--
1.7.1
More information about the ffmpeg-devel
mailing list