| FFmpeg
    | 
#include <stdint.h>#include "libavutil/attributes.h"#include "libavutil/avassert.h"#include "libavutil/avstring.h"#include "libavutil/channel_layout.h"#include "libavutil/crc.h"#include "libavutil/internal.h"#include "libavutil/mem_internal.h"#include "libavutil/opt.h"#include "libavutil/thread.h"#include "avcodec.h"#include "encode.h"#include "internal.h"#include "me_cmp.h"#include "put_bits.h"#include "audiodsp.h"#include "ac3dsp.h"#include "ac3.h"#include "fft.h"#include "ac3enc.h"#include "eac3enc.h"Go to the source code of this file.
| Data Structures | |
| struct | AC3Mant | 
| Macros | |
| #define | CMIXLEV_NUM_OPTIONS 3 | 
| #define | SURMIXLEV_NUM_OPTIONS 3 | 
| #define | EXTMIXLEV_NUM_OPTIONS 8 | 
| #define | OFFSET(param) offsetof(AC3EncodeContext, options.param) | 
| #define | AC3ENC_PARAM (AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM) | 
| #define | EXP_DIFF_THRESHOLD 500 | 
| Exponent Difference Threshold.  More... | |
| #define | CRC16_POLY ((1 << 0) | (1 << 2) | (1 << 15) | (1 << 16)) | 
| CRC-16 Polynomial.  More... | |
| #define | FLT_OPTION_THRESHOLD 0.01 | 
| Functions | |
| void | ff_ac3_adjust_frame_size (AC3EncodeContext *s) | 
| Adjust the frame size to make the average bit rate match the target bit rate.  More... | |
| void | ff_ac3_compute_coupling_strategy (AC3EncodeContext *s) | 
| Set the initial coupling strategy parameters prior to coupling analysis.  More... | |
| static void | ac3_apply_rematrixing (AC3EncodeContext *s) | 
| Apply stereo rematrixing to coefficients based on rematrixing flags.  More... | |
| static av_cold void | exponent_init (void) | 
| static void | extract_exponents (AC3EncodeContext *s) | 
| static void | compute_exp_strategy (AC3EncodeContext *s) | 
| static void | encode_exponents_blk_ch (uint8_t *exp, int nb_exps, int exp_strategy, int cpl) | 
| Update the exponents so that they are the ones the decoder will decode.  More... | |
| static void | encode_exponents (AC3EncodeContext *s) | 
| static int | count_exponent_bits (AC3EncodeContext *s) | 
| static void | ac3_group_exponents (AC3EncodeContext *s) | 
| Group exponents.  More... | |
| static void | ac3_process_exponents (AC3EncodeContext *s) | 
| Calculate final exponents from the supplied MDCT coefficients and exponent shift.  More... | |
| static void | count_frame_bits_fixed (AC3EncodeContext *s) | 
| static av_cold void | bit_alloc_init (AC3EncodeContext *s) | 
| static void | count_frame_bits (AC3EncodeContext *s) | 
| static void | bit_alloc_masking (AC3EncodeContext *s) | 
| static void | reset_block_bap (AC3EncodeContext *s) | 
| static void | count_mantissa_bits_init (uint16_t mant_cnt[AC3_MAX_BLOCKS][16]) | 
| Initialize mantissa counts.  More... | |
| static void | count_mantissa_bits_update_ch (AC3EncodeContext *s, int ch, uint16_t mant_cnt[AC3_MAX_BLOCKS][16], int start, int end) | 
| Update mantissa bit counts for all blocks in 1 channel in a given bandwidth range.  More... | |
| static int | count_mantissa_bits (AC3EncodeContext *s) | 
| static int | bit_alloc (AC3EncodeContext *s, int snr_offset) | 
| Run the bit allocation with a given SNR offset.  More... | |
| static int | cbr_bit_allocation (AC3EncodeContext *s) | 
| static int | ac3_compute_bit_allocation (AC3EncodeContext *s) | 
| static int | sym_quant (int c, int e, int levels) | 
| Symmetric quantization on 'levels' levels.  More... | |
| static int | asym_quant (int c, int e, int qbits) | 
| Asymmetric quantization on 2^qbits levels.  More... | |
| static void | quantize_mantissas_blk_ch (AC3Mant *s, int32_t *fixed_coef, uint8_t *exp, uint8_t *bap, int16_t *qmant, int start_freq, int end_freq) | 
| Quantize a set of mantissas for a single channel in a single block.  More... | |
| static void | ac3_quantize_mantissas (AC3EncodeContext *s) | 
| Quantize mantissas using coefficients, exponents, and bit allocation pointers.  More... | |
| static void | ac3_output_frame_header (AC3EncodeContext *s) | 
| static void | output_audio_block (AC3EncodeContext *s, int blk) | 
| static unsigned int | mul_poly (unsigned int a, unsigned int b, unsigned int poly) | 
| static unsigned int | pow_poly (unsigned int a, unsigned int n, unsigned int poly) | 
| static void | output_frame_end (AC3EncodeContext *s) | 
| static void | ac3_output_frame (AC3EncodeContext *s, unsigned char *frame) | 
| Write the frame to the output bitstream.  More... | |
| int | ff_ac3_encode_frame_common_end (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) | 
| static void | dprint_options (AC3EncodeContext *s) | 
| static int | validate_float_option (float v, const float *v_list, int v_list_size) | 
| static void | validate_mix_level (void *log_ctx, const char *opt_name, float *opt_param, const float *list, int list_size, int default_value, int min_value, int *ctx_param) | 
| int | ff_ac3_validate_metadata (AC3EncodeContext *s) | 
| Validate metadata options as set by AVOption system.  More... | |
| av_cold int | ff_ac3_encode_close (AVCodecContext *avctx) | 
| Finalize encoding and free any memory allocated by the encoder.  More... | |
| static av_cold int | set_channel_info (AC3EncodeContext *s, int channels, uint64_t *channel_layout) | 
| static av_cold int | validate_options (AC3EncodeContext *s) | 
| static av_cold void | set_bandwidth (AC3EncodeContext *s) | 
| static av_cold int | allocate_buffers (AC3EncodeContext *s) | 
| av_cold int | ff_ac3_encode_init (AVCodecContext *avctx) | 
| Variables | |
| static const float | cmixlev_options [CMIXLEV_NUM_OPTIONS] | 
| static const float | surmixlev_options [SURMIXLEV_NUM_OPTIONS] | 
| static const float | extmixlev_options [EXTMIXLEV_NUM_OPTIONS] | 
| const AVOption | ff_ac3_enc_options [] | 
| const AVClass | ff_ac3enc_class | 
| const AVCodecDefault | ff_ac3_enc_defaults [] | 
| static uint8_t | exponent_group_tab [2][3][256] | 
| LUT for number of exponent groups.  More... | |
| const uint64_t | ff_ac3_channel_layouts [19] | 
| List of supported channel layouts.  More... | |
| static const uint8_t | ac3_enc_channel_map [8][2][6] | 
| Table to remap channels from SMPTE order to AC-3 order.  More... | |
| static const uint8_t | ac3_bandwidth_tab [5][3][19] | 
| LUT to select the bandwidth code based on the bit rate, sample rate, and number of full-bandwidth channels.  More... | |
| static const int8_t | ac3_coupling_start_tab [6][3][19] | 
| LUT to select the coupling start band based on the bit rate, sample rate, and number of full-bandwidth channels.  More... | |
| static const uint8_t | exp_strategy_reuse_tab [4][6] | 
| Table used to select exponent strategy based on exponent reuse block interval.  More... | |
The simplest AC-3 encoder.
Definition in file ac3enc.c.
| #define OFFSET | ( | param | ) | offsetof(AC3EncodeContext, options.param) | 
| #define AC3ENC_PARAM (AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM) | 
| #define EXP_DIFF_THRESHOLD 500 | 
| #define CRC16_POLY ((1 << 0) | (1 << 2) | (1 << 15) | (1 << 16)) | 
| void ff_ac3_adjust_frame_size | ( | AC3EncodeContext * | s | ) | 
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.
| s | AC-3 encoder private context | 
Definition at line 261 of file ac3enc.c.
Referenced by encode_frame().
| void ff_ac3_compute_coupling_strategy | ( | AC3EncodeContext * | s | ) | 
Set the initial coupling strategy parameters prior to coupling analysis.
| s | AC-3 encoder private context | 
Definition at line 279 of file ac3enc.c.
Referenced by encode_frame().
| 
 | static | 
Apply stereo rematrixing to coefficients based on rematrixing flags.
| s | AC-3 encoder private context | 
Definition at line 350 of file ac3enc.c.
Referenced by ff_ac3_encode_frame_common_end().
| 
 | static | 
Definition at line 384 of file ac3enc.c.
Referenced by ff_ac3_encode_init().
| 
 | static | 
Definition at line 403 of file ac3enc.c.
Referenced by ac3_process_exponents().
| 
 | static | 
Definition at line 433 of file ac3enc.c.
Referenced by ac3_process_exponents().
| 
 | static | 
Update the exponents so that they are the ones the decoder will decode.
| [in,out] | exp | array of exponents for 1 block in 1 channel | 
| nb_exps | number of exponents in active bandwidth | |
| exp_strategy | exponent strategy for the block | |
| cpl | indicates if the block is in the coupling channel | 
Definition at line 499 of file ac3enc.c.
Referenced by encode_exponents().
| 
 | static | 
Definition at line 572 of file ac3enc.c.
Referenced by ac3_process_exponents().
| 
 | static | 
Definition at line 622 of file ac3enc.c.
Referenced by ac3_compute_bit_allocation().
| 
 | static | 
Group exponents.
3 delta-encoded exponents are in each 7-bit group. The number of groups varies depending on exponent strategy and bandwidth.
| s | AC-3 encoder private context | 
Definition at line 654 of file ac3enc.c.
Referenced by ff_ac3_encode_frame_common_end().
| 
 | static | 
Calculate final exponents from the supplied MDCT coefficients and exponent shift.
Extract exponents from MDCT coefficients, calculate exponent strategies, and encode final exponents.
| s | AC-3 encoder private context | 
Definition at line 712 of file ac3enc.c.
Referenced by ff_ac3_encode_frame_common_end().
| 
 | static | 
Definition at line 728 of file ac3enc.c.
Referenced by bit_alloc_init().
| 
 | static | 
Definition at line 837 of file ac3enc.c.
Referenced by ff_ac3_encode_init().
| 
 | static | 
Definition at line 873 of file ac3enc.c.
Referenced by ac3_compute_bit_allocation().
| 
 | static | 
Definition at line 1016 of file ac3enc.c.
Referenced by ac3_compute_bit_allocation().
| 
 | static | 
Definition at line 1046 of file ac3enc.c.
Referenced by bit_alloc(), and cbr_bit_allocation().
| 
 | static | 
Initialize mantissa counts.
These are set so that they are padded to the next whole group size when bits are counted in compute_mantissa_size.
| [in,out] | mant_cnt | running counts for each bap value for each block | 
Definition at line 1071 of file ac3enc.c.
Referenced by count_mantissa_bits().
| 
 | static | 
Update mantissa bit counts for all blocks in 1 channel in a given bandwidth range.
| s | AC-3 encoder private context | |
| ch | channel index | |
| [in,out] | mant_cnt | running counts for each bap value for each block | 
| start | starting coefficient bin | |
| end | ending coefficient bin | 
Definition at line 1093 of file ac3enc.c.
Referenced by count_mantissa_bits().
| 
 | static | 
Definition at line 1113 of file ac3enc.c.
Referenced by bit_alloc().
| 
 | static | 
Run the bit allocation with a given SNR offset.
This calculates the bit allocation pointers that will be used to determine the quantization of each mantissa.
| s | AC-3 encoder private context | 
| snr_offset | SNR offset, 0 to 1023 | 
Definition at line 1139 of file ac3enc.c.
Referenced by cbr_bit_allocation(), compute_bit_allocation(), encode_frame(), mp_decode_layer2(), and MPA_encode_frame().
| 
 | static | 
Definition at line 1170 of file ac3enc.c.
Referenced by ac3_compute_bit_allocation().
| 
 | static | 
Definition at line 1221 of file ac3enc.c.
Referenced by ff_ac3_encode_frame_common_end().
Symmetric quantization on 'levels' levels.
| c | unquantized coefficient | 
| e | exponent | 
| levels | number of quantization levels | 
Definition at line 1241 of file ac3enc.c.
Referenced by quantize_mantissas_blk_ch().
Asymmetric quantization on 2^qbits levels.
| c | unquantized coefficient | 
| e | exponent | 
| qbits | number of quantization bits | 
Definition at line 1257 of file ac3enc.c.
Referenced by quantize_mantissas_blk_ch().
| 
 | static | 
Quantize a set of mantissas for a single channel in a single block.
| s | Mantissa count context | |
| fixed_coef | unquantized fixed-point coefficients | |
| exp | exponents | |
| bap | bit allocation pointer indices | |
| [out] | qmant | quantized coefficients | 
| start_freq | starting coefficient bin | |
| end_freq | ending coefficient bin | 
Definition at line 1281 of file ac3enc.c.
Referenced by ac3_quantize_mantissas().
| 
 | static | 
Quantize mantissas using coefficients, exponents, and bit allocation pointers.
| s | AC-3 encoder private context | 
Definition at line 1376 of file ac3enc.c.
Referenced by ff_ac3_encode_frame_common_end().
| 
 | static | 
Definition at line 1405 of file ac3enc.c.
Referenced by ff_ac3_encode_init().
| 
 | static | 
Definition at line 1461 of file ac3enc.c.
Referenced by ac3_output_frame().
Definition at line 1654 of file ac3enc.c.
Referenced by output_frame_end(), and pow_poly().
Definition at line 1671 of file ac3enc.c.
Referenced by ff_ac3_encode_init().
| 
 | static | 
Definition at line 1688 of file ac3enc.c.
Referenced by ac3_output_frame().
| 
 | static | 
Write the frame to the output bitstream.
| s | AC-3 encoder private context | 
| frame | output data buffer | 
Definition at line 1737 of file ac3enc.c.
Referenced by ff_ac3_encode_frame_common_end().
| int ff_ac3_encode_frame_common_end | ( | AVCodecContext * | avctx, | 
| AVPacket * | avpkt, | ||
| const AVFrame * | frame, | ||
| int * | got_packet_ptr | ||
| ) | 
Definition at line 1751 of file ac3enc.c.
Referenced by encode_frame().
| 
 | static | 
Definition at line 1783 of file ac3enc.c.
Referenced by ff_ac3_encode_init().
Definition at line 1900 of file ac3enc.c.
Referenced by validate_mix_level().
| 
 | static | 
Definition at line 1916 of file ac3enc.c.
Referenced by ff_ac3_validate_metadata().
| int ff_ac3_validate_metadata | ( | AC3EncodeContext * | s | ) | 
Validate metadata options as set by AVOption system.
These values can optionally be changed per-frame.
| s | AC-3 encoder private context | 
Definition at line 1940 of file ac3enc.c.
Referenced by encode_frame(), and validate_options().
| av_cold int ff_ac3_encode_close | ( | AVCodecContext * | avctx | ) | 
| 
 | static | 
Definition at line 2170 of file ac3enc.c.
Referenced by validate_options().
| 
 | static | 
Definition at line 2215 of file ac3enc.c.
Referenced by ff_ac3_encode_init().
| 
 | static | 
Definition at line 2360 of file ac3enc.c.
Referenced by ff_ac3_encode_init().
| 
 | static | 
Definition at line 2430 of file ac3enc.c.
Referenced by ff_ac3_encode_init().
| av_cold int ff_ac3_encode_init | ( | AVCodecContext * | avctx | ) | 
Definition at line 2516 of file ac3enc.c.
Referenced by ac3_fixed_encode_init(), and ff_ac3_float_encode_init().
| 
 | static | 
Definition at line 58 of file ac3enc.c.
Referenced by ff_ac3_validate_metadata().
| 
 | static | 
Definition at line 63 of file ac3enc.c.
Referenced by ff_ac3_validate_metadata().
| 
 | static | 
Definition at line 68 of file ac3enc.c.
Referenced by ff_ac3_validate_metadata().
| const AVClass ff_ac3enc_class | 
| const AVCodecDefault ff_ac3_enc_defaults[] | 
| 
 | static | 
LUT for number of exponent groups.
exponent_group_tab[coupling][exponent strategy-1][number of coefficients]
Definition at line 144 of file ac3enc.c.
Referenced by ac3_group_exponents(), count_exponent_bits(), encode_exponents_blk_ch(), exponent_init(), and output_audio_block().
| const uint64_t ff_ac3_channel_layouts[19] | 
List of supported channel layouts.
| 
 | static | 
Table to remap channels from SMPTE order to AC-3 order.
[channel_mode][lfe][ch]
Definition at line 176 of file ac3enc.c.
Referenced by set_channel_info().
| 
 | static | 
LUT to select the bandwidth code based on the bit rate, sample rate, and number of full-bandwidth channels.
bandwidth_tab[fbw_channels-1][sample rate code][bit rate code]
Definition at line 187 of file ac3enc.c.
Referenced by set_bandwidth().
| 
 | static | 
LUT to select the coupling start band based on the bit rate, sample rate, and number of full-bandwidth channels.
-1 = coupling off ac3_coupling_start_tab[channel_mode-2][sample rate code][bit rate code]
TODO: more testing for optimal parameters. multi-channel tests at 44.1kHz and 32kHz.
Definition at line 220 of file ac3enc.c.
Referenced by set_bandwidth().
| 
 | static | 
Table used to select exponent strategy based on exponent reuse block interval.
Definition at line 422 of file ac3enc.c.
Referenced by compute_exp_strategy().
 1.8.17
 1.8.17