diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2011-08-10 16:29:46 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-08-10 16:29:51 +0200 |
commit | a9aa88df1d8bdef7a3ba520e285c6c5b639d5fd5 (patch) | |
tree | ad58a7f68309b31b07d54564879e4f60ffdeac88 /libavcodec/ac3enc.c | |
parent | e2cc3311246376e902f0defc6c57bd554babcf39 (diff) | |
parent | 7221139ba0486c24afeac1f41ba97c75f58046b9 (diff) | |
download | ffmpeg-a9aa88df1d8bdef7a3ba520e285c6c5b639d5fd5.tar.gz |
Merge remote-tracking branch 'qatar/master'
* qatar/master:
lavc: make avcodec_init() static on next bump.
ac3enc: remove unneeded #include
ac3enc: restructure coupling coordinate reuse calculation
ac3enc: allow new coupling coordinates to be sent independently for each channel.
ac3enc: separate exponent bit counting from exponent grouping.
h264: propagate error return values for AV_LOG_ERROR-triggering events
aac: Don't attempt to output configure an invalid channel configuration.
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/ac3enc.c')
-rw-r--r-- | libavcodec/ac3enc.c | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index b17036cb68..69be683ffa 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -527,19 +527,46 @@ static void encode_exponents(AC3EncodeContext *s) /** + * Count exponent bits based on bandwidth, coupling, and exponent strategies. + */ +static int count_exponent_bits(AC3EncodeContext *s) +{ + int blk, ch; + int nb_groups, bit_count; + + bit_count = 0; + for (blk = 0; blk < s->num_blocks; blk++) { + AC3Block *block = &s->blocks[blk]; + for (ch = !block->cpl_in_use; ch <= s->channels; ch++) { + int exp_strategy = s->exp_strategy[ch][blk]; + int cpl = (ch == CPL_CH); + int nb_coefs = block->end_freq[ch] - s->start_freq[ch]; + + if (exp_strategy == EXP_REUSE) + continue; + + nb_groups = exponent_group_tab[cpl][exp_strategy-1][nb_coefs]; + bit_count += 4 + (nb_groups * 7); + } + } + + return bit_count; +} + + +/** * Group exponents. * 3 delta-encoded exponents are in each 7-bit group. The number of groups * varies depending on exponent strategy and bandwidth. */ -static void group_exponents(AC3EncodeContext *s) +void ff_ac3_group_exponents(AC3EncodeContext *s) { int blk, ch, i, cpl; - int group_size, nb_groups, bit_count; + int group_size, nb_groups; uint8_t *p; int delta0, delta1, delta2; int exp0, exp1; - bit_count = 0; for (blk = 0; blk < s->num_blocks; blk++) { AC3Block *block = &s->blocks[blk]; for (ch = !block->cpl_in_use; ch <= s->channels; ch++) { @@ -549,7 +576,6 @@ static void group_exponents(AC3EncodeContext *s) cpl = (ch == CPL_CH); group_size = exp_strategy + (exp_strategy == EXP_D45); nb_groups = exponent_group_tab[cpl][exp_strategy-1][block->end_freq[ch]-s->start_freq[ch]]; - bit_count += 4 + (nb_groups * 7); p = block->exp[ch] + s->start_freq[ch] - cpl; /* DC exponent */ @@ -581,8 +607,6 @@ static void group_exponents(AC3EncodeContext *s) } } } - - s->exponent_bits = bit_count; } @@ -599,8 +623,6 @@ void ff_ac3_process_exponents(AC3EncodeContext *s) encode_exponents(s); - group_exponents(s); - emms_c(); } @@ -842,9 +864,9 @@ static void count_frame_bits(AC3EncodeContext *s) if (block->cpl_in_use) { for (ch = 1; ch <= s->fbw_channels; ch++) { if (block->channel_in_cpl[ch]) { - if (!s->eac3 || block->new_cpl_coords != 2) + if (!s->eac3 || block->new_cpl_coords[ch] != 2) frame_bits++; - if (block->new_cpl_coords) { + if (block->new_cpl_coords[ch]) { frame_bits += 2; frame_bits += (4 + 4) * s->num_cpl_bands; } @@ -1095,6 +1117,8 @@ int ff_ac3_compute_bit_allocation(AC3EncodeContext *s) { count_frame_bits(s); + s->exponent_bits = count_exponent_bits(s); + bit_alloc_masking(s); return cbr_bit_allocation(s); @@ -1370,9 +1394,9 @@ static void output_audio_block(AC3EncodeContext *s, int blk) if (block->cpl_in_use) { for (ch = 1; ch <= s->fbw_channels; ch++) { if (block->channel_in_cpl[ch]) { - if (!s->eac3 || block->new_cpl_coords != 2) - put_bits(&s->pb, 1, block->new_cpl_coords); - if (block->new_cpl_coords) { + if (!s->eac3 || block->new_cpl_coords[ch] != 2) + put_bits(&s->pb, 1, block->new_cpl_coords[ch]); + if (block->new_cpl_coords[ch]) { put_bits(&s->pb, 2, block->cpl_master_exp[ch]); for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { put_bits(&s->pb, 4, block->cpl_coord_exp [ch][bnd]); |