Revision 427e2293

View differences:

libavcodec/ac3enc.c
65 65
    int sample_rate;                        ///< sampling frequency, in Hz
66 66

  
67 67
    int frame_size_min;                     ///< minimum frame size in case rounding is necessary
68
    int frame_size;                         ///< current frame size in words
68
    int frame_size;                         ///< current frame size in bytes
69 69
    int frame_size_code;                    ///< frame size code                        (frmsizecod)
70 70
    int bits_written;                       ///< bit count    (used to avg. bitrate)
71 71
    int samples_written;                    ///< sample count (used to avg. bitrate)
......
562 562
            frame_bits += compute_mantissa_size(s, bap[blk][ch], s->nb_coefs[ch]);
563 563
        }
564 564
    }
565
    return 16 * s->frame_size - frame_bits;
565
    return 8 * s->frame_size - frame_bits;
566 566
}
567 567

  
568 568

  
......
699 699
    put_bits(&s->pb, 16, 0x0b77);   /* frame header */
700 700
    put_bits(&s->pb, 16, 0);        /* crc1: will be filled later */
701 701
    put_bits(&s->pb, 2,  s->bit_alloc.sr_code);
702
    put_bits(&s->pb, 6,  s->frame_size_code + (s->frame_size - s->frame_size_min));
702
    put_bits(&s->pb, 6,  s->frame_size_code + (s->frame_size - s->frame_size_min) / 2);
703 703
    put_bits(&s->pb, 5,  s->bitstream_id);
704 704
    put_bits(&s->pb, 3,  s->bitstream_mode);
705 705
    put_bits(&s->pb, 3,  s->channel_mode);
......
1048 1048
    flush_put_bits(&s->pb);
1049 1049
    /* add zero bytes to reach the frame size */
1050 1050
    frame = s->pb.buf;
1051
    pad_bytes = 2 * s->frame_size - (put_bits_ptr(&s->pb) - frame) - 2;
1051
    pad_bytes = s->frame_size - (put_bits_ptr(&s->pb) - frame) - 2;
1052 1052
    assert(pad_bytes >= 0);
1053 1053
    if (pad_bytes > 0)
1054 1054
        memset(put_bits_ptr(&s->pb), 0, pad_bytes);
1055 1055

  
1056 1056
    /* Now we must compute both crcs : this is not so easy for crc1
1057 1057
       because it is at the beginning of the data... */
1058
    frame_size_58 = (frame_size >> 1) + (frame_size >> 3);
1058
    frame_size_58 = ((frame_size >> 2) + (frame_size >> 4)) << 1;
1059 1059

  
1060 1060
    crc1 = av_bswap16(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0,
1061
                             frame + 4, 2 * frame_size_58 - 4));
1061
                             frame + 4, frame_size_58 - 4));
1062 1062

  
1063 1063
    /* XXX: could precompute crc_inv */
1064
    crc_inv = pow_poly((CRC16_POLY >> 1), (16 * frame_size_58) - 16, CRC16_POLY);
1064
    crc_inv = pow_poly((CRC16_POLY >> 1), (8 * frame_size_58) - 16, CRC16_POLY);
1065 1065
    crc1    = mul_poly(crc_inv, crc1, CRC16_POLY);
1066 1066
    AV_WB16(frame + 2, crc1);
1067 1067

  
1068 1068
    crc2 = av_bswap16(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0,
1069
                             frame + 2 * frame_size_58,
1070
                             (frame_size - frame_size_58) * 2 - 2));
1071
    AV_WB16(frame + 2*frame_size - 2, crc2);
1069
                             frame + frame_size_58,
1070
                             frame_size - frame_size_58 - 2));
1071
    AV_WB16(frame + frame_size - 2, crc2);
1072 1072
}
1073 1073

  
1074 1074

  
......
1174 1174
        s->bits_written    -= s->bit_rate;
1175 1175
        s->samples_written -= s->sample_rate;
1176 1176
    }
1177
    s->frame_size = s->frame_size_min + (s->bits_written * s->sample_rate < s->samples_written * s->bit_rate);
1178
    s->bits_written    += s->frame_size * 16;
1177
    s->frame_size = s->frame_size_min + 2 * (s->bits_written * s->sample_rate < s->samples_written * s->bit_rate);
1178
    s->bits_written    += s->frame_size * 8;
1179 1179
    s->samples_written += AC3_FRAME_SIZE;
1180 1180

  
1181 1181
    compute_bit_allocation(s, bap, encoded_exp, exp_strategy, frame_bits);
......
1188 1188
    }
1189 1189
    output_frame_end(s);
1190 1190

  
1191
    return s->frame_size * 2;
1191
    return s->frame_size;
1192 1192
}
1193 1193

  
1194 1194

  
......
1298 1298
        return -1;
1299 1299
    s->bit_rate        = bitrate;
1300 1300
    s->frame_size_code = i << 1;
1301
    s->frame_size_min  = ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code];
1301
    s->frame_size_min  = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code];
1302 1302
    s->bits_written    = 0;
1303 1303
    s->samples_written = 0;
1304 1304
    s->frame_size      = s->frame_size_min;

Also available in: Unified diff