/*
* Common code between the AC-3 encoder and decoder
- * Copyright (c) 2000 Fabrice Bellard.
+ * Copyright (c) 2000 Fabrice Bellard
*
* This file is part of FFmpeg.
*
*/
/**
- * @file ac3.c
+ * @file libavcodec/ac3.c
* Common code between the AC-3 encoder and decoder.
*/
#include "avcodec.h"
#include "ac3.h"
-#include "bitstream.h"
+#include "get_bits.h"
static uint8_t band_start_tab[51];
static uint8_t bin_to_band_tab[253];
} while (end > band_start_tab[k]);
}
-void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
- int start, int end, int fast_gain, int is_lfe,
- int dba_mode, int dba_nsegs, uint8_t *dba_offsets,
- uint8_t *dba_lengths, uint8_t *dba_values,
- int16_t *mask)
+int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
+ int start, int end, int fast_gain, int is_lfe,
+ int dba_mode, int dba_nsegs, uint8_t *dba_offsets,
+ uint8_t *dba_lengths, uint8_t *dba_values,
+ int16_t *mask)
{
int16_t excite[50]; /* excitation */
int bin, k;
if (dba_mode == DBA_REUSE || dba_mode == DBA_NEW) {
int band, seg, delta;
+ if (dba_nsegs >= 8)
+ return -1;
band = 0;
- for (seg = 0; seg < FFMIN(8, dba_nsegs); seg++) {
- band = FFMIN(49, band + dba_offsets[seg]);
+ for (seg = 0; seg < dba_nsegs; seg++) {
+ band += dba_offsets[seg];
+ if (band >= 50 || dba_lengths[seg] > 50-band)
+ return -1;
if (dba_values[seg] >= 4) {
delta = (dba_values[seg] - 3) << 7;
} else {
}
}
}
+ return 0;
}
void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end,