From e8d21fba3f09271cb713f6a8203ef403704ed29c Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 16 Dec 2010 02:32:55 +0000 Subject: [PATCH] Allocate planar_samples using av_mallocz(). Lowers memory usage when encoding less than 6 channels. Originally committed as revision 26024 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/ac3enc.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 4ce6cfd534..2db3cec307 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -120,7 +120,7 @@ typedef struct AC3EncodeContext { int mant1_cnt, mant2_cnt, mant4_cnt; ///< mantissa counts for bap=1,2,4 uint16_t *qmant1_ptr, *qmant2_ptr, *qmant4_ptr; ///< mantissa pointers for bap=1,2,4 - int16_t planar_samples[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE+AC3_FRAME_SIZE]; + int16_t **planar_samples; int16_t windowed_samples[AC3_WINDOW_SIZE]; uint8_t *bap_buffer; uint8_t *bap1_buffer; @@ -1464,9 +1464,12 @@ static int ac3_encode_frame(AVCodecContext *avctx, */ static av_cold int ac3_encode_close(AVCodecContext *avctx) { - int blk; + int blk, ch; AC3EncodeContext *s = avctx->priv_data; + for (ch = 0; ch < s->channels; ch++) + av_freep(&s->planar_samples[ch]); + av_freep(&s->planar_samples); av_freep(&s->bap_buffer); av_freep(&s->bap1_buffer); for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { @@ -1606,9 +1609,16 @@ static av_cold void set_bandwidth(AC3EncodeContext *s, int cutoff) static av_cold int allocate_buffers(AVCodecContext *avctx) { - int blk; + int blk, ch; AC3EncodeContext *s = avctx->priv_data; + FF_ALLOC_OR_GOTO(avctx, s->planar_samples, s->channels * sizeof(*s->planar_samples), + alloc_fail); + for (ch = 0; ch < s->channels; ch++) { + FF_ALLOCZ_OR_GOTO(avctx, s->planar_samples[ch], + (AC3_FRAME_SIZE+AC3_BLOCK_SIZE) * sizeof(**s->planar_samples), + alloc_fail); + } FF_ALLOC_OR_GOTO(avctx, s->bap_buffer, AC3_MAX_BLOCKS * s->channels * AC3_MAX_COEFS * sizeof(*s->bap_buffer), alloc_fail); FF_ALLOC_OR_GOTO(avctx, s->bap1_buffer, AC3_MAX_BLOCKS * s->channels *