diff options
author | Benjamin Larsson <banan@ludd.ltu.se> | 2009-02-02 18:51:02 +0000 |
---|---|---|
committer | Benjamin Larsson <banan@ludd.ltu.se> | 2009-02-02 18:51:02 +0000 |
commit | aa8d024ce2169574a7b21e2a9ac6b2da7ecd2f32 (patch) | |
tree | ac24e452e14d374f5d438be22600e4147152b485 /libavcodec/nellymoserenc.c | |
parent | 426a6f34a0f8a1132af80fdbf912d577d20524dd (diff) | |
download | ffmpeg-aa8d024ce2169574a7b21e2a9ac6b2da7ecd2f32.tar.gz |
Allocate trellis tables on heap only when needed.
Originally committed as revision 16945 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/nellymoserenc.c')
-rw-r--r-- | libavcodec/nellymoserenc.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/libavcodec/nellymoserenc.c b/libavcodec/nellymoserenc.c index d3caf9188b..9167313ef2 100644 --- a/libavcodec/nellymoserenc.c +++ b/libavcodec/nellymoserenc.c @@ -44,6 +44,7 @@ #define POW_TABLE_SIZE (1<<11) #define POW_TABLE_OFFSET 3 +#define OPT_SIZE ((1<<15) + 3000) typedef struct NellyMoserEncodeContext { AVCodecContext *avctx; @@ -54,6 +55,8 @@ typedef struct NellyMoserEncodeContext { MDCTContext mdct_ctx; DECLARE_ALIGNED_16(float, mdct_out[NELLY_SAMPLES]); DECLARE_ALIGNED_16(float, buf[2][3 * NELLY_BUF_LEN]); ///< sample buffer + float (*opt )[NELLY_BANDS]; + uint8_t (*path)[NELLY_BANDS]; } NellyMoserEncodeContext; static float pow_table[POW_TABLE_SIZE]; ///< -pow(2, -i / 2048.0 - 3.0); @@ -149,6 +152,11 @@ static av_cold int encode_init(AVCodecContext *avctx) for (i = 0; i < POW_TABLE_SIZE; i++) pow_table[i] = -pow(2, -i / 2048.0 - 3.0 + POW_TABLE_OFFSET); + if (s->avctx->trellis) { + s->opt = av_malloc(NELLY_BANDS * OPT_SIZE * sizeof(float )); + s->path = av_malloc(NELLY_BANDS * OPT_SIZE * sizeof(uint8_t)); + } + return 0; } @@ -157,6 +165,12 @@ static av_cold int encode_end(AVCodecContext *avctx) NellyMoserEncodeContext *s = avctx->priv_data; ff_mdct_end(&s->mdct_ctx); + + if (s->avctx->trellis) { + av_free(s->opt); + av_free(s->path); + } + return 0; } @@ -184,8 +198,6 @@ static void get_exponent_greedy(NellyMoserEncodeContext *s, float *cand, int *id } } -#define OPT_SIZE ((1<<15) + 3000) - static inline float distance(float x, float y, int band) { //return pow(fabs(x-y), 2.0); @@ -198,8 +210,8 @@ static void get_exponent_dynamic(NellyMoserEncodeContext *s, float *cand, int *i int i, j, band, best_idx; float power_candidate, best_val; - float opt[NELLY_BANDS][OPT_SIZE]; - int path[NELLY_BANDS][OPT_SIZE]; + float (*opt )[NELLY_BANDS] = s->opt ; + uint8_t(*path)[NELLY_BANDS] = s->path; for (i = 0; i < NELLY_BANDS * OPT_SIZE; i++) { opt[0][i] = INFINITY; |