summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2011-08-05 16:00:18 -0400
committerJustin Ruggles <justin.ruggles@gmail.com>2011-08-09 16:28:18 -0400
commitd55ad59a8a67b73f3370ee01efd0051fbffe3577 (patch)
tree31ed0608a919c255c74ba047d3514d37f0145ad2 /libavcodec
parent12fe75942316dd13dec42502145fd3292882f510 (diff)
ac3enc: separate exponent bit counting from exponent grouping.
Move bit counting to the bit allocation function. Move exponent grouping to after bit allocation. This will allow for adjustment of bandwidth parameters during bit allocation without having to do exponent grouping multiple times.
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/ac3enc.c40
-rw-r--r--libavcodec/ac3enc.h2
-rw-r--r--libavcodec/ac3enc_template.c2
3 files changed, 36 insertions, 8 deletions
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index c138f99207..d454654c00 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();
}
@@ -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);
diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index 6d57143a01..c1e69b101f 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -257,6 +257,8 @@ void ff_ac3_process_exponents(AC3EncodeContext *s);
int ff_ac3_compute_bit_allocation(AC3EncodeContext *s);
+void ff_ac3_group_exponents(AC3EncodeContext *s);
+
void ff_ac3_quantize_mantissas(AC3EncodeContext *s);
void ff_ac3_output_frame(AC3EncodeContext *s, unsigned char *frame);
diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c
index 103e7b1a96..dd1e48d1f8 100644
--- a/libavcodec/ac3enc_template.c
+++ b/libavcodec/ac3enc_template.c
@@ -463,6 +463,8 @@ int AC3_NAME(encode_frame)(AVCodecContext *avctx, unsigned char *frame,
return ret;
}
+ ff_ac3_group_exponents(s);
+
ff_ac3_quantize_mantissas(s);
ff_ac3_output_frame(s, frame);