The number of dba segments is the coded value + 1.
The coupling dba offset starts at the first coupling band, not at zero.
---
I finally got my hands on an AC-3 sample which uses delta bit allocation.
Unfortunately the Libav AC-3 decoder didn't decode it properly. This patch
fixes that.
libavcodec/ac3.c | 4 ++--
libavcodec/ac3dec.c | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/libavcodec/ac3.c b/libavcodec/ac3.c
index 704c6e0..99e5b50 100644
--- a/libavcodec/ac3.c
+++ b/libavcodec/ac3.c
@@ -192,9 +192,9 @@ int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
if (dba_mode == DBA_REUSE || dba_mode == DBA_NEW) {
int i, seg, delta;
- if (dba_nsegs >= 8)
+ if (dba_nsegs > 8)
return -1;
- band = 0;
+ band = band_start;
for (seg = 0; seg < dba_nsegs; seg++) {
band += dba_offsets[seg];
if (band >= AC3_CRITICAL_BANDS || dba_lengths[seg] > AC3_CRITICAL_BANDS-band)
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index 396df87..208b40f 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -1065,7 +1065,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
if (decode_exponents(gbc, s->exp_strategy[blk][ch],
s->num_exp_groups[ch], s->dexps[ch][0],
&s->dexps[ch][s->start_freq[ch]+!!ch])) {
- av_log(s->avctx, AV_LOG_ERROR, "exponent out-of-range\n");
+ av_log(s->avctx, AV_LOG_ERROR, "exponent out-of-range (blk=%d ch=%d)\n", blk, ch);
return -1;
}
if(ch != CPL_CH && ch != s->lfe_ch)
@@ -1173,8 +1173,8 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
/* channel delta offset, len and bit allocation */
for (ch = !cpl_in_use; ch <= fbw_channels; ch++) {
if (s->dba_mode[ch] == DBA_NEW) {
- s->dba_nsegs[ch] = get_bits(gbc, 3);
- for (seg = 0; seg <= s->dba_nsegs[ch]; seg++) {
+ s->dba_nsegs[ch] = get_bits(gbc, 3) + 1;
+ for (seg = 0; seg < s->dba_nsegs[ch]; seg++) {
s->dba_offsets[ch][seg] = get_bits(gbc, 5);
s->dba_lengths[ch][seg] = get_bits(gbc, 4);
s->dba_values[ch][seg] = get_bits(gbc, 3);
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel