56 #define CMIXLEV_NUM_OPTIONS 3 61 #define SURMIXLEV_NUM_OPTIONS 3 66 #define EXTMIXLEV_NUM_OPTIONS 8 114 { { 0, 0, 0, 12, 16, 32, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48 },
115 { 0, 0, 0, 16, 20, 36, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56 },
116 { 0, 0, 0, 32, 40, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60 } },
118 { { 0, 0, 0, 0, 0, 0, 0, 20, 24, 32, 48, 48, 48, 48, 48, 48, 48, 48, 48 },
119 { 0, 0, 0, 0, 0, 0, 4, 24, 28, 36, 56, 56, 56, 56, 56, 56, 56, 56, 56 },
120 { 0, 0, 0, 0, 0, 0, 20, 44, 52, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60 } },
122 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 24, 32, 40, 48, 48, 48, 48, 48, 48 },
123 { 0, 0, 0, 0, 0, 0, 0, 0, 4, 20, 28, 36, 44, 56, 56, 56, 56, 56, 56 },
124 { 0, 0, 0, 0, 0, 0, 0, 0, 20, 40, 48, 60, 60, 60, 60, 60, 60, 60, 60 } },
126 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 24, 32, 48, 48, 48, 48, 48, 48 },
127 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 28, 36, 56, 56, 56, 56, 56, 56 },
128 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 48, 60, 60, 60, 60, 60, 60, 60 } },
130 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 20, 32, 40, 48, 48, 48, 48 },
131 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 24, 36, 44, 56, 56, 56, 56 },
132 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 44, 60, 60, 60, 60, 60, 60 } }
148 { { 0, 0, 0, 0, 0, 0, 0, 1, 1, 7, 8, 11, 12, -1, -1, -1, -1, -1, -1 },
149 { 0, 0, 0, 0, 0, 0, 1, 3, 5, 7, 10, 12, 13, -1, -1, -1, -1, -1, -1 },
150 { 0, 0, 0, 0, 1, 2, 2, 9, 13, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
153 { { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 6, 9, 11, 12, 13, -1, -1, -1, -1 },
154 { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 6, 9, 11, 12, 13, -1, -1, -1, -1 },
155 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
158 { { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 6, 9, 11, 12, 13, -1, -1, -1, -1 },
159 { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 6, 9, 11, 12, 13, -1, -1, -1, -1 },
160 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
163 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 10, 11, 11, 12, 12, 14, -1 },
164 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 10, 11, 11, 12, 12, 14, -1 },
165 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
168 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 10, 11, 11, 12, 12, 14, -1 },
169 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 10, 11, 11, 12, 12, 14, -1 },
170 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
173 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 8, 11, 12, 12, -1, -1 },
174 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 8, 11, 12, 12, -1, -1 },
175 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
245 if (!blk || (block->
cpl_in_use && !got_cpl_snr)) {
293 for (i = start; i <
end; i++) {
310 int expstr,
i, grpsize;
313 grpsize = 3 << expstr;
314 for (i = 12; i < 256; i++) {
341 #define EXP_DIFF_THRESHOLD 500 361 for (ch = !s->
cpl_on; ch <= s->fbw_channels; ch++) {
394 while (blk < s->num_blocks) {
396 while (blk1 < s->num_blocks && exp_strategy[blk1] ==
EXP_REUSE)
410 if (CONFIG_EAC3_ENCODER && s->
eac3)
431 switch(exp_strategy) {
433 for (i = 1, k = 1-cpl; i <= nb_groups; i++) {
435 if (exp[k+1] < exp_min)
437 exp[i-cpl] = exp_min;
442 for (i = 1, k = 1-cpl; i <= nb_groups; i++) {
444 if (exp[k+1] < exp_min)
446 if (exp[k+2] < exp_min)
448 if (exp[k+3] < exp_min)
450 exp[i-cpl] = exp_min;
457 if (!cpl && exp[0] > 15)
462 for (i = 1; i <= nb_groups; i++)
463 exp[i] =
FFMIN(exp[i], exp[i-1] + 2);
466 exp[
i] =
FFMIN(exp[i], exp[i+1] + 2);
469 exp[-1] = exp[0] & ~1;
472 switch (exp_strategy) {
474 for (i = nb_groups, k = (nb_groups * 2)-cpl; i > 0; i--) {
481 for (i = nb_groups, k = (nb_groups * 4)-cpl; i > 0; i--) {
482 exp[k] = exp[k-1] = exp[k-2] = exp[k-3] = exp[i-cpl];
498 int blk, blk1, ch, cpl;
500 int nb_coefs, num_reuse_blocks;
508 while (blk < s->num_blocks) {
521 while (blk1 < s->num_blocks && exp_strategy[blk1] ==
EXP_REUSE) {
525 num_reuse_blocks = blk1 - blk - 1;
549 int nb_groups, bit_count;
563 bit_count += 4 + (nb_groups * 7);
581 int group_size, nb_groups;
583 int delta0, delta1, delta2;
593 group_size = exp_strategy + (exp_strategy ==
EXP_D45);
602 for (i = 1; i <= nb_groups; i++) {
607 delta0 = exp1 - exp0 + 2;
613 delta1 = exp1 - exp0 + 2;
619 delta2 = exp1 - exp0 + 2;
622 block->
grouped_exp[ch][
i] = ((delta0 * 5 + delta1) * 5) + delta2;
654 static const uint8_t frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 };
728 frame_bits += 2 + 2 + 2 + 2 + 3;
748 frame_bits += 1 + 16;
768 for (ch = 0; ch <= s->
channels; ch++)
810 frame_bits += 1 + 1 + 2;
816 frame_bits += 3 + 1 + 1;
823 frame_bits += 5 + 2 + 1;
839 frame_bits += 5 * s->
cpl_on;
897 if (!s->
eac3 || blk > 0)
979 for (ch = 0; ch <= s->
channels; ch++) {
1000 memset(mant_cnt[blk], 0,
sizeof(mant_cnt[blk]));
1001 mant_cnt[
blk][1] = mant_cnt[
blk][2] = 2;
1002 mant_cnt[
blk][4] = 1;
1039 int ch, max_end_freq;
1067 snr_offset = (snr_offset - 240) * 4;
1098 int snr_offset, snr_incr;
1113 while (snr_offset >= 0 &&
1121 for (snr_incr = 64; snr_incr > 0; snr_incr >>= 2) {
1122 while (snr_offset + snr_incr <= 1023 &&
1123 bit_alloc(s, snr_offset + snr_incr) <= bits_left) {
1124 snr_offset += snr_incr;
1167 int v = (((levels *
c) >> (24 - e)) + levels) >> 1;
1185 c = (((c * (1<<e)) >> (24 - qbits)) + 1) >> 1;
1186 m = (1 << (qbits-1));
1207 int16_t *qmant,
int start_freq,
1212 for (i = start_freq; i < end_freq; i++) {
1213 int c = fixed_coef[
i];
1301 int blk, ch, ch0=0, got_cpl;
1308 for (ch = 1; ch <= s->
channels; ch++) {
1386 int ch,
i, baie, bnd, got_cpl,
av_uninit(ch0);
1415 int start_sub, end_sub;
1432 for (bnd = start_sub+1; bnd < end_sub; bnd++)
1457 if (!s->
eac3 || blk > 0)
1468 for (ch = !block->
cpl_in_use; ch <= s->fbw_channels; ch++)
1483 int cpl = (ch ==
CPL_CH);
1493 for (i = 1; i <= nb_groups; i++)
1545 for (ch = 1; ch <= s->
channels; ch++) {
1553 for (i = s->
start_freq[ch]; i < block->end_freq[ch]; i++) {
1558 case 1:
if (q != 128)
put_bits (&s->
pb, 5, q);
break;
1559 case 2:
if (q != 128)
put_bits (&s->
pb, 7, q);
break;
1561 case 4:
if (q != 128)
put_bits (&s->
pb, 7, q);
break;
1574 #define CRC16_POLY ((1 << 0) | (1 << 2) | (1 << 15) | (1 << 16)) 1577 static unsigned int mul_poly(
unsigned int a,
unsigned int b,
unsigned int poly)
1594 static unsigned int pow_poly(
unsigned int a,
unsigned int n,
unsigned int poly)
1614 int frame_size_58, pad_bytes, crc1, crc2_partial, crc2, crc_inv;
1640 crc2_partial =
av_crc(crc_ctx, 0, frame + frame_size_58,
1645 if (crc2 == 0x770B) {
1701 *got_packet_ptr = 1;
1713 case 6:
av_strlcpy(strbuf,
"AC-3 (alt syntax)", 32);
break;
1714 case 8:
av_strlcpy(strbuf,
"AC-3 (standard)", 32);
break;
1715 case 9:
av_strlcpy(strbuf,
"AC-3 (dnet half-rate)", 32);
break;
1716 case 10:
av_strlcpy(strbuf,
"AC-3 (dnet quater-rate)", 32);
break;
1717 case 16:
av_strlcpy(strbuf,
"E-AC-3 (enhanced)", 32);
break;
1718 default:
snprintf(strbuf, 32,
"ERROR");
1723 ff_dlog(avctx,
"channel_layout: %s\n", strbuf);
1730 ff_dlog(avctx,
"per_frame_metadata: %s\n",
1736 ff_dlog(avctx,
"center_mixlev: {not written}\n");
1741 ff_dlog(avctx,
"surround_mixlev: {not written}\n");
1750 ff_dlog(avctx,
"room_type: %s\n", strbuf);
1752 ff_dlog(avctx,
"mixing_level: {not written}\n");
1753 ff_dlog(avctx,
"room_type: {not written}\n");
1764 ff_dlog(avctx,
"dsur_mode: %s\n", strbuf);
1766 ff_dlog(avctx,
"dsur_mode: {not written}\n");
1778 ff_dlog(avctx,
"dmix_mode: %s\n", strbuf);
1779 ff_dlog(avctx,
"ltrt_cmixlev: %0.3f (%d)\n",
1781 ff_dlog(avctx,
"ltrt_surmixlev: %0.3f (%d)\n",
1783 ff_dlog(avctx,
"loro_cmixlev: %0.3f (%d)\n",
1785 ff_dlog(avctx,
"loro_surmixlev: %0.3f (%d)\n",
1788 ff_dlog(avctx,
"extended bitstream info 1: {not written}\n");
1797 ff_dlog(avctx,
"dsurex_mode: %s\n", strbuf);
1804 ff_dlog(avctx,
"dheadphone_mode: %s\n", strbuf);
1811 ff_dlog(avctx,
"ad_conv_type: %s\n", strbuf);
1813 ff_dlog(avctx,
"extended bitstream info 2: {not written}\n");
1820 #define FLT_OPTION_THRESHOLD 0.01 1826 for (i = 0; i < v_list_size; i++) {
1831 if (i == v_list_size)
1839 float *opt_param,
const float *
list,
1840 int list_size,
int default_value,
int min_value,
1844 if (mixlev < min_value) {
1845 mixlev = default_value;
1846 if (*opt_param >= 0.0) {
1848 "default value: %0.3f\n", opt_name, list[mixlev]);
1851 *opt_param = list[mixlev];
1852 *ctx_param = mixlev;
1972 "specified number of channels\n");
2009 "room_type is set\n");
2014 "80dB and 111dB\n");
2027 "not compatible with reduced samplerates. writing of " 2028 "extended bitstream information will be disabled.\n");
2053 for (ch = 0; ch < s->
channels; ch++)
2093 uint64_t *channel_layout)
2099 if (*channel_layout > 0x7FF)
2101 ch_layout = *channel_layout;
2112 switch (ch_layout) {
2129 *channel_layout = ch_layout;
2145 "encoder will guess the layout, but it " 2146 "might be incorrect.\n");
2158 max_sr = s->
eac3 ? 2 : 8;
2159 for (i = 0; i <= max_sr; i++) {
2175 case 1: avctx->
bit_rate = 96000;
break;
2176 case 2: avctx->
bit_rate = 192000;
break;
2177 case 3: avctx->
bit_rate = 320000;
break;
2178 case 4: avctx->
bit_rate = 384000;
break;
2179 case 5: avctx->
bit_rate = 448000;
break;
2185 int max_br, min_br, wpf, min_br_code;
2186 int num_blks_code, num_blocks, frame_samples;
2187 long long min_br_dist;
2193 for (num_blks_code = 3; num_blks_code >= 0; num_blks_code--) {
2194 num_blocks = ((
int[]){ 1, 2, 3, 6 })[num_blks_code];
2196 max_br = 2048 * s->
sample_rate / frame_samples * 16;
2197 min_br = ((s->
sample_rate + (frame_samples-1)) / frame_samples) * 16;
2203 "for this sample rate\n", min_br, max_br);
2217 min_br_dist = INT64_MAX;
2218 for (i = 0; i < 19; i++) {
2220 if (br_dist < min_br_dist) {
2221 min_br_dist = br_dist;
2232 int best_br = 0, best_code = 0;
2233 long long best_diff = INT64_MAX;
2234 for (i = 0; i < 19; i++) {
2237 if (diff < best_diff) {
2315 if (cpl_start < 0) {
2324 int i, cpl_start_band, cpl_end_band;
2328 cpl_start_band = av_clip(cpl_start, 0,
FFMIN(cpl_end_band-1, 15));
2333 *cpl_band_sizes = 12;
2334 for (i = cpl_start_band + 1; i < cpl_end_band; i++) {
2336 *cpl_band_sizes += 12;
2340 *cpl_band_sizes = 12;
2356 int channel_blocks = channels * s->
num_blocks;
2396 for (ch = 0; ch <
channels; ch++) {
2442 int ret, frame_size_58;
2470 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
void(* mdct_end)(struct AC3EncodeContext *s)
static av_cold int set_channel_info(AC3EncodeContext *s, int channels, uint64_t *channel_layout)
static void ac3_output_frame_header(AC3EncodeContext *s)
This structure describes decoded (raw) audio or video data.
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]
void(* update_bap_counts)(uint16_t mant_cnt[16], uint8_t *bap, int len)
Update bap counts using the supplied array of bap.
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)
int frame_bits
all frame bits except exponents and mantissas
#define FF_ALLOC_TYPED_ARRAY(p, nelem)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
static int ac3_compute_bit_allocation(AC3EncodeContext *s)
#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(* mdct_init)(struct AC3EncodeContext *s)
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.
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
#define LOCAL_ALIGNED_16(t, v,...)
void ff_eac3_get_frame_exp_strategy(AC3EncodeContext *s)
Determine frame exponent strategy use and indices.
void(* extract_exponents)(uint8_t *exp, int32_t *coef, int nb_coefs)
int channel_mode
channel mode (acmod)
int num_cpl_subbands
number of coupling subbands (ncplsubnd)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
static void ac3_apply_rematrixing(AC3EncodeContext *s)
Apply stereo rematrixing to coefficients based on rematrixing flags.
enum AVSampleFormat sample_fmt
audio sample format
The exact code depends on how similar the blocks are and how related they are to the block
#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
av_cold void ff_audiodsp_init(AudioDSPContext *c)
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)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
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.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
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.
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.
uint8_t ** exp
original exponents
int num_rematrixing_bands
number of rematrixing bands
static av_cold int validate_options(AC3EncodeContext *s)
#define LEVEL_MINUS_1POINT5DB
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.
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 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
void(* output_frame_header)(struct AC3EncodeContext *s)
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
static void ac3_output_frame(AC3EncodeContext *s, unsigned char *frame)
Write the frame to the output bitstream.
#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
static void ac3_quantize_mantissas(AC3EncodeContext *s)
Quantize mantissas using coefficients, exponents, and bit allocation pointers.
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 ac3_process_exponents(AC3EncodeContext *s)
Calculate final exponents from the supplied MDCT coefficients and exponent shift. ...
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 floor_code
floor code (floorcod)
#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
static void ac3_group_exponents(AC3EncodeContext *s)
Group exponents.
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
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.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
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
const SampleType * mdct_window
MDCT window function array.
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)
static av_cold void exponent_init(void)
int frame_size
Number of samples per channel in an audio frame.
#define AC3ENC_OPT_MODE_OFF
#define AC3ENC_OPT_ADCONV_HDCD
#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
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining list
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)
int(* allocate_sample_buffers)(struct AC3EncodeContext *s)
const uint8_t * channel_map
channel map used to reorder channels
int frame_bits_fixed
number of non-coefficient bits for fixed parameters
int warned_alternate_bitstream
int end_freq[AC3_MAX_CHANNELS]
end frequency bin (endmant)
#define FLT_OPTION_THRESHOLD
int(* compute_mantissa_size)(uint16_t mant_cnt[6][16])
Calculate the number of bits needed to encode a set of mantissas.
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.
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(* 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 num_blocks
number of blocks per frame
#define flags(name, subs,...)
static void encode_exponents(AC3EncodeContext *s)
#define CMIXLEV_NUM_OPTIONS
static void reset_block_bap(AC3EncodeContext *s)
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
int ff_ac3_encode_frame_common_end(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
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.
int64_t bits_written
bit count (used to avg. bitrate)
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
static int ff_thread_once(char *control, void(*routine)(void))
#define AC3ENC_OPT_NOT_INDICATED
static int cbr_bit_allocation(AC3EncodeContext *s)
int frame_size_min
minimum frame size in case rounding is necessary
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)
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)
const int ff_ac3_sample_rate_tab[]
static av_always_inline int64_t ff_samples_to_time_base(AVCodecContext *avctx, int64_t samples)
Rescale from sample rate to AVCodecContext.time_base.
uint8_t * cpl_coord_mant_buffer
int use_frame_exp_strategy
indicates use of frame exp strategy
#define FFSWAP(type, a, b)
#define FF_ALLOCZ_TYPED_ARRAY(p, nelem)
static void bit_alloc_masking(AC3EncodeContext *s)
const uint16_t ff_ac3_db_per_bit_tab[4]
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
#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)
This structure stores compressed data.
Common code between the AC-3 encoder and decoder.
int32_t * fixed_coef_buffer
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.
int32_t ** fixed_coef
fixed-point MDCT coefficients
av_cold int ff_ac3_encode_init(AVCodecContext *avctx)