mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-13 21:28:01 +02:00
Split out counting of frame bits into a separate function.
Originally committed as revision 26002 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
33a7d549e8
commit
8999944ecb
@ -744,6 +744,57 @@ static int process_exponents(AC3EncodeContext *s,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Count the bits used to encode the frame, minus exponents and mantissas.
|
||||||
|
* @return bit count
|
||||||
|
*/
|
||||||
|
static int count_frame_bits(AC3EncodeContext *s,
|
||||||
|
uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS])
|
||||||
|
{
|
||||||
|
static const int frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 };
|
||||||
|
int blk, ch;
|
||||||
|
int frame_bits;
|
||||||
|
|
||||||
|
/* header size */
|
||||||
|
frame_bits = 65;
|
||||||
|
frame_bits += frame_bits_inc[s->channel_mode];
|
||||||
|
|
||||||
|
/* audio blocks */
|
||||||
|
for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
|
||||||
|
frame_bits += s->fbw_channels * 2 + 2; /* blksw * c, dithflag * c, dynrnge, cplstre */
|
||||||
|
if (s->channel_mode == AC3_CHMODE_STEREO) {
|
||||||
|
frame_bits++; /* rematstr */
|
||||||
|
if (!blk)
|
||||||
|
frame_bits += 4;
|
||||||
|
}
|
||||||
|
frame_bits += 2 * s->fbw_channels; /* chexpstr[2] * c */
|
||||||
|
if (s->lfe_on)
|
||||||
|
frame_bits++; /* lfeexpstr */
|
||||||
|
for (ch = 0; ch < s->fbw_channels; ch++) {
|
||||||
|
if (exp_strategy[blk][ch] != EXP_REUSE)
|
||||||
|
frame_bits += 6 + 2; /* chbwcod[6], gainrng[2] */
|
||||||
|
}
|
||||||
|
frame_bits++; /* baie */
|
||||||
|
frame_bits++; /* snr */
|
||||||
|
frame_bits += 2; /* delta / skip */
|
||||||
|
}
|
||||||
|
frame_bits++; /* cplinu for block 0 */
|
||||||
|
/* bit alloc info */
|
||||||
|
/* sdcycod[2], fdcycod[2], sgaincod[2], dbpbcod[2], floorcod[3] */
|
||||||
|
/* csnroffset[6] */
|
||||||
|
/* (fsnoffset[4] + fgaincod[4]) * c */
|
||||||
|
frame_bits += 2*4 + 3 + 6 + s->channels * (4 + 3);
|
||||||
|
|
||||||
|
/* auxdatae, crcrsv */
|
||||||
|
frame_bits += 2;
|
||||||
|
|
||||||
|
/* CRC */
|
||||||
|
frame_bits += 16;
|
||||||
|
|
||||||
|
return frame_bits;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the number of bits needed to encode a set of mantissas.
|
* Calculate the number of bits needed to encode a set of mantissas.
|
||||||
*/
|
*/
|
||||||
@ -879,12 +930,11 @@ static int compute_bit_allocation(AC3EncodeContext *s,
|
|||||||
uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS],
|
uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS],
|
||||||
int frame_bits)
|
int frame_bits)
|
||||||
{
|
{
|
||||||
int blk, ch;
|
int ch;
|
||||||
int coarse_snr_offset, fine_snr_offset;
|
int coarse_snr_offset, fine_snr_offset;
|
||||||
uint8_t bap1[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS];
|
uint8_t bap1[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS];
|
||||||
int16_t psd[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS];
|
int16_t psd[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS];
|
||||||
int16_t mask[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS];
|
int16_t mask[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS];
|
||||||
static const int frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 };
|
|
||||||
|
|
||||||
/* init default parameters */
|
/* init default parameters */
|
||||||
s->slow_decay_code = 2;
|
s->slow_decay_code = 2;
|
||||||
@ -902,43 +952,8 @@ static int compute_bit_allocation(AC3EncodeContext *s,
|
|||||||
s->bit_alloc.db_per_bit = ff_ac3_db_per_bit_tab[s->db_per_bit_code];
|
s->bit_alloc.db_per_bit = ff_ac3_db_per_bit_tab[s->db_per_bit_code];
|
||||||
s->bit_alloc.floor = ff_ac3_floor_tab[s->floor_code];
|
s->bit_alloc.floor = ff_ac3_floor_tab[s->floor_code];
|
||||||
|
|
||||||
/* header size */
|
/* count frame bits other than exponents and mantissas */
|
||||||
frame_bits += 65;
|
frame_bits += count_frame_bits(s, exp_strategy);
|
||||||
// if (s->channel_mode == 2)
|
|
||||||
// frame_bits += 2;
|
|
||||||
frame_bits += frame_bits_inc[s->channel_mode];
|
|
||||||
|
|
||||||
/* audio blocks */
|
|
||||||
for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
|
|
||||||
frame_bits += s->fbw_channels * 2 + 2; /* blksw * c, dithflag * c, dynrnge, cplstre */
|
|
||||||
if (s->channel_mode == AC3_CHMODE_STEREO) {
|
|
||||||
frame_bits++; /* rematstr */
|
|
||||||
if (!blk)
|
|
||||||
frame_bits += 4;
|
|
||||||
}
|
|
||||||
frame_bits += 2 * s->fbw_channels; /* chexpstr[2] * c */
|
|
||||||
if (s->lfe_on)
|
|
||||||
frame_bits++; /* lfeexpstr */
|
|
||||||
for (ch = 0; ch < s->fbw_channels; ch++) {
|
|
||||||
if (exp_strategy[blk][ch] != EXP_REUSE)
|
|
||||||
frame_bits += 6 + 2; /* chbwcod[6], gainrng[2] */
|
|
||||||
}
|
|
||||||
frame_bits++; /* baie */
|
|
||||||
frame_bits++; /* snr */
|
|
||||||
frame_bits += 2; /* delta / skip */
|
|
||||||
}
|
|
||||||
frame_bits++; /* cplinu for block 0 */
|
|
||||||
/* bit alloc info */
|
|
||||||
/* sdcycod[2], fdcycod[2], sgaincod[2], dbpbcod[2], floorcod[3] */
|
|
||||||
/* csnroffset[6] */
|
|
||||||
/* (fsnoffset[4] + fgaincod[4]) * c */
|
|
||||||
frame_bits += 2*4 + 3 + 6 + s->channels * (4 + 3);
|
|
||||||
|
|
||||||
/* auxdatae, crcrsv */
|
|
||||||
frame_bits += 2;
|
|
||||||
|
|
||||||
/* CRC */
|
|
||||||
frame_bits += 16;
|
|
||||||
|
|
||||||
/* calculate psd and masking curve before doing bit allocation */
|
/* calculate psd and masking curve before doing bit allocation */
|
||||||
bit_alloc_masking(s, encoded_exp, exp_strategy, psd, mask);
|
bit_alloc_masking(s, encoded_exp, exp_strategy, psd, mask);
|
||||||
|
Loading…
Reference in New Issue
Block a user