Revision c4549bd6 libavcodec/ac3enc.c

View differences:

libavcodec/ac3enc.c
112 112
    uint8_t  coeff_shift[AC3_MAX_CHANNELS];     ///< fixed-point coefficient shift values
113 113
    uint8_t  new_rematrixing_strategy;          ///< send new rematrixing flags in this block
114 114
    uint8_t  rematrixing_flags[4];              ///< rematrixing flags
115
    struct AC3Block *exp_ref_block[AC3_MAX_CHANNELS]; ///< reference blocks for EXP_REUSE
115 116
} AC3Block;
116 117

  
117 118
/**
......
692 693
static void encode_exponents(AC3EncodeContext *s)
693 694
{
694 695
    int blk, blk1, ch;
695
    uint8_t *exp, *exp1, *exp_strategy;
696
    uint8_t *exp, *exp_strategy;
696 697
    int nb_coefs, num_reuse_blocks;
697 698

  
698 699
    for (ch = 0; ch < s->channels; ch++) {
......
704 705
        while (blk < AC3_MAX_BLOCKS) {
705 706
            blk1 = blk + 1;
706 707

  
707
            /* count the number of EXP_REUSE blocks after the current block */
708
            while (blk1 < AC3_MAX_BLOCKS && exp_strategy[blk1] == EXP_REUSE)
708
            /* count the number of EXP_REUSE blocks after the current block
709
               and set exponent reference block pointers */
710
            s->blocks[blk].exp_ref_block[ch] = &s->blocks[blk];
711
            while (blk1 < AC3_MAX_BLOCKS && exp_strategy[blk1] == EXP_REUSE) {
712
                s->blocks[blk1].exp_ref_block[ch] = &s->blocks[blk];
709 713
                blk1++;
714
            }
710 715
            num_reuse_blocks = blk1 - blk - 1;
711 716

  
712 717
            /* for the EXP_REUSE case we select the min of the exponents */
......
714 719

  
715 720
            encode_exponents_blk_ch(exp, nb_coefs, exp_strategy[blk]);
716 721

  
717
            /* copy encoded exponents for reuse case */
718
            exp1 = exp + AC3_MAX_COEFS;
719
            while (blk < blk1-1) {
720
                memcpy(exp1, exp, nb_coefs * sizeof(*exp));
721
                exp1 += AC3_MAX_COEFS;
722
                blk++;
723
            }
722
            exp += AC3_MAX_COEFS * (num_reuse_blocks + 1);
724 723
            blk = blk1;
725
            exp = exp1;
726 724
        }
727 725
    }
728 726
}
......
1035 1033
    reset_block_bap(s);
1036 1034
    mantissa_bits = 0;
1037 1035
    for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
1038
        AC3Block *block = &s->blocks[blk];
1036
        AC3Block *block;
1039 1037
        // initialize grouped mantissa counts. these are set so that they are
1040 1038
        // padded to the next whole group size when bits are counted in
1041 1039
        // compute_mantissa_size_final
......
1047 1045
               blocks within a frame are the exponent values.  We can take
1048 1046
               advantage of that by reusing the bit allocation pointers
1049 1047
               whenever we reuse exponents. */
1050
            if (s->exp_strategy[ch][blk] == EXP_REUSE) {
1051
                memcpy(block->bap[ch], s->blocks[blk-1].bap[ch], AC3_MAX_COEFS);
1052
            } else {
1048
            block = s->blocks[blk].exp_ref_block[ch];
1049
            if (s->exp_strategy[ch][blk] != EXP_REUSE) {
1053 1050
                ff_ac3_bit_alloc_calc_bap(block->mask[ch], block->psd[ch], 0,
1054 1051
                                          s->nb_coefs[ch], snr_offset,
1055 1052
                                          s->bit_alloc.floor, ff_ac3_bap_tab,
......
1352 1349

  
1353 1350
    for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
1354 1351
        AC3Block *block = &s->blocks[blk];
1352
        AC3Block *ref_block;
1355 1353
        s->mant1_cnt  = s->mant2_cnt  = s->mant4_cnt  = 0;
1356 1354
        s->qmant1_ptr = s->qmant2_ptr = s->qmant4_ptr = NULL;
1357 1355

  
1358 1356
        for (ch = 0; ch < s->channels; ch++) {
1357
            ref_block = block->exp_ref_block[ch];
1359 1358
            quantize_mantissas_blk_ch(s, block->fixed_coef[ch],
1360
                                      block->exp[ch], block->bap[ch],
1359
                                      ref_block->exp[ch], ref_block->bap[ch],
1361 1360
                                      block->qmant[ch], s->nb_coefs[ch]);
1362 1361
        }
1363 1362
    }
......
1516 1515
    /* mantissas */
1517 1516
    for (ch = 0; ch < s->channels; ch++) {
1518 1517
        int b, q;
1518
        AC3Block *ref_block = block->exp_ref_block[ch];
1519 1519
        for (i = 0; i < s->nb_coefs[ch]; i++) {
1520 1520
            q = block->qmant[ch][i];
1521
            b = block->bap[ch][i];
1521
            b = ref_block->bap[ch][i];
1522 1522
            switch (b) {
1523 1523
            case 0:                                         break;
1524 1524
            case 1: if (q != 128) put_bits(&s->pb,   5, q); break;

Also available in: Unified diff