From 8683c6a638f2e323d11b520c5e130b46b1eb1eda Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 26 Jun 2011 23:58:19 -0400 Subject: ac3enc: move ff_ac3_encode_frame() to ac3enc_template.c This avoids using function pointers for quite a few small functions, most of which just call DSP functions. --- libavcodec/ac3enc.c | 82 ++++++----------------------------------------------- 1 file changed, 9 insertions(+), 73 deletions(-) (limited to 'libavcodec/ac3enc.c') diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 3fbbbd0991..44dfce80e2 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -177,7 +177,7 @@ static const int8_t ac3_coupling_start_tab[6][3][19] = { * Adjust the frame size to make the average bit rate match the target bit rate. * This is only needed for 11025, 22050, and 44100 sample rates or any E-AC-3. */ -static void adjust_frame_size(AC3EncodeContext *s) +void ff_ac3_adjust_frame_size(AC3EncodeContext *s) { while (s->bits_written >= s->bit_rate && s->samples_written >= s->sample_rate) { s->bits_written -= s->bit_rate; @@ -190,7 +190,7 @@ static void adjust_frame_size(AC3EncodeContext *s) } -static void compute_coupling_strategy(AC3EncodeContext *s) +void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s) { int blk, ch; int got_cpl_snr; @@ -254,7 +254,7 @@ static void compute_coupling_strategy(AC3EncodeContext *s) /** * Apply stereo rematrixing to coefficients based on rematrixing flags. */ -static void apply_rematrixing(AC3EncodeContext *s) +void ff_ac3_apply_rematrixing(AC3EncodeContext *s) { int nb_coefs; int blk, bnd, i; @@ -570,7 +570,7 @@ static void group_exponents(AC3EncodeContext *s) * Extract exponents from MDCT coefficients, calculate exponent strategies, * and encode final exponents. */ -static void process_exponents(AC3EncodeContext *s) +void ff_ac3_process_exponents(AC3EncodeContext *s) { extract_exponents(s); @@ -1028,7 +1028,7 @@ static int cbr_bit_allocation(AC3EncodeContext *s) * frame size. Output is the SNR offset and a set of bit allocation pointers * used to quantize the mantissas. */ -static int compute_bit_allocation(AC3EncodeContext *s) +int ff_ac3_compute_bit_allocation(AC3EncodeContext *s) { count_frame_bits(s); @@ -1163,7 +1163,7 @@ static void quantize_mantissas_blk_ch(AC3Mant *s, int32_t *fixed_coef, /** * Quantize mantissas using coefficients, exponents, and bit allocation pointers. */ -static void quantize_mantissas(AC3EncodeContext *s) +void ff_ac3_quantize_mantissas(AC3EncodeContext *s) { int blk, ch, ch0=0, got_cpl; @@ -1522,7 +1522,7 @@ static void output_frame_end(AC3EncodeContext *s) /** * Write the frame to the output bitstream. */ -static void output_frame(AC3EncodeContext *s, unsigned char *frame) +void ff_ac3_output_frame(AC3EncodeContext *s, unsigned char *frame) { int blk; @@ -1691,7 +1691,7 @@ static void validate_mix_level(void *log_ctx, const char *opt_name, * Validate metadata options as set by AVOption system. * These values can optionally be changed per-frame. */ -static int validate_metadata(AVCodecContext *avctx) +int ff_ac3_validate_metadata(AVCodecContext *avctx) { AC3EncodeContext *s = avctx->priv_data; AC3EncOptions *opt = &s->options; @@ -1800,57 +1800,6 @@ static int validate_metadata(AVCodecContext *avctx) } -/** - * Encode a single AC-3 frame. - */ -int ff_ac3_encode_frame(AVCodecContext *avctx, unsigned char *frame, - int buf_size, void *data) -{ - AC3EncodeContext *s = avctx->priv_data; - const SampleType *samples = data; - int ret; - - if (!s->eac3 && s->options.allow_per_frame_metadata) { - ret = validate_metadata(avctx); - if (ret) - return ret; - } - - if (s->bit_alloc.sr_code == 1 || s->eac3) - adjust_frame_size(s); - - s->deinterleave_input_samples(s, samples); - - s->apply_mdct(s); - - s->scale_coefficients(s); - - s->cpl_on = s->cpl_enabled; - compute_coupling_strategy(s); - - if (s->cpl_on) - s->apply_channel_coupling(s); - - s->compute_rematrixing_strategy(s); - - apply_rematrixing(s); - - process_exponents(s); - - ret = compute_bit_allocation(s); - if (ret) { - av_log(avctx, AV_LOG_ERROR, "Bit allocation failed. Try increasing the bitrate.\n"); - return ret; - } - - quantize_mantissas(s); - - output_frame(s, frame); - - return s->frame_size; -} - - /** * Finalize encoding and free any memory allocated by the encoder. */ @@ -2047,7 +1996,7 @@ static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s) } if (!s->eac3) { - ret = validate_metadata(avctx); + ret = ff_ac3_validate_metadata(avctx); if (ret) return ret; } @@ -2273,24 +2222,11 @@ av_cold int ff_ac3_encode_init(AVCodecContext *avctx) if (CONFIG_AC3_FIXED_ENCODER && s->fixed_point) { s->mdct_end = ff_ac3_fixed_mdct_end; s->mdct_init = ff_ac3_fixed_mdct_init; - s->apply_window = ff_ac3_fixed_apply_window; - s->normalize_samples = ff_ac3_fixed_normalize_samples; - s->scale_coefficients = ff_ac3_fixed_scale_coefficients; s->allocate_sample_buffers = ff_ac3_fixed_allocate_sample_buffers; - s->deinterleave_input_samples = ff_ac3_fixed_deinterleave_input_samples; - s->apply_mdct = ff_ac3_fixed_apply_mdct; - s->apply_channel_coupling = ff_ac3_fixed_apply_channel_coupling; - s->compute_rematrixing_strategy = ff_ac3_fixed_compute_rematrixing_strategy; } else if (CONFIG_AC3_ENCODER || CONFIG_EAC3_ENCODER) { s->mdct_end = ff_ac3_float_mdct_end; s->mdct_init = ff_ac3_float_mdct_init; - s->apply_window = ff_ac3_float_apply_window; - s->scale_coefficients = ff_ac3_float_scale_coefficients; s->allocate_sample_buffers = ff_ac3_float_allocate_sample_buffers; - s->deinterleave_input_samples = ff_ac3_float_deinterleave_input_samples; - s->apply_mdct = ff_ac3_float_apply_mdct; - s->apply_channel_coupling = ff_ac3_float_apply_channel_coupling; - s->compute_rematrixing_strategy = ff_ac3_float_compute_rematrixing_strategy; } if (CONFIG_EAC3_ENCODER && s->eac3) s->output_frame_header = ff_eac3_output_frame_header; -- cgit v1.2.3