56 #define CMIXLEV_NUM_OPTIONS 3 61 #define SURMIXLEV_NUM_OPTIONS 3 66 #define EXTMIXLEV_NUM_OPTIONS 8 75 #define OFFSET(param) offsetof(AC3EncodeContext, options.param) 76 #define AC3ENC_PARAM (AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM) 88 {
"per_frame_metadata",
"Allow Changing Metadata Per-Frame",
OFFSET(allow_per_frame_metadata),
AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, AC3ENC_PARAM},
90 {
"dialnorm",
"Dialogue Level (dB)",
OFFSET(dialogue_level),
AV_OPT_TYPE_INT, {.i64 = -31 }, -31, -1, AC3ENC_PARAM},
102 {
"ltrt_cmixlev",
"Lt/Rt Center Mix Level",
OFFSET(ltrt_center_mix_level),
AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM},
103 {
"ltrt_surmixlev",
"Lt/Rt Surround Mix Level",
OFFSET(ltrt_surround_mix_level),
AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM},
104 {
"loro_cmixlev",
"Lo/Ro Center Mix Level",
OFFSET(loro_center_mix_level),
AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM},
105 {
"loro_surmixlev",
"Lo/Ro Surround Mix Level",
OFFSET(loro_surround_mix_level),
AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM},
119 {
"stereo_rematrixing",
"Stereo Rematrixing",
OFFSET(stereo_rematrixing),
AV_OPT_TYPE_BOOL, {.i64 = 1 }, 0, 1, AC3ENC_PARAM},
170 { { 0, 1, 2, 3, }, { 0, 1, 3, 4, 2, } },
171 { { 0, 2, 1, 3, 4, }, { 0, 2, 1, 4, 5, 3 } },
182 { { 0, 0, 0, 12, 16, 32, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48 },
183 { 0, 0, 0, 16, 20, 36, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56 },
184 { 0, 0, 0, 32, 40, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60 } },
186 { { 0, 0, 0, 0, 0, 0, 0, 20, 24, 32, 48, 48, 48, 48, 48, 48, 48, 48, 48 },
187 { 0, 0, 0, 0, 0, 0, 4, 24, 28, 36, 56, 56, 56, 56, 56, 56, 56, 56, 56 },
188 { 0, 0, 0, 0, 0, 0, 20, 44, 52, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60 } },
190 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 24, 32, 40, 48, 48, 48, 48, 48, 48 },
191 { 0, 0, 0, 0, 0, 0, 0, 0, 4, 20, 28, 36, 44, 56, 56, 56, 56, 56, 56 },
192 { 0, 0, 0, 0, 0, 0, 0, 0, 20, 40, 48, 60, 60, 60, 60, 60, 60, 60, 60 } },
194 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 24, 32, 48, 48, 48, 48, 48, 48 },
195 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 28, 36, 56, 56, 56, 56, 56, 56 },
196 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 48, 60, 60, 60, 60, 60, 60, 60 } },
198 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 20, 32, 40, 48, 48, 48, 48 },
199 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 24, 36, 44, 56, 56, 56, 56 },
200 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 44, 60, 60, 60, 60, 60, 60 } }
216 { { 0, 0, 0, 0, 0, 0, 0, 1, 1, 7, 8, 11, 12, -1, -1, -1, -1, -1, -1 },
217 { 0, 0, 0, 0, 0, 0, 1, 3, 5, 7, 10, 12, 13, -1, -1, -1, -1, -1, -1 },
218 { 0, 0, 0, 0, 1, 2, 2, 9, 13, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
221 { { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 6, 9, 11, 12, 13, -1, -1, -1, -1 },
222 { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 6, 9, 11, 12, 13, -1, -1, -1, -1 },
223 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
226 { { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 6, 9, 11, 12, 13, -1, -1, -1, -1 },
227 { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 6, 9, 11, 12, 13, -1, -1, -1, -1 },
228 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
231 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 10, 11, 11, 12, 12, 14, -1 },
232 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 10, 11, 11, 12, 12, 14, -1 },
233 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
236 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 10, 11, 11, 12, 12, 14, -1 },
237 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 10, 11, 11, 12, 12, 14, -1 },
238 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
241 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 8, 11, 12, 12, -1, -1 },
242 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 8, 11, 12, 12, -1, -1 },
243 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
313 if (!blk || (block->
cpl_in_use && !got_cpl_snr)) {
361 for (i = start; i < end; i++) {
378 int expstr,
i, grpsize;
381 grpsize = 3 << expstr;
382 for (i = 12; i < 256; i++) {
409 #define EXP_DIFF_THRESHOLD 500 429 for (ch = !s->
cpl_on; ch <= s->fbw_channels; ch++) {
462 while (blk < s->num_blocks) {
464 while (blk1 < s->num_blocks && exp_strategy[blk1] ==
EXP_REUSE)
478 if (CONFIG_EAC3_ENCODER && s->
eac3)
499 switch(exp_strategy) {
501 for (i = 1, k = 1-cpl; i <= nb_groups; i++) {
503 if (exp[k+1] < exp_min)
505 exp[i-cpl] = exp_min;
510 for (i = 1, k = 1-cpl; i <= nb_groups; i++) {
512 if (exp[k+1] < exp_min)
514 if (exp[k+2] < exp_min)
516 if (exp[k+3] < exp_min)
518 exp[i-cpl] = exp_min;
525 if (!cpl && exp[0] > 15)
530 for (i = 1; i <= nb_groups; i++)
531 exp[i] =
FFMIN(exp[i], exp[i-1] + 2);
534 exp[
i] =
FFMIN(exp[i], exp[i+1] + 2);
537 exp[-1] = exp[0] & ~1;
540 switch (exp_strategy) {
542 for (i = nb_groups, k = (nb_groups * 2)-cpl; i > 0; i--) {
549 for (i = nb_groups, k = (nb_groups * 4)-cpl; i > 0; i--) {
550 exp[k] = exp[k-1] = exp[k-2] = exp[k-3] = exp[i-cpl];
566 int blk, blk1, ch, cpl;
568 int nb_coefs, num_reuse_blocks;
576 while (blk < s->num_blocks) {
589 while (blk1 < s->num_blocks && exp_strategy[blk1] ==
EXP_REUSE) {
593 num_reuse_blocks = blk1 - blk - 1;
617 int nb_groups, bit_count;
631 bit_count += 4 + (nb_groups * 7);
649 int group_size, nb_groups;
651 int delta0, delta1, delta2;
661 group_size = exp_strategy + (exp_strategy ==
EXP_D45);
670 for (i = 1; i <= nb_groups; i++) {
675 delta0 = exp1 - exp0 + 2;
681 delta1 = exp1 - exp0 + 2;
687 delta2 = exp1 - exp0 + 2;
690 block->
grouped_exp[ch][
i] = ((delta0 * 5 + delta1) * 5) + delta2;
722 static const uint8_t frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 };
796 frame_bits += 2 + 2 + 2 + 2 + 3;
816 frame_bits += 1 + 16;
836 for (ch = 0; ch <= s->
channels; ch++)
878 frame_bits += 1 + 1 + 2;
884 frame_bits += 3 + 1 + 1;
891 frame_bits += 5 + 2 + 1;
907 frame_bits += 5 * s->
cpl_on;
965 if (!s->
eac3 || blk > 0)
1047 for (ch = 0; ch <= s->
channels; ch++) {
1068 memset(mant_cnt[blk], 0,
sizeof(mant_cnt[blk]));
1069 mant_cnt[
blk][1] = mant_cnt[
blk][2] = 2;
1070 mant_cnt[
blk][4] = 1;
1107 int ch, max_end_freq;
1135 snr_offset = (snr_offset - 240) * 4;
1166 int snr_offset, snr_incr;
1181 while (snr_offset >= 0 &&
1189 for (snr_incr = 64; snr_incr > 0; snr_incr >>= 2) {
1190 while (snr_offset + snr_incr <= 1023 &&
1191 bit_alloc(s, snr_offset + snr_incr) <= bits_left) {
1192 snr_offset += snr_incr;
1235 int v = (((levels *
c) >> (24 - e)) + levels) >> 1;
1253 c = (((c * (1<<e)) >> (24 - qbits)) + 1) >> 1;
1254 m = (1 << (qbits-1));
1275 int16_t *qmant,
int start_freq,
1280 for (i = start_freq; i < end_freq; i++) {
1281 int c = fixed_coef[
i];
1369 int blk, ch, ch0=0, got_cpl;
1376 for (ch = 1; ch <= s->
channels; ch++) {
1454 int ch,
i, baie, bnd, got_cpl,
av_uninit(ch0);
1483 int start_sub, end_sub;
1500 for (bnd = start_sub+1; bnd < end_sub; bnd++)
1525 if (!s->
eac3 || blk > 0)
1536 for (ch = !block->
cpl_in_use; ch <= s->fbw_channels; ch++)
1551 int cpl = (ch ==
CPL_CH);
1561 for (i = 1; i <= nb_groups; i++)
1613 for (ch = 1; ch <= s->
channels; ch++) {
1621 for (i = s->
start_freq[ch]; i < block->end_freq[ch]; i++) {
1626 case 1:
if (q != 128)
put_bits (&s->
pb, 5, q);
break;
1627 case 2:
if (q != 128)
put_bits (&s->
pb, 7, q);
break;
1629 case 4:
if (q != 128)
put_bits (&s->
pb, 7, q);
break;
1642 #define CRC16_POLY ((1 << 0) | (1 << 2) | (1 << 15) | (1 << 16)) 1645 static unsigned int mul_poly(
unsigned int a,
unsigned int b,
unsigned int poly)
1662 static unsigned int pow_poly(
unsigned int a,
unsigned int n,
unsigned int poly)
1682 int frame_size_58, pad_bytes, crc1, crc2_partial, crc2, crc_inv;
1708 crc2_partial =
av_crc(crc_ctx, 0, frame + frame_size_58,
1713 if (crc2 == 0x770B) {
1769 *got_packet_ptr = 1;
1781 case 6:
av_strlcpy(strbuf,
"AC-3 (alt syntax)", 32);
break;
1782 case 8:
av_strlcpy(strbuf,
"AC-3 (standard)", 32);
break;
1783 case 9:
av_strlcpy(strbuf,
"AC-3 (dnet half-rate)", 32);
break;
1784 case 10:
av_strlcpy(strbuf,
"AC-3 (dnet quater-rate)", 32);
break;
1785 case 16:
av_strlcpy(strbuf,
"E-AC-3 (enhanced)", 32);
break;
1786 default:
snprintf(strbuf, 32,
"ERROR");
1791 ff_dlog(avctx,
"channel_layout: %s\n", strbuf);
1798 ff_dlog(avctx,
"per_frame_metadata: %s\n",
1804 ff_dlog(avctx,
"center_mixlev: {not written}\n");
1809 ff_dlog(avctx,
"surround_mixlev: {not written}\n");
1818 ff_dlog(avctx,
"room_type: %s\n", strbuf);
1820 ff_dlog(avctx,
"mixing_level: {not written}\n");
1821 ff_dlog(avctx,
"room_type: {not written}\n");
1832 ff_dlog(avctx,
"dsur_mode: %s\n", strbuf);
1834 ff_dlog(avctx,
"dsur_mode: {not written}\n");
1846 ff_dlog(avctx,
"dmix_mode: %s\n", strbuf);
1847 ff_dlog(avctx,
"ltrt_cmixlev: %0.3f (%d)\n",
1849 ff_dlog(avctx,
"ltrt_surmixlev: %0.3f (%d)\n",
1851 ff_dlog(avctx,
"loro_cmixlev: %0.3f (%d)\n",
1853 ff_dlog(avctx,
"loro_surmixlev: %0.3f (%d)\n",
1856 ff_dlog(avctx,
"extended bitstream info 1: {not written}\n");
1865 ff_dlog(avctx,
"dsurex_mode: %s\n", strbuf);
1872 ff_dlog(avctx,
"dheadphone_mode: %s\n", strbuf);
1879 ff_dlog(avctx,
"ad_conv_type: %s\n", strbuf);
1881 ff_dlog(avctx,
"extended bitstream info 2: {not written}\n");
1888 #define FLT_OPTION_THRESHOLD 0.01 1894 for (i = 0; i < v_list_size; i++) {
1899 if (i == v_list_size)
1907 float *opt_param,
const float *
list,
1908 int list_size,
int default_value,
int min_value,
1912 if (mixlev < min_value) {
1913 mixlev = default_value;
1914 if (*opt_param >= 0.0) {
1916 "default value: %0.3f\n", opt_name, list[mixlev]);
1919 *opt_param = list[mixlev];
1920 *ctx_param = mixlev;
2040 "specified number of channels\n");
2077 "room_type is set\n");
2082 "80dB and 111dB\n");
2095 "not compatible with reduced samplerates. writing of " 2096 "extended bitstream information will be disabled.\n");
2121 for (ch = 0; ch < s->
channels; ch++)
2161 uint64_t *channel_layout)
2167 if (*channel_layout > 0x7FF)
2169 ch_layout = *channel_layout;
2180 switch (ch_layout) {
2197 *channel_layout = ch_layout;
2213 "encoder will guess the layout, but it " 2214 "might be incorrect.\n");
2226 max_sr = s->
eac3 ? 2 : 8;
2227 for (i = 0; i <= max_sr; i++) {
2243 case 1: avctx->
bit_rate = 96000;
break;
2244 case 2: avctx->
bit_rate = 192000;
break;
2245 case 3: avctx->
bit_rate = 320000;
break;
2246 case 4: avctx->
bit_rate = 384000;
break;
2247 case 5: avctx->
bit_rate = 448000;
break;
2253 int max_br, min_br, wpf, min_br_code;
2254 int num_blks_code, num_blocks, frame_samples;
2255 long long min_br_dist;
2261 for (num_blks_code = 3; num_blks_code >= 0; num_blks_code--) {
2262 num_blocks = ((
int[]){ 1, 2, 3, 6 })[num_blks_code];
2264 max_br = 2048 * s->
sample_rate / frame_samples * 16;
2265 min_br = ((s->
sample_rate + (frame_samples-1)) / frame_samples) * 16;
2271 "for this sample rate\n", min_br, max_br);
2285 min_br_dist = INT64_MAX;
2286 for (i = 0; i < 19; i++) {
2288 if (br_dist < min_br_dist) {
2289 min_br_dist = br_dist;
2300 int best_br = 0, best_code = 0;
2301 long long best_diff = INT64_MAX;
2302 for (i = 0; i < 19; i++) {
2305 if (diff < best_diff) {
2383 if (cpl_start < 0) {
2392 int i, cpl_start_band, cpl_end_band;
2396 cpl_start_band =
av_clip(cpl_start, 0,
FFMIN(cpl_end_band-1, 15));
2401 *cpl_band_sizes = 12;
2402 for (i = cpl_start_band + 1; i < cpl_end_band; i++) {
2404 *cpl_band_sizes += 12;
2408 *cpl_band_sizes = 12;
2424 int channel_blocks = channels * s->
num_blocks;
2464 for (ch = 0; ch <
channels; ch++) {
2510 int ret, frame_size_58;
2538 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
const AVOption ff_ac3_enc_options[]
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)
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)
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)
const AVCodecDefault ff_ac3_enc_defaults[]
#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
#define AC3ENC_OPT_DOWNMIX_DPLII
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_enc_channel_map[8][2][6]
Table to remap channels from SMPTE order to AC-3 order.
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...
#define COMMON_CHANNEL_MAP
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)
#define AC3ENC_OPT_DSUREX_DPLIIZ
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)