[FFmpeg-devel] [PATCH] aacenc: replace VLA with malloced buffer in context

Mans Rullgard mans
Sun Jul 4 02:59:54 CEST 2010


---
 libavcodec/aacenc.c |    6 +++++-
 libavcodec/aacenc.h |    1 +
 2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index 1aaaf3a..78eb7d2 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -202,6 +202,9 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
     ff_psy_init(&s->psy, avctx, 2, sizes, lengths);
     s->psypp = ff_psy_preprocess_init(avctx);
     s->coder = &ff_aac_coders[2];
+    s->psywindows = av_malloc(avctx->channels * sizeof(*s->psywindows));
+    if (!s->psywindows)
+        return AVERROR(ENOMEM);
 
     s->lambda = avctx->global_quality ? avctx->global_quality : 120;
 
@@ -486,7 +489,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 = s->psywindows;
 
     if (s->last_frame)
         return 0;
@@ -625,6 +628,7 @@ static av_cold int aac_encode_end(AVCodecContext *avctx)
     ff_mdct_end(&s->mdct128);
     ff_psy_end(&s->psy);
     ff_psy_preprocess_end(s->psypp);
+    av_freep(&s->psywindows);
     av_freep(&s->samples);
     av_freep(&s->cpe);
     return 0;
diff --git a/libavcodec/aacenc.h b/libavcodec/aacenc.h
index 86c68d3..1f730c0 100644
--- a/libavcodec/aacenc.h
+++ b/libavcodec/aacenc.h
@@ -60,6 +60,7 @@ typedef struct AACEncContext {
     ChannelElement *cpe;                         ///< channel elements
     FFPsyContext psy;
     struct FFPsyPreprocessContext* psypp;
+    FFPsyWindowInfo *psywindows;
     AACCoefficientsEncoder *coder;
     int cur_channel;
     int last_frame;
-- 
1.7.1.1




More information about the ffmpeg-devel mailing list