[SCM] libav/experimental: Allocate planar_samples using av_mallocz(). Lowers memory usage when encoding less than 6 channels.

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Jun 30 17:20:28 UTC 2013


The following commit has been merged in the experimental branch:
commit e8d21fba3f09271cb713f6a8203ef403704ed29c
Author: Justin Ruggles <justin.ruggles at gmail.com>
Date:   Thu Dec 16 02:32:55 2010 +0000

    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

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 4ce6cfd..2db3cec 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 *

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list