54 #define CMIXLEV_NUM_OPTIONS 3
59 #define SURMIXLEV_NUM_OPTIONS 3
64 #define EXTMIXLEV_NUM_OPTIONS 8
112 { { 0, 0, 0, 12, 16, 32, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48 },
113 { 0, 0, 0, 16, 20, 36, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56 },
114 { 0, 0, 0, 32, 40, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60 } },
116 { { 0, 0, 0, 0, 0, 0, 0, 20, 24, 32, 48, 48, 48, 48, 48, 48, 48, 48, 48 },
117 { 0, 0, 0, 0, 0, 0, 4, 24, 28, 36, 56, 56, 56, 56, 56, 56, 56, 56, 56 },
118 { 0, 0, 0, 0, 0, 0, 20, 44, 52, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60 } },
120 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 24, 32, 40, 48, 48, 48, 48, 48, 48 },
121 { 0, 0, 0, 0, 0, 0, 0, 0, 4, 20, 28, 36, 44, 56, 56, 56, 56, 56, 56 },
122 { 0, 0, 0, 0, 0, 0, 0, 0, 20, 40, 48, 60, 60, 60, 60, 60, 60, 60, 60 } },
124 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 24, 32, 48, 48, 48, 48, 48, 48 },
125 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 28, 36, 56, 56, 56, 56, 56, 56 },
126 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 48, 60, 60, 60, 60, 60, 60, 60 } },
128 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 20, 32, 40, 48, 48, 48, 48 },
129 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 24, 36, 44, 56, 56, 56, 56 },
130 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 44, 60, 60, 60, 60, 60, 60 } }
146 { { 0, 0, 0, 0, 0, 0, 0, 1, 1, 7, 8, 11, 12, -1, -1, -1, -1, -1, -1 },
147 { 0, 0, 0, 0, 0, 0, 1, 3, 5, 7, 10, 12, 13, -1, -1, -1, -1, -1, -1 },
148 { 0, 0, 0, 0, 1, 2, 2, 9, 13, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
151 { { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 6, 9, 11, 12, 13, -1, -1, -1, -1 },
152 { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 6, 9, 11, 12, 13, -1, -1, -1, -1 },
153 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
156 { { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 6, 9, 11, 12, 13, -1, -1, -1, -1 },
157 { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 6, 9, 11, 12, 13, -1, -1, -1, -1 },
158 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
161 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 10, 11, 11, 12, 12, 14, -1 },
162 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 10, 11, 11, 12, 12, 14, -1 },
163 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
166 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 10, 11, 11, 12, 12, 14, -1 },
167 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 10, 11, 11, 12, 12, 14, -1 },
168 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
171 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 8, 11, 12, 12, -1, -1 },
172 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 8, 11, 12, 12, -1, -1 },
173 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
243 if (!blk || (block->
cpl_in_use && !got_cpl_snr)) {
291 for (i = start; i <
end; i++) {
308 int expstr, i, grpsize;
311 grpsize = 3 << expstr;
312 for (i = 12; i < 256; i++) {
320 if (CONFIG_EAC3_ENCODER && s->
eac3)
342 #define EXP_DIFF_THRESHOLD 500
362 for (ch = !s->
cpl_on; ch <= s->fbw_channels; ch++) {
395 while (blk < s->num_blocks) {
397 while (blk1 < s->num_blocks && exp_strategy[blk1] ==
EXP_REUSE)
411 if (CONFIG_EAC3_ENCODER && s->
eac3)
432 switch(exp_strategy) {
434 for (i = 1, k = 1-cpl; i <= nb_groups; i++) {
436 if (exp[k+1] < exp_min)
438 exp[i-cpl] = exp_min;
443 for (i = 1, k = 1-cpl; i <= nb_groups; i++) {
445 if (exp[k+1] < exp_min)
447 if (exp[k+2] < exp_min)
449 if (exp[k+3] < exp_min)
451 exp[i-cpl] = exp_min;
458 if (!cpl && exp[0] > 15)
463 for (i = 1; i <= nb_groups; i++)
464 exp[i] =
FFMIN(exp[i], exp[i-1] + 2);
467 exp[i] =
FFMIN(exp[i], exp[i+1] + 2);
470 exp[-1] = exp[0] & ~1;
473 switch (exp_strategy) {
475 for (i = nb_groups, k = (nb_groups * 2)-cpl; i > 0; i--) {
482 for (i = nb_groups, k = (nb_groups * 4)-cpl; i > 0; i--) {
483 exp[k] = exp[k-1] = exp[k-2] = exp[k-3] = exp[i-cpl];
499 int blk, blk1,
ch, cpl;
501 int nb_coefs, num_reuse_blocks;
503 for (ch = !s->
cpl_on; ch <= s->channels; ch++) {
509 while (blk < s->num_blocks) {
522 while (blk1 < s->num_blocks && exp_strategy[blk1] ==
EXP_REUSE) {
526 num_reuse_blocks = blk1 - blk - 1;
550 int nb_groups, bit_count;
555 for (ch = !block->
cpl_in_use; ch <= s->channels; ch++) {
564 bit_count += 4 + (nb_groups * 7);
582 int group_size, nb_groups;
584 int delta0, delta1, delta2;
589 for (ch = !block->
cpl_in_use; ch <= s->channels; ch++) {
594 group_size = exp_strategy + (exp_strategy ==
EXP_D45);
603 for (i = 1; i <= nb_groups; i++) {
608 delta0 = exp1 - exp0 + 2;
614 delta1 = exp1 - exp0 + 2;
620 delta2 = exp1 - exp0 + 2;
623 block->
grouped_exp[
ch][i] = ((delta0 * 5 + delta1) * 5) + delta2;
655 static const int frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 };
729 frame_bits += 2 + 2 + 2 + 2 + 3;
749 frame_bits += 1 + 16;
769 for (ch = 0; ch <= s->
channels; ch++)
811 frame_bits += 1 + 1 + 2;
817 frame_bits += 3 + 1 + 1;
824 frame_bits += 5 + 2 + 1;
840 frame_bits += 5 * s->
cpl_on;
898 if (!s->
eac3 || blk > 0)
947 for (ch = !block->
cpl_in_use; ch <= s->channels; ch++) {
980 for (ch = 0; ch <= s->
channels; ch++) {
1001 memset(mant_cnt[blk], 0,
sizeof(mant_cnt[blk]));
1002 mant_cnt[
blk][1] = mant_cnt[
blk][2] = 2;
1003 mant_cnt[
blk][4] = 1;
1040 int ch, max_end_freq;
1046 for (ch = !s->
cpl_enabled; ch <= s->channels; ch++)
1068 snr_offset = (snr_offset - 240) << 2;
1074 for (ch = !block->
cpl_in_use; ch <= s->channels; ch++) {
1099 int snr_offset, snr_incr;
1114 while (snr_offset >= 0 &&
1122 for (snr_incr = 64; snr_incr > 0; snr_incr >>= 2) {
1123 while (snr_offset + snr_incr <= 1023 &&
1124 bit_alloc(s, snr_offset + snr_incr) <= bits_left) {
1125 snr_offset += snr_incr;
1133 for (ch = !s->
cpl_on; ch <= s->channels; ch++)
1168 int v = (((levels *
c) >> (24 - e)) + levels) >> 1;
1186 c = (((c * (1<<e)) >> (24 - qbits)) + 1) >> 1;
1187 m = (1 << (qbits-1));
1208 int16_t *qmant,
int start_freq,
1213 for (i = start_freq; i < end_freq; i++) {
1214 int c = fixed_coef[i];
1302 int blk,
ch, ch0=0, got_cpl;
1309 for (ch = 1; ch <= s->
channels; ch++) {
1416 int start_sub, end_sub;
1433 for (bnd = start_sub+1; bnd < end_sub; bnd++)
1458 if (!s->
eac3 || blk > 0)
1469 for (ch = !block->
cpl_in_use; ch <= s->fbw_channels; ch++)
1482 for (ch = !block->
cpl_in_use; ch <= s->channels; ch++) {
1484 int cpl = (ch ==
CPL_CH);
1494 for (i = 1; i <= nb_groups; i++)
1520 for (ch = !block->
cpl_in_use; ch <= s->channels; ch++) {
1546 for (ch = 1; ch <= s->
channels; ch++) {
1554 for (i = s->
start_freq[ch]; i < block->end_freq[ch]; i++) {
1559 case 1:
if (q != 128)
put_bits (&s->
pb, 5, q);
break;
1560 case 2:
if (q != 128)
put_bits (&s->
pb, 7, q);
break;
1562 case 4:
if (q != 128)
put_bits (&s->
pb, 7, q);
break;
1575 #define CRC16_POLY ((1 << 0) | (1 << 2) | (1 << 15) | (1 << 16))
1615 int frame_size_58, pad_bytes, crc1, crc2_partial, crc2, crc_inv;
1641 crc2_partial =
av_crc(crc_ctx, 0, frame + frame_size_58,
1646 if (crc2 == 0x770B) {
1684 case 6:
av_strlcpy(strbuf,
"AC-3 (alt syntax)", 32);
break;
1685 case 8:
av_strlcpy(strbuf,
"AC-3 (standard)", 32);
break;
1686 case 9:
av_strlcpy(strbuf,
"AC-3 (dnet half-rate)", 32);
break;
1687 case 10:
av_strlcpy(strbuf,
"AC-3 (dnet quater-rate)", 32);
break;
1688 case 16:
av_strlcpy(strbuf,
"E-AC-3 (enhanced)", 32);
break;
1689 default:
snprintf(strbuf, 32,
"ERROR");
1694 ff_dlog(avctx,
"channel_layout: %s\n", strbuf);
1701 ff_dlog(avctx,
"per_frame_metadata: %s\n",
1707 ff_dlog(avctx,
"center_mixlev: {not written}\n");
1712 ff_dlog(avctx,
"surround_mixlev: {not written}\n");
1721 ff_dlog(avctx,
"room_type: %s\n", strbuf);
1723 ff_dlog(avctx,
"mixing_level: {not written}\n");
1724 ff_dlog(avctx,
"room_type: {not written}\n");
1735 ff_dlog(avctx,
"dsur_mode: %s\n", strbuf);
1737 ff_dlog(avctx,
"dsur_mode: {not written}\n");
1749 ff_dlog(avctx,
"dmix_mode: %s\n", strbuf);
1750 ff_dlog(avctx,
"ltrt_cmixlev: %0.3f (%d)\n",
1752 ff_dlog(avctx,
"ltrt_surmixlev: %0.3f (%d)\n",
1754 ff_dlog(avctx,
"loro_cmixlev: %0.3f (%d)\n",
1756 ff_dlog(avctx,
"loro_surmixlev: %0.3f (%d)\n",
1759 ff_dlog(avctx,
"extended bitstream info 1: {not written}\n");
1768 ff_dlog(avctx,
"dsurex_mode: %s\n", strbuf);
1775 ff_dlog(avctx,
"dheadphone_mode: %s\n", strbuf);
1782 ff_dlog(avctx,
"ad_conv_type: %s\n", strbuf);
1784 ff_dlog(avctx,
"extended bitstream info 2: {not written}\n");
1791 #define FLT_OPTION_THRESHOLD 0.01
1797 for (i = 0; i < v_list_size; i++) {
1802 if (i == v_list_size)
1810 float *opt_param,
const float *list,
1811 int list_size,
int default_value,
int min_value,
1815 if (mixlev < min_value) {
1816 mixlev = default_value;
1817 if (*opt_param >= 0.0) {
1819 "default value: %0.3f\n", opt_name, list[mixlev]);
1822 *opt_param = list[mixlev];
1823 *ctx_param = mixlev;
1943 "specified number of channels\n");
1980 "room_type is set\n");
1985 "80dB and 111dB\n");
1996 static int warn_once = 1;
1999 "not compatible with reduced samplerates. writing of "
2000 "extended bitstream information will be disabled.\n");
2024 for (ch = 0; ch < s->
channels; ch++)
2064 uint64_t *channel_layout)
2070 if (*channel_layout > 0x7FF)
2072 ch_layout = *channel_layout;
2083 switch (ch_layout) {
2089 case AV_CH_LAYOUT_QUAD:
2091 case AV_CH_LAYOUT_5POINT0:
2100 *channel_layout = ch_layout;
2116 "encoder will guess the layout, but it "
2117 "might be incorrect.\n");
2129 max_sr = s->
eac3 ? 2 : 8;
2130 for (i = 0; i <= max_sr; i++) {
2146 case 1: avctx->
bit_rate = 96000;
break;
2147 case 2: avctx->
bit_rate = 192000;
break;
2148 case 3: avctx->
bit_rate = 320000;
break;
2149 case 4: avctx->
bit_rate = 384000;
break;
2150 case 5: avctx->
bit_rate = 448000;
break;
2156 int max_br, min_br, wpf, min_br_code;
2157 int num_blks_code, num_blocks, frame_samples;
2158 long long min_br_dist;
2164 for (num_blks_code = 3; num_blks_code >= 0; num_blks_code--) {
2165 num_blocks = ((
int[]){ 1, 2, 3, 6 })[num_blks_code];
2167 max_br = 2048 * s->
sample_rate / frame_samples * 16;
2168 min_br = ((s->
sample_rate + (frame_samples-1)) / frame_samples) * 16;
2174 "for this sample rate\n", min_br, max_br);
2188 min_br_dist = INT64_MAX;
2189 for (i = 0; i < 19; i++) {
2191 if (br_dist < min_br_dist) {
2192 min_br_dist = br_dist;
2203 int best_br = 0, best_code = 0;
2204 long long best_diff = INT64_MAX;
2205 for (i = 0; i < 19; i++) {
2208 if (diff < best_diff) {
2286 if (cpl_start < 0) {
2295 int i, cpl_start_band, cpl_end_band;
2299 cpl_start_band = av_clip(cpl_start, 0,
FFMIN(cpl_end_band-1, 15));
2304 *cpl_band_sizes = 12;
2305 for (i = cpl_start_band + 1; i < cpl_end_band; i++) {
2307 *cpl_band_sizes += 12;
2311 *cpl_band_sizes = 12;
2328 int channel_blocks = channels * s->
num_blocks;
2381 for (ch = 0; ch < channels; ch++) {
2406 for (ch = 0; ch < channels; ch++)
2414 for (ch = 0; ch < channels; ch++)
2428 int ret, frame_size_58;
2461 }
else if (CONFIG_AC3_ENCODER || CONFIG_EAC3_ENCODER) {
2466 if (CONFIG_EAC3_ENCODER && s->
eac3)
static void count_mantissa_bits_init(uint16_t mant_cnt[AC3_MAX_BLOCKS][16])
Initialize mantissa counts.
av_cold void ff_me_cmp_init(MECmpContext *c, AVCodecContext *avctx)
uint8_t new_rematrixing_strategy
send new rematrixing flags in this block
uint8_t exp_strategy[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]
exponent strategies
const uint8_t ff_ac3_bap_tab[64]
#define AC3_MAX_CODED_FRAME_SIZE
static av_cold int set_channel_info(AC3EncodeContext *s, int channels, uint64_t *channel_layout)
static void ac3_output_frame_header(AC3EncodeContext *s)
#define FF_ALLOCZ_ARRAY_OR_GOTO(ctx, p, nelem, elsize, label)
int db_per_bit_code
dB/bit code (dbpbcod)
static const uint8_t exp_strategy_reuse_tab[4][6]
Table used to select exponent strategy based on exponent reuse block interval.
int slow_decay_code
slow decay code (sdcycod)
Encoding Options used by AVOption.
const uint8_t ff_ac3_slow_decay_tab[4]
int ff_ac3_fixed_allocate_sample_buffers(AC3EncodeContext *s)
float loro_surround_mix_level
static void put_sbits(PutBitContext *pb, int n, int32_t value)
static void compute_exp_strategy(AC3EncodeContext *s)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
static int asym_quant(int c, int e, int qbits)
Asymmetric quantization on 2^qbits levels.
#define AV_LOG_WARNING
Something somehow does not look correct.
int dolby_surround_ex_mode
static uint8_t exponent_group_tab[2][3][256]
LUT for number of exponent groups.
int64_t bit_rate
the average bitrate
#define AV_CH_LAYOUT_SURROUND
uint8_t ** cpl_coord_exp
coupling coord exponents (cplcoexp)
int bandwidth_code
bandwidth code (0 to 60) (chbwcod)
const uint16_t ff_ac3_frame_size_tab[38][3]
Possible frame sizes.
uint8_t * grouped_exp_buffer
static av_cold int allocate_buffers(AC3EncodeContext *s)
#define LEVEL_PLUS_1POINT5DB
int16_t ** psd
psd per frequency bin
int frame_size_code
frame size code (frmsizecod)
void(* mdct_end)(struct AC3EncodeContext *s)
int frame_bits
all frame bits except exponents and mantissas
av_cold void ff_audiodsp_init(AudioDSPContext *c)
void ff_ac3_process_exponents(AC3EncodeContext *s)
Calculate final exponents from the supplied MDCT coefficients and exponent shift. ...
const uint16_t ff_ac3_sample_rate_tab[3]
#define AV_CH_LAYOUT_4POINT0
uint8_t ** cpl_coord_mant
coupling coord mantissas (cplcomant)
uint16_t ** qmant
quantized mantissas
int start_freq[AC3_MAX_CHANNELS]
start frequency bin (strtmant)
#define AV_CH_LAYOUT_STEREO
const uint16_t ff_ac3_slow_gain_tab[4]
PutBitContext pb
bitstream writer context
static const float cmixlev_options[CMIXLEV_NUM_OPTIONS]
int num_cpl_channels
number of channels in coupling
AC3BitAllocParameters bit_alloc
bit allocation parameters
#define AV_CH_LAYOUT_5POINT0
static int count_exponent_bits(AC3EncodeContext *s)
static void extract_exponents(AC3EncodeContext *s)
Macro definitions for various function/variable attributes.
int ff_ac3_float_allocate_sample_buffers(AC3EncodeContext *s)
enum AVAudioServiceType audio_service_type
Type of service that the audio stream conveys.
int ff_ac3_validate_metadata(AC3EncodeContext *s)
Validate metadata options as set by AVOption system.
float ltrt_surround_mix_level
int new_cpl_leak
send new coupling leak info
int rematrixing_enabled
stereo rematrixing enabled
void ff_eac3_get_frame_exp_strategy(AC3EncodeContext *s)
Determine frame exponent strategy use and indices.
int channel_mode
channel mode (acmod)
int num_cpl_subbands
number of coupling subbands (ncplsubnd)
enum AVSampleFormat sample_fmt
audio sample format
int(* allocate_sample_buffers)(struct AC3EncodeContext *s)
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
static void count_frame_bits(AC3EncodeContext *s)
static const float extmixlev_options[EXTMIXLEV_NUM_OPTIONS]
uint8_t rematrixing_flags[4]
rematrixing flags
int fbw_channels
number of full-bandwidth channels (nfchans)
uint8_t new_cpl_coords[AC3_MAX_CHANNELS]
send new coupling coordinates (cplcoe)
static av_cold int end(AVCodecContext *avctx)
static av_cold void set_bandwidth(AC3EncodeContext *s)
const uint8_t ff_ac3_enc_channel_map[8][2][6]
Table to remap channels from SMPTE order to AC-3 order.
av_cold int ff_ac3_encode_close(AVCodecContext *avctx)
Finalize encoding and free any memory allocated by the encoder.
#define AV_CH_LOW_FREQUENCY
int slow_gain_code
slow gain code (sgaincod)
Public header for CRC hash function implementation.
uint8_t cpl_master_exp[AC3_MAX_CHANNELS]
coupling coord master exponents (mstrcplco)
#define CRC16_POLY
CRC-16 Polynomial.
uint8_t ** exp
original exponents
int num_rematrixing_bands
number of rematrixing bands
static av_cold int validate_options(AC3EncodeContext *s)
AC3DSPContext ac3dsp
AC-3 optimized functions.
int loro_center_mix_level
Lo/Ro center mix level code.
int num_cpl_bands
number of coupling bands (ncplbnd)
static int bit_alloc(AC3EncodeContext *s, int snr_offset)
Run the bit allocation with a given SNR offset.
void ff_ac3_fixed_mdct_end(AC3EncodeContext *s)
static void dprint_options(AC3EncodeContext *s)
int lfe_channel
channel index of the LFE channel
int ref_bap_set
indicates if ref_bap pointers have been set
#define EXP_DIFF_THRESHOLD
Exponent Difference Threshold.
static av_cold void exponent_init(AC3EncodeContext *s)
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.
int new_snr_offsets
send new SNR offsets
int loro_surround_mix_level
Lo/Ro surround mix level code.
CoefType ** mdct_coef
MDCT coefficients.
int16_t * qmant4_ptr
mantissa pointers for bap=1,2,4
#define AV_CH_LAYOUT_5POINT1
uint8_t channel_in_cpl[AC3_MAX_CHANNELS]
channel in coupling (chincpl)
#define AC3ENC_OPT_SMALL_ROOM
int num_blks_code
number of blocks code (numblkscod)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const uint64_t ff_ac3_channel_layouts[19]
List of supported channel layouts.
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
static int sym_quant(int c, int e, int levels)
Symmetric quantization on 'levels' levels.
const uint8_t ff_ac3_fast_decay_tab[4]
AC3EncOptions options
encoding options
int16_t ** band_psd
psd per critical band
float ltrt_center_mix_level
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.
int channels
total number of channels (nchans)
int initial_padding
Audio only.
#define AC3_MAX_CHANNELS
maximum number of channels, including coupling channel
int flags
AV_CODEC_FLAG_*.
int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, int start, int end, int fast_gain, int is_lfe, int dba_mode, int dba_nsegs, uint8_t *dba_offsets, uint8_t *dba_lengths, uint8_t *dba_values, int16_t *mask)
Calculate the masking curve.
int cpl_on
coupling turned on for this frame
simple assert() macros that are a bit more flexible than ISO C assert().
#define AV_CH_LAYOUT_QUAD
int fixed_point
indicates if fixed-point encoder is being used
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
int ltrt_surround_mix_level
Lt/Rt surround mix level code.
int new_cpl_strategy
send new coupling strategy
int surround_mix_level
surround mix level code
int cpl_in_use
coupling in use for this block (cplinu)
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
int cpl_enabled
coupling enabled for all frames
static void output_frame_end(AC3EncodeContext *s)
#define EXTMIXLEV_NUM_OPTIONS
uint64_t channel_layout
Audio channel layout.
#define LEVEL_MINUS_4POINT5DB
static int put_bits_count(PutBitContext *s)
static void output_audio_block(AC3EncodeContext *s, int blk)
const uint16_t ff_ac3_bitrate_tab[19]
static int count_mantissa_bits(AC3EncodeContext *s)
Data for a single audio block.
common internal API header
int(* mdct_init)(struct AC3EncodeContext *s)
int floor_code
floor code (floorcod)
int ff_ac3_compute_bit_allocation(AC3EncodeContext *s)
#define AC3ENC_OPT_DOWNMIX_LORO
int bitstream_mode
bitstream mode (bsmod)
#define AC3ENC_OPT_ADCONV_STANDARD
int has_surround
indicates if there are one or more surround channels
audio channel layout utility functions
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
int eac3
indicates if this is E-AC-3 vs. AC-3
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 cha...
float loro_center_mix_level
av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact)
int mant4_cnt
mantissa counts for bap=1,2,4
int ff_ac3_float_mdct_init(AC3EncodeContext *s)
Initialize MDCT tables.
const uint16_t ff_ac3_fast_gain_tab[8]
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
void ff_ac3_adjust_frame_size(AC3EncodeContext *s)
Adjust the frame size to make the average bit rate match the target bit rate.
int exponent_bits
number of bits used for exponents
#define AV_CH_LAYOUT_5POINT1_BACK
int coarse_snr_offset
coarse SNR offsets (csnroffst)
int16_t ** mask
masking curve
void(* extract_exponents)(uint8_t *exp, int32_t *coef, int nb_coefs)
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
SampleType ** planar_samples
int fast_decay_code
fast decay code (fdcycod)
int frame_size
Number of samples per channel in an audio frame.
#define AC3ENC_OPT_MODE_OFF
void(* bit_alloc_calc_bap)(int16_t *mask, int16_t *psd, int start, int end, int snr_offset, int floor, const uint8_t *bap_tab, uint8_t *bap)
Calculate bit allocation pointers.
#define AC3ENC_OPT_ADCONV_HDCD
void(* output_frame_header)(struct AC3EncodeContext *s)
#define CPL_CH
coupling channel index
const uint8_t ff_eac3_default_cpl_band_struct[18]
Table E2.16 Default Coupling Banding Structure.
uint8_t * ref_bap[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]
bit allocation pointers (bap)
void ff_eac3_output_frame_header(AC3EncodeContext *s)
Write the E-AC-3 frame header to the output bitstream.
Libavcodec external API header.
int audio_production_info
int sample_rate
samples per second
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-bandwidt...
main external API structure.
int fast_gain_code[AC3_MAX_CHANNELS]
fast gain codes (signal-to-mask ratio) (fgaincod)
int sample_rate
sampling frequency, in Hz
CoefType * mdct_coef_buffer
int has_center
indicates if there is a center channel
int bit_rate
target bit rate, in bits-per-second
static unsigned int mul_poly(unsigned int a, unsigned int b, unsigned int poly)
const uint8_t * channel_map
channel map used to reorder channels
int frame_bits_fixed
number of non-coefficient bits for fixed parameters
int end_freq[AC3_MAX_CHANNELS]
end frequency bin (endmant)
#define FLT_OPTION_THRESHOLD
static int validate_float_option(float v, const float *v_list, int v_list_size)
uint8_t * cpl_coord_exp_buffer
int ltrt_center_mix_level
Lt/Rt center mix level code.
#define AV_CH_LAYOUT_5POINT0_BACK
av_cold void ff_eac3_exponent_init(void)
Initialize E-AC-3 exponent tables.
int center_mix_level
center mix level code
AC-3 encoder private context.
void ff_ac3_output_frame(AC3EncodeContext *s, unsigned char *frame)
Write the frame to the output bitstream.
static void count_frame_bits_fixed(AC3EncodeContext *s)
AC3Block blocks[AC3_MAX_BLOCKS]
per-block info
const int16_t ff_ac3_floor_tab[8]
SampleType * windowed_samples
int preferred_stereo_downmix
void ff_ac3_quantize_mantissas(AC3EncodeContext *s)
Quantize mantissas using coefficients, exponents, and bit allocation pointers.
int(* compute_mantissa_size)(uint16_t mant_cnt[6][16])
Calculate the number of bits needed to encode a set of mantissas.
int num_blocks
number of blocks per frame
static void encode_exponents(AC3EncodeContext *s)
#define CMIXLEV_NUM_OPTIONS
static void reset_block_bap(AC3EncodeContext *s)
#define FF_ALLOC_ARRAY_OR_GOTO(ctx, p, nelem, elsize, label)
static av_cold void bit_alloc_init(AC3EncodeContext *s)
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
int frame_size
current frame size in bytes
#define SURMIXLEV_NUM_OPTIONS
void(* update_bap_counts)(uint16_t mant_cnt[16], uint8_t *bap, int len)
Update bap counts using the supplied array of bap.
uint8_t ** grouped_exp
grouped exponents
int cpl_end_freq
coupling channel end frequency bin
#define AC3ENC_OPT_LARGE_ROOM
uint8_t cpl_band_sizes[AC3_MAX_CPL_BANDS]
number of coeffs in each coupling band
common internal api header.
#define AC3ENC_OPT_MODE_ON
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
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)
static const float surmixlev_options[SURMIXLEV_NUM_OPTIONS]
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_YASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
int64_t bits_written
bit count (used to avg. bitrate)
void(* ac3_exponent_min)(uint8_t *exp, int num_reuse_blocks, int nb_coefs)
Set each encoded exponent in a block to the minimum of itself and the exponents in the same frequency...
int bitstream_id
bitstream id (bsid)
int16_t * band_psd_buffer
AVCodecContext * avctx
parent AVCodecContext
uint8_t exp_ref_block[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]
reference blocks for EXP_REUSE
int cutoff
Audio cutoff bandwidth (0 means "automatic")
int allow_per_frame_metadata
void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd, int16_t *band_psd)
Calculate the log power-spectral density of the input signal.
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.
static av_always_inline int diff(const uint32_t a, const uint32_t b)
#define AC3ENC_OPT_DOWNMIX_LTRT
int channels
number of audio channels
#define AC3ENC_OPT_NOT_INDICATED
static int cbr_bit_allocation(AC3EncodeContext *s)
int frame_size_min
minimum frame size in case rounding is necessary
void ff_ac3_float_mdct_end(AC3EncodeContext *s)
Finalize MDCT and free allocated memory.
AC-3 encoder & E-AC-3 encoder common header.
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
static unsigned int pow_poly(unsigned int a, unsigned int n, unsigned int poly)
#define LOCAL_ALIGNED_16(t, v,...)
void ff_ac3_apply_rematrixing(AC3EncodeContext *s)
Apply stereo rematrixing to coefficients based on rematrixing flags.
const uint8_t ff_ac3_rematrix_band_tab[5]
Table of bin locations for rematrixing bands reference: Section 7.5.2 Rematrixing : Frequency Band De...
int64_t samples_written
sample count (used to avg. bitrate)
uint8_t * cpl_coord_mant_buffer
int use_frame_exp_strategy
indicates use of frame exp strategy
#define FFSWAP(type, a, b)
static void bit_alloc_masking(AC3EncodeContext *s)
int ff_ac3_fixed_mdct_init(AC3EncodeContext *s)
void ff_ac3_group_exponents(AC3EncodeContext *s)
Group exponents.
const uint16_t ff_ac3_db_per_bit_tab[4]
#define AV_CH_LAYOUT_MONO
void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s)
Set the initial coupling strategy parameters prior to coupling analysis.
int cutoff
user-specified cutoff frequency, in Hz
int lfe_on
indicates if there is an LFE channel (lfeon)
int fine_snr_offset[AC3_MAX_CHANNELS]
fine SNR offsets (fsnroffst)
Common code between the AC-3 encoder and decoder.
int32_t * fixed_coef_buffer
int32_t ** fixed_coef
fixed-point MDCT coefficients
av_cold int ff_ac3_encode_init(AVCodecContext *avctx)