Commit e754dfc0 authored by Justin Ruggles's avatar Justin Ruggles

ac3enc: dynamically allocate AC3EncodeContext fields windowed_samples and mdct

This will allow the same struct to be used for both the fixed and float ac3
encoders.
parent 36151b3e
...@@ -273,12 +273,12 @@ static void apply_mdct(AC3EncodeContext *s) ...@@ -273,12 +273,12 @@ static void apply_mdct(AC3EncodeContext *s)
AC3Block *block = &s->blocks[blk]; AC3Block *block = &s->blocks[blk];
const SampleType *input_samples = &s->planar_samples[ch][blk * AC3_BLOCK_SIZE]; const SampleType *input_samples = &s->planar_samples[ch][blk * AC3_BLOCK_SIZE];
apply_window(&s->dsp, s->windowed_samples, input_samples, s->mdct.window, AC3_WINDOW_SIZE); apply_window(&s->dsp, s->windowed_samples, input_samples, s->mdct->window, AC3_WINDOW_SIZE);
block->coeff_shift[ch+1] = normalize_samples(s); block->coeff_shift[ch+1] = normalize_samples(s);
s->mdct.fft.mdct_calcw(&s->mdct.fft, block->mdct_coef[ch+1], s->mdct->fft.mdct_calcw(&s->mdct->fft, block->mdct_coef[ch+1],
s->windowed_samples); s->windowed_samples);
} }
} }
} }
...@@ -2318,6 +2318,7 @@ static av_cold int ac3_encode_close(AVCodecContext *avctx) ...@@ -2318,6 +2318,7 @@ static av_cold int ac3_encode_close(AVCodecContext *avctx)
int blk, ch; int blk, ch;
AC3EncodeContext *s = avctx->priv_data; AC3EncodeContext *s = avctx->priv_data;
av_freep(&s->windowed_samples);
for (ch = 0; ch < s->channels; ch++) for (ch = 0; ch < s->channels; ch++)
av_freep(&s->planar_samples[ch]); av_freep(&s->planar_samples[ch]);
av_freep(&s->planar_samples); av_freep(&s->planar_samples);
...@@ -2343,7 +2344,8 @@ static av_cold int ac3_encode_close(AVCodecContext *avctx) ...@@ -2343,7 +2344,8 @@ static av_cold int ac3_encode_close(AVCodecContext *avctx)
av_freep(&block->qmant); av_freep(&block->qmant);
} }
mdct_end(&s->mdct); mdct_end(s->mdct);
av_freep(&s->mdct);
av_freep(&avctx->coded_frame); av_freep(&avctx->coded_frame);
return 0; return 0;
...@@ -2598,6 +2600,8 @@ static av_cold int allocate_buffers(AVCodecContext *avctx) ...@@ -2598,6 +2600,8 @@ static av_cold int allocate_buffers(AVCodecContext *avctx)
AC3EncodeContext *s = avctx->priv_data; AC3EncodeContext *s = avctx->priv_data;
int channels = s->channels + 1; /* includes coupling channel */ int channels = s->channels + 1; /* includes coupling channel */
FF_ALLOC_OR_GOTO(avctx, s->windowed_samples, AC3_WINDOW_SIZE *
sizeof(*s->windowed_samples), alloc_fail);
FF_ALLOC_OR_GOTO(avctx, s->planar_samples, s->channels * sizeof(*s->planar_samples), FF_ALLOC_OR_GOTO(avctx, s->planar_samples, s->channels * sizeof(*s->planar_samples),
alloc_fail); alloc_fail);
for (ch = 0; ch < s->channels; ch++) { for (ch = 0; ch < s->channels; ch++) {
...@@ -2741,7 +2745,8 @@ static av_cold int ac3_encode_init(AVCodecContext *avctx) ...@@ -2741,7 +2745,8 @@ static av_cold int ac3_encode_init(AVCodecContext *avctx)
bit_alloc_init(s); bit_alloc_init(s);
ret = mdct_init(avctx, &s->mdct, 9); FF_ALLOCZ_OR_GOTO(avctx, s->mdct, sizeof(AC3MDCTContext), init_fail);
ret = mdct_init(avctx, s->mdct, 9);
if (ret) if (ret)
goto init_fail; goto init_fail;
......
...@@ -128,7 +128,7 @@ typedef struct AC3EncodeContext { ...@@ -128,7 +128,7 @@ typedef struct AC3EncodeContext {
PutBitContext pb; ///< bitstream writer context PutBitContext pb; ///< bitstream writer context
DSPContext dsp; DSPContext dsp;
AC3DSPContext ac3dsp; ///< AC-3 optimized functions AC3DSPContext ac3dsp; ///< AC-3 optimized functions
AC3MDCTContext mdct; ///< MDCT context AC3MDCTContext *mdct; ///< MDCT context
AC3Block blocks[AC3_MAX_BLOCKS]; ///< per-block info AC3Block blocks[AC3_MAX_BLOCKS]; ///< per-block info
...@@ -189,6 +189,7 @@ typedef struct AC3EncodeContext { ...@@ -189,6 +189,7 @@ typedef struct AC3EncodeContext {
int frame_bits; ///< all frame bits except exponents and mantissas int frame_bits; ///< all frame bits except exponents and mantissas
int exponent_bits; ///< number of bits used for exponents int exponent_bits; ///< number of bits used for exponents
SampleType *windowed_samples;
SampleType **planar_samples; SampleType **planar_samples;
uint8_t *bap_buffer; uint8_t *bap_buffer;
uint8_t *bap1_buffer; uint8_t *bap1_buffer;
...@@ -208,8 +209,6 @@ typedef struct AC3EncodeContext { ...@@ -208,8 +209,6 @@ typedef struct AC3EncodeContext {
uint8_t *ref_bap [AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< bit allocation pointers (bap) uint8_t *ref_bap [AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< bit allocation pointers (bap)
int ref_bap_set; ///< indicates if ref_bap pointers have been set int ref_bap_set; ///< indicates if ref_bap pointers have been set
DECLARE_ALIGNED(32, SampleType, windowed_samples)[AC3_WINDOW_SIZE];
void (*output_frame_header)(struct AC3EncodeContext *s); void (*output_frame_header)(struct AC3EncodeContext *s);
} AC3EncodeContext; } AC3EncodeContext;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment