summaryrefslogtreecommitdiff
path: root/libavcodec/ac3enc.c
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2011-06-21 12:59:11 -0400
committerJustin Ruggles <justin.ruggles@gmail.com>2011-06-27 12:59:39 -0400
commit7dcdf974d02caee206b38d0946b2fc1fab082aa3 (patch)
treede6527dfb31bbb8f1f6495053243b0d033a8cfcb /libavcodec/ac3enc.c
parent659aa20e56de03b461afdaa6ae7e5d4be6e0d5fc (diff)
ac3enc: Remove bit allocation fallbacks.
They introduce too much complexity for very little benefit. The result is that encoding will be more likely to fail at extremely low bitrates where quality would be awful anyway.
Diffstat (limited to 'libavcodec/ac3enc.c')
-rw-r--r--libavcodec/ac3enc.c71
1 files changed, 1 insertions, 70 deletions
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 1f7d05e87c..3fbbbd0991 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -1023,47 +1023,6 @@ static int cbr_bit_allocation(AC3EncodeContext *s)
/**
- * Downgrade exponent strategies to reduce the bits used by the exponents.
- * This is a fallback for when bit allocation fails with the normal exponent
- * strategies. Each time this function is run it only downgrades the
- * strategy in 1 channel of 1 block.
- * @return non-zero if downgrade was unsuccessful
- */
-static int downgrade_exponents(AC3EncodeContext *s)
-{
- int ch, blk;
-
- for (blk = AC3_MAX_BLOCKS-1; blk >= 0; blk--) {
- for (ch = !s->blocks[blk].cpl_in_use; ch <= s->fbw_channels; ch++) {
- if (s->exp_strategy[ch][blk] == EXP_D15) {
- s->exp_strategy[ch][blk] = EXP_D25;
- return 0;
- }
- }
- }
- for (blk = AC3_MAX_BLOCKS-1; blk >= 0; blk--) {
- for (ch = !s->blocks[blk].cpl_in_use; ch <= s->fbw_channels; ch++) {
- if (s->exp_strategy[ch][blk] == EXP_D25) {
- s->exp_strategy[ch][blk] = EXP_D45;
- return 0;
- }
- }
- }
- /* block 0 cannot reuse exponents, so only downgrade D45 to REUSE if
- the block number > 0 */
- for (blk = AC3_MAX_BLOCKS-1; blk > 0; blk--) {
- for (ch = !s->blocks[blk].cpl_in_use; ch <= s->fbw_channels; ch++) {
- if (s->exp_strategy[ch][blk] > EXP_REUSE) {
- s->exp_strategy[ch][blk] = EXP_REUSE;
- return 0;
- }
- }
- }
- return -1;
-}
-
-
-/**
* Perform bit allocation search.
* Finds the SNR offset value that maximizes quality and fits in the specified
* frame size. Output is the SNR offset and a set of bit allocation pointers
@@ -1071,39 +1030,11 @@ static int downgrade_exponents(AC3EncodeContext *s)
*/
static int compute_bit_allocation(AC3EncodeContext *s)
{
- int ret;
-
count_frame_bits(s);
bit_alloc_masking(s);
- ret = cbr_bit_allocation(s);
- while (ret) {
- /* fallback 1: disable channel coupling */
- if (s->cpl_on) {
- s->cpl_on = 0;
- compute_coupling_strategy(s);
- s->compute_rematrixing_strategy(s);
- apply_rematrixing(s);
- process_exponents(s);
- ret = compute_bit_allocation(s);
- continue;
- }
-
- /* fallback 2: downgrade exponents */
- if (!downgrade_exponents(s)) {
- extract_exponents(s);
- encode_exponents(s);
- group_exponents(s);
- ret = compute_bit_allocation(s);
- continue;
- }
-
- /* fallbacks were not enough... */
- break;
- }
-
- return ret;
+ return cbr_bit_allocation(s);
}