summaryrefslogtreecommitdiff
path: root/libavcodec/mpc8.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec/mpc8.c')
-rw-r--r--libavcodec/mpc8.c89
1 files changed, 26 insertions, 63 deletions
diff --git a/libavcodec/mpc8.c b/libavcodec/mpc8.c
index 2744bcbac1..c263762c8b 100644
--- a/libavcodec/mpc8.c
+++ b/libavcodec/mpc8.c
@@ -86,33 +86,37 @@ static int mpc8_get_mask(GetBitContext *gb, int size, int t)
return mask;
}
-static const uint16_t vlc_offsets[13] = {
- 0, 640, 1184, 1748, 2298, 2426, 2490, 3002, 3258, 3786, 4298, 4876, 5388
-};
-
-static av_cold void build_vlc(VLC *vlc,
+static av_cold void build_vlc(VLC *vlc, unsigned *buf_offset,
const uint8_t codes_counts[16],
- const uint8_t syms[], int offset)
+ const uint8_t **syms, int offset)
{
+ static VLC_TYPE vlc_buf[9296][2];
uint8_t len[MPC8_MAX_VLC_SIZE];
unsigned num = 0;
+ vlc->table = &vlc_buf[*buf_offset];
+ vlc->table_allocated = FF_ARRAY_ELEMS(vlc_buf) - *buf_offset;
+
for (int i = 16; i > 0; i--)
for (unsigned tmp = num + codes_counts[i - 1]; num < tmp; num++)
len[num] = i;
ff_init_vlc_from_lengths(vlc, FFMIN(len[0], 9), num, len, 1,
- syms, 1, 1, offset, INIT_VLC_USE_NEW_STATIC, NULL);
+ *syms, 1, 1, offset, INIT_VLC_STATIC_OVERLONG, NULL);
+ *buf_offset += vlc->table_size;
+ *syms += num;
}
static av_cold int mpc8_decode_init(AVCodecContext * avctx)
{
- int i;
+ int i, offset = 0;
MPCContext *c = avctx->priv_data;
GetBitContext gb;
static int vlc_initialized = 0;
+ const uint8_t *q_syms = mpc8_q_syms, *bands_syms = mpc8_bands_syms;
+ const uint8_t *res_syms = mpc8_res_syms, *scfi_syms = mpc8_scfi_syms;
+ const uint8_t *dscf_syms = mpc8_dscf_syms;
int channels;
- static VLC_TYPE codes_table[5388][2];
if(avctx->extradata_size < 2){
av_log(avctx, AV_LOG_ERROR, "Too small extradata size (%i)!\n", avctx->extradata_size);
@@ -145,65 +149,24 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx)
if(vlc_initialized) return 0;
av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n");
-#define INIT_VLC(vlc, bits, len_counts, symbols, offset, static_size) \
- do { \
- static VLC_TYPE table[static_size][2]; \
- (vlc)->table = table; \
- (vlc)->table_allocated = static_size; \
- build_vlc(vlc, len_counts, symbols, offset); \
- } while (0)
-
+ build_vlc(&band_vlc, &offset, mpc8_bands_len_counts, &bands_syms, 0);
- INIT_VLC(&band_vlc, MPC8_BANDS_BITS,
- mpc8_bands_len_counts, mpc8_bands_syms, 0, 542);
+ build_vlc(&q1_vlc, &offset, mpc8_q1_len_counts, &q_syms, 0);
+ build_vlc(&q9up_vlc, &offset, mpc8_q9up_len_counts, &q_syms, 0);
- INIT_VLC(&q1_vlc, MPC8_Q1_BITS,
- mpc8_q1_len_counts, mpc8_q1_syms, 0, 520);
- INIT_VLC(&q9up_vlc, MPC8_Q9UP_BITS,
- mpc8_q9up_len_counts, mpc8_q9up_syms, 0, 524);
-
- INIT_VLC(&scfi_vlc[0], MPC8_SCFI0_BITS,
- mpc8_scfi_len_counts[0], mpc8_scfi0_syms, 0, 1 << MPC8_SCFI0_BITS);
- INIT_VLC(&scfi_vlc[1], MPC8_SCFI1_BITS,
- mpc8_scfi_len_counts[1], mpc8_scfi1_syms, 0, 1 << MPC8_SCFI1_BITS);
+ for(i = 0; i < 2; i++){
+ build_vlc(&scfi_vlc[i], &offset, mpc8_scfi_len_counts[i], &scfi_syms, 0);
- INIT_VLC(&dscf_vlc[0], MPC8_DSCF0_BITS,
- mpc8_dscf_len_counts[0], mpc8_dscf0_syms, 0, 560);
- INIT_VLC(&dscf_vlc[1], MPC8_DSCF1_BITS,
- mpc8_dscf_len_counts[1], mpc8_dscf1_syms, 0, 598);
+ build_vlc(&dscf_vlc[i], &offset, mpc8_dscf_len_counts[i], &dscf_syms, 0);
- INIT_VLC(&q3_vlc[0], MPC8_Q3_BITS,
- mpc8_q3_len_counts, mpc8_q3_syms, MPC8_Q3_OFFSET, 512);
- INIT_VLC(&q3_vlc[1], MPC8_Q4_BITS,
- mpc8_q4_len_counts, mpc8_q4_syms, MPC8_Q4_OFFSET, 516);
+ build_vlc(&res_vlc[i], &offset, mpc8_res_len_counts[i], &res_syms, 0);
- for(i = 0; i < 2; i++){
- res_vlc[i].table = &codes_table[vlc_offsets[0+i]];
- res_vlc[i].table_allocated = vlc_offsets[1+i] - vlc_offsets[0+i];
- build_vlc(&res_vlc[i],
- mpc8_res_len_counts[i], mpc8_res_syms[i], 0);
-
- q2_vlc[i].table = &codes_table[vlc_offsets[2+i]];
- q2_vlc[i].table_allocated = vlc_offsets[3+i] - vlc_offsets[2+i];
- build_vlc(&q2_vlc[i],
- mpc8_q2_len_counts[i], mpc8_q2_syms[i], 0);
-
- quant_vlc[0][i].table = &codes_table[vlc_offsets[4+i]];
- quant_vlc[0][i].table_allocated = vlc_offsets[5+i] - vlc_offsets[4+i];
- build_vlc(&quant_vlc[0][i],
- mpc8_q5_len_counts[i], mpc8_q5_syms[i], MPC8_Q5_OFFSET);
- quant_vlc[1][i].table = &codes_table[vlc_offsets[6+i]];
- quant_vlc[1][i].table_allocated = vlc_offsets[7+i] - vlc_offsets[6+i];
- build_vlc(&quant_vlc[1][i],
- mpc8_q6_len_counts[i], mpc8_q6_syms[i], MPC8_Q6_OFFSET);
- quant_vlc[2][i].table = &codes_table[vlc_offsets[8+i]];
- quant_vlc[2][i].table_allocated = vlc_offsets[9+i] - vlc_offsets[8+i];
- build_vlc(&quant_vlc[2][i],
- mpc8_q7_len_counts[i], mpc8_q7_syms[i], MPC8_Q7_OFFSET);
- quant_vlc[3][i].table = &codes_table[vlc_offsets[10+i]];
- quant_vlc[3][i].table_allocated = vlc_offsets[11+i] - vlc_offsets[10+i];
- build_vlc(&quant_vlc[3][i],
- mpc8_q8_len_counts[i], mpc8_q8_syms[i], MPC8_Q8_OFFSET);
+ build_vlc(&q2_vlc[i], &offset, mpc8_q2_len_counts[i], &q_syms, 0);
+ build_vlc(&q3_vlc[i], &offset, mpc8_q34_len_counts[i],
+ &q_syms, -48 - 16 * i);
+ for (int j = 0; j < 4; j++)
+ build_vlc(&quant_vlc[j][i], &offset, mpc8_q5_8_len_counts[i][j],
+ &q_syms, -((8 << j) - 1));
}
vlc_initialized = 1;
ff_mpa_synth_init_fixed();