# HG changeset patch # User kostya # Date 1239977396 0 # Node ID d719a2711c64f976ed5a79a389b56453fb6f44ed # Parent ab2daba3e200988fe11a2842c6e5785d22ce84c8 Use new static VLC scheme in Indeo2, Musepack and WNV1 decoders diff -r ab2daba3e200 -r d719a2711c64 indeo2.c --- a/indeo2.c Fri Apr 17 13:59:07 2009 +0000 +++ b/indeo2.c Fri Apr 17 14:09:56 2009 +0000 @@ -192,20 +192,22 @@ static av_cold int ir2_decode_init(AVCodecContext *avctx){ Ir2Context * const ic = avctx->priv_data; + static VLC_TYPE vlc_tables[1 << CODE_VLC_BITS][2]; ic->avctx = avctx; avctx->pix_fmt= PIX_FMT_YUV410P; - if (!ir2_vlc.table) + ir2_vlc.table = vlc_tables; + ir2_vlc.table_allocated = 1 << CODE_VLC_BITS; #ifdef ALT_BITSTREAM_READER_LE init_vlc(&ir2_vlc, CODE_VLC_BITS, IR2_CODES, &ir2_codes[0][1], 4, 2, - &ir2_codes[0][0], 4, 2, INIT_VLC_USE_STATIC | INIT_VLC_LE); + &ir2_codes[0][0], 4, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE); #else init_vlc(&ir2_vlc, CODE_VLC_BITS, IR2_CODES, &ir2_codes[0][1], 4, 2, - &ir2_codes[0][0], 4, 2, INIT_VLC_USE_STATIC); + &ir2_codes[0][0], 4, 2, INIT_VLC_USE_NEW_STATIC); #endif return 0; diff -r ab2daba3e200 -r d719a2711c64 mpc7.c --- a/mpc7.c Fri Apr 17 13:59:07 2009 +0000 +++ b/mpc7.c Fri Apr 17 14:09:56 2009 +0000 @@ -40,6 +40,13 @@ static VLC scfi_vlc, dscf_vlc, hdr_vlc, quant_vlc[MPC7_QUANT_VLC_TABLES][2]; +static uint16_t quant_offsets[MPC7_QUANT_VLC_TABLES*2 + 1] = +{ + 0, 512, 1024, 1536, 2052, 2564, 3076, 3588, 4100, 4612, 5124, + 5636, 6164, 6676, 7224 +}; + + static av_cold int mpc7_decode_init(AVCodecContext * avctx) { int i, j; @@ -48,6 +55,11 @@ uint8_t buf[16]; static int vlc_initialized = 0; + static VLC_TYPE scfi_table[1 << MPC7_SCFI_BITS][2]; + static VLC_TYPE dscf_table[1 << MPC7_DSCF_BITS][2]; + static VLC_TYPE hdr_table[1 << MPC7_HDR_BITS][2]; + static VLC_TYPE quant_tables[7224][2]; + if(avctx->extradata_size < 16){ av_log(avctx, AV_LOG_ERROR, "Too small extradata size (%i)!\n", avctx->extradata_size); return -1; @@ -75,29 +87,37 @@ if(vlc_initialized) return 0; av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n"); + scfi_vlc.table = scfi_table; + scfi_vlc.table_allocated = 1 << MPC7_SCFI_BITS; if(init_vlc(&scfi_vlc, MPC7_SCFI_BITS, MPC7_SCFI_SIZE, &mpc7_scfi[1], 2, 1, - &mpc7_scfi[0], 2, 1, INIT_VLC_USE_STATIC)){ + &mpc7_scfi[0], 2, 1, INIT_VLC_USE_NEW_STATIC)){ av_log(avctx, AV_LOG_ERROR, "Cannot init SCFI VLC\n"); return -1; } + dscf_vlc.table = dscf_table; + dscf_vlc.table_allocated = 1 << MPC7_DSCF_BITS; if(init_vlc(&dscf_vlc, MPC7_DSCF_BITS, MPC7_DSCF_SIZE, &mpc7_dscf[1], 2, 1, - &mpc7_dscf[0], 2, 1, INIT_VLC_USE_STATIC)){ + &mpc7_dscf[0], 2, 1, INIT_VLC_USE_NEW_STATIC)){ av_log(avctx, AV_LOG_ERROR, "Cannot init DSCF VLC\n"); return -1; } + hdr_vlc.table = hdr_table; + hdr_vlc.table_allocated = 1 << MPC7_HDR_BITS; if(init_vlc(&hdr_vlc, MPC7_HDR_BITS, MPC7_HDR_SIZE, &mpc7_hdr[1], 2, 1, - &mpc7_hdr[0], 2, 1, INIT_VLC_USE_STATIC)){ + &mpc7_hdr[0], 2, 1, INIT_VLC_USE_NEW_STATIC)){ av_log(avctx, AV_LOG_ERROR, "Cannot init HDR VLC\n"); return -1; } for(i = 0; i < MPC7_QUANT_VLC_TABLES; i++){ for(j = 0; j < 2; j++){ + quant_vlc[i][j].table = &quant_tables[quant_offsets[i*2 + j]]; + quant_vlc[i][j].table_allocated = quant_offsets[i*2 + j + 1] - quant_offsets[i*2 + j]; if(init_vlc(&quant_vlc[i][j], 9, mpc7_quant_vlc_sizes[i], &mpc7_quant_vlc[i][j][1], 4, 2, - &mpc7_quant_vlc[i][j][0], 4, 2, INIT_VLC_USE_STATIC)){ + &mpc7_quant_vlc[i][j][0], 4, 2, INIT_VLC_USE_NEW_STATIC)){ av_log(avctx, AV_LOG_ERROR, "Cannot init QUANT VLC %i,%i\n",i,j); return -1; } diff -r ab2daba3e200 -r d719a2711c64 mpc8.c --- a/mpc8.c Fri Apr 17 13:59:07 2009 +0000 +++ b/mpc8.c Fri Apr 17 14:09:56 2009 +0000 @@ -88,6 +88,10 @@ return mask; } +static int vlc_offsets[13] = { + 0, 640, 1184, 1748, 2298, 2426, 2554, 3066, 3578, 4106, 4618, 5196, 5708 +}; + static av_cold int mpc8_decode_init(AVCodecContext * avctx) { int i; @@ -95,6 +99,17 @@ GetBitContext gb; static int vlc_initialized = 0; + static VLC_TYPE band_table[542][2]; + static VLC_TYPE q1_table[520][2]; + static VLC_TYPE q9up_table[524][2]; + static VLC_TYPE scfi0_table[1 << MPC8_SCFI0_BITS][2]; + static VLC_TYPE scfi1_table[1 << MPC8_SCFI1_BITS][2]; + static VLC_TYPE dscf0_table[560][2]; + static VLC_TYPE dscf1_table[598][2]; + static VLC_TYPE q3_0_table[512][2]; + static VLC_TYPE q3_1_table[516][2]; + static VLC_TYPE codes_table[5708][2]; + if(avctx->extradata_size < 2){ av_log(avctx, AV_LOG_ERROR, "Too small extradata size (%i)!\n", avctx->extradata_size); return -1; @@ -116,61 +131,91 @@ if(vlc_initialized) return 0; av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n"); + band_vlc.table = band_table; + band_vlc.table_allocated = 542; init_vlc(&band_vlc, MPC8_BANDS_BITS, MPC8_BANDS_SIZE, mpc8_bands_bits, 1, 1, - mpc8_bands_codes, 1, 1, INIT_VLC_USE_STATIC); + mpc8_bands_codes, 1, 1, INIT_VLC_USE_NEW_STATIC); + q1_vlc.table = q1_table; + q1_vlc.table_allocated = 520; init_vlc(&q1_vlc, MPC8_Q1_BITS, MPC8_Q1_SIZE, mpc8_q1_bits, 1, 1, - mpc8_q1_codes, 1, 1, INIT_VLC_USE_STATIC); + mpc8_q1_codes, 1, 1, INIT_VLC_USE_NEW_STATIC); + q9up_vlc.table = q9up_table; + q9up_vlc.table_allocated = 524; init_vlc(&q9up_vlc, MPC8_Q9UP_BITS, MPC8_Q9UP_SIZE, mpc8_q9up_bits, 1, 1, - mpc8_q9up_codes, 1, 1, INIT_VLC_USE_STATIC); + mpc8_q9up_codes, 1, 1, INIT_VLC_USE_NEW_STATIC); + scfi_vlc[0].table = scfi0_table; + scfi_vlc[0].table_allocated = 1 << MPC8_SCFI0_BITS; init_vlc(&scfi_vlc[0], MPC8_SCFI0_BITS, MPC8_SCFI0_SIZE, mpc8_scfi0_bits, 1, 1, - mpc8_scfi0_codes, 1, 1, INIT_VLC_USE_STATIC); + mpc8_scfi0_codes, 1, 1, INIT_VLC_USE_NEW_STATIC); + scfi_vlc[1].table = scfi1_table; + scfi_vlc[1].table_allocated = 1 << MPC8_SCFI1_BITS; init_vlc(&scfi_vlc[1], MPC8_SCFI1_BITS, MPC8_SCFI1_SIZE, mpc8_scfi1_bits, 1, 1, - mpc8_scfi1_codes, 1, 1, INIT_VLC_USE_STATIC); + mpc8_scfi1_codes, 1, 1, INIT_VLC_USE_NEW_STATIC); + dscf_vlc[0].table = dscf0_table; + dscf_vlc[0].table_allocated = 560; init_vlc(&dscf_vlc[0], MPC8_DSCF0_BITS, MPC8_DSCF0_SIZE, mpc8_dscf0_bits, 1, 1, - mpc8_dscf0_codes, 1, 1, INIT_VLC_USE_STATIC); + mpc8_dscf0_codes, 1, 1, INIT_VLC_USE_NEW_STATIC); + dscf_vlc[1].table = dscf1_table; + dscf_vlc[1].table_allocated = 598; init_vlc(&dscf_vlc[1], MPC8_DSCF1_BITS, MPC8_DSCF1_SIZE, mpc8_dscf1_bits, 1, 1, - mpc8_dscf1_codes, 1, 1, INIT_VLC_USE_STATIC); + mpc8_dscf1_codes, 1, 1, INIT_VLC_USE_NEW_STATIC); + q3_vlc[0].table = q3_0_table; + q3_vlc[0].table_allocated = 512; init_vlc_sparse(&q3_vlc[0], MPC8_Q3_BITS, MPC8_Q3_SIZE, mpc8_q3_bits, 1, 1, mpc8_q3_codes, 1, 1, - mpc8_q3_syms, 1, 1, INIT_VLC_USE_STATIC); + mpc8_q3_syms, 1, 1, INIT_VLC_USE_NEW_STATIC); + q3_vlc[1].table = q3_1_table; + q3_vlc[1].table_allocated = 516; init_vlc_sparse(&q3_vlc[1], MPC8_Q4_BITS, MPC8_Q4_SIZE, mpc8_q4_bits, 1, 1, mpc8_q4_codes, 1, 1, - mpc8_q4_syms, 1, 1, INIT_VLC_USE_STATIC); + mpc8_q4_syms, 1, 1, INIT_VLC_USE_NEW_STATIC); 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]; init_vlc(&res_vlc[i], MPC8_RES_BITS, MPC8_RES_SIZE, &mpc8_res_bits[i], 1, 1, - &mpc8_res_codes[i], 1, 1, INIT_VLC_USE_STATIC); + &mpc8_res_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); + q2_vlc[i].table = &codes_table[vlc_offsets[2+i]]; + q2_vlc[i].table_allocated = vlc_offsets[3+i] - vlc_offsets[2+i]; init_vlc(&q2_vlc[i], MPC8_Q2_BITS, MPC8_Q2_SIZE, &mpc8_q2_bits[i], 1, 1, - &mpc8_q2_codes[i], 1, 1, INIT_VLC_USE_STATIC); + &mpc8_q2_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); + 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]; init_vlc(&quant_vlc[0][i], MPC8_Q5_BITS, MPC8_Q5_SIZE, &mpc8_q5_bits[i], 1, 1, - &mpc8_q5_codes[i], 1, 1, INIT_VLC_USE_STATIC); + &mpc8_q5_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); + 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]; init_vlc(&quant_vlc[1][i], MPC8_Q6_BITS, MPC8_Q6_SIZE, &mpc8_q6_bits[i], 1, 1, - &mpc8_q6_codes[i], 1, 1, INIT_VLC_USE_STATIC); + &mpc8_q6_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); + 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]; init_vlc(&quant_vlc[2][i], MPC8_Q7_BITS, MPC8_Q7_SIZE, &mpc8_q7_bits[i], 1, 1, - &mpc8_q7_codes[i], 1, 1, INIT_VLC_USE_STATIC); + &mpc8_q7_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); + 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]; init_vlc(&quant_vlc[3][i], MPC8_Q8_BITS, MPC8_Q8_SIZE, &mpc8_q8_bits[i], 1, 1, - &mpc8_q8_codes[i], 1, 1, INIT_VLC_USE_STATIC); + &mpc8_q8_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); } vlc_initialized = 1; avctx->sample_fmt = SAMPLE_FMT_S16; diff -r ab2daba3e200 -r d719a2711c64 wnv1.c --- a/wnv1.c Fri Apr 17 13:59:07 2009 +0000 +++ b/wnv1.c Fri Apr 17 14:09:56 2009 +0000 @@ -129,15 +129,16 @@ static av_cold int decode_init(AVCodecContext *avctx){ WNV1Context * const l = avctx->priv_data; + static VLC_TYPE code_table[1 << CODE_VLC_BITS][2]; l->avctx = avctx; avctx->pix_fmt = PIX_FMT_YUV422P; - if(!code_vlc.table){ + code_vlc.table = code_table; + code_vlc.table_allocated = 1 << CODE_VLC_BITS; init_vlc(&code_vlc, CODE_VLC_BITS, 16, &code_tab[0][1], 4, 2, - &code_tab[0][0], 4, 2, INIT_VLC_USE_STATIC); - } + &code_tab[0][0], 4, 2, INIT_VLC_USE_NEW_STATIC); return 0; }