Commit b5849f77 authored by Justin Ruggles's avatar Justin Ruggles

ac3enc: merge AC3MDCTContext with AC3EncodeContext.

Since both the fixed-point and floating-point encoders use the FFTContext,
this no longer needs to be in a separate context. Also, when a short-transform
context is added, the same MDCT window will be used.
parent 82cea7cb
...@@ -1836,8 +1836,7 @@ av_cold int ff_ac3_encode_close(AVCodecContext *avctx) ...@@ -1836,8 +1836,7 @@ av_cold int ff_ac3_encode_close(AVCodecContext *avctx)
av_freep(&block->cpl_coord_mant); av_freep(&block->cpl_coord_mant);
} }
s->mdct_end(s->mdct); s->mdct_end(s);
av_freep(&s->mdct);
av_freep(&avctx->coded_frame); av_freep(&avctx->coded_frame);
return 0; return 0;
...@@ -2242,8 +2241,7 @@ av_cold int ff_ac3_encode_init(AVCodecContext *avctx) ...@@ -2242,8 +2241,7 @@ av_cold int ff_ac3_encode_init(AVCodecContext *avctx)
bit_alloc_init(s); bit_alloc_init(s);
FF_ALLOCZ_OR_GOTO(avctx, s->mdct, sizeof(AC3MDCTContext), init_fail); ret = s->mdct_init(s);
ret = s->mdct_init(avctx, s->mdct, 9);
if (ret) if (ret)
goto init_fail; goto init_fail;
......
...@@ -66,11 +66,6 @@ typedef int64_t CoefSumType; ...@@ -66,11 +66,6 @@ typedef int64_t CoefSumType;
#endif #endif
typedef struct AC3MDCTContext {
const SampleType *window; ///< MDCT window function
FFTContext fft; ///< FFT context for MDCT calculation
} AC3MDCTContext;
/** /**
* Encoding Options used by AVOption. * Encoding Options used by AVOption.
*/ */
...@@ -143,7 +138,8 @@ typedef struct AC3EncodeContext { ...@@ -143,7 +138,8 @@ 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 FFTContext mdct; ///< FFT context for MDCT calculation
const SampleType *mdct_window; ///< MDCT window function array
AC3Block blocks[AC3_MAX_BLOCKS]; ///< per-block info AC3Block blocks[AC3_MAX_BLOCKS]; ///< per-block info
...@@ -226,8 +222,8 @@ typedef struct AC3EncodeContext { ...@@ -226,8 +222,8 @@ typedef struct AC3EncodeContext {
int ref_bap_set; ///< indicates if ref_bap pointers have been set int ref_bap_set; ///< indicates if ref_bap pointers have been set
/* fixed vs. float function pointers */ /* fixed vs. float function pointers */
void (*mdct_end)(AC3MDCTContext *mdct); void (*mdct_end)(struct AC3EncodeContext *s);
int (*mdct_init)(AVCodecContext *avctx, AC3MDCTContext *mdct, int nbits); int (*mdct_init)(struct AC3EncodeContext *s);
/* fixed vs. float templated function pointers */ /* fixed vs. float templated function pointers */
int (*allocate_sample_buffers)(struct AC3EncodeContext *s); int (*allocate_sample_buffers)(struct AC3EncodeContext *s);
...@@ -262,13 +258,11 @@ void ff_ac3_output_frame(AC3EncodeContext *s, unsigned char *frame); ...@@ -262,13 +258,11 @@ void ff_ac3_output_frame(AC3EncodeContext *s, unsigned char *frame);
/* prototypes for functions in ac3enc_fixed.c and ac3enc_float.c */ /* prototypes for functions in ac3enc_fixed.c and ac3enc_float.c */
void ff_ac3_fixed_mdct_end(AC3MDCTContext *mdct); void ff_ac3_fixed_mdct_end(AC3EncodeContext *s);
void ff_ac3_float_mdct_end(AC3MDCTContext *mdct); void ff_ac3_float_mdct_end(AC3EncodeContext *s);
int ff_ac3_fixed_mdct_init(AVCodecContext *avctx, AC3MDCTContext *mdct, int ff_ac3_fixed_mdct_init(AC3EncodeContext *s);
int nbits); int ff_ac3_float_mdct_init(AC3EncodeContext *s);
int ff_ac3_float_mdct_init(AVCodecContext *avctx, AC3MDCTContext *mdct,
int nbits);
/* prototypes for functions in ac3enc_template.c */ /* prototypes for functions in ac3enc_template.c */
......
...@@ -41,9 +41,9 @@ static AVClass ac3enc_class = { "Fixed-Point AC-3 Encoder", av_default_item_name ...@@ -41,9 +41,9 @@ static AVClass ac3enc_class = { "Fixed-Point AC-3 Encoder", av_default_item_name
/** /**
* Finalize MDCT and free allocated memory. * Finalize MDCT and free allocated memory.
*/ */
av_cold void AC3_NAME(mdct_end)(AC3MDCTContext *mdct) av_cold void AC3_NAME(mdct_end)(AC3EncodeContext *s)
{ {
ff_mdct_end(&mdct->fft); ff_mdct_end(&s->mdct);
} }
...@@ -51,11 +51,10 @@ av_cold void AC3_NAME(mdct_end)(AC3MDCTContext *mdct) ...@@ -51,11 +51,10 @@ av_cold void AC3_NAME(mdct_end)(AC3MDCTContext *mdct)
* Initialize MDCT tables. * Initialize MDCT tables.
* @param nbits log2(MDCT size) * @param nbits log2(MDCT size)
*/ */
av_cold int AC3_NAME(mdct_init)(AVCodecContext *avctx, AC3MDCTContext *mdct, av_cold int AC3_NAME(mdct_init)(AC3EncodeContext *s)
int nbits)
{ {
int ret = ff_mdct_init(&mdct->fft, nbits, 0, -1.0); int ret = ff_mdct_init(&s->mdct, 9, 0, -1.0);
mdct->window = ff_ac3_window; s->mdct_window = ff_ac3_window;
return ret; return ret;
} }
......
...@@ -45,10 +45,10 @@ static AVClass ac3enc_class = { "AC-3 Encoder", av_default_item_name, ...@@ -45,10 +45,10 @@ static AVClass ac3enc_class = { "AC-3 Encoder", av_default_item_name,
/** /**
* Finalize MDCT and free allocated memory. * Finalize MDCT and free allocated memory.
*/ */
av_cold void ff_ac3_float_mdct_end(AC3MDCTContext *mdct) av_cold void ff_ac3_float_mdct_end(AC3EncodeContext *s)
{ {
ff_mdct_end(&mdct->fft); ff_mdct_end(&s->mdct);
av_freep(&mdct->window); av_freep(&s->mdct_window);
} }
...@@ -56,26 +56,25 @@ av_cold void ff_ac3_float_mdct_end(AC3MDCTContext *mdct) ...@@ -56,26 +56,25 @@ av_cold void ff_ac3_float_mdct_end(AC3MDCTContext *mdct)
* Initialize MDCT tables. * Initialize MDCT tables.
* @param nbits log2(MDCT size) * @param nbits log2(MDCT size)
*/ */
av_cold int ff_ac3_float_mdct_init(AVCodecContext *avctx, AC3MDCTContext *mdct, av_cold int ff_ac3_float_mdct_init(AC3EncodeContext *s)
int nbits)
{ {
float *window; float *window;
int i, n, n2; int i, n, n2;
n = 1 << nbits; n = 1 << 9;
n2 = n >> 1; n2 = n >> 1;
window = av_malloc(n * sizeof(*window)); window = av_malloc(n * sizeof(*window));
if (!window) { if (!window) {
av_log(avctx, AV_LOG_ERROR, "Cannot allocate memory.\n"); av_log(s->avctx, AV_LOG_ERROR, "Cannot allocate memory.\n");
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
ff_kbd_window_init(window, 5.0, n2); ff_kbd_window_init(window, 5.0, n2);
for (i = 0; i < n2; i++) for (i = 0; i < n2; i++)
window[n-1-i] = window[i]; window[n-1-i] = window[i];
mdct->window = window; s->mdct_window = window;
return ff_mdct_init(&mdct->fft, nbits, 0, -2.0 / n); return ff_mdct_init(&s->mdct, 9, 0, -2.0 / n);
} }
......
...@@ -108,13 +108,13 @@ static void apply_mdct(AC3EncodeContext *s) ...@@ -108,13 +108,13 @@ static void apply_mdct(AC3EncodeContext *s)
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, apply_window(&s->dsp, s->windowed_samples, input_samples,
s->mdct->window, AC3_WINDOW_SIZE); s->mdct_window, AC3_WINDOW_SIZE);
if (s->fixed_point) if (s->fixed_point)
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.mdct_calcw(&s->mdct, block->mdct_coef[ch+1],
s->windowed_samples); s->windowed_samples);
} }
} }
} }
......
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